Skip to content

Commit

Permalink
Ensure file objects are cleaned up on error
Browse files Browse the repository at this point in the history
Call save_and_import_content().

re #1457
https://pulp.plan.io/issues/1457
  • Loading branch information
pcreech committed Jan 15, 2016
1 parent 283b205 commit 6386379
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ def _import_modules(self, module_paths):
_logger.debug(IMPORT_MODULE, dict(mod=module_path))

module.set_storage_path(os.path.basename(module_path))
module.save()
module.import_content(module_path)
module.save_and_import_content(module_path)

repo_controller.associate_single_unit(self.repo.repo_obj, module)

Expand Down
3 changes: 1 addition & 2 deletions pulp_puppet_plugins/pulp_puppet/plugins/importers/forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ def _add_new_module(self, downloader, module):
# Create and save the Module
module = Module.from_metadata(metadata)
module.set_storage_path(os.path.basename(downloaded_filename))
module.save()
module.import_content(downloaded_filename)
module.save_and_import_content(downloaded_filename)

# Associate the module with the repo
repo_controller.associate_single_unit(self.repo.repo_obj, module)
Expand Down
3 changes: 1 addition & 2 deletions pulp_puppet_plugins/pulp_puppet/plugins/importers/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def handle_uploaded_unit(repo, type_id, unit_key, metadata, file_path, conduit):

uploaded_module = Module.from_metadata(extracted_data)
uploaded_module.set_storage_path(os.path.basename(new_file_path))
uploaded_module.save()
uploaded_module.import_content(new_file_path)
uploaded_module.save_and_import_content(new_file_path)

repo_controller.associate_single_unit(repo.repo_obj, uploaded_module)

Expand Down
4 changes: 2 additions & 2 deletions pulp_puppet_plugins/test/unit/plugins/importer/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_handle_uploaded_unit(self, mock_repo_controller, mock_module):
self.unit_metadata, self.source_file, self.conduit)

# Verify
mock_module.from_metadata.return_value.save.assert_called_once_with()
mock_module.from_metadata.return_value.save_and_import_content.assert_called_once()

self.assertTrue(isinstance(report, dict))
self.assertTrue('success_flag' in report)
Expand All @@ -72,7 +72,7 @@ def test_handle_uploaded_unit_with_no_data(self, mock_repo_controller, mock_modu
report = upload.handle_uploaded_unit(self.repo, constants.TYPE_PUPPET_MODULE, {},
{}, self.source_file, self.conduit)

mock_module.from_metadata.return_value.save.assert_called_once_with()
mock_module.from_metadata.return_value.save_and_import_content.assert_called_once()

self.assertTrue(report['success_flag'])

Expand Down

0 comments on commit 6386379

Please sign in to comment.