def test_embedded_upgrade_fail(self): """Verify embedded upgrade throws expected exception.""" self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}) firmware = NetAppESeriesFirmware() with self.assertRaisesRegexp( AnsibleFailJson, "Failed to upload and activate firmware."): with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): with patch(self.REQUEST_FUNC, return_value=Exception()): firmware.embedded_upgrade()
def test_embedded_upgrade_pass(self): """Verify embedded upgrade function.""" with patch(self.CREATE_MULTIPART_FORMDATA_FUNC, return_value=("", {})): with patch(self.SLEEP_FUNC, return_value=None): self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"}) firmware = NetAppESeriesFirmware() with patch(self.REQUEST_FUNC, return_value=(200, "")): with patch( self.BASE_REQUEST_FUNC, side_effect=[Exception(), Exception(), (200, "")]): firmware.embedded_upgrade() self.assertTrue(firmware.upgrade_in_progress) self._set_args({ "firmware": "test.dlp", "nvsram": "test.dlp", "wait_for_completion": True }) firmware = NetAppESeriesFirmware() firmware.firmware_version = lambda: b"11.40.3R2" firmware.nvsram_version = lambda: b"N280X-842834-D02" with patch(self.REQUEST_FUNC, return_value=(200, [{ "fwVersion": "08.42.30.05", "nvsramVersion": "N280X-842834-D02", "extendedSAData": { "codeVersions": [{ "codeModule": "bundleDisplay", "versionString": "11.40.3R2" }] } }])): firmware.embedded_upgrade() self.assertFalse(firmware.upgrade_in_progress)