diff --git a/cinder/tests/unit/volume/drivers/test_infinidat.py b/cinder/tests/unit/volume/drivers/test_infinidat.py index 1539f65f0d5..76cd068fbd5 100644 --- a/cinder/tests/unit/volume/drivers/test_infinidat.py +++ b/cinder/tests/unit/volume/drivers/test_infinidat.py @@ -59,6 +59,7 @@ class InfiniboxDriverTestCaseBase(test.TestCase): self.configuration.san_is_local = False self.configuration.chap_username = None self.configuration.chap_password = None + self.configuration.infinidat_use_compression = None self.driver = infinidat.InfiniboxVolumeDriver( configuration=self.configuration) @@ -208,6 +209,31 @@ class InfiniboxDriverTestCase(InfiniboxDriverTestCaseBase): self.driver.create_volume(test_volume) self._mock_volume.set_metadata_from_dict.assert_called_once() + @mock.patch("cinder.volume.volume_types.get_volume_type_qos_specs") + def test_create_volume_compression_enabled(self, *mocks): + self.configuration.infinidat_use_compression = True + self.driver.create_volume(test_volume) + self.assertTrue( + self._system.volumes.create.call_args[1]["compression_enabled"] + ) + + @mock.patch("cinder.volume.volume_types.get_volume_type_qos_specs") + def test_create_volume_compression_not_enabled(self, *mocks): + self.configuration.infinidat_use_compression = False + self.driver.create_volume(test_volume) + self.assertFalse( + self._system.volumes.create.call_args[1]["compression_enabled"] + ) + + @mock.patch("cinder.volume.volume_types.get_volume_type_qos_specs") + def test_create_volume_compression_not_available(self, *mocks): + self._system.compat.has_compression.return_value = False + self.driver.create_volume(test_volume) + self.assertNotIn( + "compression_enabled", + self._system.volumes.create.call_args[1] + ) + def test_delete_volume(self): self.driver.delete_volume(test_volume) diff --git a/cinder/volume/drivers/infinidat.py b/cinder/volume/drivers/infinidat.py index bb7e1a21eb8..a7fc334cd4e 100644 --- a/cinder/volume/drivers/infinidat.py +++ b/cinder/volume/drivers/infinidat.py @@ -76,6 +76,10 @@ infinidat_opts = [ default=[], help='List of names of network spaces to use for iSCSI ' 'connectivity'), + cfg.BoolOpt('infinidat_use_compression', + default=False, + help='Specifies whether to turn on compression for newly ' + 'created volumes.'), ] CONF = cfg.CONF @@ -97,7 +101,7 @@ def infinisdk_to_cinder_exceptions(func): @interface.volumedriver class InfiniboxVolumeDriver(san.SanISCSIDriver): - VERSION = '1.4' + VERSION = '1.5' # ThirdPartySystems wiki page CI_WIKI_NAME = "INFINIDAT_Cinder_CI" @@ -128,6 +132,15 @@ class InfiniboxVolumeDriver(san.SanISCSIDriver): raise exception.VolumeDriverException(message=msg) else: self._protocol = 'FC' + if (self.configuration.infinidat_use_compression and + not self._system.compat.has_compression()): + # InfiniBox systems support compression only from v3.0 and up + msg = _('InfiniBox system does not support volume compression.\n' + 'Compression is available on InfiniBox 3.0 onward.\n' + 'Please disable volume compression by setting ' + 'infinidat_use_compression to False in the Cinder ' + 'configuration file.') + raise exception.VolumeDriverException(message=msg) LOG.debug('setup complete') def _make_volume_name(self, cinder_volume): @@ -429,10 +442,14 @@ 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 - infinidat_volume = self._system.volumes.create(name=volume_name, - pool=pool, - provtype=provtype, - size=size) + create_kwargs = dict(name=volume_name, + pool=pool, + provtype=provtype, + size=size) + if self._system.compat.has_compression(): + create_kwargs["compression_enabled"] = ( + self.configuration.infinidat_use_compression) + infinidat_volume = self._system.volumes.create(**create_kwargs) self._set_qos(volume, infinidat_volume) self._set_cinder_object_metadata(infinidat_volume, volume) return infinidat_volume diff --git a/releasenotes/notes/infinidat-compression-a828904aaba90da2.yaml b/releasenotes/notes/infinidat-compression-a828904aaba90da2.yaml new file mode 100644 index 00000000000..8f3894c4a5e --- /dev/null +++ b/releasenotes/notes/infinidat-compression-a828904aaba90da2.yaml @@ -0,0 +1,6 @@ +--- +features: + - Added support for volume compression in INFINIDAT driver. + Compression is available on InfiniBox 3.0 onward. + To enable volume compression, set ``infinidat_use_compression`` to + True in the backend section in the Cinder configuration file.