mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
network/exos: add exos_facts module (#43210)
Add exos_facts module. Known limitations at this time include: - Interface MTU is not reported. - Only primary interface IP is reported. Add basic unit tests for the exos_facts module. An EXOS CLI prompt can be prefixed with '! ' (shutting down), '* ' (running configuration does not match saved configuration), and can include various status tokens within parentheses after these prefixes. Update prompt regex to accept valid CLI prompts.
This commit is contained in:
committed by
Ricardo Carrillo Cruz
parent
e24c036057
commit
bd4d68c785
@@ -0,0 +1 @@
|
||||
[{"CLIoutput": "\n Neighbor Neighbor Neighbor\nPort Chassis ID Port ID TTL Age System Name\n===============================================================================\n1 00:02:02:02:02:02 1 120 26 EXOS-VM\n2 00:02:02:02:02:02 2 120 25 EXOS-VM\n3 00:02:02:02:02:02 3 120 25 EXOS-VM\n===============================================================================\nNOTE: The Chassis ID and/or Port ID might be truncated to fit the screen.\n\n"}, {"lldpPortNbrInfoShort": {"age": 26, "lastUpdate": 8412, "nbrChassisID": "00:02:02:02:02:02", "nbrChassisIdType": 4, "nbrIndex": 1, "nbrPortDescr": "Not-Advertised", "nbrPortID": 1, "nbrPortIdType": 5, "nbrSysDescr": "ExtremeXOS (EXOS-VM) version 30.1.0.27 xos_30.1 by lrichardson on Mon Apr 30 13:38:10 EDT 2018", "nbrSysName": "EXOS-VM", "nbrsOnThisPort": 1, "port": 1, "ttl": 120}, "status": "MORE"}, {"lldpPortNbrInfoShort": {"age": 25, "lastUpdate": 8412, "nbrChassisID": "00:02:02:02:02:02", "nbrChassisIdType": 4, "nbrIndex": 1, "nbrPortDescr": "Not-Advertised", "nbrPortID": 2, "nbrPortIdType": 5, "nbrSysDescr": "ExtremeXOS (EXOS-VM) version 30.1.0.27 xos_30.1 by lrichardson on Mon Apr 30 13:38:10 EDT 2018", "nbrSysName": "EXOS-VM", "nbrsOnThisPort": 1, "port": 2, "ttl": 120}, "status": "MORE"}, {"lldpPortNbrInfoShort": {"age": 25, "lastUpdate": 8417, "nbrChassisID": "00:02:02:02:02:02", "nbrChassisIdType": 4, "nbrIndex": 1, "nbrPortDescr": "Not-Advertised", "nbrPortID": 3, "nbrPortIdType": 5, "nbrSysDescr": "ExtremeXOS (EXOS-VM) version 30.1.0.27 xos_30.1 by lrichardson on Mon Apr 30 13:38:10 EDT 2018", "nbrSysName": "EXOS-VM", "nbrsOnThisPort": 1, "port": 3, "ttl": 120}, "status": "MORE"}, {"status": "SUCCESS"}]
|
||||
@@ -0,0 +1 @@
|
||||
[{"CLIoutput": "Port Configuration\nPort Virtual Port Link Auto Speed Duplex Flow Load Media\n router State State Neg Cfg Actual Cfg Actual Cntrl Master Pri Red\n================================================================================\n1 VR-Default E R OFF 25000 FULL NONE \n2 VR-Default E R OFF 25000 FULL NONE \n3 VR-Default E R OFF 25000 FULL NONE \n4 VR-Default E R OFF 25000 FULL NONE \n================================================================================\n> indicates Port Display Name truncated past 8 characters\nLink State: A-Active, R-Ready, NP-Port Not Present, L-Loopback\nPort State: D-Disabled, E-Enabled, L-License Disabled\nMedia: !-Unsupported, $-Unlicensed\nMedia Red: * - use \"show port info detail\" for redundant media type\nFlow Cntrl: Shows link partner's abilities. NONE if Auto Neg is OFF\n"}, {"show_ports_config": {"duplexActual": null, "duplexCfg": "FULL", "flowControl": null, "isAutoNegOn": 0, "licenseDisable": 0, "linkState": 0, "port": 1, "portList": "1-4", "portState": 1, "primaryMedia": " NONE", "speedActual": null, "speedCfg": 25000, "vrName": "VR-Default"}, "status": "MORE"}, {"show_ports_config": {"duplexActual": null, "duplexCfg": "FULL", "flowControl": null, "isAutoNegOn": 0, "licenseDisable": 0, "linkState": 0, "port": 2, "portList": "1-4", "portState": 1, "primaryMedia": " NONE", "speedActual": null, "speedCfg": 25000, "vrName": "VR-Default"}, "status": "MORE"}, {"show_ports_config": {"duplexActual": null, "duplexCfg": "FULL", "flowControl": null, "isAutoNegOn": 0, "licenseDisable": 0, "linkState": 0, "port": 3, "portList": "1-4", "portState": 1, "primaryMedia": " NONE", "speedActual": null, "speedCfg": 25000, "vrName": "VR-Default"}, "status": "MORE"}, {"show_ports_config": {"duplexActual": null, "duplexCfg": "FULL", "flowControl": null, "isAutoNegOn": 0, "licenseDisable": 0, "linkState": 0, "port": 4, "portList": "1-4", "portState": 1, "primaryMedia": " NONE", "speedActual": null, "speedCfg": 25000, "vrName": "VR-Default"}, "status": "SUCCESS"}]
|
||||
@@ -0,0 +1,2 @@
|
||||
[{"CLIoutput": "Port Display String Description String \n===== ==================== ==================================================\n1 Firewall\n2 \n3 Database Server\n4 \n===== ==================== ==================================================\n"}, {"show_ports_description": {"descriptionString": "Firewall", "port": 1, "portList": "1-4"}, "status": "MORE"}, {"show_ports_description": {"port": 2, "portList": "1-4"}, "status": "MORE"}, {"show_ports_description": {"descriptionString": "Database Server", "port": 3, "portList": "1-4"}, "status": "MORE"}, {"show_ports_description": {"port": 4, "portList": "1-4"}, "status": "SUCCESS"}]
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
95
test/units/modules/network/exos/fixtures/show_memory
Normal file
95
test/units/modules/network/exos/fixtures/show_memory
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
System Memory Information
|
||||
-------------------------
|
||||
Total DRAM (KB): 8388608
|
||||
System (KB): 357088
|
||||
User (KB): 558460
|
||||
Free (KB): 7473060
|
||||
|
||||
Memory Utilization Statistics
|
||||
-----------------------------
|
||||
|
||||
Process Name Memory (KB)
|
||||
-----------------------------
|
||||
aaa 2212
|
||||
acl 1637
|
||||
bfd 1158
|
||||
bgp 10031
|
||||
brm 822
|
||||
cfgmgr 2466
|
||||
cli 16169
|
||||
devmgr 884
|
||||
dirser 463
|
||||
dosprotect 570
|
||||
dot1ag 1370
|
||||
eaps 1359
|
||||
edp 1260
|
||||
elrp 1250
|
||||
elsm 917
|
||||
ems 3196
|
||||
epm 1646
|
||||
erps 1282
|
||||
esrp 1101
|
||||
ethoam 858
|
||||
etmon 7865
|
||||
exacl 0
|
||||
exdhcpsnoop 0
|
||||
exdos 0
|
||||
exfib 0
|
||||
exnasnoop 0
|
||||
exosmc 0
|
||||
exosq 0
|
||||
expolicy 0
|
||||
exsflow 0
|
||||
exsnoop 0
|
||||
exsshd 1522
|
||||
exvlan 0
|
||||
fdb 1990
|
||||
hal 141451
|
||||
hclag 899
|
||||
idMgr 3448
|
||||
ipSecurity 1042
|
||||
ipfix 956
|
||||
isis 1403
|
||||
ismb 0
|
||||
lacp 1306
|
||||
lldp 1724
|
||||
mcmgr 2183
|
||||
mpls 0
|
||||
mrp 1482
|
||||
msdp 915
|
||||
netLogin 1641
|
||||
netTools 4336
|
||||
nettx 0
|
||||
nodealias 1847
|
||||
nodemgr 501
|
||||
ntp 812
|
||||
openflow 0
|
||||
ospf 1455
|
||||
ospfv3 5130
|
||||
otm 1095
|
||||
ovsdb 8206
|
||||
pim 2100
|
||||
polMgr 479
|
||||
policy 45998
|
||||
pwmib 458
|
||||
rip 1000
|
||||
ripng 739
|
||||
rtmgr 2679
|
||||
snmpMaster 2798
|
||||
snmpSubagent 5728
|
||||
stp 2020
|
||||
techSupport 681
|
||||
telnetd 890
|
||||
tftpd 336
|
||||
throw 5262
|
||||
thttpd 8944
|
||||
twamp 471
|
||||
upm 859
|
||||
vlan 3215
|
||||
vmt 1599
|
||||
vpex 1771
|
||||
vrrp 1185
|
||||
vsm 1486
|
||||
xmlc 1013
|
||||
xmld 3468
|
||||
33
test/units/modules/network/exos/fixtures/show_switch
Normal file
33
test/units/modules/network/exos/fixtures/show_switch
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
SysName: X870-32c
|
||||
SysLocation:
|
||||
SysContact: support@extremenetworks.com, +1 888 257 3000
|
||||
System MAC: 00:04:96:9A:B4:F7
|
||||
System Type: X870-32c
|
||||
|
||||
SysHealth check: Enabled (Normal)
|
||||
Recovery Mode: All
|
||||
System Watchdog: Enabled
|
||||
|
||||
Current Time: Wed Jul 18 12:44:49 2018
|
||||
Timezone: [Auto DST Disabled] GMT Offset: 0 minutes, name is UTC.
|
||||
Boot Time: Tue Jul 17 12:49:58 2018
|
||||
Boot Count: 4970
|
||||
Next Reboot: None scheduled
|
||||
System UpTime: 23 hours 54 minutes 50 seconds
|
||||
|
||||
Current State: OPERATIONAL
|
||||
Image Selected: secondary
|
||||
Image Booted: secondary
|
||||
Primary ver: 30.1.0.37
|
||||
Secondary ver: 22.5.1.7
|
||||
|
||||
Config Selected: primary.cfg
|
||||
Config Booted: primary.cfg
|
||||
Config Automatic: NONE (Disabled)
|
||||
|
||||
primary.cfg Created by ExtremeXOS version 22.6.0.11
|
||||
983139 bytes saved on Wed Jun 6 16:59:49 2018
|
||||
|
||||
LAA MAC: Locally Administered MAC Address Disabled
|
||||
|
||||
111
test/units/modules/network/exos/test_exos_facts.py
Normal file
111
test/units/modules/network/exos/test_exos_facts.py
Normal file
@@ -0,0 +1,111 @@
|
||||
#
|
||||
# (c) 2018 Extreme Networks Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.exos import exos_facts
|
||||
from units.modules.utils import set_module_args
|
||||
from .exos_module import TestExosModule, load_fixture
|
||||
|
||||
|
||||
class TestExosFactsModule(TestExosModule):
|
||||
|
||||
module = exos_facts
|
||||
|
||||
def setUp(self):
|
||||
super(TestExosFactsModule, self).setUp()
|
||||
|
||||
self.mock_run_commands = patch('ansible.modules.network.exos.exos_facts.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestExosFactsModule, self).tearDown()
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
|
||||
def load_from_file(*args, **kwargs):
|
||||
module, commands = args
|
||||
output = list()
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
|
||||
for command in commands:
|
||||
filename = str(command).replace(' ', '_')
|
||||
filename = os.path.join(fixture_path, filename)
|
||||
with open(filename) as f:
|
||||
data = f.read()
|
||||
output.append(data)
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_exos_facts_default(self):
|
||||
set_module_args(dict(gather_subset='default'))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_model'], 'X870-32c'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_serialnum'], '1604G-00175'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_version'], '22.5.1.7'
|
||||
)
|
||||
|
||||
def test_exos_facts_hardware(self):
|
||||
set_module_args(dict(gather_subset='hardware'))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_memfree_mb'], 7298
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_memtotal_mb'], 8192
|
||||
)
|
||||
|
||||
def test_exos_facts_interfaces(self):
|
||||
set_module_args(dict(gather_subset='interfaces'))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['1']['bandwidth_configured'], '25000'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['3']['description'], 'Database Server'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['3']['type'], 'Ethernet'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['vlan1']['ipv4'][0]['address'], '10.0.1.1'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['vlan3']['ipv6'][0]['address'], 'fe80::202:b3ff:fe1e:8329'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_all_ipv4_addresses'], ['10.0.1.1', '192.168.1.1']
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_all_ipv6_addresses'], ['fe80::202:b3ff:fe1e:8329']
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['vlan3']['type'], 'VLAN'
|
||||
)
|
||||
Reference in New Issue
Block a user