Ejemplo n.º 1
0
 def test_acos_command_match_any(self):
     wait_for = [
         'result[0] contains "Thunder"', 'result[0] contains "test"'
     ]
     set_module_args(
         dict(commands=['show version'], wait_for=wait_for, match='any'))
     self.execute_module()
Ejemplo n.º 2
0
 def test_acos_command_simple(self):
     set_module_args(dict(commands=['show version']))
     result = self.execute_module()
     self.assertTrue(result['stdout'][0].startswith('Thunder Series'))
     self.assertFalse(result['stdout'][0].startswith('ACOS'))
     self.assertIn('aFleX version: 2.0.0', result['stdout'][0])
     self.assertEqual(len(result['stdout']), 1)
Ejemplo n.º 3
0
 def test_acos_facts_in_existing_partition(self, mock_partition):
     set_module_args(dict(partition='my_partition', gather_subset='config'))
     self.execute_module()
     second_args = [calls[0][1]
                    for calls in mock_partition.call_args_list]
     self.assertIn('active-partition my_partition', second_args)
     self.assertTrue(mock_partition.called)
Ejemplo n.º 4
0
 def test_acos_facts_partition_does_not_exist(self, mock_partition):
     fixture = [load_fixture("acos_facts_active-partition_my_partition_new")]
     mock_partition.return_value = fixture
     set_module_args(dict(partition='my_partition_new', gather_subset='config'))
     with self.assertRaises(AnsibleFailJson):
         result = self.execute_module()
         self.assertIn('Provided partition does not exist', result['msg'])
Ejemplo n.º 5
0
 def test_acos_command_configure_no_warning(self):
     commands = ['configure']
     set_module_args({
         'commands': commands,
         '_ansible_check_mode': True,
     })
     result = self.execute_module()
     self.assertNotEqual(result['warnings'], [])
Ejemplo n.º 6
0
 def test_acos_command_match_all_failure(self):
     wait_for = [
         'result[0] contains "Thunder"', 'result[0] contains "test"'
     ]
     commands = ['show version', 'show version']
     set_module_args(dict(commands=commands, wait_for=wait_for,
                          match='all'))
     self.execute_module(failed=True)
Ejemplo n.º 7
0
 def test_acos_config_in_existing_partition(self, mock_partition):
     fixture = [load_fixture("acos_config_show_partition.cfg")]
     mock_partition.return_value = fixture
     partition_name = 'my_partition'
     set_module_args(dict(partition=partition_name))
     self.execute_module()
     second_args = [calls[0][1] for calls in mock_partition.call_args_list]
     self.assertIn('active-partition my_partition', second_args)
Ejemplo n.º 8
0
 def test_acos_config_save_changed_false(self):
     set_module_args(dict(save_when="changed"))
     self.execute_module()
     self.assertEqual(self.run_commands.call_count, 3)
     self.assertEqual(self.conn.edit_config.call_count, 1)
     args = self.run_commands.call_args_list
     commands = [x[0][1] for x in args]
     self.assertNotIn("write memory\r", commands)
Ejemplo n.º 9
0
 def test_acos_command_in_existing_partition(self):
     commands = ['show running-config']
     set_module_args(dict(commands=commands, partition='my_partition'))
     self.execute_module()
     second_args = [
         calls[0][1] for calls in self.run_commands.call_args_list
     ]
     self.assertTrue(self.run_commands.called)
     self.assertIn('active-partition my_partition', second_args)
Ejemplo n.º 10
0
 def test_acos_config_match_none(self):
     lines = ["ip dns primary 10.18.18.81"]
     set_module_args(dict(lines=lines, match="none"))
     self.execute_module()
     self.conn.get_diff.assert_called_with(
         candidate='ip dns primary 10.18.18.81',
         diff_ignore_lines=None,
         diff_match='none',
         running=self.running_config)
Ejemplo n.º 11
0
 def test_acos_facts_hardware(self):
     set_module_args(dict(gather_subset='hardware'))
     result = self.execute_module()
     self.assertEqual(
         result['ansible_facts']['ansible_net_memfree_mb'], "3897 Mbyte"
     )
     self.assertEqual(
         result['ansible_facts']['ansible_net_memtotal_mb'], "8071 Mbyte"
     )
