Merge "Implement Virtual Switch resilience test case"
[yardstick.git] / yardstick / tests / unit / benchmark / core / test_task.py
index 253e9d8..9e8e4e9 100644 (file)
@@ -66,7 +66,7 @@ class TaskTestCase(unittest.TestCase):
 
         mock_dispatcher.get = mock.MagicMock(return_value=[dispatcher1,
                                                            dispatcher2])
-        self.assertEqual(None, t._do_output(output_config, {}))
+        self.assertIsNone(t._do_output(output_config, {}))
 
     @mock.patch.object(task, 'Context')
     def test_parse_networks_from_nodes(self, mock_context):
@@ -153,7 +153,7 @@ class TaskTestCase(unittest.TestCase):
         runner.get_result.return_value = []
         mock_base_runner.Runner.get.return_value = runner
         t._run([scenario], False, "yardstick.out")
-        self.assertTrue(runner.run.called)
+        runner.run.assert_called_once()
 
     @mock.patch.object(os, 'environ')
     def test_check_precondition(self, mock_os_environ):
@@ -264,6 +264,38 @@ class TaskTestCase(unittest.TestCase):
         actual_result = t._parse_options(options)
         self.assertEqual(expected_result, actual_result)
 
+    def test_parse_options_no_teardown(self):
+        options = {
+            'openstack': {
+                'EXTERNAL_NETWORK': '$network'
+            },
+            'nodes': ['node1', '$node'],
+            'host': '$host',
+            'contexts' : {'name': "my-context",
+                          'no_teardown': True}
+        }
+
+        t = task.Task()
+        t.outputs = {
+            'network': 'ext-net',
+            'node': 'node2',
+            'host': 'server.yardstick'
+        }
+
+        expected_result = {
+            'openstack': {
+                'EXTERNAL_NETWORK': 'ext-net'
+            },
+            'nodes': ['node1', 'node2'],
+            'host': 'server.yardstick',
+            'contexts': {'name': 'my-context',
+                         'no_teardown': True,
+                        }
+        }
+
+        actual_result = t._parse_options(options)
+        self.assertEqual(expected_result, actual_result)
+
     @mock.patch('six.moves.builtins.open', side_effect=mock.mock_open())
     @mock.patch.object(task, 'utils')
     @mock.patch('logging.root')
@@ -389,6 +421,34 @@ key2:
         self.parser._change_node_names(scenario, [my_context])
         self.assertEqual(scenario, expected_scenario)
 
+    def test__change_node_names_options_empty(self):
+        ctx_attrs = {
+            'name': 'demo',
+            'task_id': '1234567890'
+        }
+
+        my_context = dummy.DummyContext()
+        my_context.init(ctx_attrs)
+        scenario = copy.deepcopy(self.scenario)
+        scenario['options'] = None
+
+        self.parser._change_node_names(scenario, [my_context])
+        self.assertIsNone(scenario['options'])
+
+    def test__change_node_names_options_server_name_empty(self):
+        ctx_attrs = {
+            'name': 'demo',
+            'task_id': '1234567890'
+        }
+
+        my_context = dummy.DummyContext()
+        my_context.init(ctx_attrs)
+        scenario = copy.deepcopy(self.scenario)
+        scenario['options']['server_name'] = None
+
+        self.parser._change_node_names(scenario, [my_context])
+        self.assertIsNone(scenario['options']['server_name'])
+
     def test__parse_tasks(self):
         task_obj = task.Task()
         _uuid = uuid.uuid4()