def test_check_nvsram_compatibility_pass(self):
     """Verify proxy nvsram compatibility."""
     self._set_args({"firmware": "test.dlp", "nvsram": "test_nvsram.dlp"})
     firmware = NetAppESeriesFirmware()
     with patch(self.SLEEP_FUNC, return_value=None):
         with patch(self.REQUEST_FUNC,
                    side_effect=[(200, {
                        "requestId": 1
                    }), (200, {
                        "checkRunning": True
                    }),
                                 (200, {
                                     "checkRunning":
                                     False,
                                     "results": [{
                                         "nvsramFiles": [{
                                             "filename":
                                             "test_nvsram.dlp"
                                         }]
                                     }]
                                 })]):
             firmware.proxy_check_nvsram_compatibility()
    def test_proxy_upload_and_check_compatibility_fail(self):
        """Verify proxy_upload_and_check_compatibility throws expected exceptions."""
        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()
        firmware.proxy_check_nvsram_compatibility = lambda: None
        with self.assertRaisesRegexp(
                AnsibleFailJson,
                "Failed to retrieve existing existing firmware files."):
            with patch(self.CREATE_MULTIPART_FORMDATA_FUNC,
                       return_value=("headers", "data")):
                with patch(self.REQUEST_FUNC, return_value=Exception()):
                    firmware.proxy_upload_and_check_compatibility()

        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Failed to upload NVSRAM file."):
            with patch(self.CREATE_MULTIPART_FORMDATA_FUNC,
                       return_value=("headers", "data")):
                with patch(self.REQUEST_FUNC,
                           side_effect=[(200, [{
                               "version": "XX.XX.XX.XX",
                               "filename": "test"
                           }, {
                               "version": "XXXXXXXXXX",
                               "filename": "test.dlp"
                           }]),
                                        Exception()]):
                    firmware.proxy_upload_and_check_compatibility()

        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Failed to upload firmware bundle file."):
            with patch(self.CREATE_MULTIPART_FORMDATA_FUNC,
                       return_value=("headers", "data")):
                with patch(self.REQUEST_FUNC,
                           side_effect=[(200, [{
                               "version": "XX.XX.XX.XX",
                               "filename": "test"
                           }, {
                               "version": "XXXXXXXXXX",
                               "filename": "test.dlp"
                           }]), (200, None),
                                        Exception()]):
                    firmware.proxy_upload_and_check_compatibility()
    def test_proxy_upload_and_check_compatibility_pass(self):
        """Verify proxy_upload_and_check_compatibility"""
        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()
        firmware.proxy_check_nvsram_compatibility = lambda: None
        firmware.proxy_check_firmware_compatibility = lambda: None
        with patch(self.CREATE_MULTIPART_FORMDATA_FUNC,
                   return_value=("headers", "data")):
            with patch(self.REQUEST_FUNC,
                       side_effect=[(200, [{
                           "version": "XX.XX.XX.XX",
                           "filename": "test"
                       }, {
                           "version": "XXXXXXXXXX",
                           "filename": "test.dlp"
                       }]), (200, None), (200, None)]):
                firmware.proxy_upload_and_check_compatibility()

            with patch(self.REQUEST_FUNC,
                       return_value=(200, [{
                           "version": "XX.XX.XX.XX",
                           "filename": "test"
                       }, {
                           "version": "test_nvsram",
                           "filename": "test_nvsram.dlp"
                       }, {
                           "version": "test",
                           "filename": "test.dlp"
                       }, {
                           "filename": "test_firmware.dlp",
                           "version": "test_firmware"
                       }])):
                firmware.proxy_upload_and_check_compatibility()
    def test_check_nvsram_compatibility_fail(self):
        """Verify proxy nvsram compatibility throws expected exceptions."""
        self._set_args({"firmware": "test.dlp", "nvsram": "test_nvsram.dlp"})
        firmware = NetAppESeriesFirmware()
        with patch(self.SLEEP_FUNC, return_value=None):
            with self.assertRaisesRegexp(
                    AnsibleFailJson,
                    "Failed to receive NVSRAM compatibility information."):
                with patch(self.REQUEST_FUNC, return_value=Exception()):
                    firmware.proxy_check_nvsram_compatibility()

            with self.assertRaisesRegexp(
                    AnsibleFailJson,
                    "Failed to retrieve NVSRAM status update from proxy."):
                with patch(self.REQUEST_FUNC,
                           side_effect=[(200, {
                               "requestId": 1
                           }), Exception()]):
                    firmware.proxy_check_nvsram_compatibility()

            with self.assertRaisesRegexp(AnsibleFailJson,
                                         "NVSRAM is not compatible."):
                with patch(self.REQUEST_FUNC,
                           side_effect=[(200, {
                               "requestId": 1
                           }), (200, {
                               "checkRunning": True
                           }),
                                        (200, {
                                            "checkRunning":
                                            False,
                                            "results": [{
                                                "nvsramFiles": [{
                                                    "filename":
                                                    "not_test_nvsram.dlp"
                                                }]
                                            }]
                                        })]):
                    firmware.proxy_check_nvsram_compatibility()