Beispiel #1
0
 def test_get_status(self, mock_open, mock_load, mock_get_log):
     v_actions = ValidationActions()
     col, values = v_actions.get_status('foo')
     self.assertEqual(col, ['name', 'host', 'status', 'task_data'])
     self.assertEqual(
         values,
         [('Check if iscsi.service is enabled', 'foo', 'FAILED', {})])
    def test_show_history_most_recent(self, mock_open, mock_load, mock_get_log,
                                      mock_stat):

        first_validation = mock.MagicMock()
        second_validation = mock.MagicMock()

        first_validation.st_mtime = 5
        second_validation.st_mtime = 7

        validations = {
            '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json': first_validation,
            '/tmp/123_bar_2020-03-05T13:17:22.447857Z.json': second_validation
        }

        def _generator(x=None):
            if x:
                return validations[x]
            return first_validation

        mock_stat.side_effect = _generator

        v_actions = ValidationActions()
        col, values = v_actions.show_history(history_limit=1)

        self.assertEqual(
            col, ('UUID', 'Validations', 'Status', 'Execution at', 'Duration'))
        self.assertEqual(
            values, [('008886df-d297-1eaa-2a74-000000000008', '512e', 'PASSED',
                      '2019-11-25T13:40:14.404623Z', '0:00:03.753')])
Beispiel #3
0
    def test_validation_skip_on_specific_host(self, mock_tmp, mock_ansible_run,
                                              mock_validation_play):
        mock_ansible_run.return_value = ('fake.yaml', 0, 'successful')
        run_called_args = {
            'workdir': '/tmp/',
            'playbook': '/tmp/foo/fake.yaml',
            'base_dir': '/usr/share/ansible/',
            'playbook_dir': '/tmp/foo',
            'parallel_run': True,
            'inventory': 'tmp/inventory.yaml',
            'output_callback': 'validation_stdout',
            'quiet': True,
            'extra_vars': None,
            'limit_hosts': '!cloud1',
            'ansible_artifact_path': '/tmp/',
            'extra_env_variables': None,
            'ansible_cfg': None,
            'gathering_policy': 'explicit',
            'log_path': None,
            'run_async': False,
            'python_interpreter': None
        }

        playbook = ['fake.yaml']
        inventory = 'tmp/inventory.yaml'
        skip_list = {'fake': {'hosts': 'cloud1', 'reason': None, 'lp': None}}

        run = ValidationActions()
        run_return = run.run_validations(playbook,
                                         inventory,
                                         validations_dir='/tmp/foo',
                                         skip_list=skip_list,
                                         limit_hosts=None)
        mock_ansible_run.assert_called_with(**run_called_args)
Beispiel #4
0
 def take_action(self, parsed_args):
     """Take validation action"""
     # Get parameters:
     inventory = parsed_args.inventory
     group = parsed_args.group
     validation_name = parsed_args.validation_name
     quiet = parsed_args.quiet
     validation_dir = parsed_args.validation_dir
     ansible_base_dir = parsed_args.ansible_base_dir
     extra_vars = parsed_args.extra_vars
     if extra_vars:
         try:
             extra_vars = dict(e.split("=") for e in parsed_args.extra_vars)
         except ValueError:
             msg = "extra vars option should be formed as: KEY=VALUE."
             raise RuntimeError(msg)
     v_actions = ValidationActions(validation_path=validation_dir,
                                   group=group)
     try:
         results = v_actions.run_validations(
             inventory=inventory,
             group=group,
             validation_name=validation_name,
             base_dir=ansible_base_dir,
             extra_vars=extra_vars,
             quiet=quiet)
     except RuntimeError as e:
         sys.exit(e)
     if results:
         if parsed_args.output_log:
             self._write_output(parsed_args.output_log, results)
         else:
             self._print_dict_table(results)
Beispiel #5
0
 def test_show_history_all(self, mock_open, mock_load, mock_get_log):
     v_actions = ValidationActions()
     col, values = v_actions.show_history()
     self.assertEqual(
         col, ('UUID', 'Validations', 'Status', 'Execution at', 'Duration'))
     self.assertEqual(
         values, [('008886df-d297-1eaa-2a74-000000000008', '512e', 'PASSED',
                   '2019-11-25T13:40:14.404623Z', '0:00:03.753')])
