Ejemplo n.º 1
0
    def test_stack_webhook_invalid_output_key(self, mock_post):
        scenario = utils.HeatScenario(self.context)
        stack = mock.Mock()
        stack.outputs = [{"output_key": "output1", "output_value": "url1"},
                         {"output_key": "output2", "output_value": "url2"}]

        self.assertRaises(exceptions.InvalidConfigException,
                          scenario._stack_webhook, stack, "bogus")
Ejemplo n.º 2
0
 def setUp(self):
     super(HeatScenarioTestCase, self).setUp()
     self.stack = mock.Mock()
     self.scenario = utils.HeatScenario(self.context)
     self.default_template = "heat_template_version: 2013-05-23"
     self.dummy_parameters = {"dummy_param": "dummy_key"}
     self.dummy_files = ["dummy_file.yaml"]
     self.dummy_environment = {"dummy_env": "dummy_env_value"}
Ejemplo n.º 3
0
 def test_list_stacks(self):
     scenario = utils.HeatScenario(self.context)
     return_stacks_list = scenario._list_stacks()
     self.clients("heat").stacks.list.assert_called_once_with()
     self.assertEqual(list(self.clients("heat").stacks.list.return_value),
                      return_stacks_list)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.list_stacks")
Ejemplo n.º 4
0
 def test_stack_show_output_via_API(self):
     scenario = utils.HeatScenario(self.context)
     scenario._stack_show_output_via_API(self.stack,
                                         self.default_output_key)
     self.clients("heat").stacks.get.assert_called_once_with(
         stack_id=self.stack.id)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.show_output_via_API")
Ejemplo n.º 5
0
 def test__count_instances(self):
     self.clients("heat").resources.list.return_value = [
         mock.Mock(resource_type="OS::Nova::Server"),
         mock.Mock(resource_type="OS::Nova::Server"),
         mock.Mock(resource_type="OS::Heat::AutoScalingGroup")
     ]
     scenario = utils.HeatScenario(self.context)
     self.assertEqual(scenario._count_instances(self.stack), 2)
     self.clients("heat").resources.list.assert_called_once_with(
         self.stack.id, nested_depth=1)
Ejemplo n.º 6
0
 def setup(self):
     template = self._prepare_stack_template(
         self.config["resources_per_stack"])
     for user, tenant_id in rutils.iterate_per_tenants(
             self.context["users"]):
         heat_scenario = heat_utils.HeatScenario({"user": user})
         self.context["tenants"][tenant_id]["stacks"] = []
         for i in range(self.config["stacks_per_tenant"]):
             stack = heat_scenario._create_stack(template)
             self.context["tenants"][tenant_id]["stacks"].append(stack.id)
Ejemplo n.º 7
0
    def test_stack_webhook(self, mock_post):
        scenario = utils.HeatScenario(self.context)
        stack = mock.Mock(outputs=[
            {"output_key": "output1", "output_value": "url1"},
            {"output_key": "output2", "output_value": "url2"}])

        scenario._stack_webhook(stack, "output1")
        mock_post.assert_called_with("url1")
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "heat.output1_webhook")
Ejemplo n.º 8
0
 def test_failed_update_stack(self):
     stack = mock.Mock()
     resource = mock.Mock()
     resource.stack_status = "UPDATE_FAILED"
     stack.manager.get.return_value = resource
     self.clients("heat").stacks.get.return_value = stack
     scenario = utils.HeatScenario(context=self.context)
     ex = self.assertRaises(exceptions.GetResourceErrorStatus,
                            scenario._update_stack, stack,
                            "heat_template_version: 2013-05-23")
     self.assertIn("has UPDATE_FAILED status", str(ex))
Ejemplo n.º 9
0
 def test_delete_stack(self):
     scenario = utils.HeatScenario()
     scenario._delete_stack(self.stack)
     self.stack.delete.assert_called_once_with()
     self.wait_for_delete.mock.assert_called_once_with(
         self.stack,
         update_resource=self.gfm(),
         check_interval=CONF.benchmark.heat_stack_delete_poll_interval,
         timeout=CONF.benchmark.heat_stack_delete_timeout)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.delete_stack")
Ejemplo n.º 10
0
 def test_check_stack(self):
     scenario = utils.HeatScenario(self.context)
     scenario._check_stack(self.stack)
     self.clients("heat").actions.check.assert_called_once_with(
         self.stack.id)
     self.mock_wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.mock_get_from_manager.mock.return_value,
         ready_statuses=["CHECK_COMPLETE"],
         check_interval=CONF.benchmark.heat_stack_check_poll_interval,
         timeout=CONF.benchmark.heat_stack_check_timeout)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.check_stack")
Ejemplo n.º 11
0
 def test_failed_create_stack(self):
     self.clients("heat").stacks.create.return_value = {
         "stack": {"id": "test_id"}
     }
     stack = mock.Mock()
     resource = mock.Mock()
     resource.stack_status = "CREATE_FAILED"
     stack.manager.get.return_value = resource
     self.clients("heat").stacks.get.return_value = stack
     scenario = utils.HeatScenario(context=self.context)
     ex = self.assertRaises(exceptions.GetResourceErrorStatus,
                            scenario._create_stack, "stack_name")
     self.assertIn("has CREATE_FAILED status", str(ex))
