Merge ~smoser/cloud-init:feature/integration-execute-with-string into cloud-init:master

Proposed by Scott Moser on 2017-09-08
Status: Rejected
Rejected by: Scott Moser on 2017-09-13
Proposed branch: ~smoser/cloud-init:feature/integration-execute-with-string
Merge into: cloud-init:master
Diff against target: 46 lines (+8/-2)
2 files modified
tests/cloud_tests/instances/base.py (+2/-1)
tests/cloud_tests/instances/lxd.py (+6/-1)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing on 2017-09-08
Joshua Powers (community) Approve on 2017-09-08
cloud-init commiters 2017-09-08 Pending
Review via email: mp+330459@code.launchpad.net

Commit Message

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.

To post a comment you must log in.
Joshua Powers (powersj) wrote :

+1 thanks for this it makes it a lot easier on simple commands.

review: Approve

FAILED: Continuous integration, rev:bfcb291233812bdd34aed9b798d3330cf01d9a92
https://jenkins.ubuntu.com/server/job/cloud-init-ci/276/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/276/rebuild

review: Needs Fixing (continuous-integration)
Scott Moser (smoser) wrote :

Unmerged commits

bfcb291... by Scott Moser on 2017-09-08

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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/cloud_tests/instances/base.py b/tests/cloud_tests/instances/base.py
2index 959e9cc..1af3571 100644
3--- a/tests/cloud_tests/instances/base.py
4+++ b/tests/cloud_tests/instances/base.py
5@@ -23,7 +23,7 @@ class Instance(object):
6 self.config = config
7 self.features = features
8
9- def execute(self, command, stdout=None, stderr=None, env={},
10+ def execute(self, command, stdout=None, stderr=None, env=None,
11 rcs=None, description=None):
12 """Execute command in instance, recording output, error and exit code.
13
14@@ -31,6 +31,7 @@ class Instance(object):
15 target filesystem being available at /.
16
17 @param command: the command to execute as root inside the image
18+ if command is an string, then it will be executed as: [sh, -c, command]
19 @param stdout, stderr: file handles to write output and error to
20 @param env: environment variables
21 @param rcs: allowed return codes from command
22diff --git a/tests/cloud_tests/instances/lxd.py b/tests/cloud_tests/instances/lxd.py
23index b9c2cc6..6b72d62 100644
24--- a/tests/cloud_tests/instances/lxd.py
25+++ b/tests/cloud_tests/instances/lxd.py
26@@ -31,7 +31,7 @@ class LXDInstance(base.Instance):
27 self._pylxd_container.sync()
28 return self._pylxd_container
29
30- def execute(self, command, stdout=None, stderr=None, env={},
31+ def execute(self, command, stdout=None, stderr=None, env=None,
32 rcs=None, description=None):
33 """Execute command in instance, recording output, error and exit code.
34
35@@ -46,6 +46,11 @@ class LXDInstance(base.Instance):
36 @param description: purpose of command
37 @return_value: tuple containing stdout data, stderr data, exit code
38 """
39+ if env is None:
40+ env = {}
41+ if isinstance(command, str):
42+ command = ["sh", "-c", command]
43+
44 # ensure instance is running and execute the command
45 self.start()
46 res = self.pylxd_container.execute(command, environment=env)

Subscribers

People subscribed via source and target branches

to all changes: