Skip to content

Commit 7e4d8af

Browse files
committed
virt: Add 'context', drop 'network_info' parameters for 'unrescue'
In a future change, we'll want access to this so that it's possible to retrieve vTPM data during the unrescue operation. While we're here, it seems nothing is using the 'network_info' argument anymore, presumably since the demise of nova-network, and this can and should be dropped. Resolve both issues in one go, adding the 'context' parameter, dropping the 'network_info' one, and updating the various callers and tests for same. Maintainers of out-of-tree drivers have been notified of these changes [1]. [1] http://lists.openstack.org/pipermail/openstack-discuss/2020-July/015824.html Part of blueprint add-emulated-virtual-tpm Change-Id: Id5e4b0f26d5a2a93db6a7d96555a2cff29d9a2cf Signed-off-by: Stephen Finucane <[email protected]>
1 parent 72cf37b commit 7e4d8af

File tree

16 files changed

+72
-39
lines changed

16 files changed

+72
-39
lines changed

mypy-files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
nova/virt/driver.py
12
nova/virt/hardware.py
23
nova/virt/libvirt/__init__.py
34
nova/virt/libvirt/driver.py

nova/compute/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,7 @@ def rescue_instance(self, context, instance, rescue_password,
41274127
@wrap_instance_event(prefix='compute')
41284128
@wrap_instance_fault
41294129
def unrescue_instance(self, context, instance):
4130+
orig_context = context
41304131
context = context.elevated()
41314132
LOG.info('Unrescuing', instance=instance)
41324133

@@ -4138,8 +4139,7 @@ def unrescue_instance(self, context, instance):
41384139
phase=fields.NotificationPhase.START)
41394140

41404141
with self._error_out_instance_on_exception(context, instance):
4141-
self.driver.unrescue(instance,
4142-
network_info)
4142+
self.driver.unrescue(orig_context, instance)
41434143

41444144
instance.vm_state = vm_states.ACTIVE
41454145
instance.task_state = None

nova/test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,9 @@ def findmethods(object):
625625
baseclass)
626626

627627
for name in sorted(implmethods.keys()):
628-
baseargs = utils.getargspec(basemethods[name])
629-
implargs = utils.getargspec(implmethods[name])
628+
# NOTE(stephenfin): We ignore type annotations
629+
baseargs = utils.getargspec(basemethods[name])[:-1]
630+
implargs = utils.getargspec(implmethods[name])[:-1]
630631

