-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/get_builds: service to fetch kernel build nodes
Add a service to poll for `build` events i.e. listen to successful kernel build nodes and fetch artifacts. Signed-off-by: Jeny Sadadia <[email protected]>
- Loading branch information
Jeny Sadadia
committed
May 7, 2024
1 parent
424d602
commit 8e7b353
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
# Copyright (C) 2024 Collabora Limited | ||
# Author: Jeny Sadadia <[email protected]> | ||
|
||
import sys | ||
|
||
import kernelci | ||
import kernelci.config | ||
from kernelci.legacy.cli import Args, Command, parse_opts | ||
|
||
from base import Service | ||
|
||
|
||
class GetBuilds(Service): | ||
|
||
def __init__(self, configs, args): | ||
super().__init__(configs, args, 'get_builds') | ||
|
||
def _setup(self, args): | ||
return self._api_helper.subscribe_filters({ | ||
'kind': 'kbuild', | ||
'state': 'done', | ||
'result': 'pass' | ||
}, 'build') | ||
|
||
def _stop(self, sub_id): | ||
if sub_id: | ||
self._api_helper.unsubscribe_filters(sub_id) | ||
sys.stdout.flush() | ||
|
||
def _run(self, sub_id): | ||
self.log.info("Listening for events... ") | ||
self.log.info("Press Ctrl-C to stop.") | ||
|
||
while True: | ||
node = self._api_helper.receive_event_node(sub_id) | ||
self.log.info(f"node received: {node}") | ||
self.log.info(f"artifacts: {node['artifacts']}") | ||
return True | ||
|
||
|
||
class cmd_run(Command): | ||
help = "Listen for successful kernel build events" | ||
args = [Args.api_config] | ||
|
||
def __call__(self, configs, args): | ||
return GetBuilds(configs, args).run(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
opts = parse_opts('get_builds', globals()) | ||
yaml_configs = opts.get_yaml_configs() or 'config' | ||
configs = kernelci.config.load(yaml_configs) | ||
status = opts.command(configs, opts) | ||
sys.exit(0 if status is True else 1) |