def test_vyos_ping_failure_stats(self): '''Test for asserting stats when ping fails''' set_module_args(dict(count=4, dest="10.10.10.20")) result = self.execute_module(failed=True) self.assertEqual(result['packet_loss'], '100%') self.assertEqual(result['packets_rx'], 0) self.assertEqual(result['packets_tx'], 4)
def test_vyos_system_clear_all(self): set_module_args(dict(state='absent')) commands = [ 'delete system host-name', 'delete system domain-search domain', 'delete system domain-name', 'delete system name-server' ] self.execute_module(changed=True, commands=commands)
def test_vyos_config_lines(self): commands = ['set system host-name foo'] set_module_args(dict(lines=commands)) candidate = '\n'.join(commands) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff( candidate, self.running_config)) self.execute_module(changed=True, commands=commands)
def test_vyos_facts_not_all(self): set_module_args(dict(gather_subset='!all')) result = self.execute_module() facts = result.get('ansible_facts') self.assertEqual(len(facts), 10) self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7')
def test_vyos_system_no_change(self): set_module_args( dict(host_name='router', domain_name='example.com', name_server=['8.8.8.8', '8.8.4.4'])) result = self.execute_module() self.assertEqual([], result['commands'])
def test_vyos_facts_exclude_most(self): set_module_args(dict(gather_subset=['!neighbors', '!config'])) result = self.execute_module() facts = result.get('ansible_facts') self.assertEqual(len(facts), 10) self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7')
def test_vyos_system_domain_search(self): set_module_args( dict(domain_search=['foo.example.com', 'bar.example.com'])) commands = [ "set system domain-search domain 'foo.example.com'", "set system domain-search domain 'bar.example.com'" ] self.execute_module(changed=True, commands=commands)
def test_vyos_command_match_all(self): wait_for = [ 'result[0] contains "VyOS maintainers"', 'result[0] contains "*****@*****.**"' ] set_module_args( dict(commands=['show version'], wait_for=wait_for, match='all')) self.execute_module()
def test_vyos_config_config(self): config = 'set system host-name localhost' new_config = ['set system host-name router'] set_module_args(dict(lines=new_config, config=config)) candidate = '\n'.join(new_config) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff(candidate, config)) self.execute_module(changed=True, commands=new_config)
def test_vyos_user_update_password_changed(self): set_module_args( dict(name='test', configured_password='******', update_password='******')) result = self.execute_module(changed=True) self.assertEqual(result['commands'], [ 'set system login user test authentication plaintext-password test' ])
def test_vyos_user_purge(self): set_module_args(dict(purge=True)) result = self.execute_module(changed=True) self.assertEqual( sorted(result['commands']), sorted([ 'delete system login user ansible', 'delete system login user admin' ]))
def test_vyos_static_route_present(self): set_module_args( dict(prefix='172.26.0.0/16', next_hop='172.26.4.1', admin_distance='1')) result = self.execute_module(changed=True) self.assertEqual(result['commands'], [ 'set protocols static route 172.26.0.0/16 next-hop 172.26.4.1 distance 1' ])
def test_vyos_command_match_all_failure(self): wait_for = [ 'result[0] contains "VyOS maintainers"', 'result[0] contains "test string"' ] commands = ['show version', 'show version'] set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) self.execute_module(failed=True)
def test_vyos_config_match_none(self): lines = [ 'set system interfaces ethernet eth0 address 1.2.3.4/24', 'set system interfaces ethernet eth0 description test string' ] set_module_args(dict(lines=lines, match='none')) candidate = '\n'.join(lines) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff( candidate, None, diff_match='none')) self.execute_module(changed=True, commands=lines, sort=False)
def test_vyos_ping_success_stats_with_options(self): set_module_args(dict(count=10, ttl=128, size=512, dest="10.10.10.11")) result = self.execute_module() self.assertEqual(result['packet_loss'], '0%') self.assertEqual(result['packets_rx'], 10) self.assertEqual(result['packets_tx'], 10) self.assertEqual(result['rtt']['min'], 1) self.assertEqual(result['rtt']['avg'], 3) self.assertEqual(result['rtt']['max'], 21) self.assertEqual(result['rtt']['mdev'], 5)
def test_vyos_config_src_brackets(self): src = load_fixture('vyos_config_src_brackets.cfg') set_module_args(dict(src=src)) candidate = '\n'.join(self.module.format_commands(src.splitlines())) commands = [ 'set interfaces ethernet eth0 address 10.10.10.10/24', 'set system host-name foo' ] self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff( candidate, self.running_config)) self.execute_module(changed=True, commands=commands)
def test_vyos_ping_success_stats(self): '''Test for asserting stats when ping passes''' set_module_args(dict(count=2, dest="10.10.10.10")) result = self.execute_module() self.assertEqual(result['packet_loss'], '0%') self.assertEqual(result['packets_rx'], 2) self.assertEqual(result['packets_tx'], 2) self.assertEqual(result['rtt']['min'], 12) self.assertEqual(result['rtt']['avg'], 17) self.assertEqual(result['rtt']['max'], 22) self.assertEqual(result['rtt']['mdev'], 10)
def test_vyos_facts_invalid_subset(self): set_module_args(dict(gather_subset='cereal')) self.execute_module(failed=True)
def test_vyos_config_unchanged(self): src = load_fixture('vyos_config_config.cfg') self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff(src, src)) set_module_args(dict(src=src)) self.execute_module()
def test_vyos_system_clear_hostname(self): set_module_args(dict(host_name='foo', state='absent')) commands = ["delete system host-name"] self.execute_module(changed=True, commands=commands)
def test_vyos_remove_single_name_server(self): set_module_args(dict(name_server=['8.8.4.4'], state='absent')) commands = ["delete system name-server '8.8.4.4'"] self.execute_module(changed=True, commands=commands)
def test_vyos_ping_expected_success(self): ''' Test for successful pings when destination should be reachable ''' set_module_args(dict(count=2, dest="10.10.10.10")) self.execute_module()
def test_vyos_system_domain_name(self): set_module_args(dict(domain_name='example2.com')) commands = ["set system domain-name 'example2.com'"] self.execute_module(changed=True, commands=commands)
def test_vyos_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.execute_module(failed=True)
def test_vyos_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.execute_module(failed=True)
def test_vyos_system_clear_domain_name(self): set_module_args(dict(domain_name='example.com', state='absent')) commands = ['delete system domain-name'] self.execute_module(changed=True, commands=commands)
def test_vyos_system_hostname(self): set_module_args(dict(host_name='foo')) commands = ["set system host-name 'foo'"] self.execute_module(changed=True, commands=commands)
def test_vyos_config_backup(self): set_module_args(dict(backup=True)) result = self.execute_module() self.assertIn('__backup__', result)
def test_vyos_ping_expected_failure(self): ''' Test for unsuccessful pings when destination should not be reachable ''' set_module_args(dict(count=4, dest="10.10.10.20", state="absent")) self.execute_module()
def test_vyos_system_clear_domain_search(self): set_module_args(dict(domain_search=[])) commands = ['delete system domain-search domain'] self.execute_module(changed=True, commands=commands)