From 73715596d619c093f4db3df4ccefa5c8780c7c67 Mon Sep 17 00:00:00 2001 From: deepak_mourya Date: Tue, 27 Feb 2018 08:25:00 +0530 Subject: [PATCH] Test remove security group in tempest tests This test will use to remove security group from the container. Depends-On: Ife757d85f0ea6920e10d45d8a07703a38ec85d1f Change-Id: Id9accbc8139e268775be68a85b7d3892033181df Closes-Bug: #1749351 --- zun_tempest_plugin/tests/tempest/api/clients.py | 5 +++++ .../tests/tempest/api/common/datagen.py | 11 +++++++++++ .../tests/tempest/api/test_containers.py | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/zun_tempest_plugin/tests/tempest/api/clients.py b/zun_tempest_plugin/tests/tempest/api/clients.py index a24e84d..c2bc52e 100644 --- a/zun_tempest_plugin/tests/tempest/api/clients.py +++ b/zun_tempest_plugin/tests/tempest/api/clients.py @@ -242,6 +242,11 @@ class ZunClient(rest_client.RestClient): self.container_uri(container_id, action='add_security_group'), body=model.to_json(), **kwargs) + def remove_security_group(self, container_id, model, **kwargs): + return self.post( + self.container_uri(container_id, action='remove_security_group'), + body=model.to_json(), **kwargs) + def list_services(self, **kwargs): resp, body = self.get(self.services_uri(), **kwargs) return self.deserialize(resp, body, diff --git a/zun_tempest_plugin/tests/tempest/api/common/datagen.py b/zun_tempest_plugin/tests/tempest/api/common/datagen.py index 2fbf176..be8d76a 100644 --- a/zun_tempest_plugin/tests/tempest/api/common/datagen.py +++ b/zun_tempest_plugin/tests/tempest/api/common/datagen.py @@ -103,3 +103,14 @@ def container_add_sg_data(**kwargs): model = container_model.ContainerPatchEntity.from_dict(data) return model + + +def container_remove_sg_data(**kwargs): + data = { + 'name': 'sg_name', + } + + data.update(kwargs) + model = container_model.ContainerPatchEntity.from_dict(data) + + return model diff --git a/zun_tempest_plugin/tests/tempest/api/test_containers.py b/zun_tempest_plugin/tests/tempest/api/test_containers.py index 70a57a1..fb17a4a 100644 --- a/zun_tempest_plugin/tests/tempest/api/test_containers.py +++ b/zun_tempest_plugin/tests/tempest/api/test_containers.py @@ -400,7 +400,7 @@ class TestContainer(base.BaseZunTest): self.assertTrue('BLOCK I/O(B)' in encodeutils.safe_decode(body)) @decorators.idempotent_id('b3b9cf17-82ad-4c1b-a4af-8210a778a33e') - def test_add_sg_to_container(self): + def test_add_and_remove_sg_to_container(self): _, model = self._run_container() sgs = self._get_all_security_groups(model) self.assertEqual(1, len(sgs)) @@ -423,6 +423,19 @@ class TestContainer(base.BaseZunTest): utils.wait_for_condition(assert_security_group_is_added) + gen_model = datagen.container_remove_sg_data(name=sg_name) + resp1, body = self.container_client.remove_security_group( + model.uuid, gen_model) + self.assertEqual(202, resp1.status) + + def assert_security_group_is_removed(): + sgs = self._get_all_security_groups(model) + if sg_name not in sgs: + return True + else: + return False + utils.wait_for_condition(assert_security_group_is_removed) + def _assert_resource_constraints(self, container, cpu=None, memory=None): if cpu is not None: cpu_quota = container.get('HostConfig').get('CpuQuota') @@ -521,8 +534,8 @@ class TestContainer(base.BaseZunTest): @decorators.idempotent_id('dcb0dddb-7f0f-43f6-b82a-0cae13938bd6') def test_detach_and_attach_network_to_container(self): _, model = self._run_container() - self.assertEqual(1, len(model.addresses)) + self.assertEqual(1, len(model.addresses)) network = list(model.addresses.keys())[0] resp, body = self.container_client.network_detach( model.uuid, params={'network': network})