Allow a user specific Copr remote SRPM URL.

By using a user specific URL, multiple members of the same team can
submit Copr releases without having to share credentials to the SRPM
remote location.  For example, each member of the team can set
COPR_REMOTE_LOCATION in .titorc to their <username>.fedorapeople.org
space.
This commit is contained in:
Alex Wood 2015-07-24 13:23:22 -04:00
parent 4138dbe33c
commit 3b99185216
5 changed files with 44 additions and 10 deletions

View file

@ -67,7 +67,8 @@ def read_user_config():
tokens = line.split("=")
if len(tokens) != 2:
raise Exception("Error parsing ~/.titorc: %s" % line)
config[tokens[0]] = tokens[1].strip()
# Remove whitespace from the values
config[tokens[0].strip()] = tokens[1].strip()
return config

View file

@ -13,14 +13,14 @@
import os.path
from tito.common import run_command, info_out
from tito.common import run_command, info_out, error_out
from tito.release import KojiReleaser
class CoprReleaser(KojiReleaser):
""" Releaser for Copr using copr-cli command """
REQUIRED_CONFIG = ['project_name', 'upload_command', 'remote_location']
REQUIRED_CONFIG = ['project_name', 'upload_command']
cli_tool = "copr-cli"
NAME = "Copr"
@ -28,6 +28,8 @@ class CoprReleaser(KojiReleaser):
config=None, user_config=None,
target=None, releaser_config=None, no_cleanup=False,
test=False, auto_accept=False, **kwargs):
self.user_config = user_config
KojiReleaser.__init__(self, name, tag, build_dir, config,
user_config, target, releaser_config, no_cleanup, test,
auto_accept, **kwargs)
@ -47,10 +49,24 @@ class CoprReleaser(KojiReleaser):
self.builder.config.add_section(self.copr_project_name)
KojiReleaser._koji_release(self)
def _check_releaser_config(self):
"""
Verify this release target has all the config options it needs.
"""
if self.releaser_config.has_option(self.target, "remote_location"):
self.remote_location = self.releaser_config.get(self.target, "remote_location")
elif 'COPR_REMOTE_LOCATION' in self.user_config:
self.remote_location = self.user_config['COPR_REMOTE_LOCATION']
else:
error_out(["No remote location for Copr SRPMs found.",
"Either define 'remote_location' in the releaser configuration "
"or 'COPR_REMOTE_LOCATION' in ~/.titorc"])
KojiReleaser._check_releaser_config(self)
def _submit_build(self, executable, koji_opts, tag, srpm_location):
""" Copy srpm to remote destination and submit it to Copr """
cmd = self.releaser_config.get(self.target, "upload_command")
url = self.releaser_config.get(self.target, "remote_location")
if self.srpm_submitted:
srpm_location = self.srpm_submitted
srpm_base_name = os.path.basename(srpm_location)
@ -58,7 +74,7 @@ class CoprReleaser(KojiReleaser):
# e.g. "scp %(srpm)s my.web.com:public_html/my_srpm/"
cmd_upload = cmd % {'srpm': srpm_location}
cmd_submit = "/usr/bin/copr-cli build %s %s%s" % (self.releaser_config.get(self.target, "project_name"),
url, srpm_base_name)
self.remote_location, srpm_base_name)
if self.dry_run:
self.print_dry_run_warning(cmd_upload)

View file

@ -23,7 +23,7 @@ from tempfile import mkdtemp
import shutil
from tito.common import create_builder, debug, \
run_command, get_project_name, warn_out
run_command, get_project_name, warn_out, error_out
from tito.compat import PY2, dictionary_override
from tito.exception import TitoException
from tito.config_object import ConfigObject
@ -115,13 +115,11 @@ class Releaser(ConfigObject):
"""
for opt in self.GLOBAL_REQUIRED_CONFIG:
if not self.releaser_config.has_option(self.target, opt):
raise TitoException(
"Release target '%s' missing required option '%s'" %
error_out("Release target '%s' missing required option '%s'" %
(self.target, opt))
for opt in self.REQUIRED_CONFIG:
if not self.releaser_config.has_option(self.target, opt):
raise TitoException(
"Release target '%s' missing required option '%s'" %
error_out("Release target '%s' missing required option '%s'" %
(self.target, opt))
# TODO: accomodate 'builder.*' for yum releaser and we can use this:

View file

@ -19,6 +19,7 @@ from functional.fixture import TitoGitTestFixture
from tito.compat import * # NOQA
from tito.release import CoprReleaser
from unit import Capture
PKG_NAME = "releaseme"
@ -61,3 +62,19 @@ class CoprReleaserTests(TitoGitTestFixture):
False, False, **{'offline': True})
releaser.release(dry_run=True)
self.assertTrue(releaser.srpm_submitted is not None)
def test_with_remote_defined_in_user_conf(self):
self.releaser_config.remove_option("test", "remote_location")
user_config = {'COPR_REMOTE_LOCATION': 'http://example.com/~otheruser/'}
releaser = CoprReleaser(PKG_NAME, None, '/tmp/tito/',
self.config, user_config, 'test', self.releaser_config, False,
False, False, **{'offline': True})
releaser.release(dry_run=True)
self.assertTrue(releaser.srpm_submitted is not None)
def test_no_remote_defined(self):
self.releaser_config.remove_option("test", "remote_location")
with Capture(silent=True):
self.assertRaises(SystemExit, CoprReleaser, PKG_NAME, None, '/tmp/tito/',
self.config, {}, 'test', self.releaser_config, False,
False, False, **{'offline': True})

View file

@ -58,6 +58,8 @@ The username to use when pushing the repository MEAD is going to build
from. If this value is unset, the MEAD releaser will default to using
the name of the current user.
COPR_REMOTE_LOCATION::
URL that Tito will push SRPMs to for Copr to use.
EXAMPLE
-------