76 lines
3.1 KiB
Diff
76 lines
3.1 KiB
Diff
From 9628970bf0d5a7db6553c57b55f4623c91330228 Mon Sep 17 00:00:00 2001
|
|
From: Petr Stodulka <pstodulk@redhat.com>
|
|
Date: Thu, 24 Nov 2022 12:48:51 +0100
|
|
Subject: [PATCH 35/37] DNFWorkaround: extend the model by script_args
|
|
|
|
The original model provided a possibility to execute a script
|
|
that will handle problems before the DNF / RPM transaction,
|
|
in correct contexts (overlay, host system, ..) before any use
|
|
of the upgrade dnf plugin.
|
|
|
|
But current solution provided only the script_path field, which
|
|
suggests it should contain only the path to the script. The executed
|
|
command (inside a context) looked like this:
|
|
bash -c script_path
|
|
However we have realized we need to be able to execute a script
|
|
with additional arguments. Regarding that, introducing
|
|
the script_args field. SO the final command looks like this:
|
|
bash -c 'script_path arg1 arg2..'
|
|
when script_args are specified. The default is set to an empty
|
|
list.
|
|
---
|
|
.../common/libraries/dnfplugin.py | 9 ++++++++-
|
|
.../common/models/dnfworkaround.py | 18 ++++++++++++++++--
|
|
2 files changed, 24 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/repos/system_upgrade/common/libraries/dnfplugin.py b/repos/system_upgrade/common/libraries/dnfplugin.py
|
|
index 0a546637..0ef9ea9b 100644
|
|
--- a/repos/system_upgrade/common/libraries/dnfplugin.py
|
|
+++ b/repos/system_upgrade/common/libraries/dnfplugin.py
|
|
@@ -241,7 +241,14 @@ def apply_workarounds(context=None):
|
|
for workaround in api.consume(DNFWorkaround):
|
|
try:
|
|
api.show_message('Applying transaction workaround - {}'.format(workaround.display_name))
|
|
- context.call(['/bin/bash', '-c', workaround.script_path])
|
|
+ if workaround.script_args:
|
|
+ cmd_str = '{script} {args}'.format(
|
|
+ script=workaround.script_path,
|
|
+ args=' '.join(workaround.script_args)
|
|
+ )
|
|
+ else:
|
|
+ cmd_str = workaround.script_path
|
|
+ context.call(['/bin/bash', '-c', cmd_str])
|
|
except (OSError, CalledProcessError) as e:
|
|
raise StopActorExecutionError(
|
|
message=('Failed to execute script to apply transaction workaround {display_name}.'
|
|
diff --git a/repos/system_upgrade/common/models/dnfworkaround.py b/repos/system_upgrade/common/models/dnfworkaround.py
|
|
index c921c5fc..4a813dcd 100644
|
|
--- a/repos/system_upgrade/common/models/dnfworkaround.py
|
|
+++ b/repos/system_upgrade/common/models/dnfworkaround.py
|
|
@@ -15,6 +15,20 @@ class DNFWorkaround(Model):
|
|
topic = SystemInfoTopic
|
|
|
|
script_path = fields.String()
|
|
- """ Absolute path to a bash script to execute """
|
|
+ """
|
|
+ Absolute path to a bash script to execute
|
|
+ """
|
|
+
|
|
+ script_args = fields.List(fields.String(), default=[])
|
|
+ """
|
|
+ Arguments with which the script should be executed
|
|
+
|
|
+ In case that an argument contains a whitespace or an escapable character,
|
|
+ the argument must be already treated correctly. e.g.
|
|
+ `script_args = ['-i', 'my\\ string']
|
|
+ """
|
|
+
|
|
display_name = fields.String()
|
|
- """ Name to display for this script when executed """
|
|
+ """
|
|
+ Name to display for this script when executed
|
|
+ """
|
|
--
|
|
2.38.1
|
|
|