Move insert_fake_baseruntime to utils.py.

This commit is contained in:
Ralph Bean
2016-11-30 10:49:08 -05:00
parent 20a235202e
commit a2122f84a4
2 changed files with 96 additions and 82 deletions

View File

@@ -36,7 +36,10 @@ from module_build_service.pdc import (
get_module_tag, get_module_build_dependencies)
import module_build_service.auth
import module_build_service.scheduler.main
from module_build_service.utils import submit_module_build
from module_build_service.utils import (
submit_module_build,
insert_fake_baseruntime,
)
from module_build_service.messaging import RidaModule
@@ -99,7 +102,7 @@ def upgradedb():
""" Upgrades the database schema to the latest revision
"""
flask_migrate.upgrade()
_insert_fake_baseruntime()
insert_fake_baseruntime()
@manager.command
@@ -107,84 +110,6 @@ def cleardb():
models.ModuleBuild.query.delete()
models.ComponentBuild.query.delete()
def _insert_fake_baseruntime():
import sqlalchemy as sa
import modulemd
yaml = """
document: modulemd
version: 1
data:
name: base-runtime
stream: master
version: 3
summary: A fake base-runtime module, used to bootstrap the infrastructure.
description: ...
profiles:
buildroot:
rpms:
- bash
- bzip2
- coreutils
- cpio
- diffutils
- fedora-release
- findutils
- gawk
- gcc
- gcc-c++
- grep
- gzip
- info
- make
- patch
- redhat-rpm-config
- rpm-build
- sed
- shadow-utils
- tar
- unzip
- util-linux
- which
- xz
srpm-buildroot:
rpms:
- bash
- fedora-release
- fedpkg-minimal
- gnupg2
- redhat-rpm-config
- rpm-build
- shadow-utils
"""
mmd = modulemd.ModuleMetadata()
mmd.loads(yaml)
# Check to see if this thing already exists...
query = models.ModuleBuild.query\
.filter_by(name=mmd.name)\
.filter_by(stream=mmd.stream)\
.filter_by(version=mmd.version)
if query.count():
logging.info('%r exists. Skipping creation.' % query.first())
return
# Otherwise, it does not exist. So, create it.
module = models.ModuleBuild.create(
db.session,
conf,
name=mmd.name,
stream=mmd.stream,
version=mmd.version,
modulemd=yaml,
scmurl='...',
username='modularity',
)
module.state = models.BUILD_STATES['done']
module.state_reason = 'Artificially created.'
db.session.commit()
@manager.command
def build_module_locally(url):
@@ -210,7 +135,7 @@ def build_module_locally(url):
# In the future, we should use PDC to get what we need from the fake module,
# so it's probably not big problem.
db.create_all()
_insert_fake_baseruntime()
insert_fake_baseruntime()
username = getpass.getuser()
submit_module_build(username, url)

View File

@@ -306,7 +306,7 @@ def record_component_builds(mmd, module, initial_batch = 1):
# reserved for module-build-macros. First real components must be
# planned for batch 2 and following.
batch = initial_batch
for pkg in components:
# If the pkg is another module, we fetch its modulemd file
# and record its components recursively with the initial_batch
@@ -403,3 +403,92 @@ def submit_module_build(username, url):
log.info("%s submitted build of %s, stream=%s, version=%s", username,
mmd.name, mmd.stream, mmd.version)
return module
def insert_fake_baseruntime():
""" Insert a fake base-runtime module into our db.
This is done so that we can reference the build profiles in its modulemd.
See:
- https://pagure.io/fm-orchestrator/pull-request/228
- https://pagure.io/fm-orchestrator/pull-request/225
"""
import sqlalchemy as sa
import modulemd
yaml = """
document: modulemd
version: 1
data:
name: base-runtime
stream: master
version: 3
summary: A fake base-runtime module, used to bootstrap the infrastructure.
description: ...
profiles:
buildroot:
rpms:
- bash
- bzip2
- coreutils
- cpio
- diffutils
- fedora-release
- findutils
- gawk
- gcc
- gcc-c++
- grep
- gzip
- info
- make
- patch
- redhat-rpm-config
- rpm-build
- sed
- shadow-utils
- tar
- unzip
- util-linux
- which
- xz
srpm-buildroot:
rpms:
- bash
- fedora-release
- fedpkg-minimal
- gnupg2
- redhat-rpm-config
- rpm-build
- shadow-utils
"""
mmd = modulemd.ModuleMetadata()
mmd.loads(yaml)
# Check to see if this thing already exists...
query = models.ModuleBuild.query\
.filter_by(name=mmd.name)\
.filter_by(stream=mmd.stream)\
.filter_by(version=mmd.version)
if query.count():
logging.info('%r exists. Skipping creation.' % query.first())
return
# Otherwise, it does not exist. So, create it.
module = models.ModuleBuild.create(
db.session,
conf,
name=mmd.name,
stream=mmd.stream,
version=mmd.version,
modulemd=yaml,
scmurl='...',
username='modularity',
)
module.state = models.BUILD_STATES['done']
module.state_reason = 'Artificially created.'
db.session.commit()