Skip to content

Commit 06fe782

Browse files
committed
chain builds
1 parent 5cfb0fe commit 06fe782

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

abf.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ def parse_command_line():
203203
g.add_argument('-b', '--branch', action='store', help=_('branch to build.'))
204204
g.add_argument('-t', '--tag', action='store', help=_('tag to build.'))
205205
g.add_argument('-c', '--commit', action='store', help=_('commit sha hash to build.'))
206+
cb = subparser.add_mutually_exclusive_group()
207+
cb.add_argument('--create-chain', action='store_true', help=_('start new chain build'))
208+
cb.add_argument('--add-to-chain', action='store', help=_('add build to chain build(argument last adds to your last chain build)'))
209+
level = subparser.add_mutually_exclusive_group()
210+
level.add_argument('--current-level', action='store_true', help=_('adds build to the same level'))
211+
level.add_argument('--next-level', action='store_true', help=_('adds build to the next level'))
206212
subparser.add_argument('-s', '--save-to-repository', action='store', help=_('repository to save results to '
207213
'([platform/]repository). If no platform part specified, it is assumed to be "<default_group>_personal". '
208214
'If this option is not specified at all, "<default_group>_personal/main" will be used.'))
@@ -1411,7 +1417,7 @@ def auto_resolve():
14111417
log.error(_("Invalid architecture: %s") % arch)
14121418
exit(1)
14131419
arches.append(a)
1414-
else:
1420+
elif command_line.add_to_chain is None:
14151421
try_arches = ['x86_64', 'aarch64']
14161422

14171423
# rosa2014.1, rosa2016.1 etc. (Rosa Fresh), but not e.g. rosa-server75 (Rosa-RHEL)
@@ -1469,6 +1475,32 @@ def auto_resolve():
14691475
for b in command_line.build_list:
14701476
extra_build_lists.append(int(b))
14711477

1478+
chain_config = {}
1479+
if command_line.create_chain:
1480+
chain_config = {'create_chain': True}
1481+
command_line.auto_publish_status = 'none'
1482+
auto_create_container = True
1483+
extra_build_lists = []
1484+
elif command_line.add_to_chain is not None:
1485+
chain_config = {'add_to_chain': command_line.add_to_chain}
1486+
if command_line.add_to_chain == 'last':
1487+
arch_names = ChainBuild.last(models).arches
1488+
else:
1489+
arch_names = ChainBuild(models, command_line.add_to_chain).arches
1490+
arches = []
1491+
for arch in arch_names:
1492+
arches.append(Arch.get_arch_by_name(models, arch))
1493+
log.info(_("Arches are assumed to be ") + str(arches))
1494+
if command_line.current_level:
1495+
chain_config['current_level'] = True
1496+
elif command_line.next_level:
1497+
chain_config['next_level'] = True
1498+
else:
1499+
chain_config['next_level'] = True
1500+
command_line.auto_publish_status = 'none'
1501+
auto_create_container = True
1502+
extra_build_lists = []
1503+
14721504
build_ids = BuildList.new_build_task(
14731505
models,
14741506
proj,
@@ -1487,7 +1519,8 @@ def auto_resolve():
14871519
use_extra_tests,
14881520
extra_build_lists,
14891521
# TODO: Read external_nodes config value from user's profile
1490-
command_line.external_nodes or BuildList.external_nodes_vals[0]
1522+
command_line.external_nodes or BuildList.external_nodes_vals[0],
1523+
chain_config
14911524
)
14921525
ids = ','.join([str(i) for i in build_ids])
14931526
if 'projects_cfg' in globals():

abf/api/jsn.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def process_response(self, response_string):
9696
res = json.loads(response_string)
9797
except ValueError as ex:
9898
self.log.error(_("Internal server error: it has returned non-json data. "))
99-
# print(response_string)
10099
exit(1)
101100
m = None
102101
if 'message' in res and res['message'] not in AbfJson.good_messages:
@@ -312,6 +311,15 @@ def get_architectures(self):
312311
URL = "/api/v1/arches.json"
313312
return self.get_url_contents(URL)
314313

