[NetApp] Fix latent issues in unit tests

Update one test to avoid overriding global variables, which cause
other tests to fail depending on their execution concurrency.

Fix another test to ensure a variable is declared before referenced,
and enhance the DDT data to include additional test cases.

Change-Id: Ifead61164dc0bb880ca03dad1124a32be960fa6f
This commit is contained in:
Alan Bishop 2025-03-06 11:18:05 -08:00
parent e0cd2a76e0
commit f2b4970cef
2 changed files with 45 additions and 11 deletions

View File

@ -3570,12 +3570,12 @@ class NetAppCmodeClientTestCase(test.TestCase):
@ddt.unpack
def test_create_snapmirror(self, schedule, policy):
self.mock_object(self.client.connection, 'send_request')
fake_client.SM_SOURCE_CG = None
fake_client.SM_DESTINATION_CG = None
sm_source_cg = None
sm_destination_cg = None
self.client.create_snapmirror(
fake_client.SM_SOURCE_VSERVER, fake_client.SM_SOURCE_VOLUME,
fake_client.SM_DEST_VSERVER, fake_client.SM_DEST_VOLUME,
fake_client.SM_SOURCE_CG, fake_client.SM_DESTINATION_CG,
sm_source_cg, sm_destination_cg,
schedule=schedule, policy=policy)
snapmirror_create_args = {

View File

@ -2834,9 +2834,31 @@ class NetAppRestCmodeClientTestCase(test.TestCase):
self.client.send_request.assert_has_calls([
mock.call('/snapmirror/relationships/', 'post', body=body)])
@ddt.data({'policy': 'AutomatedFailOver'})
@ddt.data(
{
'policy': None,
'sm_source_cg': fake_client.SM_SOURCE_CG,
'sm_destination_cg': fake_client.SM_DESTINATION_CG,
},
{
'policy': None,
'sm_source_cg': None,
'sm_destination_cg': None,
},
{
'policy': 'AutomatedFailOver',
'sm_source_cg': fake_client.SM_SOURCE_CG,
'sm_destination_cg': fake_client.SM_DESTINATION_CG,
},
{
'policy': 'AutomatedFailOver',
'sm_source_cg': None,
'sm_destination_cg': None,
},
)
@ddt.unpack
def test_create_snapmirror_active_sync(self, policy):
def test_create_snapmirror_active_sync(self, policy,
sm_source_cg, sm_destination_cg):
"""Tests creation of snapmirror with active sync"""
api_responses = [
{
@ -2845,34 +2867,46 @@ class NetAppRestCmodeClientTestCase(test.TestCase):
},
},
]
body = {}
self.mock_object(self.client, 'send_request',
side_effect = copy.deepcopy(api_responses))
self.client.create_snapmirror(
fake_client.SM_SOURCE_VSERVER, fake_client.SM_SOURCE_VOLUME,
fake_client.SM_DEST_VSERVER, fake_client.SM_DEST_VOLUME,
fake_client.SM_SOURCE_CG, fake_client.SM_DESTINATION_CG,
sm_source_cg, sm_destination_cg,
policy=policy)
if fake_client.SM_SOURCE_VSERVER is not None and \
fake_client.SM_SOURCE_CG is not None:
if sm_source_cg is not None and sm_destination_cg is not None:
body = {
'source': {
'path':
fake_client.SM_SOURCE_VSERVER + ':/cg/' +
fake_client.SM_SOURCE_CG,
sm_source_cg,
'consistency_group_volumes': [
{'name': fake_client.SM_SOURCE_VOLUME}]
},
'destination': {
'path': fake_client.SM_DEST_VSERVER + ':/cg/' +
fake_client.SM_DESTINATION_CG,
sm_destination_cg,
'consistency_group_volumes': [
{'name': fake_client.SM_DEST_VOLUME}]
}
}
else:
body = {
'source': {
'path': fake_client.SM_SOURCE_VSERVER + ':' +
fake_client.SM_SOURCE_VOLUME
},
'destination': {
'path': fake_client.SM_DEST_VSERVER + ':' +
fake_client.SM_DEST_VOLUME
},
}
if policy:
body['policy'] = {'name': policy}
if body is not None:
if bool(body):
self.client.send_request.assert_has_calls([
mock.call('/snapmirror/relationships/', 'post', body=body)])