Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
cover/

# Translations
*.mo
Expand Down
17 changes: 7 additions & 10 deletions common/pulp_python/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@

REPOSITORY_TYPE_ID = 'python_repository'
PACKAGE_TYPE_ID = 'python_package'
REPO_NOTE_PYTHON = 'PYTHON'

WEB_IMPORTER_TYPE_ID = 'python_web_importer'
WEB_DISTRIBUTOR_TYPE_ID = 'python_web_distributor'

CLI_WEB_DISTRIBUTOR_ID = 'python_web_distributor_name_cli'
IMPORTER_TYPE_ID = 'python_importer'
DISTRIBUTOR_TYPE_ID = 'python_distributor'

IMPORTER_CONFIG_KEY_BRANCHES = 'branches'
CLI_DISTRIBUTOR_ID = 'cli_python_distributor'

DISTRIBUTOR_CONFIG_FILE_NAME = 'server/plugins.conf.d/python_distributor.json'

# Config keys for the distributor plugin conf
CONFIG_KEY_PYTHON_PUBLISH_DIRECTORY = 'python_publish_directory'
CONFIG_VALUE_PYTHON_PUBLISH_DIRECTORY = '/var/lib/pulp/published/python'
CONFIG_KEY_PUBLISH_DIRECTORY = 'python_publish_directory'
CONFIG_VALUE_PUBLISH_DIRECTORY = '/var/lib/pulp/published/python'

# STEP_ID
PUBLISH_STEP_WEB_PUBLISHER = 'python_publish_step_web'
PUBLISH_STEP_PUBLISHER = 'python_publish_step'
PUBLISH_STEP_CONTENT = 'python_publish_content'
PUBLISH_STEP_METADATA = 'python_publish_metadata'
PUBLISH_STEP_OVER_HTTP = 'python_publish_over_http'
Empty file removed common/pulp_python/common/model.py
Empty file.
8 changes: 4 additions & 4 deletions extensions_admin/pulp_python/extensions/admin/cudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class CreatePythonRepositoryCommand(CreateAndConfigureRepositoryCommand, ImporterConfigMixin):
default_notes = {REPO_NOTE_TYPE_KEY: constants.REPO_NOTE_PYTHON}
IMPORTER_TYPE_ID = constants.WEB_IMPORTER_TYPE_ID
IMPORTER_TYPE_ID = constants.IMPORTER_TYPE_ID

def __init__(self, context):
CreateAndConfigureRepositoryCommand.__init__(self, context)
Expand All @@ -53,10 +53,10 @@ def _describe_distributors(self, user_input):
config = {}
auto_publish = user_input.get('auto-publish', True)
data = [
dict(distributor_type_id=constants.WEB_DISTRIBUTOR_TYPE_ID,
dict(distributor_type_id=constants.DISTRIBUTOR_TYPE_ID,
distributor_config=config,
auto_publish=auto_publish,
distributor_id=constants.CLI_WEB_DISTRIBUTOR_ID),
distributor_id=constants.CLI_DISTRIBUTOR_ID),
]

return data
Expand Down Expand Up @@ -104,7 +104,7 @@ def run(self, **kwargs):

if web_config:
kwargs['distributor_configs'] = {}
kwargs['distributor_configs'][constants.CLI_WEB_DISTRIBUTOR_ID] = web_config
kwargs['distributor_configs'][constants.CLI_DISTRIBUTOR_ID] = web_config

super(UpdatePythonRepositoryCommand, self).run(**kwargs)

Expand Down
27 changes: 12 additions & 15 deletions extensions_admin/pulp_python/extensions/admin/pulp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from pulp.client.extensions.decorator import priority

from pulp_python.common import constants
from pulp_python.extensions.admin.cudl import CreatePythonRepositoryCommand
from pulp_python.extensions.admin.cudl import UpdatePythonRepositoryCommand
from pulp_python.extensions.admin.cudl import ListPythonRepositoriesCommand
from pulp_python.extensions.admin.cudl import (
CreatePythonRepositoryCommand, UpdatePythonRepositoryCommand, ListPythonRepositoriesCommand)
from pulp_python.extensions.admin import upload


SECTION_ROOT = 'python'
Expand All @@ -31,12 +31,10 @@ def initialize(context):
:type context: pulp.client.extensions.core.ClientContext
"""
root_section = context.cli.create_section(SECTION_ROOT, DESC_ROOT)
repo_section = add_repo_section(context, root_section)
add_publish_section(context, repo_section)
add_sync_section(context, repo_section)
_add_repo_section(context, root_section)


def add_repo_section(context, parent_section):
def _add_repo_section(context, parent_section):
"""
add a repo section to the python section

Expand All @@ -53,10 +51,13 @@ def add_repo_section(context, parent_section):
repo_section.add_command(cudl.DeleteRepositoryCommand(context))
repo_section.add_command(ListPythonRepositoriesCommand(context))

return repo_section
_add_publish_section(context, repo_section)
_add_sync_section(context, repo_section)

