From 9efda7d562d072acbe183ea9f164fe974356fd60 Mon Sep 17 00:00:00 2001
From: Robert Cerven <rcerven@redhat.com>
Date: Thu, 7 Apr 2022 20:43:36 +0200
Subject: [PATCH] add --background option for container-build which allows to
create build with lower priority
* CLOUDBLD-9358
Signed-off-by: Robert Cerven <rcerven@redhat.com>
---
pyrpkg/__init__.py | 7 ++++++-
pyrpkg/cli.py | 7 +++++++
tests/test_cli.py | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 331c354..5b1e001 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -3358,6 +3358,7 @@ class Commands(object):
build_client=None,
koji_task_watcher=None,
nowait=False,
+ background=False,
flatpak=False):
# check if repo is dirty and all commits are pushed
@@ -3405,7 +3406,11 @@ class Commands(object):
if flatpak:
task_opts['flatpak'] = True
- priority = opts.get("priority", None)
+ priority = None
+ if background:
+ # relative to koji.PRIO_DEFAULT
+ priority = 5
+
task_id = self.kojisession.buildContainer(source,
container_target,
task_opts,
diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index c253bb5..e7b6e26 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -1665,6 +1665,12 @@ class cliClient(object):
default=False,
help="Don't wait on build")
+ parser.add_argument(
+ '--background',
+ action='store_true',
+ default=False,
+ help="Run the build at a lower priority")
+
parser.add_argument(
'--build-release',
default=None,
@@ -2252,6 +2258,7 @@ class cliClient(object):
build_client=build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=self.args.nowait,
+ background=self.args.background,
flatpak=flatpak)
return rv
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 94aaaff..054e950 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -161,6 +161,39 @@ class TestContainerBuildWithKoji(CliTestCase):
build_client=utils.build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=False,
+ background=False,
+ flatpak=False
+ )
+
+ def test_using_kojiprofile_background(self):
+ cli_cmd = ['rpkg', '--path', self.cloned_repo_path,
+ 'container-build', '--background']
+
+ with patch('sys.argv', new=cli_cmd):
+ cli = self.new_cli()
+ cli.container_build_koji()
+
+ self.mock_container_build_koji.assert_called_once_with(
+ False,
+ opts={
+ 'scratch': False,
+ 'quiet': False,
+ 'release': None,
+ 'isolated': False,
+ 'koji_parent_build': None,
+ 'yum_repourls': None,
+ 'dependency_replacements': None,
+ 'git_branch': 'eng-rhel-7',
+ 'arches': None,
+ 'signing_intent': None,
+ 'compose_ids': None,
+ 'skip_build': False
+ },
+ kojiprofile='koji',
+ build_client=utils.build_client,
+ koji_task_watcher=koji_cli.lib.watch_tasks,
+ nowait=False,
+ background=True,
flatpak=False
)
@@ -193,6 +226,7 @@ class TestContainerBuildWithKoji(CliTestCase):
build_client=utils.build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=False,
+ background=False,
flatpak=False
)
@@ -226,6 +260,7 @@ class TestContainerBuildWithKoji(CliTestCase):
build_client=utils.build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=False,
+ background=False,
flatpak=False
)
@@ -258,6 +293,7 @@ class TestContainerBuildWithKoji(CliTestCase):
build_client=utils.build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=False,
+ background=False,
flatpak=False
)
@@ -289,6 +325,7 @@ class TestContainerBuildWithKoji(CliTestCase):
build_client=utils.build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=False,
+ background=False,
flatpak=False
)
@@ -346,6 +383,7 @@ class TestContainerBuildWithKoji(CliTestCase):
build_client=utils.build_client,
koji_task_watcher=koji_cli.lib.watch_tasks,
nowait=False,
+ background=False,
flatpak=True
)
--
2.35.1