Ejemplo n.º 12
0
 def test_snapshot_stack(self):
     scenario = utils.HeatScenario()
     scenario._snapshot_stack(self.stack)
     self.clients("heat").stacks.snapshot.assert_called_once_with(
         self.stack.id)
     self.wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.gfm(),
         is_ready=self.res_is.mock(),
         check_interval=CONF.benchmark.heat_stack_snapshot_poll_interval,
         timeout=CONF.benchmark.heat_stack_snapshot_timeout)
     self.res_is.mock.assert_has_calls([mock.call("SNAPSHOT_COMPLETE")])
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.snapshot_stack")
Ejemplo n.º 13
0
 def test_delete_stack(self):
     scenario = utils.HeatScenario(self.context)
     scenario._delete_stack(self.stack)
     self.stack.delete.assert_called_once_with()
     self.mock_wait_for_status.mock.assert_called_once_with(
         self.stack,
         ready_statuses=["deleted"],
         check_deletion=True,
         update_resource=self.mock_get_from_manager.mock.return_value,
         check_interval=CONF.benchmark.heat_stack_delete_poll_interval,
         timeout=CONF.benchmark.heat_stack_delete_timeout)
     self.mock_get_from_manager.mock.assert_called_once_with()
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.delete_stack")
Ejemplo n.º 14
0
 def test_restore_stack(self):
     scenario = utils.HeatScenario()
     scenario._restore_stack(self.stack, "dummy_id")
     self.clients("heat").stacks.restore.assert_called_once_with(
         self.stack.id, "dummy_id")
     self.wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.gfm(),
         is_ready=self.res_is.mock(),
         check_interval=CONF.benchmark.heat_stack_restore_poll_interval,
         timeout=CONF.benchmark.heat_stack_restore_timeout)
     self.res_is.mock.assert_has_calls([mock.call("RESTORE_COMPLETE")])
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.restore_stack")
Ejemplo n.º 15
0
 def test_restore_stack(self):
     scenario = utils.HeatScenario(self.context)
     scenario._restore_stack(self.stack, "dummy_id")
     self.clients("heat").stacks.restore.assert_called_once_with(
         self.stack.id, "dummy_id")
     self.mock_wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.mock_get_from_manager.mock.return_value,
         ready_statuses=["RESTORE_COMPLETE"],
         failure_statuses=["RESTORE_FAILED"],
         check_interval=CONF.benchmark.heat_stack_restore_poll_interval,
         timeout=CONF.benchmark.heat_stack_restore_timeout)
     self.mock_get_from_manager.mock.assert_called_once_with()
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.restore_stack")
Ejemplo n.º 16
0
 def test_snapshot_stack(self):
     scenario = utils.HeatScenario(self.context)
     scenario._snapshot_stack(self.stack)
     self.clients("heat").stacks.snapshot.assert_called_once_with(
         self.stack.id)
     self.mock_wait_for_status.mock.assert_called_once_with(
         self.stack,
         update_resource=self.mock_get_from_manager.mock.return_value,
         ready_statuses=["SNAPSHOT_COMPLETE"],
         failure_statuses=["SNAPSHOT_FAILED", "ERROR"],
         check_interval=CONF.openstack.heat_stack_snapshot_poll_interval,
         timeout=CONF.openstack.heat_stack_snapshot_timeout)
     self.mock_get_from_manager.mock.assert_called_once_with()
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.snapshot_stack")
Ejemplo n.º 17
0
 def test_snapshot_stack(self):
     scenario = utils.HeatScenario(self.context)
     scenario._snapshot_stack(self.stack)
     self.clients("heat").stacks.snapshot.assert_called_once_with(
         self.stack.id)
     self.mock_wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.mock_get_from_manager.mock.return_value,
         is_ready=self.mock_resource_is.mock.return_value,
         check_interval=CONF.benchmark.heat_stack_snapshot_poll_interval,
         timeout=CONF.benchmark.heat_stack_snapshot_timeout)
     self.mock_resource_is.mock.assert_called_once_with("SNAPSHOT_COMPLETE")
     self.mock_get_from_manager.mock.assert_called_once_with(
         ["SNAPSHOT_FAILED"])
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.snapshot_stack")
Ejemplo n.º 18
0
 def setUp(self):
     super(HeatScenarioTestCase, self).setUp()
     self.stack = mock.Mock()
     self.res_is = mockpatch.Patch(BM_UTILS + ".resource_is")
     self.get_fm = mockpatch.Patch(BM_UTILS + ".get_from_manager")
     self.wait_for = mockpatch.Patch(HEAT_UTILS + ".bench_utils.wait_for")
     self.wait_for_delete = mockpatch.Patch(HEAT_UTILS +
                                            ".bench_utils.wait_for_delete")
     self.useFixture(self.wait_for)
     self.useFixture(self.wait_for_delete)
     self.useFixture(self.res_is)
     self.useFixture(self.get_fm)
     self.gfm = self.get_fm.mock
     self.useFixture(mockpatch.Patch("time.sleep"))
     self.scenario = utils.HeatScenario()
     self.default_template = "heat_template_version: 2013-05-23"
     self.dummy_parameters = {"dummy_param": "dummy_key"}
     self.dummy_files = ["dummy_file.yaml"]
     self.dummy_environment = {"dummy_env": "dummy_env_value"}
