Attached volume has no attached_servers

When use "cinder show" to look up the volume that
has been attached to a container, its status is "in-use"
but its "attached_servers" is none.

The reason is that Zun does not give a value of parameter
"instance_uuid" when call cinder interface of attach.
Then the container's uuid does not be recorded into volume's
attached_servers.

Change-Id: I3bd5e18f3f312a94cbbd4b3d2bbce3b0ae79ea69
Closes-bug: #1786162
This commit is contained in:
weikeyou
2018-08-09 13:44:26 +08:00
parent 30ca058a3d
commit f2d0ee9be3
3 changed files with 10 additions and 5 deletions

View File

@@ -61,7 +61,8 @@ class CinderWorkflowTestCase(base.TestCase):
mock_cinder_api.attach.assert_called_once_with(
volume_id=self.fake_volume_id,
mountpoint=self.fake_device_info['path'],
hostname=CONF.host)
hostname=CONF.host,
container_uuid='123')
mock_connector.disconnect_volume.assert_not_called()
mock_cinder_api.terminate_connection.assert_not_called()
mock_cinder_api.detach.assert_not_called()
@@ -154,7 +155,8 @@ class CinderWorkflowTestCase(base.TestCase):
mock_cinder_api.attach.assert_called_once_with(
volume_id=self.fake_volume_id,
mountpoint=self.fake_device_info['path'],
hostname=CONF.host)
hostname=CONF.host,
container_uuid='123')
mock_connector.disconnect_volume.assert_called_once_with(
self.fake_conn_info['data'], None)
mock_cinder_api.terminate_connection.assert_called_once_with(
@@ -172,6 +174,7 @@ class CinderWorkflowTestCase(base.TestCase):
fail_connect=False, fail_attach=False):
volume = mock.MagicMock()
volume.volume_id = self.fake_volume_id
volume.container_uuid = '123'
mock_cinder_api = mock.MagicMock()
mock_cinder_api_cls.return_value = mock_cinder_api
mock_connector = mock.MagicMock()

View File

@@ -107,9 +107,9 @@ class CinderAPI(object):
def terminate_connection(self, volume_id, connector):
return self.cinder.volumes.terminate_connection(volume_id, connector)
def attach(self, volume_id, mountpoint, hostname):
def attach(self, volume_id, mountpoint, hostname, container_uuid=None):
return self.cinder.volumes.attach(volume=volume_id,
instance_uuid=None,
instance_uuid=container_uuid,
mountpoint=mountpoint,
host_name=hostname)

View File

@@ -85,6 +85,7 @@ class CinderWorkflow(object):
def _do_attach_volume(self, cinder_api, volume):
volume_id = volume.volume_id
container_uuid = volume.container_uuid
cinder_api.reserve_volume(volume_id)
conn_info = cinder_api.initialize_connection(
@@ -116,7 +117,8 @@ class CinderWorkflow(object):
try:
cinder_api.attach(volume_id=volume_id,
mountpoint=mountpoint,
hostname=CONF.host)
hostname=CONF.host,
container_uuid=container_uuid)
LOG.info("Attach volume to this server successfully")
except Exception:
with excutils.save_and_reraise_exception():