Skip to content

Commit 6657401

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "nova-manage: Ensure mountpoint is passed when updating attachment"
2 parents 7967ad7 + d59188d commit 6657401

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

nova/cmd/manage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,8 @@ def _refresh(self, instance_uuid, volume_id, connector):
30093009
# Update the attachment with host connector, this regenerates
30103010
# the connection_info that we can now stash in the bdm.
30113011
new_connection_info = volume_api.attachment_update(
3012-
cctxt, new_attachment_id, connector)['connection_info']
3012+
cctxt, new_attachment_id, connector,
3013+
bdm.device_name)['connection_info']
30133014

30143015
# Before we save it to the BDM ensure the serial is stashed as
30153016
# is done in various other codepaths when attaching volumes.

nova/tests/fixtures/cinder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@ def fake_attachment_update(
324324
volume_id, _attachment['id'],
325325
_attachment['connector'].get('host')))
326326

327+
# If the mountpoint was provided stash it in the connector as we do
328+
# within nova.volume.cinder.API.attachment_update before calling
329+
# c-api and then stash the connector in the attachment record.
330+
if mountpoint:
331+
connector['device'] = mountpoint
327332
attachment['connector'] = connector
333+
328334
LOG.info('Updating volume attachment: %s', attachment_id)
329335
attachment_ref = {
330336
'id': attachment_id,

nova/tests/functional/test_nova_manage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ def test_refresh(self):
297297

298298
bdm = objects.BlockDeviceMapping.get_by_volume_and_instance(
299299
self.ctxt, volume_id, server['id'])
300+
original_device_name = bdm.device_name
300301
self.assertEqual(original_attachment_id, bdm.attachment_id)
301302

302303
# The CinderFixture also stashes the attachment id in the
@@ -332,6 +333,12 @@ def test_refresh(self):
332333
self.assertEqual(
333334
new_attachment_id, connection_info['data']['attachment_id'])
334335

336+
# Assert that the original device_name is stashed in the connector of
337+
# the attachment within the fixture.
338+
attachment_ref = attachments[new_attachment_id]
339+
connector = attachment_ref.get('connector')
340+
self.assertEqual(original_device_name, connector.get('device'))
341+
335342
# Assert that we have actions we expect against the instance
336343
self._assert_instance_actions(server)
337344

nova/tests/unit/cmd/test_manage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,14 +3548,16 @@ def test_refresh(
35483548
fake_compute_api = mock_compute_api.return_value
35493549
fake_volume_api = mock_volume_api.return_value
35503550
fake_compute_rpcapi = mock_compute_rpcapi.return_value
3551+
device_name = '/dev/vda'
35513552

35523553
mock_get_instance.return_value = objects.Instance(
35533554
uuid=uuidsentinel.instance,
35543555
vm_state=obj_fields.InstanceState.STOPPED,
35553556
host='foo', locked=False)
35563557
mock_get_bdm.return_value = objects.BlockDeviceMapping(
35573558
uuid=uuidsentinel.bdm, volume_id=uuidsentinel.volume,
3558-
attachment_id=uuidsentinel.instance)
3559+
attachment_id=uuidsentinel.instance,
3560+
device_name=device_name)
35593561
mock_action = mock.Mock(spec=objects.InstanceAction)
35603562
mock_action_start.return_value = mock_action
35613563

@@ -3579,7 +3581,7 @@ def test_refresh(
35793581
fake_volume_api.attachment_delete.assert_called_once_with(
35803582
mock.ANY, uuidsentinel.instance)
35813583
fake_volume_api.attachment_update.assert_called_once_with(
3582-
mock.ANY, uuidsentinel.new_attachment, mock.ANY)
3584+
mock.ANY, uuidsentinel.new_attachment, mock.ANY, device_name)
35833585
fake_volume_api.attachment_complete.assert_called_once_with(
35843586
mock.ANY, uuidsentinel.new_attachment)
35853587
fake_compute_api.unlock.assert_called_once_with(

0 commit comments

Comments
 (0)