-
Notifications
You must be signed in to change notification settings - Fork 119
/
test_marathon_groups.py
160 lines (119 loc) · 4.91 KB
/
test_marathon_groups.py
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
import json
from common import (assert_command, exec_command, list_deployments,
watch_deployment)
def test_add_group():
_add_group('tests/data/marathon/groups/good.json')
_list_groups('test-group/sleep/goodnight')
result = list_deployments(None, 'test-group/sleep/goodnight')
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
_remove_group('test-group')
def test_validate_complicated_group_and_app():
_add_group('tests/data/marathon/groups/complicated.json')
result = list_deployments(None, 'test-group/moregroups/moregroups/sleep1')
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
_remove_group('test-group')
def test_optional_add_group():
assert_command(['dcos', 'marathon', 'group', 'add',
'tests/data/marathon/groups/good.json'])
_list_groups('test-group/sleep/goodnight')
result = list_deployments(None, 'test-group/sleep/goodnight')
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
_remove_group('test-group')
def test_add_existing_group():
_add_group('tests/data/marathon/groups/good.json')
result = list_deployments(None, 'test-group/sleep/goodnight')
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
with open('tests/data/marathon/groups/good.json') as fd:
stderr = b"Group '/test-group' already exists\n"
assert_command(['dcos', 'marathon', 'group', 'add'],
returncode=1,
stderr=stderr,
stdin=fd)
result = list_deployments(None, 'test-group/sleep/goodnight')
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
_remove_group('test-group')
def test_show_group():
_add_group('tests/data/marathon/groups/good.json')
_list_groups('test-group/sleep/goodnight')
result = list_deployments(None, 'test-group/sleep/goodnight')
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
_show_group('test-group')
_remove_group('test-group')
def test_add_bad_app():
with open('tests/data/marathon/groups/bad_app.json') as fd:
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'group', 'add'],
stdin=fd)
expected = "Error: Additional properties are not allowed" + \
" ('badtype' was unexpected)"
assert returncode == 1
assert stdout == b''
assert stderr.decode('utf-8').startswith(expected)
def test_add_bad_group():
with open('tests/data/marathon/groups/bad_group.json') as fd:
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'group', 'add'],
stdin=fd)
expected = "Error: Additional properties are not allowed" + \
" ('fakeapp' was unexpected)"
assert returncode == 1
assert stdout == b''
assert stderr.decode('utf-8').startswith(expected)
def test_add_bad_complicated_group():
with open('tests/data/marathon/groups/complicated_bad.json') as fd:
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'group', 'add'],
stdin=fd)
err = "Error: missing required property 'id'"
assert returncode == 1
assert stdout == b''
assert err in stderr.decode('utf-8')
def _list_groups(group_id=None):
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'group', 'list'])
result = json.loads(stdout.decode('utf-8'))
if group_id is None:
assert len(result) == 0
else:
groups = None
for g in group_id.split("/")[:-1]:
if groups is None:
result = result[0]
groups = "/{}".format(g)
else:
result = result['groups'][0]
groups += g
assert result['id'] == groups
groups += "/"
assert result['apps'][0]['id'] == "/" + group_id
assert returncode == 0
assert stderr == b''
return result
def _remove_group(group_id):
assert_command(['dcos', 'marathon', 'group', 'remove', group_id])
# Let's make sure that we don't return until the deployment has finished
result = list_deployments(None, group_id)
if len(result) != 0:
watch_deployment(result[0]['id'], 60)
def _add_group(file_path):
with open(file_path) as fd:
assert_command(['dcos', 'marathon', 'group', 'add'], stdin=fd)
def _show_group(group_id, version=None):
if version is None:
cmd = ['dcos', 'marathon', 'group', 'show', group_id]
else:
cmd = ['dcos', 'marathon', 'group', 'show',
'--group-version={}'.format(version), group_id]
returncode, stdout, stderr = exec_command(cmd)
result = json.loads(stdout.decode('utf-8'))
assert returncode == 0
assert isinstance(result, dict)
assert result['id'] == '/' + group_id
assert stderr == b''
return result