From 28a1bb3f3c184991da255e0780e784f14b2f3b3f Mon Sep 17 00:00:00 2001 From: Ponnuvel Palaniyappan Date: Thu, 29 Aug 2024 12:58:12 +0100 Subject: [PATCH] Fix a bug cephfs subvolume size calculation The charm is documented to take the 'size' in gigabytes. But when passing it down to 'ceph fs subvolume', it's incorrectly calculating the bytes. Closes-Bug: #2078019 Change-Id: I94ebe1bf506ef7741dbf9d2975a7ba82405a41ff Signed-off-by: Ponnuvel Palaniyappan --- src/ganesha.py | 4 ++-- unit_tests/test_ganesha.py | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/ganesha.py b/src/ganesha.py index 5c54c11..0cd71d0 100644 --- a/src/ganesha.py +++ b/src/ganesha.py @@ -126,7 +126,7 @@ class GaneshaNFS(object): if existing_shares: return existing_shares[0].path if size is not None: - size_in_bytes = size * 1024 * 1024 + size_in_bytes = size * 1024 * 1024 * 1024 if access_ips is None: access_ips = ['0.0.0.0'] # Ganesha deals with networks just fine, except when the network is @@ -188,7 +188,7 @@ class GaneshaNFS(object): return exports def resize_share(self, name: str, size: int): - size_in_bytes = size * 1024 * 1024 + size_in_bytes = size * 1024 * 1024 * 1024 self._ceph_subvolume_command('resize', 'ceph-fs', name, str(size_in_bytes), '--no_shrink') diff --git a/unit_tests/test_ganesha.py b/unit_tests/test_ganesha.py index ba2dc19..be8d0fe 100644 --- a/unit_tests/test_ganesha.py +++ b/unit_tests/test_ganesha.py @@ -78,3 +78,43 @@ class ExportTest(unittest.TestCase): [ {'Access_Type': 'rw', 'Clients': '10.0.0.0/8, 192.168.0.0/16'}, ]) + + +class TestGaneshaNFS(unittest.TestCase): + + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_ceph_subvolume_command') + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_ganesha_add_export') + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_get_next_export_id') + @unittest.mock.patch.object(ganesha.GaneshaNFS, 'list_shares') + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_ceph_auth_key') + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_rados_get') + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_rados_put') + @unittest.mock.patch.object(ganesha.Export, 'to_export') + def test_create_share(self, mock_export, + mock_rados_put, + mock_rados_get, + mock_auth_key, + mock_list_shares, + mock_export_id, + mock_add_export, + mock_subvolume_command): + mock_subvolume_command.return_value = b'mock-volume' + mock_list_shares.return_value = [] + mock_export_id.return_value = 1 + mock_auth_key.return_value = b'mock-auth-key' + + inst = ganesha.GaneshaNFS('ceph-client', 'mypool') + inst.create_share('test-create-share', size=3, access_ips=None) + + mock_subvolume_command.assert_any_call('create', 'ceph-fs', + 'test-create-share', + str(3 * 1024 * 1024 * 1024)) + + @unittest.mock.patch.object(ganesha.GaneshaNFS, '_ceph_subvolume_command') + def test_resize_share(self, mock_subvolume_command): + inst = ganesha.GaneshaNFS('ceph-client', 'mypool') + inst.resize_share('test-resize-share', 5) + mock_subvolume_command.assert_any_call('resize', 'ceph-fs', + 'test-resize-share', + str(5 * 1024 * 1024 * 1024), + '--no_shrink')