Merge "Revert "Pass host when call attach to Cinder""
This commit is contained in:
commit
df8216b2bc
nova
tests/unit
virt
volume
@ -394,13 +394,8 @@ class ComputeVolumeTestCase(BaseTestCase):
|
|||||||
def test_attach_volume_serial(self):
|
def test_attach_volume_serial(self):
|
||||||
fake_bdm = objects.BlockDeviceMapping(context=self.context,
|
fake_bdm = objects.BlockDeviceMapping(context=self.context,
|
||||||
**self.fake_volume)
|
**self.fake_volume)
|
||||||
|
with (mock.patch.object(cinder.API, 'get_volume_encryption_metadata',
|
||||||
with test.nested(
|
return_value={})):
|
||||||
mock.patch.object(cinder.API, 'get_volume_encryption_metadata'),
|
|
||||||
mock.patch.object(self.compute.driver, 'get_volume_connector')
|
|
||||||
) as (mock_encryptor, mock_connector):
|
|
||||||
mock_encryptor.return_value = {}
|
|
||||||
mock_connector.return_value = {'host': 'fake_host'}
|
|
||||||
instance = self._create_fake_instance_obj()
|
instance = self._create_fake_instance_obj()
|
||||||
self.compute.attach_volume(self.context, instance, bdm=fake_bdm)
|
self.compute.attach_volume(self.context, instance, bdm=fake_bdm)
|
||||||
self.assertEqual(self.cinfo.get('serial'), uuids.volume_id)
|
self.assertEqual(self.cinfo.get('serial'), uuids.volume_id)
|
||||||
@ -525,12 +520,9 @@ class ComputeVolumeTestCase(BaseTestCase):
|
|||||||
self.assertEqual(1, attempts)
|
self.assertEqual(1, attempts)
|
||||||
|
|
||||||
def test_boot_volume_serial(self):
|
def test_boot_volume_serial(self):
|
||||||
|
with (
|
||||||
with test.nested(
|
mock.patch.object(objects.BlockDeviceMapping, 'save')
|
||||||
mock.patch.object(objects.BlockDeviceMapping, 'save'),
|
) as mock_save:
|
||||||
mock.patch.object(self.compute.driver, 'get_volume_connector')
|
|
||||||
) as (mock_save, mock_connector):
|
|
||||||
mock_connector.return_value = {'host': 'fake_host'}
|
|
||||||
block_device_mapping = [
|
block_device_mapping = [
|
||||||
block_device.BlockDeviceDict({
|
block_device.BlockDeviceDict({
|
||||||
'id': 1,
|
'id': 1,
|
||||||
@ -785,9 +777,6 @@ class ComputeVolumeTestCase(BaseTestCase):
|
|||||||
self.stubs.Set(cinder.API, 'get_volume_encryption_metadata',
|
self.stubs.Set(cinder.API, 'get_volume_encryption_metadata',
|
||||||
fake_get_volume_encryption_metadata)
|
fake_get_volume_encryption_metadata)
|
||||||
|
|
||||||
with (mock.patch.object(self.compute.driver, 'get_volume_connector')
|
|
||||||
) as mock_connector:
|
|
||||||
mock_connector.return_value = {'host': 'fake_host'}
|
|
||||||
self.compute.attach_volume(self.context, instance, bdm)
|
self.compute.attach_volume(self.context, instance, bdm)
|
||||||
|
|
||||||
# Poll volume usage & then detach the volume. This will update the
|
# Poll volume usage & then detach the volume. This will update the
|
||||||
@ -4675,14 +4664,14 @@ class ComputeTestCase(BaseTestCase):
|
|||||||
self.stubs.Set(cinder.API, "initialize_connection", fake_init_conn)
|
self.stubs.Set(cinder.API, "initialize_connection", fake_init_conn)
|
||||||
|
|
||||||
def fake_attach(self, context, volume_id, instance_uuid, device_name,
|
def fake_attach(self, context, volume_id, instance_uuid, device_name,
|
||||||
mode='rw', host='fake_host'):
|
mode='rw'):
|
||||||
volume['instance_uuid'] = instance_uuid
|
volume['instance_uuid'] = instance_uuid
|
||||||
volume['device_name'] = device_name
|
volume['device_name'] = device_name
|
||||||
self.stubs.Set(cinder.API, "attach", fake_attach)
|
self.stubs.Set(cinder.API, "attach", fake_attach)
|
||||||
|
|
||||||
# stub out virt driver attach
|
# stub out virt driver attach
|
||||||
def fake_get_volume_connector(*args, **kwargs):
|
def fake_get_volume_connector(*args, **kwargs):
|
||||||
return {'host': 'fake_host'}
|
return {}
|
||||||
self.stubs.Set(self.compute.driver, 'get_volume_connector',
|
self.stubs.Set(self.compute.driver, 'get_volume_connector',
|
||||||
fake_get_volume_connector)
|
fake_get_volume_connector)
|
||||||
|
|
||||||
|
@ -206,8 +206,7 @@ class API(object):
|
|||||||
if instance and not volume.get('attachments', {}).get(instance.uuid):
|
if instance and not volume.get('attachments', {}).get(instance.uuid):
|
||||||
raise exception.VolumeUnattached(volume_id=volume['id'])
|
raise exception.VolumeUnattached(volume_id=volume['id'])
|
||||||
|
|
||||||
def attach(self, context, volume_id, instance_uuid, mountpoint, mode='rw',
|
def attach(self, context, volume_id, instance_uuid, mountpoint, mode='rw'):
|
||||||
host=None):
|
|
||||||
LOG.info('attaching volume %s', volume_id)
|
LOG.info('attaching volume %s', volume_id)
|
||||||
volume = self.get(context, volume_id)
|
volume = self.get(context, volume_id)
|
||||||
volume['status'] = 'in-use'
|
volume['status'] = 'in-use'
|
||||||
|
@ -450,14 +450,11 @@ class TestDriverBlockDevice(test.NoDBTestCase):
|
|||||||
if not fail_volume_attach:
|
if not fail_volume_attach:
|
||||||
self.volume_api.attach(elevated_context, fake_volume['id'],
|
self.volume_api.attach(elevated_context, fake_volume['id'],
|
||||||
'fake_uuid', bdm_dict['device_name'],
|
'fake_uuid', bdm_dict['device_name'],
|
||||||
mode=access_mode,
|
mode=access_mode).AndReturn(None)
|
||||||
host=connector['host']).AndReturn(
|
|
||||||
None)
|
|
||||||
else:
|
else:
|
||||||
self.volume_api.attach(elevated_context, fake_volume['id'],
|
self.volume_api.attach(elevated_context, fake_volume['id'],
|
||||||
'fake_uuid', bdm_dict['device_name'],
|
'fake_uuid', bdm_dict['device_name'],
|
||||||
mode=access_mode,
|
mode=access_mode).AndRaise(
|
||||||
host=connector['host']).AndRaise(
|
|
||||||
test.TestingException)
|
test.TestingException)
|
||||||
if driver_attach:
|
if driver_attach:
|
||||||
self.virt_driver.detach_volume(
|
self.virt_driver.detach_volume(
|
||||||
|
@ -252,12 +252,11 @@ class CinderApiTestCase(test.NoDBTestCase):
|
|||||||
mock_volumes = mock.MagicMock()
|
mock_volumes = mock.MagicMock()
|
||||||
mock_cinderclient.return_value = mock.MagicMock(volumes=mock_volumes)
|
mock_cinderclient.return_value = mock.MagicMock(volumes=mock_volumes)
|
||||||
|
|
||||||
self.api.attach(self.ctx, 'id1', 'uuid', 'point', host='fake_host')
|
self.api.attach(self.ctx, 'id1', 'uuid', 'point')
|
||||||
|
|
||||||
mock_cinderclient.assert_called_once_with(self.ctx)
|
mock_cinderclient.assert_called_once_with(self.ctx)
|
||||||
mock_volumes.attach.assert_called_once_with('id1', 'uuid', 'point',
|
mock_volumes.attach.assert_called_once_with('id1', 'uuid', 'point',
|
||||||
mode='rw',
|
mode='rw')
|
||||||
host_name='fake_host')
|
|
||||||
|
|
||||||
@mock.patch('nova.volume.cinder.cinderclient')
|
@mock.patch('nova.volume.cinder.cinderclient')
|
||||||
def test_attach_with_mode(self, mock_cinderclient):
|
def test_attach_with_mode(self, mock_cinderclient):
|
||||||
@ -268,7 +267,7 @@ class CinderApiTestCase(test.NoDBTestCase):
|
|||||||
|
|
||||||
mock_cinderclient.assert_called_once_with(self.ctx)
|
mock_cinderclient.assert_called_once_with(self.ctx)
|
||||||
mock_volumes.attach.assert_called_once_with('id1', 'uuid', 'point',
|
mock_volumes.attach.assert_called_once_with('id1', 'uuid', 'point',
|
||||||
mode='ro', host_name=None)
|
mode='ro')
|
||||||
|
|
||||||
def test_detach(self):
|
def test_detach(self):
|
||||||
self.mox.StubOutWithMock(self.api,
|
self.mox.StubOutWithMock(self.api,
|
||||||
|
@ -300,10 +300,8 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
|
|||||||
# detach.
|
# detach.
|
||||||
self.save()
|
self.save()
|
||||||
try:
|
try:
|
||||||
host = connector.get('host')
|
|
||||||
volume_api.attach(context, volume_id, instance.uuid,
|
volume_api.attach(context, volume_id, instance.uuid,
|
||||||
self['mount_device'], mode=mode,
|
self['mount_device'], mode=mode)
|
||||||
host=host)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
if do_driver_attach:
|
if do_driver_attach:
|
||||||
|
@ -358,11 +358,9 @@ class API(object):
|
|||||||
cinderclient(context).volumes.roll_detaching(volume_id)
|
cinderclient(context).volumes.roll_detaching(volume_id)
|
||||||
|
|
||||||
@translate_volume_exception
|
@translate_volume_exception
|
||||||
def attach(self, context, volume_id, instance_uuid, mountpoint, mode='rw',
|
def attach(self, context, volume_id, instance_uuid, mountpoint, mode='rw'):
|
||||||
host=None):
|
|
||||||
cinderclient(context).volumes.attach(volume_id, instance_uuid,
|
cinderclient(context).volumes.attach(volume_id, instance_uuid,
|
||||||
mountpoint, mode=mode,
|
mountpoint, mode=mode)
|
||||||
host_name=host)
|
|
||||||
|
|
||||||
@translate_volume_exception
|
@translate_volume_exception
|
||||||
def detach(self, context, volume_id, instance_uuid=None,
|
def detach(self, context, volume_id, instance_uuid=None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user