| 1 |
|
| 2 |
|
| 3 |
from __future__ import absolute_import, division, print_function |
| 4 |
__metaclass__ = type |
| 5 |
|
| 6 |
import unittest |
| 7 |
from contextlib import contextmanager |
| 8 |
from ansible.module_utils.testing import patch_module_args |
| 9 |
from ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_global import NetAppESeriesGlobalSettings |
| 10 |
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ( |
| 11 |
AnsibleFailJson, AnsibleExitJson, ModuleTestCase |
| 12 |
) |
| 13 |
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import patch |
| 14 |
|
| 15 |
|
| 16 |
class GlobalSettingsTest(ModuleTestCase): |
| 17 |
REQUIRED_PARAMS = { |
| 18 |
'api_username': 'rw', |
| 19 |
'api_password': 'password', |
| 20 |
'api_url': 'http://localhost', |
| 21 |
'ssid': '1', |
| 22 |
} |
| 23 |
REQ_FUNC = 'ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_global.NetAppESeriesGlobalSettings.request' |
| 24 |
|
| 25 |
@contextmanager |
| 26 |
def _set_args(self, args=None): |
| 27 |
module_args = self.REQUIRED_PARAMS.copy() |
| 28 |
if args is not None: |
| 29 |
module_args.update(args) |
| 30 |
with patch_module_args(module_args): |
| 31 |
yield |
| 32 |
|
| 33 |
def test_init_pass(self): |
| 34 |
"""Verify module instantiates successfully.""" |
| 35 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 36 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 37 |
instance = NetAppESeriesGlobalSettings() |
| 38 |
|
| 39 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "disabled", |
| 40 |
"host_connectivity_reporting": "disabled", "name": "array1"}): |
| 41 |
instance = NetAppESeriesGlobalSettings() |
| 42 |
|
| 43 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "disabled", |
| 44 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 45 |
instance = NetAppESeriesGlobalSettings() |
| 46 |
|
| 47 |
def test_init_fail(self): |
| 48 |
"""Verify module fails when autoload is enabled but host connectivity reporting is not.""" |
| 49 |
with self._set_args({"automatic_load_balancing": "enabled", "host_connectivity_reporting": "disabled"}): |
| 50 |
with self.assertRaisesRegex(AnsibleFailJson, r"Option automatic_load_balancing requires host_connectivity_reporting to be enabled."): |
| 51 |
instance = NetAppESeriesGlobalSettings() |
| 52 |
|
| 53 |
@unittest.skip("Test needs to be reworked.") |
| 54 |
def test_get_current_configuration_pass(self): |
| 55 |
"""Ensure get_current_configuration method succeeds.""" |
| 56 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 57 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 58 |
instance = NetAppESeriesGlobalSettings() |
| 59 |
with patch(self.REQ_FUNC, side_effect=[(200, {"productCapabilities": [], "featureParameters": {"cacheBlockSizes": []}}), (200, []), |
| 60 |
(200, [{"defaultHostTypeIndex": 28, "cache": {"cacheBlkSize": 32768, "demandFlushThreshold": 90}}]), |
| 61 |
(200, {"autoLoadBalancingEnabled": True, "hostConnectivityReportingEnabled": True, "name": "array1"})]): |
| 62 |
self.assertEqual(instance.get_current_configuration(), {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [], |
| 63 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 90}, |
| 64 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 65 |
"host_type_options": {}, "name": 'array1'}) |
| 66 |
|
| 67 |
def test_get_current_configuration_fail(self): |
| 68 |
"""Ensure exceptions are thrown when current configuration requests fail.""" |
| 69 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 70 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 71 |
instance = NetAppESeriesGlobalSettings() |
| 72 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to retrieve storage array capabilities."): |
| 73 |
with patch(self.REQ_FUNC, side_effect=[Exception()]): |
| 74 |
instance.get_current_configuration() |
| 75 |
|
| 76 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 77 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 78 |
instance = NetAppESeriesGlobalSettings() |
| 79 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to retrieve storage array host options."): |
| 80 |
with patch(self.REQ_FUNC, side_effect=[(200, {"productCapabilities": [], "featureParameters": {"cacheBlockSizes": []}}), Exception()]): |
| 81 |
instance.get_current_configuration() |
| 82 |
|
| 83 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 84 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 85 |
instance = NetAppESeriesGlobalSettings() |
| 86 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to retrieve cache settings."): |
| 87 |
with patch( |
| 88 |
self.REQ_FUNC, |
| 89 |
side_effect=[ |
| 90 |
(200, { |
| 91 |
"productCapabilities": [], |
| 92 |
"featureParameters": {"cacheBlockSizes": []} |
| 93 |
}), |
| 94 |
(200, []), |
| 95 |
Exception() |
| 96 |
] |
| 97 |
): |
| 98 |
instance.get_current_configuration() |
| 99 |
|
| 100 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 101 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 102 |
instance = NetAppESeriesGlobalSettings() |
| 103 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to determine current configuration."): |
| 104 |
with patch(self.REQ_FUNC, side_effect=[(200, {"productCapabilities": [], "featureParameters": {"cacheBlockSizes": []}}), (200, []), |
| 105 |
(200, [{"defaultHostTypeIndex": 28, "cache": {"cacheBlkSize": 32768, "demandFlushThreshold": 90}}]), |
| 106 |
Exception()]): |
| 107 |
instance.get_current_configuration() |
| 108 |
|
| 109 |
def test_cache_block_size_pass(self): |
| 110 |
"""Verify cache_block_size passes successfully.""" |
| 111 |
with self._set_args({"cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 112 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 113 |
instance = NetAppESeriesGlobalSettings() |
| 114 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 115 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 90}, |
| 116 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 117 |
"host_type_options": {}, "name": 'array1'} |
| 118 |
self.assertFalse(instance.change_cache_block_size_required()) |
| 119 |
|
| 120 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 121 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 122 |
instance = NetAppESeriesGlobalSettings() |
| 123 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 124 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 90}, |
| 125 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 126 |
"host_type_options": {}, "name": 'array1'} |
| 127 |
self.assertFalse(instance.change_cache_block_size_required()) |
| 128 |
|
| 129 |
with self._set_args({"cache_block_size": 16384, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 130 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 131 |
instance = NetAppESeriesGlobalSettings() |
| 132 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 133 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 90}, |
| 134 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 135 |
"host_type_options": {}, "name": 'array1'} |
| 136 |
self.assertTrue(instance.change_cache_block_size_required()) |
| 137 |
|
| 138 |
def test_cache_block_size_fail(self): |
| 139 |
"""Verify cache_block_size throws expected exceptions.""" |
| 140 |
with self._set_args({"cache_block_size": 16384, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 141 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 142 |
instance = NetAppESeriesGlobalSettings() |
| 143 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [32768], |
| 144 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 90}, |
| 145 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 146 |
"host_type_options": {}, "name": 'array1'} |
| 147 |
with self.assertRaisesRegex(AnsibleFailJson, r"Invalid cache block size."): |
| 148 |
self.assertTrue(instance.change_cache_block_size_required()) |
| 149 |
|
| 150 |
def test_change_cache_flush_threshold_required_pass(self): |
| 151 |
"""Verify change_cache_block_size_required passes successfully.""" |
| 152 |
with self._set_args({"cache_block_size": 32768, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 153 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 154 |
instance = NetAppESeriesGlobalSettings() |
| 155 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 156 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 157 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 158 |
"host_type_options": {}, "name": 'array1'} |
| 159 |
self.assertFalse(instance.change_cache_flush_threshold_required()) |
| 160 |
|
| 161 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 80, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 162 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 163 |
instance = NetAppESeriesGlobalSettings() |
| 164 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 165 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 166 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 167 |
"host_type_options": {}, "name": 'array1'} |
| 168 |
self.assertFalse(instance.change_cache_flush_threshold_required()) |
| 169 |
|
| 170 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 171 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 172 |
instance = NetAppESeriesGlobalSettings() |
| 173 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 174 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 175 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 176 |
"host_type_options": {}, "name": 'array1'} |
| 177 |
self.assertTrue(instance.change_cache_flush_threshold_required()) |
| 178 |
|
| 179 |
def test_change_cache_flush_threshold_required_fail(self): |
| 180 |
"""Verify change_cache_block_size_required throws expected exceptions.""" |
| 181 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 100, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 182 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 183 |
instance = NetAppESeriesGlobalSettings() |
| 184 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 185 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 186 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 187 |
"host_type_options": {}, "name": 'array1'} |
| 188 |
|
| 189 |
with self.assertRaisesRegex(AnsibleFailJson, r"Invalid cache flushing threshold, it must be equal to or between 0 and 100."): |
| 190 |
instance.change_cache_flush_threshold_required() |
| 191 |
|
| 192 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 0, "default_host_type": "linux dm-mp", "automatic_load_balancing": "enabled", |
| 193 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 194 |
instance = NetAppESeriesGlobalSettings() |
| 195 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 196 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 197 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 198 |
"host_type_options": {}, "name": 'array1'} |
| 199 |
|
| 200 |
with self.assertRaisesRegex(AnsibleFailJson, r"Invalid cache flushing threshold, it must be equal to or between 0 and 100."): |
| 201 |
instance.change_cache_flush_threshold_required() |
| 202 |
|
| 203 |
def test_change_host_type_required_pass(self): |
| 204 |
"""Verify change_host_type_required passes successfully.""" |
| 205 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "automatic_load_balancing": "enabled", |
| 206 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 207 |
instance = NetAppESeriesGlobalSettings() |
| 208 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 209 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 210 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 211 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 212 |
self.assertFalse(instance.change_host_type_required()) |
| 213 |
|
| 214 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Linux DM-MP", "automatic_load_balancing": "enabled", |
| 215 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 216 |
instance = NetAppESeriesGlobalSettings() |
| 217 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 218 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 219 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 220 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 221 |
self.assertFalse(instance.change_host_type_required()) |
| 222 |
|
| 223 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "enabled", |
| 224 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 225 |
instance = NetAppESeriesGlobalSettings() |
| 226 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 227 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 228 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 229 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 230 |
self.assertTrue(instance.change_host_type_required()) |
| 231 |
|
| 232 |
def test_change_host_type_required_fail(self): |
| 233 |
"""Verify change_host_type_required throws expected exceptions""" |
| 234 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "NotAHostType", "automatic_load_balancing": "enabled", |
| 235 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 236 |
instance = NetAppESeriesGlobalSettings() |
| 237 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 238 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 239 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 240 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 241 |
with self.assertRaisesRegex(AnsibleFailJson, r"Invalid host type index!"): |
| 242 |
self.assertTrue(instance.change_host_type_required()) |
| 243 |
|
| 244 |
def test_change_autoload_enabled_required_pass(self): |
| 245 |
"""Verify change_autoload_enabled_required passes successfully.""" |
| 246 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", |
| 247 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 248 |
instance = NetAppESeriesGlobalSettings() |
| 249 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 250 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 251 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 252 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 253 |
self.assertFalse(instance.change_autoload_enabled_required()) |
| 254 |
|
| 255 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "enabled", |
| 256 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 257 |
instance = NetAppESeriesGlobalSettings() |
| 258 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 259 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 260 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 261 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 262 |
self.assertFalse(instance.change_autoload_enabled_required()) |
| 263 |
|
| 264 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 265 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 266 |
instance = NetAppESeriesGlobalSettings() |
| 267 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 268 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 269 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 270 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 271 |
self.assertTrue(instance.change_autoload_enabled_required()) |
| 272 |
|
| 273 |
def test_change_autoload_enabled_required_fail(self): |
| 274 |
"""Verify change_autoload_enabled_required throws expected exceptions""" |
| 275 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "NotAHostType", "automatic_load_balancing": "enabled", |
| 276 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 277 |
instance = NetAppESeriesGlobalSettings() |
| 278 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 279 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 280 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 281 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 282 |
with self.assertRaisesRegex(AnsibleFailJson, r"Automatic load balancing is not available."): |
| 283 |
self.assertTrue(instance.change_autoload_enabled_required()) |
| 284 |
|
| 285 |
def test_change_host_connectivity_reporting_enabled_required_pass(self): |
| 286 |
"""Verify change_host_connectivity_reporting_enabled_required passes successfully.""" |
| 287 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 288 |
"name": "array1"}): |
| 289 |
instance = NetAppESeriesGlobalSettings() |
| 290 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 291 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 292 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 293 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 294 |
self.assertFalse(instance.change_host_connectivity_reporting_enabled_required()) |
| 295 |
|
| 296 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 297 |
"host_connectivity_reporting": "enabled", "name": "array1"}): |
| 298 |
instance = NetAppESeriesGlobalSettings() |
| 299 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 300 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 301 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 302 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 303 |
self.assertFalse(instance.change_host_connectivity_reporting_enabled_required()) |
| 304 |
|
| 305 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 306 |
"host_connectivity_reporting": "disabled", "name": "array1"}): |
| 307 |
instance = NetAppESeriesGlobalSettings() |
| 308 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 309 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 310 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 311 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 312 |
self.assertTrue(instance.change_host_connectivity_reporting_enabled_required()) |
| 313 |
|
| 314 |
def test_change_name_required_pass(self): |
| 315 |
"""Verify change_name_required passes successfully.""" |
| 316 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 317 |
"host_connectivity_reporting": "disabled"}): |
| 318 |
instance = NetAppESeriesGlobalSettings() |
| 319 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 320 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 321 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 322 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 323 |
self.assertFalse(instance.change_name_required()) |
| 324 |
|
| 325 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 326 |
"host_connectivity_reporting": "disabled", "name": "array1"}): |
| 327 |
instance = NetAppESeriesGlobalSettings() |
| 328 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 329 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 330 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 331 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 332 |
self.assertFalse(instance.change_name_required()) |
| 333 |
|
| 334 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 335 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 336 |
instance = NetAppESeriesGlobalSettings() |
| 337 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 338 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 339 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 340 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 341 |
self.assertTrue(instance.change_name_required()) |
| 342 |
|
| 343 |
@unittest.skip("Test needs to be reworked.") |
| 344 |
def test_change_name_required_fail(self): |
| 345 |
"""Verify change_name_required throws expected exceptions""" |
| 346 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "NotAHostType", "automatic_load_balancing": "enabled", |
| 347 |
"host_connectivity_reporting": "enabled", "name": "A" * 31}): |
| 348 |
instance = NetAppESeriesGlobalSettings() |
| 349 |
instance.get_current_configuration = lambda: {"autoload_capable": False, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 350 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 351 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 352 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 353 |
with self.assertRaisesRegex(AnsibleFailJson, r"The provided name is invalid, it must be less than or equal to 30 characters in length."): |
| 354 |
self.assertTrue(instance.change_name_required()) |
| 355 |
|
| 356 |
def test_update_cache_settings_pass(self): |
| 357 |
"""Verify update_cache_settings passes successfully.""" |
| 358 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 359 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 360 |
instance = NetAppESeriesGlobalSettings() |
| 361 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 362 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 363 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 364 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 365 |
with patch(self.REQ_FUNC, return_value=(200, None)): |
| 366 |
instance.update_cache_settings() |
| 367 |
|
| 368 |
def test_update_cache_settings_fail(self): |
| 369 |
"""Verify update_cache_settings throws expected exceptions""" |
| 370 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 371 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 372 |
instance = NetAppESeriesGlobalSettings() |
| 373 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 374 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 375 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 376 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 377 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to set cache settings."): |
| 378 |
with patch(self.REQ_FUNC, return_value=Exception()): |
| 379 |
instance.update_cache_settings() |
| 380 |
|
| 381 |
def test_update_host_type_pass(self): |
| 382 |
"""Verify update_host_type passes successfully.""" |
| 383 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 384 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 385 |
instance = NetAppESeriesGlobalSettings() |
| 386 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 387 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 388 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 389 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 390 |
with patch(self.REQ_FUNC, return_value=(200, None)): |
| 391 |
instance.update_host_type() |
| 392 |
|
| 393 |
def test_update_host_type_fail(self): |
| 394 |
"""Verify update_host_type throws expected exceptions""" |
| 395 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 396 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 397 |
instance = NetAppESeriesGlobalSettings() |
| 398 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 399 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 400 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 401 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 402 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to set default host type."): |
| 403 |
with patch(self.REQ_FUNC, return_value=Exception()): |
| 404 |
instance.update_host_type() |
| 405 |
|
| 406 |
def test_update_autoload_pass(self): |
| 407 |
"""Verify update_autoload passes successfully.""" |
| 408 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 409 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 410 |
instance = NetAppESeriesGlobalSettings() |
| 411 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 412 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 413 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 414 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 415 |
with patch(self.REQ_FUNC, return_value=(200, None)): |
| 416 |
instance.update_autoload() |
| 417 |
|
| 418 |
def test_update_autoload_fail(self): |
| 419 |
"""Verify update_autoload throws expected exceptions""" |
| 420 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 421 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 422 |
instance = NetAppESeriesGlobalSettings() |
| 423 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 424 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 425 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 426 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 427 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to set automatic load balancing state."): |
| 428 |
with patch(self.REQ_FUNC, return_value=Exception()): |
| 429 |
instance.update_autoload() |
| 430 |
|
| 431 |
def test_update_host_connectivity_reporting_enabled_pass(self): |
| 432 |
"""Verify update_host_connectivity_reporting_enabled passes successfully.""" |
| 433 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 434 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 435 |
instance = NetAppESeriesGlobalSettings() |
| 436 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 437 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 438 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 439 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 440 |
with patch(self.REQ_FUNC, return_value=(200, None)): |
| 441 |
instance.update_host_connectivity_reporting_enabled() |
| 442 |
|
| 443 |
def test_update_host_connectivity_reporting_enabled_fail(self): |
| 444 |
"""Verify update_host_connectivity_reporting_enabled throws expected exceptions""" |
| 445 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 446 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 447 |
instance = NetAppESeriesGlobalSettings() |
| 448 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 449 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 450 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 451 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 452 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to enable host connectivity reporting."): |
| 453 |
with patch(self.REQ_FUNC, return_value=Exception()): |
| 454 |
instance.update_host_connectivity_reporting_enabled() |
| 455 |
|
| 456 |
def test_update_name_pass(self): |
| 457 |
"""Verify update_name passes successfully.""" |
| 458 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 459 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 460 |
instance = NetAppESeriesGlobalSettings() |
| 461 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 462 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 463 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 464 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 465 |
with patch(self.REQ_FUNC, return_value=(200, None)): |
| 466 |
instance.update_name() |
| 467 |
|
| 468 |
def test_update_name_fail(self): |
| 469 |
"""Verify update_name throws expected exceptions""" |
| 470 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 471 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 472 |
instance = NetAppESeriesGlobalSettings() |
| 473 |
instance.get_current_configuration = lambda: {"autoload_capable": True, "autoload_enabled": True, "cache_block_size_options": [16384, 32768], |
| 474 |
"cache_settings": {"cache_block_size": 32768, "cache_flush_threshold": 80}, |
| 475 |
"default_host_type_index": 28, "host_connectivity_reporting_enabled": True, |
| 476 |
"host_type_options": {"windows": 1, "linux": 28}, "name": 'array1'} |
| 477 |
with self.assertRaisesRegex(AnsibleFailJson, r"Failed to set the storage array name!"): |
| 478 |
with patch(self.REQ_FUNC, return_value=Exception()): |
| 479 |
instance.update_name() |
| 480 |
|
| 481 |
@unittest.skip("Test needs to be reworked.") |
| 482 |
def test_update_pass(self): |
| 483 |
"""Verify update passes successfully.""" |
| 484 |
with self._set_args({ |
| 485 |
"cache_block_size": 32768, |
| 486 |
"cache_flush_threshold": 90, |
| 487 |
"default_host_type": "Windows", |
| 488 |
"automatic_load_balancing": "disabled", |
| 489 |
"host_connectivity_reporting": "disabled", |
| 490 |
"name": "array2" |
| 491 |
}): |
| 492 |
instance = NetAppESeriesGlobalSettings() |
| 493 |
|
| 494 |
instance.change_autoload_enabled_required = lambda: False |
| 495 |
instance.change_cache_block_size_required = lambda: False |
| 496 |
instance.change_cache_flush_threshold_required = lambda: False |
| 497 |
instance.change_host_type_required = lambda: False |
| 498 |
instance.change_name_required = lambda: False |
| 499 |
instance.change_host_connectivity_reporting_enabled_required = lambda: False |
| 500 |
with self.assertRaisesRegex(AnsibleExitJson, r"'changed': False"): |
| 501 |
with patch( |
| 502 |
self.REQ_FUNC, |
| 503 |
side_effect=[ |
| 504 |
(200, {"productCapabilities": [], "featureParameters": {"cacheBlockSizes": []}}), |
| 505 |
(200, []), |
| 506 |
(200, [{ |
| 507 |
"defaultHostTypeIndex": 28, |
| 508 |
"cache": {"cacheBlkSize": 32768, "demandFlushThreshold": 90} |
| 509 |
}]), |
| 510 |
(200, { |
| 511 |
"autoLoadBalancingEnabled": True, |
| 512 |
"hostConnectivityReportingEnabled": True, |
| 513 |
"name": "array1" |
| 514 |
}) |
| 515 |
] * 2 |
| 516 |
): |
| 517 |
instance.update() |
| 518 |
|
| 519 |
with self._set_args({"cache_block_size": 32768, "cache_flush_threshold": 90, "default_host_type": "Windows", "automatic_load_balancing": "disabled", |
| 520 |
"host_connectivity_reporting": "disabled", "name": "array2"}): |
| 521 |
instance = NetAppESeriesGlobalSettings() |
| 522 |
instance.change_autoload_enabled_required = lambda: True |
| 523 |
instance.change_cache_block_size_required = lambda: False |
| 524 |
instance.change_cache_flush_threshold_required = lambda: False |
| 525 |
instance.change_host_type_required = lambda: False |
| 526 |
instance.change_name_required = lambda: False |
| 527 |
instance.change_host_connectivity_reporting_enabled_required = lambda: False |
| 528 |
instance.update_autoload = lambda: None |
| 529 |
with self.assertRaisesRegex(AnsibleExitJson, r"'changed': True"): |
| 530 |
with patch( |
| 531 |
self.REQ_FUNC, |
| 532 |
side_effect=[ |
| 533 |
(200, {"productCapabilities": [], "featureParameters": {"cacheBlockSizes": []}}), |
| 534 |
(200, []), |
| 535 |
(200, [{ |
| 536 |
"defaultHostTypeIndex": 28, |
| 537 |
"cache": {"cacheBlkSize": 32768, "demandFlushThreshold": 90} |
| 538 |
}]), |
| 539 |
(200, { |
| 540 |
"autoLoadBalancingEnabled": True, |
| 541 |
"hostConnectivityReportingEnabled": True, "name": "array1" |
| 542 |
}) |
| 543 |
] * 2 |
| 544 |
): |
| 545 |
instance.update() |