示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 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')
示例#5
0
 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'])
示例#6
0
 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')
示例#7
0
 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)
示例#8
0
 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()
示例#9
0
 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'
         ]))
示例#12
0
 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'
     ])
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
 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)
示例#16
0
 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)
示例#17
0
 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)
示例#18
0
 def test_vyos_facts_invalid_subset(self):
     set_module_args(dict(gather_subset='cereal'))
     self.execute_module(failed=True)
示例#19
0
 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()
示例#20
0
 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)
示例#21
0
 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)
示例#22
0
 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()
示例#23
0
 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)
示例#24
0
 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)
示例#25
0
 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)
示例#26
0
 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)
示例#27
0
 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)
示例#28
0
 def test_vyos_config_backup(self):
     set_module_args(dict(backup=True))
     result = self.execute_module()
     self.assertIn('__backup__', result)
示例#29
0
 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()
示例#30
0
 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)