Skip to content

Commit 3de7fb7

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add missed accel_uuids for _poll_shelved_instances"
2 parents 6fd4c8d + 78be7de commit 3de7fb7

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

nova/compute/manager.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9478,12 +9478,20 @@ def _poll_shelved_instances(self, context):
94789478
if timeutils.is_older_than(shelved_at, CONF.shelved_offload_time):
94799479
to_gc.append(instance)
94809480

9481+
cyclient = cyborg.get_client(context)
94819482
for instance in to_gc:
94829483
try:
94839484
instance.task_state = task_states.SHELVING_OFFLOADING
94849485
instance.save(expected_task_state=(None,))
9485-
self.shelve_offload_instance(context, instance,
9486-
clean_shutdown=False)
9486+
accel_uuids = []
9487+
if instance.flavor.extra_specs.get('accel:device_profile'):
9488+
# TODO(brinzhang): After cyborg support batch query ARQs
9489+
# for more than one instances, we will improve efficiency
9490+
# with this implemention.
9491+
accel_uuids = cyclient.get_arq_uuids_for_instance(instance)
9492+
self.shelve_offload_instance(
9493+
context, instance, clean_shutdown=False,
9494+
accel_uuids=accel_uuids)
94879495
except Exception:
94889496
LOG.exception('Periodic task failed to offload instance.',
94899497
instance=instance)

nova/tests/unit/compute/test_shelve.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,34 @@ def fake_soi(context, instance, **kwargs):
762762
self.assertTrue(soi.called)
763763
self.assertEqual([instance2.uuid], data)
764764

765+
@mock.patch('nova.accelerator.cyborg._CyborgClient.'
766+
'get_arq_uuids_for_instance')
767+
@mock.patch('oslo_utils.timeutils.is_older_than')
768+
@mock.patch('oslo_utils.timeutils.parse_strtime')
769+
def test_shelved_poll_with_accel_uuids(self, mock_parse, mock_older,
770+
mock_get_arq_uuids):
771+
self.flags(shelved_offload_time=1)
772+
mock_older.return_value = True
773+
instance = self._create_fake_instance_obj()
774+
instance.task_state = None
775+
instance.vm_state = vm_states.SHELVED
776+
instance.host = self.compute.host
777+
instance.system_metadata = {'shelved_at': ''}
778+
instance.flavor.extra_specs['accel:device_profile'] = 'dp_test'
779+
mock_get_arq_uuids.return_value = [uuids.fake]
780+
instance.save()
781+
782+
data = []
783+
784+
def fake_soi(context, instance, **kwargs):
785+
data.append(instance.uuid)
786+
787+
with mock.patch.object(self.compute, 'shelve_offload_instance') as soi:
788+
soi.side_effect = fake_soi
789+
self.compute._poll_shelved_instances(self.context)
790+
self.assertTrue(soi.called)
791+
self.assertEqual([instance.uuid], data)
792+
765793
@mock.patch('oslo_utils.timeutils.is_older_than')
766794
@mock.patch('oslo_utils.timeutils.parse_strtime')
767795
def test_shelved_poll_checks_task_state_on_save(self, mock_parse,

0 commit comments

Comments
 (0)