631632
self.assertEqual(baseargs, implargs,
632633
"%s args don't match base class %s" %

nova/tests/unit/compute/test_compute.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,11 +2248,10 @@ def fake_rescue(self, context, instance_ref, network_info, image_meta,
22482248

22492249
self.stub_out('nova.virt.fake.FakeDriver.rescue', fake_rescue)
22502250

2251-
def fake_unrescue(self, instance_ref, network_info):
2251+
def fake_unrescue(self, context, instance_ref):
22522252
called['unrescued'] = True
22532253

2254-
self.stub_out('nova.virt.fake.FakeDriver.unrescue',
2255-
fake_unrescue)
2254+
self.stub_out('nova.virt.fake.FakeDriver.unrescue', fake_unrescue)
22562255

22572256
instance = self._create_fake_instance_obj()
22582257
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
@@ -2327,10 +2326,10 @@ def fake_rescue(self, context, instance_ref, network_info, image_meta,
23272326
@mock.patch('nova.context.RequestContext.elevated')
23282327
def test_unrescue_notifications(self, mock_context, mock_notify):
23292328
# Ensure notifications on instance rescue.
2330-
def fake_unrescue(self, instance_ref, network_info):
2329+
def fake_unrescue(self, context, instance_ref):
23312330
pass
2332-
self.stub_out('nova.virt.fake.FakeDriver.unrescue',
2333-
fake_unrescue)
2331+
2332+
self.stub_out('nova.virt.fake.FakeDriver.unrescue', fake_unrescue)
23342333
context = self.context
23352334
mock_context.return_value = context
23362335

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4443,7 +4443,7 @@ def test_unrescue(self, mock_notify):
44434443
]
44444444
notify_instance_usage.assert_has_calls(notify_calls)
44454445

4446-
driver_unrescue.assert_called_once_with(instance, fake_nw_info)
4446+
driver_unrescue.assert_called_once_with(self.context, instance)
44474447
mock_notify.assert_has_calls([
44484448
mock.call(self.context, instance, 'fake-mini',
44494449
action='unrescue', phase='start'),

nova/tests/unit/virt/ironic/test_driver.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,7 +3063,7 @@ def test_unrescue(self, mock_sps, mock_looping):
30633063
instance = fake_instance.fake_instance_obj(self.ctx,
30643064
node=node.uuid)
30653065

3066-
self.driver.unrescue(instance, None)
3066+
self.driver.unrescue(self.ctx, instance)
30673067
mock_sps.assert_called_once_with(node.uuid, 'unrescue')
30683068

30693069
@mock.patch.object(loopingcall, 'FixedIntervalLoopingCall')
@@ -3078,8 +3078,7 @@ def test_unrescue_provision_state_fail(self, mock_sps, mock_looping):
30783078
instance = fake_instance.fake_instance_obj(self.ctx,
30793079
node=node.uuid)
30803080
self.assertRaises(exception.InstanceUnRescueFailure,
3081-
self.driver.unrescue,
3082-
instance, None)
3081+
self.driver.unrescue, self.ctx, instance)
30833082

30843083
@mock.patch.object(ironic_driver.IronicDriver,
30853084
'_validate_instance_and_node')
@@ -3092,8 +3091,7 @@ def test_unrescue_instance_not_found(self, mock_sps, fake_validate):
30923091
instance_id='fake')
30933092

30943093
self.assertRaises(exception.InstanceUnRescueFailure,
3095-
self.driver.unrescue,
3096-
instance, None)
3094+
self.driver.unrescue, self.ctx, instance)
30973095

30983096
@mock.patch.object(ironic_driver.IronicDriver,
30993097
'_validate_instance_and_node')
@@ -3108,8 +3106,7 @@ def test_unrescue_unrescue_fail(self, mock_sps, fake_validate):
31083106
node=node.uuid)
31093107

31103108
self.assertRaises(exception.InstanceUnRescueFailure,
3111-
self.driver.unrescue,
3112-
instance, None)
3109+
self.driver.unrescue, self.ctx, instance)
31133110

31143111
def test__can_send_version(self):
31153112
self.assertIsNone(

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23272,7 +23272,7 @@ def isdir_sideeffect(*args, **kwargs):
2327223272
) as (mock_write, mock_destroy, mock_create, mock_del,
2327323273
mock_rmtree, mock_isdir, mock_lvm_disks,
2327423274
mock_remove_volumes, mock_glob):
23275-
drvr.unrescue(instance, None)
23275+
drvr.unrescue(self.context, instance)
2327623276
mock_destroy.assert_called_once_with(instance)
2327723277
mock_create.assert_called_once_with("fake_unrescue_xml",
2327823278
fake_dom)

nova/tests/unit/virt/test_virt_drivers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ def test_rescue(self):
297297
@mock.patch('os.unlink')
298298
@mock.patch('nova.virt.libvirt.utils.load_file', return_value='')
299299
def test_unrescue_unrescued_instance(self, mock_load_file, mock_unlink):
300-
instance_ref, network_info = self._get_running_instance()
301-
self.connection.unrescue(instance_ref, network_info)
300+
instance_ref, _ = self._get_running_instance()
301+
self.connection.unrescue(self.ctxt, instance_ref)
302302

