Merge "Propose the backporting process"
[yardstick.git] / yardstick / tests / unit / benchmark / core / test_task.py
index 82a90b1..3523663 100644 (file)
@@ -17,6 +17,7 @@ import six
 import unittest
 import uuid
 
+from yardstick.benchmark.contexts import base
 from yardstick.benchmark.contexts import dummy
 from yardstick.benchmark.core import task
 from yardstick.common import constants as consts
@@ -27,7 +28,7 @@ from yardstick.common import utils
 
 class TaskTestCase(unittest.TestCase):
 
-    @mock.patch.object(task, 'Context')
+    @mock.patch.object(base, 'Context')
     def test_parse_nodes_with_context_same_context(self, mock_context):
         scenario_cfg = {
             "nodes": {
@@ -68,7 +69,7 @@ class TaskTestCase(unittest.TestCase):
                                                            dispatcher2])
         self.assertIsNone(t._do_output(output_config, {}))
 
-    @mock.patch.object(task, 'Context')
+    @mock.patch.object(base, 'Context')
     def test_parse_networks_from_nodes(self, mock_context):
         nodes = {
             'node1': {
@@ -132,7 +133,7 @@ class TaskTestCase(unittest.TestCase):
         self.assertEqual(mock_context.get_network.call_count, expected_get_network_calls)
         self.assertDictEqual(networks, expected)
 
-    @mock.patch.object(task, 'Context')
+    @mock.patch.object(base, 'Context')
     @mock.patch.object(task, 'base_runner')
     def test_run(self, mock_base_runner, *args):
         scenario = {
@@ -153,7 +154,32 @@ 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(base, 'Context')
+    @mock.patch.object(task, 'base_runner')
+    def test_run_ProxDuration(self, mock_base_runner, *args):
+        scenario = {
+            'host': 'athena.demo',
+            'target': 'ares.demo',
+            'runner': {
+                'duration': 60,
+                'interval': 1,
+                'sampled': 'yes',
+                'confirmation': 1,
+                'type': 'ProxDuration'
+            },
+            'type': 'Ping'
+        }
+
+        t = task.Task()
+        runner = mock.Mock()
+        runner.join.return_value = 0
+        runner.get_output.return_value = {}
+        runner.get_result.return_value = []
+        mock_base_runner.Runner.get.return_value = runner
+        t._run([scenario], False, "yardstick.out")
+        runner.run.assert_called_once()
 
     @mock.patch.object(os, 'environ')
     def test_check_precondition(self, mock_os_environ):
@@ -357,6 +383,12 @@ key2:
                 }
             }
 
+    @staticmethod
+    def _remove_contexts():
+        for context in base.Context.list:
+            context._delete_context()
+        base.Context.list = []
+
     def test__change_node_names(self):
 
         ctx_attrs = {
@@ -371,6 +403,7 @@ key2:
             }
 
         my_context = dummy.DummyContext()
+        self.addCleanup(self._remove_contexts)
         my_context.init(ctx_attrs)
 
         expected_scenario = {
@@ -413,6 +446,7 @@ key2:
             }
 
         my_context = dummy.DummyContext()
+        self.addCleanup(self._remove_contexts)
         my_context.init(ctx_attrs)
 
         scenario = copy.deepcopy(self.scenario)
@@ -421,6 +455,36 @@ 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()
+        self.addCleanup(self._remove_contexts)
+        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()
+        self.addCleanup(self._remove_contexts)
+        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()