def test_edgeos_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('Version:      v1.9.7'))
 def test_cnos_vrf_absent_no_change(self):
     set_module_args(dict(name='test1', state='absent'))
     self.execute_module(changed=False, commands=[])
 def test_iosxr_user_delete(self):
     set_module_args(dict(name='ansible', state='absent'))
     result = self.execute_module(changed=True)
     self.assertEqual(result['commands'], ['no username ansible'])
 def test_junos_netconf_config_error(self):
     self.netconf_conn().get.return_value = None
     set_module_args(dict(state='present'))
     result = self.execute_module(failed=True)
     self.assertEqual(result['msg'], 'unable to retrieve current config')
 def test_cnos_vrf_present_management(self):
     set_module_args(dict(name='management', state='present'))
     self.execute_module(changed=True, commands=['vrf context management'])
 def test_prefix_list_network_remove(self):
     set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'foo',
                      'pn_network': '172.16.3.1', 'pn_netmask': '24', 'state': 'absent'})
     result = self.execute_module(changed=True, state='absent')
     expected_cmd = ' switch sw01 prefix-list-network-remove  name foo network 172.16.3.1 netmask 24'
     self.assertEqual(result['cli_cmd'], expected_cmd)
Пример #7
0
 def _set_args(self, args):
     module_args = self.REQUIRED_PARAMS.copy()
     module_args.update(args)
     set_module_args(module_args)
Пример #8
0
 def test_edgeos_config_config(self):
     config = 'set system host-name localhost'
     new_config = ['set system host-name er01']
     set_module_args(dict(lines=new_config, config=config))
     self.execute_module(changed=True, commands=new_config)
 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
Пример #10
0
 def test_edgeos_config_backup(self):
     set_module_args(dict(backup=True))
     result = self.execute_module()
     self.assertIn('__backup__', result)
Пример #11
0
 def test_edgeos_config_lines(self):
     commands = ['set system host-name er01']
     set_module_args(dict(lines=commands))
     self.execute_module(changed=True, commands=commands)
Пример #12
0
 def test_edgeos_config_unchanged(self):
     src = load_fixture('edgeos_config_config.cfg')
     set_module_args(dict(src=src))
     self.execute_module()
 def test_edgeos_command_retries(self):
     wait_for = 'result[0] contains "bad 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, 2)
 def test_edgeos_commond_wait_for(self):
     wait_for = 'result[0] contains "Ubiquiti Networks"'
     set_module_args(dict(commands=['show version'], wait_for=wait_for))
     self.execute_module()
Пример #15
0
 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)
Пример #16
0
 def test_snmp_host_enabled_state_no_change(self):
     set_module_args(dict(hosts=[dict(name='1.1.1.1',
                                      enabled=True)]))
     self.execute_module(changed=False)
Пример #17
0
 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)
Пример #18
0
 def test_snmp_host_enabled_state_with_change(self):
     set_module_args(dict(hosts=[dict(name='1.1.1.1',
                                      enabled=False)]))
     commands = ['snmp-server host 1.1.1.1 disable']
     self.execute_module(changed=True, commands=commands)
 def test_ios_vlan_id_startwith_9(self):
     set_module_args({'vlan_id': '9', 'name': 'vlan9', 'state': 'present'})
     result = self.execute_module(changed=False)
     expected_commands = []
     self.assertEqual(result['commands'], expected_commands)
Пример #20
0
 def test_snmp_host_port_no_change(self):
     set_module_args(dict(hosts=[dict(name='2.2.2.2',
                                      notification_type='trap',
                                      version='2c',
                                      port='5')]))
     self.execute_module(changed=False)
 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]
Пример #22
0
 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_junos_netconf_enable(self):
     self.netconf_conn().get.return_value = ''
     set_module_args(dict(state='present'))
     result = self.execute_module(changed=True)
     self.assertEqual(result['commands'],
                      ['set system services netconf ssh port 830'])
Пример #24
0
 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_cnos_vrf_absent_management(self):
     set_module_args(dict(name='management', state='absent'))
     result = self.execute_module(failed=True)
     self.assertEqual(result['msg'],
                      'Management VRF context cannot be deleted')
Пример #26
0
 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_cnos_vrf_default(self):
     set_module_args(dict(name='default', state='present'))
     result = self.execute_module(failed=True)
     self.assertEqual(result['msg'], 'VRF context default is reserved')
Пример #28
0
 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_iosxr_user_password(self):
     set_module_args(dict(name='ansible', configured_password='******'))
     result = self.execute_module(changed=True)
     self.assertEqual(result['commands'], ['username ansible secret test'])
Пример #30
0
 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)