| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Mock Api response for Unit tests of host module on Unity""" |
| 6 |
|
| 7 |
from __future__ import (absolute_import, division, print_function) |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
from ansible_collections.dellemc.unity.tests.unit.plugins.module_utils.mock_sdk_response \ |
| 12 |
import MockSDKObject |
| 13 |
|
| 14 |
|
| 15 |
class MockHostApi: |
| 16 |
HOST_MODULE_ARGS = { |
| 17 |
'unispherehost': '**.***.**.***', |
| 18 |
'port': '123', |
| 19 |
'host_id': None, |
| 20 |
'host_name': None, |
| 21 |
'host_os': None, |
| 22 |
'description': None, |
| 23 |
'initiators': None, |
| 24 |
'initiator_state': None, |
| 25 |
'new_host_name': None, |
| 26 |
'network_address': None, |
| 27 |
'network_address_state': None, |
| 28 |
'state': None |
| 29 |
} |
| 30 |
|
| 31 |
IP_ADDRESS_MOCK_VALUE = '***.***.*.*' |
| 32 |
IQN_INITIATOR_MOCK_VALUE = 'iqn.1111-11.com.vmware: host_name_1-111111f' |
| 33 |
|
| 34 |
@staticmethod |
| 35 |
def get_host_count_response(): |
| 36 |
return [{"auto_manage_type": "HostManageEnum.OTHERS", "description": "", "existed": True, |
| 37 |
"fc_host_initiators": {"UnityHostInitiatorList": [{"UnityHostInitiator": {}}]}, "health": |
| 38 |
{"UnityHealth": {}}, "host_ip_ports": {"UnityHostIpPortList": [{"UnityHostIpPort": {}}, |
| 39 |
{"UnityHostIpPort": {}}]}, "host_pushed_uuid": "1-1-1-1-1", |
| 40 |
"id": "Host_id_1", "iscsi_host_initiators": {"UnityHostInitiatorList": [{"UnityHostInitiator": {}}]}, |
| 41 |
"name": "host_name_1", "os_type": "XXXXXXXX", "type": "HostTypeEnum.HOST_AUTO"}] |
| 42 |
|
| 43 |
@staticmethod |
| 44 |
def get_host_initiators_list(): |
| 45 |
return ['1:1:1:1:1:1:1:1:1', MockHostApi.IQN_INITIATOR_MOCK_VALUE] |
| 46 |
|
| 47 |
@staticmethod |
| 48 |
def get_host_details_response(response_type): |
| 49 |
if response_type == 'api': |
| 50 |
return {'auto_manage_type': 'HostManageEnum.OTHERS', 'datastores': None, 'description': '', |
| 51 |
'fc_host_initiators': [MockSDKObject({'chap_user_name': None, |
| 52 |
'health': {'UnityHealth': {}}, 'id': 'HostInitiator_fc_1', |
| 53 |
'initiator_id': '1:1:1:1:1:1:1:1:1', |
| 54 |
'initiator_source_type': 'HostInitiatorSourceTypeEnum.OPEN_NATIVE', 'is_bound': None, |
| 55 |
'is_chap_secret_enabled': False, |
| 56 |
'is_ignored': False, 'iscsi_type': None, |
| 57 |
'node_wwn': '11:12:13:14:**:**:**:**', |
| 58 |
'parent_host': {'UnityHost': {'id': 'Host_id_1'}}, |
| 59 |
'paths': [MockSDKObject({'id': 'HostInitiator_mock_6', 'is_logged_in': True}), |
| 60 |
MockSDKObject({'id': 'HostInitiator_mock_5', 'is_logged_in': True}), |
| 61 |
MockSDKObject({'id': 'HostInitiator_mock_4', 'is_logged_in': True}), |
| 62 |
MockSDKObject({'id': 'HostInitiator_mock_3', 'is_logged_in': True})], |
| 63 |
'port_wwn': '10:10:10:10:10:10:10:10:10', 'source_type': None, |
| 64 |
'type': 'HostInitiatorTypeEnum.FC', 'existed': True})], |
| 65 |
'host_container': None, 'host_ip_ports': [MockSDKObject({'address': MockHostApi.IP_ADDRESS_MOCK_VALUE, |
| 66 |
'host': None, 'id': 'HostNetworkAddress_1', |
| 67 |
'is_ignored': None, 'name': None, 'netmask': None, 'type': None, |
| 68 |
'v6_prefix_length': None, 'existed': True}), |
| 69 |
MockSDKObject({'address': 'host_name_1', 'host': None, 'id': 'HostNetworkAddress_2', |
| 70 |
'is_ignored': None, 'name': None, 'netmask': None, 'type': None, |
| 71 |
'v6_prefix_length': None, 'existed': True})], |
| 72 |
'host_luns': MockSDKObject({'lun': |
| 73 |
[MockSDKObject({'hlu': 1, 'host': None, 'id': 'host_a', 'name': 'host_name_a', 'is_read_only': None, |
| 74 |
'lun': {'UnityLun': {}}, 'snap': None, 'type': None, 'existed': True}), |
| 75 |
MockSDKObject({'hlu': 0, 'host': None, 'id': 'host_b', 'name': 'host_name_b', 'is_read_only': None, |
| 76 |
'lun': {'UnityLun': {}}, 'snap': None, 'type': None, 'existed': True})]}), |
| 77 |
'host_polled_uuid': None, 'host_pushed_uuid': '1-1-1-1-1', |
| 78 |
'host_uuid': None, 'host_v_vol_datastore': None, 'id': 'Host_id_1', |
| 79 |
'iscsi_host_initiators': [MockSDKObject({'chap_user_name': None, 'health': {'UnityHealth': {}}, 'id': 'HostInitiator_iscsi_1', |
| 80 |
'initiator_id': MockHostApi.IQN_INITIATOR_MOCK_VALUE, |
| 81 |
'initiator_source_type': 'HostInitiatorSourceTypeEnum.OPEN_NATIVE', 'is_bound': True, |
| 82 |
'is_chap_secret_enabled': False, 'is_ignored': False, |
| 83 |
'iscsi_type': 'HostInitiatorIscsiTypeEnum.SOFTWARE', 'node_wwn': None, |
| 84 |
'parent_host': {'UnityHost': {'id': 'Host_id_1'}}, |
| 85 |
'paths': [MockSDKObject({'id': 'HostInitiator_mock_1', 'is_logged_in': True}), |
| 86 |
MockSDKObject({'id': 'HostInitiator_mock_2', 'is_logged_in': True})], |
| 87 |
'port_wwn': None, 'source_type': None, 'type': 'HostInitiatorTypeEnum.ISCSI', |
| 88 |
'existed': True})], |
| 89 |
'last_poll_time': None, 'name': 'host_name_1', |
| 90 |
'os_type': 'XXXXXXXX', 'registration_type': None, 'storage_resources': None, 'tenant': None, |
| 91 |
'type': 'HostTypeEnum.HOST_AUTO', |
| 92 |
'vms': None, 'existed': True, 'health': {'UnityHealth': {}}} |
| 93 |
elif response_type == 'module': |
| 94 |
return {'changed': False, |
| 95 |
'host_details': {'auto_manage_type': 'HostManageEnum.OTHERS', 'datastores': None, 'description': '', |
| 96 |
'fc_host_initiators': [{'id': 'HostInitiator_fc_1', |
| 97 |
'name': '1:1:1:1:1:1:1:1:1', |
| 98 |
'paths': [{'id': 'HostInitiator_mock_6', |
| 99 |
'is_logged_in': True}, |
| 100 |
{'id': 'HostInitiator_mock_5', |
| 101 |
'is_logged_in': True}, |
| 102 |
{'id': 'HostInitiator_mock_4', |
| 103 |
'is_logged_in': True}, |
| 104 |
{'id': 'HostInitiator_mock_3', |
| 105 |
'is_logged_in': True}]}], |
| 106 |
'health': {'UnityHealth': {}}, |
| 107 |
'host_container': None, |
| 108 |
'host_luns': [{'id': "host_a", 'name': 'host_name_a'}, {'id': 'host_b', 'name': 'host_name_b'}], |
| 109 |
'host_polled_uuid': None, 'host_pushed_uuid': '1-1-1-1-1', |
| 110 |
'host_uuid': None, 'host_v_vol_datastore': None, 'id': 'Host_id_1', |
| 111 |
'iscsi_host_initiators': [{'id': 'HostInitiator_iscsi_1', |
| 112 |
'name': MockHostApi.IQN_INITIATOR_MOCK_VALUE, |
| 113 |
'paths': [{'id': 'HostInitiator_mock_1', |
| 114 |
'is_logged_in': True}, |
| 115 |
{'id': 'HostInitiator_mock_2', |
| 116 |
'is_logged_in': True}]}], |
| 117 |
'last_poll_time': None, 'name': 'host_name_1', 'os_type': 'XXXXXXXX', |
| 118 |
'registration_type': None, 'storage_resources': None, 'tenant': None, |
| 119 |
'type': 'HostTypeEnum.HOST_AUTO', 'vms': None, 'existed': True, |
| 120 |
'network_addresses': [MockHostApi.IP_ADDRESS_MOCK_VALUE, 'host_name_1']}} |
| 121 |
elif response_type == 'error': |
| 122 |
return "Incorrect username or password provided." |
| 123 |
|
| 124 |
@staticmethod |
| 125 |
def get_host_details_after_network_address_addition(response_type): |
| 126 |
if response_type == 'api': |
| 127 |
host_object = MockHostApi.get_host_details_response('api') |
| 128 |
host_object['host_ip_ports'].append(MockSDKObject({'address': 'net_add_1', 'host': None, 'id': 'HostNetworkAddress_3', |
| 129 |
'is_ignored': None, 'name': None, 'netmask': None, 'type': None, |
| 130 |
'v6_prefix_length': None, 'existed': True})) |
| 131 |
return host_object |
| 132 |
elif response_type == 'module': |
| 133 |
host_module_response = MockHostApi.get_host_details_response('module') |
| 134 |
host_module_response['host_details']['network_addresses'].append('net_add_1') |
| 135 |
host_module_response['changed'] = True |
| 136 |
return host_module_response |
| 137 |
elif response_type == 'invalid_address': |
| 138 |
return 'Please enter valid IPV4 address or host name for network address' |
| 139 |
|
| 140 |
@staticmethod |
| 141 |
def get_host_details_after_network_address_removal(response_type): |
| 142 |
if response_type == 'api': |
| 143 |
host_object = MockHostApi.get_host_details_response('api') |
| 144 |
host_object['host_ip_ports'] = [MockSDKObject({'address': MockHostApi.IP_ADDRESS_MOCK_VALUE, 'host': None, 'id': 'HostNetworkAddress_1', |
| 145 |
'is_ignored': None, 'name': None, 'netmask': None, 'type': None, |
| 146 |
'v6_prefix_length': None, 'existed': True})] |
| 147 |
return host_object |
| 148 |
elif response_type == 'module': |
| 149 |
host_module_response = MockHostApi.get_host_details_response('module') |
| 150 |
host_module_response['host_details']['network_addresses'].remove('host_name_1') |
| 151 |
host_module_response['changed'] = True |
| 152 |
return host_module_response |
| 153 |
elif response_type == 'invalid_IPV4': |
| 154 |
return 'Please enter valid IPV4 address for network address' |