| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Mock Api response for Unit tests of interface 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 |
from copy import deepcopy |
| 14 |
|
| 15 |
|
| 16 |
class MockInterfaceApi: |
| 17 |
INTERFACE_MODULE_ARGS = { |
| 18 |
'unispherehost': '**.***.**.***', |
| 19 |
'port': '123', |
| 20 |
'nas_server_id': None, |
| 21 |
'nas_server_name': None, |
| 22 |
'ethernet_port_name': None, |
| 23 |
'ethernet_port_id': None, |
| 24 |
'role': None, |
| 25 |
'interface_ip': None, |
| 26 |
'netmask': None, |
| 27 |
'prefix_length': None, |
| 28 |
'gateway': None, |
| 29 |
'vlan_id': None, |
| 30 |
'state': None |
| 31 |
} |
| 32 |
ETHERNET_PORT_NAME = "Card Ethernet Port" |
| 33 |
NETMASK_DUMMY = "255.xx.xx.xx" |
| 34 |
GATEWAY_DUMMY = "10.***.**.1" |
| 35 |
INTERFACE_DUMMY = "10.***.**.**" |
| 36 |
|
| 37 |
NAS_SERVER_OBJECT = \ |
| 38 |
MockSDKObject({'allow_unmapped_user': None, 'cifs_server': {'UnityCifsServerList': [{'UnityCifsServer': {'id': 'cifs_id_0'}}]}, |
| 39 |
'current_sp': {'UnityStorageProcessor': {'id': 'abc'}}, |
| 40 |
'current_unix_directory_service': 'NasServerUnixDirectoryServiceEnum.NIS', 'default_unix_user': None, |
| 41 |
'default_windows_user': None, 'file_dns_server': {'UnityFileDnsServer': {'id': 'dns_id_0'}}, |
| 42 |
'file_interface': {'UnityFileInterfaceList': [{'UnityFileInterface': {'id': 'file_interface_id_0'}}]}, |
| 43 |
'filesystems': {'UnityFileSystemList': [{'UnityFileSystem': {'id': 'fs_id_0'}}]}, |
| 44 |
'home_sp': {'UnityStorageProcessor': {'id': 'abd'}}, |
| 45 |
'id': 'nas_id_00', 'is_backup_only': False, 'is_multi_protocol_enabled': False, |
| 46 |
'is_packet_reflect_enabled': False, 'is_replication_destination': False, |
| 47 |
'is_replication_enabled': True, 'is_windows_to_unix_username_mapping_enabled': None, |
| 48 |
'name': 'dummy_nas', 'pool': {'UnityPool': {'id': 'pool_id_0'}}, |
| 49 |
'preferred_interface_settings': {'UnityPreferredInterfaceSettings': {'id': 'preferred_interface_0'}}, |
| 50 |
'replication_type': 'ReplicationTypeEnum.MIXED', |
| 51 |
'tenant': None, 'virus_checker': {'UnityVirusChecker': {'id': 'cava_id_0'}}, |
| 52 |
'existed': True}) |
| 53 |
|
| 54 |
INTERFACE_OBJECT = \ |
| 55 |
MockSDKObject({"existed": True, |
| 56 |
"gateway": GATEWAY_DUMMY, |
| 57 |
"id": "file_interface_id_0", |
| 58 |
"ip_address": INTERFACE_DUMMY, |
| 59 |
"ip_port": {"UnityIpPort": {"id": "ethernet_port_id_0"}}, |
| 60 |
"ip_protocol_version": "IpProtocolVersionEnum.IPv4", |
| 61 |
"is_disabled": False, "is_preferred": True, |
| 62 |
"mac_address": "AA:AA:AA:**:**:**", |
| 63 |
"name": "dummy_if_name", |
| 64 |
"nas_server": {"UnityNasServer": {"id": "nas_id_00"}}, |
| 65 |
"netmask": NETMASK_DUMMY, |
| 66 |
"role": "FileInterfaceRoleEnum.BACKUP", |
| 67 |
"vlan_id": 324}) |
| 68 |
|
| 69 |
FILE_INTERFACE_ROLE_ENUM_DUMMY = { |
| 70 |
'PRODUCTION': (0, 'Production'), |
| 71 |
'BACKUP': (1, 'Backup') |
| 72 |
} |
| 73 |
|
| 74 |
@staticmethod |
| 75 |
def get_nas_without_interface(): |
| 76 |
nas_object = deepcopy(MockInterfaceApi.NAS_SERVER_OBJECT) |
| 77 |
nas_object.file_interface['UnityFileInterfaceList'] = [] |
| 78 |
return nas_object |
| 79 |
|
| 80 |
@staticmethod |
| 81 |
def get_nas_server_obj_existed_false(): |
| 82 |
nas_object = deepcopy(MockInterfaceApi.NAS_SERVER_OBJECT) |
| 83 |
nas_object.existed = False |
| 84 |
return nas_object |
| 85 |
|
| 86 |
@staticmethod |
| 87 |
def get_interface_exception_response(response_type): |
| 88 |
if response_type == 'nas_server_id_exception': |
| 89 |
return "Failed to get details of NAS server: dummy_nas with error: " |
| 90 |
elif response_type == 'interface_exception': |
| 91 |
return "Getting Interface details failed with error " |
| 92 |
elif response_type == 'add_interface_exception': |
| 93 |
return "Failed to add interface to NAS Server with error: " |
| 94 |
elif response_type == 'delete_interface_exception': |
| 95 |
return "Failed to delete interface with error: " |
| 96 |
|
| 97 |
@staticmethod |
| 98 |
def get_interface_error_response(response_type): |
| 99 |
if response_type == 'invalid_ethernet_port_name': |
| 100 |
return "Please provide valid value for: ethernet_port_name" |
| 101 |
elif response_type == 'invalid_vlan_id': |
| 102 |
return "vlan_id should be in the range of 3 to 4094" |
| 103 |
elif response_type == 'invalid_interface_ip': |
| 104 |
return 'The value for interface ip is invalid' |
| 105 |
elif response_type == 'invalid_gateway': |
| 106 |
return "The value for gateway is invalid" |
| 107 |
elif response_type == 'invalid_netmask': |
| 108 |
return 'Invalid IPV4 address specified for netmask' |
| 109 |
elif response_type == 'modify_failure': |
| 110 |
return "Modification of Interfaces for NAS server is not supported through Ansible module" |
| 111 |
elif response_type == 'no_role': |
| 112 |
return "Role is a mandatory parameter for adding interface to NAS Server." |
| 113 |
elif response_type == 'no_ethernet': |
| 114 |
return "ethernet_port_name/ethernet_port_id is mandatory parameter for adding interface to NAS Server." |
| 115 |
|
| 116 |
@staticmethod |
| 117 |
def get_nas_server_obj_errors(response_type): |
| 118 |
if response_type == 'existed_false': |
| 119 |
return "NAS server with id nas_id_00 does not exist" |
| 120 |
elif response_type == 'exception': |
| 121 |
return "Failed to get details of NAS server with error: " |