From cfbe4419b9c09f5cd82a210ab9d2bf09d8976e2e Mon Sep 17 00:00:00 2001 From: Pablo Andres Fuente Date: Tue, 24 Jun 2014 17:30:31 -0300 Subject: [PATCH] Event status set to ERROR when it fails When a resource action fails during the execution of an event, the event status and the reservation status are now set to ERROR. Change-Id: I37a7757c5ee8a12665a41ffc3c8194d921f196e4 Closes-Bug: #1333345 --- climate/manager/service.py | 12 ++++++++---- climate/tests/manager/test_service.py | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/climate/manager/service.py b/climate/manager/service.py index 3faf7ec8..ba9892d1 100644 --- a/climate/manager/service.py +++ b/climate/manager/service.py @@ -423,6 +423,7 @@ class ManagerService(service_utils.RPCServer): """Commits basic lease actions such as starting and ending.""" lease = self.get_lease(lease_id) + event_status = 'DONE' for reservation in lease['reservations']: resource_type = reservation['resource_type'] try: @@ -436,12 +437,15 @@ class ManagerService(service_utils.RPCServer): 'action': action_time, 'lease': lease_id, }) - - if reservation_status is not None: + event_status = 'ERROR' db_api.reservation_update(reservation['id'], - {'status': reservation_status}) + {'status': 'error'}) + else: + if reservation_status is not None: + db_api.reservation_update(reservation['id'], + {'status': reservation_status}) - db_api.event_update(event_id, {'status': 'DONE'}) + db_api.event_update(event_id, {'status': event_status}) def _send_notification(self, lease, ctx, events=[]): payload = notification_api.format_lease_payload(lease) diff --git a/climate/tests/manager/test_service.py b/climate/tests/manager/test_service.py index e3ad0336..50bc9d2a 100644 --- a/climate/tests/manager/test_service.py +++ b/climate/tests/manager/test_service.py @@ -1103,9 +1103,29 @@ class ServiceTestCase(tests.TestCase): self.patch(self.manager, 'get_lease').return_value = self.lease + self.manager._basic_action(self.lease_id, '1', 'on_end', + reservation_status='done') + + self.reservation_update.assert_called_once_with( + '111', {'status': 'error'}) + self.event_update.assert_called_once_with('1', {'status': 'ERROR'}) + + def test_basic_action_raise_exception_no_reservation_status(self): + def raiseClimateException(resource_id): + raise exceptions.ClimateException(resource_id) + + self.manager.resource_actions = ( + {'virtual:instance': + {'on_start': self.fake_plugin.on_start, + 'on_end': raiseClimateException}}) + + self.patch(self.manager, 'get_lease').return_value = self.lease + self.manager._basic_action(self.lease_id, '1', 'on_end') - self.event_update.assert_called_once_with('1', {'status': 'DONE'}) + self.reservation_update.assert_called_once_with( + '111', {'status': 'error'}) + self.event_update.assert_called_once_with('1', {'status': 'ERROR'}) def test_getattr_with_correct_plugin_and_method(self): self.fake_list_computehosts = (