Skip to content

Commit 403fc67

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Enable start/stop of instances with accelerators."
2 parents 2cfb0a4 + 536d42d commit 403fc67

File tree

12 files changed

+66
-14
lines changed

12 files changed

+66
-14
lines changed

nova/compute/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,9 +3099,10 @@ def _power_on(self, context, instance):
30993099
network_info = self.network_api.get_instance_nw_info(context, instance)
31003100
block_device_info = self._get_instance_block_device_info(context,
31013101
instance)
3102+
accel_info = self._get_accel_info(context, instance)
31023103
self.driver.power_on(context, instance,
31033104
network_info,
3104-
block_device_info)
3105+
block_device_info, accel_info)
31053106

31063107
def _delete_snapshot_of_shelved_instance(self, context, instance,
31073108
snapshot_id):

nova/tests/functional/test_servers.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7839,8 +7839,10 @@ def setUp(self):
78397839
self._setup_compute_nodes_and_device_rps()
78407840

78417841
def _setup_compute_nodes_and_device_rps(self):
7842+
self.compute_services = []
78427843
for i in range(self.NUM_HOSTS):
7843-
self._start_compute(host='accel_host' + str(i))
7844+
svc = self._start_compute(host='accel_host' + str(i))
7845+
self.compute_services.append(svc)
78447846
self.compute_rp_uuids = [
78457847
rp['uuid'] for rp in self._get_all_providers()
78467848
if rp['uuid'] == rp['root_provider_uuid']]
@@ -8004,6 +8006,30 @@ def throw_error(*args, **kwargs):
80048006
# Verify that no allocations/usages remain after deletion
80058007
self._check_no_allocs_usage(server_uuid)
80068008

8009+
def test_create_server_with_local_delete(self):
8010+
"""Delete the server when compute service is down."""
8011+
server = self._get_server()
8012+
server_uuid = server['id']
8013+
8014+
# Stop the server.
8015+
self.api.post_server_action(server_uuid, {'os-stop': {}})
8016+
self._wait_for_state_change(server, 'SHUTOFF')
8017+
self._check_allocations_usage(server)
8018+
# Stop and force down the compute service.
8019+
compute_id = self.admin_api.get_services(
8020+
host='accel_host0', binary='nova-compute')[0]['id']
8021+
self.compute_services[0].stop()
8022+
self.admin_api.put_service(compute_id, {'forced_down': 'true'})
8023+
8024+
# Delete the server with compute service down.
8025+
self.api.delete_server(server_uuid)
8026+
self.cyborg.mock_del_arqs.assert_called_once_with(server_uuid)
8027+
self._check_no_allocs_usage(server_uuid)
8028+
8029+
# Restart the compute service to see if anything fails.
8030+
self.admin_api.put_service(compute_id, {'forced_down': 'false'})
8031+
self.compute_services[0].start()
8032+
80078033

80088034
class AcceleratorServerReschedTest(AcceleratorServerBase):
80098035

nova/tests/unit/compute/test_compute.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,7 @@ def test_power_on(self):
24932493
called = {'power_on': False}
24942494

24952495
def fake_driver_power_on(self, context, instance, network_info,
2496-
block_device_info):
2496+
block_device_info, accel_device_info=None):
24972497
called['power_on'] = True
24982498

24992499
self.stub_out('nova.virt.fake.FakeDriver.power_on',
@@ -2512,6 +2512,25 @@ def fake_driver_power_on(self, context, instance, network_info,
25122512
self.assertTrue(called['power_on'])
25132513
self.compute.terminate_instance(self.context, inst_obj, [])
25142514

2515+
@mock.patch.object(compute_manager.ComputeManager,
2516+
'_get_instance_block_device_info')
2517+
@mock.patch('nova.network.neutron.API.get_instance_nw_info')
2518+
@mock.patch.object(fake.FakeDriver, 'power_on')
2519+
@mock.patch('nova.accelerator.cyborg._CyborgClient.get_arqs_for_instance')
2520+
def test_power_on_with_accels(self, mock_get_arqs,
2521+
mock_power_on, mock_nw_info, mock_blockdev):
2522+
instance = self._create_fake_instance_obj()
2523+
instance.flavor.extra_specs = {'accel:device_profile': 'mydp'}
2524+
accel_info = [{'k1': 'v1', 'k2': 'v2'}]
2525+
mock_get_arqs.return_value = accel_info
2526+
mock_nw_info.return_value = 'nw_info'
2527+
mock_blockdev.return_value = 'blockdev_info'
2528+
2529+
self.compute._power_on(self.context, instance)
2530+
mock_get_arqs.assert_called_once_with(instance['uuid'])
2531+
mock_power_on.assert_called_once_with(self.context,
2532+
instance, 'nw_info', 'blockdev_info', accel_info)
2533+
25152534
def test_power_off(self):
25162535
# Ensure instance can be powered off.
25172536

nova/virt/driver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,14 @@ def power_off(self, instance, timeout=0, retry_interval=0):
889889
raise NotImplementedError()
890890

891891
def power_on(self, context, instance, network_info,
892-
block_device_info=None):
892+
block_device_info=None, accel_info=None):
893893
"""Power on the specified instance.
894894
895895
:param instance: nova.objects.instance.Instance
896+
:param network_info: instance network information
897+
:param block_device_info: instance volume block device info
898+
:param accel_info: List of accelerator request dicts. The exact
899+
data struct is doc'd in nova/virt/driver.py::spawn().
896900
"""
897901
raise NotImplementedError()
898902

nova/virt/fake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
276276
raise exception.InstanceNotFound(instance_id=instance.uuid)
277277

278278
def power_on(self, context, instance, network_info,
279-
block_device_info=None):
279+
block_device_info=None, accel_info=None):
280280
if instance.uuid in self.instances:
281281
self.instances[instance.uuid].state = power_state.RUNNING
282282
else:

