|
14 | 14 | NFS_POOL_NAME = '.nfs' # should match mgr_module.py |
15 | 15 |
|
16 | 16 | # TODO Add test for cluster update when ganesha can be deployed on multiple ports. |
| 17 | + |
| 18 | + |
17 | 19 | class TestNFS(MgrTestCase): |
18 | 20 | def _cmd(self, *args): |
19 | 21 | return self.get_ceph_cmd_stdout(args) |
@@ -119,18 +121,20 @@ def _check_nfs_cluster_status(self, expected_status, fail_msg): |
119 | 121 | return |
120 | 122 | self.fail(fail_msg) |
121 | 123 |
|
122 | | - def _check_auth_ls(self, fs_name, check_in=False): |
| 124 | + def _check_auth_ls(self, fs_name, check_in=False, user_id=None): |
123 | 125 | ''' |
124 | 126 | Tests export user id creation or deletion. |
125 | 127 | :param export_id: Denotes export number |
126 | 128 | :param check_in: Check specified export id |
127 | 129 | ''' |
128 | 130 | output = self._cmd('auth', 'ls') |
129 | 131 | client_id = f'client.nfs.{self.cluster_id}' |
| 132 | + search_id = f'client.{user_id}' if user_id else f'{client_id}.{fs_name}' |
| 133 | + |
130 | 134 | if check_in: |
131 | | - self.assertIn(f'{client_id}.{fs_name}', output) |
| 135 | + self.assertIn(search_id, output) |
132 | 136 | else: |
133 | | - self.assertNotIn(f'{client_id}.{fs_name}', output) |
| 137 | + self.assertNotIn(search_id, output) |
134 | 138 |
|
135 | 139 | def _test_idempotency(self, cmd_func, cmd_args): |
136 | 140 | ''' |
@@ -231,11 +235,11 @@ def _create_default_export(self): |
231 | 235 | self._test_create_cluster() |
232 | 236 | self._create_export(export_id='1', create_fs=True) |
233 | 237 |
|
234 | | - def _delete_export(self): |
| 238 | + def _delete_export(self, pseduo_path=None): |
235 | 239 | ''' |
236 | 240 | Delete an export. |
237 | 241 | ''' |
238 | | - self._nfs_cmd('export', 'rm', self.cluster_id, self.pseudo_path) |
| 242 | + self._nfs_cmd('export', 'rm', self.cluster_id, pseduo_path if pseduo_path else self.pseudo_path) |
239 | 243 | self._check_auth_ls(self.fs_name) |
240 | 244 |
|
241 | 245 | def _test_list_export(self): |
@@ -272,11 +276,12 @@ def _test_list_detailed(self, sub_vol_path): |
272 | 276 | self.sample_export['fsal']['user_id'] = f'{self.expected_name}.{self.fs_name}.3746f603' |
273 | 277 | self.assertDictEqual(self.sample_export, nfs_output[3]) |
274 | 278 |
|
275 | | - def _get_export(self): |
| 279 | + def _get_export(self, pseudo_path=None): |
276 | 280 | ''' |
277 | 281 | Returns export block in json format |
278 | 282 | ''' |
279 | | - return json.loads(self._nfs_cmd('export', 'info', self.cluster_id, self.pseudo_path)) |
| 283 | + return json.loads(self._nfs_cmd('export', 'info', self.cluster_id, |
| 284 | + pseudo_path if pseudo_path else self.pseudo_path)) |
280 | 285 |
|
281 | 286 | def _test_get_export(self): |
282 | 287 | ''' |
@@ -1212,3 +1217,64 @@ def test_cephfs_export_update_at_non_dir_path(self): |
1212 | 1217 | finally: |
1213 | 1218 | self.ctx.cluster.run(args=['rm', '-rf', f'{mnt_pt}/*']) |
1214 | 1219 | self._delete_cluster_with_fs(self.fs_name, mnt_pt, preserve_mode) |
| 1220 | + |
| 1221 | + def test_nfs_export_creation_without_cmount_path(self): |
| 1222 | + """ |
| 1223 | + Test that ensure cmount_path is present in FSAL block |
| 1224 | + """ |
| 1225 | + pseudo_path = '/test_without_cmount' |
| 1226 | + self._create_export(export_id='1234', |
| 1227 | + extra_cmd=['--pseudo-path', pseudo_path]) |
| 1228 | + nfs_output = self._get_export(pseudo_path) |
| 1229 | + self.assertIn('cmount_path', nfs_output['fsal']) |
| 1230 | + |
| 1231 | + self._delete_export(pseudo_path) |
| 1232 | + |
| 1233 | + def test_nfs_exports_with_same_and_diff_user_id(self): |
| 1234 | + """ |
| 1235 | + Test that exports with same FSAL share same user_id |
| 1236 | + """ |
| 1237 | + pseudo_path_1 = '/test1' |
| 1238 | + pseudo_path_2 = '/test2' |
| 1239 | + pseudo_path_3 = '/test3' |
| 1240 | + |
| 1241 | + # Create subvolumes |
| 1242 | + self._cmd('fs', 'subvolume', 'create', self.fs_name, 'sub_vol_1') |
| 1243 | + self._cmd('fs', 'subvolume', 'create', self.fs_name, 'sub_vol_2') |
| 1244 | + |
| 1245 | + fs_path_1 = self._cmd('fs', 'subvolume', 'getpath', self.fs_name, 'sub_vol_1').strip() |
| 1246 | + fs_path_2 = self._cmd('fs', 'subvolume', 'getpath', self.fs_name, 'sub_vol_2').strip() |
| 1247 | + # Both exports should have same user_id(since cmount_path=/ & fs_name is same) |
| 1248 | + self._create_export(export_id='21', |
| 1249 | + extra_cmd=['--pseudo-path', pseudo_path_1, |
| 1250 | + '--path', fs_path_1]) |
| 1251 | + self._create_export(export_id='22', |
| 1252 | + extra_cmd=['--pseudo-path', pseudo_path_2, |
| 1253 | + '--path', fs_path_2]) |
| 1254 | + |
| 1255 | + nfs_output_1 = self._get_export(pseudo_path_1) |
| 1256 | + nfs_output_2 = self._get_export(pseudo_path_2) |
| 1257 | + # Check if both exports have same user_id |
| 1258 | + self.assertEqual(nfs_output_2['fsal']['user_id'], nfs_output_1['fsal']['user_id']) |
| 1259 | + self.assertEqual(nfs_output_1['fsal']['user_id'], 'nfs.test.nfs-cephfs.3746f603') |
| 1260 | + |
| 1261 | + cmount_path = '/volumes' |
| 1262 | + self._create_export(export_id='23', |
| 1263 | + extra_cmd=['--pseudo-path', pseudo_path_3, |
| 1264 | + '--path', fs_path_1, |
| 1265 | + '--cmount-path', cmount_path]) |
| 1266 | + |
| 1267 | + nfs_output_3 = self._get_export(pseudo_path_3) |
| 1268 | + self.assertNotEqual(nfs_output_3['fsal']['user_id'], nfs_output_1['fsal']['user_id']) |
| 1269 | + self.assertEqual(nfs_output_3['fsal']['user_id'], 'nfs.test.nfs-cephfs.32cd8545') |
| 1270 | + |
| 1271 | + self._delete_export(pseudo_path_1) |
| 1272 | + # Deleting export with same user_id should not delete the user_id |
| 1273 | + self._check_auth_ls(self.fs_name, True, nfs_output_2['fsal']['user_id']) |
| 1274 | + self._delete_export(pseudo_path_2) |
| 1275 | + # Deleting export 22 should delete the user_id since it's only export left with that user_id |
| 1276 | + self._check_auth_ls(self.fs_name, False, nfs_output_2['fsal']['user_id']) |
| 1277 | + |
| 1278 | + self._delete_export(pseudo_path_3) |
| 1279 | + # Deleting export 23 should delete the user_id since it's only export with that user_id |
| 1280 | + self._check_auth_ls(self.fs_name, False, nfs_output_3['fsal']['user_id']) |
0 commit comments