mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-11-28 06:33:38 +08:00
Add siblings to the extended JSON output of module builds
This commit is contained in:
@@ -32,7 +32,7 @@ from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
import hashlib
|
||||
import sqlalchemy
|
||||
from sqlalchemy.orm import validates, scoped_session, sessionmaker
|
||||
from sqlalchemy.orm import validates, scoped_session, sessionmaker, load_only
|
||||
from flask import has_app_context
|
||||
from module_build_service import db, log, get_url_for, app, conf, Modulemd
|
||||
import module_build_service.messaging
|
||||
@@ -392,6 +392,13 @@ class ModuleBuild(MBSBase):
|
||||
def context(self):
|
||||
return ModuleBuild.context_from_contexts(self.build_context, self.runtime_context)
|
||||
|
||||
@property
|
||||
def siblings(self):
|
||||
query = self.query.filter_by(
|
||||
name=self.name, stream=self.stream, version=self.version).options(
|
||||
load_only('id')).filter(ModuleBuild.id != self.id)
|
||||
return [build.id for build in query.all()]
|
||||
|
||||
@classmethod
|
||||
def create(cls, session, conf, name, stream, version, modulemd, scmurl, username,
|
||||
copr_owner=None, copr_project=None, rebuild_strategy=None, publish_msg=True):
|
||||
@@ -568,7 +575,8 @@ class ModuleBuild(MBSBase):
|
||||
'reason': record.state_reason}
|
||||
for record
|
||||
in self.state_trace(self.id)],
|
||||
'state_url': state_url
|
||||
'state_url': state_url,
|
||||
'siblings': self.siblings
|
||||
})
|
||||
|
||||
return json
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
import os
|
||||
|
||||
from tests.test_models import init_data
|
||||
from tests import init_data as init_data_contexts
|
||||
from tests.test_models import init_data, module_build_from_modulemd
|
||||
from tests import init_data as init_data_contexts, clean_database
|
||||
from module_build_service import conf, Modulemd
|
||||
from module_build_service.models import ComponentBuild, ModuleBuild, make_session
|
||||
|
||||
@@ -72,6 +72,25 @@ class TestModels:
|
||||
assert build.runtime_context == 'bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c'
|
||||
assert build.context == 'f1a17afd'
|
||||
|
||||
def test_siblings_property(self):
|
||||
""" Tests that the siblings property returns the ID of all modules with
|
||||
the same name:stream:version
|
||||
"""
|
||||
clean_database()
|
||||
yaml_path = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'staged_data', 'formatted_testmodule.yaml')
|
||||
mmd = Modulemd.Module.new_from_file(yaml_path)
|
||||
mmd.upgrade()
|
||||
with make_session(conf) as session:
|
||||
for i in range(3):
|
||||
build = module_build_from_modulemd(mmd.dumps())
|
||||
build.build_context = 'f6e2aeec7576196241b9afa0b6b22acf2b6873d' + str(i)
|
||||
build.runtime_context = 'bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c' + str(i)
|
||||
session.add(build)
|
||||
session.commit()
|
||||
build_one = ModuleBuild.query.get(2)
|
||||
assert build_one.siblings == [3, 4]
|
||||
|
||||
|
||||
class TestModelsGetStreamsContexts:
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ class TestViews:
|
||||
assert data['time_submitted'] == u'2016-09-03T11:23:20Z'
|
||||
assert data['version'] == '2'
|
||||
assert data['rebuild_strategy'] == 'changed-and-after'
|
||||
assert data['siblings'] == []
|
||||
|
||||
def test_pagination_metadata(self):
|
||||
rv = self.client.get('/module-build-service/1/module-builds/?per_page=2&page=2')
|
||||
@@ -532,6 +533,7 @@ class TestViews:
|
||||
assert len(data['state_trace']) == 1
|
||||
assert data['state_trace'][0]['state'] == 0
|
||||
assert data['tasks'] == {}
|
||||
assert data['siblings'] == []
|
||||
mmd = Modulemd.Module().new_from_string(data['modulemd'])
|
||||
mmd.upgrade()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user