From 5cd53f330879187fc43899db406bf30c65d95915 Mon Sep 17 00:00:00 2001 From: Maho Koshiya Date: Wed, 5 Jul 2017 07:41:29 +0900 Subject: [PATCH] Add a termination scenario test When the user specifies end_time and executes update API, check that resources are correctly released at lease end time. It confirm that the instance created during the lease period have been removed by lease end. Change-Id: Ic1076905ad5f2fc894036b045743eacb5c2db9bd Partial-bug: #1694181 --- .../resource_reservation_client_manager.py | 4 +- .../tempest/scenario/test_host_reservation.py | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/contrib/tempest/tempest/resource_reservation_client_manager.py b/contrib/tempest/tempest/resource_reservation_client_manager.py index e58159da..1d6a8638 100644 --- a/contrib/tempest/tempest/resource_reservation_client_manager.py +++ b/contrib/tempest/tempest/resource_reservation_client_manager.py @@ -52,7 +52,7 @@ class ResourceReservationV1Client(rest_client.RestClient): def update_lease(self, lease, body): body = json.dumps(body) - resp, body = self.post(self.lease_path % lease, body=body) + resp, body = self.put(self.lease_path % lease, body=body) return self._response_helper(resp, body) def delete_lease(self, lease): @@ -74,7 +74,7 @@ class ResourceReservationV1Client(rest_client.RestClient): def update_host(self, host, body): body = json.dumps(body) - resp, body = self.post(self.host_path % host, body=body) + resp, body = self.put(self.host_path % host, body=body) return self._response_helper(resp, body) def delete_host(self, host): diff --git a/contrib/tempest/tempest/scenario/test_host_reservation.py b/contrib/tempest/tempest/scenario/test_host_reservation.py index 6ae6b214..4eb4b8ef 100644 --- a/contrib/tempest/tempest/scenario/test_host_reservation.py +++ b/contrib/tempest/tempest/scenario/test_host_reservation.py @@ -272,3 +272,64 @@ class TestHostReservationScenario(rrs.ResourceReservationScenarioTest): lease = self.reservation_client.get_lease(lease_id)['lease'] self.assertTrue('deleted' in next(iter(lease['reservations']))['status']) + + @decorators.attr(type='smoke') + def test_update_host_reservation(self): + + # create the host if it doesn't exist + host = self._add_host_once() + + # create new lease and start reservation immediately + body = self.get_lease_body('scenario-3-update', host['host']) + lease = self.reservation_client.create_lease(body)['lease'] + lease_id = lease['id'] + + # check host added to the reservation + reservation_id = next(iter(lease['reservations']))['id'] + self.wait_until_aggregated(reservation_id, host['host']) + + # check the host aggregate for blazar + self.fetch_aggregate_by_name(reservation_id) + + # create an instance with reservation id + create_kwargs = { + 'scheduler_hints': { + 'reservation': reservation_id, + }, + 'image_id': CONF.compute.image_ref, + 'flavor': CONF.compute.flavor_ref, + } + server = self.create_server(clients=self.os_admin, + wait_until=None, + **create_kwargs) + waiters.wait_for_server_status(self.os_admin.servers_client, + server['id'], 'ACTIVE') + + # wait enough time for the update API to succeed + time.sleep(75) + + # update the lease end_time + end_time = datetime.datetime.utcnow() + body = { + 'end_date': end_time.strftime('%Y-%m-%d %H:%M') + } + self.reservation_client.update_lease(lease_id, + body)['lease'] + + # check if the lease has been correctly terminated and + # the instance is removed + waiters.wait_for_server_termination(self.os_admin.servers_client, + server['id']) + + # check that the host aggregate was deleted + self.assertRaises(exceptions.NotFound, + self.fetch_aggregate_by_name, reservation_id) + + # check that the host is back in the freepool + freepool = self.fetch_aggregate_by_name('freepool') + self.assertTrue(host['host'] in freepool['hosts']) + + # check the reservation status + lease = self.reservation_client.get_lease(lease_id)['lease'] + self.assertTrue('deleted'in + next(iter(lease['reservations']))['status'])