示例#1
0
    def test_voss_config_lines_w_parents(self):
        lines = ['no shutdown']
        parents = ['interface GigabitEthernet 1/1']
        set_module_args(dict(lines=lines, parents=parents))
        module = MagicMock()
        module.params = {'lines': lines, 'parents': parents, 'src': None}
        candidate_config = voss_config.get_candidate_config(module)

        self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(
            candidate_config, self.running_config))

        commands = ['interface GigabitEthernet 1/1', 'no shutdown']
        self.execute_module(changed=True, commands=commands)
示例#2
0
    def test_voss_config_ipv6(self):
        lines = [
            'ip address 1 1.1.1.1/255.255.255.255',
            'ipv6 interface address 2011:0:0:0:0:0:0:1/128'
        ]
        parents = ['interface loopback 1']
        set_module_args(dict(lines=lines, parents=parents))
        module = MagicMock()
        module.params = {'lines': lines, 'parents': parents, 'src': None}
        candidate_config = voss_config.get_candidate_config(module)

        self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(
            candidate_config, self.running_config))
        self.execute_module(changed=False)
示例#3
0
    def test_voss_config_match_exact(self):
        lines = ['name "ServerA"', 'vlacp enable', 'no shutdown']
        parents = ['interface GigabitEthernet 1/1']
        set_module_args(dict(lines=lines, parents=parents, match='exact'))

        module = MagicMock()
        module.params = {'lines': lines, 'parents': parents, 'src': None}
        candidate_config = voss_config.get_candidate_config(module)
        self.conn.get_diff = MagicMock(
            return_value=self.cliconf_obj.get_diff(candidate_config,
                                                   self.running_config,
                                                   diff_match='exact',
                                                   path=parents))

        commands = parents + lines
        self.execute_module(changed=True, commands=commands, sort=False)
示例#4
0
 def test_voss_config_after(self):
     lines = ['prompt "VSP8K"']
     set_module_args(dict(lines=lines, after=['test1', 'test2']))
     self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(
         '\n'.join(lines), self.running_config))
     commands = ['prompt "VSP8K"', 'test1', 'test2']
     self.execute_module(changed=True, commands=commands, sort=False)
示例#5
0
 def test_voss_config_lines_wo_parents(self):
     lines = ['prompt "VSP8K"']
     set_module_args(dict(lines=lines))
     self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(
         '\n'.join(lines), self.running_config))
     commands = ['prompt "VSP8K"']
     self.execute_module(changed=True, commands=commands)
示例#6
0
    def test_voss_config_replace_block(self):
        lines = ['name "ServerB"', 'test string']
        parents = ['interface GigabitEthernet 1/2']
        set_module_args(dict(lines=lines, replace='block', parents=parents))

        module = MagicMock()
        module.params = {'lines': lines, 'parents': parents, 'src': None}
        candidate_config = voss_config.get_candidate_config(module)

        self.conn.get_diff = MagicMock(
            return_value=self.cliconf_obj.get_diff(candidate_config,
                                                   self.running_config,
                                                   diff_replace='block',
                                                   path=parents))

        commands = parents + lines
        self.execute_module(changed=True, commands=commands)
示例#7
0
 def test_voss_config_config(self):
     config = 'prompt "VSP300"'
     lines = ['prompt router']
     set_module_args(dict(lines=lines, config=config))
     self.conn.get_diff = MagicMock(
         return_value=self.cliconf_obj.get_diff('\n'.join(lines), config))
     commands = ['prompt router']
     self.execute_module(changed=True, commands=commands)
示例#8
0
 def test_voss_config_before_after_no_change(self):
     lines = ['prompt "VSP300"']
     set_module_args(
         dict(lines=lines,
              before=['test1', 'test2'],
              after=['test3', 'test4']))
     self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(
         '\n'.join(lines), self.running_config))
     self.execute_module()
示例#9
0
 def test_voss_config_src(self):
     src = load_fixture('voss_config_src.cfg')
     set_module_args(dict(src=src))
     self.conn.get_diff = MagicMock(
         return_value=self.cliconf_obj.get_diff(src, self.running_config))
     commands = [
         'prompt "VSP8K"', 'interface GigabitEthernet 1/1', 'name "UNUSED"',
         'exit'
     ]
     self.execute_module(changed=True, commands=commands)
示例#10
0
 def test_voss_config_src_ipv6(self):
     src = load_fixture('voss_config_ipv6.cfg')
     set_module_args(dict(src=src))
     self.conn.get_diff = MagicMock(
         return_value=self.cliconf_obj.get_diff(src, self.running_config))
     commands = [
         'interface loopback 1', 'ip address 1 2.2.2.2/255.255.255.255',
         'ipv6 interface address 2011:0:0:0:0:0:0:2/128', 'exit'
     ]
     self.execute_module(changed=True, commands=commands)
示例#11
0
    def setUp(self):
        super(TestVossConfigModule, self).setUp()

        self.mock_get_config = patch(
            'ansible_collections.extremenetworks.voss.plugins.modules.voss_config.get_config'
        )
        self.get_config = self.mock_get_config.start()

        self.mock_get_connection = patch(
            'ansible_collections.extremenetworks.voss.plugins.modules.voss_config.get_connection'
        )
        self.get_connection = self.mock_get_connection.start()

        self.conn = self.get_connection()
        self.conn.edit_config = MagicMock()

        self.mock_run_commands = patch(
            'ansible_collections.extremenetworks.voss.plugins.modules.voss_config.run_commands'
        )
        self.run_commands = self.mock_run_commands.start()

        self.cliconf_obj = Cliconf(MagicMock())
        self.running_config = load_fixture('voss_config_config.cfg')
示例#12
0
 def test_voss_config_save_changed_true(self):
     src = load_fixture('voss_config_src.cfg')
     set_module_args(dict(src=src, save_when='changed'))
     commands = [
         'prompt "VSP8K"', 'interface GigabitEthernet 1/1', 'name "UNUSED"',
         'exit'
     ]
     self.conn.get_diff = MagicMock(
         return_value=self.cliconf_obj.get_diff(src, self.running_config))
     self.execute_module(changed=True, commands=commands)
     self.assertEqual(self.run_commands.call_count, 1)
     self.assertEqual(self.get_config.call_count, 1)
     self.assertEqual(self.conn.edit_config.call_count, 1)
     args = self.run_commands.call_args[0][1]
     self.assertIn('save config\r', args)
示例#13
0
from ansible_collections.extremenetworks.voss.tests.unit.compat.mock import MagicMock
from ansible.utils.path import unfrackpath

mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath,
                                  side_effect=lambda x, *args, **kwargs: x)
示例#14
0
 def test_voss_config_unchanged(self):
     src = load_fixture('voss_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()
示例#15
0
 def test_voss_config_match_none(self):
     lines = ['prompt router']
     set_module_args(dict(lines=lines, match='none'))
     self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(
         '\n'.join(lines), self.running_config, diff_match='none'))
     self.execute_module(changed=True, commands=lines)