def test_successive_calls_to_extract_method(
            self, shutil_mock, _get_firmware_file_in_new_path_mock,
            _extract_rpm_mock, _extract_scexe_mock, tempfile_mock,
            add_exec_permission_to_mock):
        """This is more of an integration test of the extract method

        """
        # | GIVEN |
        firmware_files = [
            self.any_scexe_file,
            'any_file.bin',
            self.any_rpm_file,
        ]
        actual_raw_fw_files = []
        expected_raw_fw_files = [('extracted_file_from_scexe', True),
                                 ('any_file.bin', False),
                                 ('extracted_file_from_rpm', True)]
        _get_firmware_file_in_new_path_mock.side_effect = [
            'extracted_file_from_scexe',
            'extracted_file_from_rpm',
        ]
        # | WHEN |
        for fw_file in firmware_files:
            fw_img_extractor = firmware_controller.get_fw_extractor(fw_file)
            raw_fw_file, is_extracted = fw_img_extractor.extract()
            actual_raw_fw_files.append((raw_fw_file, is_extracted))
        # | THEN |
        self.assertSequenceEqual(actual_raw_fw_files, expected_raw_fw_files)
    def test_successive_calls_to_extract_method(
            self, shutil_mock, _get_firmware_file_in_new_path_mock,
            _extract_rpm_mock, _extract_scexe_mock, tempfile_mock,
            add_exec_permission_to_mock):
        """This is more of an integration test of the extract method

        """
        # | GIVEN |
        firmware_files = [
            self.any_scexe_file,
            'any_file.bin',
            self.any_rpm_file,
        ]
        actual_raw_fw_files = []
        expected_raw_fw_files = [
            ('extracted_file_from_scexe', True),
            ('any_file.bin', False),
            ('extracted_file_from_rpm', True)
        ]
        _get_firmware_file_in_new_path_mock.side_effect = [
            'extracted_file_from_scexe',
            'extracted_file_from_rpm',
        ]
        # | WHEN |
        for fw_file in firmware_files:
            fw_img_extractor = firmware_controller.get_fw_extractor(fw_file)
            raw_fw_file, is_extracted = fw_img_extractor.extract()
            actual_raw_fw_files.append((raw_fw_file, is_extracted))
        # | THEN |
        self.assertSequenceEqual(actual_raw_fw_files, expected_raw_fw_files)
 def test_no_op_extract_gets_invoked_for_raw_firmware_file(
         self, any_raw_file):
     # no_op extract when fw_img_extractor is initialized
     # with raw firmware file
     # | WHEN |
     fw_img_extractor = firmware_controller.get_fw_extractor(any_raw_file)
     return_result, is_extracted = fw_img_extractor.extract()
     # | THEN |
     self.assertEqual(any_raw_file, return_result)
     self.assertFalse(is_extracted)
 def test_no_op_extract_gets_invoked_for_raw_firmware_file(self,
                                                           any_raw_file):
     # no_op extract when fw_img_extractor is initialized
     # with raw firmware file
     # | WHEN |
     fw_img_extractor = firmware_controller.get_fw_extractor(any_raw_file)
     return_result, is_extracted = fw_img_extractor.extract()
     # | THEN |
     self.assertEqual(any_raw_file, return_result)
     self.assertFalse(is_extracted)
 def test__extract_scexe_file_gets_invoked_for_scexe_firmware_file(
         self, _extract_scexe_file_mock):
     # _extract_scexe_file gets invoked when fw_img_extractor is initialized
     # with scexe firmware file
     # | WHEN |
     fw_img_extractor = (firmware_controller.get_fw_extractor(
         self.any_scexe_file))
     fw_img_extractor._do_extract('some_target_file', 'some_extract_path')
     # | THEN |
     _extract_scexe_file_mock.assert_called_once_with(
         fw_img_extractor, 'some_target_file', 'some_extract_path')
 def test_extract_method_raises_exception_if_raw_fw_file_not_found(
         self, shutil_mock, _get_firmware_file_in_new_path_mock,
         _extract_scexe_mock, os_mock, tempfile_mock,
         add_exec_permission_to_mock):
     # | GIVEN |
     os_mock.path.splitext.return_value = ('any_file', '.scexe')
     _get_firmware_file_in_new_path_mock.return_value = None
     fw_img_extractor = (firmware_controller.get_fw_extractor(
         self.any_scexe_file))
     # | WHEN | & | THEN |
     self.assertRaises(exception.InvalidInputError,
                       fw_img_extractor.extract)
    def test_extract_deletes_temp_extracted_folder_before_raising_exception(
            self, shutil_mock, _get_firmware_file_in_new_path_mock, os_mock,
            tempfile_mock, add_exec_permission_to_mock):
        # | GIVEN |
        os_mock.path.splitext.return_value = ('any_file', '.rpm')

        fw_img_extractor = (firmware_controller.get_fw_extractor(
            self.any_rpm_file))
        # Now mock the _do_extract method of fw_img_extractor instance
        exc = exception.ImageExtractionFailed(image_ref=self.any_rpm_file,
                                              reason='God only knows!')
        _do_extract_mock = mock.MagicMock(side_effect=exc)
        fw_img_extractor._do_extract = _do_extract_mock
        # | WHEN | & | THEN |
        self.assertRaises(exception.ImageExtractionFailed,
                          fw_img_extractor.extract)
        shutil_mock.rmtree.assert_called_once_with(
            tempfile_mock.mkdtemp.return_value, ignore_errors=True)
    def test_extract_method_calls__do_extract_in_turn(
            self, shutil_mock, _get_firmware_file_in_new_path_mock, os_mock,
            tempfile_mock, add_exec_permission_to_mock):
        # | GIVEN |
        os_mock.path.splitext.return_value = ('any_file', '.scexe')
        fw_img_extractor = (firmware_controller.get_fw_extractor(
            self.any_scexe_file))
        # Now mock the _do_extract method of fw_img_extractor instance
        _do_extract_mock = mock.MagicMock()
        fw_img_extractor._do_extract = _do_extract_mock

        expected_return_result = 'extracted_firmware_file'
        _get_firmware_file_in_new_path_mock.return_value = (
            expected_return_result)
        # | WHEN |
        actual_return_result, is_extracted = fw_img_extractor.extract()
        # | THEN |
        _do_extract_mock.assert_called_once_with(self.any_scexe_file, mock.ANY)
        self.assertEqual(expected_return_result, actual_return_result)
