Skip to content

Commit

Permalink
block_device: Make refresh_conn_infos py3 compatible
Browse files Browse the repository at this point in the history
Also add a simple test ensuring that refresh_connection_info is called
for each DriverVolumeBlockDevice derived device provided.

Related-Bug: #1419577
Partially-Implements: blueprint goal-python35
Change-Id: Ib1ff00e7f4f5b599317d7111c322ce9af8a9a2b1
  • Loading branch information
lyarwood committed Oct 11, 2016
1 parent 0b59a2d commit b83cae0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
33 changes: 33 additions & 0 deletions nova/tests/unit/virt/test_block_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,36 @@ def test_get_volume_create_az_cinder_cross_az_attach_true(self):
instance = fake_instance.fake_instance_obj(self.context, **updates)
self.assertIsNone(
driver_block_device._get_volume_create_az_value(instance))

def test_refresh_conn_infos(self):
# Only DriverVolumeBlockDevice derived devices should refresh their
# connection_info during a refresh_conn_infos call.
test_volume = mock.MagicMock(
spec=driver_block_device.DriverVolumeBlockDevice)
test_image = mock.MagicMock(
spec=driver_block_device.DriverImageBlockDevice)
test_snapshot = mock.MagicMock(
spec=driver_block_device.DriverSnapshotBlockDevice)
test_blank = mock.MagicMock(
spec=driver_block_device.DriverBlankBlockDevice)
test_eph = mock.MagicMock(
spec=driver_block_device.DriverEphemeralBlockDevice)
test_swap = mock.MagicMock(
spec=driver_block_device.DriverSwapBlockDevice)
block_device_mapping = [test_volume, test_image, test_eph,
test_snapshot, test_swap, test_blank]
driver_block_device.refresh_conn_infos(block_device_mapping,
mock.sentinel.refresh_context,
mock.sentinel.refresh_instance,
mock.sentinel.refresh_vol_api,
mock.sentinel.refresh_virt_drv)
for test_mock in [test_volume, test_image, test_snapshot, test_blank]:
test_mock.refresh_connection_info.assert_called_once_with(
mock.sentinel.refresh_context,
mock.sentinel.refresh_instance,
mock.sentinel.refresh_vol_api,
mock.sentinel.refresh_virt_drv)
# NOTE(lyarwood): Can't think of a better way of testing this as we
# can't assert_not_called if the method isn't in the spec.
self.assertFalse(hasattr(test_eph, 'refresh_connection_info'))
self.assertFalse(hasattr(test_swap, 'refresh_connection_info'))
9 changes: 5 additions & 4 deletions nova/virt/block_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import functools
import itertools
import operator

from oslo_log import log as logging
from oslo_serialization import jsonutils
Expand Down Expand Up @@ -514,9 +513,11 @@ def _log_and_attach(bdm):


def refresh_conn_infos(block_device_mapping, *refresh_args, **refresh_kwargs):
map(operator.methodcaller('refresh_connection_info',
*refresh_args, **refresh_kwargs),
block_device_mapping)
for device in block_device_mapping:
# NOTE(lyarwood): At present only DriverVolumeBlockDevice derived
# devices provide a refresh_connection_info method.
if hasattr(device, 'refresh_connection_info'):
device.refresh_connection_info(*refresh_args, **refresh_kwargs)
return block_device_mapping


Expand Down

0 comments on commit b83cae0

Please sign in to comment.