From ab60e0444b9010d116d29b6f4d8cc331fdf62836 Mon Sep 17 00:00:00 2001 From: Michael Hrivnak Date: Thu, 25 Jul 2013 18:12:35 -0400 Subject: [PATCH] 988005 - uploads of units that are not RPMs work again --- .../pulp_rpm/plugins/importers/yum/upload.py | 13 ++++- plugins/test/unit/test_upload.py | 57 +++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 plugins/test/unit/test_upload.py diff --git a/plugins/pulp_rpm/plugins/importers/yum/upload.py b/plugins/pulp_rpm/plugins/importers/yum/upload.py index 3b03f7004..bc08c0c51 100644 --- a/plugins/pulp_rpm/plugins/importers/yum/upload.py +++ b/plugins/pulp_rpm/plugins/importers/yum/upload.py @@ -52,7 +52,7 @@ def upload(repo, type_id, unit_key, metadata, file_path, conduit, config): :type file_path: str :param conduit: provides access to relevant Pulp functionality - :type conduit: pulp.plugins.conduits.unit_add.UnitAddConduit + :type conduit: pulp.plugins.conduits.upload.UploadConduit :param config: plugin configuration for the repository :type config: pulp.plugins.config.PluginCallConfiguration @@ -80,14 +80,16 @@ def upload(repo, type_id, unit_key, metadata, file_path, conduit, config): relative_path = getattr(model, 'relative_path', '') # The provides and requires are not provided by the client, so extract them now - _update_provides_requires(model) + if isinstance(model, models.RPM): + _update_provides_requires(model) # both of the below operations perform IO try: # init unit unit = conduit.init_unit(model.TYPE, model.unit_key, model.metadata, relative_path) # copy file to destination - shutil.copy(file_path, unit.storage_path) + if file_path and unit.storage_path: + shutil.copy(file_path, unit.storage_path) except IOError: return _fail_report('failed to copy file to destination') @@ -106,6 +108,11 @@ def _update_provides_requires(model): """ Determines the provides and requires fields based on the RPM's XML snippet and updates the model instance. + + :param model: an RPM model to which providesand requires fields should be + added. The model's metadata must already include the + 'repodata' attribute. + :type model: pulp_rpm.common.models.RPM """ try: diff --git a/plugins/test/unit/test_upload.py b/plugins/test/unit/test_upload.py new file mode 100644 index 000000000..532d55e61 --- /dev/null +++ b/plugins/test/unit/test_upload.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# +# Copyright © 2013 Red Hat, Inc. +# +# This software is licensed to you under the GNU General Public +# License as published by the Free Software Foundation; either version +# 2 of the License (GPLv2) or (at your option) any later version. +# There is NO WARRANTY for this software, express or implied, +# including the implied warranties of MERCHANTABILITY, +# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should +# have received a copy of GPLv2 along with this software; if not, see +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + +import unittest + +import mock +from pulp.plugins.conduits.upload import UploadConduit +from pulp.plugins.config import PluginCallConfiguration +from pulp.plugins.model import Repository, SyncReport + +from pulp_rpm.common import models +from pulp_rpm.plugins.importers.yum import upload + + +class TestUploadGroup(unittest.TestCase): + def setUp(self): + self.repo = Repository('repo1') + self.conduit = UploadConduit(self.repo.id, 'yum_importer', 'user', 'me') + self.metadata = {'unit_metadata': { + 'mandatory_package_names': None, + 'name': 'pulp-test', + 'default': None, + 'display_order': 0, + 'description': 'test group', + 'user_visible': None, + 'translated_name': '', + 'translated_description': {}, + 'optional_package_names': None, + 'default_package_names': None, + 'langonly': None, + 'conditional_package_names': []} + } + + def test_upload(self): + self.conduit.init_unit = mock.MagicMock(spec_set=self.conduit.init_unit) + self.conduit.save_unit = mock.MagicMock(spec_set=self.conduit.save_unit) + unit_key = {'id': 'group1', 'repo_id': self.repo.id} + + report = upload.upload(self.repo, models.PackageGroup.TYPE, unit_key, + self.metadata, '', self.conduit, + PluginCallConfiguration({}, {})) + + self.conduit.init_unit.assert_called_once_with(models.PackageGroup.TYPE, + unit_key, self.metadata, '') + self.conduit.save_unit.assert_called_once_with(self.conduit.init_unit.return_value) + self.assertTrue(isinstance(report, SyncReport)) + self.assertTrue(report.success_flag)