-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbase.py
More file actions
1220 lines (1018 loc) · 35.4 KB
/
base.py
File metadata and controls
1220 lines (1018 loc) · 35.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
_NOW = 1151365354
_TIMEFORMAT = '%b %d %I:%M %p'
import errno
import functools
import os
from supervisor.compat import Fault
from supervisor.compat import as_bytes
# mock is imported here for py2/3 compat. we only declare mock as a dependency
# via tests_require so it is not available on all supervisor installs. the
# modules imported in supervisor.compat must always be available.
try: # pragma: no cover
from unittest.mock import Mock, patch, sentinel
except ImportError: # pragma: no cover
from mock import Mock, patch, sentinel
try: # pragma: no cover
import unittest.mock as mock
except ImportError: # pragma: no cover
import mock
class DummyOptions:
loglevel = 20
minfds = 5
chdir_exception = None
fork_exception = None
execv_exception = None
kill_exception = None
make_pipes_exception = None
remove_exception = None
write_exception = None
def __init__(self):
self.identifier = 'supervisor'
self.childlogdir = '/tmp'
self.uid = 999
self.logger = self.getLogger()
self.backofflimit = 10
self.logfile = '/tmp/logfile'
self.nocleanup = False
self.strip_ansi = False
self.pidhistory = {}
self.process_group_configs = []
self.nodaemon = False
self.socket_map = {}
self.mood = 1
self.mustreopen = False
self.realizeargs = None
self.fds_cleaned_up = False
self.rlimit_set = False
self.setuid_called = False
self.httpservers_opened = False
self.signals_set = False
self.daemonized = False
self.make_logger_messages = None
self.autochildlogdir_cleared = False
self.cleaned_up = False
self.pidfile_written = False
self.directory = None
self.waitpid_return = None, None
self.kills = {}
self._signal = None
self.parent_pipes_closed = None
self.child_pipes_closed = None
self.forkpid = 0
self.pgrp_set = None
self.duped = {}
self.written = {}
self.fds_closed = []
self._exitcode = None
self.execve_called = False
self.execv_args = None
self.setuid_msg = None
self.privsdropped = None
self.logs_reopened = False
self.write_accept = None
self.tempfile_name = '/foo/bar'
self.removed = []
self.existing = []
self.openreturn = None
self.readfd_result = ''
self.parse_criticals = []
self.parse_warnings = []
self.parse_infos = []
self.serverurl = 'http://localhost:9001'
self.changed_directory = False
self.umaskset = None
self.poller = DummyPoller(self)
self.silent = False
def getLogger(self, *args, **kw):
logger = DummyLogger()
logger.handlers = [DummyLogger()]
logger.args = args, kw
return logger
def realize(self, args, **kw):
self.realizeargs = args
self.realizekw = kw
def process_config(self, do_usage=True):
pass
def cleanup_fds(self):
self.fds_cleaned_up = True
def set_rlimits_or_exit(self):
self.rlimits_set = True
self.parse_infos.append('rlimits_set')
def set_uid_or_exit(self):
self.setuid_called = True
self.parse_criticals.append('setuid_called')
def openhttpservers(self, supervisord):
self.httpservers_opened = True
def daemonize(self):
self.daemonized = True
def setsignals(self):
self.signals_set = True
def get_signal(self):
return self._signal
def get_socket_map(self):
return self.socket_map
def make_logger(self):
pass
def clear_autochildlogdir(self):
self.autochildlogdir_cleared = True
def get_autochildlog_name(self, *ignored):
return self.tempfile_name
def cleanup(self):
self.cleaned_up = True
def write_pidfile(self):
self.pidfile_written = True
def waitpid(self):
return self.waitpid_return
def kill(self, pid, sig):
if self.kill_exception is not None:
raise self.kill_exception
self.kills[pid] = sig
def stat(self, filename):
import os
return os.stat(filename)
def get_path(self):
return ["/bin", "/usr/bin", "/usr/local/bin"]
def get_pid(self):
import os
return os.getpid()
def check_execv_args(self, filename, argv, st):
if filename == '/bad/filename':
from supervisor.options import NotFound
raise NotFound('bad filename')
def make_pipes(self, stderr=True):
if self.make_pipes_exception is not None:
raise self.make_pipes_exception
pipes = {'child_stdin': 3, 'stdin': 4, 'stdout': 5, 'child_stdout': 6}
if stderr:
pipes['stderr'], pipes['child_stderr'] = (7, 8)
else:
pipes['stderr'], pipes['child_stderr'] = None, None
return pipes
def write(self, fd, chars):
if self.write_exception is not None:
raise self.write_exception
if self.write_accept:
chars = chars[self.write_accept]
data = self.written.setdefault(fd, '')
data += chars
self.written[fd] = data
return len(chars)
def fork(self):
if self.fork_exception is not None:
raise self.fork_exception
return self.forkpid
def close_fd(self, fd):
self.fds_closed.append(fd)
def close_parent_pipes(self, pipes):
self.parent_pipes_closed = pipes
def close_child_pipes(self, pipes):
self.child_pipes_closed = pipes
def setpgrp(self):
self.pgrp_set = True
def dup2(self, frm, to):
self.duped[frm] = to
def _exit(self, code):
self._exitcode = code
def execve(self, filename, argv, environment):
self.execve_called = True
if self.execv_exception is not None:
raise self.execv_exception
self.execv_args = (filename, argv)
self.execv_environment = environment
def drop_privileges(self, uid):
if self.setuid_msg:
return self.setuid_msg
self.privsdropped = uid
def readfd(self, fd):
return self.readfd_result
def reopenlogs(self):
self.logs_reopened = True
def mktempfile(self, prefix, suffix, dir):
return self.tempfile_name
def remove(self, path):
import os
if self.remove_exception is not None:
raise self.remove_exception
self.removed.append(path)
def exists(self, path):
if path in self.existing:
return True
return False
def open(self, name, mode='r'):
if self.openreturn:
return self.openreturn
return open(name, mode)
def chdir(self, dir):
if self.chdir_exception is not None:
raise self.chdir_exception
self.changed_directory = True
def setumask(self, mask):
self.umaskset = mask
class DummyLogger:
level = None
def __init__(self):
self.reopened = False
self.removed = False
self.closed = False
self.data = []
def info(self, msg, **kw):
if kw:
msg = msg % kw
self.data.append(msg)
warn = debug = critical = trace = error = blather = info
def log(self, level, msg, **kw):
if kw:
msg = msg % kw
self.data.append(msg)
def addHandler(self, handler):
handler.close()
def reopen(self):
self.reopened = True
def close(self):
self.closed = True
def remove(self):
self.removed = True
def flush(self):
self.flushed = True
def getvalue(self):
return ''.join(self.data)
class DummySupervisor:
def __init__(self, options=None, state=None, process_groups=None):
if options is None:
self.options = DummyOptions()
else:
self.options = options
if state is None:
from supervisor.supervisord import SupervisorStates
self.options.mood = SupervisorStates.RUNNING
else:
self.options.mood = state
if process_groups is None:
self.process_groups = {}
else:
self.process_groups = process_groups
def get_state(self):
return self.options.mood
class DummySocket:
bind_called = False
bind_addr = None
listen_called = False
listen_backlog = None
close_called = False
def __init__(self, fd):
self.fd = fd
def fileno(self):
return self.fd
def bind(self, addr):
self.bind_called = True
self.bind_addr = addr
def listen(self, backlog):
self.listen_called = True
self.listen_backlog = backlog
def close(self):
self.close_called = True
def __str__(self):
return 'dummy socket'
class DummySocketConfig:
def __init__(self, fd, backlog=128):
self.fd = fd
self.backlog = backlog
self.url = 'unix:///sock'
def addr(self):
return 'dummy addr'
def __eq__(self, other):
return self.fd == other.fd
def __ne__(self, other):
return not self.__eq__(other)
def get_backlog(self):
return self.backlog
def create_and_bind(self):
return DummySocket(self.fd)
class DummySocketManager:
def __init__(self, config, **kwargs):
self._config = config
def config(self):
return self._config
def get_socket(self):
return DummySocket(self._config.fd)
@functools.total_ordering
class DummyProcess(object):
write_exception = None
# Initial state; overridden by instance variables
pid = 0 # Subprocess pid; 0 when not running
laststart = 0 # Last time the subprocess was started; 0 if never
laststop = 0 # Last time the subprocess was stopped; 0 if never
delay = 0 # If nonzero, delay starting or killing until this time
administrative_stop = False # true if the process stopped by an admin
system_stop = False # true if the process has been stopped by the system
killing = False # flag determining whether we are trying to kill this proc
backoff = 0 # backoff counter (to backofflimit)
waitstatus = None
exitstatus = None
pipes = None
rpipes = None
dispatchers = None
stdout_logged = ''
stderr_logged = ''
spawnerr = None
stdout_buffer = '' # buffer of characters from child stdout output to log
stderr_buffer = '' # buffer of characters from child stderr output to log
stdin_buffer = '' # buffer of characters to send to child process' stdin
listener_state = None
group = None
sent_signal = None
def __init__(self, config, state=None):
self.config = config
self.logsremoved = False
self.stop_called = False
self.stop_report_called = True
self.backoff_secs = None
self.spawned = False
if state is None:
from supervisor.process import ProcessStates
state = ProcessStates.RUNNING
self.state = state
self.error_at_clear = False
self.killed_with = None
self.drained = False
self.stdout_buffer = as_bytes('')
self.stderr_buffer = as_bytes('')
self.stdout_logged = as_bytes('')
self.stderr_logged = as_bytes('')
self.stdin_buffer = as_bytes('')
self.pipes = {}
self.rpipes = {}
self.dispatchers = {}
self.finished = None
self.logs_reopened = False
self.execv_arg_exception = None
self.input_fd_drained = None
self.output_fd_drained = None
self.transitioned = False
def reopenlogs(self):
self.logs_reopened = True
def removelogs(self):
if self.error_at_clear:
raise IOError('whatever')
self.logsremoved = True
def get_state(self):
return self.state
def stop(self):
self.stop_called = True
self.killing = False
from supervisor.process import ProcessStates
self.state = ProcessStates.STOPPED
def stop_report(self):
self.stop_report_called = True
def kill(self, signal):
self.killed_with = signal
def signal(self, signal):
self.sent_signal = signal
def spawn(self):
self.spawned = True
from supervisor.process import ProcessStates
self.state = ProcessStates.RUNNING
def drain(self):
self.drained = True
def readable_fds(self):
return []
def record_output(self):
self.stdout_logged += self.stdout_buffer
self.stdout_buffer = ''
self.stderr_logged += self.stderr_buffer
self.stderr_buffer = ''
def finish(self, pid, sts):
self.finished = pid, sts
def give_up(self):
from supervisor.process import ProcessStates
self.state = ProcessStates.FATAL
def get_execv_args(self):
if self.execv_arg_exception:
raise self.execv_arg_exception('whatever')
import shlex
commandargs = shlex.split(self.config.command)
program = commandargs[0]
return program, commandargs
def drain_output_fd(self, fd):
self.output_fd_drained = fd
def drain_input_fd(self, fd):
self.input_fd_drained = fd
def write(self, chars):
if self.write_exception is not None:
raise self.write_exception
self.stdin_buffer += chars
def transition(self):
self.transitioned = True
def __eq__(self, other):
return self.config.priority == other.config.priority
def __lt__(self, other):
return self.config.priority < other.config.priority
class DummyPConfig:
def __init__(self, options, name, command, directory=None, umask=None,
priority=999, autostart=True,
autorestart=True, startsecs=10, startretries=999,
uid=None, stdout_logfile=None, stdout_capture_maxbytes=0,
stdout_events_enabled=False,
stdout_logfile_backups=0, stdout_logfile_maxbytes=0,
stdout_syslog=False,
stderr_logfile=None, stderr_capture_maxbytes=0,
stderr_events_enabled=False,
stderr_logfile_backups=0, stderr_logfile_maxbytes=0,
stderr_syslog=False,
redirect_stderr=False,
stopsignal=None, stopwaitsecs=10, stopasgroup=False, killasgroup=False,
exitcodes=(0,), environment=None, environment_file=None, environment_loader=None,
serverurl=None):
self.options = options
self.name = name
self.command = command
self.priority = priority
self.autostart = autostart
self.autorestart = autorestart
self.startsecs = startsecs
self.startretries = startretries
self.uid = uid
self.stdout_logfile = stdout_logfile
self.stdout_capture_maxbytes = stdout_capture_maxbytes
self.stdout_events_enabled = stdout_events_enabled
self.stdout_logfile_backups = stdout_logfile_backups
self.stdout_logfile_maxbytes = stdout_logfile_maxbytes
self.stdout_syslog = stdout_syslog
self.stderr_logfile = stderr_logfile
self.stderr_capture_maxbytes = stderr_capture_maxbytes
self.stderr_events_enabled = stderr_events_enabled
self.stderr_logfile_backups = stderr_logfile_backups
self.stderr_logfile_maxbytes = stderr_logfile_maxbytes
self.stderr_syslog = stderr_syslog
self.redirect_stderr = redirect_stderr
if stopsignal is None:
import signal
stopsignal = signal.SIGTERM
self.stopsignal = stopsignal
self.stopwaitsecs = stopwaitsecs
self.stopasgroup = stopasgroup
self.killasgroup = killasgroup
self.exitcodes = exitcodes
self.environment = environment
self.environment_file = environment_file
self.environment_loader = environment_loader
self.directory = directory
self.umask = umask
self.autochildlogs_created = False
self.serverurl = serverurl
def get_path(self):
return ["/bin", "/usr/bin", "/usr/local/bin"]
def create_autochildlogs(self):
self.autochildlogs_created = True
def make_process(self, group=None):
process = DummyProcess(self)
process.group = group
return process
def make_dispatchers(self, proc):
use_stderr = not self.redirect_stderr
pipes = self.options.make_pipes(use_stderr)
stdout_fd,stderr_fd,stdin_fd = (pipes['stdout'],pipes['stderr'],
pipes['stdin'])
dispatchers = {}
if stdout_fd is not None:
dispatchers[stdout_fd] = DummyDispatcher(readable=True)
if stderr_fd is not None:
dispatchers[stderr_fd] = DummyDispatcher(readable=True)
if stdin_fd is not None:
dispatchers[stdin_fd] = DummyDispatcher(writable=True)
return dispatchers, pipes
def load_external_environment_definition(self):
from supervisor.options import ProcessConfig
return ProcessConfig.load_external_environment_definition_for_config(self)
def makeExecutable(file, substitutions=None):
import os
import sys
import tempfile
if substitutions is None:
substitutions = {}
data = open(file).read()
last = os.path.split(file)[1]
substitutions['PYTHON'] = sys.executable
for key in substitutions.keys():
data = data.replace('<<%s>>' % key.upper(), substitutions[key])
tmpnam = tempfile.mktemp(prefix=last)
with open(tmpnam, 'w') as f:
f.write(data)
os.chmod(tmpnam, 0o755)
return tmpnam
def makeSpew(unkillable=False):
import os
here = os.path.dirname(__file__)
if not unkillable:
return makeExecutable(os.path.join(here, 'fixtures/spew.py'))
return makeExecutable(os.path.join(here, 'fixtures/unkillable_spew.py'))
class DummyMedusaServerLogger:
def __init__(self):
self.logged = []
def log(self, category, msg):
self.logged.append((category, msg))
class DummyMedusaServer:
def __init__(self):
self.logger = DummyMedusaServerLogger()
class DummyMedusaChannel:
def __init__(self):
self.server = DummyMedusaServer()
self.producer = None
def push_with_producer(self, producer):
self.producer = producer
def close_when_done(self):
pass
def set_terminator(self, terminator):
pass
class DummyRequest(object):
command = 'GET'
_error = None
_done = False
version = '1.0'
def __init__(self, path, params, query, fragment, env=None):
self.args = path, params, query, fragment
self.producers = []
self.headers = {}
self.header = []
self.outgoing = []
self.channel = DummyMedusaChannel()
if env is None:
self.env = {}
else:
self.env = env
def split_uri(self):
return self.args
def error(self, code):
self._error = code
def push(self, producer):
self.producers.append(producer)
def __setitem__(self, header, value):
self.headers[header] = value
def __getitem__(self, header):
return self.headers[header]
def __delitem__(self, header):
del self.headers[header]
def has_key(self, header):
return header in self.headers
def __contains__(self, item):
return item in self.headers
def done(self):
self._done = True
def build_reply_header(self):
return ''
def log(self, *arg, **kw):
pass
def cgi_environment(self):
return self.env
def get_server_url(self):
return 'http://example.com'
class DummyRPCInterfaceFactory:
def __init__(self, supervisord, **config):
self.supervisord = supervisord
self.config = config
class DummyRPCServer:
def __init__(self):
self.supervisor = DummySupervisorRPCNamespace()
self.system = DummySystemRPCNamespace()
class DummySystemRPCNamespace:
pass
class DummySupervisorRPCNamespace:
_restartable = True
_restarted = False
_shutdown = False
_readlog_error = False
from supervisor.process import ProcessStates
all_process_info = [
{
'name':'foo',
'group':'foo',
'pid':11,
'state':ProcessStates.RUNNING,
'statename':'RUNNING',
'start':_NOW - 100,
'stop':0,
'spawnerr':'',
'now':_NOW,
'description':'foo description',
},
{
'name':'bar',
'group':'bar',
'pid':12,
'state':ProcessStates.FATAL,
'statename':'FATAL',
'start':_NOW - 100,
'stop':_NOW - 50,
'spawnerr':'screwed',
'now':_NOW,
'description':'bar description',
},
{
'name':'baz_01',
'group':'baz',
'pid':13,
'state':ProcessStates.STOPPED,
'statename':'STOPPED',
'start':_NOW - 100,
'stop':_NOW - 25,
'spawnerr':'',
'now':_NOW,
'description':'baz description',
},
]
def getAPIVersion(self):
return '3.0'
getVersion = getAPIVersion # deprecated
def getPID(self):
return 42
def _read_log(self, channel, name, offset, length):
from supervisor import xmlrpc
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
elif name == 'FAILED':
raise Fault(xmlrpc.Faults.FAILED, 'FAILED')
elif name == 'NO_FILE':
raise Fault(xmlrpc.Faults.NO_FILE, 'NO_FILE')
a = (channel + ' line\n') * 10
return a[offset:]
def readProcessStdoutLog(self, name, offset, length):
return self._read_log('stdout', name, offset, length)
readProcessLog = readProcessStdoutLog
def readProcessStderrLog(self, name, offset, length):
return self._read_log('stderr', name, offset, length)
def getAllProcessInfo(self):
return self.all_process_info
def getProcessInfo(self, name):
from supervisor import xmlrpc
for i in self.all_process_info:
if i['name']==name:
info=i
return info
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
if name == 'FAILED':
raise Fault(xmlrpc.Faults.FAILED, 'FAILED')
if name == 'NO_FILE':
raise Fault(xmlrpc.Faults.NO_FILE, 'NO_FILE')
def startProcess(self, name):
from supervisor import xmlrpc
if name == 'BAD_NAME:BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME:BAD_NAME')
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
if name == 'NO_FILE':
raise Fault(xmlrpc.Faults.NO_FILE, 'NO_FILE')
if name == 'NOT_EXECUTABLE':
raise Fault(xmlrpc.Faults.NOT_EXECUTABLE, 'NOT_EXECUTABLE')
if name == 'ALREADY_STARTED':
raise Fault(xmlrpc.Faults.ALREADY_STARTED, 'ALREADY_STARTED')
if name == 'SPAWN_ERROR':
raise Fault(xmlrpc.Faults.SPAWN_ERROR, 'SPAWN_ERROR')
if name == 'ABNORMAL_TERMINATION':
raise Fault(xmlrpc.Faults.ABNORMAL_TERMINATION,
'ABNORMAL_TERMINATION')
return True
def startProcessGroup(self, name):
from supervisor import xmlrpc
from supervisor.compat import Fault
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
return [
{'name':'foo_00', 'group':'foo',
'status': xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'foo_01', 'group':'foo',
'status':xmlrpc.Faults.SUCCESS,
'description': 'OK'},
]
def startAllProcesses(self):
from supervisor import xmlrpc
return [
{'name':'foo', 'group':'foo',
'status': xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'foo2', 'group':'foo2',
'status':xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'failed', 'group':'failed_group',
'status':xmlrpc.Faults.SPAWN_ERROR,
'description':'SPAWN_ERROR'}
]
def stopProcessGroup(self, name):
from supervisor import xmlrpc
from supervisor.compat import Fault
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
return [
{'name':'foo_00', 'group':'foo',
'status': xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'foo_01', 'group':'foo',
'status':xmlrpc.Faults.SUCCESS,
'description': 'OK'},
]
def stopProcess(self, name):
from supervisor import xmlrpc
if name == 'BAD_NAME:BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME:BAD_NAME')
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
if name == 'NOT_RUNNING':
raise Fault(xmlrpc.Faults.NOT_RUNNING, 'NOT_RUNNING')
if name == 'FAILED':
raise Fault(xmlrpc.Faults.FAILED, 'FAILED')
return True
def stopAllProcesses(self):
from supervisor import xmlrpc
return [
{'name':'foo','group':'foo',
'status': xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'foo2', 'group':'foo2',
'status':xmlrpc.Faults.SUCCESS,'description': 'OK'},
{'name':'failed', 'group':'failed_group',
'status':xmlrpc.Faults.BAD_NAME,
'description':'FAILED'}
]
def restart(self):
if self._restartable:
self._restarted = True
return
from supervisor import xmlrpc
raise Fault(xmlrpc.Faults.SHUTDOWN_STATE, '')
def shutdown(self):
if self._restartable:
self._shutdown = True
return
from supervisor import xmlrpc
raise Fault(xmlrpc.Faults.SHUTDOWN_STATE, '')
def reloadConfig(self):
return [[['added'], ['changed'], ['removed']]]
def addProcessGroup(self, name):
from supervisor import xmlrpc
if name == 'ALREADY_ADDED':
raise Fault(xmlrpc.Faults.ALREADY_ADDED, '')
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, '')
if name == 'FAILED':
raise Fault(xmlrpc.Faults.FAILED, '')
if name == 'SHUTDOWN_STATE':
raise Fault(xmlrpc.Faults.SHUTDOWN_STATE, '')
if hasattr(self, 'processes'):
self.processes.append(name)
else:
self.processes = [name]
def removeProcessGroup(self, name):
from supervisor import xmlrpc
if name == 'STILL_RUNNING':
raise Fault(xmlrpc.Faults.STILL_RUNNING, '')
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, '')
if name == 'FAILED':
raise Fault(xmlrpc.Faults.FAILED, '')
self.processes.remove(name)
def clearProcessStdoutLog(self, name):
from supervisor import xmlrpc
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
return True
clearProcessLog = clearProcessStdoutLog
clearProcessStderrLog = clearProcessStdoutLog
clearProcessLogs = clearProcessStdoutLog
def clearAllProcessLogs(self):
from supervisor import xmlrpc
return [
{'name':'foo',
'group':'foo',
'status':xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'foo2',
'group':'foo2',
'status':xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'failed',
'group':'failed_group',
'status':xmlrpc.Faults.FAILED,
'description':'FAILED'}
]
def raiseError(self):
raise ValueError('error')
def getXmlRpcUnmarshallable(self):
return {'stdout_logfile': None} # None is unmarshallable
def getSupervisorVersion(self):
return '3000'
def readLog(self, whence, offset):
if self._readlog_error:
raise Fault(self._readlog_error, '')
return 'mainlogdata'
def signalProcessGroup(self, name, signal):
from supervisor import xmlrpc
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
return [
{'name':'foo_00',
'group':'foo',
'status': xmlrpc.Faults.SUCCESS,
'description': 'OK'},
{'name':'foo_01',
'group':'foo',
'status':xmlrpc.Faults.SUCCESS,
'description': 'OK'},
]
def signalProcess(self, name, signal):
from supervisor import xmlrpc
if signal == 'BAD_SIGNAL':
raise Fault(xmlrpc.Faults.BAD_SIGNAL, 'BAD_SIGNAL')
if name == 'BAD_NAME:BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME:BAD_NAME')
if name == 'BAD_NAME':
raise Fault(xmlrpc.Faults.BAD_NAME, 'BAD_NAME')
if name == 'NOT_RUNNING':
raise Fault(xmlrpc.Faults.NOT_RUNNING, 'NOT_RUNNING')
if name == 'FAILED':
raise Fault(xmlrpc.Faults.FAILED, 'FAILED')
return True