Skip to content

Commit c97507d

Browse files
committed
record action log when deleting shelved instance
Closes-Bug: #1993736 Change-Id: I9ce18cbba5083c55d15d9b7c2a89133d227754ea
1 parent 5ad1555 commit c97507d

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

nova/compute/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,8 @@ def _delete(self, context, instance, delete_type, cb, **instance_attrs):
25472547
instance=instance)
25482548
with nova_context.target_cell(context, cell) as cctxt:
25492549
self._local_delete(cctxt, instance, bdms, delete_type, cb)
2550+
self._record_action_start(context, instance,
2551+
instance_actions.DELETE)
25502552

25512553
except exception.InstanceNotFound:
25522554
# NOTE(comstud): Race condition. Instance already gone.

nova/tests/functional/test_instance_actions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ def test_get_instance_actions_deleted(self):
5959
self.assertEqual('delete', actions[0]['action'])
6060
self.assertEqual('create', actions[1]['action'])
6161

62+
def test_get_instance_actions_shelve_deleted(self):
63+
server = self._create_server()
64+
self._shelve_server(server)
65+
self._delete_server(server)
66+
actions = self.api.get_instance_actions(server['id'])
67+
self.assertEqual('delete', actions[0]['action'])
68+
self.assertEqual('shelve', actions[1]['action'])
69+
self.assertEqual('create', actions[2]['action'])
70+
6271

6372
class HypervisorError(Exception):
6473
"""This is just used to make sure the exception type is in the events."""

nova/tests/unit/compute/test_api.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,10 +1254,12 @@ def test_delete_forced(self):
12541254
@mock.patch('nova.objects.Instance.save')
12551255
@mock.patch('nova.compute.utils.notify_about_instance_usage')
12561256
@mock.patch('nova.objects.Service.get_by_compute_host')
1257+
@mock.patch('nova.compute.api.API._record_action_start')
12571258
@mock.patch('nova.compute.api.API._local_delete')
12581259
def test_delete_error_state_with_no_host(
1259-
self, mock_local_delete, mock_service_get, _mock_notify,
1260-
_mock_save, mock_bdm_get, mock_lookup, _mock_del_booting):
1260+
self, mock_local_delete, mock_record, mock_service_get,
1261+
_mock_notify, _mock_save, mock_bdm_get, mock_lookup,
1262+
_mock_del_booting):
12611263
# Instance in error state with no host should be a local delete
12621264
# for non API cells
12631265
inst = self._create_instance_obj(params=dict(vm_state=vm_states.ERROR,
@@ -1269,6 +1271,8 @@ def test_delete_error_state_with_no_host(
12691271
mock_local_delete.assert_called_once_with(
12701272
self.context, inst, mock_bdm_get.return_value,
12711273
'delete', self.compute_api._do_delete)
1274+
mock_record.assert_called_once_with(self.context, inst,
1275+
instance_actions.DELETE)
12721276
mock_terminate.assert_not_called()
12731277
mock_service_get.assert_not_called()
12741278

@@ -7905,8 +7909,9 @@ def test_get_all_ip6_filter_exc(self, mock_list_port, mock_check_ext):
79057909
@mock.patch.object(compute_utils, 'notify_about_instance_usage')
79067910
@mock.patch.object(objects.BlockDeviceMapping, 'destroy')
79077911
@mock.patch.object(objects.Instance, 'destroy')
7912+
@mock.patch('nova.compute.api.API._record_action_start')
79087913
def _test_delete_volume_backed_instance(
7909-
self, vm_state, mock_instance_destroy, bdm_destroy,
7914+
self, vm_state, mock_record, mock_instance_destroy, bdm_destroy,
79107915
notify_about_instance_usage, mock_save, mock_elevated,
79117916
bdm_get_by_instance_uuid, mock_lookup, _mock_del_booting,
79127917
notify_about_instance_action):
@@ -7935,6 +7940,8 @@ def _test_delete_volume_backed_instance(
79357940
'detach') as mock_detach:
79367941
self.compute_api.delete(self.context, inst)
79377942

7943+
mock_record.assert_called_once_with(self.context, inst,
7944+
instance_actions.DELETE)
79387945
mock_deallocate.assert_called_once_with(self.context, inst)
79397946
mock_detach.assert_called_once_with(self.context, volume_id,
79407947
inst.uuid)

0 commit comments

Comments
 (0)