repo_section.add_command(upload.UploadPackageCommand(context))

def add_publish_section(context, parent_section):

def _add_publish_section(context, parent_section):
"""
add a publish section to the repo section

Expand All @@ -71,14 +72,12 @@ def add_publish_section(context, parent_section):
section.add_command(
sync_publish.RunPublishRepositoryCommand(context,
renderer,
constants.CLI_WEB_DISTRIBUTOR_ID))
constants.CLI_DISTRIBUTOR_ID))
section.add_command(
sync_publish.PublishStatusCommand(context, renderer))

return section


def add_sync_section(context, parent_section):
def _add_sync_section(context, parent_section):
"""
add a sync section

Expand All @@ -94,5 +93,3 @@ def add_sync_section(context, parent_section):

sync_section = parent_section.create_subsection(SECTION_SYNC, DESC_SYNC)
sync_section.add_command(sync_publish.RunSyncRepositoryCommand(context, renderer))

return sync_section
35 changes: 35 additions & 0 deletions extensions_admin/pulp_python/extensions/admin/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pulp.client.commands.repo import upload

from pulp_python.common import constants


class UploadPackageCommand(upload.UploadCommand):
"""
The command used to upload Python packages.
"""
def determine_type_id(self, filename, **kwargs):
"""
Return pulp_python.common.constants.PACKAGE_TYPE_ID.

:param filename: Unused
:type filename: basestring
:param kwargs: Unused
:type kwargs: dict
:returns: pulp_python.common.constants.PACKAGE_TYPE_ID
:rtype: basestring
"""
return constants.PACKAGE_TYPE_ID

def generate_unit_key(self, *args, **kwargs):
"""
We don't need to generate the unit key client-side, but the superclass requires us to define
this method. It returns the empty dictionary.

:param args: Unused
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args that we don't use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 10/22/2014 04:18 PM, bmbouter wrote:

args that we don't use?

The Python server-side plugins were intentionally written to avoid
needing the client to pass any metadata, since the uploaded package
already has all the metadata in it. However, the CLI uploader method
signature will pass various things to us like that filename and perhaps
other things (see the superclass). In the CLI code we don't want or care
about any of these args because we are going to just return the empty
dictionary no matter what, but we have to accept the args because we are
going to get them from the CLI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

:type args: list
:param kwargs: Unused
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kwargs that we don't use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

:type kwargs: dict
:returns: An empty dictionary
:rtype: dict
"""
return {}
12 changes: 6 additions & 6 deletions extensions_admin/test/unit/admin/test_cudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def test_default_notes(self):
def test_importer_id(self):
# this value is required to be set, so just make sure it's correct
self.assertEqual(cudl.CreatePythonRepositoryCommand.IMPORTER_TYPE_ID,
constants.WEB_IMPORTER_TYPE_ID)
constants.IMPORTER_TYPE_ID)

