Skip to content

Commit 4e24a3b

Browse files
committed
Merge pull request #595 from edsantiago/run_cgroup_parent_err_msg
docker run --cgroup-parent: error message change
2 parents 8ad2461 + 440da60 commit 4e24a3b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[docker_cli/run_cgroup_parent]
22
subsubtests = run_cgroup_parent_invalid_name,run_cgroup_parent_path,run_cgroup_parent_path_with_hyphens
3+
4+
[docker_cli/run_cgroup_parent/run_cgroup_parent_invalid_name]
5+
#: Regex describing the error message we expect. Passed to re.match().
6+
expect_stderr = (docker: )?Error response from daemon: cgroup-parent for systemd cgroup should be a valid slice named as "xxx.slice"\.

subtests/docker_cli/run_cgroup_parent/run_cgroup_parent.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _setup(self, cg_parent):
4040
self.sub_stuff['rand2'] = utils.generate_random_string(8)
4141
self.sub_stuff['cgroup_parent'] = cg_parent.format(**self.sub_stuff)
4242

43-
def _expect(self, path=None, stderr=None):
43+
def _expect(self, path=None, stderr=None, exit_status=0):
4444
"""
4545
Set up test parameters: what to expect on completion.
4646
The format strings {rand1} and {rand2} will be replaced with the
@@ -49,6 +49,7 @@ def _expect(self, path=None, stderr=None):
4949
"""
5050
self.sub_stuff['expected_path'] = path if path else ''
5151
self.sub_stuff['expected_stderr'] = stderr if stderr else ''
52+
self.sub_stuff['expected_status'] = exit_status
5253

5354
def run_once(self):
5455
"""
@@ -72,7 +73,8 @@ def postprocess(self):
7273
super(run_cgroup_parent_base, self).postprocess()
7374

7475
cmdresult = self.sub_stuff["cmdresult"]
75-
OutputGood(cmdresult, ignore_error=True)
76+
expected_status = self.sub_stuff["expected_status"]
77+
OutputGood(cmdresult, ignore_error=(expected_status != 0))
7678

7779
self.sub_stuff["cid"] = self._read_cid()
7880
path_exp = self.sub_stuff['expected_path'].format(**self.sub_stuff)
@@ -86,7 +88,13 @@ def postprocess(self):
8688
stderr = "\n".join([line
8789
for line in cmdresult.stderr.strip().split("\n")
8890
if not line.startswith('time="')])
89-
self.failif_ne(stderr, stderr_exp, "stderr")
91+
if stderr_exp:
92+
re_stderr = re.compile(stderr_exp)
93+
if not re.match(re_stderr, stderr):
94+
raise DockerTestFail("expected '%s' not found in stderr ('%s')"
95+
% (stderr_exp, stderr))
96+
else:
97+
self.failif_ne(stderr, stderr_exp, "unexpected stderr")
9098

9199
# If we're expecting stdout, it must contain multiple lines each
92100
# of the form:
@@ -112,6 +120,9 @@ def postprocess(self):
112120
else:
113121
self.failif_ne(stdout, '', "unexpected output on stdout")
114122

123+
# Check exit code last: the stdout/stderr diagnostics are more helpful
124+
self.failif_ne(cmdresult.exit_status, expected_status, "exit status")
125+
115126
def _read_cid(self):
116127
"""
117128
Read container ID from --cidfile file, so we can replace {cid}
@@ -161,9 +172,7 @@ class run_cgroup_parent_invalid_name(run_cgroup_parent_base):
161172
def initialize(self):
162173
super(run_cgroup_parent_invalid_name, self).initialize()
163174
self._setup("/{rand1}")
164-
self._expect(stderr="Error response from daemon:"
165-
" Cannot start container {cid}: [8] System error:"
166-
" Invalid slice name /{rand1}")
175+
self._expect(stderr=self.config['expect_stderr'], exit_status=125)
167176

168177

169178
class run_cgroup_parent_path(run_cgroup_parent_base):

0 commit comments

Comments
 (0)