diff --git a/manila/share/drivers/dell_emc/plugins/unity/client.py b/manila/share/drivers/dell_emc/plugins/unity/client.py index 889e21822c..1e9cb7de9d 100644 --- a/manila/share/drivers/dell_emc/plugins/unity/client.py +++ b/manila/share/drivers/dell_emc/plugins/unity/client.py @@ -18,6 +18,7 @@ import six from oslo_log import log from oslo_utils import importutils +from oslo_utils import units storops = importutils.try_import('storops') if storops: @@ -30,6 +31,9 @@ from manila.i18n import _, _LI, _LE LOG = log.getLogger(__name__) +# Minimun file system size in Unity +MIN_FS_SIZE_IN_GB = 3 + class UnityClient(object): def __init__(self, host, username, password): @@ -69,16 +73,16 @@ class UnityClient(object): except storops_ex.UnityNfsShareNameExistedError: return self.get_share(share_name, 'NFS') - @staticmethod - def create_nfs_filesystem_and_share( - pool, nas_server, share_name, size): + def create_nfs_filesystem_and_share(self, pool, nas_server, + share_name, size_gb): """Create filesystem and share from pool/NAS server. :param pool: pool for file system creation :param nas_server: nas server for file system creation :param share_name: file system and share name - :param size: file system size + :param size_gb: file system size """ + size = self.get_valid_fs_size_in_byte(size_gb) pool.create_nfs_share( nas_server, share_name, size) @@ -98,8 +102,9 @@ class UnityClient(object): def delete_share(share): share.delete() - def create_filesystem(self, pool, nas_server, share_name, size, proto): + def create_filesystem(self, pool, nas_server, share_name, size_gb, proto): try: + size = self.get_valid_fs_size_in_byte(size_gb) return pool.create_filesystem(nas_server, share_name, size, @@ -272,3 +277,20 @@ class UnityClient(object): link_up_ports.append(port) return link_up_ports + + @staticmethod + def get_valid_fs_size_in_byte(size_gb): + if size_gb < MIN_FS_SIZE_IN_GB: + LOG.debug('Using %(min_size)s GB file system for shares less than ' + '%(min_size)s GB.', {'min_size': MIN_FS_SIZE_IN_GB}) + size_gb = MIN_FS_SIZE_IN_GB + return size_gb * units.Gi + + def extend_filesystem(self, fs, new_size_gb): + size = self.get_valid_fs_size_in_byte(new_size_gb) + try: + fs.extend(size) + except storops_ex.UnityNothingToModifyError: + LOG.debug('The size of the file system %(id)s is %(size)s ' + 'bytes.', {'id': fs.get_id(), 'size': size}) + return size diff --git a/manila/share/drivers/dell_emc/plugins/unity/connection.py b/manila/share/drivers/dell_emc/plugins/unity/connection.py index 1dfabb806f..c7b6965f07 100644 --- a/manila/share/drivers/dell_emc/plugins/unity/connection.py +++ b/manila/share/drivers/dell_emc/plugins/unity/connection.py @@ -17,7 +17,6 @@ from oslo_log import log from oslo_utils import excutils from oslo_utils import importutils -from oslo_utils import units storops = importutils.try_import('storops') if storops: @@ -98,7 +97,7 @@ class UnityStorageConnection(driver.StorageConnection): def create_share(self, context, share, share_server=None): """Create a share and export it based on protocol used.""" share_name = share['id'] - size = share['size'] * units.Gi + size = share['size'] # Check share's protocol. # Throw an exception immediately if it is an invalid protocol. @@ -205,7 +204,8 @@ class UnityStorageConnection(driver.StorageConnection): share['share_proto']) if not self._is_share_from_snapshot(backend_share): - backend_share.filesystem.extend(new_size * units.Gi) + self.client.extend_filesystem(backend_share.filesystem, + new_size) else: share_id = share['id'] reason = _LE("Driver does not support extending a " diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/fake_exceptions.py b/manila/tests/share/drivers/dell_emc/plugins/unity/fake_exceptions.py index a743872061..d37a9d2e0c 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/fake_exceptions.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/fake_exceptions.py @@ -64,3 +64,7 @@ class UnityNfsAlreadyEnabledError(UnityException): class UnityHostNotFoundException(UnityException): pass + + +class UnityNothingToModifyError(UnityException): + pass diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml b/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml index b514ed00ec..f3c1fa76d6 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml @@ -972,3 +972,11 @@ test_get_storage_processor: unity: _methods: get_sp: *sp_a + +test_extend_filesystem: + fs: + _methods: + get_id: 'svc_12' + extend: + _raise: + UnityNothingToModifyError: diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py b/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py index e67b7e0670..7d62172244 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py @@ -13,11 +13,15 @@ # License for the specific language governing permissions and limitations # under the License. +import ddt +from oslo_utils import units + from manila import exception from manila import test from manila.tests.share.drivers.dell_emc.plugins.unity import res_mock +@ddt.ddt class TestClient(test.TestCase): @res_mock.mock_client_input @res_mock.patch_client @@ -166,3 +170,20 @@ class TestClient(test.TestCase): sp = client.get_storage_processor(sp_id='SPA') self.assertEqual('SPA', sp.name) + + @ddt.data((1, 3), (2, 3), (3, 3), (4, 4), (10, 10)) + @ddt.unpack + @res_mock.patch_client + def test_get_valid_fs_size(self, client, share_size_gb, fs_size_gb): + size = client.get_valid_fs_size_in_byte(share_size_gb) + + self.assertEqual(fs_size_gb * units.Gi, size) + + @res_mock.mock_client_input + @res_mock.patch_client + def test_extend_filesystem(self, client, mocked_input): + fs = mocked_input['fs'] + + size = client.extend_filesystem(fs, 5) + + self.assertEqual(5 * units.Gi, size) diff --git a/releasenotes/notes/unity-drvier-support-1gb-share-48f032dff8a6a789.yaml b/releasenotes/notes/unity-drvier-support-1gb-share-48f032dff8a6a789.yaml new file mode 100644 index 0000000000..a2134df12d --- /dev/null +++ b/releasenotes/notes/unity-drvier-support-1gb-share-48f032dff8a6a789.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Shares under 3 GB cannot be created on the Dell EMC Unity back end. If users + create shares smaller than 3 GB, they will be allocated a 3 GB file system on + the Unity system.