def test_magp_enable(self): set_module_args( dict(interface='Vlan 1200', magp_id=103, state='enabled')) commands = ['interface vlan 1200 magp 103 no shutdown'] self.execute_module(changed=True, commands=commands)
def test_cnos_config_backup(self): set_module_args(dict(backup=True)) result = self.execute_module() self.assertIn('__backup__', result)
def test_cnos_config_lines_w_parents(self): set_module_args(dict(lines=['shutdown'], parents=['interface ethernet 1/13'])) commands = ['interface ethernet 1/13', 'shutdown'] self.execute_module(changed=True, commands=commands)
def test_cnos_config_match_none(self): lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string'] parents = ['interface ethernet 1/13'] set_module_args(dict(lines=lines, parents=parents, match='none')) commands = parents + lines self.execute_module(changed=True, commands=commands, sort=False)
def test_cnos_config_unchanged(self): src = load_fixture('cnos_config_config.cfg') set_module_args(dict(src=src)) self.execute_module()
def test_junos_ping_unexpected_success(self): ''' Test for successful pings when destination should not be reachable - FAIL. ''' set_module_args(dict(count=2, dest="10.10.10.10", state="absent")) self.conn.get = MagicMock(return_value=load_fixture( 'junos_ping_ping_10.10.10.10_count_2', content='str')) self.execute_module(failed=True)
def _run_module(self, module_args): set_module_args(module_args) with pytest.raises(AnsibleExitJson) as ex: self.module.main() return ex.value.args[0]
def test_igmp_proxy_reporting_enabled(self): set_module_args(dict(state='enabled', proxy_reporting='enabled')) commands = ['ip igmp snooping', 'ip igmp snooping proxy reporting'] self.execute_module(changed=True, commands=commands)
def test_igmp_unregistered_multicast_flood(self): set_module_args(dict(state='enabled', unregistered_multicast='flood')) commands = ['ip igmp snooping'] self.execute_module(changed=True, commands=commands)
def test_igmp_mrouter_timeout(self): set_module_args(dict(state='enabled', mrouter_timeout=100)) commands = ['ip igmp snooping', 'ip igmp snooping mrouter-timeout 100'] self.execute_module(changed=True, commands=commands)
def test_igmp_port_purge_timeout(self): set_module_args(dict(state='enabled', port_purge_timeout=150)) commands = [ 'ip igmp snooping', 'ip igmp snooping port-purge-timeout 150' ] self.execute_module(changed=True, commands=commands)
def test_igmp_enable(self): set_module_args(dict(state='enabled')) commands = ['ip igmp snooping'] self.execute_module(changed=True, commands=commands)
def test_igmp_no_change(self): set_module_args(dict(state='disabled')) self.execute_module(changed=False)
def test_igmp_version_v3(self): set_module_args(dict(state='enabled', default_version='V3')) commands = ['ip igmp snooping'] self.execute_module(changed=True, commands=commands)
def test_junos_ping_expected_success(self): set_module_args(dict(count=2, dest="10.10.10.10")) self.conn.get = MagicMock(return_value=load_fixture( 'junos_ping_ping_10.10.10.10_count_2', content='str')) result = self.execute_module() self.assertEqual(result['commands'], 'ping 10.10.10.10 count 2')
def _set_args(self, args=None): module_args = self.REQUIRED_PARAMS.copy() if args is not None: module_args.update(args) set_module_args(module_args)
def test_junos_ping_expected_failure(self): set_module_args(dict(count=4, dest="10.10.10.20", state="absent")) self.conn.get = MagicMock(return_value=load_fixture( 'junos_ping_ping_10.10.10.20_count_4', content='str')) result = self.execute_module() self.assertEqual(result['commands'], 'ping 10.10.10.20 count 4')
def test_icx_command_configure_not_warning(self): commands = ['configure terminal'] set_module_args(dict(commands=commands)) result = self.execute_module() self.assertEqual(result['warnings'], [])
def test_junos_ping_unexpected_failure(self): ''' Test for unsuccessful pings when destination should be reachable - FAIL. ''' set_module_args(dict(count=4, dest="10.10.10.20")) self.conn.get = MagicMock(return_value=load_fixture( 'junos_ping_ping_10.10.10.20_count_4', content='str')) self.execute_module(failed=True)
def test_icx_command_multiple(self): set_module_args(dict(commands=['show version', 'show version'])) result = self.execute_module() self.assertEqual(len(result['stdout']), 2) self.assertTrue(result['stdout'][0].startswith( 'Copyright (c) 1996-2017 Brocade Communications Systems'))
def test_eos_l3_interfaces_deleted(self): set_module_args(dict(state="deleted")) commands = ['no lacp system-priority'] self.execute_module(changed=True, commands=commands)
def test_icx_command_wait_for(self): wait_for = 'result[0] contains "ICX"' set_module_args(dict(commands=['show version'], wait_for=wait_for)) self.execute_module()
def test_cnos_config_match_strict(self): lines = ['ip address 100.10.10.10/24', 'no switchport'] parents = ['interface Ethernet1/12'] set_module_args(dict(lines=lines, parents=parents, match='strict')) commands = parents + ['no switchport'] self.execute_module(changed=True, commands=commands, sort=False)
def test_icx_command_wait_for_fails(self): wait_for = 'result[0] contains "test string"' set_module_args(dict(commands=['show version'], wait_for=wait_for)) self.execute_module(failed=True) # run_commands call count is 1(skip) + 10(current) self.assertEqual(self.run_commands.call_count, 11)
def test_cnos_config_src(self): src = load_fixture('cnos_config_src.cfg') set_module_args(dict(src=src)) commands = ['hostname foo', 'interface ethernet 1/13', 'speed 10000'] self.execute_module(changed=True, commands=commands)
def test_icx_command_retries(self): wait_for = 'result[0] contains "test string"' set_module_args( dict(commands=['show version'], wait_for=wait_for, retries=2)) self.execute_module(failed=True) self.assertEqual(self.run_commands.call_count, 3)
def test_cnos_config_lines_wo_parents(self): set_module_args(dict(lines=['hostname foo'])) commands = ['hostname foo'] self.execute_module(changed=True, commands=commands)
def _set_args(self, **kwargs): module_args = self.REQUIRED_PARAMS.copy() if kwargs is not None: module_args.update(kwargs) set_module_args(module_args)
def test_cnos_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_magp_present_no_change(self): set_module_args(dict(interface='Vlan 1200', magp_id=103)) self.execute_module(changed=False)