Skip to content

Commit

Permalink
feat(opennebula): Use posix shell if bash is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Mar 29, 2024
1 parent 9ed2dd4 commit a4785fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions cloudinit/sources/DataSourceOpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/sources/test_opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

class TestOpenNebulaDataSource(CiTestCase):
parsed_user = None
allowed_subp = ["bash"]
allowed_subp = ["bash", "sh"]

def setUp(self):
super(TestOpenNebulaDataSource, self).setUp()
Expand Down

0 comments on commit a4785fa

Please sign in to comment.