sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #05882
[Merge] ~maas-committers/maas-ci/+git/system-tests:add-pwd-to-lxc-exec into ~maas-committers/maas-ci/+git/system-tests:master
Jack Lloyd-Walters has proposed merging ~maas-committers/maas-ci/+git/system-tests:add-pwd-to-lxc-exec into ~maas-committers/maas-ci/+git/system-tests:master.
Commit message:
[Systemtests] add working directory support to `lxc.Instance.execute()` and `lxc.Instance.quietly_execute()`
Requested reviews:
MAAS Lander (maas-lander): unittests
MAAS Committers (maas-committers)
For more details, see:
https://code.launchpad.net/~maas-committers/maas-ci/+git/system-tests/+merge/438703
--
Your team MAAS Committers is requested to review the proposed merge of ~maas-committers/maas-ci/+git/system-tests:add-pwd-to-lxc-exec into ~maas-committers/maas-ci/+git/system-tests:master.
diff --git a/systemtests/lxd.py b/systemtests/lxd.py
index cd91678..87b996d 100644
--- a/systemtests/lxd.py
+++ b/systemtests/lxd.py
@@ -178,11 +178,13 @@ class Instance:
) -> Instance:
return self._lxd.create_container(self.name, image, user_data, profile)
- def _get_lxc_command(self, environment: Optional[dict[str, str]]) -> list[str]:
+ def _get_lxc_command(self, environment: Optional[dict[str, str]], working_dir: Optional[str]) -> list[str]:
lxc_command = ["lxc", "exec", "--force-noninteractive", self._instance_name]
if environment is not None:
for key, value in environment.items():
lxc_command.extend(["--env", f"{key}={value}"])
+ if working_dir is not None:
+ lxc_command.extend(["--cwd", working_dir])
lxc_command.append("--")
return lxc_command
@@ -210,21 +212,21 @@ class Instance:
return _retry_bad_handshake()
def execute(
- self, command: list[str], environment: Optional[dict[str, str]] = None
+ self, command: list[str], environment: Optional[dict[str, str]] = None, working_dir: Optional[str] = None,
) -> subprocess.CompletedProcess[str]:
__tracebackhide__ = True
- lxc_command = self._get_lxc_command(environment)
+ lxc_command = self._get_lxc_command(environment, working_dir)
# Suppress logging of the lxc wrapper for clearer logs
executor = partial(self._run, command, prefix=lxc_command)
return self._run_with_logger(executor, self.logger)
def quietly_execute(
- self, command: list[str], environment: Optional[dict[str, str]] = None
+ self, command: list[str], environment: Optional[dict[str, str]] = None, working_dir: Optional[str] = None,
) -> subprocess.CompletedProcess[str]:
"""Execute a command without logging it."""
__tracebackhide__ = True
- lxc_command = self._get_lxc_command(environment)
+ lxc_command = self._get_lxc_command(environment, working_dir)
executor = partial(
subprocess.run,