nova/virt/hyperv/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
224224
self._vmops.power_off(instance, timeout, retry_interval)
225225

226226
def power_on(self, context, instance, network_info,
227-
block_device_info=None):
227+
block_device_info=None, accel_info=None):
228228
self._vmops.power_on(instance, block_device_info, network_info)
229229

230230
def resume_state_on_host_boot(self, context, instance, network_info,

nova/virt/ironic/driver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
14741474
node.uuid, instance=instance)
14751475

14761476
def power_on(self, context, instance, network_info,
1477-
block_device_info=None):
1477+
block_device_info=None, accel_info=None):
14781478
"""Power on the specified instance.
14791479
14801480
NOTE: Unlike the libvirt driver, this method does not delete
@@ -1486,7 +1486,8 @@ def power_on(self, context, instance, network_info,
14861486
this driver.
14871487
:param block_device_info: Instance block device
14881488
information. Ignored by this driver.
1489-
1489+
:param accel_info: List of accelerator requests for this instance.
1490+
Ignored by this driver.
14901491
"""
14911492
LOG.debug('Power on called for instance', instance=instance)
14921493
node = self._validate_instance_and_node(instance)

nova/virt/libvirt/driver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,12 +3313,13 @@ def power_off(self, instance, timeout=0, retry_interval=0):
33133313
self._destroy(instance)
33143314

33153315
def power_on(self, context, instance, network_info,
3316-
block_device_info=None):
3316+
block_device_info=None, accel_info=None):
33173317
"""Power on the specified instance."""
33183318
# We use _hard_reboot here to ensure that all backing files,
33193319
# network, and block device connections, etc. are established
33203320
# and available before we attempt to start the instance.
3321-
self._hard_reboot(context, instance, network_info, block_device_info)
3321+
self._hard_reboot(context, instance, network_info, block_device_info,
3322+
accel_info)
33223323

33233324
def trigger_crash_dump(self, instance):
33243325

nova/virt/powervm/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
464464
timeout=timeout)
465465

466466
def power_on(self, context, instance, network_info,
467-
block_device_info=None):
467+
block_device_info=None, accel_info=None):
468468
"""Power on the specified instance.
469469
470470
:param instance: nova.objects.instance.Instance

nova/virt/vmwareapi/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
658658
self._vmops.power_off(instance, timeout, retry_interval)
659659

660660
def power_on(self, context, instance, network_info,
661-
block_device_info=None):
661+
block_device_info=None, accel_info=None):
662662
"""Power on the specified instance."""
663663
self._vmops.power_on(instance)
664664

nova/virt/xenapi/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
331331
self._vmops.power_off(instance)
332332

333333
def power_on(self, context, instance, network_info,
334-
block_device_info=None):
334+
block_device_info=None, accel_info=None):
335335
"""Power on the specified instance."""
336336
self._vmops.power_on(instance)
337337

nova/virt/zvm/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def power_off(self, instance, timeout=0, retry_interval=0):
395395
self._hypervisor.guest_softstop(instance.name)
396396

397397
def power_on(self, context, instance, network_info,
398-
block_device_info=None):
398+
block_device_info=None, accel_info=None):
399399
self._hypervisor.guest_start(instance.name)
400400

401401
def pause(self, instance):

0 commit comments

Comments
 (0)