Beispiel #6
0
    def take_action(self, parsed_args):
        """Take validation action"""
        # Get parameters:
        validation_dir = parsed_args.validation_dir
        group = parsed_args.group

        v_actions = ValidationActions(validation_path=validation_dir)
        return v_actions.group_information(group)
Beispiel #7
0
 def test_group_information(self, mock_open, mock_yaml, mock_data):
     v_actions = ValidationActions()
     col, values = v_actions.group_information('512e')
     self.assertEqual(col,
                      ('Groups', 'Description', 'Number of Validations'))
     self.assertEqual(values, [('no-op', 'noop-foo', 2),
                               ('post', 'post-foo', 2),
                               ('pre', 'pre-foo', 2)])
Beispiel #8
0
    def take_action(self, parsed_args):
        """Take validation action"""

        group = parsed_args.group
        validation_dir = parsed_args.validation_dir

        v_actions = ValidationActions(validation_path=validation_dir)
        return (v_actions.list_validations(group))
Beispiel #9
0
    def test_validation_list(self, mock_validation_dir):
        validations_list = ValidationActions(fakes.GROUPS_LIST, '/tmp/foo')

        self.assertEqual(
            validations_list.list_validations(),
            (self.column_name, [('my_val1', 'My Validation One Name',
                                 ['prep', 'pre-deployment']),
                                ('my_val2', 'My Validation Two Name',
                                 ['prep', 'pre-introspection'])]))
 def test_show_validations_parameters(self, mock_open, mock_load,
                                      mock_get_param, mock_get_play):
     mock_get_param.return_value = {
         'foo': {
             'parameters': fakes.FAKE_METADATA
         }
     }
     v_actions = ValidationActions()
     result = v_actions.show_validations_parameters('foo')
     self.assertEqual(result, mock_get_param.return_value)
Beispiel #11
0
    def take_action(self, parsed_args):
        """Take validation action"""
        # Get parameters:
        validation_dir = parsed_args.validation_dir
        validation_name = parsed_args.validation_name

        v_actions = ValidationActions(validation_path=validation_dir)
        data = v_actions.show_validations(validation_name)

        if data:
            return data.keys(), data.values()
Beispiel #12
0
    def take_action(self, parsed_args):
        v_actions = ValidationActions(parsed_args.validation_dir)
        params = v_actions.show_validations_parameters(
            parsed_args.validation_name, parsed_args.group,
            parsed_args.format_output, parsed_args.download)

        if parsed_args.download:
            self.app.LOG.info(
                "The file {} has been created successfully".format(
                    parsed_args.download))
        return params.keys(), params.values()
Beispiel #13
0
    def test_validation_skip_validation(self, mock_validation_play):

        playbook = ['fake.yaml']
        inventory = 'tmp/inventory.yaml'
        skip_list = {'fake': {'hosts': 'ALL', 'reason': None, 'lp': None}}

        run = ValidationActions()
        run_return = run.run_validations(playbook,
                                         inventory,
                                         validations_dir='/tmp/foo',
                                         skip_list=skip_list,
                                         limit_hosts=None)
        self.assertEqual(run_return, [])
Beispiel #14
0
    def take_action(self, parsed_args):
        """Take validation action"""
        # Get parameters:
        group = parsed_args.group
        validation_dir = parsed_args.validation_dir

        v_actions = ValidationActions(validation_path=validation_dir,
                                      group=group)
        results = v_actions.list_validations()
        if results:
            if parsed_args.output_log:
                self._write_output(parsed_args.output_log, results)
            else:
                self._print_tuple_table(results)
Beispiel #15
0
    def take_action(self, parsed_args):

        if parsed_args.history_limit < 1:
            raise ValueError(
                ("Number <n> of the most recent runs must be > 0. "
                 "You have provided {}").format(parsed_args.history_limit))
        self.app.LOG.info(
            ("Limiting output to the maximum of "
             "{} last validations.").format(parsed_args.history_limit))

        actions = ValidationActions(parsed_args.validation_log_dir)

        return actions.show_history(validation_ids=parsed_args.validation,
                                    history_limit=parsed_args.history_limit)
