def test_routeros_facts_config(self): set_module_args(dict(gather_subset='config')) result = self.execute_module() self.assertIsInstance(result['ansible_facts']['ansible_net_config'], str)
def test_slxos_config_save_changed_false(self): set_module_args(dict(save_when='changed')) self.execute_module(changed=False) self.assertEqual(self.run_commands.call_count, 0) self.assertEqual(self.get_config.call_count, 0) self.assertEqual(self.load_config.call_count, 0)
def test_nso_config_changed(self, open_url_mock): vpn_schema = nso_module.load_fixture('l3vpn_schema.json') l3vpn_schema = nso_module.load_fixture('l3vpn_l3vpn_schema.json') endpoint_schema = nso_module.load_fixture( 'l3vpn_l3vpn_endpoint_schema.json') changes = nso_module.load_fixture('config_config_changes.json') calls = [ MockResponse('login', {}, 200, '{}', {'set-cookie': 'id'}), MockResponse('get_system_setting', {'operation': 'version'}, 200, '{"result": "4.5.1"}'), MockResponse('get_module_prefix_map', {}, 200, '{"result": {"l3vpn": "l3vpn"}}'), MockResponse('new_trans', {'mode': 'read'}, 200, '{"result": {"th": 1}}'), MockResponse('get_schema', {'path': '/l3vpn:vpn'}, 200, '{"result": %s}' % (json.dumps(vpn_schema, ))), MockResponse('get_schema', {'path': '/l3vpn:vpn/l3vpn'}, 200, '{"result": %s}' % (json.dumps(l3vpn_schema, ))), MockResponse('exists', {'path': '/l3vpn:vpn/l3vpn{company}'}, 200, '{"result": {"exists": true}}'), MockResponse('get_schema', {'path': '/l3vpn:vpn/l3vpn/endpoint'}, 200, '{"result": %s}' % (json.dumps(endpoint_schema, ))), MockResponse( 'exists', {'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}'}, 200, '{"result": {"exists": false}}'), MockResponse('new_trans', {'mode': 'read_write'}, 200, '{"result": {"th": 2}}'), MockResponse( 'create', {'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}'}, 200, '{"result": {}}'), MockResponse( 'set_value', { 'path': '/l3vpn:vpn/l3vpn{company}/route-distinguisher', 'value': 999 }, 200, '{"result": {}}'), MockResponse( 'set_value', { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/as-number', 'value': 65101 }, 200, '{"result": {}}'), MockResponse( 'set_value', { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/bandwidth', 'value': 12000000 }, 200, '{"result": {}}'), MockResponse( 'set_value', { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/ce-device', 'value': 'ce6' }, 200, '{"result": {}}'), MockResponse( 'set_value', { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/ce-interface', 'value': 'GigabitEthernet0/12' }, 200, '{"result": {}}'), MockResponse( 'set_value', { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/ip-network', 'value': '10.10.1.0/24' }, 200, '{"result": {}}'), MockResponse('get_trans_changes', {}, 200, '{"result": %s}' % (json.dumps(changes), )), MockResponse('validate_commit', {}, 200, '{"result": {}}'), MockResponse('commit', {}, 200, '{"result": {}}'), MockResponse('logout', {}, 200, '{"result": {}}'), ] open_url_mock.side_effect = lambda *args, **kwargs: nso_module.mock_call( calls, *args, **kwargs) data = nso_module.load_fixture('config_config.json') set_module_args({ 'username': '******', 'password': '******', 'url': 'http://localhost:8080/jsonrpc', 'data': data, 'validate_certs': False }) self.execute_module( changed=True, changes=[ { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/ce-device', 'type': 'set', 'from': None, 'to': 'ce6' }, { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/ip-network', 'type': 'set', 'from': None, 'to': '10.10.1.0/24' }, { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/as-number', 'type': 'set', 'from': None, 'to': '65101' }, { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/ce-interface', 'type': 'set', 'from': None, 'to': 'GigabitEthernet0/12' }, { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}/bandwidth', 'type': 'set', 'from': None, 'to': '12000000' }, { 'path': '/l3vpn:vpn/l3vpn{company}/endpoint{branch-office1}', 'type': 'create' }, ], diffs=[]) self.assertEqual(0, len(calls))
def test_slxos_config_replace_config_requires_src(self): args = dict(replace='config') set_module_args(args) self.execute_module(failed=True)
def test_slxos_config_src(self): src = load_fixture('slxos_config_src.cfg') set_module_args(dict(src=src)) commands = ['hostname foo', 'interface Ethernet 0/0', 'no ip address'] self.execute_module(changed=True, commands=commands)
def test_slxos_config_match_none_parents(self): lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string'] parents = ['interface Ethernet 0/0'] set_module_args(dict(lines=lines, parents=parents, match='none')) commands = parents + lines self.execute_module(changed=True, commands=commands, sort=False)
def test_slxos_config_match_strict_requires_lines(self): args = dict(match='strict') set_module_args(args) self.execute_module(failed=True)
def test_igmp_version_with_change(self): self.enabled = True set_module_args(dict(vlan_id=10, version='V2')) commands = ['vlan 10 ip igmp snooping version 2'] self.execute_module(changed=True, commands=commands)
def test_igmp_enabled_no_change(self): self.enabled = True set_module_args(dict(state='enabled', vlan_id=10)) self.execute_module(changed=False)
def test_igmp_querier_enabled_with_change(self): self.enabled = True set_module_args(dict(vlan_id=10, querier=dict(state='enabled'))) commands = ['vlan 10 ip igmp snooping querier'] self.execute_module(changed=True, commands=commands)
def test_igmp_version_no_change(self): self.enabled = True set_module_args(dict(vlan_id=10, version='V3')) self.execute_module(changed=False)
def test_igmp_querier_enabled_no_change(self): self.enabled = True self.querier_state = True set_module_args(dict(vlan_id=10, querier=dict(state='enabled'))) self.execute_module(changed=False)
def test_igmp_mrouter_enabled_with_change(self): self.enabled = True set_module_args( dict(vlan_id=10, mrouter=dict(state='enabled', name='Eth1/1'))) commands = ['vlan 10 ip igmp snooping mrouter interface ethernet 1/1'] self.execute_module(changed=True, commands=commands)
def test_without_required_parameters(self): """Failure must occurs when all parameters are missing.""" with self.assertRaises(AnsibleFailJson): set_module_args({}) self.module.main()
def test_slxos_config_replace_block(self): lines = ['description test string', 'test string'] parents = ['interface Ethernet 0/0'] set_module_args(dict(lines=lines, replace='block', parents=parents)) commands = parents + lines self.execute_module(changed=True, commands=commands)
def test_igmp_enabled_with_change(self): set_module_args(dict(state='enabled', vlan_id=10)) commands = ['vlan 10 ip igmp snooping'] self.execute_module(changed=True, commands=commands)
def test_slxos_config_match_none(self): lines = ['hostname router'] set_module_args(dict(lines=lines, match='none')) self.execute_module(changed=True, commands=lines)
def test_igmp_mrouter_disabled_no_change(self): self.enabled = True set_module_args( dict(vlan_id=10, mrouter=dict(state='disabled', name='Eth1/1'))) self.execute_module(changed=False)
def test_slxos_config_src_and_parents_fails(self): args = dict(src='foo', parents='foo') set_module_args(args) self.execute_module(failed=True)
def test_slxos_config_lines_wo_parents(self): set_module_args(dict(lines=['hostname foo'])) commands = ['hostname foo'] self.execute_module(changed=True, commands=commands)
def test_slxos_config_replace_block_requires_lines(self): args = dict(replace='block') set_module_args(args) self.execute_module(failed=True)
def test_slxos_config_lines_w_parents(self): set_module_args( dict(lines=['shutdown'], parents=['interface Ethernet 0/0'])) commands = ['interface Ethernet 0/0', 'shutdown'] self.execute_module(changed=True, commands=commands)
def test_slxos_config_unchanged(self): src = load_fixture('slxos_config_config.cfg') set_module_args(dict(src=src)) self.execute_module()
def test_slxos_config_after(self): set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2'])) commands = ['hostname foo', 'test1', 'test2'] self.execute_module(changed=True, commands=commands, sort=False)
def test_slxos_config_backup(self): set_module_args(dict(backup=True)) result = self.execute_module() self.assertIn('__backup__', result)
def test_slxos_config_before_after_no_change(self): set_module_args( dict(lines=['hostname router'], before=['test1', 'test2'], after=['test3', 'test4'])) self.execute_module()
def test_without_parameters(self): """Test without parameters""" set_module_args({}) with self.assertRaises(AnsibleFailJson): self.module.main()
def test_slxos_config_config(self): config = 'hostname localhost' set_module_args(dict(lines=['hostname router'], config=config)) commands = ['hostname router'] self.execute_module(changed=True, commands=commands)
def test_access_list_ip_remove(self): set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'foo', 'pn_ip': '172.16.3.1', 'state': 'absent'}) result = self.execute_module(changed=True, state='absent') expected_cmd = ' switch sw01 access-list-ip-remove name foo ip 172.16.3.1' self.assertEqual(result['cli_cmd'], expected_cmd)
def _run_module_with_fail_json(self, module_args): set_module_args(module_args) with pytest.raises(AnsibleFailJson) as exc: self.module.main() result = exc.value.args[0] return result