Ensure capsules is deleted

Starting from API version 1.32, the capsule deletion become asynchronized.
After issuing a delete request, we need to continuely check the status
and wait for the deletion to be completed.

Change-Id: I963ee2ded063417dbc4f25705adf39b977fc5171
This commit is contained in:
Hongbin Lu 2019-02-17 17:17:35 +00:00
parent 8a685f86b3
commit e1d8cb3c73
2 changed files with 19 additions and 2 deletions

View File

@ -353,6 +353,10 @@ class ZunClient(rest_client.RestClient):
return False
utils.wait_for_condition(is_capsule_in_desired_state, timeout=120)
def list_capsules(self, **kwargs):
resp, body = self.get(self.capsules_uri(), **kwargs)
return self.deserialize(resp, body, capsule_model.CapsuleEntity)
def get_capsule(self, capsule_id, params=None):
resp, body = self.get(self.capsule_uri(capsule_id, params=params))
return self.deserialize(resp, body, capsule_model.CapsuleEntity)
@ -360,6 +364,16 @@ class ZunClient(rest_client.RestClient):
def delete_capsule(self, capsule_id, params=None):
return self.delete(self.capsule_uri(capsule_id, params=params))
def ensure_capsule_deleted(self, capsule_id):
def is_capsule_deleted():
_, model = self.list_capsules()
capsule_ids = [c['uuid'] for c in model.capsules]
if capsule_id in capsule_ids:
return False
else:
return True
utils.wait_for_condition(is_capsule_deleted)
def delete_network(self, network_id, params=None):
return self.delete(self.network_uri(network_id, params=params))

View File

@ -22,7 +22,6 @@ class TestCapsule(base.BaseZunTest):
credentials = ['primary', 'admin']
min_microversion = '1.12'
max_microversion = '1.31'
@classmethod
def get_client_manager(cls, credential_type=None, roles=None,
@ -41,7 +40,7 @@ class TestCapsule(base.BaseZunTest):
def _create_capsule(self, **kwargs):
gen_model = datagen.capsule_data(**kwargs)
resp, model = self.container_client.post_capsule(gen_model)
self.addCleanup(self.container_client.delete_capsule, model.uuid)
self.addCleanup(self._delete_capsule, model.uuid)
self.assertEqual(202, resp.status)
# Wait for container to finish creation
self.container_client.ensure_capsule_in_desired_state(
@ -54,6 +53,10 @@ class TestCapsule(base.BaseZunTest):
# TODO(hongbin): verify all containers are running
return resp, model
def _delete_capsule(self, uuid):
self.container_client.delete_capsule(uuid)
self.container_client.ensure_capsule_deleted(uuid)
@decorators.idempotent_id('b7e79a0b-c09e-4539-886f-a9f33ae15620')
def test_create_capsule_full(self):
capsule_data = {