diff options
-rw-r--r-- | yardstick/benchmark/contexts/heat.py | 22 | ||||
-rw-r--r-- | yardstick/common/exceptions.py | 4 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/contexts/test_heat.py | 32 |
3 files changed, 49 insertions, 9 deletions
diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 1e2537738..8dd7d85e6 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -25,6 +25,7 @@ from yardstick.benchmark.contexts.model import Network from yardstick.benchmark.contexts.model import PlacementGroup, ServerGroup from yardstick.benchmark.contexts.model import Server from yardstick.benchmark.contexts.model import update_scheduler_hints +from yardstick.common import exceptions as y_exc from yardstick.common.openstack_utils import get_neutron_client from yardstick.orchestrator.heat import HeatTemplate, get_short_key_uuid from yardstick.common import constants as consts @@ -297,6 +298,17 @@ class HeatContext(Context): network.network_type = neutron_net.get('provider:network_type') network.neutron_info = neutron_net + def _create_new_stack(self, heat_template): + try: + return heat_template.create(block=True, + timeout=self.heat_timeout) + except KeyboardInterrupt: + raise y_exc.StackCreationInterrupt + except: + LOG.exception("stack failed") + # let the other failures happen, we want stack trace + raise + def deploy(self): """deploys template into a stack using cloud""" LOG.info("Deploying context '%s' START", self.name) @@ -307,15 +319,7 @@ class HeatContext(Context): if self.template_file is None: self._add_resources_to_template(heat_template) - try: - self.stack = heat_template.create(block=True, - timeout=self.heat_timeout) - except KeyboardInterrupt: - raise SystemExit("\nStack create interrupted") - except Exception: - LOG.exception("stack failed") - # let the other failures happen, we want stack trace - raise + self.stack = self._create_new_stack(heat_template) # TODO: use Neutron to get segmentation-id self.get_neutron_info() diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py index 4f89fed32..2af4c6343 100644 --- a/yardstick/common/exceptions.py +++ b/yardstick/common/exceptions.py @@ -74,3 +74,7 @@ class DPDKSetupDriverError(YardstickException): class ScenarioConfigContextNameNotFound(YardstickException): message = 'Context name "%(context_name)s" not found' + + +class StackCreationInterrupt(YardstickException): + message = 'Stack create interrupted.' 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' |