Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

988005 - uploads of units that are not RPMs work again #284

Merged
merged 1 commit into from Jul 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions plugins/pulp_rpm/plugins/importers/yum/upload.py
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand All @@ -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:
Expand Down
57 changes: 57 additions & 0 deletions 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)