| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Mock Api response for Unit tests of nfs 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 |
from mock.mock import MagicMock |
| 14 |
|
| 15 |
|
| 16 |
class MockNfsApi: |
| 17 |
NFS_MODULE_ARGS = { |
| 18 |
'unispherehost': '**.***.**.***', |
| 19 |
'port': '123', |
| 20 |
'description': None, |
| 21 |
'anonymous_uid': None, |
| 22 |
'anonymous_gid': None, |
| 23 |
'min_security': None, |
| 24 |
'default_access': None, |
| 25 |
'nas_server_id': None, |
| 26 |
'nas_server_name': None, |
| 27 |
'nfs_export_id': None, |
| 28 |
'nfs_export_name': None, |
| 29 |
'snapshot_name': None, |
| 30 |
'snapshot_id': None, |
| 31 |
'filesystem_name': None, |
| 32 |
'filesystem_id': None, |
| 33 |
'host_state': None, |
| 34 |
'adv_host_mgmt_enabled': None, |
| 35 |
'no_access_hosts': None, |
| 36 |
'read_only_hosts': None, |
| 37 |
'read_only_root_hosts': None, |
| 38 |
'read_write_hosts': None, |
| 39 |
'read_write_root_hosts': None, |
| 40 |
'path': None, |
| 41 |
'state': None |
| 42 |
} |
| 43 |
|
| 44 |
DUMMY_DOMAIN_VALUE = "google.com" |
| 45 |
DUMMY_SUBNET_VALUE = "**.***.2.2/10" |
| 46 |
|
| 47 |
FILESYSTEM_OBJECT = MockSDKObject({"access_policy": "AccessPolicyEnum.UNIX", "cifs_notify_on_change_dir_depth": 512, |
| 48 |
"data_reduction_percent": 0, "data_reduction_ratio": 1.0, "data_reduction_size_saved": 0, |
| 49 |
"description": "", "existed": True, |
| 50 |
"folder_rename_policy": "FSRenamePolicyEnum.SMB_RENAME_FORBIDDEN", |
| 51 |
"format": "FSFormatEnum.UFS64", "host_io_size": "HostIOSizeEnum.GENERAL_16K", |
| 52 |
"id": "fs_id_1", "is_advanced_dedup_enabled": False, "is_cifs_notify_on_access_enabled": False, |
| 53 |
"is_cifs_notify_on_write_enabled": False, "is_cifs_op_locks_enabled": True, |
| 54 |
"is_cifs_sync_writes_enabled": False, "is_data_reduction_enabled": False, "is_read_only": False, |
| 55 |
"is_smbca": False, "is_thin_enabled": True, "locking_policy": "FSLockingPolicyEnum.MANDATORY", |
| 56 |
"min_size_allocated": 0, "name": "fs_dummy_name", "nas_server": {"id": "nas_id_1"}, |
| 57 |
"nfs_share": [{"id": "NFSShare_id_1"}], "pool": {"id": "pool_id_1"}, |
| 58 |
"pool_full_policy": "ResourcePoolFullPolicyEnum.FAIL_WRITES", "snap_count": 0, "snaps_size": 0, |
| 59 |
"snaps_size_allocated": 0, "storage_resource": {"id": "stg_id_1"}, |
| 60 |
"supported_protocols": "FSSupportedProtocolEnum.NFS", |
| 61 |
"tiering_policy": "TieringPolicyEnum.AUTOTIER_HIGH", |
| 62 |
"type": "FilesystemTypeEnum.FILESYSTEM"}) |
| 63 |
|
| 64 |
NFS_SHARE_OBJECT = MockSDKObject({"anonymous_gid": 4294967294, "anonymous_uid": 4294967294, |
| 65 |
"default_access": "NFSShareDefaultAccessEnum.NO_ACCESS", "description": "", "existed": True, |
| 66 |
"export_option": 1, "export_paths": ["**.***.**.**:/nfsshare_dummy_name"], |
| 67 |
"filesystem": MockSDKObject({"id": "fs_id_1", "name": "fs_name1", "nas_server": "not_none"}), |
| 68 |
"id": "NFSShare_id_1", |
| 69 |
"min_security": "NFSShareSecurityEnum.SYS", |
| 70 |
"modification_time": "2022-04-24 17:07:57.749000+00:00", |
| 71 |
"name": "nfsshare_dummy_name", |
| 72 |
"no_access_hosts": None, |
| 73 |
"no_access_hosts_string": None, |
| 74 |
"read_only_hosts": None, |
| 75 |
"read_only_hosts_string": None, |
| 76 |
"read_only_root_access_hosts": None, |
| 77 |
"read_only_root_hosts_string": None, |
| 78 |
"read_write_hosts": None, |
| 79 |
"read_write_hosts_string": None, |
| 80 |
"read_write_root_hosts_string": None, |
| 81 |
"root_access_hosts": None, |
| 82 |
"path": "/", |
| 83 |
"role": "NFSShareRoleEnum.PRODUCTION", |
| 84 |
"type": "NFSTypeEnum.NFS_SHARE"}) |
| 85 |
|
| 86 |
NFS_SHARE_DISPLAY_ATTR = {'anonymous_gid': 4294967294, 'anonymous_uid': 4294967294, 'creation_time': '2022-03-09 15:05:34.720000+00:00', |
| 87 |
'default_access': 'NFSShareDefaultAccessEnum.NO_ACCESS', 'description': '', 'export_option': 1, |
| 88 |
'export_paths': ['**.***.**.**:/nfsshare_dummy_name'], |
| 89 |
'filesystem': {'UnityFileSystem': {'id': 'fs_id_1', 'name': 'fs_name1'}}, 'host_accesses': None, |
| 90 |
'id': 'NFSShare_id_1', 'is_read_only': None, 'min_security': 'NFSShareSecurityEnum.SYS', |
| 91 |
'modification_time': '2022-04-24 17:07:57.749000+00:00', 'name': 'nfsshare_dummy_name', |
| 92 |
'nfs_owner_username': None, 'no_access_hosts': None, |
| 93 |
'no_access_hosts_string': None, |
| 94 |
'path': '/', 'read_only_hosts': None, 'read_only_hosts_string': '', 'read_only_root_access_hosts': None, |
| 95 |
'read_only_root_hosts_string': '', 'read_write_hosts': None, 'read_write_hosts_string': '', |
| 96 |
'read_write_root_hosts_string': '', 'role': 'NFSShareRoleEnum.PRODUCTION', 'root_access_hosts': None, |
| 97 |
'snap': None, 'type': 'NFSTypeEnum.NFS_SHARE', 'existed': True, |
| 98 |
'nas_server': {'UnityNasServer': {'id': 'nas_id_1', 'name': 'lglad068'}}} |
| 99 |
|
| 100 |
@staticmethod |
| 101 |
def get_nfs_share_object_on_host_access(action, advhostmgmt): |
| 102 |
if advhostmgmt: |
| 103 |
if action == 'add': |
| 104 |
nfs_share_object = MockNfsApi.NFS_SHARE_OBJECT |
| 105 |
return nfs_share_object |
| 106 |
elif action == 'remove': |
| 107 |
nfs_share_object = MockNfsApi.NFS_SHARE_OBJECT |
| 108 |
nfs_share_object.no_access_hosts = { |
| 109 |
'UnityHostList': [ |
| 110 |
{ |
| 111 |
'UnityHost': { |
| 112 |
'id': 'Host_1389' |
| 113 |
} |
| 114 |
}, |
| 115 |
{ |
| 116 |
'UnityHost': { |
| 117 |
'id': 'Host_1330' |
| 118 |
} |
| 119 |
} |
| 120 |
] |
| 121 |
} |
| 122 |
return nfs_share_object |
| 123 |
else: |
| 124 |
if action == 'add': |
| 125 |
nfs_share_display_attr = MockNfsApi.NFS_SHARE_OBJECT |
| 126 |
nfs_share_display_attr.read_only_root_hosts_string = '' |
| 127 |
return nfs_share_display_attr |
| 128 |
elif action == 'remove': |
| 129 |
nfs_share_display_attr = MockNfsApi.NFS_SHARE_OBJECT |
| 130 |
nfs_share_display_attr.read_only_root_hosts_string = '*.google.com,**.***.0.0/255.***.*.*' |
| 131 |
return nfs_share_display_attr |
| 132 |
|
| 133 |
@staticmethod |
| 134 |
def get_nfs_share_display_attr_on_host_access(action, advhostmgmt): |
| 135 |
if advhostmgmt: |
| 136 |
if action == 'add': |
| 137 |
nfs_share_display_attr = MockNfsApi.NFS_SHARE_DISPLAY_ATTR |
| 138 |
nfs_share_display_attr['no_access_hosts'] = { |
| 139 |
'UnityHostList': [ |
| 140 |
{ |
| 141 |
'UnityHost': { |
| 142 |
'id': 'Host_1389' |
| 143 |
} |
| 144 |
}, |
| 145 |
{ |
| 146 |
'UnityHost': { |
| 147 |
'id': 'Host_1330' |
| 148 |
} |
| 149 |
} |
| 150 |
] |
| 151 |
} |
| 152 |
return nfs_share_display_attr |
| 153 |
elif action == 'remove': |
| 154 |
nfs_share_display_attr = MockNfsApi.NFS_SHARE_DISPLAY_ATTR |
| 155 |
nfs_share_display_attr['no_access_hosts'] = None |
| 156 |
return nfs_share_display_attr |
| 157 |
else: |
| 158 |
if action == 'add': |
| 159 |
nfs_share_display_attr = MockNfsApi.NFS_SHARE_DISPLAY_ATTR |
| 160 |
nfs_share_display_attr['read_only_root_hosts_string'] = '*.google.com,**.***.0.0/255.***.*.*' |
| 161 |
return nfs_share_display_attr |
| 162 |
elif action == 'remove': |
| 163 |
nfs_share_display_attr = MockNfsApi.NFS_SHARE_DISPLAY_ATTR |
| 164 |
nfs_share_display_attr['read_only_root_hosts_string'] = '' |
| 165 |
return nfs_share_display_attr |
| 166 |
|
| 167 |
@staticmethod |
| 168 |
def get_host_obj(id): |
| 169 |
if id == 1: |
| 170 |
host_1 = MagicMock() |
| 171 |
host_1.id = 'Host_1389' |
| 172 |
host_1.name = 'host_1' |
| 173 |
return host_1 |
| 174 |
elif id == 2: |
| 175 |
host_2 = MagicMock() |
| 176 |
host_2.id = 'Host_1330' |
| 177 |
host_2.name = 'host_2' |
| 178 |
return host_2 |
| 179 |
|
| 180 |
@staticmethod |
| 181 |
def host_access_negative_response(response_type): |
| 182 |
if response_type == 'subnet_validation': |
| 183 |
return "Subnet should be in format 'IP address/netmask' or 'IP address/prefix length'" |
| 184 |
elif response_type == 'advhostmngmnt_field_validation': |
| 185 |
return "'host_state' and 'adv_host_mgmt_enabled' is required along with: read_only_root_hosts" |
| 186 |
elif response_type == 'modify_exception': |
| 187 |
return 'Failed to modify nfs error: ' |