Ejemplo n.º 12
0
 def test_acos_command_multiple(self):
     set_module_args(dict(commands=['show version', 'show hardware']))
     result = self.execute_module()
     self.assertIsNotNone(result['stdout'][0])
     self.assertEqual(len(result['stdout']), 2)
     self.assertTrue(result['stdout'][0].startswith('Thunder Series'))
     self.assertNotEqual(result['stdout'][0], "test")
     self.assertIsNotNone(result['stdout'][1])
     self.assertIn('Storage', result['stdout'][1])
Ejemplo n.º 13
0
 def test_acos_config_save_always(self):
     lines = ["ip dns primary 10.18.18.19"]
     set_module_args(dict(lines=lines, save_when="always"))
     self.execute_module()
     self.assertEqual(self.run_commands.call_count, 4)
     self.assertEqual(self.conn.edit_config.call_count, 1)
     args = self.run_commands.call_args_list
     commands = [x[0][1] for x in args]
     self.assertIn("write memory\r", commands)
Ejemplo n.º 14
0
 def test_acos_config_partition_does_not_exist(self, mock_partition):
     fixture = [
         load_fixture("acos_config_active-partition_my_partition3.cfg")
     ]
     mock_partition.return_value = fixture
     partition_name = 'my_partition3'
     set_module_args(dict(partition=partition_name))
     self.assertRaises(AnsibleFailJson, self.execute_module)
     with self.assertRaises(AnsibleFailJson):
         result = self.execute_module()
         self.assertIn('Provided partition does not exist', result['msg'])
Ejemplo n.º 15
0
    def test_acos_config_save_no_modified(self, mock_networkConfig):
        lines = ["ip dns primary 10.18.18.39"]
        set_module_args(dict(lines=lines, save_when="modified"))
        self.execute_module()

        args = self.run_commands.call_args_list[-1][0][1]
        self.assertEqual(args, ['show running-config', 'show startup-config'])

        self.assertEqual(mock_networkConfig.call_count, 3)

        commands = [x[0][1] for x in self.run_commands.call_args_list]
        self.assertNotIn("write memory\r", commands)
Ejemplo n.º 16
0
 def test_acos_config_lines(self):
     lines = ["ip dns primary 10.18.18.81"]
     set_module_args(dict(lines=lines))
     self.execute_module()
     self.conn.get_diff = Mock(return_value=self.cliconf_obj.get_diff(
         candidate=lines,
         running=self.running_config,
         diff_match=self.match,
         diff_ignore_lines=self.diff_ignore_lines))
     self.assertIn("ip dns primary 10.18.18.81",
                   self.conn.get_diff.return_value['config_diff'])
     self.assertTrue(self.conn.edit_config.called)
Ejemplo n.º 17
0
 def test_acos_facts_config(self):
     set_module_args(dict(gather_subset='config'))
     result = self.execute_module()
     self.assertEqual(
         result['ansible_facts']['ansible_net_api'], 'cliConf'
     )
     self.assertNotEqual(
         result['ansible_facts']['ansible_net_serialnum'], '123'
     )
     self.assertNotIn(
         '!Current configuration:', result[
             'ansible_facts']['ansible_net_config']
     )
Ejemplo n.º 18
0
 def test_acos_command_configure_check_warning(self):
     commands = ['configure']
     set_module_args({
         'commands': commands,
         '_ansible_check_mode': True,
     })
     result = self.execute_module()
     self.assertEqual(
         result['warnings'],
         [
             'Only show commands are supported when using check mode, not executing configure'
         ],
     )
Ejemplo n.º 19
0
    def test_acos_config_save_modified(self, mock_networkConfig):

        running_config_fixture = Mock()
        running_config_fixture.sha1 = "show running_config fixtures"
        startup_config_fixture = Mock()
        startup_config_fixture.sha1 = "show startup_config fixtures"

        mock_networkConfig.side_effect = [
            running_config_fixture, startup_config_fixture
        ]
        set_module_args(dict(save_when="modified"))

        self.execute_module()
        args = self.run_commands.call_args_list

        commands = [x[0][1] for x in args]
        self.assertIn("write memory\r", commands)
