2018-01-08 14:29:16 +00:00
|
|
|
#
|
|
|
|
# Copyright: Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
from ansible.compat.tests.mock import patch
|
|
|
|
from units.modules.utils import set_module_args
|
2018-01-11 22:21:17 +00:00
|
|
|
from .onyx_module import TestOnyxModule, load_fixture
|
|
|
|
from ansible.modules.network.onyx import onyx_facts
|
2018-01-08 14:29:16 +00:00
|
|
|
|
|
|
|
|
2018-01-11 22:21:17 +00:00
|
|
|
class TestOnyxFacts(TestOnyxModule):
|
2018-01-08 14:29:16 +00:00
|
|
|
|
2018-01-11 22:21:17 +00:00
|
|
|
module = onyx_facts
|
2018-01-08 14:29:16 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2018-01-11 22:21:17 +00:00
|
|
|
super(TestOnyxFacts, self).setUp()
|
2018-01-08 14:29:16 +00:00
|
|
|
|
|
|
|
self.mock_run_command = patch.object(
|
2018-01-11 22:21:17 +00:00
|
|
|
onyx_facts.FactsBase, "_show_cmd")
|
2018-01-08 14:29:16 +00:00
|
|
|
self.run_command = self.mock_run_command.start()
|
|
|
|
|
|
|
|
def tearDown(self):
|
2018-01-11 22:21:17 +00:00
|
|
|
super(TestOnyxFacts, self).tearDown()
|
2018-01-08 14:29:16 +00:00
|
|
|
|
|
|
|
self.mock_run_command.stop()
|
|
|
|
|
|
|
|
def load_fixtures(self, commands=None, transport=None):
|
|
|
|
|
|
|
|
def load_from_file(*args, **kwargs):
|
|
|
|
command = args[0]
|
2018-01-11 22:21:17 +00:00
|
|
|
filename = "onyx_facts_%s.cfg" % command
|
2018-01-08 14:29:16 +00:00
|
|
|
filename = filename.replace(' ', '_')
|
|
|
|
filename = filename.replace('/', '7')
|
|
|
|
output = load_fixture(filename)
|
|
|
|
return output
|
|
|
|
|
|
|
|
self.run_command.side_effect = load_from_file
|
|
|
|
|
2018-01-11 22:21:17 +00:00
|
|
|
def test_onyx_facts_version(self):
|
2018-01-08 14:29:16 +00:00
|
|
|
set_module_args(dict(gather_subset='version'))
|
|
|
|
result = self.execute_module()
|
|
|
|
facts = result.get('ansible_facts')
|
|
|
|
self.assertEqual(len(facts), 2)
|
|
|
|
version = facts['ansible_net_version']
|
|
|
|
self.assertEqual(version['Product name'], 'MLNX-OS')
|
|
|
|
|
2018-01-11 22:21:17 +00:00
|
|
|
def test_onyx_facts_modules(self):
|
2018-01-08 14:29:16 +00:00
|
|
|
set_module_args(dict(gather_subset='modules'))
|
|
|
|
result = self.execute_module()
|
|
|
|
facts = result.get('ansible_facts')
|
|
|
|
self.assertEqual(len(facts), 2)
|
|
|
|
modules = facts['ansible_net_modules']
|
|
|
|
self.assertIn("MGMT", modules)
|
|
|
|
|
2018-01-11 22:21:17 +00:00
|
|
|
def test_onyx_facts_interfaces(self):
|
2018-01-08 14:29:16 +00:00
|
|
|
set_module_args(dict(gather_subset='interfaces'))
|
|
|
|
result = self.execute_module()
|
|
|
|
facts = result.get('ansible_facts')
|
|
|
|
self.assertEqual(len(facts), 2)
|
|
|
|
interfaces = facts['ansible_net_interfaces']
|
|
|
|
self.assertEqual(len(interfaces), 2)
|
|
|
|
|
2018-01-11 22:21:17 +00:00
|
|
|
def test_onyx_facts_all(self):
|
2018-01-08 14:29:16 +00:00
|
|
|
set_module_args(dict(gather_subset='all'))
|
|
|
|
result = self.execute_module()
|
|
|
|
facts = result.get('ansible_facts')
|
|
|
|
self.assertEqual(len(facts), 4)
|