def test_describe_distributors(self):
command = cudl.CreatePythonRepositoryCommand(Mock())
user_input = {}
result = command._describe_distributors(user_input)
target_result = {'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID,
'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID,
target_result = {'distributor_id': constants.CLI_DISTRIBUTOR_ID,
'distributor_type_id': constants.DISTRIBUTOR_TYPE_ID,
'distributor_config': {},
'auto_publish': True}
compare_dict(result[0], target_result)
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_repo_update_distributors(self):
self.command.run(**user_input)

repo_config = {}
dist_config = {constants.CLI_WEB_DISTRIBUTOR_ID: {'auto_publish': False}}
dist_config = {constants.CLI_DISTRIBUTOR_ID: {'auto_publish': False}}
self.context.server.repo.update.assert_called_once_with('foo-repo', repo_config,
None, dist_config)

Expand Down Expand Up @@ -121,7 +121,7 @@ def test_get_repositories(self):
{'config': {}}
],
'distributors': [
{'id': constants.CLI_WEB_DISTRIBUTOR_ID}
{'id': constants.CLI_DISTRIBUTOR_ID}
]
},
{'id': 'non-rpm-repo',
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_get_other_repositories(self):
'repo_id': 'matching',
'notes': {REPO_NOTE_TYPE_KEY: constants.REPO_NOTE_PYTHON, },
'distributors': [
{'id': constants.CLI_WEB_DISTRIBUTOR_ID}
{'id': constants.CLI_DISTRIBUTOR_ID}
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion extensions_admin/test/unit/admin/test_pulp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RunPublishRepositoryCommand, RunSyncRepositoryCommand
from pulp.client.extensions.core import PulpCli

from pulp_python.extensions.admin import pulp_cli
from pulp_python.extensions.admin import pulp_cli, upload


class TestInitialize(unittest.TestCase):
Expand All @@ -31,6 +31,7 @@ def test_structure(self):
self.assertTrue(isinstance(repo_section.commands['delete'], DeleteRepositoryCommand))
self.assertTrue(isinstance(repo_section.commands['update'], UpdateRepositoryCommand))
self.assertTrue(isinstance(repo_section.commands['list'], ListRepositoriesCommand))
self.assertTrue(isinstance(repo_section.commands['upload'], upload.UploadPackageCommand))

section = repo_section.subsections['sync']
self.assertTrue(isinstance(section.commands['run'], RunSyncRepositoryCommand))
Expand Down
35 changes: 35 additions & 0 deletions extensions_admin/test/unit/admin/test_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
This module contains tests for the pulp_python.extensions.admin.upload module.
"""
import unittest

import mock

from pulp_python.common import constants
from pulp_python.extensions.admin import upload


@mock.patch('pulp.client.upload.manager.UploadManager.init_with_defaults', mock.MagicMock())
class TestUploadPackageCommand(unittest.TestCase):
"""
This class contains tests for the UploadPackageCommand class.
"""
def test_determine_type_id(self):
"""
Assert that determine_type_id() returns the correct type.
"""
command = upload.UploadPackageCommand(mock.MagicMock())

type_id = command.determine_type_id('some_file_name', some='kwargs')

self.assertEqual(type_id, constants.PACKAGE_TYPE_ID)

def test_generate_unit_key(self):
"""
Assert that generate_unit_key() returns the empty dictionary.
"""
command = upload.UploadPackageCommand(mock.MagicMock())

key = command.generate_unit_key('some', 'args', and_some='kwargs')

self.assertEqual(key, {})
2 changes: 1 addition & 1 deletion plugins/pulp_python/plugins/distributors/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_root_publish_directory(config):
:return: The publish directory for the python plugin
:rtype: str
"""
return config.get(constants.CONFIG_KEY_PYTHON_PUBLISH_DIRECTORY)
return config.get(constants.CONFIG_KEY_PUBLISH_DIRECTORY)


def get_master_publish_dir(repo, config):
Expand Down
10 changes: 5 additions & 5 deletions plugins/pulp_python/plugins/distributors/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
logger = logging.getLogger(__name__)


class WebPublisher(PluginStep):
class PythonPublisher(PluginStep):
"""
Web publisher class that is responsible for the actual publishing
of a repository via a web server
Publisher class that is responsible for the actual publishing
of a repository via a web server.
"""
def __init__(self, repo, publish_conduit, config):
"""
Expand All @@ -25,8 +25,8 @@ def __init__(self, repo, publish_conduit, config):
:param config: Pulp configuration for the distributor
:type config: pulp.plugins.config.PluginCallConfiguration
"""
super(WebPublisher, self).__init__(constants.PUBLISH_STEP_WEB_PUBLISHER,
repo, publish_conduit, config)
super(PythonPublisher, self).__init__(constants.PUBLISH_STEP_PUBLISHER,
repo, publish_conduit, config)

publish_dir = configuration.get_web_publish_dir(repo, config)
os.makedirs(self.get_working_dir())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from pulp_python.common import constants
from pulp_python.plugins.distributors import configuration
from pulp_python.plugins.distributors.steps import WebPublisher
from pulp_python.plugins.distributors.steps import PythonPublisher


PLUGIN_DEFAULT_CONFIG = {
constants.CONFIG_KEY_PYTHON_PUBLISH_DIRECTORY: constants.CONFIG_VALUE_PYTHON_PUBLISH_DIRECTORY
constants.CONFIG_KEY_PUBLISH_DIRECTORY: constants.CONFIG_VALUE_PUBLISH_DIRECTORY
}

_logger = logging.getLogger(__name__)
Expand All @@ -30,10 +30,10 @@ def entry_point():

plugin_config.update(edited_config)

return WebDistributor, plugin_config
return PythonDistributor, plugin_config


class WebDistributor(Distributor):
class PythonDistributor(Distributor):

@classmethod
def metadata(cls):
Expand All @@ -51,16 +51,16 @@ def metadata(cls):
:rtype: dict
"""
return {
'id': constants.WEB_DISTRIBUTOR_TYPE_ID,
'display_name': _('Python Web Distributor'),
'types': [constants.REPOSITORY_TYPE_ID]
'id': constants.DISTRIBUTOR_TYPE_ID,
'display_name': _('Python Python Distributor'),
'types': [constants.PACKAGE_TYPE_ID]
}

def __init__(self):
"""
Initialize the WebDistributor.
Initialize the PythonDistributor.
"""
super(WebDistributor, self).__init__()
super(PythonDistributor, self).__init__()
self._publisher = None
self.canceled = False

Expand All @@ -86,7 +86,7 @@ def publish_repo(self, repo, publish_conduit, config):
:rtype: pulp.plugins.model.PublishReport
"""
_logger.debug('Publishing Python repository: %s' % repo.id)
self._publisher = WebPublisher(repo, publish_conduit, config)
self._publisher = PythonPublisher(repo, publish_conduit, config)
return self._publisher.process_lifecycle()

def cancel_publish_repo(self):
Expand Down
Loading