def test_proxy_check_upgrade_required_fail(self):
        """Verify proxy_check_upgrade_required throws expected exceptions."""
        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()

        firmware.firmware_version = lambda: b"08.42.50.00"
        firmware.nvsram_version = lambda: b"not_nvsram_version"
        with self.assertRaisesRegexp(
                AnsibleFailJson,
                "Failed to retrieve controller firmware information."):
            with patch(self.REQUEST_FUNC, return_value=Exception()):
                firmware.proxy_check_upgrade_required()

        with self.assertRaisesRegexp(
                AnsibleFailJson,
                "Failed to retrieve storage system's NVSRAM version."):
            with patch(self.REQUEST_FUNC,
                       side_effect=[(200, [{
                           "versionString": "08.42.50.00"
                       }]),
                                    Exception()]):
                firmware.is_firmware_bundled = lambda: True
                firmware.proxy_check_upgrade_required()

        with self.assertRaisesRegexp(
                AnsibleFailJson,
                "Failed to retrieve storage system's NVSRAM version."):
            with patch(self.REQUEST_FUNC,
                       side_effect=[(200, ["08.42.50.00"]),
                                    Exception()]):
                firmware.is_firmware_bundled = lambda: False
                firmware.proxy_check_upgrade_required()

        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Downgrades are not permitted."):
            with patch(self.REQUEST_FUNC,
                       side_effect=[(200, [{
                           "versionString": "08.42.50.00"
                       }]), (200, ["nvsram_version"])]):
                firmware.firmware_version = lambda: b"08.40.00.00"
                firmware.nvsram_version = lambda: "nvsram_version"
                firmware.is_firmware_bundled = lambda: True
                firmware.proxy_check_upgrade_required()

        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Downgrades are not permitted."):
            with patch(self.REQUEST_FUNC,
                       side_effect=[(200, ["08.42.50.00"]),
                                    (200, ["nvsram_version"])]):
                firmware.is_firmware_bundled = lambda: False
                firmware.proxy_check_upgrade_required()
    def test_proxy_check_upgrade_required_pass(self):
        """Verify proxy_check_upgrade_required."""
        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()

        firmware.firmware_version = lambda: b"08.42.50.00"
        firmware.nvsram_version = lambda: b"nvsram_version"
        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, [{
                       "versionString": "08.42.50.00"
                   }]), (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: True
            firmware.proxy_check_upgrade_required()
            self.assertFalse(firmware.upgrade_required)

        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, ["08.42.50.00"]),
                                (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: False
            firmware.proxy_check_upgrade_required()
            self.assertFalse(firmware.upgrade_required)

        firmware.firmware_version = lambda: b"08.42.50.00"
        firmware.nvsram_version = lambda: b"not_nvsram_version"
        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, [{
                       "versionString": "08.42.50.00"
                   }]), (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: True
            firmware.proxy_check_upgrade_required()
            self.assertTrue(firmware.upgrade_required)

        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, ["08.42.50.00"]),
                                (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: False
            firmware.proxy_check_upgrade_required()
            self.assertTrue(firmware.upgrade_required)

        firmware.firmware_version = lambda: b"08.52.00.00"
        firmware.nvsram_version = lambda: b"nvsram_version"
        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, [{
                       "versionString": "08.42.50.00"
                   }]), (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: True
            firmware.proxy_check_upgrade_required()
            self.assertTrue(firmware.upgrade_required)

        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, ["08.42.50.00"]),
                                (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: False
            firmware.proxy_check_upgrade_required()
            self.assertTrue(firmware.upgrade_required)

        firmware.firmware_version = lambda: b"08.52.00.00"
        firmware.nvsram_version = lambda: b"not_nvsram_version"
        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, [{
                       "versionString": "08.42.50.00"
                   }]), (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: True
            firmware.proxy_check_upgrade_required()
            self.assertTrue(firmware.upgrade_required)

        with patch(self.REQUEST_FUNC,
                   side_effect=[(200, ["08.42.50.00"]),
                                (200, ["nvsram_version"])]):
            firmware.is_firmware_bundled = lambda: False
            firmware.proxy_check_upgrade_required()
            self.assertTrue(firmware.upgrade_required)