Add platform facts in network facts modules (#51434)

* Add platform facts in network facts modules

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* Add nxos

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* Add vyos

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* Add iosxr

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* Add junos

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix pep8

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* update unit test

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix vyos_facts unittest

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix ios_facts unittest

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix iosxr unittests

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix CI failure

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix junos test

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2019-03-11 10:56:39 +05:30 committed by GitHub
commit a41028244d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 303 additions and 180 deletions

View file

@ -33,9 +33,23 @@ class TestIosFactsModule(TestIosModule):
self.mock_run_commands = patch('ansible.modules.network.ios.ios_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
self.mock_get_capabilities = patch('ansible.modules.network.ios.ios_facts.get_capabilities')
self.get_capabilities = self.mock_get_capabilities.start()
self.get_capabilities.return_value = {
'device_info': {
'network_os': 'ios',
'network_os_hostname': 'an-ios-01',
'network_os_image': 'flash0:/vios-adventerprisek9-m',
'network_os_model': 'WS-C3750-24TS',
'network_os_version': '15.6(3)M2'
},
'network_api': 'cliconf'
}
def tearDown(self):
super(TestIosFactsModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_get_capabilities.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):

View file

@ -38,10 +38,23 @@ class TestIosxrFacts(TestIosxrModule):
'ansible.modules.network.iosxr.iosxr_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
self.mock_get_capabilities = patch('ansible.modules.network.iosxr.iosxr_facts.get_capabilities')
self.get_capabilities = self.mock_get_capabilities.start()
self.get_capabilities.return_value = {
'device_info': {
'network_os': 'iosxr',
'network_os_hostname': 'iosxr01',
'network_os_image': 'bootflash:disk0/xrvr-os-mbi-6.1.3/mbixrvr-rp.vm',
'network_os_version': '6.1.3[Default]'
},
'network_api': 'cliconf'
}
def tearDown(self):
super(TestIosxrFacts, self).tearDown()
self.mock_run_commands.stop()
self.mock_get_capabilities.stop()
def load_fixtures(self, commands=None):

View file

@ -49,9 +49,6 @@ class TestJunosCommandModule(TestJunosModule):
self.mock_get_config = patch('ansible.modules.network.junos.junos_facts.get_configuration')
self.get_config = self.mock_get_config.start()
self.mock_conn = patch('ansible.module_utils.connection.Connection')
self.conn = self.mock_conn.start()
self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection')
self.netconf_conn = self.mock_netconf.start()
@ -61,13 +58,20 @@ class TestJunosCommandModule(TestJunosModule):
self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection')
self.netconf_rpc = self.mock_netconf_rpc.start()
self.mock_get_capabilities = patch('ansible.module_utils.network.junos.junos.get_capabilities')
self.mock_get_capabilities = patch('ansible.modules.network.junos.junos_facts.get_capabilities')
self.get_capabilities = self.mock_get_capabilities.start()
self.get_capabilities.return_value = {'network_api': 'netconf'}
self.get_capabilities.return_value = {
'device_info': {
'network_os': 'junos',
'network_os_hostname': 'vsrx01',
'network_os_model': 'vsrx',
'network_os_version': '17.3R1.10'
},
'network_api': 'netconf'
}
def tearDown(self):
super(TestJunosCommandModule, self).tearDown()
self.mock_conn.stop()
self.mock_netconf.stop()
self.mock_exec_rpc.stop()
self.mock_netconf_rpc.stop()

View file

@ -36,9 +36,22 @@ class TestVyosFactsModule(TestVyosModule):
self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
self.mock_get_capabilities = patch('ansible.modules.network.vyos.vyos_facts.get_capabilities')
self.get_capabilities = self.mock_get_capabilities.start()
self.get_capabilities.return_value = {
'device_info': {
'network_os': 'vyos',
'network_os_hostname': 'vyos01',
'network_os_model': 'VMware',
'network_os_version': 'VyOS 1.1.7'
},
'network_api': 'cliconf'
}
def tearDown(self):
super(TestVyosFactsModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_get_capabilities.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):
@ -61,7 +74,7 @@ class TestVyosFactsModule(TestVyosModule):
set_module_args(dict(gather_subset='default'))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5)
self.assertEqual(len(facts), 8)
self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01')
self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7')
@ -69,7 +82,7 @@ class TestVyosFactsModule(TestVyosModule):
set_module_args(dict(gather_subset='!all'))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5)
self.assertEqual(len(facts), 8)
self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01')
self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7')
@ -77,7 +90,7 @@ class TestVyosFactsModule(TestVyosModule):
set_module_args(dict(gather_subset=['!neighbors', '!config']))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5)
self.assertEqual(len(facts), 8)
self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01')
self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7')