From a4785fa6be84adb5ec4c427d696accfab65a2cc8 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Fri, 29 Mar 2024 12:26:26 -0600 Subject: [PATCH] feat(opennebula): Use posix shell if bash is unavailable --- cloudinit/sources/DataSourceOpenNebula.py | 20 +++++++------------- tests/unittests/sources/test_opennebula.py | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py index a78d861e52ec..9e2f6389acc4 100644 --- a/cloudinit/sources/DataSourceOpenNebula.py +++ b/cloudinit/sources/DataSourceOpenNebula.py @@ -299,26 +299,20 @@ def switch_user_cmd(user): return ["sudo", "-u", user] -def parse_shell_config( - content, keylist=None, bash=None, asuser=None, switch_user_cb=None -): +def parse_shell_config(content, asuser=None): - if isinstance(bash, str): - bash = [bash] - elif bash is None: + if subp.which("bash"): bash = ["bash", "-e"] + else: + bash = ["sh", "-e"] - if switch_user_cb is None: - switch_user_cb = switch_user_cmd # allvars expands to all existing variables by using '${!x*}' notation # where x is lower or upper case letters or '_' allvars = ["${!%s*}" % x for x in string.ascii_letters + "_"] - keylist_in = keylist - if keylist is None: - keylist = allvars - keylist_in = [] + keylist = allvars + keylist_in = [] setup = "\n".join( ( @@ -362,7 +356,7 @@ def varprinter(vlist): cmd = [] if asuser is not None: - cmd = switch_user_cb(asuser) + cmd = switch_user_cmd(asuser) cmd.extend(bash) diff --git a/tests/unittests/sources/test_opennebula.py b/tests/unittests/sources/test_opennebula.py index 3482e3170f57..5b3984612a91 100644 --- a/tests/unittests/sources/test_opennebula.py +++ b/tests/unittests/sources/test_opennebula.py @@ -43,7 +43,7 @@ class TestOpenNebulaDataSource(CiTestCase): parsed_user = None - allowed_subp = ["bash"] + allowed_subp = ["bash", "sh"] def setUp(self): super(TestOpenNebulaDataSource, self).setUp()