def test_aaa_accounting_no_change(self): set_module_args(dict(tacacs_accounting_enabled=False)) self.execute_module(changed=False)
def test_aruba_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_aruba_config_lines_w_parents(self): set_module_args(dict(lines=['shutdown'], parents=['interface GigabitEthernet0/0'])) commands = ['interface GigabitEthernet0/0', 'shutdown'] self.execute_module(changed=True, commands=commands)
def test_eos_system_hostname_changed(self): set_module_args(dict(hostname='foo')) commands = ['hostname foo'] self.execute_module(changed=True, commands=commands)
def test_eos_system_domain_list(self): set_module_args(dict(domain_list=['ansible.com', 'redhat.com'])) commands = [ 'no ip domain-list ops.ansible.com', 'ip domain-list redhat.com' ] self.execute_module(changed=True, commands=commands)
def test_eos_user_sshkey(self): set_module_args(dict(name='ansible', sshkey='test')) commands = ['username ansible sshkey test'] self.execute_module(changed=True, commands=commands)
def test_eos_system_no_change(self): set_module_args( dict(hostname='switch01', domain_name='eng.ansible.com')) commands = [] self.execute_module(commands=commands)
def test_aaa_fallback_no_change(self): set_module_args(dict(auth_fallback_enabled=True)) self.execute_module(changed=False)
def test_aaa_fallback_with_change(self): set_module_args(dict(auth_fallback_enabled=False)) commands = ['no aaa authorization map fallback server-err'] self.execute_module(changed=True, commands=commands)
def test_aaa_auth_order_no_change(self): set_module_args(dict(auth_order='remote-first')) self.execute_module(changed=False)
def test_aaa_auth_order_with_change(self): set_module_args(dict(auth_order='local-only')) commands = ['aaa authorization map order local-only'] self.execute_module(changed=True, commands=commands)
def test_aaa_auth_default_user_with_change(self): set_module_args(dict(auth_default_user='******')) commands = ['aaa authorization map default-user monitor'] self.execute_module(changed=True, commands=commands)
def test_aaa_auth_default_user_no_change(self): set_module_args(dict(auth_default_user='******')) self.execute_module(changed=False)
def test_aaa_accounting_with_change(self): set_module_args(dict(tacacs_accounting_enabled=True)) commands = ['aaa accounting changes default stop-only tacacs+'] self.execute_module(changed=True, commands=commands)
def test_eos_user_purge(self): set_module_args(dict(purge=True)) commands = ['no username ansible'] 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({}) iptables.main()
def test_eos_user_role(self): set_module_args( dict(name='ansible', role='test', configured_password='******')) result = self.execute_module(changed=True) self.assertIn('username ansible role test', result['commands'])
def test_iprange(self): """ Test iprange module with its flags src_range and dst_range """ set_module_args({ 'chain': 'INPUT', 'match': ['iprange'], 'src_range': '192.168.1.100-192.168.1.199', 'jump': 'ACCEPT' }) commands_results = [ (0, '', ''), ] with patch.object(basic.AnsibleModule, 'run_command') as run_command: run_command.side_effect = commands_results with self.assertRaises(AnsibleExitJson) as result: iptables.main() self.assertTrue(result.exception.args[0]['changed']) self.assertEqual(run_command.call_count, 1) self.assertEqual(run_command.call_args_list[0][0][0], [ '/sbin/iptables', '-t', 'filter', '-C', 'INPUT', '-m', 'iprange', '-j', 'ACCEPT', '--src-range', '192.168.1.100-192.168.1.199', ]) set_module_args({ 'chain': 'INPUT', 'src_range': '192.168.1.100-192.168.1.199', 'dst_range': '10.0.0.50-10.0.0.100', 'jump': 'ACCEPT' }) commands_results = [ (0, '', ''), ] with patch.object(basic.AnsibleModule, 'run_command') as run_command: run_command.side_effect = commands_results with self.assertRaises(AnsibleExitJson) as result: iptables.main() self.assertTrue(result.exception.args[0]['changed']) self.assertEqual(run_command.call_count, 1) self.assertEqual(run_command.call_args_list[0][0][0], [ '/sbin/iptables', '-t', 'filter', '-C', 'INPUT', '-j', 'ACCEPT', '-m', 'iprange', '--src-range', '192.168.1.100-192.168.1.199', '--dst-range', '10.0.0.50-10.0.0.100' ]) set_module_args({ 'chain': 'INPUT', 'dst_range': '10.0.0.50-10.0.0.100', 'jump': 'ACCEPT' }) commands_results = [ (0, '', ''), ] with patch.object(basic.AnsibleModule, 'run_command') as run_command: run_command.side_effect = commands_results with self.assertRaises(AnsibleExitJson) as result: iptables.main() self.assertTrue(result.exception.args[0]['changed']) self.assertEqual(run_command.call_count, 1) self.assertEqual(run_command.call_args_list[0][0][0], [ '/sbin/iptables', '-t', 'filter', '-C', 'INPUT', '-j', 'ACCEPT', '-m', 'iprange', '--dst-range', '10.0.0.50-10.0.0.100' ])
def test_eos_system_state_absent(self): set_module_args(dict(state='absent')) commands = ['no ip domain-name', 'no hostname'] self.execute_module(changed=True, commands=commands)
def test_eos_user_update_password_on_create_ok(self): set_module_args( dict(name='ansible', configured_password='******', update_password='******')) self.execute_module()
def test_eos_system_missing_vrf(self): name_servers = dict(server='8.8.8.8', vrf='missing') set_module_args(dict(name_servers=name_servers)) self.execute_module(failed=True)
def test_eos_user_create(self): set_module_args(dict(name='test', nopassword=True)) commands = ['username test nopassword'] self.execute_module(changed=True, commands=commands)
def test_eos_system_domain_name(self): set_module_args(dict(domain_name='test.com')) commands = ['ip domain-name test.com'] self.execute_module(changed=True, commands=commands)
def test_eos_user_delete(self): set_module_args(dict(name='ansible', state='absent')) commands = ['no username ansible'] self.execute_module(changed=True, commands=commands)
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_eos_user_password(self): set_module_args(dict(name='ansible', configured_password='******')) commands = ['username ansible secret test'] self.execute_module(changed=True, commands=commands)
def test_aruba_config_lines_wo_parents(self): set_module_args(dict(lines=['hostname foo'])) commands = ['hostname foo'] self.execute_module(changed=True, commands=commands)
def test_eos_user_privilege_invalid(self): set_module_args( dict(name='ansible', privilege=25, configured_password='******')) self.execute_module(failed=True)
def test_aruba_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_configure_congestion_control_disabled_with_no_change(self): set_module_args(dict(state="disabled", interfaces=["Eth1/1"], tc=0)) self.execute_module(changed=False)