Skip to content

Commit 04edead

Browse files
committed
[vmware] VmdkDriverRemoteApi: RPC initialization improvements
Currently, creating the RPC client at the driver initialization might lead into an issue that, while upgrading to newer releases, the RPC client will limit the maximum RPC version to the older release's version, since that version is never refreshed while the volume backend is running. Initializing the RPC client every time it's needed will make sure it always refreshes the available RPC service versions. Also, inherit the RPC_DEFAULT_VERSION from the VolumeAPI, so that the smallest available major version is requested by default, instead of the biggest available version.
1 parent 893c218 commit 04edead

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

cinder/tests/unit/volume/drivers/vmware/test_vmware_vmdk.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,12 +3444,18 @@ def test_revert_to_snapshot(self, vops):
34443444
vops.revert_to_snapshot.assert_called_once_with(backing,
34453445
snapshot.name)
34463446

3447+
@mock.patch('cinder.volume.drivers.vmware.remote.VmdkDriverRemoteApi.'
3448+
'move_volume_backing_to_folder')
3449+
@mock.patch('cinder.volume.drivers.vmware.remote.VmdkDriverRemoteApi.'
3450+
'select_ds_for_volume')
3451+
@mock.patch('cinder.volume.drivers.vmware.remote.VmdkDriverRemoteApi.'
3452+
'get_service_locator_info')
34473453
@mock.patch.object(VMDK_DRIVER, 'volumeops')
34483454
@mock.patch('oslo_vmware.vim_util.get_moref')
3449-
def test_migrate_volume(self, get_moref, vops, backing=None,
3455+
def test_migrate_volume(self, get_moref, vops, get_service_locator,
3456+
select_ds_for_volume, move_volume_backing,
3457+
backing=None,
34503458
raises_error=False, capabilities=None):
3451-
r_api = mock.Mock()
3452-
self._driver._remote_api = r_api
34533459
volume = self._create_volume_obj()
34543460
vops.get_backing.return_value = backing
34553461
if capabilities is None:
@@ -3467,22 +3473,22 @@ def test_migrate_volume(self, get_moref, vops, backing=None,
34673473
mock.sentinel.rp_ref,
34683474
mock.sentinel.ds_ref
34693475
]
3470-
r_api.get_service_locator_info.return_value = \
3476+
get_service_locator.return_value = \
34713477
mock.sentinel.service_locator
3472-
r_api.select_ds_for_volume.return_value = ds_info
3478+
select_ds_for_volume.return_value = ds_info
34733479
if raises_error:
3474-
r_api.move_volume_backing_to_folder.side_effect = Exception
3480+
move_volume_backing.side_effect = Exception
34753481

34763482
ret_val = self._driver.migrate_volume(mock.sentinel.context, volume,
34773483
host)
34783484

34793485
dest_host = host['host']
34803486

34813487
def _assertions_migration_not_called():
3482-
r_api.get_service_locator_info.assert_not_called()
3483-
r_api.select_ds_for_volume.assert_not_called()
3488+
get_service_locator.assert_not_called()
3489+
select_ds_for_volume.assert_not_called()
34843490
vops.relocate_backing.assert_not_called()
3485-
r_api.move_volume_backing_to_folder.assert_not_called()
3491+
move_volume_backing.assert_not_called()
34863492
get_moref.assert_not_called()
34873493

34883494
def _assertions_for_no_backing():
@@ -3496,10 +3502,10 @@ def _assertions_migration_not_performed():
34963502

34973503
def _assertions_for_migration():
34983504
vops.get_backing.assert_called_once_with(volume.name, volume.id)
3499-
r_api.get_service_locator_info.assert_called_once_with(
3505+
get_service_locator.assert_called_once_with(
35003506
mock.sentinel.context, dest_host)
35013507

3502-
r_api.select_ds_for_volume.assert_called_once_with(
3508+
select_ds_for_volume.assert_called_once_with(
35033509
mock.sentinel.context, dest_host, volume)
35043510

35053511
get_moref.assert_has_calls([
@@ -3511,7 +3517,7 @@ def _assertions_for_migration():
35113517
backing, mock.sentinel.ds_ref, mock.sentinel.rp_ref,
35123518
mock.sentinel.host_ref, service=mock.sentinel.service_locator)
35133519

3514-
r_api.move_volume_backing_to_folder.assert_called_once_with(
3520+
move_volume_backing.assert_called_once_with(
35153521
mock.sentinel.context, dest_host, volume, ds_info['folder'])
35163522

35173523
if raises_error:

cinder/volume/drivers/vmware/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class VmdkDriverRemoteApi(rpc.RPCAPI):
3030
RPC_API_VERSION = VolumeAPI.RPC_API_VERSION
31-
RPC_DEFAULT_VERSION = RPC_API_VERSION
31+
RPC_DEFAULT_VERSION = VolumeAPI.RPC_DEFAULT_VERSION
3232
TOPIC = VolumeAPI.TOPIC
3333
BINARY = VolumeAPI.BINARY
3434

cinder/volume/drivers/vmware/vmdk.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ def __init__(self, *args, **kwargs):
337337
self.additional_endpoints.extend([
338338
remote_api.VmdkDriverRemoteService(self)
339339
])
340-
self._remote_api = remote_api.VmdkDriverRemoteApi()
341340

342341
@staticmethod
343342
def get_driver_options():
@@ -2645,18 +2644,19 @@ def migrate_volume(self, context, volume, host):
26452644
{'volume_name': volume.name, 'dest_host': dest_host})
26462645
return (True, None)
26472646

2648-
service_locator = self._remote_api.get_service_locator_info(context,
2649-
dest_host)
2650-
ds_info = self._remote_api.select_ds_for_volume(context, dest_host,
2651-
volume)
2647+
dest_api = remote_api.VmdkDriverRemoteApi()
2648+
2649+
service_locator = dest_api.get_service_locator_info(context, dest_host)
2650+
ds_info = dest_api.select_ds_for_volume(context, dest_host, volume)
2651+
26522652
host_ref = vim_util.get_moref(ds_info['host'], 'HostSystem')
26532653
rp_ref = vim_util.get_moref(ds_info['resource_pool'], 'ResourcePool')
26542654
ds_ref = vim_util.get_moref(ds_info['datastore'], 'Datastore')
26552655

26562656
self.volumeops.relocate_backing(backing, ds_ref, rp_ref, host_ref,
26572657
service=service_locator)
26582658
try:
2659-
self._remote_api.move_volume_backing_to_folder(
2659+
dest_api.move_volume_backing_to_folder(
26602660
context, dest_host, volume, ds_info['folder'])
26612661
except Exception:
26622662
# At this point the backing has been migrated to the new host.

0 commit comments

Comments
 (0)