From b889260732d2ed4b101d6d306d6c660baff92a42 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Fri, 12 Apr 2019 23:33:42 +0000 Subject: [PATCH] Add tempest test for rebuild Depends-On: https://review.opendev.org/#/c/654254/ Change-Id: I32a170658ed713317bb8bf713ed9ecf3642087c7 --- .../tests/tempest/api/clients.py | 24 +++++++++++++++++++ .../tempest/api/models/container_model.py | 11 +++++++++ .../tests/tempest/api/test_containers.py | 20 ++++++++++++++++ zun_tempest_plugin/tests/tempest/base.py | 3 +++ 4 files changed, 58 insertions(+) diff --git a/zun_tempest_plugin/tests/tempest/api/clients.py b/zun_tempest_plugin/tests/tempest/api/clients.py index 4f52c3a..cec417c 100644 --- a/zun_tempest_plugin/tests/tempest/api/clients.py +++ b/zun_tempest_plugin/tests/tempest/api/clients.py @@ -153,6 +153,11 @@ class ZunClient(rest_client.RestClient): return url + def container_action_uri(cls, container_id, request_id): + url = "/containers/{0}/container_actions/{1}".format( + container_id, request_id) + return url + @classmethod def add_params(cls, url, params): """add_params adds dict values (params) to url as query parameters @@ -258,6 +263,10 @@ class ZunClient(rest_client.RestClient): return self.post( self.container_uri(container_id, action='reboot'), None, **kwargs) + def rebuild_container(self, container_id, **kwargs): + return self.post( + self.container_uri(container_id, action='rebuild'), None, **kwargs) + def exec_container(self, container_id, command, **kwargs): return self.post( self.container_uri(container_id, action='execute'), @@ -301,6 +310,12 @@ class ZunClient(rest_client.RestClient): return self.deserialize(resp, body, service_model.ServiceCollection) + def get_container_action(self, container_id, request_id): + resp, body = self.get( + self.container_action_uri(container_id, request_id)) + return self.deserialize( + resp, body, container_model.ContainerActionEntity) + def ensure_container_in_desired_state(self, container_id, status): def is_container_in_desired_state(): _, container = self.get_container(container_id) @@ -320,6 +335,15 @@ class ZunClient(rest_client.RestClient): return True utils.wait_for_condition(is_container_deleted) + def ensure_action_finished(self, container_id, request_id): + def is_action_finished(): + _, action = self.get_container_action(container_id, request_id) + if action.finish_time is not None: + return True + else: + return False + utils.wait_for_condition(is_action_finished, timeout=120) + def network_attach(self, container_id, params=None, **kwargs): return self.post( self.container_uri(container_id, action='network_attach', diff --git a/zun_tempest_plugin/tests/tempest/api/models/container_model.py b/zun_tempest_plugin/tests/tempest/api/models/container_model.py index 61b0447..68eb69e 100644 --- a/zun_tempest_plugin/tests/tempest/api/models/container_model.py +++ b/zun_tempest_plugin/tests/tempest/api/models/container_model.py @@ -39,3 +39,14 @@ class ContainerPatchEntity(base_model.EntityModel): """Entity Model that represents a single instance of ContainerPatchData""" ENTITY_NAME = 'containerpatch' MODEL_TYPE = ContainerPatchData + + +class ContainerActionData(base_model.BaseModel): + """Data that encapsulates container action attributes""" + pass + + +class ContainerActionEntity(base_model.EntityModel): + """Entity Model that represents a single instance of ContainerActionData""" + ENTITY_NAME = 'containeraction' + MODEL_TYPE = ContainerActionData diff --git a/zun_tempest_plugin/tests/tempest/api/test_containers.py b/zun_tempest_plugin/tests/tempest/api/test_containers.py index 33ade1c..de30410 100644 --- a/zun_tempest_plugin/tests/tempest/api/test_containers.py +++ b/zun_tempest_plugin/tests/tempest/api/test_containers.py @@ -608,6 +608,26 @@ class TestContainer(base.BaseZunTest): self.assertEqual(202, resp.status) # TODO(hongbin): wait for reboot to complete and assure it succeeds + @decorators.idempotent_id('a0c8843f-c32e-4658-b228-eb16c746f495') + @utils.requires_microversion('1.33') + def test_rebuild_container(self): + _, model = self._run_container() + + resp, _ = self.container_client.rebuild_container(model.uuid) + self.assertEqual(202, resp.status) + request_id = self._get_request_id(resp) + # Wait for container to rebuild + self.container_client.ensure_action_finished( + model.uuid, request_id) + + resp, action = self.container_client.get_container_action( + model.uuid, request_id) + self.assertEqual(200, resp.status) + # if the action succeeds, action.message will be None + self.assertIsNone(action.message) + self.container_client.ensure_container_in_desired_state( + model.uuid, 'Running') + @decorators.idempotent_id('8a591ff8-6793-427f-82a6-e3921d8b4f81') def test_exec_container(self): _, model = self._run_container() diff --git a/zun_tempest_plugin/tests/tempest/base.py b/zun_tempest_plugin/tests/tempest/base.py index 29e2012..85b509e 100644 --- a/zun_tempest_plugin/tests/tempest/base.py +++ b/zun_tempest_plugin/tests/tempest/base.py @@ -155,3 +155,6 @@ class BaseZunTest(api_version_utils.BaseMicroversionTest, subnetpool = client.create_subnetpool(**kwargs)['subnetpool'] self.addCleanup(client.delete_subnetpool, subnetpool['id']) return subnetpool + + def _get_request_id(self, resp): + return resp.get('x-openstack-request-id', '')