diff options
-rw-r--r-- | cloudinit/config/cc_growpart.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py index 2d01175f..1ddc9dc7 100644 --- a/cloudinit/config/cc_growpart.py +++ b/cloudinit/config/cc_growpart.py @@ -72,6 +72,7 @@ import stat from cloudinit import log as logging from cloudinit.settings import PER_ALWAYS from cloudinit import subp +from cloudinit import temp_utils from cloudinit import util frequency = PER_ALWAYS @@ -145,20 +146,29 @@ class ResizeGrowPart(object): myenv = os.environ.copy() myenv['LANG'] = 'C' before = get_size(partdev) - try: - subp.subp(["growpart", '--dry-run', diskdev, partnum], env=myenv) - except subp.ProcessExecutionError as e: - if e.exit_code != 1: - util.logexc(LOG, "Failed growpart --dry-run for (%s, %s)", - diskdev, partnum) - raise ResizeFailedException(e) from e - return (before, before) - try: - subp.subp(["growpart", diskdev, partnum], env=myenv) - except subp.ProcessExecutionError as e: - util.logexc(LOG, "Failed: growpart %s %s", diskdev, partnum) - raise ResizeFailedException(e) from e + # growpart uses tmp dir to store intermediate states + # and may conflict with systemd-tmpfiles-clean + with temp_utils.tempdir(needs_exe=True) as tmpd: + growpart_tmp = os.path.join(tmpd, "growpart") + if not os.path.exists(growpart_tmp): + os.mkdir(growpart_tmp, 0o700) + myenv['TMPDIR'] = growpart_tmp + try: + subp.subp(["growpart", '--dry-run', diskdev, partnum], + env=myenv) + except subp.ProcessExecutionError as e: + if e.exit_code != 1: + util.logexc(LOG, "Failed growpart --dry-run for (%s, %s)", + diskdev, partnum) + raise ResizeFailedException(e) from e + return (before, before) + + try: + subp.subp(["growpart", diskdev, partnum], env=myenv) + except subp.ProcessExecutionError as e: + util.logexc(LOG, "Failed: growpart %s %s", diskdev, partnum) + raise ResizeFailedException(e) from e return (before, get_size(partdev)) |