Remove host filter for _cleanup_running_deleted_instances periodic task
Periodic task _cleanup_running_deleted_instances() looks for orphaned
and running instances on hypervisor that should be deleted.
The problem is it checks if running instance has the same
hypervisor defined as it is in nova database.
In bug #1285000 it has been found that removing instance during
its migration could lead to abandon instance files on destination
host.
This change removes host filter in _running_deleted_instances() to
find also orphaned instances that are running on 'post migration'
destination host.
Change-Id: Idd1b58b85329b8e021eba4bc27f577af1b3338f4
Partial-Bug: #1285000
(cherry picked from commit aba3f64932
)
This commit is contained in:
parent
2cd4fd3380
commit
c95f00aebf
|
@ -610,6 +610,9 @@ class ComputeManager(manager.Manager):
|
|||
# The driver doesn't support uuids listing, so we'll have
|
||||
# to brute force.
|
||||
driver_instances = self.driver.list_instances()
|
||||
# NOTE(mjozefcz): In this case we need to apply host filter.
|
||||
# Without this all instance data would be fetched from db.
|
||||
filters['host'] = self.host
|
||||
instances = objects.InstanceList.get_by_filters(context, filters,
|
||||
use_slave=True)
|
||||
name_map = {instance.name: instance for instance in instances}
|
||||
|
@ -6719,8 +6722,7 @@ class ComputeManager(manager.Manager):
|
|||
"""
|
||||
timeout = CONF.running_deleted_instance_timeout
|
||||
filters = {'deleted': True,
|
||||
'soft_deleted': False,
|
||||
'host': self.host}
|
||||
'soft_deleted': False}
|
||||
instances = self._get_instances_on_driver(context, filters)
|
||||
return [i for i in instances if self._deleted_old_enough(i, timeout)]
|
||||
|
||||
|
|
|
@ -6613,8 +6613,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
mock.call(ctxt, inst2.uuid, use_slave=True)])
|
||||
mock_get_inst.assert_called_once_with(ctxt,
|
||||
{'deleted': True,
|
||||
'soft_deleted': False,
|
||||
'host': self.compute.host})
|
||||
'soft_deleted': False})
|
||||
|
||||
@mock.patch.object(compute_manager.ComputeManager,
|
||||
'_get_instances_on_driver')
|
||||
|
@ -6629,8 +6628,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
|
||||
mock_get.assert_called_once_with(ctxt,
|
||||
{'deleted': True,
|
||||
'soft_deleted': False,
|
||||
'host': self.compute.host})
|
||||
'soft_deleted': False})
|
||||
mock_power.assert_has_calls([mock.call(inst1), mock.call(inst2)])
|
||||
mock_set.assert_has_calls([mock.call(inst1, False),
|
||||
mock.call(inst2, False)])
|
||||
|
@ -6649,8 +6647,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
|
||||
mock_get.assert_called_once_with(ctxt,
|
||||
{'deleted': True,
|
||||
'soft_deleted': False,
|
||||
'host': self.compute.host})
|
||||
'soft_deleted': False})
|
||||
mock_set.assert_has_calls([mock.call(inst1, False),
|
||||
mock.call(inst2, False)])
|
||||
mock_power.assert_has_calls([mock.call(inst1), mock.call(inst2)])
|
||||
|
@ -6670,8 +6667,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
|
||||
mock_get.assert_called_once_with(ctxt,
|
||||
{'deleted': True,
|
||||
'soft_deleted': False,
|
||||
'host': self.compute.host})
|
||||
'soft_deleted': False})
|
||||
mock_power.assert_has_calls([mock.call(inst1), mock.call(inst2)])
|
||||
mock_set.assert_has_calls([mock.call(inst1, False),
|
||||
mock.call(inst2, False)])
|
||||
|
@ -6694,8 +6690,7 @@ class ComputeTestCase(BaseTestCase,
|
|||
self.assertEqual(val, [instance])
|
||||
mock_get.assert_called_once_with(
|
||||
admin_context, {'deleted': True,
|
||||
'soft_deleted': False,
|
||||
'host': self.compute.host})
|
||||
'soft_deleted': False})
|
||||
mock_is_older.assert_called_once_with(now,
|
||||
CONF.running_deleted_instance_timeout)
|
||||
|
||||
|
|
|
@ -1428,6 +1428,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertEqual([x['uuid'] for x in driver_instances],
|
||||
[x['uuid'] for x in result])
|
||||
expected_filters = {'uuid': driver_uuids}
|
||||
mock_instance_list.assert_called_with(self.context, expected_filters,
|
||||
use_slave=True)
|
||||
|
||||
@mock.patch('nova.objects.InstanceList.get_by_filters')
|
||||
def test_get_instances_on_driver_empty(self, mock_instance_list):
|
||||
|
@ -1446,7 +1449,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
# Test getting instances when driver doesn't support
|
||||
# 'list_instance_uuids'
|
||||
self.compute.host = 'host'
|
||||
filters = {'host': self.compute.host}
|
||||
filters = {}
|
||||
|
||||
self.flags(instance_name_template='inst-%i')
|
||||
|
||||
|
@ -1480,6 +1483,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertEqual([x['uuid'] for x in driver_instances],
|
||||
[x['uuid'] for x in result])
|
||||
expected_filters = {'host': self.compute.host}
|
||||
mock_instance_list.assert_called_with(self.context, expected_filters,
|
||||
use_slave=True)
|
||||
|
||||
def test_instance_usage_audit(self):
|
||||
instances = [objects.Instance(uuid=uuids.instance)]
|
||||
|
|
Loading…
Reference in New Issue