314+
def get_last_chain_build(self):
315+
URL = "/api/v1/chain_builds/last.json"
316+
return self.get_url_contents(URL)
317+
318+
def get_chain_build_by_id(self, id):
319+
chain_build_id = int(id)
320+
URL = "/api/v1/chain_builds/%d.json" % chain_build_id
321+
return self.get_url_contents(URL)
322+
315323
def get_platforms(self, typ=None):
316324
URL = "/api/v1/platforms.json"
317325
GET = {}

abf/model.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,22 @@ def get_arch_by_name(models, name):
298298
def __repr__(self):
299299
return self.name
300300

301+
class ChainBuild(Model):
302+
required_fields = ['id', 'arches']
303+
304+
def load(self):
305+
self.params_dict = self.init_data
306+
self.cacher = lt_cache
307+
308+
def get_init_data(self, ID):
309+
ID = str(ID)
310+
self.init_data = self.models.jsn.get_chain_build_by_id(ID)['chain_build']
311+
312+
@staticmethod
313+
def last(models):
314+
chain_build = models.jsn.get_last_chain_build()['chain_build']
315+
return ChainBuild(models, init_data=chain_build)
316+
301317
class User(Model):
302318
required_fields = ['id', 'name', 'email', 'language', 'professional_experience', 'site', 'company', 'location',
303319
'uname', 'own_projects_count', 'build_priority', 'created_at', 'updated_at', 'avatar_url', 'html_url']
@@ -575,7 +591,8 @@ def new_build_task(models,
575591
include_testing_subrepo,
576592
use_extra_tests,
577593
extra_build_lists,
578-
external_nodes):
594+
external_nodes,
595+
chain_config):
579596
if external_nodes == 'none':
580597
DATA = {
581598
'project_id': project.id,
@@ -593,7 +610,8 @@ def new_build_task(models,
593610
'extra_repositories': [],
594611
'extra_build_lists': extra_build_lists,
595612
'include_testing_subrepository': include_testing_subrepo,
596-
'use_extra_tests': use_extra_tests
613+
'use_extra_tests': use_extra_tests,
614+
'chain_config': chain_config
597615
}
598616
else:
599617
DATA = {
@@ -613,7 +631,8 @@ def new_build_task(models,
613631
'extra_build_lists': extra_build_lists,
614632
'include_testing_subrepository': include_testing_subrepo,
615633
'use_extra_tests': use_extra_tests,
616-
'external_nodes': external_nodes
634+
'external_nodes': external_nodes,
635+
'chain_config': chain_config
617636
}
618637

619638
build_platforms = {}
@@ -641,8 +660,21 @@ def new_build_task(models,
641660
'notify the console-client developers. Send them a set of command-line arguments and the request data:\n%s') % DATA )
642661
exit(1)
643662
if result['build_list']['id'] is not None:
644-
log.info(_("Task %(proj)s|%(plat)s|%(save_repo)s|%(arch)s has been sent. Build task id is %(id)s") %
645-
{'proj': project, 'plat': bpl, 'save_repo': save_to_repository, 'arch': arch, 'id': result['build_list']['id']})
663+
if 'chain_build_id' in result['build_list']:
664+
if 'create_chain' in DATA['chain_config']:
665+
DATA['chain_config'] = {'add_first': result['build_list']['chain_build_id']}
666+
log.info(_("Task %(proj)s|%(plat)s|%(save_repo)s|%(arch)s has been sent. Build task id is %(id)s. Chain build id is %(chain_build_id)s") %
667+
{
668+
'proj': project,
669+
'plat': bpl,
670+
'save_repo': save_to_repository,
671+
'arch': arch, 'id': result['build_list']['id'],
672+
'chain_build_id': result['build_list']['chain_build_id']
673+
}
674+
)
675+
else:
676+
log.info(_("Task %(proj)s|%(plat)s|%(save_repo)s|%(arch)s has been sent. Build task id is %(id)s") %
677+
{'proj': project, 'plat': bpl, 'save_repo': save_to_repository, 'arch': arch, 'id': result['build_list']['id']})
646678
else:
647679
log.info(_("Build request %(proj)s|%(plat)s|%(save_repo)s|%(arch)s has failed.\nReason: %(reason)s") %
648680
{'proj': project, 'plat': bpl, 'save_repo': save_to_repository, 'arch': arch, 'reason': result['build_list']['message']})

0 commit comments

Comments
 (0)