| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Mock Api response for Unit tests of consistency group module on Unity""" |
| 6 |
|
| 7 |
from __future__ import (absolute_import, division, print_function) |
| 8 |
from unittest.mock import MagicMock |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ |
| 13 |
import MockSDKObject |
| 14 |
|
| 15 |
|
| 16 |
class MockConsistenyGroupApi: |
| 17 |
CONSISTENCY_GROUP_MODULE_ARGS = { |
| 18 |
'unispherehost': '**.***.**.***', |
| 19 |
'port': '123', |
| 20 |
'cg_id': None, |
| 21 |
'cg_name': None, |
| 22 |
'new_cg_name': None, |
| 23 |
'pool_id': None, |
| 24 |
'description': None, |
| 25 |
'snap_schedule': None, |
| 26 |
'tiering_policy': None, |
| 27 |
'volumes': [], |
| 28 |
'vol_state': None, |
| 29 |
'hosts': [], |
| 30 |
'mapping_state': None, |
| 31 |
'replication_params': {}, |
| 32 |
'replication_state': None, |
| 33 |
'state': None |
| 34 |
} |
| 35 |
IP_ADDRESS_MOCK_VALUE = '***.***.***.**' |
| 36 |
|
| 37 |
@staticmethod |
| 38 |
def cg_get_details_method_response(): |
| 39 |
return {'advanced_dedup_status': 'DedupStatusEnum.DISABLED', 'block_host_access': None, 'data_reduction_percent': 0, |
| 40 |
'data_reduction_ratio': 1.0, 'data_reduction_size_saved': 0, 'data_reduction_status': 'DataReductionStatusEnum.DISABLED', |
| 41 |
'datastores': None, 'dedup_status': None, 'description': '', 'esx_filesystem_block_size': None, |
| 42 |
'esx_filesystem_major_version': None, 'filesystem': None, 'health': {}, 'host_v_vol_datastore': None, |
| 43 |
'id': 'cg_id_1', 'is_replication_destination': False, 'is_snap_schedule_paused': None, |
| 44 |
'luns': [{'id': 'lun_id_1', 'name': 'test_lun_cg_issue', 'is_thin_enabled': False, |
| 45 |
'size_total': 1, 'is_data_reduction_enabled': False}], |
| 46 |
'name': 'lun_test_cg_source_12', 'per_tier_size_used': [1, 0, 0], |
| 47 |
'pools': [{'id': 'pool_id_1'}], |
| 48 |
'relocation_policy': 'TieringPolicyEnum.AUTOTIER_HIGH', 'replication_type': 'ReplicationTypeEnum.NONE', |
| 49 |
'size_allocated': 0, 'size_total': 1, 'size_used': None, 'snap_count': 0, 'snap_schedule': None, |
| 50 |
'snaps_size_allocated': 0, 'snaps_size_total': 0, 'thin_status': 'ThinStatusEnum.TRUE', |
| 51 |
'type': 'StorageResourceTypeEnum.CONSISTENCY_GROUP', 'virtual_volumes': None, 'vmware_uuid': None, |
| 52 |
'existed': True, 'snapshots': [], 'cg_replication_enabled': False} |
| 53 |
|
| 54 |
@staticmethod |
| 55 |
def get_cg_object(): |
| 56 |
return MockSDKObject({'advanced_dedup_status': 'DedupStatusEnum.DISABLED', 'block_host_access': None, |
| 57 |
'data_reduction_percent': 0, 'data_reduction_ratio': 1.0, 'data_reduction_size_saved': 0, |
| 58 |
'data_reduction_status': 'DataReductionStatusEnum.DISABLED', |
| 59 |
'datastores': None, 'dedup_status': None, 'description': '', 'esx_filesystem_block_size': None, |
| 60 |
'esx_filesystem_major_version': None, 'filesystem': None, 'health': {}, 'host_v_vol_datastore': None, |
| 61 |
'id': 'cg_id_1', 'is_replication_destination': False, 'is_snap_schedule_paused': None, |
| 62 |
'luns': [MockSDKObject({'id': 'lun_id_1', 'name': 'test_lun_cg_issue', |
| 63 |
'is_thin_enabled': False, 'size_total': 1, 'is_data_reduction_enabled': False})], |
| 64 |
'name': 'lun_test_cg_source_12', 'per_tier_size_used': [1, 0, 0], |
| 65 |
'pools': [MockSDKObject({'id': 'pool_id_1'})], |
| 66 |
'relocation_policy': 'TieringPolicyEnum.AUTOTIER_HIGH', 'replication_type': 'ReplicationTypeEnum.NONE', |
| 67 |
'size_allocated': 0, 'size_total': 1, 'size_used': None, 'snap_count': 0, 'snap_schedule': None, |
| 68 |
'snaps_size_allocated': 0, 'snaps_size_total': 0, 'thin_status': 'ThinStatusEnum.TRUE', |
| 69 |
'type': 'StorageResourceTypeEnum.CONSISTENCY_GROUP', 'virtual_volumes': None, 'vmware_uuid': None, |
| 70 |
'existed': True, 'snapshots': [], 'cg_replication_enabled': False}) |
| 71 |
|
| 72 |
@staticmethod |
| 73 |
def get_cg_replication_dependent_response(response_type): |
| 74 |
if response_type == 'cg_replication_enabled_details': |
| 75 |
cg_replication_enabled_details = MockConsistenyGroupApi.cg_get_details_method_response() |
| 76 |
cg_replication_enabled_details['cg_replication_enabled'] = True |
| 77 |
return cg_replication_enabled_details |
| 78 |
elif response_type == 'remote_system': |
| 79 |
return [MockSDKObject({"connection_type": "ReplicationCapabilityEnum.ASYNC", "existed": True, |
| 80 |
"health": {"UnityHealth": {}}, "id": "system_id_1", "local_spa_interfaces": [MockConsistenyGroupApi.IP_ADDRESS_MOCK_VALUE], |
| 81 |
"local_spb_interfaces": [MockConsistenyGroupApi.IP_ADDRESS_MOCK_VALUE], |
| 82 |
"management_address": "**.***.**.**", "model": "U XXX", |
| 83 |
"name": "ABXXXXXX", "remote_spa_interfaces": [MockConsistenyGroupApi.IP_ADDRESS_MOCK_VALUE], |
| 84 |
"remote_spb_interfaces": [MockConsistenyGroupApi.IP_ADDRESS_MOCK_VALUE], |
| 85 |
"serial_number": "ABXXXXXX", "sync_fc_ports": ["abc_def", "ghi_jkl"], "username": "username"})] |
| 86 |
elif response_type == 'remote_system_pool_object': |
| 87 |
return MockSDKObject({"alert_threshold": 60, "creation_time": "2021-10-18 12:51:27+00:00", "description": "", |
| 88 |
"existed": True, "harvest_state": "UsageHarvestStateEnum.IDLE", "health": {"UnityHealth": {}}, |
| 89 |
"id": "pool_3", "is_all_flash": True, "is_empty": False, "is_fast_cache_enabled": False, |
| 90 |
"is_harvest_enabled": True, "is_snap_harvest_enabled": True, "name": "Extreme_Perf_tier", |
| 91 |
"object_id": 1, "pool_fast_vp": {"UnityPoolFastVp": {}}, "pool_space_harvest_high_threshold": 95.0, |
| 92 |
"pool_space_harvest_low_threshold": 70.5, "pool_type": "StoragePoolTypeEnum.DYNAMIC", |
| 93 |
"raid_type": "RaidTypeEnum.RAID5", "size_free": 1, "size_subscribed": 1, "size_total": 1, |
| 94 |
"size_used": 1, "snap_size_subscribed": 1, "snap_size_used": 1, "snap_space_harvest_high_threshold": 20.5, |
| 95 |
"snap_space_harvest_low_threshold": 1.0, |
| 96 |
"tiers": {"UnityPoolTierList": [{"UnityPoolTier": {}}, {"UnityPoolTier": {}}, {"UnityPoolTier": {}}]}}) |
| 97 |
elif response_type == 'replication_session': |
| 98 |
return MockSDKObject({"current_transfer_est_remain_time": 0, "daily_snap_replication_policy": {}, |
| 99 |
"dst_resource_id": "dest_id_1", "dst_status": "ReplicationSessionStatusEnum.OK", "existed": True, |
| 100 |
"health": {}, "hourly_snap_replication_policy": {}, |
| 101 |
"id": "111111_XXX1111111_0000_1111111_XXX111111111_0000", |
| 102 |
"last_sync_time": "2022-02-17 09: 50: 54+00: 00", |
| 103 |
"local_role": "ReplicationSessionReplicationRoleEnum.LOOPBACK", |
| 104 |
"max_time_out_of_sync": 60, "members": {}, "name": "rep_session_1", |
| 105 |
"network_status": "ReplicationSessionNetworkStatusEnum.OK", "remote_system": {}, |
| 106 |
"replication_resource_type": "ReplicationEndpointResourceTypeEnum.CONSISTENCYGROUP", |
| 107 |
"src_resource_id": "src_id_1", |
| 108 |
"src_status": "ReplicationSessionStatusEnum.OK", |
| 109 |
"status": "ReplicationOpStatusEnum.AUTO_SYNC_CONFIGURED", |
| 110 |
"sync_progress": 0, "sync_state": "ReplicationSessionSyncStateEnum.IDLE"}) |
| 111 |
elif response_type == 'destination_cg_name_validation': |
| 112 |
return 'destination_cg_name value should be in range of 1 to 95' |
| 113 |
elif response_type == 'enable_cg_exception': |
| 114 |
return 'Enabling replication to the consistency group lun_test_cg_source_12 failed with error ' |
| 115 |
elif response_type == 'disable_cg_exception': |
| 116 |
return 'Disabling replication to the consistency group lun_test_cg_source_12 failed with error ' |
| 117 |
|
| 118 |
@staticmethod |
| 119 |
def get_remote_system_conn_response(): |
| 120 |
conn = MockConsistenyGroupApi.get_cg_replication_dependent_response("remote_system")[0] |
| 121 |
conn.get_pool = MagicMock(return_value=MockConsistenyGroupApi.get_cg_replication_dependent_response('remote_system_pool_object')) |
| 122 |
return conn |