Beispiel #16
0
    def take_action(self, parsed_args):
        """Take validation action"""
        # Get parameters:
        group = parsed_args.group
        validation_dir = parsed_args.validation_dir

        v_actions = ValidationActions(validation_path=validation_dir,
                                      group=group)
        results = v_actions.show_history(validation_name)
        if results:
            if parsed_args.output_log:
                self._write_output(parsed_args.output_log, results)
            else:
                self._print_tuple_table(data=results, status_col=2)
Beispiel #17
0
    def test_validation_run_no_validation(self, mock_get_val):
        playbook = ['fake.yaml']
        inventory = 'tmp/inventory.yaml'

        run = ValidationActions()
        self.assertRaises(RuntimeError, run.run_validations, playbook,
                          inventory)
Beispiel #18
0
 def test_validation_show(self, mock_exists, mock_open,
                          mock_parse_validation, mock_data, mock_log):
     data = {
         'Name': 'Advanced Format 512e Support',
         'Description': 'foo',
         'Groups': ['prep', 'pre-deployment'],
         'ID': '512e',
         'Parameters': {}
     }
     data.update({
         'Last execution date': '2019-11-25 13:40:14',
         'Number of execution': 'Total: 1, Passed: 0, Failed: 1'
     })
     validations_show = ValidationActions()
     out = validations_show.show_validations('512e')
     self.assertEqual(out, data)
Beispiel #19
0
    def test_validation_run_wrong_validation_name(self, mock_validation_play):
        mock_validation_play.return_value = []

        run = ValidationActions()
        self.assertRaises(RuntimeError,
                          run.run_validations,
                          validation_name='fake.yaml',
                          validations_dir='/tmp/foo')
Beispiel #20
0
    def test_validation_run_success(self, mock_tmp, mock_ansible_run,
                                    mock_validation_dir, mock_results):
        mock_validation_dir.return_value = [{
            'description':
            'My Validation One Description',
            'groups': ['prep', 'pre-deployment'],
            'id':
            'foo',
            'name':
            'My Validition One Name',
            'parameters': {}
        }]
        mock_ansible_run.return_value = ('foo.yaml', 0, 'successful')

        mock_results.return_value = [{
            'Duration': '0:00:01.761',
            'Host_Group': 'overcloud',
            'Status': 'PASSED',
            'Status_by_Host': 'subnode-1,PASSED',
            'UUID': 'foo',
            'Unreachable_Hosts': '',
            'Validations': 'ntp'
        }]
        expected_run_return = [{
            'Duration': '0:00:01.761',
            'Host_Group': 'overcloud',
            'Status': 'PASSED',
            'Status_by_Host': 'subnode-1,PASSED',
            'UUID': 'foo',
            'Unreachable_Hosts': '',
            'Validations': 'ntp'
        }]

        playbook = ['fake.yaml']
        inventory = 'tmp/inventory.yaml'

        run = ValidationActions()
        run_return = run.run_validations(playbook,
                                         inventory,
                                         group=fakes.GROUPS_LIST,
                                         validations_dir='/tmp/foo')
        self.assertEqual(run_return, expected_run_return)
Beispiel #21
0
 def test_show_validations_parameters_non_supported_format(self, mock_open):
     v_actions = ValidationActions()
     self.assertRaises(RuntimeError,
                       v_actions.show_validations_parameters,
                       validation='foo',
                       output_format='bar')
Beispiel #22
0
 def test_get_status_no_param(self):
     v_actions = ValidationActions()
     self.assertRaises(RuntimeError, v_actions.get_status)
Beispiel #23
0
 def take_action(self, parsed_args):
     actions = ValidationActions(parsed_args.validation_dir)
     return actions.show_history(parsed_args.validation)
Beispiel #24
0
 def test_validation_show_not_found(self, mock_exists):
     validations_show = ValidationActions()
     self.assertRaises(RuntimeError, validations_show.show_validations,
                       '512e')