From 01b9d7ce4e54d05f5cb7e044db284d46328ce6b0 Mon Sep 17 00:00:00 2001 From: Maurice Escher Date: Fri, 18 Mar 2022 18:18:22 +0100 Subject: [PATCH] ccloud fix of https://bugs.launchpad.net/manila/+bug/1964592 use cluster client to check vserver exists before using vserver client Change-Id: I80f1e802ddd9c90225b39f1a5e2e9df866cb4936 --- .../netapp/dataontap/cluster_mode/lib_multi_svm.py | 8 ++++---- .../dataontap/cluster_mode/test_lib_multi_svm.py | 14 ++------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_multi_svm.py b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_multi_svm.py index 711826b9f7..5a7d488bd8 100644 --- a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_multi_svm.py +++ b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_multi_svm.py @@ -108,6 +108,10 @@ def _get_vserver(self, share_server=None, vserver_name=None, msg = _('Share server or vserver name not provided') raise exception.InvalidInput(reason=msg) + if not reexport: + if not self._client.vserver_exists(vserver): + raise exception.VserverNotFound(vserver=vserver) + if backend_name: vserver_client = data_motion.get_client_for_backend( backend_name, vserver @@ -115,10 +119,6 @@ def _get_vserver(self, share_server=None, vserver_name=None, else: vserver_client = self._get_api_client(vserver) - if not reexport: - if not vserver_client.vserver_exists(vserver): - raise exception.VserverNotFound(vserver=vserver) - return vserver, vserver_client def _get_ems_pool_info(self): diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py index 447909b9a7..31ef4d45d6 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py @@ -221,11 +221,8 @@ def test_get_vserver_no_share_server(self): self.library._get_vserver) def test_get_vserver_no_share_server_with_vserver_name(self): + self.library._client.vserver_exists.return_value = True fake_vserver_client = mock.Mock() - - mock_vserver_exists = self.mock_object( - fake_vserver_client, 'vserver_exists', - mock.Mock(return_value=True)) self.mock_object(self.library, '_get_api_client', mock.Mock(return_value=fake_vserver_client)) @@ -233,9 +230,6 @@ def test_get_vserver_no_share_server_with_vserver_name(self): result_vserver, result_vserver_client = self.library._get_vserver( share_server=None, vserver_name=fake.VSERVER1) - mock_vserver_exists.assert_called_once_with( - fake.VSERVER1 - ) self.assertEqual(fake.VSERVER1, result_vserver) self.assertEqual(fake_vserver_client, result_vserver_client) @@ -281,11 +275,7 @@ def test_get_vserver_none_vserver(self): def test_get_vserver_not_found(self): - mock_client = mock.Mock() - mock_client.vserver_exists.return_value = False - self.mock_object(self.library, - '_get_api_client', - mock.Mock(return_value=mock_client)) + self.library._client.vserver_exists.return_value = False kwargs = {'share_server': fake.SHARE_SERVER} self.assertRaises(exception.VserverNotFound,