Ejemplo n.º 20
0
 def test_acos_facts_negation_hardware(self):
     set_module_args(dict(gather_subset='!hardware'))
     result = self.execute_module()
     self.assertEqual(
         result['ansible_facts']['ansible_net_interfaces'][
             'Ethernet 4']['operstatus'], 'up'
     )
     self.assertIsNotNone(
         result['ansible_facts'][
             'ansible_net_interfaces']['Ethernet 4']['duplex']
     )
     self.assertNotIn(
         'ansible_net_memfree_mb', result['ansible_facts']
     )
     self.assertNotIn(
         'ansible_net_memtotal_mb', result['ansible_facts']
     )
Ejemplo n.º 21
0
 def test_acos_facts_default(self):
     set_module_args(dict(gather_subset='default'))
     result = self.execute_module()
     self.assertEqual(
         result['ansible_facts'][
             'ansible_net_hostid'], 'ABCDEFGHIJKLMNOPQ'
     )
     self.assertEqual(
         result['ansible_facts']['ansible_net_image'], '4.1.1-P9.105'
     )
     self.assertEqual(
         result['ansible_facts'][
             'ansible_net_model'], 'Thunder Series Unified Application Service Gateway vThunder'
     )
     self.assertEqual(
         result['ansible_facts'][
             'ansible_net_version'], '64-bit Advanced Core OS (ACOS) version 4.1.1-P9, build 105 (Sep-21-2018,22:25)'
     )
Ejemplo n.º 22
0
 def test_acos_facts_interfaces(self):
     set_module_args(dict(gather_subset='interfaces'))
     result = self.execute_module()
     self.assertEqual(
         result['ansible_facts']['ansible_net_interfaces'][
             'Ethernet 1']['mtu'], 1500
     )
     self.assertEqual(
         result['ansible_facts']['ansible_net_interfaces'][
             'Ethernet 2']['ipv6'][0]['address'], '2001:db8:85a3::8a2e:370:7334'
     )
     self.assertEqual(
         result['ansible_facts']['ansible_net_interfaces'][
             'Ethernet 3']['macaddress'], 'fa16.3e6d.95ec'
     )
     self.assertIsNone(
         result['ansible_facts'][
             'ansible_net_interfaces']['lif 10']['duplex']
     )
     self.assertIsNotNone(
         result['ansible_facts'][
             'ansible_net_interfaces']['Ethernet 2']['duplex']
     )
Ejemplo n.º 23
0
 def test_acos_command_partition_does_not_exists(self):
     commands = ['show running-config']
     set_module_args(dict(commands=commands, partition='my_partition2'))
     with self.assertRaises(AnsibleFailJson):
         result = self.execute_module()
         self.assertIn('Provided partition does not exist', result['msg'])
Ejemplo n.º 24
0
 def test_acos_config_src(self):
     set_module_args(dict(src=self.src))
     self.execute_module()
     self.assertTrue(self.conn.edit_config.called)
Ejemplo n.º 25
0
 def test_acos_config_backup(self):
     set_module_args(dict(backup=True))
     result = self.execute_module()
     self.assertIn("__backup__", result)
Ejemplo n.º 26
0
 def test_acos_command_match_any_failure(self):
     wait_for = ['result[0] contains "test1"', 'result[0] contains "test2"']
     set_module_args(
         dict(commands=['show version'], wait_for=wait_for, match='any'))
     self.execute_module(failed=True)
Ejemplo n.º 27
0
 def test_acos_command_wait_for(self):
     wait_for = 'result[0] contains "ACOS"'
     set_module_args(dict(commands=['show version'], wait_for=wait_for))
     result = self.execute_module()
     self.assertIn('ACOS', result['stdout'][0])
Ejemplo n.º 28
0
 def test_acos_command_wait_for_fails(self):
     wait_for = 'result[0] contains "test"'
     set_module_args(dict(commands=['show version'], wait_for=wait_for))
     self.execute_module(failed=True)
     self.assertEqual(self.run_commands.call_count, 12)
Ejemplo n.º 29
0
 def test_acos_command_retries_failure(self):
     wait_for = 'result[0] contains "test"'
     set_module_args(
         dict(commands=['show version'], wait_for=wait_for, retries=2))
     self.execute_module(failed=True)
Ejemplo n.º 30
0
 def test_acos_command_retries(self):
     wait_for = 'result[0] contains "ACOS"'
     set_module_args(
         dict(commands=['show version'], wait_for=wait_for, retries=2))
     self.execute_module()