-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs on advanced netmiko extras, add new test case for single com… (
#284) * add docs on advanced netmiko extras, add new test case for single command validations
- Loading branch information
Showing
6 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Added documentation on using ssh public key authentication. | ||
- Added documentation on using ssh proxy via jumphost. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...device_onboarding/tests/mock/extract_and_process/first_single_command_test/command_output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[ | ||
{ | ||
"software_image": "C3560CX-UNIVERSALK9-M", | ||
"version": "15.2(7)E9", | ||
"release": "fc1", | ||
"rommon": "Bootstrap", | ||
"hostname": "IOS-SW-1", | ||
"uptime": "18 hours, 30 minutes", | ||
"uptime_years": "", | ||
"uptime_weeks": "", | ||
"uptime_days": "", | ||
"uptime_hours": "18", | ||
"uptime_minutes": "30", | ||
"reload_reason": "power-on", | ||
"running_image": "c3560cx-universalk9-mz.152-7.E9.bin", | ||
"hardware": [ | ||
"WS-C3560CX-12PC-S" | ||
], | ||
"serial": [ | ||
"FOC2341Y2CQ" | ||
], | ||
"config_register": "0xF", | ||
"mac_address": [ | ||
"6C:71:0D:1D:35:80" | ||
], | ||
"restarted": "20:40:50 UTC Thu May 30 2024" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...evice_onboarding/tests/mock/extract_and_process/first_single_command_test/expected_result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"IOS-SW-1" |
4 changes: 4 additions & 0 deletions
4
...rding/tests/mock/extract_and_process/first_single_command_test/partial_command_mapper.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
command: "show version" | ||
parser: "textfsm" | ||
jpath: "[*].hostname" |
60 changes: 60 additions & 0 deletions
60
nautobot_device_onboarding/tests/test_extract_and_process.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Test for single command, extraction, and processing.""" | ||
|
||
import json | ||
import os | ||
import unittest | ||
|
||
import yaml | ||
from nornir.core.inventory import ConnectionOptions, Defaults, Host | ||
|
||
from nautobot_device_onboarding.nornir_plays.formatter import extract_and_post_process | ||
|
||
MOCK_DIR = os.path.join("nautobot_device_onboarding", "tests", "mock") | ||
|
||
|
||
class TestSingleCommandFormatterExtractAndProcess(unittest.TestCase): | ||
"""Test for single command, extraction, and processing.""" | ||
|
||
def setUp(self): | ||
self.host = Host( | ||
name="198.51.100.1", | ||
hostname="198.51.100.1", | ||
port=22, | ||
username="username", | ||
password="password", # nosec | ||
platform="not_used_here", | ||
connection_options={ | ||
"netmiko": ConnectionOptions( | ||
hostname="198.51.100.1", | ||
port=22, | ||
username="username", | ||
password="password", # nosec | ||
platform="platform", | ||
) | ||
}, | ||
defaults=Defaults(data={"sync_vlans": False, "sync_vrfs": False, "sync_cables": False}), | ||
) | ||
|
||
def test_extract_and_process_from_directory(self): | ||
test_dir = f"{MOCK_DIR}/extract_and_process/" | ||
for subdir in os.listdir(test_dir): | ||
subdir_path = os.path.join(test_dir, subdir) | ||
if os.path.isdir(subdir_path): | ||
with self.subTest(subdir=subdir): | ||
with open( | ||
os.path.join(subdir_path, "partial_command_mapper.yml"), "r", encoding="utf-8" | ||
) as parsing_info: | ||
platform_parsing_info = yaml.safe_load(parsing_info) | ||
with open(os.path.join(subdir_path, "command_output"), "r", encoding="utf-8") as command_info: | ||
command_outputs = json.loads(command_info.read()) | ||
with open(os.path.join(subdir_path, "expected_result"), "r", encoding="utf-8") as expected_info: | ||
expected_result = json.loads(expected_info.read()) | ||
|
||
_, postpro_result = extract_and_post_process( | ||
command_outputs, | ||
platform_parsing_info, | ||
{"obj": self.host.name, "original_host": self.host.name}, | ||
None, | ||
False, | ||
) | ||
self.assertEqual(expected_result, postpro_result) |