From: John Mulligan Date: Wed, 1 May 2024 14:55:34 +0000 (-0400) Subject: mgr/smb: add a unit test to cover apply func create_only argument X-Git-Tag: v20.0.0~1728^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=751bae6f9b9afd0b7ff50127154cb67e4d5791be;p=ceph.git mgr/smb: add a unit test to cover apply func create_only argument Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/tests/test_handler.py b/src/pybind/mgr/smb/tests/test_handler.py index ceaf044744d64..b08339f57ad06 100644 --- a/src/pybind/mgr/smb/tests/test_handler.py +++ b/src/pybind/mgr/smb/tests/test_handler.py @@ -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