Ejemplo n.º 19
0
    def test__scale_stack(self):
        scenario = utils.HeatScenario(self.context)
        scenario._count_instances = mock.Mock(side_effect=[3, 3, 2])
        scenario._stack_webhook = mock.Mock()

        scenario._scale_stack(self.stack, "test_output_key", -1)

        scenario._stack_webhook.assert_called_once_with(
            self.stack, "test_output_key")
        self.mock_wait_for.mock.assert_called_once_with(
            self.stack,
            is_ready=mock.ANY,
            failure_statuses=["UPDATE_FAILED"],
            update_resource=self.mock_get_from_manager.mock.return_value,
            timeout=CONF.benchmark.heat_stack_scale_timeout,
            check_interval=CONF.benchmark.heat_stack_scale_poll_interval)
        self.mock_get_from_manager.mock.assert_called_once_with()

        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "heat.scale_with_test_output_key")
Ejemplo n.º 20
0
 def test_update_stack(self):
     self.clients("heat").stacks.update.return_value = None
     scenario = utils.HeatScenario()
     scenario._update_stack(self.stack, self.default_template,
                            self.dummy_parameters, self.dummy_files,
                            self.dummy_environment)
     args, kwargs = self.clients("heat").stacks.update.call_args
     self.assertIn(self.dummy_parameters, kwargs.values())
     self.assertIn(self.default_template, kwargs.values())
     self.assertIn(self.dummy_files, kwargs.values())
     self.assertIn(self.dummy_environment, kwargs.values())
     self.assertIn(self.stack.id, args)
     self.wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.gfm(),
         is_ready=self.res_is.mock(),
         check_interval=CONF.benchmark.heat_stack_update_poll_interval,
         timeout=CONF.benchmark.heat_stack_update_timeout)
     self.res_is.mock.assert_has_calls([mock.call("UPDATE_COMPLETE")])
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.update_stack")
Ejemplo n.º 21
0
 def test_update_stack(self):
     self.clients("heat").stacks.update.return_value = None
     scenario = utils.HeatScenario(self.context)
     scenario._update_stack(self.stack, self.default_template,
                            self.dummy_parameters, self.dummy_files,
                            self.dummy_environment)
     args, kwargs = self.clients("heat").stacks.update.call_args
     self.assertIn(self.dummy_parameters, kwargs.values())
     self.assertIn(self.default_template, kwargs.values())
     self.assertIn(self.dummy_files, kwargs.values())
     self.assertIn(self.dummy_environment, kwargs.values())
     self.assertIn(self.stack.id, args)
     self.mock_wait_for.mock.assert_called_once_with(
         self.stack,
         update_resource=self.mock_get_from_manager.mock.return_value,
         ready_statuses=["UPDATE_COMPLETE"],
         failure_statuses=["UPDATE_FAILED"],
         check_interval=CONF.benchmark.heat_stack_update_poll_interval,
         timeout=CONF.benchmark.heat_stack_update_timeout)
     self.mock_get_from_manager.mock.assert_called_once_with()
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.update_stack")
Ejemplo n.º 22
0
 def setup(self):
     template = get_data(self.config["template"])
     files = {}
     for key, filename in self.config.get("files", {}).items():
         files[key] = get_data(filename)
     parameters = self.config.get("parameters", rutils.LockedDict())
     with parameters.unlocked():
         if "network_id" not in parameters:
             parameters["network_id"] = self._get_public_network_id()
         for user, tenant_id in rutils.iterate_per_tenants(
                 self.context["users"]):
             for name, path in self.config.get("context_parameters",
                                               {}).items():
                 parameters[name] = self._get_context_parameter(
                     user, tenant_id, path)
             if "router_id" not in parameters:
                 networks = self.context["tenants"][tenant_id]["networks"]
                 parameters["router_id"] = networks[0]["router_id"]
             if "key_name" not in parameters:
                 parameters["key_name"] = user["keypair"]["name"]
             heat_scenario = heat_utils.HeatScenario({
                 "user":
                 user,
                 "task":
                 self.context["task"],
                 "owner_id":
                 self.context["owner_id"]
             })
             self.context["tenants"][tenant_id]["stack_dataplane"] = []
             for i in range(self.config["stacks_per_tenant"]):
                 stack = heat_scenario._create_stack(template,
                                                     files=files,
                                                     parameters=parameters)
                 tenant_data = self.context["tenants"][tenant_id]
                 tenant_data["stack_dataplane"].append(
                     [stack.id, template, files, parameters])