mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-03 10:48:03 +08:00
Merge #124 Fix #117,#51 - Add rida.builder.Builder.tag_to_repo method to get the URL to repository based on a tag name. Also create target when creating build target to ensure this repo is generated for Koji builder.
This commit is contained in:
@@ -225,6 +225,19 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def tag_to_repo(self, config, tag_name, arch):
|
||||
"""
|
||||
:param config: instance of rida.config.Config
|
||||
:param tag_name: Tag for which the repository is returned
|
||||
:param arch: Architecture for which the repository is returned
|
||||
|
||||
Returns URL of repository containing the built artifacts for
|
||||
the tag with particular name and architecture.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
class Builder(object):
|
||||
"""Wrapper class"""
|
||||
|
||||
@@ -251,6 +264,22 @@ class Builder(object):
|
||||
else:
|
||||
raise ValueError("Builder backend='%s' not recognized" % backend)
|
||||
|
||||
@classmethod
|
||||
def tag_to_repo(cls, backend, config, tag_name, arch):
|
||||
"""
|
||||
:param backend: a string representing the backend e.g. 'koji'.
|
||||
:param config: instance of rida.config.Config
|
||||
:param tag_name: Tag for which the repository is returned
|
||||
:param arch: Architecture for which the repository is returned
|
||||
|
||||
Returns URL of repository containing the built artifacts for
|
||||
the tag with particular name and architecture.
|
||||
"""
|
||||
if backend == "koji":
|
||||
return KojiModuleBuilder.tag_to_repo(config, tag_name, arch)
|
||||
else:
|
||||
raise ValueError("Builder backend='%s' not recognized" % backend)
|
||||
|
||||
|
||||
class KojiModuleBuilder(GenericBuilder):
|
||||
""" Koji specific builder class """
|
||||
@@ -431,7 +460,16 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
|
||||
)
|
||||
add_groups()
|
||||
|
||||
self.module_target = self._koji_add_target(self.tag_name, self.module_build_tag, self.module_tag)
|
||||
# Add main build target.
|
||||
self.module_target = self._koji_add_target(self.tag_name,
|
||||
self.module_build_tag,
|
||||
self.module_tag)
|
||||
|
||||
# Add -repo target, so Kojira creates RPM repository with built
|
||||
# module for us.
|
||||
self._koji_add_target(self.tag_name + "-repo", self.module_tag,
|
||||
self.module_tag)
|
||||
|
||||
self.__prep = True
|
||||
log.info("%r buildroot sucessfully connected." % self)
|
||||
|
||||
@@ -480,7 +518,6 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
|
||||
|
||||
return get_result()
|
||||
|
||||
|
||||
def _get_task_by_artifact(self, artifact_name):
|
||||
"""
|
||||
:param artifact_name: e.g. bash
|
||||
@@ -552,6 +589,18 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
|
||||
source, task_id, self))
|
||||
return task_id
|
||||
|
||||
@classmethod
|
||||
def tag_to_repo(cls, config, tag_name, arch):
|
||||
"""
|
||||
:param config: instance of rida.config.Config
|
||||
:param tag_name: Tag for which the repository is returned
|
||||
:param arch: Architecture for which the repository is returned
|
||||
|
||||
Returns URL of repository containing the built artifacts for
|
||||
the tag with particular name and architecture.
|
||||
"""
|
||||
return "%s/%s/latest/%s" % (config.koji_repository_url, tag_name, arch)
|
||||
|
||||
def _get_tag(self, tag, strict=True):
|
||||
if isinstance(tag, dict):
|
||||
tag = tag['name']
|
||||
|
||||
@@ -60,6 +60,7 @@ class Config(object):
|
||||
self._koji_config = None
|
||||
self._koji_profile = None
|
||||
self._koji_arches = None
|
||||
self._koji_repository_url = None
|
||||
self._rpms_default_repository = ""
|
||||
self._rpms_allow_repository = False
|
||||
self._rpms_default_cache = ""
|
||||
@@ -232,6 +233,14 @@ class Config(object):
|
||||
def koji_arches(self, s):
|
||||
self._koji_arches = list(s)
|
||||
|
||||
@property
|
||||
def koji_repository_url(self):
|
||||
return self._koji_repository_url
|
||||
|
||||
@koji_repository_url.setter
|
||||
def koji_repository_url(self, s):
|
||||
self._koji_repository_url = str(s)
|
||||
|
||||
@property
|
||||
def scmurls(self):
|
||||
"""Allowed SCM URLs."""
|
||||
|
||||
47
tests/test_builder/test_koji.py
Normal file
47
tests/test_builder/test_koji.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Copyright (c) 2016 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Jan Kaluza <jkaluza@redhat.com>
|
||||
|
||||
import unittest
|
||||
import mock
|
||||
|
||||
import rida.messaging
|
||||
import rida.scheduler.handlers.repos
|
||||
import rida.models
|
||||
import rida.builder
|
||||
|
||||
class TestKojiBuilder(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = mock.Mock()
|
||||
self.config.koji_profile = 'staging'
|
||||
self.config.koji_repository_url = 'https://kojipkgs.stg.fedoraproject.org/repos'
|
||||
|
||||
|
||||
def test_tag_to_repo(self):
|
||||
""" Test that when a repo msg hits us and we have no match,
|
||||
that we do nothing gracefully.
|
||||
"""
|
||||
repo = rida.builder.Builder.tag_to_repo("koji", self.config,
|
||||
"module-base-runtime-0.25-9",
|
||||
"x86_64")
|
||||
self.assertEquals(repo, "https://kojipkgs.stg.fedoraproject.org/repos"
|
||||
"/module-base-runtime-0.25-9/latest/x86_64")
|
||||
Reference in New Issue
Block a user