Skip to content

Commit

Permalink
Add relative_url as a valid config key for export distributor
Browse files Browse the repository at this point in the history
  • Loading branch information
seandst committed Jan 11, 2016
1 parent 9086c10 commit 1d959a6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
3 changes: 2 additions & 1 deletion common/pulp_rpm/common/constants.py
Expand Up @@ -136,9 +136,10 @@
SKIP_KEYWORD = 'skip'
START_DATE_KEYWORD = 'start_date'
GENERATE_SQLITE_KEYWORD = 'generate_sqlite'
RELATIVE_URL_KEYWORD = 'relative_url'
EXPORT_OPTIONAL_CONFIG_KEYS = (END_DATE_KEYWORD, ISO_PREFIX_KEYWORD, SKIP_KEYWORD,
EXPORT_DIRECTORY_KEYWORD, START_DATE_KEYWORD, ISO_SIZE_KEYWORD,
GENERATE_SQLITE_KEYWORD, CREATE_PULP_MANIFEST)
GENERATE_SQLITE_KEYWORD, CREATE_PULP_MANIFEST, RELATIVE_URL_KEYWORD)

EXPORT_HTTP_DIR = '/var/lib/pulp/published/http/exports/repo'
EXPORT_HTTPS_DIR = '/var/lib/pulp/published/https/exports/repo'
Expand Down
5 changes: 5 additions & 0 deletions docs/tech-reference/export-distributor.rst
Expand Up @@ -62,6 +62,11 @@ Optional Configuration Parameters
ISO images and published over HTTP or HTTPS. Instead, they are written to the export directory.
This option is useful if exporting to an external hard drive, for example.

``relative_url``
Relative path at which the repository will be served when exported. If this option is specified with
``export_dir``, this will become the exported subdirectory name instead of the default, which is the
repository id.

``manifest``
If this boolean is True, a PULP_MANIFEST file will be created in the directory where ISOs are
created. This allows the ISO importer to directly import what was published. Defaults to False.
Expand Up @@ -110,6 +110,10 @@ def validate_export_config(config):
if not os.path.isabs(value):
msg = _("Value for 'export_dir' must be an absolute path: %s" % value)
return False, msg
if key == constants.RELATIVE_URL_KEYWORD:
if os.path.isabs(value):
msg = _("Value for '%s' must be be a relative path: %s" % (key, value))
return False, msg
if key == constants.CREATE_PULP_MANIFEST:
if not isinstance(value, bool):
return False, _('Value for "manifest" must be a boolean.')
Expand Down
20 changes: 15 additions & 5 deletions plugins/pulp_rpm/plugins/distributors/yum/configuration.py
Expand Up @@ -9,7 +9,7 @@

from pulp_rpm.common.constants import SCRATCHPAD_DEFAULT_METADATA_CHECKSUM, \
CONFIG_DEFAULT_CHECKSUM, CONFIG_KEY_CHECKSUM_TYPE, REPO_AUTH_CONFIG_FILE, \
PUBLISH_HTTP_KEYWORD, PUBLISH_HTTPS_KEYWORD
PUBLISH_HTTP_KEYWORD, PUBLISH_HTTPS_KEYWORD, RELATIVE_URL_KEYWORD
from pulp_rpm.common.ids import TYPE_ID_DISTRIBUTOR_YUM
from pulp.repoauth import protected_repo_utils, repo_cert_utils
from pulp_rpm.yum_plugin import util
Expand Down Expand Up @@ -222,10 +222,15 @@ def get_export_repo_publish_dirs(repo, config):
:rtype: list of str
"""
publish_dirs = []
if config.get(RELATIVE_URL_KEYWORD):
repo_path_base = config.get(RELATIVE_URL_KEYWORD)
else:
repo_path_base = repo.repo_id

if config.get(PUBLISH_HTTP_KEYWORD):
publish_dirs.append(os.path.join(HTTP_EXPORT_DIR, repo.repo_id))
publish_dirs.append(os.path.join(HTTP_EXPORT_DIR, repo_path_base))
if config.get(PUBLISH_HTTPS_KEYWORD):
publish_dirs.append(os.path.join(HTTPS_EXPORT_DIR, repo.repo_id))
publish_dirs.append(os.path.join(HTTPS_EXPORT_DIR, repo_path_base))

return publish_dirs

Expand All @@ -242,10 +247,15 @@ def get_export_repo_group_publish_dirs(repo, config):
:rtype: list of str
"""
publish_dirs = []
if config.get(RELATIVE_URL_KEYWORD):
repo_path_base = config.get(RELATIVE_URL_KEYWORD)
else:
repo_path_base = repo.id

if config.get(PUBLISH_HTTP_KEYWORD):
publish_dirs.append(os.path.join(HTTP_EXPORT_GROUP_DIR, repo.id))
publish_dirs.append(os.path.join(HTTP_EXPORT_GROUP_DIR, repo_path_base))
if config.get(PUBLISH_HTTPS_KEYWORD):
publish_dirs.append(os.path.join(HTTPS_EXPORT_GROUP_DIR, repo.id))
publish_dirs.append(os.path.join(HTTPS_EXPORT_GROUP_DIR, repo_path_base))

return publish_dirs

Expand Down
Expand Up @@ -68,6 +68,7 @@ def test_full_config(self):
self.repo_config[constants.EXPORT_DIRECTORY_KEYWORD] = '/path/to/dir'
self.repo_config[constants.START_DATE_KEYWORD] = '2013-07-18T11:22:00'
self.repo_config[constants.END_DATE_KEYWORD] = '2013-07-18T11:23:00'
self.repo_config[constants.RELATIVE_URL_KEYWORD] = 'relative/url'
self.repo_config[constants.CREATE_PULP_MANIFEST] = True

result, msg = export_utils.validate_export_config(
Expand Down Expand Up @@ -114,6 +115,11 @@ def test_bad_end_date(self):
result = export_utils.validate_export_config(PluginCallConfiguration({}, self.repo_config))
self.assertFalse(result[0])

def test_bad_relative_url(self):
self.repo_config[constants.RELATIVE_URL_KEYWORD] = '/absolute/path'
result = export_utils.validate_export_config(PluginCallConfiguration({}, self.repo_config))
self.assertFalse(result[0])

def test_non_absolute_path(self):
# Setup
self.repo_config[constants.EXPORT_DIRECTORY_KEYWORD] = 'non/absolute/path'
Expand Down Expand Up @@ -186,6 +192,11 @@ def test_none_https(self):
result = export_utils.validate_export_config(PluginCallConfiguration({}, self.repo_config))
self.assertFalse(result[0])

def test_none_relative_url(self):
self.repo_config[constants.RELATIVE_URL_KEYWORD] = None
result = export_utils.validate_export_config(PluginCallConfiguration({}, self.repo_config))
self.assertFalse(result[0])

def test_bad_manifest_flag(self):
self.repo_config[constants.CREATE_PULP_MANIFEST] = 'true'

Expand Down

0 comments on commit 1d959a6

Please sign in to comment.