From 3e975002302eaa31cece9ea6eb741304cdca64ad Mon Sep 17 00:00:00 2001 From: Petr Klima Date: Wed, 11 Nov 2020 19:56:49 +0100 Subject: [PATCH 1/4] hostname parsing - correct unittests --- .../SG300-10/expected_result.json | 2 +- .../expected_result.json | 71 ++++++++ .../SG350X-48P-K9-domainname/show_hosts.txt | 36 ++++ .../show_interface_status.txt | 67 ++++++++ .../show_inventory.txt | 16 ++ .../SG350X-48P-K9-domainname/show_system.txt | 21 +++ .../SG350X-48P-K9-domainname/show_version.txt | 10 ++ .../expected_result.json | 2 +- .../SG350X-48P-K9/expected_result.json | 2 +- .../expected_result.json | 4 +- .../show_hosts.txt | 0 .../show_interface_status.txt | 0 .../show_inventory.txt | 0 .../SG500-28-K9/show_running_config.txt | 154 ++++++++++++++++++ .../show_system.txt | 0 .../show_version.txt | 0 .../SG550X-24MP-K9/expected_result.json | 2 +- .../SG550X-24MP-K9/show_hosts.txt | 4 +- 18 files changed, 383 insertions(+), 8 deletions(-) create mode 100644 test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/expected_result.json create mode 100644 test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_hosts.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_interface_status.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_inventory.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_system.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_version.txt rename test/unit/mocked_data/test_get_facts/{SG500-28-K9-no_hostname => SG500-28-K9}/expected_result.json (95%) rename test/unit/mocked_data/test_get_facts/{SG500-28-K9-no_hostname => SG500-28-K9}/show_hosts.txt (100%) rename test/unit/mocked_data/test_get_facts/{SG500-28-K9-no_hostname => SG500-28-K9}/show_interface_status.txt (100%) rename test/unit/mocked_data/test_get_facts/{SG500-28-K9-no_hostname => SG500-28-K9}/show_inventory.txt (100%) create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9/show_running_config.txt rename test/unit/mocked_data/test_get_facts/{SG500-28-K9-no_hostname => SG500-28-K9}/show_system.txt (100%) rename test/unit/mocked_data/test_get_facts/{SG500-28-K9-no_hostname => SG500-28-K9}/show_version.txt (100%) diff --git a/test/unit/mocked_data/test_get_facts/SG300-10/expected_result.json b/test/unit/mocked_data/test_get_facts/SG300-10/expected_result.json index a254356..26fb998 100644 --- a/test/unit/mocked_data/test_get_facts/SG300-10/expected_result.json +++ b/test/unit/mocked_data/test_get_facts/SG300-10/expected_result.json @@ -1,5 +1,5 @@ { - "fqdn": "switchaabbcc.", + "fqdn": "Unknown", "hostname": "switchaabbcc", "interface_list": [ "gi1", diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/expected_result.json b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/expected_result.json new file mode 100644 index 0000000..ffa3f29 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/expected_result.json @@ -0,0 +1,71 @@ +{ + "fqdn" : "switch1.example.net", + "hostname" : "switch1", + "interface_list" : [ + "gi1/0/1", + "gi1/0/2", + "gi1/0/3", + "gi1/0/4", + "gi1/0/5", + "gi1/0/6", + "gi1/0/7", + "gi1/0/8", + "gi1/0/9", + "gi1/0/10", + "gi1/0/11", + "gi1/0/12", + "gi1/0/13", + "gi1/0/14", + "gi1/0/15", + "gi1/0/16", + "gi1/0/17", + "gi1/0/18", + "gi1/0/19", + "gi1/0/20", + "gi1/0/21", + "gi1/0/22", + "gi1/0/23", + "gi1/0/24", + "gi1/0/25", + "gi1/0/26", + "gi1/0/27", + "gi1/0/28", + "gi1/0/29", + "gi1/0/30", + "gi1/0/31", + "gi1/0/32", + "gi1/0/33", + "gi1/0/34", + "gi1/0/35", + "gi1/0/36", + "gi1/0/37", + "gi1/0/38", + "gi1/0/39", + "gi1/0/40", + "gi1/0/41", + "gi1/0/42", + "gi1/0/43", + "gi1/0/44", + "gi1/0/45", + "gi1/0/46", + "gi1/0/47", + "gi1/0/48", + "te1/0/1", + "te1/0/2", + "te1/0/3", + "te1/0/4", + "Po1", + "Po2", + "Po3", + "Po4", + "Po5", + "Po6", + "Po7", + "Po8" + ], + "model" : "SG350X-48P-K9", + "os_version" : "2.4.5.71", + "serial_number" : "AAA00000BBB", + "uptime" : 1232968, + "vendor" : "Cisco" +} diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_hosts.txt new file mode 100644 index 0000000..ae52691 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_hosts.txt @@ -0,0 +1,36 @@ + +Name/address lookup is enabled +Domain Timeout: 2 seconds +Domain Retry: 1 times +Domain Polling Interval: 8 seconds + + +Default Domain Table + + Domain Source Interface Preference +-------------------------------------------- ------- --------- ---------- +example.net static + + +Name Server Table + + IP Address Source Interface Preference +-------------------------------------------- ------- --------- ---------- +192.168.1.4 static 1 + + +Cache Table +Flags: (STA/DYN, OK/NE/??) +STA - Static, DYN - Dynamic +OK - Okay, NE - Negative Cache, ?? - No Response + + Remaining + Host Addresses Type State TTL +------------------------- ------------------------ ---- ------ ---------- +tftp 192.168.1.4 IPv4 STA,OK +pnpserver.example.net no resolution IPv6 DYN,NE 0000:00:20 +pnpserver.example.net no resolution IPv4 DYN,NE 0000:00:20 + + + + diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_interface_status.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_interface_status.txt new file mode 100644 index 0000000..d37ffe1 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_interface_status.txt @@ -0,0 +1,67 @@ + Flow Link Back Mdix +Port Type Duplex Speed Neg ctrl State Pressure Mode +-------- ------------ ------ ----- -------- ---- ----------- -------- ------- +gi1/0/1 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/2 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/3 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/0/4 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/0/5 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/0/6 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/7 1G-Copper -- -- -- -- Down -- -- +gi1/0/8 1G-Copper -- -- -- -- Down -- -- +gi1/0/9 1G-Copper -- -- -- -- Down -- -- +gi1/0/10 1G-Copper -- -- -- -- Down -- -- +gi1/0/11 1G-Copper -- -- -- -- Down -- -- +gi1/0/12 1G-Copper -- -- -- -- Down -- -- +gi1/0/13 1G-Copper -- -- -- -- Down -- -- +gi1/0/14 1G-Copper -- -- -- -- Down -- -- +gi1/0/15 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/16 1G-Copper Full 100 Enabled Off Up Disabled On +gi1/0/17 1G-Copper -- -- -- -- Down -- -- +gi1/0/18 1G-Copper -- -- -- -- Down -- -- +gi1/0/19 1G-Copper -- -- -- -- Down -- -- +gi1/0/20 1G-Copper -- -- -- -- Down -- -- +gi1/0/21 1G-Copper -- -- -- -- Down -- -- +gi1/0/22 1G-Copper -- -- -- -- Down -- -- +gi1/0/23 1G-Copper -- -- -- -- Down -- -- +gi1/0/24 1G-Copper -- -- -- -- Down -- -- +gi1/0/25 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/26 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/0/27 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/0/28 1G-Copper -- -- -- -- Down -- -- +gi1/0/29 1G-Copper -- -- -- -- Down -- -- +gi1/0/30 1G-Copper -- -- -- -- Down -- -- +gi1/0/31 1G-Copper -- -- -- -- Down -- -- +gi1/0/32 1G-Copper -- -- -- -- Down -- -- +gi1/0/33 1G-Copper -- -- -- -- Down -- -- +gi1/0/34 1G-Copper -- -- -- -- Down -- -- +gi1/0/35 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/36 1G-Copper Full 100 Enabled Off Up Disabled Off +gi1/0/37 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/38 1G-Copper -- -- -- -- Down -- -- +gi1/0/39 1G-Copper Full 100 Enabled Off Up Disabled On +gi1/0/40 1G-Copper -- -- -- -- Down -- -- +gi1/0/41 1G-Copper -- -- -- -- Down -- -- +gi1/0/42 1G-Copper -- -- -- -- Down -- -- +gi1/0/43 1G-Copper -- -- -- -- Down -- -- +gi1/0/44 1G-Copper -- -- -- -- Down -- -- +gi1/0/45 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/0/46 1G-Copper Full 100 Enabled Off Up Disabled Off +gi1/0/47 1G-Copper -- -- -- -- Down -- -- +gi1/0/48 1G-Copper -- -- -- -- Down -- -- +te1/0/1 10G-Combo-F Full 1000 Disabled Off Up Disabled Off +te1/0/2 10G-Combo-C -- -- -- -- Down -- -- +te1/0/3 10G-Fiber Full 1000 Disabled Off Up Disabled Off +te1/0/4 10G-Fiber Full 10000 Disabled Off Up Disabled Off + + Flow Link +Ch Type Duplex Speed Neg control State +-------- ------- ------ ----- -------- ------- ----------- +Po1 -- -- -- -- -- Not Present +Po2 -- -- -- -- -- Not Present +Po3 -- -- -- -- -- Not Present +Po4 -- -- -- -- -- Not Present +Po5 -- -- -- -- -- Not Present +Po6 -- -- -- -- -- Not Present +Po7 -- -- -- -- -- Not Present +Po8 -- -- -- -- -- Not Present diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_inventory.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_inventory.txt new file mode 100644 index 0000000..01eb58b --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_inventory.txt @@ -0,0 +1,16 @@ + +NAME: "1" DESCR: "SG350X-48P 48-Port Gigabit PoE Stackable Managed Switch" +PID: SG350X-48P-K9 VID: V04 SN: AAA00000BBB + + +NAME: "TengigabitEthernet1/0/1" DESCR: "SFP-1000Base-LX" +PID: GLC-LH-SMD VID: V01 SN: IAB8888888 + + +NAME: "TengigabitEthernet1/0/3" DESCR: "SFP-1000Base-SX" +PID: SFP-1000-SX VID: Information Unavailable SN: A888666 + + +NAME: "TengigabitEthernet1/0/4" DESCR: "SFP-10Gbase-CX1" +PID: SFP-H10G-CU1M VID: Information Unavailable SN: AB0B000B0AB000B + diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_system.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_system.txt new file mode 100644 index 0000000..976f6c5 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_system.txt @@ -0,0 +1,21 @@ +System Description: SG350X-48P 48-Port Gigabit PoE Stackable Managed Switch +System Up Time (days,hour:min:sec): 14,06:29:28 +System Contact: +System Name: switch1 +System Location: SW location +System MAC Address: 04:eb:40:e3:91:7f +System Object ID: 1.3.6.1.4.1.9.6.1.94.48.5 + +Unit Type +---- ---------------------- + 1 SG350X-48P + + +Unit Fans Status +---- ------------------------------------- + 1 FANs OK + +Unit Temperature (Celsius) Status +---- --------------------- ---------- + 1 30 OK + diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_version.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_version.txt new file mode 100644 index 0000000..6433144 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-domainname/show_version.txt @@ -0,0 +1,10 @@ +Active-image: flash://system/images/image_tesla_hybrid_2.4.5.71_release_cisco_signed.bin + Version: 2.4.5.71 + MD5 Digest: 2dff89efdb2a0ec2f9a2c414ff7d401c + Date: 04-Nov-2018 + Time: 19:46:16 +Inactive-image: flash://system/images/image1.bin + Version: 2.4.0.94 + MD5 Digest: 6f5be217100f34929986f2e93dd2d5e9 + Date: 31-May-2018 + Time: 02:39:58 diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/expected_result.json b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/expected_result.json index ffbbba5..3f329e1 100644 --- a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/expected_result.json +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/expected_result.json @@ -1,5 +1,5 @@ { - "fqdn" : "switch1.", + "fqdn" : "Unknown", "hostname" : "switch1", "interface_list" : [ "gi1/0/1", diff --git a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9/expected_result.json b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9/expected_result.json index ffbbba5..3f329e1 100644 --- a/test/unit/mocked_data/test_get_facts/SG350X-48P-K9/expected_result.json +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9/expected_result.json @@ -1,5 +1,5 @@ { - "fqdn" : "switch1.", + "fqdn" : "Unknown", "hostname" : "switch1", "interface_list" : [ "gi1/0/1", diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/expected_result.json b/test/unit/mocked_data/test_get_facts/SG500-28-K9/expected_result.json similarity index 95% rename from test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/expected_result.json rename to test/unit/mocked_data/test_get_facts/SG500-28-K9/expected_result.json index 917e2ec..a5bf0ae 100644 --- a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/expected_result.json +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9/expected_result.json @@ -1,6 +1,6 @@ { - "fqdn" : "", - "hostname" : "", + "fqdn" : "Unknown", + "hostname" : "switch1", "interface_list" : [ "gi1/1/1", "gi1/1/2", diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_hosts.txt similarity index 100% rename from test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_hosts.txt rename to test/unit/mocked_data/test_get_facts/SG500-28-K9/show_hosts.txt diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_interface_status.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_interface_status.txt similarity index 100% rename from test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_interface_status.txt rename to test/unit/mocked_data/test_get_facts/SG500-28-K9/show_interface_status.txt diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_inventory.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_inventory.txt similarity index 100% rename from test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_inventory.txt rename to test/unit/mocked_data/test_get_facts/SG500-28-K9/show_inventory.txt diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_running_config.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_running_config.txt new file mode 100644 index 0000000..a2c1765 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_running_config.txt @@ -0,0 +1,154 @@ +config-file-header +switch1 +v1.3.5.58 / R750_NIK_1_35_647_358 +CLI v1.0 +set system mode switch queues-mode 4 + +file SSD indicator encrypted +@ +ssd-control-start +ssd config +ssd file passphrase control unrestricted +no ssd file integrity control +ssd-control-end cb0a3fdb1f3a1af4e4430033719968c0 +! +vlan database +vlan 10,20,30 +exit +voice vlan oui-table add 0001e3 Siemens_AG_phone________ +voice vlan oui-table add 00036b Cisco_phone_____________ +voice vlan oui-table add 00096e Avaya___________________ +voice vlan oui-table add 000fe2 H3C_Aolynk______________ +voice vlan oui-table add 0060b9 Philips_and_NEC_AG_phone +voice vlan oui-table add 00d01e Pingtel_phone___________ +voice vlan oui-table add 00e075 Polycom/Veritel_phone___ +voice vlan oui-table add 00e0bb 3Com_phone______________ +hostname switch1 +username cisco password encrypted dddd5d7b474d2c78ebbb833789c4bfd721edf4bf privilege 15 +ip ssh server +ip ssh password-auth +snmp-server server +snmp-server community findit ro view Default +! +interface vlan 10 + ip address 10.0.3.5 255.0.0.0 +! +interface gigabitethernet1/1/1 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/2 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/3 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/4 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/5 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/6 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/7 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/8 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/9 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/10 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/11 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/12 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/13 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/14 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/15 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/16 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/17 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/18 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/19 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/20 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/21 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/22 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/23 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/24 + switchport mode access + switchport access vlan 30 +! +interface gigabitethernet1/1/25 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/26 + spanning-tree disable + spanning-tree link-type point-to-point + switchport trunk allowed vlan add 10,30 + switchport trunk native vlan 20 + macro description switch + !next command is internal. + macro auto smartport dynamic_type switch +! +interface gigabitethernet1/1/27 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/28 + spanning-tree disable + switchport mode access + switchport access vlan 20 +! +exit diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_system.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_system.txt similarity index 100% rename from test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_system.txt rename to test/unit/mocked_data/test_get_facts/SG500-28-K9/show_system.txt diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_version.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9/show_version.txt similarity index 100% rename from test/unit/mocked_data/test_get_facts/SG500-28-K9-no_hostname/show_version.txt rename to test/unit/mocked_data/test_get_facts/SG500-28-K9/show_version.txt diff --git a/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/expected_result.json b/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/expected_result.json index ea62bc4..bb2d8e0 100644 --- a/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/expected_result.json +++ b/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/expected_result.json @@ -1,5 +1,5 @@ { - "fqdn" : "switch-c.", + "fqdn" : "Unknown", "hostname" : "switch-c", "interface_list" : [ "gi1/0/1", diff --git a/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/show_hosts.txt index 2b7b616..f95e3c7 100644 --- a/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/show_hosts.txt +++ b/test/unit/mocked_data/test_get_facts/SG550X-24MP-K9/show_hosts.txt @@ -16,8 +16,8 @@ Name Server Table IP Address Source Interface Preference -------------------------------------------- ------- --------- ---------- -192.168.0.2 static 1 -192.168.0.40 static 2 +192.168.0.2 static 1 +192.168.0.40 static 2 Cache Table From e3f760faf91db06bf6186d48e453703b105c8f72 Mon Sep 17 00:00:00 2001 From: Petr Klima Date: Wed, 11 Nov 2020 18:58:05 +0000 Subject: [PATCH 2/4] correct hostname and fqdn parsing --- napalm_s350/s350.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 2c85b0a..a94ee31 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -35,7 +35,6 @@ from napalm.base.exceptions import ( import napalm.base.constants as C import napalm.base.helpers - class S350Driver(NetworkDriver): """Napalm driver for S350.""" @@ -222,7 +221,7 @@ class S350Driver(NetworkDriver): def get_facts(self): """Return a set of facts from the device.""" - serial_number, fqdn, os_version, hostname, domain_name = ('Unknown',) * 5 + serial_number, fqdn, os_version, hostname, domainname = ('Unknown',) * 5 # Submit commands to the device. show_ver = self._send_command('show version') @@ -233,13 +232,13 @@ class S350Driver(NetworkDriver): os_version = self._get_facts_parse_os_version(show_ver) - # hostname, uptime - hostname = '' - for line in show_sys.splitlines(): - if line.startswith('System Name:'): - _, hostname = line.split('System Name:') - hostname = hostname.strip() - continue + # hostname + hostname = self._get_facts_hostname(show_sys) + # special case for SG500 fw v1.4.x + if hostname == 'Unknown': + hostname = self._get_facts_hostname_from_config( + self._send_command('show running-config') + ) # uptime uptime_str = self._get_facts_uptime(show_sys) @@ -255,10 +254,8 @@ class S350Driver(NetworkDriver): show_hosts)[0] domainname = domainname['domain_name'] if domainname == 'Domain': - domainname = '' - if domainname == '' and hostname == '': - fqdn = '' - else: + domainname = 'Unknown' + if domainname != "Unknown" and hostname != "Unknown": fqdn = '{0}.{1}'.format(hostname, domainname) # interface_list @@ -286,6 +283,27 @@ class S350Driver(NetworkDriver): 'vendor': u'Cisco', } + def _get_facts_hostname_from_config(self, show_running): + # special case for SG500 fw v1.4.x + hostname = 'Unknown' + for line in show_running.splitlines(): + if line.startswith('hostname '): + _, hostname = line.split('hostname') + hostname = hostname.strip() + break + + return hostname + + def _get_facts_hostname(self, show_sys): + hostname = 'Unknown' + for line in show_sys.splitlines(): + if line.startswith('System Name:'): + _, hostname = line.split('System Name:') + hostname = hostname.strip() + break + + return hostname + def _get_facts_uptime(self, show_sys): i = 0 syslines = [] From 0cb3cbb9ead5156a110bf4ead086ac87e069b92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kl=C3=ADma?= Date: Wed, 11 Nov 2020 20:04:17 +0100 Subject: [PATCH 3/4] two blanklines before class --- napalm_s350/s350.py | 1 + 1 file changed, 1 insertion(+) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index a94ee31..55e8598 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -35,6 +35,7 @@ from napalm.base.exceptions import ( import napalm.base.constants as C import napalm.base.helpers + class S350Driver(NetworkDriver): """Napalm driver for S350.""" From 90f47dd86f0f7c6eba4348987e5a0932dc93bddb Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 13 Nov 2020 14:33:27 +0100 Subject: [PATCH 4/4] add domainname tests for SG500 and SG300 see #58 --- .../SG300-10-domainname/expected_result.json | 29 ++++ .../SG300-10-domainname/show_hosts.txt | 32 ++++ .../show_interface_status.txt | 25 +++ .../SG300-10-domainname/show_inventory.txt | 4 + .../SG300-10-domainname/show_system.txt | 10 ++ .../SG300-10-domainname/show_version.txt | 3 + .../expected_result.json | 69 ++++++++ .../SG500-28-K9-domainname/show_hosts.txt | 32 ++++ .../show_interface_status.txt | 65 ++++++++ .../SG500-28-K9-domainname/show_inventory.txt | 3 + .../show_running_config.txt | 155 ++++++++++++++++++ .../SG500-28-K9-domainname/show_system.txt | 18 ++ .../SG500-28-K9-domainname/show_version.txt | 4 + 13 files changed, 449 insertions(+) create mode 100644 test/unit/mocked_data/test_get_facts/SG300-10-domainname/expected_result.json create mode 100644 test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_hosts.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_interface_status.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_inventory.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_system.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_version.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/expected_result.json create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_hosts.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_interface_status.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_inventory.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_running_config.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_system.txt create mode 100644 test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_version.txt diff --git a/test/unit/mocked_data/test_get_facts/SG300-10-domainname/expected_result.json b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/expected_result.json new file mode 100644 index 0000000..8898893 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/expected_result.json @@ -0,0 +1,29 @@ +{ + "fqdn": "switchaabbcc.test.iai.kit.edu", + "hostname": "switchaabbcc", + "interface_list": [ + "gi1", + "gi2", + "gi3", + "gi4", + "gi5", + "gi6", + "gi7", + "gi8", + "gi9", + "gi10", + "Po1", + "Po2", + "Po3", + "Po4", + "Po5", + "Po6", + "Po7", + "Po8" + ], + "model": "SRW2008-K9", + "os_version": "1.4.11.5", + "serial_number": "AAAABBBBCCC", + "uptime": 607990, + "vendor": "Cisco" +} diff --git a/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_hosts.txt new file mode 100644 index 0000000..74613fa --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_hosts.txt @@ -0,0 +1,32 @@ + +Name/address lookup is enabled +Domain Timeout: 2 seconds +Domain Retry: 1 times +Domain Polling Interval: 8 seconds + + +Default Domain Table + + Domain Source Interface Preference +-------------------------------------------- ------- --------- ---------- +test.iai.kit.edu static + + +Name Server Table + + IP Address Source Interface Preference +-------------------------------------------- ------- --------- ---------- +Name server is not configured + + +Cache Table +Flags: (STA/DYN, OK/NE/??) +STA - Static, DYN - Dynamic +OK - Okay, NE - Negative Cache, ?? - No Response + + Remaining + Host Addresses Type State TTL +------------------------- ------------------------ ---- ------ ---------- +No hostname is mapped to an IP address + + diff --git a/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_interface_status.txt b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_interface_status.txt new file mode 100644 index 0000000..8f9b9a9 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_interface_status.txt @@ -0,0 +1,25 @@ + Flow Link Back Mdix +Port Type Duplex Speed Neg ctrl State Pressure Mode +-------- ------------ ------ ----- -------- ---- ----------- -------- ------- +gi1 1G-Copper -- -- -- -- Down -- -- +gi2 1G-Copper -- -- -- -- Down -- -- +gi3 1G-Copper -- -- -- -- Down -- -- +gi4 1G-Copper -- -- -- -- Down -- -- +gi5 1G-Copper -- -- -- -- Down -- -- +gi6 1G-Copper -- -- -- -- Down -- -- +gi7 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi8 1G-Copper Full 1000 Enabled Off Up Disabled On +gi9 1G-Combo-C -- -- -- -- Down -- -- +gi10 1G-Combo-C -- -- -- -- Down -- -- + + Flow Link +Ch Type Duplex Speed Neg control State +-------- ------- ------ ----- -------- ------- ----------- +Po1 -- -- -- -- -- Not Present +Po2 -- -- -- -- -- Not Present +Po3 -- -- -- -- -- Not Present +Po4 -- -- -- -- -- Not Present +Po5 -- -- -- -- -- Not Present +Po6 -- -- -- -- -- Not Present +Po7 -- -- -- -- -- Not Present +Po8 -- -- -- -- -- Not Present diff --git a/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_inventory.txt b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_inventory.txt new file mode 100644 index 0000000..d6b109e --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_inventory.txt @@ -0,0 +1,4 @@ + +NAME: "1" DESCR: "SG300-10 10-Port Gigabit Managed Switch" +PID: SRW2008-K9 VID: V05 SN: AAAABBBBCCC + diff --git a/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_system.txt b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_system.txt new file mode 100644 index 0000000..410f06d --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_system.txt @@ -0,0 +1,10 @@ +System Description: SG300-10 10-Port Gigabit Managed Switch +System Up Time (days,hour:min:sec): 07,00:53:10 +System Contact: +System Name: switchaabbcc +System Location: +System MAC Address: 50:f7:22:aa:bb:cc +System Object ID: 1.3.6.1.4.1.9.6.1.83.10.1 + +Fans Status: N/A + diff --git a/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_version.txt b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_version.txt new file mode 100644 index 0000000..34c1bcf --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10-domainname/show_version.txt @@ -0,0 +1,3 @@ +SW version 1.4.11.5 ( date 08-Apr-2020 time 13:49:34 ) +Boot version 1.3.5.06 ( date 21-Jul-2013 time 15:12:10 ) +HW version V05 diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/expected_result.json b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/expected_result.json new file mode 100644 index 0000000..1c80718 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/expected_result.json @@ -0,0 +1,69 @@ +{ + "fqdn" : "switch1.test.iai.kit.edu", + "hostname" : "switch1", + "interface_list" : [ + "gi1/1/1", + "gi1/1/2", + "gi1/1/3", + "gi1/1/4", + "gi1/1/5", + "gi1/1/6", + "gi1/1/7", + "gi1/1/8", + "gi1/1/9", + "gi1/1/10", + "gi1/1/11", + "gi1/1/12", + "gi1/1/13", + "gi1/1/14", + "gi1/1/15", + "gi1/1/16", + "gi1/1/17", + "gi1/1/18", + "gi1/1/19", + "gi1/1/20", + "gi1/1/21", + "gi1/1/22", + "gi1/1/23", + "gi1/1/24", + "gi1/1/25", + "gi1/1/26", + "Po1", + "Po2", + "Po3", + "Po4", + "Po5", + "Po6", + "Po7", + "Po8", + "Po9", + "Po10", + "Po11", + "Po12", + "Po13", + "Po14", + "Po15", + "Po16", + "Po17", + "Po18", + "Po19", + "Po20", + "Po21", + "Po22", + "Po23", + "Po24", + "Po25", + "Po26", + "Po27", + "Po28", + "Po29", + "Po30", + "Po31", + "Po32" + ], + "model" : "SG500-28-K9", + "os_version" : "1.4.11.5", + "serial_number" : "A1B2C3F4G5", + "uptime" : 1287, + "vendor" : "Cisco" +} diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_hosts.txt new file mode 100644 index 0000000..74613fa --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_hosts.txt @@ -0,0 +1,32 @@ + +Name/address lookup is enabled +Domain Timeout: 2 seconds +Domain Retry: 1 times +Domain Polling Interval: 8 seconds + + +Default Domain Table + + Domain Source Interface Preference +-------------------------------------------- ------- --------- ---------- +test.iai.kit.edu static + + +Name Server Table + + IP Address Source Interface Preference +-------------------------------------------- ------- --------- ---------- +Name server is not configured + + +Cache Table +Flags: (STA/DYN, OK/NE/??) +STA - Static, DYN - Dynamic +OK - Okay, NE - Negative Cache, ?? - No Response + + Remaining + Host Addresses Type State TTL +------------------------- ------------------------ ---- ------ ---------- +No hostname is mapped to an IP address + + diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_interface_status.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_interface_status.txt new file mode 100644 index 0000000..990d901 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_interface_status.txt @@ -0,0 +1,65 @@ + Flow Link Back Mdix +Port Type Duplex Speed Neg ctrl State Pressure Mode +-------- ------------ ------ ----- -------- ---- ----------- -------- ------- +gi1/1/1 1G-Copper -- -- -- -- Down -- -- +gi1/1/2 1G-Copper -- -- -- -- Down -- -- +gi1/1/3 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/1/4 1G-Copper -- -- -- -- Down -- -- +gi1/1/5 1G-Copper -- -- -- -- Down -- -- +gi1/1/6 1G-Copper -- -- -- -- Down -- -- +gi1/1/7 1G-Copper -- -- -- -- Down -- -- +gi1/1/8 1G-Copper -- -- -- -- Down -- -- +gi1/1/9 1G-Copper -- -- -- -- Down -- -- +gi1/1/10 1G-Copper -- -- -- -- Down -- -- +gi1/1/11 1G-Copper -- -- -- -- Down -- -- +gi1/1/12 1G-Copper Full 1000 Enabled Off Up Disabled Off +gi1/1/13 1G-Copper -- -- -- -- Down -- -- +gi1/1/14 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/1/15 1G-Copper Full 1000 Enabled Off Up Disabled On +gi1/1/16 1G-Copper -- -- -- -- Down -- -- +gi1/1/17 1G-Copper -- -- -- -- Down -- -- +gi1/1/18 1G-Copper -- -- -- -- Down -- -- +gi1/1/19 1G-Copper -- -- -- -- Down -- -- +gi1/1/20 1G-Copper -- -- -- -- Down -- -- +gi1/1/21 1G-Copper -- -- -- -- Down -- -- +gi1/1/22 1G-Copper -- -- -- -- Down -- -- +gi1/1/23 1G-Copper -- -- -- -- Down -- -- +gi1/1/24 1G-Copper -- -- -- -- Down -- -- +gi1/1/25 1G-Combo-C -- -- -- -- Down -- -- +gi1/1/26 1G-Combo-F Full 1000 Disabled Off Up Disabled Off + + Flow Link +Ch Type Duplex Speed Neg control State +-------- ------- ------ ----- -------- ------- ----------- +Po1 -- -- -- -- -- Not Present +Po2 -- -- -- -- -- Not Present +Po3 -- -- -- -- -- Not Present +Po4 -- -- -- -- -- Not Present +Po5 -- -- -- -- -- Not Present +Po6 -- -- -- -- -- Not Present +Po7 -- -- -- -- -- Not Present +Po8 -- -- -- -- -- Not Present +Po9 -- -- -- -- -- Not Present +Po10 -- -- -- -- -- Not Present +Po11 -- -- -- -- -- Not Present +Po12 -- -- -- -- -- Not Present +Po13 -- -- -- -- -- Not Present +Po14 -- -- -- -- -- Not Present +Po15 -- -- -- -- -- Not Present +Po16 -- -- -- -- -- Not Present +Po17 -- -- -- -- -- Not Present +Po18 -- -- -- -- -- Not Present +Po19 -- -- -- -- -- Not Present +Po20 -- -- -- -- -- Not Present +Po21 -- -- -- -- -- Not Present +Po22 -- -- -- -- -- Not Present +Po23 -- -- -- -- -- Not Present +Po24 -- -- -- -- -- Not Present +Po25 -- -- -- -- -- Not Present +Po26 -- -- -- -- -- Not Present +Po27 -- -- -- -- -- Not Present +Po28 -- -- -- -- -- Not Present +Po29 -- -- -- -- -- Not Present +Po30 -- -- -- -- -- Not Present +Po31 -- -- -- -- -- Not Present +Po32 -- -- -- -- -- Not Present diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_inventory.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_inventory.txt new file mode 100644 index 0000000..ae69ee6 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_inventory.txt @@ -0,0 +1,3 @@ + +NAME: "1" DESCR: "SG500-28 28-Port Gigabit Stackable Managed Switch" +PID: SG500-28-K9 VID: V02 SN: A1B2C3F4G5 diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_running_config.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_running_config.txt new file mode 100644 index 0000000..56cafdb --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_running_config.txt @@ -0,0 +1,155 @@ +config-file-header +switch1 +v1.3.5.58 / R750_NIK_1_35_647_358 +CLI v1.0 +set system mode switch queues-mode 4 + +file SSD indicator encrypted +@ +ssd-control-start +ssd config +ssd file passphrase control unrestricted +no ssd file integrity control +ssd-control-end cb0a3fdb1f3a1af4e4430033719968c0 +! +vlan database +vlan 10,20,30 +exit +voice vlan oui-table add 0001e3 Siemens_AG_phone________ +voice vlan oui-table add 00036b Cisco_phone_____________ +voice vlan oui-table add 00096e Avaya___________________ +voice vlan oui-table add 000fe2 H3C_Aolynk______________ +voice vlan oui-table add 0060b9 Philips_and_NEC_AG_phone +voice vlan oui-table add 00d01e Pingtel_phone___________ +voice vlan oui-table add 00e075 Polycom/Veritel_phone___ +voice vlan oui-table add 00e0bb 3Com_phone______________ +hostname switch1 +username cisco password encrypted dddd5d7b474d2c78ebbb833789c4bfd721edf4bf privilege 15 +ip ssh server +ip ssh password-auth +ip domain name test.iai.kit.edu +snmp-server server +snmp-server community findit ro view Default +! +interface vlan 10 + ip address 10.0.3.5 255.0.0.0 +! +interface gigabitethernet1/1/1 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/2 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/3 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/4 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/5 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/6 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/7 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/8 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/9 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/10 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/11 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/12 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/13 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/14 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/15 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/16 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/17 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/18 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/19 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/20 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/21 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/22 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/23 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/24 + switchport mode access + switchport access vlan 30 +! +interface gigabitethernet1/1/25 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/26 + spanning-tree disable + spanning-tree link-type point-to-point + switchport trunk allowed vlan add 10,30 + switchport trunk native vlan 20 + macro description switch + !next command is internal. + macro auto smartport dynamic_type switch +! +interface gigabitethernet1/1/27 + switchport mode access + switchport access vlan 20 +! +interface gigabitethernet1/1/28 + spanning-tree disable + switchport mode access + switchport access vlan 20 +! +exit diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_system.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_system.txt new file mode 100644 index 0000000..a921d5c --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_system.txt @@ -0,0 +1,18 @@ + +Unit Type +---- ---------------------- + 1 SG500-28 + +Unit FAN + Status +---- --------- + 1 N/A + +Unit Temperature (Celsius) Temperature Sensor Status +---- ------------------------- ------------------------- + 1 N/A + + +Unit Up time +---- --------------- + 1 00,00:21:27 diff --git a/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_version.txt b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_version.txt new file mode 100644 index 0000000..8c3e2f9 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG500-28-K9-domainname/show_version.txt @@ -0,0 +1,4 @@ + + Unit SW version Boot version HW version +------------------- ------------------- ------------------- ------------------- + 1 1.4.11.5 1.3.5.06 V02