예제 #1
0
 def test_is_firmware_bundles_fail(self):
     """Verify non-firmware fails."""
     self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"})
     with patch(builtin_path,
                mock_open(read_data=b"xxxxxxxxxxxxxxxx")) as mock_file:
         firmware = NetAppESeriesFirmware()
         with self.assertRaisesRegexp(AnsibleFailJson,
                                      "Firmware file is invalid."):
             firmware.is_firmware_bundled()
예제 #2
0
    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()
예제 #3
0
    def test_is_firmware_bundled_pass(self):
        """Determine whether firmware file is bundled."""
        self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"})
        with patch(builtin_path,
                   mock_open(read_data=b"firmwarexxxxxxxx")) as mock_file:
            firmware = NetAppESeriesFirmware()
            self.assertEqual(firmware.is_firmware_bundled(), False)

        self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"})
        with patch(builtin_path,
                   mock_open(read_data=self.BUNDLE_HEADER[:16])) as mock_file:
            firmware = NetAppESeriesFirmware()
            self.assertEqual(firmware.is_firmware_bundled(), True)
예제 #4
0
 def test_firmware_version(self):
     """Verify correct firmware version is returned."""
     self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"})
     firmware = NetAppESeriesFirmware()
     firmware.is_firmware_bundled = lambda: True
     with patch(builtin_path,
                mock_open_with_iter(
                    read_data=self.BUNDLE_HEADER)) as mock_file:
         self.assertEqual(firmware.firmware_version(), b"11.40.5")
예제 #5
0
    def test_proxy_upgrade_fail(self):
        """Verify proxy_upgrade throws expected exceptions."""
        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()

        firmware.is_firmware_bundled = lambda: True
        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Failed to initiate firmware upgrade."):
            with patch(self.REQUEST_FUNC, return_value=Exception()):
                firmware.proxy_upgrade()

        firmware.is_firmware_bundled = lambda: False
        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Failed to initiate firmware upgrade."):
            with patch(self.REQUEST_FUNC, return_value=Exception()):
                firmware.proxy_upgrade()
예제 #6
0
 def test_wait_for_web_services_pass(self):
     """Verify controller reboot wait succeeds."""
     self._set_args({"firmware": "test.dlp", "nvsram": "test.dlp"})
     firmware = NetAppESeriesFirmware()
     firmware.firmware_version = lambda: b"08.42.30.05"
     firmware.nvsram_version = lambda: b"N280X-842834-D02"
     firmware.is_firmware_bundled = lambda: False
     with patch(self.SLEEP_FUNC, return_value=None):
         with patch(self.REQUEST_FUNC,
                    side_effect=[(200, ["08.42.30.05"]),
                                 (200, ["N280X-842834-D02"]),
                                 (200, {
                                     "status": "optimal"
                                 })]):
             firmware.wait_for_web_services()
예제 #7
0
    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)

        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 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)

        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()
        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)

        self._set_args({
            "firmware": "test_firmware.dlp",
            "nvsram": "test_nvsram.dlp"
        })
        firmware = NetAppESeriesFirmware()
        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)