Skip to content

Commit

Permalink
Configure pulp_sync plugin
Browse files Browse the repository at this point in the history
If we are using v1 we want to use pulp_push, otherwise we want
pulp_sync. Only one of those plugins should be enabled, not both.
  • Loading branch information
twaugh committed Oct 29, 2015
1 parent c6fee84 commit 7e57f88
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
8 changes: 8 additions & 0 deletions inputs/prod_inner.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@
"dockpulp_loglevel": "INFO"
}
},
{
"name": "pulp_sync",
"args": {
"pulp_registry_name": "{{PULP_REGISTRY_NAME}}",
"docker_registry": "{{DOCKER_REGISTRY}}",
"dockpulp_loglevel": "INFO"
}
},
{
"args": {
"image_id": "BUILT_IMAGE_ID"
Expand Down
74 changes: 59 additions & 15 deletions osbs/build/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,18 @@ def set_params(self, **kwargs):
def set_secret_for_plugin(self, plugin, secret):
if 'secrets' in self.template['spec']['strategy']['customStrategy']:
# origin 1.0.6 and newer
secret_path = os.path.join(SECRETS_PATH, secret)
logger.info("Configuring %s secret at %s", secret, secret_path)
custom = self.template['spec']['strategy']['customStrategy']
custom['secrets'].append({
'secretSource': {
'name': secret,
},
'mountPath': secret_path,
})
self.dj.dock_json_set_arg(*(plugin + (secret_path,)))
if self.dj.dock_json_has_plugin_conf(plugin[0], plugin[1]):
secret_path = os.path.join(SECRETS_PATH, secret)
logger.info("Configuring %s secret at %s", secret, secret_path)
custom = self.template['spec']['strategy']['customStrategy']
custom['secrets'].append({
'secretSource': {
'name': secret,
},
'mountPath': secret_path,
})
self.dj.dock_json_set_arg(*(plugin + (secret_path,)))

elif plugin[1] == 'pulp_push':
# setting pulp_push secret for origin 1.0.5 and earlier
# we only use this way to preserve backwards compat for pulp_push plugin,
Expand Down Expand Up @@ -389,7 +391,10 @@ def adjust_for_registry_api_versions(self):
except (KeyError, IndexError):
tag_and_push_registries = {}

if 'v1' not in versions:
if 'v1' in versions:
logger.info("removing v2-only plugin: pulp_sync")
self.dj.remove_plugin('postbuild_plugins', 'pulp_sync')
else:
# Remove v1-only plugins
for phase, name in [('postbuild_plugins', 'compress'),
('postbuild_plugins', 'cp_built_image_to_nfs'),
Expand All @@ -401,10 +406,6 @@ def adjust_for_registry_api_versions(self):
self.remove_tag_and_push_registries(tag_and_push_registries, 'v1')

if 'v2' not in versions:
# Remove v2-only plugins
logger.info("removing v2-only plugin: sync_pulp")
self.dj.remove_plugin('postbuild_plugins', 'sync_pulp')

# remove extra tag_and_push config
self.remove_tag_and_push_registries(tag_and_push_registries, 'v2')

Expand Down Expand Up @@ -591,6 +592,43 @@ def render_pulp_push(self):
# If no pulp registry is specified, don't run the pulp plugin
self.dj.remove_plugin("postbuild_plugins", "pulp_push")

def render_pulp_sync(self):
"""
If a pulp registry is specified, use the pulp plugin
"""
pulp_registry = self.spec.pulp_registry.value
docker_v2_registries = [registry
for registry in self.spec.registry_uris.value
if registry.version == 'v2']

if (self.dj.dock_json_has_plugin_conf('postbuild_plugins',
'pulp_sync') and
pulp_registry and
docker_v2_registries):
self.dj.dock_json_set_arg('postbuild_plugins', 'pulp_sync',
'pulp_registry_name', pulp_registry)

# First specified v2 registry is the one
# we'll tell pulp to sync from
docker_registry = docker_v2_registries[0].uri
logger.info("using docker v2 registry %s for pulp_sync",
docker_registry)

self.dj.dock_json_set_arg('postbuild_plugins', 'pulp_sync',
'docker_registry', docker_registry)

# Verify we have either a secret or username/password
if self.spec.pulp_secret.value is None:
conf = self.dj.dock_json_get_plugin_conf('postbuild_plugins',
'pulp_sync')
args = conf.get('args', {})
if 'username' not in args:
raise OsbsValidationException("Pulp registry specified "
"but no auth config")
else:
# If no pulp registry is specified, don't run the pulp plugin
self.dj.remove_plugin("postbuild_plugins", "pulp_sync")

def render_import_image(self, use_auth=None):
"""
Configure the import_image plugin
Expand Down Expand Up @@ -635,6 +673,11 @@ def render(self, validate=True):
'pulp_secret_path'):
self.spec.pulp_secret.value,

('postbuild_plugins',
'pulp_sync',
'pulp_secret_path'):
self.spec.pulp_secret.value,

('exit_plugins', 'sendmail', 'pdc_secret_path'):
self.spec.pdc_secret.value})

Expand All @@ -651,6 +694,7 @@ def render(self, validate=True):
self.render_cp_built_image_to_nfs()
self.render_import_image(use_auth=use_auth)
self.render_pulp_push()
self.render_pulp_sync()
self.render_koji_promote(use_auth=use_auth)
self.render_sendmail()

Expand Down
23 changes: 22 additions & 1 deletion tests/build/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def test_render_prod_request_with_repo(self):
get_plugin(plugins, "postbuild_plugins", "cp_built_image_to_nfs")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_push")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_sync")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "import_image")
with pytest.raises(NoSuchPluginException):
Expand Down Expand Up @@ -313,6 +315,8 @@ def test_render_prod_request(self):
get_plugin(plugins, "postbuild_plugins", "cp_built_image_to_nfs")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_push")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_sync")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "import_image")
with pytest.raises(NoSuchPluginException):
Expand Down Expand Up @@ -392,6 +396,8 @@ def test_render_prod_without_koji_request(self):
get_plugin(plugins, "postbuild_plugins", "cp_built_image_to_nfs")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_push")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_sync")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "import_image")
with pytest.raises(NoSuchPluginException):
Expand Down Expand Up @@ -456,6 +462,8 @@ def test_render_prod_with_secret_request(self):
get_plugin(plugins, "prebuild_plugins", "bump_release")
assert get_plugin(plugins, "prebuild_plugins", "koji")
assert get_plugin(plugins, "postbuild_plugins", "pulp_push")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_sync")
assert get_plugin(plugins, "postbuild_plugins", "cp_built_image_to_nfs")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "import_image")
Expand All @@ -472,6 +480,7 @@ def test_render_prod_request_v1_v2(self, registry_api_versions):
bm = BuildManager(INPUTS_PATH)
build_request = bm.get_build_request_by_type(PROD_WITH_SECRET_BUILD_TYPE)
name_label = "fedora/resultingimage"
pulp_env = 'dev'
kwargs = {
'git_uri': TEST_GIT_URI,
'git_ref': TEST_GIT_REF,
Expand All @@ -482,7 +491,7 @@ def test_render_prod_request_v1_v2(self, registry_api_versions):
'name_label': name_label,
'registry_uris': ["registry1.example.com/v1", # first is primary
"registry2.example.com/v2"],
'pulp_registry': "registry.example.com",
'pulp_registry': pulp_env,
'nfs_server_path': "server:path",
'source_registry_uri': "registry.example.com",
'openshift_uri': "http://openshift/",
Expand Down Expand Up @@ -538,6 +547,8 @@ def test_render_prod_request_v1_v2(self, registry_api_versions):
"cp_built_image_to_nfs")
assert get_plugin(plugins, "postbuild_plugins",
"pulp_push")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_sync")
else:
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins",
Expand All @@ -549,6 +560,14 @@ def test_render_prod_request_v1_v2(self, registry_api_versions):
get_plugin(plugins, "postbuild_plugins",
"pulp_push")

assert get_plugin(plugins, "postbuild_plugins", "pulp_sync")
assert plugin_value_get(plugins, "postbuild_plugins", "pulp_sync",
"args", "pulp_registry_name") == pulp_env
docker_registry = plugin_value_get(plugins, "postbuild_plugins",
"pulp_sync", "args",
"docker_registry")
assert docker_registry == 'registry2.example.com'

def test_render_with_yum_repourls(self):
bm = BuildManager(INPUTS_PATH)
kwargs = {
Expand Down Expand Up @@ -613,6 +632,8 @@ def test_render_with_yum_repourls(self):
get_plugin(plugins, "postbuild_plugins", "cp_built_image_to_nfs")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_push")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "pulp_sync")
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "import_image")
with pytest.raises(NoSuchPluginException):
Expand Down

0 comments on commit 7e57f88

Please sign in to comment.