From 31c97211cbfab7d6fcc96ba92fbbc9aa988c167b Mon Sep 17 00:00:00 2001 From: Rodrigo Barbieri Date: Wed, 9 Oct 2024 16:09:56 -0300 Subject: [PATCH] Improve unit tests in NetApp Driver Change I8544efbdac207c54d75c55ee4a039c5324433794 was missing unit tests. Related-bug: #2069125 Change-Id: I9ab37f9d225a84fcceb9b618fad7d110974d2ed4 --- .../dataontap/client/test_client_cmode.py | 86 ++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py index e1e45e7937..82f741e756 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py @@ -2988,7 +2988,91 @@ class NetAppClientCmodeTestCase(test.TestCase): self.assertTrue(result) self.client.send_request.assert_called_once_with( 'kerberos-config-get', kerberos_config_get_args) - self.client.get_network_interfaces.assert_called_once() + self.client.get_network_interfaces.assert_called_once_with( + protocols=['NFS', 'CIFS']) + + def test_is_kerberos_enabled_exception_raise(self): + self.client.features.add_feature('KERBEROS_VSERVER') + api_response = netapp_api.NaElement( + fake.KERBEROS_CONFIG_GET_RESPONSE) + self.mock_object(self.client, 'send_request', + mock.Mock(side_effect=[api_response, + netapp_api.NaApiError('foobar')])) + self.mock_object(self.client, + 'get_network_interfaces', + mock.Mock(return_value=[{'interface-name': 'lif1'}, + {'interface-name': 'lif2'}, + {'interface-name': 'lif3'}])) + + self.assertRaises(netapp_api.NaApiError, + self.client.is_kerberos_enabled) + + kerberos_config_get_args_lif1 = { + 'interface-name': 'lif1', + 'desired-attributes': { + 'kerberos-config-info': { + 'is-kerberos-enabled': None, + } + } + } + + kerberos_config_get_args_lif2 = { + 'interface-name': 'lif2', + 'desired-attributes': { + 'kerberos-config-info': { + 'is-kerberos-enabled': None, + } + } + } + + self.client.send_request.assert_has_calls([ + mock.call('kerberos-config-get', kerberos_config_get_args_lif1), + mock.call('kerberos-config-get', kerberos_config_get_args_lif2), + ]) + self.client.get_network_interfaces.assert_called_once_with( + protocols=['NFS', 'CIFS']) + + def test_is_kerberos_enabled_exception_return_false(self): + self.client.features.add_feature('KERBEROS_VSERVER') + api_response = netapp_api.NaElement( + fake.KERBEROS_CONFIG_GET_RESPONSE) + self.mock_object( + self.client, 'send_request', + mock.Mock(side_effect=[api_response, netapp_api.NaApiError( + message="entry doesn't exist")])) + self.mock_object(self.client, + 'get_network_interfaces', + mock.Mock(return_value=[{'interface-name': 'lif1'}, + {'interface-name': 'lif2'}, + {'interface-name': 'lif3'}])) + + result = self.client.is_kerberos_enabled() + + kerberos_config_get_args_lif1 = { + 'interface-name': 'lif1', + 'desired-attributes': { + 'kerberos-config-info': { + 'is-kerberos-enabled': None, + } + } + } + + kerberos_config_get_args_lif2 = { + 'interface-name': 'lif2', + 'desired-attributes': { + 'kerberos-config-info': { + 'is-kerberos-enabled': None, + } + } + } + + self.assertFalse(result) + self.client.send_request.assert_has_calls([ + mock.call('kerberos-config-get', kerberos_config_get_args_lif1), + mock.call('kerberos-config-get', kerberos_config_get_args_lif2), + ]) + self.client.get_network_interfaces.assert_called_once_with( + protocols=['NFS', 'CIFS']) def test_get_kerberos_service_principal_name(self):