11
11
# limitations under the License.
12
12
13
13
from testinfra .modules .base import Module
14
+ from typing import NoReturn
14
15
15
16
STATUS = [
16
17
"STOPPED" ,
24
25
]
25
26
26
27
28
+ def supervisor_not_running () -> NoReturn :
29
+ raise RuntimeError ("Cannot get supervisor status. Is supervisor running ?" )
30
+
31
+
27
32
class Supervisor (Module ):
28
33
"""Test supervisor managed services
29
34
@@ -60,11 +65,11 @@ def _parse_status(line):
60
65
splitted = line .split ()
61
66
name = splitted [0 ]
62
67
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.
66
71
if status not in STATUS :
67
- raise RuntimeError ( "Cannot get supervisor status. Is supervisor running ?" )
72
+ supervisor_not_running ( )
68
73
if status == "RUNNING" :
69
74
pid = splitted [3 ]
70
75
if pid [- 1 ] == "," :
@@ -79,16 +84,20 @@ def _parse_status(line):
79
84
def _attrs (self ):
80
85
if self ._attrs_cache is None :
81
86
if self .supervisorctl_conf :
82
- line = self .check_output (
87
+ out = self .run_expect (
88
+ [0 , 3 , 4 ],
83
89
"%s -c %s status %s" ,
84
90
self .supervisorctl_path ,
85
91
self .supervisorctl_conf ,
86
92
self .name ,
87
93
)
88
94
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
91
97
)
98
+ if out .rc == 4 :
99
+ supervisor_not_running ()
100
+ line = out .stdout .rstrip ("\r \n " )
92
101
attrs = self ._parse_status (line )
93
102
assert attrs ["name" ] == self .name
94
103
self ._attrs_cache = attrs
0 commit comments