Beispiel #1
0
    def test__render_task_arguments(self):
        task_parser = task.TaskParser('task_file')
        task_str = io.StringIO(six.text_type(self.TASK))
        with mock.patch.object(six.moves.builtins, 'open',
                               return_value=task_str) as mock_open:
            parsed, rendered = task_parser._render_task('value1: "var1"', None)

        self.assertEqual(self.TASK_RENDERED_1, rendered)
        self.assertEqual({'key1': 'var1', 'key2': ['var2']}, parsed)
        mock_open.assert_called_once_with('task_file')
Beispiel #2
0
    def test__render_task_error_task_file(self):
        task_parser = task.TaskParser('task_file')
        with mock.patch.object(six.moves.builtins, 'open') as mock_open:
            mock_open.side_effect = (io.StringIO(
                six.text_type('value2: var4')), IOError())
            with self.assertRaises(exceptions.TaskReadError):
                task_parser._render_task('value1: "var3"', 'args_file')

        mock_open.assert_has_calls(
            [mock.call('args_file'),
             mock.call('task_file')])
Beispiel #3
0
    def test__render_task_file_arguments(self):
        task_parser = task.TaskParser('task_file')
        with mock.patch.object(six.moves.builtins, 'open') as mock_open:
            mock_open.side_effect = (
                io.StringIO(six.text_type('value2: var4')),
                io.StringIO(six.text_type(self.TASK))
            )
            parsed, rendered = task_parser._render_task('value1: "var3"',
                                                        'args_file')

        self.assertEqual(self.TASK_RENDERED_2, rendered)
        self.assertEqual({'key1': 'var3', 'key2': ['var4']}, parsed)
        mock_open.assert_has_calls([mock.call('args_file'),
                                    mock.call('task_file')])
Beispiel #4
0
 def test_parse_suite_with_constraint_no_args(self):
     SAMPLE_SCENARIO_PATH = "with_constraint_no_args_scenario_sample.yaml"
     t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
     with mock.patch.object(os, 'environ',
                     new={'NODE_NAME': 'huawei-pod1', 'INSTALLER_TYPE': 'compass'}):
         task_files, task_args, task_args_fnames = t.parse_suite()
     self.assertEqual(task_files[0], self.change_to_abspath(
                      'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
     self.assertEqual(task_files[1], self.change_to_abspath(
                      'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
     self.assertIsNone(task_args[0])
     self.assertIsNone(task_args[1])
     self.assertIsNone(task_args_fnames[0])
     self.assertIsNone(task_args_fnames[1])
Beispiel #5
0
    def test_check_precondition(self, mock_os):
        cfg = {
            'precondition': {
                'installer_type': 'compass',
                'deploy_scenarios': 'os-nosdn',
                'pod_name': 'huawei-pod1'
            }
        }

        t = task.TaskParser('/opt')
        mock_os.environ.get.side_effect = [
            'compass', 'os-nosdn', 'huawei-pod1'
        ]
        result = t._check_precondition(cfg)
        self.assertTrue(result)
Beispiel #6
0
 def test_parse_suite_no_constraint_no_args(self, mock_environ):
     SAMPLE_SCENARIO_PATH = "no_constraint_no_args_scenario_sample.yaml"
     t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
     mock_environ.get.side_effect = ['huawei-pod1', 'compass']
     task_files, task_args, task_args_fnames = t.parse_suite()
     print("files=%s, args=%s, fnames=%s" %
           (task_files, task_args, task_args_fnames))
     self.assertEqual(task_files[0],
                      'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
     self.assertEqual(task_files[1],
                      'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
     self.assertEqual(task_args[0], None)
     self.assertEqual(task_args[1], None)
     self.assertEqual(task_args_fnames[0], None)
     self.assertEqual(task_args_fnames[1], None)
Beispiel #7
0
    def test__render_task_render_error(self):
        task_parser = task.TaskParser('task_file')
        with mock.patch.object(six.moves.builtins, 'open') as mock_open, \
                mock.patch.object(task_template.TaskTemplate, 'render',
                                  side_effect=TypeError) as mock_render:
            mock_open.side_effect = (
                io.StringIO(six.text_type('value2: var4')),
                io.StringIO(six.text_type(self.TASK))
            )
            with self.assertRaises(exceptions.TaskRenderError):
                task_parser._render_task('value1: "var3"', 'args_file')

        mock_open.assert_has_calls([mock.call('args_file'),
                                    mock.call('task_file')])
        mock_render.assert_has_calls(
            [mock.call(self.TASK, value1='var3', value2='var4')])
Beispiel #8
0
 def setUp(self):
     self.parser = task.TaskParser('fake/path')
     self.scenario = {
         'host': 'athena.demo',
         'target': 'kratos.demo',
         'targets': ['ares.demo', 'mars.demo'],
         'options': {
             'server_name': {
                 'host': 'jupiter.demo',
                 'target': 'saturn.demo',
             },
         },
         'nodes': {
             'tg__0': 'tg_0.demo',
             'vnf__0': 'vnf_0.demo',
         }
     }
Beispiel #9
0
 def test_parse_suite_with_constraint_no_args(self, mock_environ):
     SAMPLE_SCENARIO_PATH = "with_constraint_no_args_scenario_sample.yaml"
     t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
     with mock.patch('yardstick.benchmark.core.task.os.environ',
                     new={
                         'NODE_NAME': 'huawei-pod1',
                         'INSTALLER_TYPE': 'compass'
                     }):
         task_files, task_args, task_args_fnames = t.parse_suite()
     print("files=%s, args=%s, fnames=%s" %
           (task_files, task_args, task_args_fnames))
     self.assertEqual(
         task_files[0],
         self.change_to_abspath(
             'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
     self.assertEqual(
         task_files[1],
         self.change_to_abspath(
             'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
     self.assertEqual(task_args[0], None)
     self.assertEqual(task_args[1], None)
     self.assertEqual(task_args_fnames[0], None)
     self.assertEqual(task_args_fnames[1], None)
Beispiel #10
0
 def test__render_task_error_arguments(self):
     with self.assertRaises(exceptions.TaskRenderArgumentError):
         task.TaskParser('task_file')._render_task('value1="var3"', None)