| 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.module_utils import six |
| 10 |
from ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_firmware import NetAppESeriesFirmware |
| 11 |
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ( |
| 12 |
AnsibleFailJson, ModuleTestCase |
| 13 |
) |
| 14 |
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import mock_open, patch |
| 15 |
|
| 16 |
if six.PY2: |
| 17 |
builtin_path = "__builtin__.open" |
| 18 |
else: |
| 19 |
builtin_path = "builtins.open" |
| 20 |
|
| 21 |
|
| 22 |
def mock_open_with_iter(*args, **kwargs): |
| 23 |
mock = mock_open(*args, **kwargs) |
| 24 |
|
| 25 |
if six.PY2: |
| 26 |
mock.return_value.__iter__ = lambda x: iter(x.readline, "") |
| 27 |
else: |
| 28 |
mock.return_value.__iter__ = lambda x: x |
| 29 |
mock.return_value.__next__ = lambda x: iter(x.readline, "") |
| 30 |
return mock |
| 31 |
|
| 32 |
|
| 33 |
class FirmwareTest(ModuleTestCase): |
| 34 |
REQUIRED_PARAMS = {"api_username": "username", |
| 35 |
"api_password": "password", |
| 36 |
"api_url": "http://localhost/devmgr/v2", |
| 37 |
"ssid": "1", |
| 38 |
"validate_certs": "no"} |
| 39 |
REQUEST_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_firmware.NetAppESeriesFirmware.request" |
| 40 |
BASE_REQUEST_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_firmware.request" |
| 41 |
CREATE_MULTIPART_FORMDATA_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_firmware.create_multipart_formdata" |
| 42 |
SLEEP_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_firmware.sleep" |
| 43 |
BUNDLE_HEADER = b'combined_content\x00\x00\x00\x04\x00\x00\x07\xf8#Engenio Downloadable Package\n#Tue Jun 04 11:46:48 CDT 2019\ncheckList=compatibleBoard' \ |
| 44 |
b'Map,compatibleSubmodelMap,compatibleFirmwareMap,fileManifest\ncompatibleSubmodelMap=261|true,262|true,263|true,264|true,276|true,277|t' \ |
| 45 |
b'rue,278|true,282|true,300|true,301|true,302|true,318|true,319|true,320|true,321|true,322|true,323|true,324|true,325|true,326|true,328|t' \ |
| 46 |
b'rue,329|true,330|true,331|true,332|true,333|true,338|true,339|true,340|true,341|true,342|true,343|true,344|true,345|true,346|true,347|t' \ |
| 47 |
b'rue,356|true,357|true,390|true\nnonDisplayableAttributeList=512\ndisplayableAttributeList=FILENAME|RCB_11.40.5_280x_5ceef00e.dlp,VERSI' \ |
| 48 |
b'ON|11.40.5\ndacStoreLimit=512\nfileManifest=metadata.tar|metadata|08.42.50.00.000|c04275f98fc2f07bd63126fc57cb0569|bundle|10240,084250' \ |
| 49 |
b'00_m3_e30_842_root.img|linux|08.42.50.00|367c5216e5c4b15b904a025bff69f039|linux|1342177280,RC_08425000_m3_e30_842_280x.img|linux_cfw|0' \ |
| 50 |
b'8.42.50.00|e6589b0a50b29ff34b34d3ced8ae3ccb|eos|1073741824,msw.img|sam|11.42.0000.0028|ef3ee5589ab4a019a3e6f83768364aa1|linux|41943040' \ |
| 51 |
b'0,iom.img|iom|11.42.0G00.0003|9bb740f8d3a4e62a0f2da2ec83c254c4|linux|8177664\nmanagementVersionList=devmgr.v1142api8.Manager\ncompatib' \ |
| 52 |
b'leFirmwareMap=08.30.*.*|true,08.30.*.30|false,08.30.*.31|false,08.30.*.32|false,08.30.*.33|false,08.30.*.34|false,08.30.*.35|false,08.' \ |
| 53 |
b'30.*.36|false,08.30.*.37|false,08.30.*.38|false,08.30.*.39|false,08.40.*.*|true,08.40.*.30|false,08.40.*.31|false,08.40.*.32|false,08.4' \ |
| 54 |
b'0.*.33|false,08.40.*.34|false,08.40.*.35|false,08.40.*.36|false,08.40.*.37|false,08.40.*.38|false,08.40.*.39|false,08.41.*.*|true,08.4' \ |
| 55 |
b'1.*.30|false,08.41.*.31|false,08.41.*.32|false,08.41.*.33|false,08.41.*.34|false,08.41.*.35|false,08.41.*.36|false,08.41.*.37|false,08' \ |
| 56 |
b'.41.*.38|false,08.41.*.39|false,08.42.*.*|true,08.42.*.30|false,08.42.*.31|false,08.42.*.32|false,08.42.*.33|false,08.42.*.34|false,08' \ |
| 57 |
b'.42.*.35|false,08.42.*.36|false,08.42.*.37|false,08.42.*.38|false,08.42.*.39|false\nversion=08.42.50.00.000\ntype=tar\nversionTag=comb' \ |
| 58 |
b'ined_content\n' |
| 59 |
|
| 60 |
NVSRAM_HEADER = b'nvsram \x00\x00\x00\x01\x00\x00\x00\xa0\x00\x00\x00\x04280X\x00\x00\x00\x00\x00\x00\x00\x032801 2804 2806 \x00\x00' \ |
| 61 |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x1bArapaho controller, 8.52 FW\x00\x00\x001dual controller configuration, with cac' \ |
| 62 |
b'he battery\x07\x81A\x08Config\x00\x00\x0008.52.00.00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\xdc\xaf\x00\x00' \ |
| 63 |
b'\x94\xc1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00 2801 2804 2806 \x00\x00\x00\x00\x00' \ |
| 64 |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ |
| 65 |
b'\x00\x00\x00\x00\x00\x00Board\n .Board Name = "NetApp RAID Controller"\n .NVSRAM Configuration Number' \ |
| 66 |
b' = "N280X-852834-D02"\n\nUserCfg\n .Enable Synchronous Negotiation = 0x00 \n' |
| 67 |
|
| 68 |
@contextmanager |
| 69 |
def _set_args(self, args=None): |
| 70 |
module_args = self.REQUIRED_PARAMS.copy() |
| 71 |
if args is not None: |
| 72 |
module_args.update(args) |
| 73 |
with patch_module_args(module_args): |
| 74 |
yield |
| 75 |
|
| 76 |
def test_is_firmware_bundled_pass(self): |
| 77 |
"""Determine whether firmware file is bundled.""" |
| 78 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 79 |
with patch(builtin_path, mock_open(read_data=b"firmwarexxxxxxxx")) as mock_file: |
| 80 |
firmware = NetAppESeriesFirmware() |
| 81 |
self.assertEqual(firmware.is_firmware_bundled(), False) |
| 82 |
|
| 83 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 84 |
with patch(builtin_path, mock_open(read_data=self.BUNDLE_HEADER[:16])) as mock_file: |
| 85 |
firmware = NetAppESeriesFirmware() |
| 86 |
self.assertEqual(firmware.is_firmware_bundled(), True) |
| 87 |
|
| 88 |
def test_is_firmware_bundles_fail(self): |
| 89 |
"""Verify non-firmware fails.""" |
| 90 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 91 |
with patch(builtin_path, mock_open(read_data=b"xxxxxxxxxxxxxxxx")) as mock_file: |
| 92 |
firmware = NetAppESeriesFirmware() |
| 93 |
with self.assertRaisesRegex(AnsibleFailJson, "Firmware file is invalid."): |
| 94 |
firmware.is_firmware_bundled() |
| 95 |
|
| 96 |
def test_firmware_version(self): |
| 97 |
"""Verify correct firmware version is returned.""" |
| 98 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 99 |
firmware = NetAppESeriesFirmware() |
| 100 |
firmware.is_firmware_bundled = lambda: True |
| 101 |
with patch(builtin_path, mock_open_with_iter(read_data=self.BUNDLE_HEADER)) as mock_file: |
| 102 |
self.assertEqual(firmware.firmware_version(), b"11.40.5") |
| 103 |
|
| 104 |
def test_nvsram_version(self): |
| 105 |
"""Verify correct nvsram version is returned.""" |
| 106 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 107 |
firmware = NetAppESeriesFirmware() |
| 108 |
|
| 109 |
with patch(builtin_path, mock_open_with_iter(read_data=self.NVSRAM_HEADER)) as mock_file: |
| 110 |
self.assertEqual(firmware.nvsram_version(), b"N280X-852834-D02") |
| 111 |
|
| 112 |
def test_check_system_health_pass(self): |
| 113 |
"""Validate check_system_health method.""" |
| 114 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 115 |
firmware = NetAppESeriesFirmware() |
| 116 |
with patch(self.REQUEST_FUNC, return_value=(200, {"successful": True})): |
| 117 |
firmware.check_system_health() |
| 118 |
|
| 119 |
def test_check_system_health_fail(self): |
| 120 |
"""Validate check_system_health method throws proper exceptions.""" |
| 121 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 122 |
firmware = NetAppESeriesFirmware() |
| 123 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 124 |
with self.assertRaisesRegex(AnsibleFailJson, "Health check failed!"): |
| 125 |
with patch(self.REQUEST_FUNC, return_value=(404, Exception())): |
| 126 |
firmware.check_system_health() |
| 127 |
|
| 128 |
def test_embedded_check_nvsram_compatibility_pass(self): |
| 129 |
"""Verify embedded nvsram compatibility.""" |
| 130 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 131 |
firmware = NetAppESeriesFirmware() |
| 132 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 133 |
with patch(self.REQUEST_FUNC, return_value=(200, {"signatureTestingPassed": True, |
| 134 |
"fileCompatible": True, |
| 135 |
"versionContents": [{"module": "nvsram", |
| 136 |
"bundledVersion": "N280X-842834-D02", |
| 137 |
"onboardVersion": "N280X-842834-D02"}]})): |
| 138 |
firmware.embedded_check_nvsram_compatibility() |
| 139 |
|
| 140 |
@unittest.skip("Test needs to be reworked.") |
| 141 |
def test_embedded_check_nvsram_compatibility_fail(self): |
| 142 |
"""Verify embedded nvsram compatibility fails with expected exceptions.""" |
| 143 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 144 |
firmware = NetAppESeriesFirmware() |
| 145 |
|
| 146 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 147 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve NVSRAM compatibility results."): |
| 148 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 149 |
firmware.embedded_check_nvsram_compatibility() |
| 150 |
|
| 151 |
with self.assertRaisesRegex(AnsibleFailJson, "Invalid NVSRAM file."): |
| 152 |
with patch(self.REQUEST_FUNC, return_value=(200, {"signatureTestingPassed": False, |
| 153 |
"fileCompatible": False, |
| 154 |
"versionContents": [{"module": "nvsram", |
| 155 |
"bundledVersion": "N280X-842834-D02", |
| 156 |
"onboardVersion": "N280X-842834-D02"}]})): |
| 157 |
firmware.embedded_check_nvsram_compatibility() |
| 158 |
|
| 159 |
with self.assertRaisesRegex(AnsibleFailJson, "Incompatible NVSRAM file."): |
| 160 |
with patch(self.REQUEST_FUNC, return_value=(200, {"signatureTestingPassed": True, |
| 161 |
"fileCompatible": False, |
| 162 |
"versionContents": [{"module": "nvsram", |
| 163 |
"bundledVersion": "N280X-842834-D02", |
| 164 |
"onboardVersion": "N280X-842834-D02"}]})): |
| 165 |
firmware.embedded_check_nvsram_compatibility() |
| 166 |
|
| 167 |
def test_embedded_check_firmware_compatibility_pass(self): |
| 168 |
"""Verify embedded firmware compatibility.""" |
| 169 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 170 |
firmware = NetAppESeriesFirmware() |
| 171 |
|
| 172 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 173 |
with patch(self.REQUEST_FUNC, return_value=(200, { |
| 174 |
"signatureTestingPassed": True, |
| 175 |
"fileCompatible": True, |
| 176 |
"versionContents": [ |
| 177 |
{"module": "bundle", "bundledVersion": "08.42.50.00.000", "onboardVersion": "08.42.30.05"}, |
| 178 |
{"module": "bundleDisplay", "bundledVersion": "11.40.5", "onboardVersion": "11.40.3R2"}, |
| 179 |
{"module": "hypervisor", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 180 |
{"module": "raid", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 181 |
{"module": "management", "bundledVersion": "11.42.0000.0028", "onboardVersion": "11.42.0000.0026"}, |
| 182 |
{"module": "iom", "bundledVersion": "11.42.0G00.0003", "onboardVersion": "11.42.0G00.0001"}]})): |
| 183 |
firmware.embedded_check_bundle_compatibility() |
| 184 |
|
| 185 |
@unittest.skip("Test needs to be reworked.") |
| 186 |
def test_embedded_check_firmware_compatibility_fail(self): |
| 187 |
"""Verify embedded firmware compatibility fails with expected exceptions.""" |
| 188 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 189 |
firmware = NetAppESeriesFirmware() |
| 190 |
|
| 191 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve bundle compatibility results."): |
| 192 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 193 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 194 |
firmware.embedded_check_bundle_compatibility() |
| 195 |
|
| 196 |
with self.assertRaisesRegex(AnsibleFailJson, "Invalid firmware bundle file."): |
| 197 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 198 |
with patch(self.REQUEST_FUNC, return_value=(200, { |
| 199 |
"signatureTestingPassed": False, |
| 200 |
"fileCompatible": True, |
| 201 |
"versionContents": [ |
| 202 |
{"module": "bundle", "bundledVersion": "08.42.50.00.000", "onboardVersion": "08.42.30.05"}, |
| 203 |
{"module": "bundleDisplay", "bundledVersion": "11.40.5", "onboardVersion": "11.40.3R2"}, |
| 204 |
{"module": "hypervisor", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 205 |
{"module": "raid", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 206 |
{"module": "management", "bundledVersion": "11.42.0000.0028", "onboardVersion": "11.42.0000.0026"}, |
| 207 |
{"module": "iom", "bundledVersion": "11.42.0G00.0003", "onboardVersion": "11.42.0G00.0001"}]})): |
| 208 |
firmware.embedded_check_bundle_compatibility() |
| 209 |
|
| 210 |
with self.assertRaisesRegex(AnsibleFailJson, "Incompatible firmware bundle file."): |
| 211 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 212 |
with patch(self.REQUEST_FUNC, return_value=(200, { |
| 213 |
"signatureTestingPassed": True, |
| 214 |
"fileCompatible": False, |
| 215 |
"versionContents": [ |
| 216 |
{"module": "bundle", "bundledVersion": "08.42.50.00.000", "onboardVersion": "08.42.30.05"}, |
| 217 |
{"module": "bundleDisplay", "bundledVersion": "11.40.5", "onboardVersion": "11.40.3R2"}, |
| 218 |
{"module": "hypervisor", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 219 |
{"module": "raid", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 220 |
{"module": "management", "bundledVersion": "11.42.0000.0028", "onboardVersion": "11.42.0000.0026"}, |
| 221 |
{"module": "iom", "bundledVersion": "11.42.0G00.0003", "onboardVersion": "11.42.0G00.0001"}]})): |
| 222 |
firmware.embedded_check_bundle_compatibility() |
| 223 |
|
| 224 |
with self.assertRaisesRegex(AnsibleFailJson, "Downgrades are not permitted."): |
| 225 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 226 |
with patch(self.REQUEST_FUNC, return_value=(200, { |
| 227 |
"signatureTestingPassed": True, |
| 228 |
"fileCompatible": True, |
| 229 |
"versionContents": [ |
| 230 |
{"module": "bundle", "bundledVersion": "08.42.00.00.000", "onboardVersion": "08.50.30.05"}, |
| 231 |
{"module": "bundleDisplay", "bundledVersion": "11.40.5", "onboardVersion": "11.40.3R2"}, |
| 232 |
{"module": "hypervisor", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 233 |
{"module": "raid", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 234 |
{"module": "management", "bundledVersion": "11.42.0000.0028", "onboardVersion": "11.42.0000.0026"}, |
| 235 |
{"module": "iom", "bundledVersion": "11.42.0G00.0003", "onboardVersion": "11.42.0G00.0001"}]})): |
| 236 |
firmware.embedded_check_bundle_compatibility() |
| 237 |
with self.assertRaisesRegex(AnsibleFailJson, "Downgrades are not permitted."): |
| 238 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): |
| 239 |
with patch(self.REQUEST_FUNC, return_value=(200, { |
| 240 |
"signatureTestingPassed": True, |
| 241 |
"fileCompatible": True, |
| 242 |
"versionContents": [ |
| 243 |
{"module": "bundle", "bundledVersion": "08.42.00.00.000", "onboardVersion": "09.20.30.05"}, |
| 244 |
{"module": "bundleDisplay", "bundledVersion": "11.40.5", "onboardVersion": "11.40.3R2"}, |
| 245 |
{"module": "hypervisor", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 246 |
{"module": "raid", "bundledVersion": "08.42.50.00", "onboardVersion": "08.42.30.05"}, |
| 247 |
{"module": "management", "bundledVersion": "11.42.0000.0028", "onboardVersion": "11.42.0000.0026"}, |
| 248 |
{"module": "iom", "bundledVersion": "11.42.0G00.0003", "onboardVersion": "11.42.0G00.0001"}]})): |
| 249 |
firmware.embedded_check_bundle_compatibility() |
| 250 |
|
| 251 |
def test_wait_for_web_services_pass(self): |
| 252 |
"""Verify controller reboot wait succeeds.""" |
| 253 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 254 |
firmware = NetAppESeriesFirmware() |
| 255 |
firmware.firmware_version = lambda: b"08.42.30.05" |
| 256 |
firmware.nvsram_version = lambda: b"N280X-842834-D02" |
| 257 |
firmware.is_firmware_bundled = lambda: False |
| 258 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 259 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.30.05"]), (200, ["N280X-842834-D02"]), (200, {"status": "optimal"})]): |
| 260 |
firmware.wait_for_web_services() |
| 261 |
|
| 262 |
@unittest.skip("Test needs to be reworked.") |
| 263 |
def test_wait_for_web_services_fail(self): |
| 264 |
"""Verify controller reboot wait throws expected exceptions""" |
| 265 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}): |
| 266 |
firmware = NetAppESeriesFirmware() |
| 267 |
with self.assertRaisesRegex(AnsibleFailJson, "Timeout waiting for Santricity Web Services."): |
| 268 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 269 |
with patch(self.BASE_REQUEST_FUNC, return_value=Exception()): |
| 270 |
firmware.wait_for_web_services() |
| 271 |
|
| 272 |
def test_check_nvsram_compatibility_pass(self): |
| 273 |
"""Verify proxy nvsram compatibility.""" |
| 274 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test_nvsram.dlp"}): |
| 275 |
firmware = NetAppESeriesFirmware() |
| 276 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 277 |
with patch(self.REQUEST_FUNC, side_effect=[(200, {"requestId": 1}), |
| 278 |
(200, {"checkRunning": True}), |
| 279 |
(200, {"checkRunning": False, |
| 280 |
"results": [{"nvsramFiles": [{"filename": "test_nvsram.dlp"}]}]})]): |
| 281 |
firmware.proxy_check_nvsram_compatibility() |
| 282 |
|
| 283 |
def test_check_nvsram_compatibility_fail(self): |
| 284 |
"""Verify proxy nvsram compatibility throws expected exceptions.""" |
| 285 |
with self._set_args({"firmware": "test.dlp", "nvsram": "test_nvsram.dlp"}): |
| 286 |
firmware = NetAppESeriesFirmware() |
| 287 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 288 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to receive NVSRAM compatibility information."): |
| 289 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 290 |
firmware.proxy_check_nvsram_compatibility() |
| 291 |
|
| 292 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve NVSRAM status update from proxy."): |
| 293 |
with patch(self.REQUEST_FUNC, side_effect=[(200, {"requestId": 1}), Exception()]): |
| 294 |
firmware.proxy_check_nvsram_compatibility() |
| 295 |
|
| 296 |
with self.assertRaisesRegex(AnsibleFailJson, "NVSRAM is not compatible."): |
| 297 |
with patch(self.REQUEST_FUNC, side_effect=[(200, {"requestId": 1}), |
| 298 |
(200, {"checkRunning": True}), |
| 299 |
(200, {"checkRunning": False, |
| 300 |
"results": [{"nvsramFiles": [{"filename": "not_test_nvsram.dlp"}]}]})]): |
| 301 |
firmware.proxy_check_nvsram_compatibility() |
| 302 |
|
| 303 |
def test_proxy_check_firmware_compatibility_pass(self): |
| 304 |
"""Verify proxy firmware compatibility.""" |
| 305 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 306 |
firmware = NetAppESeriesFirmware() |
| 307 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 308 |
with patch(self.REQUEST_FUNC, side_effect=[(200, {"requestId": 1}), |
| 309 |
(200, {"checkRunning": True}), |
| 310 |
(200, {"checkRunning": False, |
| 311 |
"results": [{"cfwFiles": [{"filename": "test_firmware.dlp"}]}]})]): |
| 312 |
firmware.proxy_check_firmware_compatibility() |
| 313 |
|
| 314 |
def test_proxy_check_firmware_compatibility_fail(self): |
| 315 |
"""Verify proxy firmware compatibility throws expected exceptions.""" |
| 316 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 317 |
firmware = NetAppESeriesFirmware() |
| 318 |
|
| 319 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 320 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to receive firmware compatibility information."): |
| 321 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 322 |
firmware.proxy_check_firmware_compatibility() |
| 323 |
|
| 324 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve firmware status update from proxy."): |
| 325 |
with patch(self.REQUEST_FUNC, side_effect=[(200, {"requestId": 1}), Exception()]): |
| 326 |
firmware.proxy_check_firmware_compatibility(retries=0) |
| 327 |
|
| 328 |
with self.assertRaisesRegex(AnsibleFailJson, "Firmware bundle is not compatible."): |
| 329 |
with patch( |
| 330 |
self.REQUEST_FUNC, |
| 331 |
side_effect=[ |
| 332 |
(200, {"requestId": 1}), |
| 333 |
(200, {"checkRunning": True}), |
| 334 |
(200, { |
| 335 |
"checkRunning": False, |
| 336 |
"results": [{"cfwFiles": [{"filename": "not_test_firmware.dlp"}]}] |
| 337 |
}) |
| 338 |
] |
| 339 |
): |
| 340 |
firmware.proxy_check_firmware_compatibility(retries=0) |
| 341 |
|
| 342 |
def test_proxy_upload_and_check_compatibility_pass(self): |
| 343 |
"""Verify proxy_upload_and_check_compatibility""" |
| 344 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 345 |
firmware = NetAppESeriesFirmware() |
| 346 |
firmware.proxy_check_nvsram_compatibility = lambda: None |
| 347 |
firmware.proxy_check_firmware_compatibility = lambda: None |
| 348 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("headers", "data")): |
| 349 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"version": "XX.XX.XX.XX", "filename": "test"}, |
| 350 |
{"version": "XXXXXXXXXX", "filename": "test.dlp"}]), |
| 351 |
(200, None), (200, None)]): |
| 352 |
firmware.proxy_upload_and_check_compatibility() |
| 353 |
|
| 354 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"version": "XX.XX.XX.XX", "filename": "test"}, |
| 355 |
{"version": "test_nvsram", "filename": "test_nvsram.dlp"}, |
| 356 |
{"version": "test", "filename": "test.dlp"}, |
| 357 |
{"filename": "test_firmware.dlp", "version": "test_firmware"}]), |
| 358 |
(200, None), (200, None)]): |
| 359 |
firmware.proxy_upload_and_check_compatibility() |
| 360 |
|
| 361 |
@unittest.skip("Test needs to be reworked.") |
| 362 |
def test_proxy_upload_and_check_compatibility_fail(self): |
| 363 |
"""Verify proxy_upload_and_check_compatibility throws expected exceptions.""" |
| 364 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 365 |
firmware = NetAppESeriesFirmware() |
| 366 |
firmware.proxy_check_nvsram_compatibility = lambda: None |
| 367 |
firmware.proxy_check_firmware_compatibility = lambda: None |
| 368 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve existing firmware files."): |
| 369 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("headers", "data")): |
| 370 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 371 |
firmware.proxy_upload_and_check_compatibility() |
| 372 |
|
| 373 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to upload NVSRAM file."): |
| 374 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("headers", "data")): |
| 375 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"version": "XX.XX.XX.XX", "filename": "test"}, |
| 376 |
{"version": "XXXXXXXXXX", "filename": "test.dlp"}, |
| 377 |
{"filename": "test_firmware.dlp", "version": "test_firmware"}]), |
| 378 |
Exception()]): |
| 379 |
firmware.proxy_upload_and_check_compatibility() |
| 380 |
|
| 381 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to upload firmware bundle file."): |
| 382 |
with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("headers", "data")): |
| 383 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"version": "XX.XX.XX.XX", "filename": "test"}, |
| 384 |
{"version": "test_nvsram", "filename": "test_nvsram.dlp"}, |
| 385 |
{"version": "XXXXXXXXXX", "filename": "test.dlp"}]), |
| 386 |
Exception()]): |
| 387 |
firmware.proxy_upload_and_check_compatibility() |
| 388 |
|
| 389 |
def test_proxy_check_upgrade_required_pass(self): |
| 390 |
"""Verify proxy_check_upgrade_required.""" |
| 391 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 392 |
firmware = NetAppESeriesFirmware() |
| 393 |
firmware.firmware_version = lambda: b"08.42.50.00" |
| 394 |
firmware.nvsram_version = lambda: b"nvsram_version" |
| 395 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"versionString": "08.42.50.00"}]), (200, ["nvsram_version"])]): |
| 396 |
firmware.is_firmware_bundled = lambda: True |
| 397 |
firmware.proxy_check_upgrade_required() |
| 398 |
self.assertFalse(firmware.upgrade_required) |
| 399 |
|
| 400 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.50.00"]), (200, ["nvsram_version"])]): |
| 401 |
firmware.is_firmware_bundled = lambda: False |
| 402 |
firmware.proxy_check_upgrade_required() |
| 403 |
self.assertFalse(firmware.upgrade_required) |
| 404 |
|
| 405 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 406 |
firmware = NetAppESeriesFirmware() |
| 407 |
firmware.firmware_version = lambda: b"08.42.50.00" |
| 408 |
firmware.nvsram_version = lambda: b"not_nvsram_version" |
| 409 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"versionString": "08.42.50.00"}]), (200, ["nvsram_version"])]): |
| 410 |
firmware.is_firmware_bundled = lambda: True |
| 411 |
firmware.proxy_check_upgrade_required() |
| 412 |
self.assertTrue(firmware.upgrade_required) |
| 413 |
|
| 414 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.50.00"]), (200, ["nvsram_version"])]): |
| 415 |
firmware.is_firmware_bundled = lambda: False |
| 416 |
firmware.proxy_check_upgrade_required() |
| 417 |
self.assertTrue(firmware.upgrade_required) |
| 418 |
|
| 419 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 420 |
firmware = NetAppESeriesFirmware() |
| 421 |
firmware.firmware_version = lambda: b"08.52.00.00" |
| 422 |
firmware.nvsram_version = lambda: b"nvsram_version" |
| 423 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"versionString": "08.42.50.00"}]), (200, ["nvsram_version"])]): |
| 424 |
firmware.is_firmware_bundled = lambda: True |
| 425 |
firmware.proxy_check_upgrade_required() |
| 426 |
self.assertTrue(firmware.upgrade_required) |
| 427 |
|
| 428 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.50.00"]), (200, ["nvsram_version"])]): |
| 429 |
firmware.is_firmware_bundled = lambda: False |
| 430 |
firmware.proxy_check_upgrade_required() |
| 431 |
self.assertTrue(firmware.upgrade_required) |
| 432 |
|
| 433 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 434 |
firmware = NetAppESeriesFirmware() |
| 435 |
firmware.firmware_version = lambda: b"08.52.00.00" |
| 436 |
firmware.nvsram_version = lambda: b"not_nvsram_version" |
| 437 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"versionString": "08.42.50.00"}]), (200, ["nvsram_version"])]): |
| 438 |
firmware.is_firmware_bundled = lambda: True |
| 439 |
firmware.proxy_check_upgrade_required() |
| 440 |
self.assertTrue(firmware.upgrade_required) |
| 441 |
|
| 442 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.50.00"]), (200, ["nvsram_version"])]): |
| 443 |
firmware.is_firmware_bundled = lambda: False |
| 444 |
firmware.proxy_check_upgrade_required() |
| 445 |
self.assertTrue(firmware.upgrade_required) |
| 446 |
|
| 447 |
@unittest.skip("Test needs to be reworked.") |
| 448 |
def test_proxy_check_upgrade_required_fail(self): |
| 449 |
"""Verify proxy_check_upgrade_required throws expected exceptions.""" |
| 450 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 451 |
firmware = NetAppESeriesFirmware() |
| 452 |
|
| 453 |
firmware.firmware_version = lambda: b"08.42.50.00" |
| 454 |
firmware.nvsram_version = lambda: b"not_nvsram_version" |
| 455 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve controller firmware information."): |
| 456 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 457 |
firmware.proxy_check_upgrade_required() |
| 458 |
|
| 459 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve storage system's NVSRAM version."): |
| 460 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"versionString": "08.42.50.00"}]), Exception()]): |
| 461 |
firmware.is_firmware_bundled = lambda: True |
| 462 |
firmware.proxy_check_upgrade_required() |
| 463 |
|
| 464 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve storage system's NVSRAM version."): |
| 465 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.50.00"]), Exception()]): |
| 466 |
firmware.is_firmware_bundled = lambda: False |
| 467 |
firmware.proxy_check_upgrade_required() |
| 468 |
|
| 469 |
with self.assertRaisesRegex(AnsibleFailJson, "Downgrades are not permitted."): |
| 470 |
with patch(self.REQUEST_FUNC, side_effect=[(200, [{"versionString": "08.42.50.00"}]), (200, ["nvsram_version"])]): |
| 471 |
firmware.firmware_version = lambda: b"08.40.00.00" |
| 472 |
firmware.nvsram_version = lambda: "nvsram_version" |
| 473 |
firmware.is_firmware_bundled = lambda: True |
| 474 |
firmware.proxy_check_upgrade_required() |
| 475 |
|
| 476 |
with self.assertRaisesRegex(AnsibleFailJson, "Downgrades are not permitted."): |
| 477 |
with patch(self.REQUEST_FUNC, side_effect=[(200, ["08.42.50.00"]), (200, ["nvsram_version"])]): |
| 478 |
firmware.is_firmware_bundled = lambda: False |
| 479 |
firmware.proxy_check_upgrade_required() |
| 480 |
|
| 481 |
def test_proxy_wait_for_upgrade_pass(self): |
| 482 |
"""Verify proxy_wait_for_upgrade.""" |
| 483 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 484 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "expected_nvsram.dlp"}): |
| 485 |
firmware = NetAppESeriesFirmware() |
| 486 |
|
| 487 |
with patch(self.REQUEST_FUNC, side_effect=[(200, {"running": True}), |
| 488 |
(200, {"running": False, "activationCompletionTime": "completion_time"})]): |
| 489 |
firmware.proxy_wait_for_upgrade() |
| 490 |
|
| 491 |
def test_proxy_wait_for_upgrade_fail(self): |
| 492 |
"""Verify proxy_wait_for_upgrade throws expected exceptions.""" |
| 493 |
with patch(self.SLEEP_FUNC, return_value=None): |
| 494 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 495 |
firmware = NetAppESeriesFirmware() |
| 496 |
|
| 497 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to complete upgrade."): |
| 498 |
with patch(self.REQUEST_FUNC, return_value=(200, {"running": False, "activationCompletionTime": None})): |
| 499 |
firmware.proxy_wait_for_upgrade() |
| 500 |
|
| 501 |
def test_proxy_upgrade_fail(self): |
| 502 |
"""Verify proxy_upgrade throws expected exceptions.""" |
| 503 |
with self._set_args({"firmware": "test_firmware.dlp", "nvsram": "test_nvsram.dlp"}): |
| 504 |
firmware = NetAppESeriesFirmware() |
| 505 |
|
| 506 |
firmware.is_firmware_bundled = lambda: True |
| 507 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to initiate firmware upgrade."): |
| 508 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 509 |
firmware.proxy_upgrade() |
| 510 |
|
| 511 |
firmware.is_firmware_bundled = lambda: False |
| 512 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to initiate firmware upgrade."): |
| 513 |
with patch(self.REQUEST_FUNC, return_value=Exception()): |
| 514 |
firmware.proxy_upgrade() |