Merge #177 Add support for modulemd-1.0 backward-incompatible changes like commit being replaced by ref

This commit is contained in:
Matt Prahl
2016-11-14 14:34:08 +00:00
14 changed files with 196 additions and 132 deletions

View File

@@ -0,0 +1,25 @@
"""Drops the release column, adds stream column
Revision ID: 145347916a56
Revises: 229f6f273a56
Create Date: 2016-11-10 15:53:21.798038
"""
# revision identifiers, used by Alembic.
revision = '145347916a56'
down_revision = '229f6f273a56'
from alembic import op
import sqlalchemy as sa
def upgrade():
with op.batch_alter_table('module_builds', schema=None) as batch_op:
batch_op.add_column(sa.Column('stream', sa.String(), nullable=False))
batch_op.drop_column('release')
def downgrade():
with op.batch_alter_table('module_builds', schema=None) as batch_op:
batch_op.add_column(sa.Column('release', sa.VARCHAR(), nullable=False))
batch_op.drop_column('stream')

View File

@@ -41,7 +41,7 @@ for a number of tasks:
- Emitting bus messages about all state changes so that other
infrastructure services can pick up the work.
"""
from flask import Flask
from flask import Flask, has_app_context, url_for
from flask_sqlalchemy import SQLAlchemy
from os import sys
import module_build_service.logger
@@ -61,6 +61,18 @@ else:
db = SQLAlchemy(app)
def get_url_for(*args, **kwargs):
"""
flask.url_for wrapper which creates the app_context on-the-fly.
"""
if has_app_context():
return url_for(*args, **kwargs)
# Localhost is right URL only when the scheduler runs on the same
# system as the web views.
app.config['SERVER_NAME'] = 'localhost'
with app.app_context():
return url_for(*args, **kwargs)
@app.errorhandler(ValidationError)
def validationerror_error(e):

View File

@@ -940,6 +940,8 @@ class MockModuleBuilder(GenericBuilder):
"""
backend = "mock"
# Global build_id/task_id we increment when new build is executed.
_build_id = 1
def __init__(self, owner, module, config, tag_name):
self.module_str = module
@@ -981,15 +983,15 @@ class MockModuleBuilder(GenericBuilder):
)
module_build_service.scheduler.main.outgoing_work_queue_put(msg)
def _send_build_change(self, state, source):
def _send_build_change(self, state, source, build_id):
nvr = kobo.rpmlib.parse_nvr(source)
# build_id=1 and task_id=1 are OK here, because we are building just
# one RPM at the time.
msg = module_build_service.messaging.KojiBuildChange(
msg_id='a faked internal message',
build_id=1,
task_id=1,
build_id=build_id,
task_id=build_id,
build_name=nvr["name"],
build_new_state=state,
build_release=nvr["release"],
@@ -1034,7 +1036,8 @@ class MockModuleBuilder(GenericBuilder):
# by MBS after the build_srpm() method returns and scope gets
# back to scheduler.main.main() method.
self._send_repo_done()
self._send_build_change(koji.BUILD_STATES['COMPLETE'], source)
self._send_build_change(koji.BUILD_STATES['COMPLETE'], source,
MockModuleBuilder._build_id)
self._send_repo_done()
except Exception as e:
log.error("Error while building artifact %s: %s" % (artifact_name,
@@ -1045,14 +1048,15 @@ class MockModuleBuilder(GenericBuilder):
# by MBS after the build_srpm() method returns and scope gets
# back to scheduler.main.main() method.
self._send_repo_done()
self._send_build_change(koji.BUILD_STATES['FAILED'], source)
self._send_build_change(koji.BUILD_STATES['FAILED'], source,
MockModuleBuilder._build_id)
self._send_repo_done()
# Return the "building" state. Real state will be taken by MBS
# from the messages emitted above.
state = koji.BUILD_STATES['BUILDING']
reason = "Submitted %s to Koji" % (artifact_name)
return 1, state, reason, None
return MockModuleBuilder._build_id, state, reason, None
def build_from_scm(self, artifact_name, source):
"""
@@ -1060,7 +1064,8 @@ class MockModuleBuilder(GenericBuilder):
"""
td = None
owd = os.getcwd()
ret = 1, koji.BUILD_STATES["FAILED"], "Cannot create SRPM", None
ret = (MockModuleBuilder._build_id, koji.BUILD_STATES["FAILED"],
"Cannot create SRPM", None)
try:
log.debug('Cloning source URL: %s' % source)
@@ -1096,6 +1101,8 @@ class MockModuleBuilder(GenericBuilder):
def build(self, artifact_name, source):
log.info("Starting building artifact %s: %s" % (artifact_name, source))
MockModuleBuilder._build_id += 1
# Git sources are treated specially.
if source.startswith("git://"):
return self.build_from_scm(artifact_name, source)

View File

@@ -33,7 +33,7 @@ from sqlalchemy import engine_from_config
from sqlalchemy.orm import validates, scoped_session, sessionmaker
import modulemd as _modulemd
from module_build_service import db, log
from module_build_service import db, log, get_url_for
import module_build_service.messaging
from sqlalchemy.orm import lazyload
@@ -103,8 +103,8 @@ class ModuleBuild(RidaBase):
__tablename__ = "module_builds"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, db.ForeignKey('modules.name'), nullable=False)
stream = db.Column(db.String, nullable=False)
version = db.Column(db.String, nullable=False)
release = db.Column(db.String, nullable=False)
state = db.Column(db.Integer, nullable=False)
state_reason = db.Column(db.String)
modulemd = db.Column(db.String, nullable=False)
@@ -159,12 +159,12 @@ class ModuleBuild(RidaBase):
% type(event).__name__)
@classmethod
def create(cls, session, conf, name, version, release, modulemd, scmurl, username):
def create(cls, session, conf, name, stream, version, modulemd, scmurl, username):
now = datetime.utcnow()
module = cls(
name=name,
stream=stream,
version=version,
release=release,
state="init",
modulemd=modulemd,
scmurl=scmurl,
@@ -228,12 +228,12 @@ class ModuleBuild(RidaBase):
return {
'id': self.id,
'name': self.name,
'stream': self.stream,
'version': self.version,
'release': self.release,
'state': self.state,
'state_name': INVERSE_BUILD_STATES[self.state],
'state_reason': self.state_reason,
'state_url': url_for('module_build_query', id=self.id),
'state_url': get_url_for('module_build_query', id=self.id),
'scmurl': self.scmurl,
'owner': self.owner,
'time_submitted': self.time_submitted,
@@ -284,8 +284,8 @@ class ModuleBuild(RidaBase):
return tasks
def __repr__(self):
return "<ModuleBuild %s-%s-%s, state %r, batch %r>" % (
self.name, self.version, self.release,
return "<ModuleBuild %s, stream=%s, version=%s, state %r, batch %r>" % (
self.name, self.stream, self.version,
INVERSE_BUILD_STATES[self.state], self.batch)

View File

@@ -90,15 +90,15 @@ def wait(config, session, msg):
# In case of mock, we do not try to get anything from pdc,
# just generate our own koji_tag to identify the module in messages.
tag = '-'.join(['module', module_info['name'],
str(module_info['version']), str(module_info['release'])])
str(module_info['stream']), str(module_info['version'])])
# TODO: Dependencies
else:
# TODO: Move this to separate func
pdc_session = module_build_service.pdc.get_pdc_client_session(config)
pdc_query = {
'name': module_info['name'],
'version': module_info['version'],
'release': module_info['release'],
'version': module_info['stream'],
'release': module_info['version'],
}
@module_build_service.utils.retry(interval=10, timeout=30, wait_on=ValueError)

View File

@@ -34,6 +34,7 @@ import subprocess as sp
import re
import tempfile
import shutil
import datetime
from module_build_service import log
from module_build_service.errors import Unauthorized, ValidationError
@@ -90,6 +91,8 @@ class SCM(object):
if self.name.endswith(".git"):
self.name = self.name[:-4]
self.commit = match.group("commit")
self.branch = "master"
self.version = None
else:
raise ValidationError("Unhandled SCM scheme: %s" % self.scheme)
@@ -105,7 +108,7 @@ class SCM(object):
if proc.returncode != 0:
raise RuntimeError("Failed on %r, retcode %r, out %r, err %r" % (
cmd, proc.returncode, stdout, stderr))
return proc.returncode
return proc.returncode, stdout, stderr
def checkout(self, scmdir):
"""Checkout the module from SCM.
@@ -129,6 +132,10 @@ class SCM(object):
SCM._run(module_clone_cmd, chdir=scmdir)
if self.commit:
SCM._run(module_checkout_cmd, chdir=sourcedir)
timestamp = SCM._run(["git", "show" , "-s", "--format=%ct"], chdir=sourcedir)[1]
dt = datetime.datetime.utcfromtimestamp(int(timestamp))
self.version = dt.strftime("%Y%m%d%H%M%S")
else:
raise RuntimeError("checkout: Unhandled SCM scheme.")
return sourcedir

View File

@@ -178,6 +178,7 @@ def submit_module_build(username, url):
yaml = ""
td = None
scm = None
try:
log.debug('Verifying modulemd')
td = tempfile.mkdtemp()
@@ -199,13 +200,25 @@ def submit_module_build(username, url):
mmd = modulemd.ModuleMetadata()
try:
mmd.loads(yaml)
except:
log.error('Invalid modulemd')
raise UnprocessableEntity('Invalid modulemd')
except Exception as e:
log.error('Invalid modulemd: %s' % str(e))
raise UnprocessableEntity('Invalid modulemd: %s' % str(e))
# If undefined, set the name field to VCS repo name.
if not mmd.name and scm:
mmd.name = scm.name
# If undefined, set the stream field to the VCS branch name.
if not mmd.stream and scm:
mmd.stream = scm.branch
# If undefined, set the version field to int represenation of VCS commit.
if not mmd.version and scm:
mmd.version = int(scm.version)
module = models.ModuleBuild.query.filter_by(name=mmd.name,
version=mmd.version,
release=mmd.release).first()
stream=mmd.stream,
version=mmd.version).first()
if module:
log.debug('Checking whether module build already exist.')
# TODO: make this configurable, we might want to allow
@@ -228,8 +241,8 @@ def submit_module_build(username, url):
db.session,
conf,
name=mmd.name,
stream=mmd.stream,
version=mmd.version,
release=mmd.release,
modulemd=yaml,
scmurl=url,
username=username
@@ -241,21 +254,21 @@ def submit_module_build(username, url):
# If the modulemd yaml specifies components, then submit them for build
if mmd.components:
for pkgname, pkg in mmd.components.rpms.packages.items():
for pkgname, pkg in mmd.components.rpms.items():
try:
if pkg.get("repository") and not conf.rpms_allow_repository:
if pkg.repository and not conf.rpms_allow_repository:
raise Unauthorized(
"Custom component repositories aren't allowed")
if pkg.get("cache") and not conf.rpms_allow_cache:
if pkg.cache and not conf.rpms_allow_cache:
raise Unauthorized("Custom component caches aren't allowed")
if not pkg.get("repository"):
pkg["repository"] = conf.rpms_default_repository + pkgname
if not pkg.get("cache"):
pkg["cache"] = conf.rpms_default_cache + pkgname
if not pkg.get("commit"):
if not pkg.repository:
pkg.repository = conf.rpms_default_repository + pkgname
if not pkg.cache:
pkg.cache = conf.rpms_default_cache + pkgname
if not pkg.ref:
try:
pkg["commit"] = module_build_service.scm.SCM(
pkg["repository"]).get_latest()
pkg.ref = module_build_service.scm.SCM(
pkg.repository).get_latest()
except Exception as e:
raise UnprocessableEntity(
"Failed to get the latest commit: %s" % pkgname)
@@ -265,7 +278,7 @@ def submit_module_build(username, url):
db.session.commit()
raise
full_url = pkg["repository"] + "?#" + pkg["commit"]
full_url = "%s?#%s" % (pkg.repository, pkg.ref)
full_urls.append((pkgname, full_url))
log.debug("Checking scm urls")
@@ -278,8 +291,8 @@ def submit_module_build(username, url):
if err_msg:
raise UnprocessableEntity(err_msg)
for pkgname, pkg in mmd.components.rpms.packages.items():
full_url = pkg["repository"] + "?#" + pkg["commit"]
for pkgname, pkg in mmd.components.rpms.items():
full_url = "%s?#%s" % (pkg.repository, pkg.ref)
existing_build = models.ComponentBuild.query.filter_by(
module_id=module.id, package=pkgname).first()
@@ -302,6 +315,6 @@ def submit_module_build(username, url):
module.transition(conf, models.BUILD_STATES["wait"])
db.session.add(module)
db.session.commit()
log.info("%s submitted build of %s-%s-%s", username, mmd.name,
mmd.version, mmd.release)
log.info("%s submitted build of %s, stream=%s, version=%s", username,
mmd.name, mmd.stream, mmd.version)
return module

View File

@@ -3,7 +3,7 @@ sqlalchemy
six
fedmsg
pdc-client
modulemd==0.1
modulemd>=1.0.0,<2.0.0
pyOpenSSL
kobo
munch

View File

@@ -33,8 +33,8 @@ def init_data():
for index in range(10):
build_one = ModuleBuild()
build_one.name = 'nginx'
build_one.version = '1'
build_one.release = 2
build_one.stream = '1'
build_one.version = 2
build_one.state = 3
build_one.modulemd = '' # Skipping since no tests rely on it
build_one.koji_tag = 'module-nginx-1.2'
@@ -77,8 +77,8 @@ def init_data():
build_two = ModuleBuild()
build_two.name = 'postgressql'
build_two.version = '1'
build_two.release = 2
build_two.stream = '1'
build_two.version = 2
build_two.state = 3
build_two.modulemd = '' # Skipping since no tests rely on it
build_two.koji_tag = 'module-postgressql-1.2'
@@ -120,8 +120,8 @@ def init_data():
build_three = ModuleBuild()
build_three.name = 'testmodule'
build_three.version = '4.3.43'
build_three.release = 6
build_three.stream = '4.3.43'
build_three.version = 6
build_three.state = 1
build_three.modulemd = '' # Skipping because no tests rely on it
build_three.koji_tag = None

View File

@@ -44,8 +44,8 @@ class TestModuleWait(unittest.TestCase):
mocked_module_build = mock.Mock()
mocked_module_build.json.return_value = {
'name': 'foo',
'stream': 1,
'version': 1,
'release': 1,
'state': 'some state',
}

View File

@@ -1,9 +1,9 @@
document: modulemd
version: 0
version: 1
data:
name: base-runtime
version: 0.25
release: 1
stream: "0.25"
version: 1
summary: The base application runtime and hardware enablement layer
description: >
A project closely linked to the Modularity Initiative, base-runtime
@@ -17,7 +17,7 @@ data:
# Build-require self for now.
# TODO: Don't forget to update this once we're no longer self-hosted
buildrequires:
base-runtime: ~
base-runtime: "0.25"
references:
community: https://fedoraproject.org/wiki/BaseRuntime
documentation: https://pagure.io/base-runtime
@@ -118,65 +118,64 @@ data:
- uucp
# ex, vi
- vim-minimal
api:
rpms:
- at
- bash
- bc
- binutils
- byacc
- cflow
- coreutils
- cronie
- ctags
- cups-client
- diffutils
- ed
- file
- flex
- findutils
- gawk
- gcc
- gcc-gfortran
- glibc-common
- grep
- gzip
- kernel
- m4
- mailx
- make
- man-db
- ncompress
- ncurses
- patch
- psmisc
- procps-ng
- sed
- shadow-utils
- sharutils
- spax
- systemd
- talk
- time
- torque-client
- util-linux
- uucp
- vim-minimal
components:
rpms:
# The same as the default installation profile for now
api:
- at
- bash
- bc
- binutils
- byacc
- cflow
- coreutils
- cronie
- ctags
- cups-client
- diffutils
- ed
- file
- flex
- findutils
- gawk
- gcc
- gcc-gfortran
- glibc-common
- grep
- gzip
- kernel
- m4
- mailx
- make
- man-db
- ncompress
- ncurses
- patch
- psmisc
- procps-ng
- sed
- shadow-utils
- sharutils
- spax
- systemd
- talk
- time
- torque-client
- util-linux
- uucp
- vim-minimal
packages:
CUnit2:
rationale: Part of the first base-runtime prototype.
commit: 2fb6e8f0529a1196a4bd0897e9bfcd93719e686c
Canna:
rationale: Part of the first base-runtime prototype.
commit: 8d636177ba858cfabf02df029b2089cf192d683e
Cython:
rationale: Part of the first base-runtime prototype.
commit: 6c9d7cad8ac0a840b18b495c4fe152967d808600
DevIL:
rationale: Part of the first base-runtime prototype.
commit: de58614c0febb5032b710739f34f7344679668f6
GConf2:
rationale: Part of the first base-runtime prototype.
commit: a13087720a27b17b61bd0a1cbd6042a1d0ab98b7
CUnit2:
rationale: Part of the first base-runtime prototype.
ref: 2fb6e8f0529a1196a4bd0897e9bfcd93719e686c
Canna:
rationale: Part of the first base-runtime prototype.
ref: 8d636177ba858cfabf02df029b2089cf192d683e
Cython:
rationale: Part of the first base-runtime prototype.
ref: 6c9d7cad8ac0a840b18b495c4fe152967d808600
DevIL:
rationale: Part of the first base-runtime prototype.
ref: de58614c0febb5032b710739f34f7344679668f6
GConf2:
rationale: Part of the first base-runtime prototype.
ref: a13087720a27b17b61bd0a1cbd6042a1d0ab98b7

View File

@@ -1,9 +1,9 @@
document: modulemd
version: 0
version: 1
data:
name: fakemodule
version: 4.3.44
release: 5
stream: "4.3.44"
version: 5
summary: A fake module containing the bash shell
description: >
A fake module used for testing
@@ -22,11 +22,11 @@ data:
default:
rpms:
- bash
api:
rpms:
- bash
components:
rpms:
api:
- bash
packages:
bash:
rationale: It's here to test the whole thing!
commit: 70fa7516b83768595a4f3280ae890a7ac957e0c7
bash:
rationale: It's here to test the whole thing!
ref: 70fa7516b83768595a4f3280ae890a7ac957e0c7

View File

@@ -1,9 +1,9 @@
document: modulemd
version: 0
version: 1
data:
name: fakemodule2
version: 4.3.44
release: 5
stream: "4.3.44"
version: 5
summary: A fake module containing the bash shell
description: >
A fake module used for testing

View File

@@ -184,12 +184,12 @@ class TestViews(unittest.TestCase):
self.assertEquals(data['scmurl'],
('git://pkgs.stg.fedoraproject.org/modules/testmodule'
'.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'))
self.assertEquals(data['release'], '5')
self.assertEquals(data['version'], '5')
self.assertTrue(data['time_submitted'] is not None)
self.assertTrue(data['time_modified'] is not None)
self.assertEquals(data['release'], '5')
self.assertEquals(data['version'], '5')
self.assertEquals(data['time_completed'], None)
self.assertEquals(data['version'], '4.3.44')
self.assertEquals(data['stream'], '4.3.44')
self.assertEquals(data['owner'], 'Homer J. Simpson')
self.assertEquals(data['id'], 31)
self.assertEquals(data['state_name'], 'wait')
@@ -221,12 +221,12 @@ class TestViews(unittest.TestCase):
self.assertEquals(data['scmurl'],
('git://pkgs.stg.fedoraproject.org/modules/testmodule'
'.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'))
self.assertEquals(data['release'], '5')
self.assertEquals(data['version'], '5')
self.assertTrue(data['time_submitted'] is not None)
self.assertTrue(data['time_modified'] is not None)
self.assertEquals(data['release'], '5')
self.assertEquals(data['version'], '5')
self.assertEquals(data['time_completed'], None)
self.assertEquals(data['version'], '4.3.44')
self.assertEquals(data['stream'], '4.3.44')
self.assertEquals(data['owner'], 'Homer J. Simpson')
self.assertEquals(data['id'], 31)
self.assertEquals(data['state_name'], 'wait')
@@ -295,7 +295,8 @@ class TestViews(unittest.TestCase):
'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'}))
data = json.loads(rv.data)
self.assertEquals(
data['message'], 'Invalid modulemd')
data['message'], 'Invalid modulemd: The supplied data isn\'t'
' a valid modulemd document')
self.assertEquals(data['status'], 422)
self.assertEquals(data['error'], 'Unprocessable Entity')