Ejemplo n.º 1
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.º 2
0
    def setUp(self):
        super(TestAcosConfigModule, self).setUp()

        self.mock_get_config = patch(
            "ansible_collections.a10.acos_cli.plugins.modules.acos_config.get_config"
        )
        self.get_config = self.mock_get_config.start()

        self.mock_get_connection = patch(
            "ansible_collections.a10.acos_cli.plugins.modules.acos_config.get_connection"
        )
        self.get_connection = self.mock_get_connection.start()

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

        self.mock_run_commands = patch(
            "ansible_collections.a10.acos_cli.plugins.modules.acos_config.run_commands"
        )
        self.run_commands = self.mock_run_commands.start()

        self.src = os.path.join(os.path.dirname(__file__),
                                'fixtures/show_config_file_commands.cfg')
        self.backup_spec = {
            "filename": "test_backup.cfg",
            "dir_path": "fixtures/backup/"
        }

        self.cliconf_obj = Cliconf(MagicMock())

        self.running_config = load_fixture("acos_running_config.cfg")
        self.match = 'line'
        self.diff_ignore_lines = 'none'
Ejemplo n.º 3
0
        def load_from_file(*args, **kwargs):
            commands = kwargs['commands']
            output = []

            for command in commands:
                filename = str(command).replace(' | ', '_').replace(' ', '_')
                output.append(load_fixture('acos_facts_%s' % filename))
            return output
Ejemplo n.º 4
0
        def load_from_file(*args, **kwargs):
            module, commands = args
            output = []
            if isinstance(commands, str):
                filename = 'acos_command_' + str(commands).replace(' ', '_')
                output.append(load_fixture(filename))
                return output

            for item in commands:
                try:
                    obj = json.loads(item['command'])
                    command = obj['command']
                except ValueError:
                    command = item['command']
                filename = 'acos_command_' + str(command).replace(' ', '_')
                output.append(load_fixture(filename))
            return output
Ejemplo n.º 5
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.º 6
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.º 7
0
 def load_fixtures(self, filename=None):
     config_file = "acos_running_config.cfg"
     self.get_config.return_value = load_fixture(config_file)
     self.get_connection.edit_config.return_value = None