Skip to content

Commit c86e935

Browse files
committed
New versions of supervisor may exit with status != 0
Now supervisorctl status exit with code 3 when service is not running. And exit with code 4 when it can't connect to supervisord socket.
1 parent 82f7bd6 commit c86e935

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

test/test_modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def test_supervisor(host, supervisorctl_path, supervisorctl_conf):
479479
assert services[0].supervisorctl_path == supervisorctl_path
480480
assert services[0].supervisorctl_conf == supervisorctl_conf
481481

482-
host.run("supervisorctl stop tail")
482+
host.check_output("supervisorctl stop tail")
483483
service = host.supervisor(
484484
"tail",
485485
supervisorctl_path=supervisorctl_path,

testinfra/modules/supervisor.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# limitations under the License.
1212

1313
from testinfra.modules.base import Module
14+
from typing import NoReturn
1415

1516
STATUS = [
1617
"STOPPED",
@@ -24,6 +25,10 @@
2425
]
2526

2627

28+
def supervisor_not_running() -> NoReturn:
29+
raise RuntimeError("Cannot get supervisor status. Is supervisor running ?")
30+
31+
2732
class Supervisor(Module):
2833
"""Test supervisor managed services
2934
@@ -60,11 +65,11 @@ def _parse_status(line):
6065
splitted = line.split()
6166
name = splitted[0]
6267
status = splitted[1]
63-
# supervisorctl exit status is 0 even if it cannot connect to
64-
# supervisord socket and output the error to stdout.
65-
# So we check that parsed status is a known status.
68+
# some old supervisorctl versions exit status is 0 even if it cannot
69+
# connect to supervisord socket and output the error to stdout. So we
70+
# check that parsed status is a known status.
6671
if status not in STATUS:
67-
raise RuntimeError("Cannot get supervisor status. Is supervisor running ?")
72+
supervisor_not_running()
6873
if status == "RUNNING":
6974
pid = splitted[3]
7075
if pid[-1] == ",":
@@ -79,16 +84,20 @@ def _parse_status(line):
7984
def _attrs(self):
8085
if self._attrs_cache is None:
8186
if self.supervisorctl_conf:
82-
line = self.check_output(
87+
out = self.run_expect(
88+
[0, 3, 4],
8389
"%s -c %s status %s",
8490
self.supervisorctl_path,
8591
self.supervisorctl_conf,
8692
self.name,
8793
)
8894
else:
89-
line = self.check_output(
90-
"%s status %s", self.supervisorctl_path, self.name
95+
out = self.run_expect(
96+
[0, 3, 4], "%s status %s", self.supervisorctl_path, self.name
9197
)
98+
if out.rc == 4:
99+
supervisor_not_running()
100+
line = out.stdout.rstrip("\r\n")
92101
attrs = self._parse_status(line)
93102
assert attrs["name"] == self.name
94103
self._attrs_cache = attrs

0 commit comments

Comments
 (0)