Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_napalm_configure_change_commit(self, nornir):
opt = {"path": THIS_DIR + "/test_napalm_configure_change_commit/step1"}
configuration = "hostname changed-hostname"
d = nornir.filter(name="dev3.group_2")
d.run(connections.napalm_connection, optional_args=opt)
result = d.run(
networking.napalm_configure, dry_run=False, configuration=configuration
)
assert result
for h, r in result.items():
assert "+hostname changed-hostname" in r.diff
assert r.changed
opt = {"path": THIS_DIR + "/test_napalm_configure_change_commit/step2"}
d.run(connections.napalm_connection, optional_args=opt)
result = d.run(
networking.napalm_configure, dry_run=True, configuration=configuration
)
assert result
for h, r in result.items():
assert "+hostname changed-hostname" not in r.diff
assert not r.changed
def remove_ex2_flash_files():
# prep to ensure test files do not exist on devices
nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
eos = nr.filter(F(groups__contains="eos"))
# remove test files from eos flash
eos.run(task=networking.netmiko_send_command, command_string="terminal dont-ask")
eos.run(
task=networking.netmiko_send_command,
command_string="delete flash:arista_zzzzz.txt",
)
def test_negate_or_both_negate(self, nornir):
f = ~F(site="site1") | ~F(role="www")
filtered = sorted(list((nornir.inventory.filter(f).hosts.keys())))
assert filtered == [
"dev2.group_1",
"dev3.group_2",
"dev4.group_2",
"dev5.no_group",
]
def test_print_failed_with_severity(self, nornir):
nornir.config.logging.configure()
result = nornir.run(read_data)
print_result(result, vars=["exception", "output"], severity_level=logging.ERROR)
def remove_ex2_flash_files():
# prep to ensure test files do not exist on devices
nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
eos = nr.filter(F(groups__contains="eos"))
# remove test files from eos flash
eos.run(task=networking.netmiko_send_command, command_string="terminal dont-ask")
eos.run(
task=networking.netmiko_send_command,
command_string="delete flash:arista_zzzzz.txt",
)
def remove_vlan():
nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
ex3_hosts = nr.filter(F(groups__contains="eos") | F(groups__contains="nxos"))
ex3_hosts.run(task=networking.netmiko_send_config, config_commands=["no vlan 123"])
def uptime(task):
cmd_mapper = {
"ios": "show version | inc uptime",
"eos": "show version | inc Uptime",
"nxos": "show version | inc uptime",
"junos": "show system uptime | match System",
}
host = task.host
platform = host.platform
cmd = cmd_mapper[platform]
multi_result = task.run(task=networking.netmiko_send_command, command_string=cmd)
print(multi_result)
def echo_task(task, msg="Nornir"):
return Result(
host=task.host,
result="Hello from {}".format(msg),
output="Hello from {}".format(msg),
)
def load_data(task):
data = {"os": "Linux", "services": ["http", "smtp", "dns"]}
return Result(host=task.host, result=data)
def test_napalm_getters(self, nornir):
opt = {"path": THIS_DIR + "/test_napalm_getters"}
d = nornir.filter(name="dev3.group_2")
d.run(connections.napalm_connection, optional_args=opt)
result = d.run(networking.napalm_get, getters=["facts", "interfaces"])
assert result
for h, r in result.items():
assert r.result["facts"]
assert r.result["interfaces"]