diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:22 +0000 |
commit | 38b7c80217c4e72b1d8988eb1e60bb6e77334114 (patch) | |
tree | 356e9fd3762877d07cde52d21e77070aeff7e789 /ansible_collections/dellemc/unity/tests | |
parent | Adding upstream version 7.7.0+dfsg. (diff) | |
download | ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.tar.xz ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.zip |
Adding upstream version 9.4.0+dfsg.upstream/9.4.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
15 files changed, 445 insertions, 46 deletions
diff --git a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.12.txt b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.12.txt deleted file mode 100644 index f78c82922..000000000 --- a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.12.txt +++ /dev/null @@ -1,33 +0,0 @@ -plugins/modules/nfs.py compile-2.6 -plugins/modules/nfs.py import-2.6 -plugins/modules/consistencygroup.py validate-modules:missing-gplv3-license -plugins/modules/filesystem.py validate-modules:missing-gplv3-license -plugins/modules/filesystem_snapshot.py validate-modules:missing-gplv3-license -plugins/modules/info.py validate-modules:missing-gplv3-license -plugins/modules/host.py validate-modules:missing-gplv3-license -plugins/modules/nasserver.py validate-modules:missing-gplv3-license -plugins/modules/nfs.py validate-modules:missing-gplv3-license -plugins/modules/smbshare.py validate-modules:missing-gplv3-license -plugins/modules/snapshot.py validate-modules:missing-gplv3-license -plugins/modules/snapshotschedule.py validate-modules:missing-gplv3-license -plugins/modules/storagepool.py validate-modules:missing-gplv3-license -plugins/modules/tree_quota.py validate-modules:missing-gplv3-license -plugins/modules/user_quota.py validate-modules:missing-gplv3-license -plugins/modules/volume.py validate-modules:missing-gplv3-license -plugins/modules/cifsserver.py validate-modules:missing-gplv3-license -plugins/modules/nfsserver.py validate-modules:missing-gplv3-license -plugins/modules/host.py import-2.6 -plugins/modules/host.py import-2.7 -plugins/modules/interface.py import-2.6 -plugins/modules/interface.py import-2.7 -plugins/modules/nfs.py import-2.7 -plugins/modules/nfs.py import-3.5 -plugins/modules/nfs.py compile-2.7 -plugins/modules/nfs.py compile-3.5 -plugins/modules/filesystem.py import-2.6 -plugins/modules/filesystem.py compile-2.6 -plugins/modules/filesystem.py compile-2.7 -plugins/modules/filesystem.py compile-3.5 -plugins/modules/filesystem.py import-2.7 -plugins/modules/filesystem.py import-3.5 -plugins/modules/interface.py validate-modules:missing-gplv3-license
\ No newline at end of file diff --git a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.13.txt b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.13.txt index a175e9976..a7aa13146 100644 --- a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.13.txt +++ b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.13.txt @@ -25,3 +25,8 @@ plugins/modules/filesystem.py compile-3.5 plugins/modules/filesystem.py import-2.7 plugins/modules/filesystem.py import-3.5 plugins/modules/interface.py validate-modules:missing-gplv3-license +plugins/modules/replication_session.py validate-modules:missing-gplv3-license +plugins/modules/replication_session.py import-2.7 +plugins/modules/replication_session.py import-3.5 +plugins/modules/replication_session.py compile-2.7 +plugins/modules/replication_session.py compile-3.5 diff --git a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.14.txt b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.14.txt index a175e9976..a7aa13146 100644 --- a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.14.txt +++ b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.14.txt @@ -25,3 +25,8 @@ plugins/modules/filesystem.py compile-3.5 plugins/modules/filesystem.py import-2.7 plugins/modules/filesystem.py import-3.5 plugins/modules/interface.py validate-modules:missing-gplv3-license +plugins/modules/replication_session.py validate-modules:missing-gplv3-license +plugins/modules/replication_session.py import-2.7 +plugins/modules/replication_session.py import-3.5 +plugins/modules/replication_session.py compile-2.7 +plugins/modules/replication_session.py compile-3.5 diff --git a/ansible_collections/dellemc/unity/tests/sanity/ignore-2.15.txt b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.15.txt new file mode 100644 index 000000000..a7aa13146 --- /dev/null +++ b/ansible_collections/dellemc/unity/tests/sanity/ignore-2.15.txt @@ -0,0 +1,32 @@ +plugins/modules/consistencygroup.py validate-modules:missing-gplv3-license +plugins/modules/filesystem.py validate-modules:missing-gplv3-license +plugins/modules/filesystem_snapshot.py validate-modules:missing-gplv3-license +plugins/modules/info.py validate-modules:missing-gplv3-license +plugins/modules/host.py validate-modules:missing-gplv3-license +plugins/modules/nasserver.py validate-modules:missing-gplv3-license +plugins/modules/nfs.py validate-modules:missing-gplv3-license +plugins/modules/smbshare.py validate-modules:missing-gplv3-license +plugins/modules/snapshot.py validate-modules:missing-gplv3-license +plugins/modules/snapshotschedule.py validate-modules:missing-gplv3-license +plugins/modules/storagepool.py validate-modules:missing-gplv3-license +plugins/modules/tree_quota.py validate-modules:missing-gplv3-license +plugins/modules/user_quota.py validate-modules:missing-gplv3-license +plugins/modules/volume.py validate-modules:missing-gplv3-license +plugins/modules/cifsserver.py validate-modules:missing-gplv3-license +plugins/modules/nfsserver.py validate-modules:missing-gplv3-license +plugins/modules/host.py import-2.7 +plugins/modules/interface.py import-2.7 +plugins/modules/nfs.py import-2.7 +plugins/modules/nfs.py import-3.5 +plugins/modules/nfs.py compile-2.7 +plugins/modules/nfs.py compile-3.5 +plugins/modules/filesystem.py compile-2.7 +plugins/modules/filesystem.py compile-3.5 +plugins/modules/filesystem.py import-2.7 +plugins/modules/filesystem.py import-3.5 +plugins/modules/interface.py validate-modules:missing-gplv3-license +plugins/modules/replication_session.py validate-modules:missing-gplv3-license +plugins/modules/replication_session.py import-2.7 +plugins/modules/replication_session.py import-3.5 +plugins/modules/replication_session.py compile-2.7 +plugins/modules/replication_session.py compile-3.5 diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_cifsserver_api.py b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_cifsserver_api.py index 427d530fa..d3f0e90a1 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_cifsserver_api.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_cifsserver_api.py @@ -5,13 +5,9 @@ """Mock Api response for Unit tests of CIFS server module on Unity""" from __future__ import (absolute_import, division, print_function) -from unittest.mock import MagicMock __metaclass__ = type -from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ - import MockSDKObject - class MockCIFSServerApi: CIFS_SERVER_MODULE_ARGS = { diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_info_api.py b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_info_api.py new file mode 100644 index 000000000..80ae035a1 --- /dev/null +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_info_api.py @@ -0,0 +1,58 @@ +# Copyright: (c) 2023, Dell Technologies + +# Apache License version 2.0 (see MODULE-LICENSE or http://www.apache.org/licenses/LICENSE-2.0.txt) + +"""Mock Api response for Unit tests of Info module on Unity""" + +from __future__ import (absolute_import, division, print_function) +from mock.mock import Mock +__metaclass__ = type + + +class MockInfoApi: + @staticmethod + def get_replication_sessions_response(status="ReplicationSessionStatusEnum.OK"): + return [Mock(**{ + "current_transfer_est_remain_time": 0, + "daily_snap_replication_policy": None, + "dst_resource_id": "nas_8", + "dst_spa_interface": { + "UnityRemoteInterface": { + "hash": 8771253398547, + "id": "APM00213404195:if_181" + } + }, + "dst_status": status, + "existed": True, + "hash": 8771259012271, + "health": { + "UnityHealth": { + "hash": 8771253424168 + } + }, + "hourly_snap_replication_policy": None, + "id": "103079215114_APM00213404195_0000_103079215274_APM00213404194_0000", + "last_sync_time": "2023-04-18 10:35:25+00:00", + "local_role": "ReplicationSessionReplicationRoleEnum.DESTINATION", + "max_time_out_of_sync": 0, + "members": None, + "name": "rep_session", + "network_status": "ReplicationSessionNetworkStatusEnum.OK", + "remote_system": { + "UnityRemoteSystem": { + "hash": 8771253380142 + } + }, + "replication_resource_type": "ReplicationEndpointResourceTypeEnum.NASSERVER", + "src_resource_id": "nas_213", + "src_spa_interface": { + "UnityRemoteInterface": { + "hash": 8771253475010, + "id": "APM00213404194:if_195" + } + }, + "src_status": status, + "status": status, + "sync_progress": 0, + "sync_state": "ReplicationSessionSyncStateEnum.IN_SYNC"} + )] diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_interface_api.py b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_interface_api.py index 6bd53ea9b..046ff2c41 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_interface_api.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_interface_api.py @@ -5,7 +5,6 @@ """Mock Api response for Unit tests of interface on Unity""" from __future__ import (absolute_import, division, print_function) -from unittest.mock import MagicMock __metaclass__ = type diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_nfsserver_api.py b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_nfsserver_api.py index 1254f0035..9c4eadc12 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_nfsserver_api.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_nfsserver_api.py @@ -5,7 +5,6 @@ """Mock Api response for Unit tests of NFS server module on Unity""" from __future__ import (absolute_import, division, print_function) -from unittest.mock import MagicMock __metaclass__ = type diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_replication_session_api.py b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_replication_session_api.py new file mode 100644 index 000000000..050084316 --- /dev/null +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_replication_session_api.py @@ -0,0 +1,112 @@ +# Copyright: (c) 2023, Dell Technologies + +# Apache License version 2.0 (see MODULE-LICENSE or http: //www.apache.org/licenses/LICENSE-2.0.txt) + +"""Mock Api response for Unit tests of Replication session module on Unity""" + +from __future__ import (absolute_import, division, print_function) +from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ + import MockSDKObject + +__metaclass__ = type + + +class MockReplicationSessionApi: + MODULE_ARGS = { + 'session_id': None, + 'session_name': None, + 'pause': None, + 'failback': None, + 'sync': None, + 'failover_with_sync': None, + 'force_full_copy': None, + 'force': None, + 'state': 'present' + } + + @staticmethod + def get_replication_session_details(status="ACTIVE"): + return { + "current_transfer_est_remain_time": 0, + "daily_snap_replication_policy": None, + "dst_resource_id": "nas_8", + "dst_spa_interface": { + "UnityRemoteInterface": { + "hash": 8771253398547, + "id": "APM00213404195:if_181" + } + }, + "dst_status": "ReplicationSessionStatusEnum.OK", + "existed": True, + "hash": 8771259012271, + "health": { + "UnityHealth": { + "hash": 8771253424168 + } + }, + "hourly_snap_replication_policy": None, + "id": "103079215114_APM00213404195_0000_103079215274_APM00213404194_0000", + "last_sync_time": "2023-04-18 10:35:25+00:00", + "local_role": "ReplicationSessionReplicationRoleEnum.DESTINATION", + "max_time_out_of_sync": 0, + "members": None, + "name": "rep_session", + "network_status": "ReplicationSessionNetworkStatusEnum.OK", + "remote_system": { + "UnityRemoteSystem": { + "hash": 8771253380142 + } + }, + "replication_resource_type": "ReplicationEndpointResourceTypeEnum.NASSERVER", + "src_resource_id": "nas_213", + "src_spa_interface": { + "UnityRemoteInterface": { + "hash": 8771253475010, + "id": "APM00213404194:if_195" + } + }, + "src_spb_interface": { + "UnityRemoteInterface": { + "hash": 8771253374169, + "id": "APM00213404194:if_194" + } + }, + "src_status": "ReplicationSessionStatusEnum.OK", + "status": Status(status), + "sync_progress": 0, + "sync_state": "ReplicationSessionSyncStateEnum.IN_SYNC" + } + + +class Status: + name = "ACTIVE" + + def __init__(self, status): + self.name = status + + +class MockReplicationSessionObject(MockSDKObject): + pause_session = False + resume_session = False + failover_session = False + failback_session = False + sync_session = False + delete_session = False + + def pause(self): + self.pause_session = True + + def resume(self, force_full_copy=None): + self.resume_session = True + + def failover(self, sync=None, force=None): + self.failover_session = True + + def failback(self, force_full_copy=None): + self.failback_session = True + + def sync(self): + self.sync_session = True + + def delete(self): + self.delete_session = True diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_volume_api.py b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_volume_api.py index 82097a338..ddf5c407e 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_volume_api.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/module_utils/mock_volume_api.py @@ -8,8 +8,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response import MockSDKObject - class MockVolumeApi: diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_cifsserver.py b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_cifsserver.py index e28c2e935..a1143a771 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_cifsserver.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_cifsserver.py @@ -14,8 +14,6 @@ from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_cifs import MockCIFSServerApi from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ import MockSDKObject -from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_api_exception \ - import HttpError as http_error, MockApiException from ansible_collections.dellemc.unity.plugins.module_utils.storage.dell import utils utils.get_logger = MagicMock() diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_host.py b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_host.py index de94c38d3..028a2fa4e 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_host.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_host.py @@ -15,7 +15,7 @@ from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_host from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ import MockSDKObject from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_api_exception \ - import HttpError as http_error, MockApiException + import HttpError as http_error from ansible_collections.dellemc.unity.plugins.module_utils.storage.dell \ import utils diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_info.py b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_info.py new file mode 100644 index 000000000..a36567660 --- /dev/null +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_info.py @@ -0,0 +1,54 @@ +# Copyright: (c) 2023, Dell Technologies + +# Apache License version 2.0 (see MODULE-LICENSE or http://www.apache.org/licenses/LICENSE-2.0.txt) + +"""Mock Api response for Unit tests of Info module on Unity""" + +from __future__ import (absolute_import, division, print_function) + +__metaclass__ = type + +import pytest +from mock.mock import MagicMock +from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_info_api \ + import MockInfoApi +from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_api_exception \ + import HttpError as http_error +from ansible_collections.dellemc.unity.plugins.module_utils.storage.dell import utils + +utils.get_logger = MagicMock() +utils.get_unity_management_host_parameters = MagicMock() +utils.ensure_required_libs = MagicMock() +utils.get_unity_unisphere_connection = MagicMock() +from ansible.module_utils import basic +basic.AnsibleModule = MagicMock() +from ansible_collections.dellemc.unity.plugins.modules.info import Info + + +class TestInfo(): + + get_module_args = {"gather_subset": None, "state": "present"} + + @pytest.fixture + def info_module_mock(self): + info_module_mock = Info() + info_module_mock.unity = MagicMock() + return info_module_mock + + def test_get_replication_session_details(self, info_module_mock): + self.get_module_args.update({'gather_subset': 'replication_session'}) + info_module_mock.module.params = self.get_module_args + info_module_mock.unity.get_replication_session = \ + MagicMock(return_value=MockInfoApi.get_replication_sessions_response()) + info_module_mock.perform_module_operation() + assert info_module_mock.module.exit_json.call_args[1]['Replication_sessions'] is not None + + def test_get_replication_session_details_throws_exception(self, info_module_mock): + self.get_module_args.update({'gather_subset': 'replication_session'}) + info_module_mock.module.params = self.get_module_args + utils.HttpError = http_error + info_module_mock.unity.get_replication_session = \ + MagicMock(side_effect=http_error) + info_module_mock.perform_module_operation() + assert "Get replication session list from unity array failed with error" in \ + info_module_mock.module.fail_json.call_args[1]['msg'] diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_nfsserver.py b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_nfsserver.py index c2a680487..f7900eeb1 100644 --- a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_nfsserver.py +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_nfsserver.py @@ -12,8 +12,6 @@ import pytest from mock.mock import MagicMock from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_nfsserver_api \ import MockNFSServerApi -from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ - import MockSDKObject from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_api_exception \ import HttpError as http_error, MockApiException from ansible_collections.dellemc.unity.plugins.module_utils.storage.dell import utils diff --git a/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_replication_session.py b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_replication_session.py new file mode 100644 index 000000000..9af1800e6 --- /dev/null +++ b/ansible_collections/dellemc/unity/tests/unit/plugins/modules/test_replication_session.py @@ -0,0 +1,178 @@ +# Copyright: (c) 2023, Dell Technologies + +# Apache License version 2.0 (see MODULE-LICENSE or http://www.apache.org/licenses/LICENSE-2.0.txt) + +"""Mock Api response for Unit tests of Replication session module on Unity""" + +from __future__ import (absolute_import, division, print_function) + +__metaclass__ = type + +import pytest +from mock.mock import MagicMock +from enum import Enum +from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_replication_session_api \ + import MockReplicationSessionApi, MockReplicationSessionObject +from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_api_exception \ + import HttpError as http_error +from ansible_collections.dellemc.unity.plugins.module_utils.storage.dell import utils + +utils.get_logger = MagicMock() +utils.get_unity_management_host_parameters = MagicMock() +utils.ensure_required_libs = MagicMock() +utils.get_unity_unisphere_connection = MagicMock() +from ansible.module_utils import basic +basic.AnsibleModule = MagicMock() +from ansible_collections.dellemc.unity.plugins.modules.replication_session import ReplicationSession, ReplicationSessionHandler + + +class ReplicationOpStatusEnum(Enum): + FAILED_OVER_WITH_SYNC = (0x8400, 'Failed_Over_with_Sync') + FAILED_OVER = (0x8401, 'Failed_Over') + PAUSED = (0x8403, 'Paused') + + +class TestReplicationSession(): + + get_module_args = MockReplicationSessionApi.MODULE_ARGS + session_name = "rep_session" + FAILED_WITH_ERROR = " failed with error" + replication_session_obj = MockReplicationSessionObject(MockReplicationSessionApi.get_replication_session_details()) + + @pytest.fixture + def replication_session_module_mock(self): + setattr(utils, 'ReplicationOpStatusEnum', ReplicationOpStatusEnum) + replication_session_module_mock = ReplicationSession() + replication_session_module_mock.unity_conn = MagicMock() + replication_session_module_mock.module.check_mode = False + return replication_session_module_mock + + def test_get_replication_session_details(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1'}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert replication_session_module_mock.module.exit_json.call_args[1]['changed'] is False + + def test_get_replication_session_details_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1'}) + replication_session_module_mock.module.params = self.get_module_args + utils.HttpError = http_error + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(side_effect=http_error) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "is invalid" in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] + + def test_pause_replication_session(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'pause': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert self.replication_session_obj.pause_session is True + + def test_pause_replication_session_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'pause': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + self.replication_session_obj.pause = MagicMock(side_effect=Exception) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "Pause replication session " + self.session_name + self.FAILED_WITH_ERROR in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] + + def test_resume_replication_session(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'pause': False}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_obj = MockReplicationSessionObject(MockReplicationSessionApi.get_replication_session_details("PAUSED")) + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert replication_session_obj.resume_session is True + + def test_resume_replication_session_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'pause': False}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_obj = MockReplicationSessionObject(MockReplicationSessionApi.get_replication_session_details("PAUSED")) + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=replication_session_obj) + replication_session_obj.resume = MagicMock(side_effect=Exception) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "Resume replication session " + self.session_name + self.FAILED_WITH_ERROR in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] + + def test_failover_replication_session(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'failover_with_sync': True, 'force': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert self.replication_session_obj.failover_session is True + + def test_failover_replication_session_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'failover_with_sync': True, 'force': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + self.replication_session_obj.failover = MagicMock(side_effect=Exception) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "Failover replication session " + self.session_name + self.FAILED_WITH_ERROR in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] + + def test_failback_replication_session_details(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'failback': True, 'force_full_copy': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_obj = MockReplicationSessionObject(MockReplicationSessionApi.get_replication_session_details("FAILED_OVER")) + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert replication_session_obj.failback_session is True + + def test_failback_replication_session_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'failback': True, 'force_full_copy': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_obj = MockReplicationSessionObject(MockReplicationSessionApi.get_replication_session_details("FAILED_OVER")) + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=replication_session_obj) + replication_session_obj.failback = MagicMock(side_effect=Exception) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "Failback replication session " + self.session_name + self.FAILED_WITH_ERROR in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] + + def test_sync_replication_session(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'sync': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert self.replication_session_obj.sync_session is True + + def test_sync_replication_session_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'sync': True}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + self.replication_session_obj.sync = MagicMock(side_effect=Exception) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "Sync replication session " + self.session_name + self.FAILED_WITH_ERROR in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] + + def test_delete_replication_session(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'state': 'absent'}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert self.replication_session_obj.delete_session is True + + def test_delete_replication_session_throws_exception(self, replication_session_module_mock): + self.get_module_args.update({'session_name': 'session1', 'state': 'absent'}) + replication_session_module_mock.module.params = self.get_module_args + replication_session_module_mock.unity_conn.get_replication_session = \ + MagicMock(return_value=self.replication_session_obj) + self.replication_session_obj.delete = MagicMock(side_effect=Exception) + ReplicationSessionHandler().handle(replication_session_module_mock, replication_session_module_mock.module.params) + assert "Deleting replication session " + self.session_name + self.FAILED_WITH_ERROR in \ + replication_session_module_mock.module.fail_json.call_args[1]['msg'] |