commit 76c603f2e66e80d296d12a5ce0c9dd2519028a46 (HEAD -> master)
Author: Scott Moser <smoser@brickies.net>
Date: Fri Sep 8 21:01:18 2017 +0000
tests: execute: support command as a string, change default env parm.
If a string is passed to execute, then invoke 'sh', '-c', 'string'.
That allows the less verbose execution of simple commands:
image.execute("ls /run")
compared to the more explicit but longer winded:
image.execute(["ls", "/run"])
If 'env' was ever modified in execute or a method that it called,
then the next invocation's default value would be changed. Instead
use None and then set to a new empty dict in the method.
diff --git a/tests/cloud_tests/instances/base.py b/tests/cloud_tests/instances/base.py
index 959e9cce..1e2ff86c 100644
--- a/tests/cloud_tests/instances/base.py
+++ b/tests/cloud_tests/instances/base.py
@@ -23,7 +23,7 @@ class Instance(object):
self.config = config
self.features = features
- def execute(self, command, stdout=None, stderr=None, env={},
+ def execute(self, command, stdout=None, stderr=None, env=None,
rcs=None, description=None):
"""Execute command in instance, recording output, error and exit code.
diff --git a/tests/cloud_tests/instances/lxd.py b/tests/cloud_tests/instances/lxd.py
index b9c2cc6b..6b72d624 100644
--- a/tests/cloud_tests/instances/lxd.py
+++ b/tests/cloud_tests/instances/lxd.py
@@ -31,7 +31,7 @@ class LXDInstance(base.Instance):
self._pylxd_container.sync()
return self._pylxd_container
- def execute(self, command, stdout=None, stderr=None, env={},
+ def execute(self, command, stdout=None, stderr=None, env=None,
rcs=None, description=None):
"""Execute command in instance, recording output, error and exit code.
@@ -46,6 +46,11 @@ class LXDInstance(base.Instance):
@param description: purpose of command
@return_value: tuple containing stdout data, stderr data, exit code
"""
+ if env is None:
+ env = {}
+ if isinstance(command, str):
+ command = ["sh", "-c", command]
+
# ensure instance is running and execute the command
self.start()
res = self.pylxd_container.execute(command, environment=env)