示例#1
0
 def test_stack_show_output(self):
     scenario = utils.HeatScenario(self.context)
     scenario._stack_show_output(self.stack, self.default_output_key)
     self.clients("heat").stacks.output_show.assert_called_once_with(
         self.stack.id, self.default_output_key)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.show_output")
示例#2
0
 def test_stack_list_output_via_API(self):
     scenario = utils.HeatScenario(self.context)
     scenario._stack_list_output_via_API(self.stack)
     self.clients("heat").stacks.get.assert_called_once_with(
         stack_id=self.stack.id)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.list_output_via_API")
示例#3
0
    def test_stack_webhook_insecure(self, mock_post):
        env_context = {
            "env": {
                "spec": {
                    "existing@openstack": {
                        "https_cacert": "cacert.crt",
                        "https_insecure": True
                    }
                }
            }
        }
        env_context.update(self.context)
        scenario = utils.HeatScenario(env_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", verify=False)
        self._test_atomic_action_timer(scenario.atomic_actions(),
                                       "heat.output1_webhook")
示例#4
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")
示例#5
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"}
     self.default_output_key = "dummy_output_key"
示例#6
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)
示例#7
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))
示例#8
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")
示例#9
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_status.mock.assert_called_once_with(
         self.stack,
         update_resource=self.mock_get_from_manager.mock.return_value,
         ready_statuses=["CHECK_COMPLETE"],
         failure_statuses=["CHECK_FAILED", "ERROR"],
         check_interval=CONF.openstack.heat_stack_check_poll_interval,
         timeout=CONF.openstack.heat_stack_check_timeout)
     self._test_atomic_action_timer(scenario.atomic_actions(),
                                    "heat.check_stack")
示例#10
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")
示例#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))
示例#12
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=["DELETE_COMPLETE"],
         failure_statuses=["DELETE_FAILED", "ERROR"],
         check_deletion=True,
         update_resource=self.mock_get_from_manager.mock.return_value,
         check_interval=CONF.openstack.heat_stack_delete_poll_interval,
         timeout=CONF.openstack.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")
示例#13
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,
             "task":
             self.context["task"],
             "owner_id":
             self.context["owner_id"]
         })
         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)
示例#14
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", "ERROR"],
            update_resource=self.mock_get_from_manager.mock.return_value,
            timeout=CONF.openstack.heat_stack_scale_timeout,
            check_interval=CONF.openstack.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")
示例#15
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_status.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", "ERROR"],
         check_interval=CONF.openstack.heat_stack_update_poll_interval,
         timeout=CONF.openstack.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")
示例#16
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])