diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 23c371a..97df73f 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -239,19 +239,14 @@ class S350Driver(NetworkDriver): _, hostname = line.split('System Name:') hostname = hostname.strip() continue - elif line.startswith('System Description:'): - _, model = line.split('System Description:') - model = model.strip() - continue elif line.startswith('System Up Time (days,hour:min:sec):'): _, uptime_str = line.split('System Up Time (days,hour:min:sec):') uptime = self._parse_uptime(uptime_str) - # serial_number - for line in show_inv.splitlines(): - if 'SN:' in line: - serial_number = line.split('SN: ')[-1] - break + # serial_number and model + inventory = self._get_facts_parse_inventory(show_inv)['1'] + serial_number = inventory['sn'] + model = inventory['pid'] # fqdn domainname = napalm.base.helpers.textfsm_extractor(self, 'hosts', @@ -286,6 +281,32 @@ class S350Driver(NetworkDriver): 'vendor': u'Cisco', } + def _get_facts_parse_inventory(self, show_inventory): + """ inventory can list more modules/devices """ + # make 1 module 1 line + show_inventory = re.sub(r'\nPID', ' PID', show_inventory, re.M) + # delete empty lines + show_inventory = re.sub(r'^\n', '', show_inventory, re.M) + show_inventory = re.sub(r'\n\n', '', show_inventory, re.M) + show_inventory = re.sub(r'\n\s*\n', r'\n', show_inventory, re.M) + lines = show_inventory.splitlines() + + modules = {} + for line in lines: + match = re.search(r""" + ^ + NAME:\s"(?P\S+)"\s* + DESCR:\s"(?P[^"]+)"\s* + PID:\s(?P\S+)\s* + VID:\s(?P.+\S)\s* + SN:\s(?P\S+)\s* + """, line, re.X) + module = match.groupdict() + modules[module['name']] = module + + if modules: + return modules + def _get_facts_parse_os_version(self, show_ver): # os_version # detect os ver > 2 @@ -366,24 +387,42 @@ class S350Driver(NetworkDriver): def get_interfaces_ip(self): """Returns all configured interface IP addresses.""" interfaces = {} - valid_interfaces = [] show_ip_int = self._send_command('show ip int') - # Limit to valid interfaces (i.e. ignore vlan 1) + header = True # cycle trought header for line in show_ip_int.splitlines(): - if ('UP' in line or 'DOWN' in line) and line.split()[-1] == 'Valid': - valid_interfaces.append(line) + if header: + # last line of first header + match = re.match(r'^---+ -+ .*$', line) + if match: + header = False + fields_end = self._get_ip_int_fields_end(line) + continue - for interface in valid_interfaces: - network, name = interface.split()[:2] + # next header, stop processing text + if re.match(r'^---+ -+ .*$', line): + break - ip = netaddr.IPNetwork(network) + line_elems = self._get_ip_int_line_to_fields(line, fields_end) + # only valid interfaces + # v 2.x firmware + if 7 in line_elems.keys(): + if line_elems[7] != 'Valid': + continue + # v 1.x firmware + elif line_elems[5] != 'Valid': + continue + + cidr = line_elems[0] + interface = line_elems[1] + + ip = netaddr.IPNetwork(cidr) family = 'ipv{0}'.format(ip.version) - interfaces[name] = { + interfaces[interface] = { family: { - str(ip.ip): { + str(ip.ip): { 'prefix_length': ip.prefixlen } } @@ -391,6 +430,26 @@ class S350Driver(NetworkDriver): return interfaces + def _get_ip_int_line_to_fields(self, line, fields_end): + """ dynamic fields lenghts """ + line_elems = {} + index = 0 + f_start = 0 + for f_end in fields_end: + line_elems[index] = line[f_start:f_end].strip() + index += 1 + f_start = f_end + return line_elems + + def _get_ip_int_fields_end(self, dashline): + """ fields length are diferent device to device, detect them on horizontal lin """ + + fields_end = [m.start() for m in re.finditer(' ', dashline)] + # fields_position.insert(0,0) + fields_end.append(len(dashline)) + + return fields_end + def get_lldp_neighbors(self): """get_lldp_neighbors implementation for s350""" neighbors = {} @@ -406,14 +465,17 @@ class S350Driver(NetworkDriver): match = re.match(r'^--------- -+ .*$', line) if match: header = False + fields_end = self._get_lldp_neighbors_fields_end(line) continue - line_elems = line.split() + line_elems = self._get_lldp_neighbors_line_to_fields(line, fields_end) - # long system name owerflow to the other line - if len(line_elems) == 1: - # complete remote name - remote_name = remote_name + line_elems[0] + # info owerflow to the other line + if line_elems[0] == '' or line_elems[4] == '' or line_elems[5] == '' : + # complete owerflown fields + local_port = local_port + line_elems[0] + remote_port = remote_port + line_elems[2] + remote_name = remote_name + line_elems[3] # then reuse old values na rewrite previous entry else: local_port = line_elems[0] @@ -429,6 +491,26 @@ class S350Driver(NetworkDriver): return neighbors + def _get_lldp_neighbors_line_to_fields(self, line, fields_end): + """ dynamic fields lenghts """ + line_elems={} + index=0 + f_start=0 + for f_end in fields_end: + line_elems[index] = line[f_start:f_end].strip() + index += 1 + f_start = f_end + return line_elems + + def _get_lldp_neighbors_fields_end(self, dashline): + """ fields length are diferent device to device, detect them on horizontal lin """ + + fields_end=[m.start() for m in re.finditer(' ', dashline)] + #fields_position.insert(0,0) + fields_end.append(len(dashline)) + + return fields_end + def _get_lldp_line_value(self, line): """ Safe-ish method to get the value from an 'lldp neighbors $IF' line. diff --git a/test/unit/mocked_data/SG300-10/show_lldp_neighbors.txt b/test/unit/mocked_data/SG300-10/show_lldp_neighbors.txt new file mode 100644 index 0000000..31fc656 --- /dev/null +++ b/test/unit/mocked_data/SG300-10/show_lldp_neighbors.txt @@ -0,0 +1,11 @@ + +System capability legend: +B - Bridge; R - Router; W - Wlan Access Point; T - telephone; +D - DOCSIS Cable Device; H - Host; r - Repeater; +TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other + + Port Device ID Port ID System Name Capabilities TTL +--------- ----------------- ------------- ----------------- ------------ ----- +gi7 00:a5:bf:ff:ee:dd gi8 switchcffeedd B, R 96 +gi8 f2:18:98:aa:bb:cc 9c:eb:e8:c3:b test-pc1 B, W 118 + 2:a1 diff --git a/test/unit/mocked_data/SG300-10/show_ports_jumbo_frame.txt b/test/unit/mocked_data/SG300-10/show_ports_jumbo_frame.txt new file mode 100644 index 0000000..4aafdc0 --- /dev/null +++ b/test/unit/mocked_data/SG300-10/show_ports_jumbo_frame.txt @@ -0,0 +1,3 @@ + + Jumbo frames are disabled + Jumbo frames will be disabled after reset diff --git a/test/unit/mocked_data/commands.txt b/test/unit/mocked_data/commands.txt index cfaf6c8..2f33174 100644 --- a/test/unit/mocked_data/commands.txt +++ b/test/unit/mocked_data/commands.txt @@ -10,6 +10,7 @@ show version show system show interfaces status show interfaces description +show ports jumbo-frame # choose any physical interface on your device show lldp local GigabitEthernet1 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 new file mode 100644 index 0000000..a254356 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10/expected_result.json @@ -0,0 +1,29 @@ +{ + "fqdn": "switchaabbcc.", + "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/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG300-10/show_hosts.txt new file mode 100644 index 0000000..b832434 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10/show_hosts.txt @@ -0,0 +1,33 @@ + +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 +-------------------------------------------- ------- --------- ---------- +Domain name is not configured + + +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/show_interface_status.txt b/test/unit/mocked_data/test_get_facts/SG300-10/show_interface_status.txt new file mode 100644 index 0000000..8f9b9a9 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10/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/show_inventory.txt b/test/unit/mocked_data/test_get_facts/SG300-10/show_inventory.txt new file mode 100644 index 0000000..d6b109e --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10/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/show_system.txt b/test/unit/mocked_data/test_get_facts/SG300-10/show_system.txt new file mode 100644 index 0000000..410f06d --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10/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/show_version.txt b/test/unit/mocked_data/test_get_facts/SG300-10/show_version.txt new file mode 100644 index 0000000..34c1bcf --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG300-10/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/SG350X-48P-K9-twisted_inventory/expected_result.json b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/expected_result.json new file mode 100644 index 0000000..ffbbba5 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/expected_result.json @@ -0,0 +1,71 @@ +{ + "fqdn" : "switch1.", + "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-twisted_inventory/show_hosts.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_hosts.txt new file mode 100644 index 0000000..438eec4 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_hosts.txt @@ -0,0 +1,33 @@ + +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 +-------------------------------------------- ------- --------- ---------- +Domain name is not configured + + +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/SG350X-48P-K9-twisted_inventory/show_interface_status.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_interface_status.txt new file mode 100644 index 0000000..d37ffe1 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/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-twisted_inventory/show_inventory.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_inventory.txt new file mode 100644 index 0000000..c9c82f5 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_inventory.txt @@ -0,0 +1,16 @@ + +NAME: "TengigabitEthernet1/0/1" DESCR: "SFP-1000Base-LX" +PID: GLC-LH-SMD VID: V01 SN: IAB8888888 + + +NAME: "1" DESCR: "SG350X-48P 48-Port Gigabit PoE Stackable Managed Switch" +PID: SG350X-48P-K9 VID: V04 SN: AAA00000BBB + + +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-twisted_inventory/show_system.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_system.txt new file mode 100644 index 0000000..976f6c5 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/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-twisted_inventory/show_version.txt b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/show_version.txt new file mode 100644 index 0000000..6433144 --- /dev/null +++ b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9-twisted_inventory/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/expected_result.json b/test/unit/mocked_data/test_get_facts/SG350X-48P-K9/expected_result.json index 97fa3e3..ffbbba5 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 @@ -63,9 +63,9 @@ "Po7", "Po8" ], - "model" : "SG350X-48P 48-Port Gigabit PoE Stackable Managed Switch", + "model" : "SG350X-48P-K9", "os_version" : "2.4.5.71", - "serial_number" : "AAA00000BBB ", + "serial_number" : "AAA00000BBB", "uptime" : 1232968, "vendor" : "Cisco" } diff --git a/test/unit/mocked_data/test_get_interfaces/SG300-10/expected_result.json b/test/unit/mocked_data/test_get_interfaces/SG300-10/expected_result.json new file mode 100644 index 0000000..24cd62c --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces/SG300-10/expected_result.json @@ -0,0 +1,92 @@ +{ + "gi1": { + "description": "test1", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi10": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi2": { + "description": "test2", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi3": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi4": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi5": { + "description": "test5", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi6": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + }, + "gi7": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 1000 + }, + "gi8": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 1000 + }, + "gi9": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1.0, + "mac_address": "50:F7:22:AA:BB:CC", + "mtu": 1518, + "speed": 0 + } +} diff --git a/test/unit/mocked_data/test_get_interfaces/SG300-10/show_interfaces_description.txt b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_interfaces_description.txt new file mode 100644 index 0000000..4919a57 --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_interfaces_description.txt @@ -0,0 +1,23 @@ +Port Description +------- ----------- +gi1 test1 +gi2 test2 +gi3 +gi4 +gi5 test5 +gi6 +gi7 +gi8 +gi9 +gi10 + +Ch Description +------- ----------- +Po1 +Po2 +Po3 +Po4 +Po5 +Po6 +Po7 +Po8 diff --git a/test/unit/mocked_data/test_get_interfaces/SG300-10/show_interfaces_status.txt b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_interfaces_status.txt new file mode 100644 index 0000000..8f9b9a9 --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_interfaces_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_interfaces/SG300-10/show_lldp_local_gi1.txt b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_lldp_local_gi1.txt new file mode 100644 index 0000000..4ae9b8e --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_lldp_local_gi1.txt @@ -0,0 +1,19 @@ + +Device ID: 50:f7:22:aa:bb:cc +Port ID: gi1 +Capabilities: Bridge +System Name: switchaabbcc + +802.3 EEE: + +17 +17 +17 +17 + + +802.1 PVID: 1 +802.1 PPVID: +802.1 VLAN: +802.1 Protocol: + diff --git a/test/unit/mocked_data/test_get_interfaces/SG300-10/show_ports_jumbo_frame.txt b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_ports_jumbo_frame.txt new file mode 100644 index 0000000..4aafdc0 --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces/SG300-10/show_ports_jumbo_frame.txt @@ -0,0 +1,3 @@ + + Jumbo frames are disabled + Jumbo frames will be disabled after reset diff --git a/test/unit/mocked_data/test_get_interfaces_ip/SG300-10/expected_result.json b/test/unit/mocked_data/test_get_interfaces_ip/SG300-10/expected_result.json new file mode 100644 index 0000000..143a01d --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces_ip/SG300-10/expected_result.json @@ -0,0 +1 @@ +{ "vlan 1" : { "ipv4" : { "192.168.1.254" : { "prefix_length" : 24 } } } } diff --git a/test/unit/mocked_data/test_get_interfaces_ip/SG300-10/show_ip_int.txt b/test/unit/mocked_data/test_get_interfaces_ip/SG300-10/show_ip_int.txt new file mode 100644 index 0000000..a5856f3 --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces_ip/SG300-10/show_ip_int.txt @@ -0,0 +1,14 @@ + + + IP Address I/F I/F Status Type Redirect Status + admin/oper +------------------ --------- ---------- ------- -------- ------ +0.0.0.0/32 vlan 1 UP/UP DHCP enable Not + receiv + ed +192.168.1.254/24 vlan 1 UP/UP Default enable Valid + + + Gateway IP Address Activity status Type +----------------------- ----------------------- -------- + diff --git a/test/unit/mocked_data/test_get_interfaces_ip/SG350X-48P-K9/expected_result.json b/test/unit/mocked_data/test_get_interfaces_ip/SG350X-48P-K9/expected_result.json index 749b0a4..49ac0f8 100644 --- a/test/unit/mocked_data/test_get_interfaces_ip/SG350X-48P-K9/expected_result.json +++ b/test/unit/mocked_data/test_get_interfaces_ip/SG350X-48P-K9/expected_result.json @@ -1 +1,4 @@ -{"vlan": {"ipv4": {"198.51.100.2": {"prefix_length": 24}}}} +{ + "vlan 1" : { "ipv4" : { "198.51.100.2" : { "prefix_length" : 24 } } }, + "vlan 852" : { "ipv4" : { "198.51.100.1" : { "prefix_length" : 16 } } } +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10-long_portid/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10-long_portid/expected_result.json new file mode 100644 index 0000000..b3849df --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10-long_portid/expected_result.json @@ -0,0 +1,14 @@ +{ + "gi7": [ + { + "hostname": "switchcffeedd", + "port": "gi8" + } + ], + "gi8": [ + { + "hostname": "test-pc1", + "port": "9c:eb:e8:c3:b2:a1" + } + ] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10-long_portid/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10-long_portid/show_lldp_neighbors.txt new file mode 100644 index 0000000..31fc656 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10-long_portid/show_lldp_neighbors.txt @@ -0,0 +1,11 @@ + +System capability legend: +B - Bridge; R - Router; W - Wlan Access Point; T - telephone; +D - DOCSIS Cable Device; H - Host; r - Repeater; +TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other + + Port Device ID Port ID System Name Capabilities TTL +--------- ----------------- ------------- ----------------- ------------ ----- +gi7 00:a5:bf:ff:ee:dd gi8 switchcffeedd B, R 96 +gi8 f2:18:98:aa:bb:cc 9c:eb:e8:c3:b test-pc1 B, W 118 + 2:a1 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10/expected_result.json new file mode 100644 index 0000000..707e144 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10/expected_result.json @@ -0,0 +1,14 @@ +{ + "gi7": [ + { + "hostname": "switchcffeedd", + "port": "gi8" + } + ], + "gi8": [ + { + "hostname": "test-pc1", + "port": "en1" + } + ] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10/show_lldp_neighbors.txt new file mode 100644 index 0000000..355152c --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG300-10/show_lldp_neighbors.txt @@ -0,0 +1,10 @@ + +System capability legend: +B - Bridge; R - Router; W - Wlan Access Point; T - telephone; +D - DOCSIS Cable Device; H - Host; r - Repeater; +TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other + + Port Device ID Port ID System Name Capabilities TTL +--------- ----------------- ------------- ----------------- ------------ ----- +gi7 00:a5:bf:ff:ee:dd gi8 switchcffeedd B, R 96 +gi8 f2:18:98:aa:bb:cc en1 test-pc1 B, W 118 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9-long_systemname/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9-long_systemname/expected_result.json index 942f033..591a9c5 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9-long_systemname/expected_result.json +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9-long_systemname/expected_result.json @@ -4,7 +4,7 @@ "port" : "74:ac:aa:ff:1a:5f" } ], "gi1/0/35" : [ { - "hostname" : "O", + "hostname" : "", "port" : "34:e6:aa:ff:53:a8" } ], "te1/0/1" : [ { diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json index 51fea79..34b31f9 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json @@ -4,7 +4,7 @@ "port" : "74:ac:aa:ff:1a:5f" } ], "gi1/0/35" : [ { - "hostname" : "O", + "hostname" : "", "port" : "34:e6:aa:ff:53:a8" } ], "te1/0/1" : [ { diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_and_sysname/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_and_sysname/expected_result.json new file mode 100644 index 0000000..5683619 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_and_sysname/expected_result.json @@ -0,0 +1,10 @@ +{ + "gi7" : [ { + "hostname" : "switchc23cf0", + "port" : "gi8" + } ], + "gi8" : [ { + "hostname" : "iai-sti0067.example.net", + "port" : "9c:eb:e8:52:bd:7c" + } ] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_and_sysname/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_and_sysname/show_lldp_neighbors.txt new file mode 100644 index 0000000..7da8dbe --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_and_sysname/show_lldp_neighbors.txt @@ -0,0 +1,12 @@ + +System capability legend: +B - Bridge; R - Router; W - Wlan Access Point; T - telephone; +D - DOCSIS Cable Device; H - Host; r - Repeater; +TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other + + Port Device ID Port ID System Name Capabilities TTL +--------- ----------------- ------------- ----------------- ------------ ----- +gi7 00:a5:bf:c2:3c:f0 gi8 switchc23cf0 B, R 91 +gi8 f2:18:98:43:be:9b 9c:eb:e8:52:b iai-sti0067.examp B, W 115 + d:7c le.net + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_id/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_id/expected_result.json new file mode 100644 index 0000000..8df5b44 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_id/expected_result.json @@ -0,0 +1 @@ +{"gi7": [{"hostname": "switchc23cf0", "port": "gi8"}], "gi8": [{"hostname": "iai-sti006", "port": "9c:eb:e8:52:bd:7c"}]} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_id/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_id/show_lldp_neighbors.txt new file mode 100644 index 0000000..cc12440 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG3xx-long_port_id/show_lldp_neighbors.txt @@ -0,0 +1,12 @@ + +System capability legend: +B - Bridge; R - Router; W - Wlan Access Point; T - telephone; +D - DOCSIS Cable Device; H - Host; r - Repeater; +TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other + + Port Device ID Port ID System Name Capabilities TTL +--------- ----------------- ------------- ----------------- ------------ ----- +gi7 00:a5:bf:c2:3c:f0 gi8 switchc23cf0 B, R 91 +gi8 f2:18:98:43:be:9b 9c:eb:e8:52:b iai-sti006 B, W 115 + d:7c + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/expected_result.json new file mode 100644 index 0000000..eae9be1 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/expected_result.json @@ -0,0 +1,20 @@ +{ + "gi7": [ + { + "parent_interface": "N/A", + "remote_chassis_id": "00:a5:bf:ff:ee:dd", + "remote_port": "gi8", + "remote_port_description": "", + "remote_system_capab": [ + "B", + "R" + ], + "remote_system_description": "", + "remote_system_enable_capab": [ + "B", + "R" + ], + "remote_system_name": "switchcffeedd" + } + ] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/show_lldp_neighbors.txt new file mode 100644 index 0000000..e62ef21 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/show_lldp_neighbors.txt @@ -0,0 +1,9 @@ + +System capability legend: +B - Bridge; R - Router; W - Wlan Access Point; T - telephone; +D - DOCSIS Cable Device; H - Host; r - Repeater; +TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other + + Port Device ID Port ID System Name Capabilities TTL +--------- ----------------- ------------- ----------------- ------------ ----- +gi7 00:a5:bf:ff:ee:dd gi8 switchcffeedd B, R 96 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/show_lldp_neighbors_gi7.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/show_lldp_neighbors_gi7.txt new file mode 100644 index 0000000..a62ba0b --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/SG300-10/show_lldp_neighbors_gi7.txt @@ -0,0 +1,27 @@ + +Device ID: 00:a5:bf:ff:ee:dd +Port ID: gi8 +Capabilities: Bridge, Router +System Name: switchcffeedd +System description: +Port description: +Management Address: 192.168.1.253 +Management Address: 254.128.0.0.0.0 +Time To Live: 118 + + +802.3 EEE: + +17 +17 +17 +17 + + +802.1 PVID: 1 +802.1 PPVID: +802.1 VLAN: +802.1 Protocol: + + + diff --git a/test/unit/mocked_data/test_get_ntp_servers/SG300-10/expected_result.json b/test/unit/mocked_data/test_get_ntp_servers/SG300-10/expected_result.json new file mode 100644 index 0000000..fcf38c1 --- /dev/null +++ b/test/unit/mocked_data/test_get_ntp_servers/SG300-10/expected_result.json @@ -0,0 +1,3 @@ +{ + "1.2.3.4": {} +} diff --git a/test/unit/mocked_data/test_get_ntp_servers/SG300-10/show_sntp_status.txt b/test/unit/mocked_data/test_get_ntp_servers/SG300-10/show_sntp_status.txt new file mode 100644 index 0000000..39e82cd --- /dev/null +++ b/test/unit/mocked_data/test_get_ntp_servers/SG300-10/show_sntp_status.txt @@ -0,0 +1,22 @@ + +Clock is unsynchronized + +Unicast servers: + +Server : 1.2.3.4 + Source : Static + Stratum : 255 + Status : unknown + Last Response : 00:00:00.0 Jan 1 1900 + Offset : 0.0000000 mSec + Delay : 0 mSec + + + +Anycast server: + + + +Broadcast: + +