def test_process_fw_on_calls__extract_fw_from_file( self, _extract_fw_from_file_mock, verify_checksum_mock, shutil_mock, os_mock, tempfile_mock): # | GIVEN | fw_processor = ilo_fw_processor.FirmwareProcessor(self.any_url) # Now mock the __download_fw_to method of fw_processor instance _download_fw_to_mock = mock.MagicMock() fw_processor._download_fw_to = _download_fw_to_mock expected_return_location = (ilo_fw_processor.FirmwareImageLocation( 'some_location/file', 'file')) _extract_fw_from_file_mock.return_value = (expected_return_location, True) node_mock = mock.ANY checksum_fake = mock.ANY # | WHEN | actual_return_location = fw_processor.process_fw_on(node_mock, checksum_fake) # | THEN | _extract_fw_from_file_mock.assert_called_once_with( node_mock, os_mock.path.join.return_value) self.assertEqual(expected_return_location.fw_image_location, actual_return_location.fw_image_location) self.assertEqual(expected_return_location.fw_image_filename, actual_return_location.fw_image_filename) shutil_mock.rmtree.assert_called_once_with( tempfile_mock.mkdtemp(), ignore_errors=True)
def test__download_swift_based_fw_to_gets_invoked_for_swift_based_firmware( self, _download_swift_based_fw_to_mock): # | GIVEN | some_swift_url = 'swift://containername/objectname' # | WHEN | fw_processor = ilo_fw_processor.FirmwareProcessor(some_swift_url) fw_processor._download_fw_to('some_target_file') # | THEN | _download_swift_based_fw_to_mock.assert_called_once_with( fw_processor, 'some_target_file')
def test__download_file_based_fw_to_gets_invoked_for_file_based_firmware( self, _download_file_based_fw_to_mock): # | GIVEN | some_file_url = 'file:///some_location/some_firmware_file' # | WHEN | fw_processor = ilo_fw_processor.FirmwareProcessor(some_file_url) fw_processor._download_fw_to('some_target_file') # | THEN | _download_file_based_fw_to_mock.assert_called_once_with( fw_processor, 'some_target_file')
def test__download_http_based_fw_to_gets_invoked_for_http_based_firmware( self, _download_http_based_fw_to_mock): # | GIVEN | for some_http_url in ('http://netloc/path_to_firmware_file', 'https://netloc/path_to_firmware_file'): # | WHEN | fw_processor = ilo_fw_processor.FirmwareProcessor(some_http_url) fw_processor._download_fw_to('some_target_file') # | THEN | _download_http_based_fw_to_mock.assert_called_once_with( fw_processor, 'some_target_file') _download_http_based_fw_to_mock.reset_mock()
def test_process_fw_on_throws_error_if_checksum_validation_fails( self, verify_checksum_mock, shutil_mock, os_mock, tempfile_mock): # | GIVEN | fw_processor = ilo_fw_processor.FirmwareProcessor(self.any_url) # Now mock the __download_fw_to method of fw_processor instance _download_fw_to_mock = mock.MagicMock() fw_processor._download_fw_to = _download_fw_to_mock verify_checksum_mock.side_effect = exception.ImageRefValidationFailed( image_href='some image', reason='checksum verification failed') node_mock = mock.ANY checksum_fake = mock.ANY # | WHEN | & | THEN | self.assertRaises(exception.ImageRefValidationFailed, fw_processor.process_fw_on, node_mock, checksum_fake) shutil_mock.rmtree.assert_called_once_with(tempfile_mock.mkdtemp(), ignore_errors=True)
def update_firmware(self, task, **kwargs): """Updates the firmware. :param task: a TaskManager object. :raises: InvalidParameterValue if update firmware mode is not 'ilo'. Even applicable for invalid input cases. :raises: NodeCleaningFailure, on failure to execute step. """ node = task.node fw_location_objs_n_components = [] firmware_images = kwargs['firmware_images'] # Note(deray): Processing of firmware images happens here. As part # of processing checksum validation is also done for the firmware file. # Processing of firmware file essentially means downloading the file # on the conductor, validating the checksum of the downloaded content, # extracting the raw firmware file from its compact format, if it is, # and hosting the file on a web server or a swift store based on the # need of the baremetal server iLO firmware update method. try: for firmware_image_info in firmware_images: url, checksum, component = ( firmware_processor.get_and_validate_firmware_image_info( firmware_image_info, kwargs['firmware_update_mode'])) LOG.debug( "Processing of firmware file: %(firmware_file)s on " "node: %(node)s ... in progress", { 'firmware_file': url, 'node': node.uuid }) fw_processor = firmware_processor.FirmwareProcessor(url) fw_location_obj = fw_processor.process_fw_on(node, checksum) fw_location_objs_n_components.append( (fw_location_obj, component)) LOG.debug( "Processing of firmware file: %(firmware_file)s on " "node: %(node)s ... done", { 'firmware_file': url, 'node': node.uuid }) except exception.IronicException as ilo_exc: # delete all the files extracted so far from the extracted list # and re-raise the exception for fw_loc_obj_n_comp_tup in fw_location_objs_n_components: fw_loc_obj_n_comp_tup[0].remove() LOG.error( "Processing of firmware image: %(firmware_image)s " "on node: %(node)s ... failed", { 'firmware_image': firmware_image_info, 'node': node.uuid }) raise exception.NodeCleaningFailure(node=node.uuid, reason=ilo_exc) # Updating of firmware images happen here. try: for fw_location_obj, component in fw_location_objs_n_components: fw_location = fw_location_obj.fw_image_location LOG.debug( "Firmware update for %(firmware_file)s on " "node: %(node)s ... in progress", { 'firmware_file': fw_location, 'node': node.uuid }) _execute_ilo_clean_step(node, 'update_firmware', fw_location, component) LOG.debug( "Firmware update for %(firmware_file)s on " "node: %(node)s ... done", { 'firmware_file': fw_location, 'node': node.uuid }) except exception.NodeCleaningFailure: with excutils.save_and_reraise_exception(): LOG.error( "Firmware update for %(firmware_file)s on " "node: %(node)s failed.", { 'firmware_file': fw_location, 'node': node.uuid }) finally: for fw_loc_obj_n_comp_tup in fw_location_objs_n_components: fw_loc_obj_n_comp_tup[0].remove() LOG.info( "All Firmware update operations completed successfully " "for node: %s.", node.uuid)
def test_fw_processor_ctor_sets_parsed_url_attrib_of_fw_processor(self): # | WHEN | fw_processor = ilo_fw_processor.FirmwareProcessor(self.any_url) # | THEN | self.assertEqual(self.any_url, fw_processor.parsed_url.geturl())