]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add a unit test to verify the new name in use check
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 14 May 2024 15:07:38 +0000 (11:07 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Sat, 6 Jul 2024 18:53:06 +0000 (14:53 -0400)
Add a unit test to verify the share name in use check recently added.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/tests/test_handler.py

index 99d1bfd1654ea2f8992386494ec9b4939c938684..5cfafe93f135f8d9d390c2d9ecfb3af48085adde 100644 (file)
@@ -1533,3 +1533,214 @@ def test_remove_in_use_ug(thandler):
     rs = results.to_simplified()
     assert not results.success
     assert 'resource in use' in rs['results'][0]['msg']
+
+
+@pytest.mark.parametrize(
+    "params",
+    [
+        # no conflict
+        {
+            'to_apply': [
+                smb.resources.Share(
+                    cluster_id='c1',
+                    share_id='zeta',
+                    name='Zeta Zoom',
+                    cephfs=smb.resources.CephFSStorage(
+                        volume='cephfs',
+                        path='/zeta',
+                    ),
+                ),
+            ],
+        },
+        # no conflict, name used only in c1 not c2
+        {
+            'to_apply': [
+                smb.resources.Share(
+                    cluster_id='c2',
+                    share_id='max',
+                    name='Beta Max',
+                    cephfs=smb.resources.CephFSStorage(
+                        volume='cephfs',
+                        path='/max',
+                    ),
+                ),
+            ],
+        },
+        # conflict with share in store
+        {
+            'to_apply': [
+                smb.resources.Share(
+                    cluster_id='c1',
+                    share_id='zalpha',
+                    name='Alphabet Soup',
+                    cephfs=smb.resources.CephFSStorage(
+                        volume='cephfs',
+                        path='/zalpha',
+                    ),
+                ),
+            ],
+            'error_msg': 'share name already in use',
+            'conflicts': {'alpha'},
+        },
+        # conflict with new share
+        {
+            'to_apply': [
+                smb.resources.Share(
+                    cluster_id='c1',
+                    share_id='epsilon',
+                    name='Epsilon Eggs',
+                    cephfs=smb.resources.CephFSStorage(
+                        volume='cephfs',
+                        path='/eggs',
+                    ),
+                ),
+                smb.resources.Share(
+                    cluster_id='c1',
+                    share_id='eggs',
+                    name='Epsilon Eggs',
+                    cephfs=smb.resources.CephFSStorage(
+                        volume='cephfs',
+                        path='/eggs',
+                    ),
+                ),
+            ],
+            'error_msg': 'share name already in use',
+            'conflicts': {'eggs'},
+        },
+        # remove share, resue old name
+        {
+            'to_apply': [
+                smb.resources.RemovedShare(
+                    cluster_id='c1',
+                    share_id='beta',
+                ),
+                smb.resources.Share(
+                    cluster_id='c1',
+                    share_id='macks',
+                    name='Beta Max',
+                    cephfs=smb.resources.CephFSStorage(
+                        volume='cephfs',
+                        path='/macks',
+                    ),
+                ),
+            ],
+        },
+    ],
+)
+def test_share_name_in_use(thandler, params):
+    thandler.internal_store.overwrite(
+        {
+            'clusters.c1': {
+                'resource_type': 'ceph.smb.cluster',
+                'cluster_id': 'c1',
+                'auth_mode': 'user',
+                'intent': 'present',
+                'user_group_settings': [
+                    {
+                        'source_type': 'resource',
+                        'ref': 'foo1',
+                    }
+                ],
+            },
+            'clusters.c2': {
+                'resource_type': 'ceph.smb.cluster',
+                'cluster_id': 'c2',
+                'auth_mode': 'user',
+                'intent': 'present',
+                'user_group_settings': [
+                    {
+                        'source_type': 'resource',
+                        'ref': 'foo1',
+                    }
+                ],
+            },
+            'users_and_groups.foo1': {
+                'resource_type': 'ceph.smb.usersgroups',
+                'users_groups_id': 'foo1',
+                'intent': 'present',
+                'values': {
+                    'users': [{"username": "foo"}],
+                    'groups': [],
+                },
+            },
+            'shares.c1.alpha': {
+                'resource_type': 'ceph.smb.share',
+                'cluster_id': 'c1',
+                'share_id': 'alpha',
+                'intent': 'present',
+                'name': 'Alphabet Soup',
+                'readonly': False,
+                'browseable': True,
+                'cephfs': {
+                    'volume': 'cephfs',
+                    'path': '/alpha',
+                    'provider': 'samba-vfs',
+                },
+            },
+            'shares.c1.beta': {
+                'resource_type': 'ceph.smb.share',
+                'cluster_id': 'c1',
+                'share_id': 'beta',
+                'intent': 'present',
+                'name': 'Beta Max',
+                'readonly': False,
+                'browseable': True,
+                'cephfs': {
+                    'volume': 'cephfs',
+                    'path': '/beta',
+                    'provider': 'samba-vfs',
+                },
+            },
+            'shares.c1.gamma': {
+                'resource_type': 'ceph.smb.share',
+                'cluster_id': 'c1',
+                'share_id': 'gamma',
+                'intent': 'present',
+                'name': 'Gamma Raise',
+                'readonly': False,
+                'browseable': True,
+                'cephfs': {
+                    'volume': 'cephfs',
+                    'path': '/gamma',
+                    'provider': 'samba-vfs',
+                },
+            },
+            'shares.c2.soup': {
+                'resource_type': 'ceph.smb.share',
+                'cluster_id': 'c2',
+                'share_id': 'soup',
+                'intent': 'present',
+                'name': 'Alphabet Soup',
+                'readonly': False,
+                'browseable': True,
+                'cephfs': {
+                    'volume': 'cephfs',
+                    'path': '/soup',
+                    'provider': 'samba-vfs',
+                },
+            },
+            'shares.c2.salad': {
+                'resource_type': 'ceph.smb.share',
+                'cluster_id': 'c2',
+                'share_id': 'salad',
+                'intent': 'present',
+                'name': 'Word Salad',
+                'readonly': False,
+                'browseable': True,
+                'cephfs': {
+                    'volume': 'cephfs',
+                    'path': '/salad',
+                    'provider': 'samba-vfs',
+                },
+            },
+        }
+    )
+
+    results = thandler.apply(params['to_apply'])
+    rs = results.to_simplified()
+    if not params.get('error_msg'):
+        assert results.success
+        return
+    assert not results.success
+    assert params['error_msg'] in rs['results'][0]['msg']
+    assert rs['results'][0]['conflicting_share_id'] in params['conflicts']