-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathchaos.py
More file actions
56 lines (45 loc) · 1.24 KB
/
chaos.py
File metadata and controls
56 lines (45 loc) · 1.24 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
import random
CREATE_ERROR_RATE = 0
DESTROY_ERROR_RATE = 0
START_ERROR_RATE = 0
STOP_ERROR_RATE = 0
class ChaosSchedulerClient(object):
def __init__(self, target, auth, options, pkey):
self.target = target
self.auth = auth
self.options = options
self.pkey = pkey
# job api
def create(self, name, image, command, **kwargs):
if random.random() < CREATE_ERROR_RATE:
raise RuntimeError
return True
def start(self, name):
"""
Start an idle job
"""
if random.random() < START_ERROR_RATE:
raise RuntimeError
return True
def stop(self, name):
"""
Stop a running job
"""
if random.random() < STOP_ERROR_RATE:
raise RuntimeError
return True
def destroy(self, name):
"""
Destroy an existing job
"""
if random.random() < DESTROY_ERROR_RATE:
raise RuntimeError
return True
def run(self, name, image, entrypoint, command):
"""
Run a one-off command
"""
if random.random() < CREATE_ERROR_RATE:
raise RuntimeError('exit code 1')
return 0, ''
SchedulerClient = ChaosSchedulerClient