Merge "INFINIDAT: add metadata to InfiniBox objects"

This commit is contained in:
Jenkins 2017-06-19 23:24:17 +00:00 committed by Gerrit Code Review
commit 191a9bbdcc
2 changed files with 49 additions and 7 deletions

View File

@ -141,6 +141,11 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
self.driver.initialize_connection,
test_volume, test_connector)
def test_initialize_connection_metadata(self):
self._system.hosts.safe_get.return_value = None
self.driver.initialize_connection(test_volume, test_connector)
self._mock_host.set_metadata_from_dict.assert_called_once()
def test_terminate_connection(self):
self.driver.terminate_connection(test_volume, test_connector)
@ -194,6 +199,10 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.create_volume, test_volume)
def test_create_volume_metadata(self):
self.driver.create_volume(test_volume)
self._mock_volume.set_metadata_from_dict.assert_called_once()
def test_delete_volume(self):
self.driver.delete_volume(test_volume)
@ -218,6 +227,11 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
def test_create_snapshot(self):
self.driver.create_snapshot(test_snapshot)
def test_create_snapshot_metadata(self):
self._mock_volume.create_snapshot.return_value = self._mock_volume
self.driver.create_snapshot(test_snapshot)
self._mock_volume.set_metadata_from_dict.assert_called_once()
def test_create_snapshot_volume_doesnt_exist(self):
self._system.volumes.safe_get.return_value = None
self.assertRaises(exception.InvalidVolume,
@ -312,6 +326,12 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
def test_create_group(self, *mocks):
self.driver.create_group(None, test_group)
@mock.patch('cinder.volume.utils.is_group_a_cg_snapshot_type',
return_value=True)
def test_create_group_metadata(self, *mocks):
self.driver.create_group(None, test_group)
self._mock_group.set_metadata_from_dict.assert_called_once()
@mock.patch('cinder.volume.utils.is_group_a_cg_snapshot_type',
return_value=True)
def test_create_group_twice(self, *mocks):

View File

@ -18,6 +18,8 @@ INFINIDAT InfiniBox Volume Driver
from contextlib import contextmanager
import functools
import platform
import socket
import mock
from oslo_config import cfg
@ -30,6 +32,7 @@ from cinder.i18n import _
from cinder import interface
from cinder.objects import fields
from cinder import utils
from cinder import version
from cinder.volume.drivers.san import san
from cinder.volume import utils as vol_utils
from cinder.zonemanager import utils as fczm_utils
@ -137,6 +140,20 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
def _make_group_snapshot_name(self, cinder_group_snap):
return 'openstack-group-snap-%s' % cinder_group_snap.id
def _set_cinder_object_metadata(self, infinidat_object, cinder_object):
data = dict(system="openstack",
openstack_version=version.version_info.release_string(),
cinder_id=cinder_object.id,
cinder_name=cinder_object.name)
infinidat_object.set_metadata_from_dict(data)
def _set_host_metadata(self, infinidat_object):
data = dict(system="openstack",
openstack_version=version.version_info.release_string(),
hostname=socket.gethostname(),
platform=platform.platform())
infinidat_object.set_metadata_from_dict(data)
def _get_infinidat_volume_by_name(self, name):
volume = self._system.volumes.safe_get(name=name)
if volume is None:
@ -185,6 +202,7 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
if infinidat_host is None:
infinidat_host = self._system.hosts.create(name=host_name)
infinidat_host.add_port(port)
self._set_host_metadata(infinidat_host)
return infinidat_host
def _get_mapping(self, host, volume):
@ -361,10 +379,12 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
volume_name = self._make_volume_name(volume)
provtype = "THIN" if self.configuration.san_thin_provision else "THICK"
size = volume.size * capacity.GiB
return self._system.volumes.create(name=volume_name,
infinidat_volume = self._system.volumes.create(name=volume_name,
pool=pool,
provtype=provtype,
size=size)
self._set_cinder_object_metadata(infinidat_volume, volume)
return infinidat_volume
@infinisdk_to_cinder_exceptions
def create_volume(self, volume):
@ -396,7 +416,8 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
"""Creates a snapshot."""
volume = self._get_infinidat_volume(snapshot.volume)
name = self._make_snapshot_name(snapshot)
volume.create_snapshot(name=name)
infinidat_snapshot = volume.create_snapshot(name=name)
self._set_cinder_object_metadata(infinidat_snapshot, snapshot)
@contextmanager
def _connection_context(self, volume):
@ -562,8 +583,9 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
# let generic volume group support handle non-cgsnapshots
if not vol_utils.is_group_a_cg_snapshot_type(group):
raise NotImplementedError()
self._system.cons_groups.create(name=self._make_cg_name(group),
obj = self._system.cons_groups.create(name=self._make_cg_name(group),
pool=self._get_infinidat_pool())
self._set_cinder_object_metadata(obj, group)
return {'status': fields.GroupStatus.AVAILABLE}
@infinisdk_to_cinder_exceptions