aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit
diff options
context:
space:
mode:
authorEmma Foley <emma.l.foley@intel.com>2018-02-21 12:36:15 +0000
committerEmma Foley <emma.l.foley@intel.com>2018-03-01 15:02:27 +0000
commit4a21b4a434d5a60cb57dce576365dc6a9a6825b5 (patch)
treec60965c749f62347c2f86631049b3bed6b3aee0e /yardstick/tests/unit
parent1681ba53783835e500e602a1b7500e0221eb08f9 (diff)
Add _create_new_stack method
The logic for creating a new stack in contexts/heat.py:HeatContext can added to a method to make the code eassier to read and test. This is in preparation for an update to deploy() that would allow an existing stack to be reused, or a new stack created. By having the create_new_stack logic in a new method, deploy() becomes easier to read and test. JIRA: YARDSTICK-886 Change-Id: I7af01e2209a3460658f8db0249b7c620743cced0 Signed-off-by: Emma Foley <emma.l.foley@intel.com>
Diffstat (limited to 'yardstick/tests/unit')
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py
index baf9f40f8..2f2d4643e 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_heat.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py
@@ -21,6 +21,8 @@ import unittest
from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import heat
from yardstick.benchmark.contexts import model
+from yardstick.common import exceptions as y_exc
+from yardstick.orchestrator import heat as orch_heat
LOG = logging.getLogger(__name__)
@@ -186,6 +188,36 @@ class HeatContextTestCase(unittest.TestCase):
with self.assertRaises(AttributeError):
self.test_context.user = 'foo'
+ def test__create_new_stack(self):
+ template = mock.Mock()
+ self.test_context._create_new_stack(template)
+ template.create.assert_called_once()
+
+ def test__create_new_stack_stack_create_failed(self):
+ template = mock.Mock()
+ template.create.side_effect = y_exc.HeatTemplateError
+
+ self.assertRaises(y_exc.HeatTemplateError,
+ self.test_context._create_new_stack,
+ template)
+
+ def test__create_new_stack_keyboard_interrupt(self):
+ template = mock.Mock()
+ template.create.side_effect = KeyboardInterrupt
+ self.assertRaises(y_exc.StackCreationInterrupt,
+ self.test_context._create_new_stack,
+ template)
+
+ @mock.patch.object(orch_heat.HeatTemplate, 'add_keypair')
+ @mock.patch.object(heat.HeatContext, '_create_new_stack')
+ def test_deploy_stack_creation_failed(self, mock_create, *args):
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = 'foo-12345678'
+ mock_create.side_effect = y_exc.HeatTemplateError
+ self.assertRaises(y_exc.HeatTemplateError,
+ self.test_context.deploy)
+
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test_deploy(self, mock_template):
self.test_context._name = 'foo'