Exemplo n.º 9
0
def process_firmware_image(compact_firmware_file, ilo_object):
    """Processes the firmware file.

    Processing the firmware file entails extracting the firmware file from its
    compact format. Along with the raw (extracted) firmware file, this method
    also sends out information of whether or not the extracted firmware file
        a) needs to be uploaded to http store
        b) is extracted in reality or the file was already in raw format
    :param compact_firmware_file: firmware file to extract from
    :param ilo_object: ilo client object (ribcl/ris object)
    :raises: InvalidInputError, for unsupported file types or raw firmware
             file not found from compact format.
    :raises: ImageExtractionFailed, for extraction related issues
    :returns: core(raw) firmware file
    :returns: to_upload, boolean to indicate whether to upload or not
    :returns: is_extracted, boolean to indicate firmware image is actually
              extracted or not.
    """
    fw_img_extractor = firmware_controller.get_fw_extractor(
        compact_firmware_file)
    LOG.debug('Extracting firmware file: %s ...', compact_firmware_file)
    raw_fw_file_path, is_extracted = fw_img_extractor.extract()

    # Note(deray): Need to check if this processing is for RIS or RIBCL
    # based systems. For Gen9 machines (RIS based) the firmware file needs
    # to be on a http store, and hence requires the upload to happen for the
    # firmware file.
    to_upload = False
    m = re.search('Gen(\d+)', ilo_object.model)
    if int(m.group(1)) > 8:
        to_upload = True

    LOG.debug('Extracting firmware file: %s ... done', compact_firmware_file)
    msg = ('Firmware file %(fw_file)s is %(msg)s. Need hosting (on an http '
           'store): %(yes_or_no)s' %
           {'fw_file': compact_firmware_file,
            'msg': ('extracted. Extracted file: %s' % raw_fw_file_path
                    if is_extracted else 'already in raw format'),
            'yes_or_no': 'Yes' if to_upload else 'No'})
    LOG.info(msg)
    return raw_fw_file_path, to_upload, is_extracted
Exemplo n.º 10
0
def process_firmware_image(compact_firmware_file, ilo_object):
    """Processes the firmware file.

    Processing the firmware file entails extracting the firmware file from its
    compact format. Along with the raw (extracted) firmware file, this method
    also sends out information of whether or not the extracted firmware file
        a) needs to be uploaded to http store
        b) is extracted in reality or the file was already in raw format
    :param compact_firmware_file: firmware file to extract from
    :param ilo_object: ilo client object (ribcl/ris object)
    :raises: InvalidInputError, for unsupported file types or raw firmware
             file not found from compact format.
    :raises: ImageExtractionFailed, for extraction related issues
    :returns: core(raw) firmware file
    :returns: to_upload, boolean to indicate whether to upload or not
    :returns: is_extracted, boolean to indicate firmware image is actually
              extracted or not.
    """
    fw_img_extractor = firmware_controller.get_fw_extractor(
        compact_firmware_file)
    LOG.debug('Extracting firmware file: %s ...', compact_firmware_file)
    raw_fw_file_path, is_extracted = fw_img_extractor.extract()

    # Note(deray): Need to check if this processing is for RIS or RIBCL
    # based systems. For Gen9 machines (RIS based) the firmware file needs
    # to be on a http store, and hence requires the upload to happen for the
    # firmware file.
    to_upload = False
    if 'Gen9' in ilo_object.model:
        to_upload = True

    LOG.debug('Extracting firmware file: %s ... done', compact_firmware_file)
    msg = ('Firmware file %(fw_file)s is %(msg)s. Need hosting (on an http '
           'store): %(yes_or_no)s' %
           {'fw_file': compact_firmware_file,
            'msg': ('extracted. Extracted file: %s' % raw_fw_file_path
                    if is_extracted else 'already in raw format'),
            'yes_or_no': 'Yes' if to_upload else 'No'})
    LOG.info(msg)
    return raw_fw_file_path, to_upload, is_extracted
 def test_get_fw_extractor_will_set_the_fw_file_attribute(self):
     # | WHEN |
     fw_img_extractor = (firmware_controller.get_fw_extractor(
         self.any_scexe_file))
     # | THEN |
     self.assertEqual(self.any_scexe_file, fw_img_extractor.fw_file)