Skip to content

Commit

Permalink
Create additional side tags on multi build tag
Browse files Browse the repository at this point in the history
Create new side tags from initial side tag and move builds to newly
created sidetag.

Closes fedora-infra#3473

Signed-off-by: Michal Konečný <mkonecny@redhat.com>
  • Loading branch information
Zlopez committed Aug 28, 2019
1 parent 3a89b54 commit 4760c45
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bodhi/server/buildsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def clear(cls):
cls.__added__ = []
cls.__tagged__ = {}
cls.__rpms__ = []
cls.__tags__ = []

def multiCall(self):
"""Emulate Koji's multiCall."""
Expand Down Expand Up @@ -448,7 +449,7 @@ def getTag(self, taginfo, **kw):
'perm': None, 'id': 246, 'arches': None,
'maven_include_all': False, 'perm_id': None}

def addTag(self, tag: str, **opts):
def createTag(self, tag: str, **opts):
"""Emulate tag adding."""
if 'parent' not in opts:
raise ValueError('No parent in tag options')
Expand Down
6 changes: 6 additions & 0 deletions bodhi/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ class BodhiConfig(dict):
'koji_hub': {
'value': 'https://koji.stg.fedoraproject.org/kojihub',
'validator': str},
'koji_pending_signing_side_tag': {
'value': '-pending-signing',
'validator': str},
'koji_testing_side_tag': {
'value': '-testing',
'validator': str},
'krb_ccache': {
'value': None,
'validator': _validate_none_or(str)},
Expand Down
26 changes: 23 additions & 3 deletions bodhi/server/services/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sqlalchemy.sql import or_
from requests import RequestException, Timeout as RequestsTimeout

from bodhi.server import log, security
from bodhi.server import log, security, buildsys, config
from bodhi.server.exceptions import BodhiException, LockedUpdateException
from bodhi.server.models import (
Update,
Expand Down Expand Up @@ -440,6 +440,8 @@ def new_update(request):
empty, the list of builds will be filled with the latest builds in this
Koji tag. This is done by validate_from_tag() because the list of builds
needs to be available in validate_acls().
Ensure that related tags ``from_tag``-pending-signing and ``from_tag``-testing
exists and if not create them in Koji.
Args:
request (pyramid.request): The current request.
Expand Down Expand Up @@ -492,8 +494,8 @@ def new_update(request):
# the builds as signed.
request.db.commit()

# After we commit the transaction, we need to get the builds and releases again, since they
# were tied to the previous session that has now been terminated.
# After we commit the transaction, we need to get the builds and releases again,
# since they were tied to the previous session that has now been terminated.
builds = []
releases = set()
for nvr in build_nvrs:
Expand Down Expand Up @@ -536,6 +538,24 @@ def new_update(request):

if len(releases) > 1:
result = dict(updates=updates)

if from_tag:
koji = buildsys.get_session()
# Validate that <koji_tag>-pending-signing and <koji-tag>-testing exists,
# if not create them
koji_tag_pending_signing = from_tag + config.config.get(
'koji_pending_signing_side_tag')
koji_tag_testing = from_tag + config.config.get('koji_testing_side_tag')
if not koji.getTag(koji_tag_pending_signing):
koji.createTag(koji_tag_pending_signing, parent=from_tag)
if not koji.getTag(koji_tag_testing):
koji.createTag(koji_tag_testing, parent=from_tag)

to_tag = koji_tag_pending_signing
# Move every new build to <from_tag>-pending-signing tag
for update in updates:
update.add_tag(to_tag)

except LockedUpdateException as e:
log.warning(str(e))
request.errors.add('body', 'builds', "%s" % str(e))
Expand Down
40 changes: 38 additions & 2 deletions bodhi/tests/server/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from webtest import TestApp

from bodhi.messages.schemas import base as base_schemas, update as update_schemas
from bodhi.server import main
from bodhi.server import main, buildsys
from bodhi.server.config import config
from bodhi.server.models import (
Build, BuildrootOverride, Compose, Group, RpmPackage, ModulePackage, Release,
Expand Down Expand Up @@ -85,6 +85,13 @@ class TestNewUpdate(BaseTestCase):
"""
This class contains tests for the new_update() function.
"""

@classmethod
def mock_getTag(cls, tag, *kwargs):
if tag == 'f17-updates-updates-candidate':
return True
return None

@mock.patch(**mock_valid_requirements)
def test_empty_build_name(self, *args):
res = self.app.post_json('/updates/', self.get_update(['']), status=400)
Expand Down Expand Up @@ -286,7 +293,8 @@ def test_new_rpm_update_from_tag(self, *args):
self.db.delete(Update.query.one())

update = self.get_update(builds=None, from_tag='f17-updates-candidate')
with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1), \
mock.patch('bodhi.server.buildsys.DevBuildsys.getTag', self.mock_getTag):
r = self.app.post_json('/updates/', update)

up = r.json_body
Expand Down Expand Up @@ -314,6 +322,34 @@ def test_new_rpm_update_from_tag(self, *args):
self.assertEqual(up['requirements'], 'rpmlint')
self.assertEqual(up['from_tag'], 'f17-updates-candidate')

koji_session = buildsys.get_session()
expected_pending_signing = ('f17-updates-candidate-pending-signing',
{'parent': 'f17-updates-candidate',
'locked': False,
'maven_support': False,
'name': 'f17-updates-candidate-pending-signing',
'perm': 'admin',
'arches': None,
'maven_include_all': False,
'perm_id': 1})
expected_testing = ('f17-updates-candidate-testing',
{'parent': 'f17-updates-candidate',
'locked': False,
'maven_support': False,
'name': 'f17-updates-candidate-testing',
'perm': 'admin',
'arches': None,
'maven_include_all': False,
'perm_id': 1})

self.assertIn(expected_pending_signing, koji_session.__tags__)
self.assertIn(expected_testing, koji_session.__tags__)
self.assertIn(('f17-updates-candidate-pending-signing',
'TurboGears-1.0.2.2-3.fc17'),
koji_session.__added__)

koji_session.clear()

@mock.patch(**mock_valid_requirements)
def test_koji_config_url(self, *args):
"""
Expand Down
5 changes: 5 additions & 0 deletions production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ use = egg:bodhi-server
# Koji's XML-RPC hub
# koji_hub = https://koji.stg.fedoraproject.org/kojihub

# Side tag postfix in Koji for pending-signing tag used for multi-build gating
# koji_pending_signing_side_tag = -pending-signing

# Side tag postfix in Koji for testing tag used for multi-build gating
# koji_pending_signing_side_tag = -testing

# URL of where users should go to set up their notifications
# fmn_url = https://apps.fedoraproject.org/notifications/
Expand Down

0 comments on commit 4760c45

Please sign in to comment.