Exemplo n.º 1
0
 def test_verify_image_checksum(self, open_mock):
     # | GIVEN |
     data = b'Yankee Doodle went to town riding on a pony;'
     file_like_object = six.BytesIO(data)
     open_mock().__enter__.return_value = file_like_object
     actual_hash = hashlib.md5(data).hexdigest()
     # | WHEN |
     ilo_common.verify_image_checksum(file_like_object, actual_hash)
Exemplo n.º 2
0
 def test_verify_image_checksum(self, open_mock):
     # | GIVEN |
     data = b'Yankee Doodle went to town riding on a pony;'
     file_like_object = six.BytesIO(data)
     open_mock().__enter__.return_value = file_like_object
     actual_hash = hashlib.md5(data).hexdigest()
     # | WHEN |
     ilo_common.verify_image_checksum(file_like_object, actual_hash)
Exemplo n.º 3
0
    def process_fw_on(self, node, expected_checksum):
        """Processes the firmware file from the url

        This is the template method which downloads the firmware file from
        url, verifies checksum and extracts the firmware and makes it ready
        for firmware update operation. ``_download_fw_to`` method is set in
        the firmware processor object creation factory method,
        ``get_fw_processor()``, based on the url type.
        :param node: a single Node.
        :param expected_checksum: checksum to be checked against.
        :returns: wrapper object of raw firmware image location
        :raises: IloOperationError, on failure to process firmware file.
        :raises: ImageDownloadFailed, on failure to download the original file.
        :raises: ImageRefValidationFailed, on failure to verify the checksum.
        :raises: SwiftOperationError, if upload to Swift fails.
        :raises: ImageUploadFailed, if upload to web server fails.
        """
        filename = os.path.basename(self.parsed_url.path)
        # create a temp directory where firmware file will be downloaded
        temp_dir = tempfile.mkdtemp()
        target_file = os.path.join(temp_dir, filename)

        # Note(deray): Operations performed in here:
        #
        #    1. Download the firmware file to the target file.
        #    2. Verify the checksum of the downloaded file.
        #    3. Extract the raw firmware file from its compact format
        #
        try:
            LOG.debug("For firmware update, downloading firmware file "
                      "%(src_file)s to: %(target_file)s ...",
                      {'src_file': self.parsed_url.geturl(),
                       'target_file': target_file})
            self._download_fw_to(target_file)
            LOG.debug("For firmware update, verifying checksum of file: "
                      "%(target_file)s ...", {'target_file': target_file})
            ilo_common.verify_image_checksum(target_file, expected_checksum)
            # Extracting raw firmware file from target_file ...
            fw_image_location_obj, is_different_file = (_extract_fw_from_file(
                node, target_file))
        except exception.IronicException:
            with excutils.save_and_reraise_exception():
                # delete the target file along with temp dir and
                # re-raise the exception
                shutil.rmtree(temp_dir, ignore_errors=True)

        # Note(deray): In case of raw (no need for extraction) firmware files,
        # the same firmware file is returned from the extract method.
        # Hence, don't blindly delete the firmware file which gets passed on
        # to extraction operation after successful extract. Check whether the
        # file is same or not and then go ahead deleting it.
        if is_different_file:
            # delete the entire downloaded content along with temp dir.
            shutil.rmtree(temp_dir, ignore_errors=True)

        LOG.info("Final processed firmware location: %s",
                 fw_image_location_obj.fw_image_location)
        return fw_image_location_obj
Exemplo n.º 4
0
    def process_fw_on(self, node, expected_checksum):
        """Processes the firmware file from the url

        This is the template method which downloads the firmware file from
        url, verifies checksum and extracts the firmware and makes it ready
        for firmware update operation. ``_download_fw_to`` method is set in
        the firmware processor object creation factory method,
        ``get_fw_processor()``, based on the url type.
        :param node: a single Node.
        :param expected_checksum: checksum to be checked against.
        :returns: wrapper object of raw firmware image location
        :raises: IloOperationError, on failure to process firmware file.
        :raises: ImageDownloadFailed, on failure to download the original file.
        :raises: ImageRefValidationFailed, on failure to verify the checksum.
        :raises: SwiftOperationError, if upload to Swift fails.
        :raises: ImageUploadFailed, if upload to web server fails.
        """
        filename = os.path.basename(self.parsed_url.path)
        # create a temp directory where firmware file will be downloaded
        temp_dir = tempfile.mkdtemp()
        target_file = os.path.join(temp_dir, filename)

        # Note(deray): Operations performed in here:
        #
        #    1. Download the firmware file to the target file.
        #    2. Verify the checksum of the downloaded file.
        #    3. Extract the raw firmware file from its compact format
        #
        try:
            LOG.debug("For firmware update, downloading firmware file "
                      "%(src_file)s to: %(target_file)s ...",
                      {'src_file': self.parsed_url.geturl(),
                       'target_file': target_file})
            self._download_fw_to(target_file)
            LOG.debug("For firmware update, verifying checksum of file: "
                      "%(target_file)s ...", {'target_file': target_file})
            ilo_common.verify_image_checksum(target_file, expected_checksum)
            # Extracting raw firmware file from target_file ...
            fw_image_location_obj, is_different_file = (_extract_fw_from_file(
                node, target_file))
        except exception.IronicException:
            with excutils.save_and_reraise_exception():
                # delete the target file along with temp dir and
                # re-raise the exception
                shutil.rmtree(temp_dir, ignore_errors=True)

        # Note(deray): In case of raw (no need for extraction) firmware files,
        # the same firmware file is returned from the extract method.
        # Hence, don't blindly delete the firmware file which gets passed on
        # to extraction operation after successful extract. Check whether the
        # file is same or not and then go ahead deleting it.
        if is_different_file:
            # delete the entire downloaded content along with temp dir.
            shutil.rmtree(temp_dir, ignore_errors=True)

        LOG.info(_LI("Final processed firmware location: %s"),
                 fw_image_location_obj.fw_image_location)
        return fw_image_location_obj