From: Shweta Sodani Date: Fri, 12 Jun 2026 11:29:22 +0000 (+0530) Subject: mgr/smb: add tests for client compatibility mode X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6f59987690de84158f32b83b911f4785b4b8073a;p=ceph.git mgr/smb: add tests for client compatibility mode Add comprehensive test coverage for the new client compatibility feature that enables macOS-specific SMB optimizations: - test_enums.py: Add tests for ClientSupportMode enum values (DEFAULT and MACOS) and string representation - test_resources.py: Add tests for cluster client_compat field, effective_client_compat property, and is_macos_compatibility_enabled property with different mode configurations - test_smb.py: Add integration tests for cluster_update_client_compat CLI command including successful updates and error handling for non-existent clusters These tests ensure the client compatibility mode can be properly set, retrieved, and updated at the cluster level. Signed-off-by: Shweta Sodani --- diff --git a/src/pybind/mgr/smb/tests/test_enums.py b/src/pybind/mgr/smb/tests/test_enums.py index 1ebd40d238c..641d6593a46 100644 --- a/src/pybind/mgr/smb/tests/test_enums.py +++ b/src/pybind/mgr/smb/tests/test_enums.py @@ -43,3 +43,23 @@ def test_login_access_expand(): == smb.enums.LoginAccess.READ_WRITE ) assert smb.enums.LoginAccess.NONE.expand() == smb.enums.LoginAccess.NONE + + +def test_client_compat_enum(): + """Test ClientSupportMode enum values and string representation.""" + assert smb.enums.ClientSupportMode.DEFAULT == 'default' + assert smb.enums.ClientSupportMode.MACOS == 'macos' + assert str(smb.enums.ClientSupportMode.DEFAULT) == 'default' + assert str(smb.enums.ClientSupportMode.MACOS) == 'macos' + + +def test_client_compat_values(): + """Test that ClientSupportMode can be constructed from string values.""" + assert ( + smb.enums.ClientSupportMode('default') + == smb.enums.ClientSupportMode.DEFAULT + ) + assert ( + smb.enums.ClientSupportMode('macos') + == smb.enums.ClientSupportMode.MACOS + ) diff --git a/src/pybind/mgr/smb/tests/test_resources.py b/src/pybind/mgr/smb/tests/test_resources.py index cb90dd47fba..a9987b2a7ce 100644 --- a/src/pybind/mgr/smb/tests/test_resources.py +++ b/src/pybind/mgr/smb/tests/test_resources.py @@ -750,6 +750,89 @@ login_control: assert share.login_control[3].access == enums.LoginAccess.NONE +def test_cluster_client_compat_default(): + """Test cluster with default client support mode (not set).""" + import yaml + + yaml_str = """ +resource_type: ceph.smb.cluster +cluster_id: testcluster +auth_mode: user +user_group_settings: + - source_type: resource + ref: testusers +""" + data = yaml.safe_load_all(yaml_str) + loaded = smb.resources.load(data) + assert loaded + cluster = loaded[0] + + # When not set, should default to None + assert cluster.client_compat is None + # effective_client_compat should return DEFAULT + assert cluster.effective_client_compat == enums.ClientSupportMode.DEFAULT + # is_macos_compatibility_enabled should be False + assert cluster.is_macos_compatibility_enabled is False + + +def test_cluster_client_compat_macos(): + """Test cluster with macos client support mode enabled.""" + import yaml + + yaml_str = """ +resource_type: ceph.smb.cluster +cluster_id: maccluster +auth_mode: user +user_group_settings: + - source_type: resource + ref: macusers +client_compat: macos +""" + data = yaml.safe_load_all(yaml_str) + loaded = smb.resources.load(data) + assert loaded + cluster = loaded[0] + + # Should be set to MACOS + assert cluster.client_compat == enums.ClientSupportMode.MACOS + # effective_client_compat should return MACOS + assert cluster.effective_client_compat == enums.ClientSupportMode.MACOS + # is_macos_compatibility_enabled should be True + assert cluster.is_macos_compatibility_enabled is True + + # Verify it's in the simplified output + sd = cluster.to_simplified() + assert sd + assert 'client_compat' in sd + assert sd['client_compat'] == 'macos' + + +def test_cluster_client_compat_explicit_default(): + """Test cluster with explicitly set default client support mode.""" + import yaml + + yaml_str = """ +resource_type: ceph.smb.cluster +cluster_id: defaultcluster +auth_mode: user +user_group_settings: + - source_type: resource + ref: defaultusers +client_compat: default +""" + data = yaml.safe_load_all(yaml_str) + loaded = smb.resources.load(data) + assert loaded + cluster = loaded[0] + + # Should be explicitly set to DEFAULT + assert cluster.client_compat == enums.ClientSupportMode.DEFAULT + # effective_client_compat should return DEFAULT + assert cluster.effective_client_compat == enums.ClientSupportMode.DEFAULT + # is_macos_compatibility_enabled should be False + assert cluster.is_macos_compatibility_enabled is False + + def test_tls_credential(): import yaml diff --git a/src/pybind/mgr/smb/tests/test_smb.py b/src/pybind/mgr/smb/tests/test_smb.py index 54f9fb19fae..1d5245af6ea 100644 --- a/src/pybind/mgr/smb/tests/test_smb.py +++ b/src/pybind/mgr/smb/tests/test_smb.py @@ -1324,3 +1324,103 @@ def test_cluster_rm_wildcard_no_match(tmodule): with pytest.raises(smb.cli.NoMatchingValue): tmodule.cluster_rm('gonk', wildcard=True) + + +def test_cluster_update_client_compat(tmodule): + """Test updating cluster client compatibility mode with shares.""" + # Create a cluster with default client_compat + cluster = _cluster( + cluster_id='foo', + auth_mode=smb.enums.AuthMode.USER, + user_group_settings=[ + smb.resources.UserGroupSource( + source_type=smb.resources.UserGroupSourceType.EMPTY, + ), + ], + ) + rg = tmodule._handler.apply([cluster]) + assert rg.success, rg.to_simplified() + + # Create some shares + share1 = smb.resources.Share( + cluster_id='foo', + share_id='share1', + cephfs=smb.resources.CephFSStorage( + volume='cephfs', + path='/share1', + ), + ) + share2 = smb.resources.Share( + cluster_id='foo', + share_id='share2', + cephfs=smb.resources.CephFSStorage( + volume='cephfs', + path='/share2', + ), + ) + rg = tmodule._handler.apply([share1, share2]) + assert rg.success, rg.to_simplified() + + # Verify initial state (should be None/DEFAULT) + clusters = tmodule._handler.matching_resources(['ceph.smb.cluster.foo']) + assert len(clusters) == 1 + initial_cluster = clusters[0] + assert initial_cluster.client_compat is None + assert ( + initial_cluster.effective_client_compat + == smb.enums.ClientSupportMode.DEFAULT + ) + + # Update to MACOS compatibility mode + result = tmodule.cluster_update_client_compat( + smb.enums.ClientSupportMode.MACOS, 'foo' + ) + assert isinstance(result, dict) + assert result['cluster_id'] == 'foo' + assert result['client_compat'] == 'macos' + assert result['cluster_updated'] is True + assert result['total_shares'] == 2 + assert len(result['successful_share_updates']) == 2 + assert 'share1' in result['successful_share_updates'] + assert 'share2' in result['successful_share_updates'] + assert len(result['failed_share_updates']) == 0 + + # Verify the update + clusters = tmodule._handler.matching_resources(['ceph.smb.cluster.foo']) + assert len(clusters) == 1 + updated_cluster = clusters[0] + assert updated_cluster.client_compat == smb.enums.ClientSupportMode.MACOS + assert ( + updated_cluster.effective_client_compat + == smb.enums.ClientSupportMode.MACOS + ) + assert updated_cluster.is_macos_compatibility_enabled is True + + # Update back to DEFAULT + result = tmodule.cluster_update_client_compat( + smb.enums.ClientSupportMode.DEFAULT, 'foo' + ) + assert isinstance(result, dict) + assert result['cluster_id'] == 'foo' + assert result['client_compat'] == 'default' + assert result['cluster_updated'] is True + assert result['total_shares'] == 2 + + # Verify the update back to DEFAULT + clusters = tmodule._handler.matching_resources(['ceph.smb.cluster.foo']) + assert len(clusters) == 1 + final_cluster = clusters[0] + assert final_cluster.client_compat == smb.enums.ClientSupportMode.DEFAULT + assert ( + final_cluster.effective_client_compat + == smb.enums.ClientSupportMode.DEFAULT + ) + assert final_cluster.is_macos_compatibility_enabled is False + + +def test_cluster_update_client_compat_nonexistent(tmodule): + """Test updating client_compat for a non-existent cluster.""" + with pytest.raises(ValueError, match="Cluster nonexistent not found"): + tmodule.cluster_update_client_compat( + smb.enums.ClientSupportMode.MACOS, 'nonexistent' + )