]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add a unit test to cover apply func create_only argument
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 1 May 2024 14:55:34 +0000 (10:55 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 13 Jun 2024 13:54:05 +0000 (09:54 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/tests/test_handler.py

index ceaf044744d6490ec3496a70de14372205e710f5..b08339f57ad06538dbb0e298fcb130c1af906529 100644 (file)
@@ -1116,3 +1116,91 @@ def test_rand_name():
     assert len(name) == 18
     name = smb.handler.rand_name('')
     assert len(name) == 8
+
+
+def test_apply_with_create_only(thandler):
+    test_apply_full_cluster_create(thandler)
+
+    to_apply = [
+        smb.resources.Cluster(
+            cluster_id='mycluster1',
+            auth_mode=smb.enums.AuthMode.ACTIVE_DIRECTORY,
+            domain_settings=smb.resources.DomainSettings(
+                realm='MYDOMAIN.EXAMPLE.ORG',
+                join_sources=[
+                    smb.resources.JoinSource(
+                        source_type=smb.enums.JoinSourceType.RESOURCE,
+                        ref='join1',
+                    ),
+                ],
+            ),
+            custom_dns=['192.168.76.204'],
+        ),
+        smb.resources.Share(
+            cluster_id='mycluster1',
+            share_id='homedirs',
+            name='Altered Home Directries',
+            cephfs=smb.resources.CephFSStorage(
+                volume='cephfs',
+                subvolume='homedirs',
+                path='/',
+            ),
+        ),
+        smb.resources.Share(
+            cluster_id='mycluster1',
+            share_id='foodirs',
+            name='Foo Directries',
+            cephfs=smb.resources.CephFSStorage(
+                volume='cephfs',
+                subvolume='homedirs',
+                path='/foo',
+            ),
+        ),
+    ]
+    results = thandler.apply(to_apply, create_only=True)
+    assert not results.success
+    rs = results.to_simplified()
+    assert len(rs['results']) == 3
+    assert (
+        rs['results'][0]['msg']
+        == 'a resource with the same ID already exists'
+    )
+    assert (
+        rs['results'][1]['msg']
+        == 'a resource with the same ID already exists'
+    )
+
+    # no changes to the store
+    assert (
+        'shares',
+        'mycluster1.foodirs',
+    ) not in thandler.internal_store.data
+    assert ('shares', 'mycluster1.homedirs') in thandler.internal_store.data
+    assert (
+        thandler.internal_store.data[('shares', 'mycluster1.homedirs')][
+            'name'
+        ]
+        == 'Home Directries'
+    )
+
+    # foodirs share is new, it can be applied separately
+    to_apply = [
+        smb.resources.Share(
+            cluster_id='mycluster1',
+            share_id='foodirs',
+            name='Foo Directries',
+            cephfs=smb.resources.CephFSStorage(
+                volume='cephfs',
+                subvolume='homedirs',
+                path='/foo',
+            ),
+        ),
+    ]
+    results = thandler.apply(to_apply, create_only=True)
+    assert results.success
+    rs = results.to_simplified()
+    assert len(rs['results']) == 1
+    assert (
+        'shares',
+        'mycluster1.foodirs',
+    ) in thandler.internal_store.data