diff options
author | Scott Moser <smoser@brickies.net> | 2016-09-21 15:45:45 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-09-21 16:33:19 -0400 |
commit | 40a400e42603aa1b80d9f623bc779799b370c091 (patch) | |
tree | c6b06266be9ba57f5764290d04d61584e732512c /cloudinit/util.py | |
parent | 970dbd13f5ae40b0f95ea390b72d2b3426e8e4d9 (diff) | |
download | vyos-cloud-init-40a400e42603aa1b80d9f623bc779799b370c091.tar.gz vyos-cloud-init-40a400e42603aa1b80d9f623bc779799b370c091.zip |
subp: add 'update_env' argument
In order for a caller to use 'env' argument of subp, they
will realistically do:
env = os.environ.copy()
env['FOO'] = 'BZR'
subp(cmd, env=env)
This shortens that to be:
subp(cmd, update_env={'FOO': 'BZR'})
Add tests, and update growpart tests to use mock when playing with
os.environ.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 6c5cf741..05cb587c 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1762,7 +1762,7 @@ def delete_dir_contents(dirname): def subp(args, data=None, rcs=None, env=None, capture=True, shell=False, - logstring=False, decode="replace", target=None): + logstring=False, decode="replace", target=None, update_env=None): # not supported in cloud-init (yet), for now kept in the call signature # to ease maintaining code shared between cloud-init and curtin @@ -1773,6 +1773,13 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False, rcs = [0] devnull_fp = None + + if update_env: + if env is None: + env = os.environ + env = env.copy() + env.update(update_env) + try: if target_path(target) != "/": args = ['chroot', target] + list(args) |