303303
@catch_notimplementederror
304304
@mock.patch('os.unlink')
@@ -307,7 +307,7 @@ def test_unrescue_rescued_instance(self, mock_unlink):
307307
instance_ref, network_info = self._get_running_instance()
308308
self.connection.rescue(self.ctxt, instance_ref, network_info,
309309
image_meta, '', None)
310-
self.connection.unrescue(instance_ref, network_info)
310+
self.connection.unrescue(self.ctxt, instance_ref)
311311

312312
@catch_notimplementederror
313313
def test_poll_rebooting_instances(self):

nova/tests/unit/virt/xenapi/test_xenapi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,14 +1365,14 @@ def test_unrescue(self):
13651365
# Unrescue expects the original instance to be powered off
13661366
conn.power_off(instance)
13671367
xenapi_fake.create_vm(instance['name'] + '-rescue', 'Running')
1368-
conn.unrescue(instance, None)
1368+
conn.unrescue(self.context, instance)
13691369

13701370
def test_unrescue_not_in_rescue(self):
13711371
instance = self._create_instance(obj=True)
13721372
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
13731373
# Ensure that it will not unrescue a non-rescued instance.
1374-
self.assertRaises(exception.InstanceNotInRescueMode, conn.unrescue,
1375-
instance, None)
1374+
self.assertRaises(exception.InstanceNotInRescueMode,
1375+
conn.unrescue, self.context, instance)
13761376

13771377
def test_finish_revert_migration(self):
13781378
instance = self._create_instance()

nova/virt/driver.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import six
3030

3131
import nova.conf
32+
from nova import context as nova_context
3233
from nova.i18n import _
34+
from nova import objects
3335
from nova.virt import event as virtevent
3436

3537
CONF = nova.conf.CONF
@@ -879,12 +881,16 @@ def set_bootable(self, instance, is_bootable):
879881
"""
880882
raise NotImplementedError()
881883

882-
def unrescue(self, instance, network_info):
884+
def unrescue(
885+
self,
886+
context: nova_context.RequestContext,
887+
instance: 'objects.Instance',
888+
):
883889
"""Unrescue the specified instance.
884890
891+
:param context: security context
885892
:param instance: nova.objects.instance.Instance
886893
"""
887-
# TODO(Vek): Need to pass context in for access to auth_token
888894
raise NotImplementedError()
889895

890896
def power_off(self, instance, timeout=0, retry_interval=0):

nova/virt/fake.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
from nova.compute import vm_states
4040
import nova.conf
4141
from nova.console import type as ctype
42+
from nova import context as nova_context
4243
from nova import exception
44+
from nova import objects
4345
from nova.objects import diagnostics as diagnostics_obj
4446
from nova.objects import fields as obj_fields
4547
from nova.objects import migrate_data
@@ -238,7 +240,11 @@ def rescue(self, context, instance, network_info, image_meta,
238240
rescue_password, block_device_info):
239241
pass
240242

241-
def unrescue(self, instance, network_info):
243+
def unrescue(
244+
self,
245+
context: nova_context.RequestContext,
246+
instance: 'objects.Instance',
247+
):
242248
self.instances[instance.uuid].state = power_state.RUNNING
243249

244250
def poll_rebooting_instances(self, timeout, instances):

nova/virt/hyperv/driver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
from oslo_log import log as logging
2727
import six
2828

29+
from nova import context as nova_context
2930
from nova import exception
31+
from nova import objects
3032
from nova.virt import driver
3133
from nova.virt.hyperv import eventhandler
3234
from nova.virt.hyperv import hostops
@@ -39,6 +41,7 @@
3941
from nova.virt.hyperv import vmops
4042
from nova.virt.hyperv import volumeops
4143

44+
4245
LOG = logging.getLogger(__name__)
4346

4447

@@ -361,7 +364,11 @@ def rescue(self, context, instance, network_info, image_meta,
361364
self._vmops.rescue_instance(context, instance, network_info,
362365
image_meta, rescue_password)
363366

364-
def unrescue(self, instance, network_info):
367+
def unrescue(
368+
self,
369+
context: nova_context.RequestContext,
370+
instance: 'objects.Instance',
371+
):
365372
self._vmops.unrescue_instance(instance)
366373

367374
def update_provider_tree(self, provider_tree, nodename, allocations=None):

nova/virt/ironic/driver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
A driver wrapping the Ironic API, such that Nova may provision
1919
bare metal resources.
2020
"""
21+
2122
import base64
2223
from distutils import version
2324
import gzip
@@ -2166,13 +2167,15 @@ def _wait_for_rescue():
21662167
LOG.info('Successfully rescued Ironic node %(node)s',
21672168
{'node': node_uuid}, instance=instance)
21682169

