Merge "INFINIDAT: add metadata to InfiniBox objects"
This commit is contained in:
commit
191a9bbdcc
@ -141,6 +141,11 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
|
|||||||
self.driver.initialize_connection,
|
self.driver.initialize_connection,
|
||||||
test_volume, test_connector)
|
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):
|
def test_terminate_connection(self):
|
||||||
self.driver.terminate_connection(test_volume, test_connector)
|
self.driver.terminate_connection(test_volume, test_connector)
|
||||||
|
|
||||||
@ -194,6 +199,10 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
|
|||||||
self.assertRaises(exception.VolumeBackendAPIException,
|
self.assertRaises(exception.VolumeBackendAPIException,
|
||||||
self.driver.create_volume, test_volume)
|
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):
|
def test_delete_volume(self):
|
||||||
self.driver.delete_volume(test_volume)
|
self.driver.delete_volume(test_volume)
|
||||||
|
|
||||||
@ -218,6 +227,11 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
|
|||||||
def test_create_snapshot(self):
|
def test_create_snapshot(self):
|
||||||
self.driver.create_snapshot(test_snapshot)
|
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):
|
def test_create_snapshot_volume_doesnt_exist(self):
|
||||||
self._system.volumes.safe_get.return_value = None
|
self._system.volumes.safe_get.return_value = None
|
||||||
self.assertRaises(exception.InvalidVolume,
|
self.assertRaises(exception.InvalidVolume,
|
||||||
@ -312,6 +326,12 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase):
|
|||||||
def test_create_group(self, *mocks):
|
def test_create_group(self, *mocks):
|
||||||
self.driver.create_group(None, test_group)
|
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',
|
@mock.patch('cinder.volume.utils.is_group_a_cg_snapshot_type',
|
||||||
return_value=True)
|
return_value=True)
|
||||||
def test_create_group_twice(self, *mocks):
|
def test_create_group_twice(self, *mocks):
|
||||||
|
@ -18,6 +18,8 @@ INFINIDAT InfiniBox Volume Driver
|
|||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import functools
|
import functools
|
||||||
|
import platform
|
||||||
|
import socket
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@ -30,6 +32,7 @@ from cinder.i18n import _
|
|||||||
from cinder import interface
|
from cinder import interface
|
||||||
from cinder.objects import fields
|
from cinder.objects import fields
|
||||||
from cinder import utils
|
from cinder import utils
|
||||||
|
from cinder import version
|
||||||
from cinder.volume.drivers.san import san
|
from cinder.volume.drivers.san import san
|
||||||
from cinder.volume import utils as vol_utils
|
from cinder.volume import utils as vol_utils
|
||||||
from cinder.zonemanager import utils as fczm_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):
|
def _make_group_snapshot_name(self, cinder_group_snap):
|
||||||
return 'openstack-group-snap-%s' % cinder_group_snap.id
|
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):
|
def _get_infinidat_volume_by_name(self, name):
|
||||||
volume = self._system.volumes.safe_get(name=name)
|
volume = self._system.volumes.safe_get(name=name)
|
||||||
if volume is None:
|
if volume is None:
|
||||||
@ -185,6 +202,7 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
|
|||||||
if infinidat_host is None:
|
if infinidat_host is None:
|
||||||
infinidat_host = self._system.hosts.create(name=host_name)
|
infinidat_host = self._system.hosts.create(name=host_name)
|
||||||
infinidat_host.add_port(port)
|
infinidat_host.add_port(port)
|
||||||
|
self._set_host_metadata(infinidat_host)
|
||||||
return infinidat_host
|
return infinidat_host
|
||||||
|
|
||||||
def _get_mapping(self, host, volume):
|
def _get_mapping(self, host, volume):
|
||||||
@ -361,10 +379,12 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
|
|||||||
volume_name = self._make_volume_name(volume)
|
volume_name = self._make_volume_name(volume)
|
||||||
provtype = "THIN" if self.configuration.san_thin_provision else "THICK"
|
provtype = "THIN" if self.configuration.san_thin_provision else "THICK"
|
||||||
size = volume.size * capacity.GiB
|
size = volume.size * capacity.GiB
|
||||||
return self._system.volumes.create(name=volume_name,
|
infinidat_volume = self._system.volumes.create(name=volume_name,
|
||||||
pool=pool,
|
pool=pool,
|
||||||
provtype=provtype,
|
provtype=provtype,
|
||||||
size=size)
|
size=size)
|
||||||
|
self._set_cinder_object_metadata(infinidat_volume, volume)
|
||||||
|
return infinidat_volume
|
||||||
|
|
||||||
@infinisdk_to_cinder_exceptions
|
@infinisdk_to_cinder_exceptions
|
||||||
def create_volume(self, volume):
|
def create_volume(self, volume):
|
||||||
@ -396,7 +416,8 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
|
|||||||
"""Creates a snapshot."""
|
"""Creates a snapshot."""
|
||||||
volume = self._get_infinidat_volume(snapshot.volume)
|
volume = self._get_infinidat_volume(snapshot.volume)
|
||||||
name = self._make_snapshot_name(snapshot)
|
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
|
@contextmanager
|
||||||
def _connection_context(self, volume):
|
def _connection_context(self, volume):
|
||||||
@ -562,8 +583,9 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver):
|
|||||||
# let generic volume group support handle non-cgsnapshots
|
# let generic volume group support handle non-cgsnapshots
|
||||||
if not vol_utils.is_group_a_cg_snapshot_type(group):
|
if not vol_utils.is_group_a_cg_snapshot_type(group):
|
||||||
raise NotImplementedError()
|
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())
|
pool=self._get_infinidat_pool())
|
||||||
|
self._set_cinder_object_metadata(obj, group)
|
||||||
return {'status': fields.GroupStatus.AVAILABLE}
|
return {'status': fields.GroupStatus.AVAILABLE}
|
||||||
|
|
||||||
@infinisdk_to_cinder_exceptions
|
@infinisdk_to_cinder_exceptions
|
||||||
|
Loading…
Reference in New Issue
Block a user