mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
edgeswitch_facts (#47618)
This commit is contained in:
0
test/units/modules/network/edgeswitch/__init__.py
Normal file
0
test/units/modules/network/edgeswitch/__init__.py
Normal file
86
test/units/modules/network/edgeswitch/edgeswitch_module.py
Normal file
86
test/units/modules/network/edgeswitch/edgeswitch_module.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# (c) 2018 Red Hat 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 units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
|
||||
|
||||
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
if path in fixture_data:
|
||||
return fixture_data[path]
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
|
||||
try:
|
||||
data = json.loads(data)
|
||||
except:
|
||||
pass
|
||||
|
||||
fixture_data[path] = data
|
||||
return data
|
||||
|
||||
|
||||
class TestEdgeswitchModule(ModuleTestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
self.load_fixtures(commands)
|
||||
|
||||
if failed:
|
||||
result = self.failed()
|
||||
self.assertTrue(result['failed'], result)
|
||||
else:
|
||||
result = self.changed(changed)
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
|
||||
if commands is not None:
|
||||
if sort:
|
||||
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
|
||||
else:
|
||||
self.assertEqual(commands, result['commands'], result['commands'])
|
||||
|
||||
return result
|
||||
|
||||
def failed(self):
|
||||
with self.assertRaises(AnsibleFailJson) as exc:
|
||||
self.module.main()
|
||||
|
||||
result = exc.exception.args[0]
|
||||
self.assertTrue(result['failed'], result)
|
||||
return result
|
||||
|
||||
def changed(self, changed=False):
|
||||
with self.assertRaises(AnsibleExitJson) as exc:
|
||||
self.module.main()
|
||||
|
||||
result = exc.exception.args[0]
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
return result
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
||||
@@ -0,0 +1,26 @@
|
||||
Interface Admin Link Description
|
||||
--------- --------- ------ ----------------------------------------------------------------
|
||||
0/1 Enable Up VMOTION ESX1
|
||||
0/2 Enable Up DATA ESX1
|
||||
0/3 Enable Up VMOTION ESX2
|
||||
0/4 Enable Up DATA ESX2
|
||||
0/5 Enable Up VMOTION ESX3
|
||||
0/6 Enable Up DATA ESX3
|
||||
0/7 Enable Up VMOTION ESX4
|
||||
0/8 Enable Up DATA ESX4
|
||||
0/9 Enable Up SAVE
|
||||
0/10 Enable Down
|
||||
0/11 Enable Down
|
||||
0/12 Enable Down
|
||||
0/13 Enable Down
|
||||
0/14 Enable Down
|
||||
0/15 Enable Up UPLINK VIDEO WITH A VERY LONG DESCRIPTION THAT HELPS NO ONE
|
||||
0/16 Enable Up UPLINK LOCAL
|
||||
3/1 Enable Down
|
||||
3/2 Enable Down
|
||||
3/3 Enable Down
|
||||
3/4 Enable Down
|
||||
3/5 Enable Down
|
||||
3/6 Enable Down
|
||||
4/1 Enable Up
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
Link Physical Physical Media Flow Control
|
||||
Port Name State Mode Status Type Status
|
||||
--------- ---------------------------- ------ ---------- ---------- ------------------ ------------
|
||||
0/1 VMOTION ESX1 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/2 DATA ESX1 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/3 VMOTION ESX2 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/4 DATA ESX2 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/5 VMOTION ESX3 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/6 DATA ESX3 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/7 VMOTION ESX4 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/8 DATA ESX4 Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/9 SAVE Up Auto D 10G Full 2.5G-BaseFX Inactive
|
||||
0/10 Down Auto D 2.5G-BaseFX Inactive
|
||||
0/11 Down Auto D 2.5G-BaseFX Inactive
|
||||
0/12 Down Auto D 2.5G-BaseFX Inactive
|
||||
0/13 Down Auto D 2.5G-BaseFX Inactive
|
||||
0/14 Down Auto Unknown Inactive
|
||||
0/15 Down Auto Unknown Inactive
|
||||
0/15 UPLINK VIDEO WITH A VERY LON Up Auto 1000 Full Unknown Inactive
|
||||
0/16 UPLINK LOCAL Up Auto 1000 Full Unknown Inactive
|
||||
3/1 Down
|
||||
3/2 Down
|
||||
3/3 Down
|
||||
3/4 Down
|
||||
3/5 Down
|
||||
3/6 Down
|
||||
4/1 Up 10 Half 10 Half
|
||||
|
||||
Flow Control:Disabled
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
System Description............................. EdgeSwitch 16-Port 10G, 1.7.4.5075842, Linux 3.6.5, 1.0.0.4872137
|
||||
System Name.................................... sw_test_1
|
||||
System Location................................
|
||||
System Contact.................................
|
||||
System Object ID............................... 1.3.6.1.4.1.4413
|
||||
System Up Time................................. 174 days 19 hrs 0 mins 51 secs
|
||||
Current SNTP Synchronized Time................. Oct 20 22:53:01 2018 UTC
|
||||
@@ -0,0 +1,8 @@
|
||||
Switch: 1
|
||||
|
||||
System Description............................. EdgeSwitch 16-Port 10G, 1.7.4.5075842, Linux 3.6.5, 1.0.0.4872137
|
||||
Machine Type................................... EdgeSwitch 16-Port 10G
|
||||
Machine Model.................................. ES-16-XG
|
||||
Serial Number.................................. F09FC2EFD310
|
||||
Burned In MAC Address.......................... F0:9F:C2:EF:D3:10
|
||||
Software Version............................... 1.7.4.5075842
|
||||
@@ -0,0 +1,73 @@
|
||||
# (c) 2018 Red Hat 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 json
|
||||
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.edgeswitch import edgeswitch_facts
|
||||
from units.modules.utils import set_module_args
|
||||
from .edgeswitch_module import TestEdgeswitchModule, load_fixture
|
||||
|
||||
|
||||
class TestEdgeswitchFactsModule(TestEdgeswitchModule):
|
||||
|
||||
module = edgeswitch_facts
|
||||
|
||||
def setUp(self):
|
||||
super(TestEdgeswitchFactsModule, self).setUp()
|
||||
self.mock_run_commands = patch('ansible.modules.network.edgeswitch.edgeswitch_facts.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestEdgeswitchFactsModule, self).tearDown()
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module = args
|
||||
commands = kwargs['commands']
|
||||
output = list()
|
||||
|
||||
for command in commands:
|
||||
filename = str(command).split(' | ')[0].replace(' ', '_')
|
||||
output.append(load_fixture('edgeswitch_facts_%s' % filename))
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_edgeswitch_facts_default(self):
|
||||
set_module_args(dict(gather_subset=['all', '!interfaces', '!config']))
|
||||
result = self.execute_module()
|
||||
facts = result.get('ansible_facts')
|
||||
self.assertEqual(len(facts), 5)
|
||||
self.assertEqual(facts['ansible_net_hostname'], 'sw_test_1')
|
||||
self.assertEqual(facts['ansible_net_serialnum'], 'F09FC2EFD310')
|
||||
self.assertEqual(facts['ansible_net_version'], '1.7.4.5075842')
|
||||
|
||||
def test_edgeswitch_facts_interfaces(self):
|
||||
set_module_args(dict(gather_subset='interfaces'))
|
||||
result = self.execute_module()
|
||||
facts = result.get('ansible_facts')
|
||||
self.assertEqual(len(facts), 6)
|
||||
self.assertEqual(facts['ansible_net_interfaces']['0/1']['operstatus'], 'Enable')
|
||||
self.assertEqual(facts['ansible_net_interfaces']['0/2']['mediatype'], '2.5G-BaseFX')
|
||||
self.assertEqual(facts['ansible_net_interfaces']['0/3']['physicalstatus'], '10G Full')
|
||||
self.assertEqual(facts['ansible_net_interfaces']['0/4']['lineprotocol'], 'Up')
|
||||
self.assertEqual(facts['ansible_net_interfaces']['0/15']['description'], 'UPLINK VIDEO WITH A VERY LONG DESCRIPTION THAT HELPS NO ONE')
|
||||
Reference in New Issue
Block a user