2169-
def unrescue(self, instance, network_info):
2170+
def unrescue(
2171+
self,
2172+
context: nova_context.RequestContext,
2173+
instance: 'objects.Instance',
2174+
):
21702175
"""Unrescue the specified instance.
21712176
2177+
:param context: security context
21722178
:param instance: nova.objects.instance.Instance
2173-
:param nova.network.model.NetworkInfo network_info:
2174-
Necessary network information for the unrescue. Ignored by this
2175-
driver.
21762179
"""
21772180
LOG.debug('Unrescue called for instance', instance=instance)
21782181

nova/virt/libvirt/driver.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,9 +3568,12 @@ def rescue(self, context, instance, network_info, image_meta,
35683568
self._destroy(instance)
35693569
self._create_domain(xml, post_xml_callback=gen_confdrive)
35703570

3571-
def unrescue(self, instance, network_info):
3572-
"""Reboot the VM which is being rescued back into primary images.
3573-
"""
3571+
def unrescue(
3572+
self,
3573+
context: nova_context.RequestContext,
3574+
instance: 'objects.Instance',
3575+
):
3576+
"""Reboot the VM which is being rescued back into primary images."""
35743577
instance_dir = libvirt_utils.get_instance_path(instance)
35753578
unrescue_xml_path = os.path.join(instance_dir, 'unrescue.xml')
35763579
xml = libvirt_utils.load_file(unrescue_xml_path)

nova/virt/vmwareapi/driver.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from nova.compute import task_states
3838
from nova.compute import utils as compute_utils
3939
import nova.conf
40+
from nova import context as nova_context
4041
from nova import exception
4142
from nova.i18n import _
4243
from nova import objects
@@ -650,7 +651,11 @@ def rescue(self, context, instance, network_info, image_meta,
650651
"""Rescue the specified instance."""
651652
self._vmops.rescue(context, instance, network_info, image_meta)
652653

653-
def unrescue(self, instance, network_info):
654+
def unrescue(
655+
self,
656+
context: nova_context.RequestContext,
657+
instance: 'objects.Instance',
658+
):
654659
"""Unrescue the specified instance."""
655660
self._vmops.unrescue(instance)
656661

nova/virt/xenapi/driver.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
from oslo_serialization import jsonutils
3030
from oslo_utils import units
3131
from oslo_utils import versionutils
32-
3332
import six.moves.urllib.parse as urlparse
3433

3534
import nova.conf
35+
from nova import context as nova_context
3636
from nova import exception
3737
from nova.i18n import _
38+
from nova import objects
3839
from nova.virt import driver
3940
from nova.virt.xenapi import host
4041
from nova.virt.xenapi import pool
@@ -316,7 +317,11 @@ def set_bootable(self, instance, is_bootable):
316317
"""Set the ability to power on/off an instance."""
317318
self._vmops.set_bootable(instance, is_bootable)
318319

319-
def unrescue(self, instance, network_info):
320+
def unrescue(
321+
self,
322+
context: nova_context.RequestContext,
323+
instance: 'objects.Instance',
324+
):
320325
"""Unrescue the specified instance."""
321326
self._vmops.unrescue(instance)
322327

0 commit comments

Comments
 (0)