Skip to content

Commit

Permalink
fix pylint, tests, and drop py36 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkala committed Oct 28, 2022
1 parent 4d6a4da commit 54085f2
Show file tree
Hide file tree
Showing 7 changed files with 862 additions and 802 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
python-version: ["3.7", "3.8", "3.9", "3.10"]
runs-on: "ubuntu-20.04"
env:
PYTHON_VER: "${{ matrix.python-version }}"
Expand Down
11 changes: 5 additions & 6 deletions nornir_nautobot/plugins/processors/get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import hashlib
import logging
import os

from pathlib import Path

from nornir.core.inventory import Host
Expand All @@ -24,9 +23,9 @@ class GetConfig(BaseProcessor):

def __init__(self) -> None:
"""Initialize the processor and ensure some variables are properly initialized."""
self.current_md5 = dict()
self.previous_md5 = dict()
self.config_filename = dict()
self.current_md5 = {}
self.previous_md5 = {}
self.config_filename = {}
self.config_dir = None
self.existing_config_hostnames = None

Expand Down Expand Up @@ -76,7 +75,7 @@ def subtask_instance_started(self, task: Task, host: Host) -> None:
self.config_filename[host.name] = f"{self.config_dir}/{task.host.name}.{self.config_extension}"

if os.path.exists(self.config_filename[host.name]):
current_config = Path(self.config_filename[host.name]).read_text()
current_config = Path(self.config_filename[host.name]).read_text(encoding="utf-8")
self.previous_md5[host.name] = hashlib.md5(current_config.encode("utf-8")).hexdigest() # nosec

def subtask_instance_completed(self, task: Task, host: Host, result: MultiResult) -> None:
Expand Down Expand Up @@ -121,7 +120,7 @@ def subtask_instance_completed(self, task: Task, host: Host, result: MultiResult
self.existing_config_hostnames.remove(host.name)

# Save configuration to file and verify the new MD5
with open(self.config_filename[host.name], "w") as config_:
with open(self.config_filename[host.name], "w", encoding="utf-8") as config_:
config_.write(conf)

host.data["has_config"] = True
Expand Down
18 changes: 9 additions & 9 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
import os
import socket
from typing import Optional

import jinja2

try:
from netmiko.ssh_exception import NetmikoAuthenticationException, NetmikoTimeoutException
except ImportError:
from netmiko import NetmikoAuthenticationException, NetmikoTimeoutException

from netutils.config.clean import clean_config, sanitize_config
from netutils.config.compliance import compliance
from netutils.dns import is_fqdn_resolvable
from netutils.ip import is_ip
from netutils.ping import tcp_ping
from nornir.core.exceptions import NornirSubTaskError
from nornir.core.task import Result, Task
from nornir_jinja2.plugins.tasks import template_file
from nornir_napalm.plugins.tasks import napalm_get
from nornir_netmiko.tasks import netmiko_send_command
from netutils.config.compliance import compliance
from netutils.config.clean import clean_config, sanitize_config
from netutils.ip import is_ip
from netutils.dns import is_fqdn_resolvable
from netutils.ping import tcp_ping

from nornir_nautobot.exceptions import NornirNautobotException
from nornir_nautobot.utils.helpers import make_folder


RUN_COMMAND_MAPPING = {
"default": "show run",
"cisco_nxos": "show run",
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_config(task: Task, logger, obj, backup_file: str, remove_lines: list, su

make_folder(os.path.dirname(backup_file))

with open(backup_file, "w") as filehandler:
with open(backup_file, "w", encoding="utf8") as filehandler:
filehandler.write(running_config)
return Result(host=task.host, result={"config": running_config})

Expand Down Expand Up @@ -207,7 +207,7 @@ def generate_config(
raise

make_folder(os.path.dirname(output_file_location))
with open(output_file_location, "w") as filehandler:
with open(output_file_location, "w", encoding="utf8") as filehandler:
filehandler.write(filled_template)
return Result(host=task.host, result={"config": filled_template})

Expand Down Expand Up @@ -266,6 +266,6 @@ def get_config(task: Task, logger, obj, backup_file: str, remove_lines: list, su

make_folder(os.path.dirname(backup_file))

with open(backup_file, "w") as filehandler:
with open(backup_file, "w", encoding="utf8") as filehandler:
filehandler.write(running_config)
return Result(host=task.host, result={"config": running_config})
Loading

0 comments on commit 54085f2

Please sign in to comment.