Skip to content

Commit

Permalink
Add filter for soft-deleted instances to periodic cleanup task
Browse files Browse the repository at this point in the history
The periodic cleanup task added recently does a db query to get
instances in need of cleanup. The filters applied to the query
must have a filter to not include soft-deleted instances.

This fix adds the required filter and adds a test to verify the
correct behavior.

Change-Id: I0c5d7e317d1fdd4e1e618c1c38870e775a715eab
Closes-Bug: #1223345
  • Loading branch information
hanlind committed Sep 10, 2013
1 parent ec73243 commit 6ae5899
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions nova/compute/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4977,6 +4977,7 @@ def _run_pending_deletes(self, context):

LOG.debug(_('Cleaning up deleted instances'))
filters = {'deleted': True,
'soft_deleted': False,
'host': CONF.host,
'cleaned': False}
attrs = ['info_cache', 'security_groups', 'system_metadata']
Expand Down
13 changes: 13 additions & 0 deletions nova/tests/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5355,6 +5355,19 @@ def _noop(*args, **kwargs):
updated_ats = (updated_at_1, updated_at_2, updated_at_3)
self.assertEqual(len(updated_ats), len(set(updated_ats)))

def test_no_pending_deletes_for_soft_deleted_instances(self):
self.flags(reclaim_instance_interval=0)
ctxt = context.get_admin_context()

instance = self._create_fake_instance(
params={'host': CONF.host,
'vm_state': vm_states.SOFT_DELETED,
'deleted_at': timeutils.utcnow()})

self.compute._run_pending_deletes(ctxt)
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
self.assertFalse(instance['cleaned'])

def test_reclaim_queued_deletes(self):
self.flags(reclaim_instance_interval=3600)
ctxt = context.get_admin_context()
Expand Down
3 changes: 2 additions & 1 deletion nova/tests/compute/test_compute_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ def get_by_filters(self, *args, **kwargs):
'get_by_filters')
instance_obj.InstanceList.get_by_filters(
{'read_deleted': 'yes'},
{'deleted': True, 'host': 'fake-mini', 'cleaned': False},
{'deleted': True, 'soft_deleted': False, 'host': 'fake-mini',
'cleaned': False},
expected_attrs=['info_cache', 'security_groups',
'system_metadata']).AndReturn([a, b, c])

Expand Down

0 comments on commit 6ae5899

Please sign in to comment.