]>
Commit | Line | Data |
---|---|---|
1911f103 TL |
1 | import json |
2 | ||
3 | import pytest | |
4 | ||
5 | from ceph.deployment.service_spec import ServiceSpec, RGWSpec, PlacementSpec | |
6 | from orchestrator import DaemonDescription, OrchestratorError | |
7 | ||
8 | ||
9 | def test_spec_octopus(): | |
10 | # https://tracker.ceph.com/issues/44934 | |
11 | # Those are real user data from early octopus. | |
12 | # Please do not modify those JSON values. | |
13 | specs_text = """[ | |
14 | { | |
15 | "placement": { | |
16 | "count": 1 | |
17 | }, | |
18 | "service_type": "alertmanager" | |
19 | }, | |
20 | { | |
21 | "placement": { | |
22 | "host_pattern": "*" | |
23 | }, | |
24 | "service_type": "crash" | |
25 | }, | |
26 | { | |
27 | "placement": { | |
28 | "count": 1 | |
29 | }, | |
30 | "service_type": "grafana" | |
31 | }, | |
32 | { | |
33 | "placement": { | |
34 | "count": 2 | |
35 | }, | |
36 | "service_type": "mgr" | |
37 | }, | |
38 | { | |
39 | "placement": { | |
40 | "count": 5 | |
41 | }, | |
42 | "service_type": "mon" | |
43 | }, | |
44 | { | |
45 | "placement": { | |
46 | "host_pattern": "*" | |
47 | }, | |
48 | "service_type": "node-exporter" | |
49 | }, | |
50 | { | |
51 | "placement": { | |
52 | "count": 1 | |
53 | }, | |
54 | "service_type": "prometheus" | |
55 | }, | |
56 | { | |
57 | "placement": { | |
58 | "hosts": [ | |
59 | { | |
60 | "hostname": "ceph-001", | |
61 | "network": "", | |
62 | "name": "" | |
63 | } | |
64 | ] | |
65 | }, | |
66 | "service_type": "rgw", | |
67 | "service_id": "default-rgw-realm.eu-central-1.1", | |
68 | "rgw_realm": "default-rgw-realm", | |
69 | "rgw_zone": "eu-central-1", | |
70 | "subcluster": "1" | |
71 | } | |
72 | ] | |
73 | """ | |
74 | dds_text = """[ | |
75 | { | |
76 | "hostname": "ceph-001", | |
77 | "container_id": "d94d7969094d", | |
78 | "container_image_id": "0881eb8f169f5556a292b4e2c01d683172b12830a62a9225a98a8e206bb734f0", | |
79 | "container_image_name": "docker.io/prom/alertmanager:latest", | |
80 | "daemon_id": "ceph-001", | |
81 | "daemon_type": "alertmanager", | |
82 | "version": "0.20.0", | |
83 | "status": 1, | |
84 | "status_desc": "running", | |
85 | "last_refresh": "2020-04-03T15:31:48.725856", | |
86 | "created": "2020-04-02T19:23:08.829543", | |
87 | "started": "2020-04-03T07:29:16.932838" | |
88 | }, | |
89 | { | |
90 | "hostname": "ceph-001", | |
91 | "container_id": "c4b036202241", | |
92 | "container_image_id": "204a01f9b0b6710dd0c0af7f37ce7139c47ff0f0105d778d7104c69282dfbbf1", | |
93 | "container_image_name": "docker.io/ceph/ceph:v15", | |
94 | "daemon_id": "ceph-001", | |
95 | "daemon_type": "crash", | |
96 | "version": "15.2.0", | |
97 | "status": 1, | |
98 | "status_desc": "running", | |
99 | "last_refresh": "2020-04-03T15:31:48.725903", | |
100 | "created": "2020-04-02T19:23:11.390694", | |
101 | "started": "2020-04-03T07:29:16.910897" | |
102 | }, | |
103 | { | |
104 | "hostname": "ceph-001", | |
105 | "container_id": "5b7b94b48f31", | |
106 | "container_image_id": "87a51ecf0b1c9a7b187b21c1b071425dafea0d765a96d5bc371c791169b3d7f4", | |
107 | "container_image_name": "docker.io/ceph/ceph-grafana:latest", | |
108 | "daemon_id": "ceph-001", | |
109 | "daemon_type": "grafana", | |
110 | "version": "6.6.2", | |
111 | "status": 1, | |
112 | "status_desc": "running", | |
113 | "last_refresh": "2020-04-03T15:31:48.725950", | |
114 | "created": "2020-04-02T19:23:52.025088", | |
115 | "started": "2020-04-03T07:29:16.847972" | |
116 | }, | |
117 | { | |
118 | "hostname": "ceph-001", | |
119 | "container_id": "9ca007280456", | |
120 | "container_image_id": "204a01f9b0b6710dd0c0af7f37ce7139c47ff0f0105d778d7104c69282dfbbf1", | |
121 | "container_image_name": "docker.io/ceph/ceph:v15", | |
122 | "daemon_id": "ceph-001.gkjwqp", | |
123 | "daemon_type": "mgr", | |
124 | "version": "15.2.0", | |
125 | "status": 1, | |
126 | "status_desc": "running", | |
127 | "last_refresh": "2020-04-03T15:31:48.725807", | |
128 | "created": "2020-04-02T19:22:18.648584", | |
129 | "started": "2020-04-03T07:29:16.856153" | |
130 | }, | |
131 | { | |
132 | "hostname": "ceph-001", | |
133 | "container_id": "3d1ba9a2b697", | |
134 | "container_image_id": "204a01f9b0b6710dd0c0af7f37ce7139c47ff0f0105d778d7104c69282dfbbf1", | |
135 | "container_image_name": "docker.io/ceph/ceph:v15", | |
136 | "daemon_id": "ceph-001", | |
137 | "daemon_type": "mon", | |
138 | "version": "15.2.0", | |
139 | "status": 1, | |
140 | "status_desc": "running", | |
141 | "last_refresh": "2020-04-03T15:31:48.725715", | |
142 | "created": "2020-04-02T19:22:13.863300", | |
143 | "started": "2020-04-03T07:29:17.206024" | |
144 | }, | |
145 | { | |
146 | "hostname": "ceph-001", | |
147 | "container_id": "36d026c68ba1", | |
148 | "container_image_id": "e5a616e4b9cf68dfcad7782b78e118be4310022e874d52da85c55923fb615f87", | |
149 | "container_image_name": "docker.io/prom/node-exporter:latest", | |
150 | "daemon_id": "ceph-001", | |
151 | "daemon_type": "node-exporter", | |
152 | "version": "0.18.1", | |
153 | "status": 1, | |
154 | "status_desc": "running", | |
155 | "last_refresh": "2020-04-03T15:31:48.725996", | |
156 | "created": "2020-04-02T19:23:53.880197", | |
157 | "started": "2020-04-03T07:29:16.880044" | |
158 | }, | |
159 | { | |
160 | "hostname": "ceph-001", | |
161 | "container_id": "faf76193cbfe", | |
162 | "container_image_id": "204a01f9b0b6710dd0c0af7f37ce7139c47ff0f0105d778d7104c69282dfbbf1", | |
163 | "container_image_name": "docker.io/ceph/ceph:v15", | |
164 | "daemon_id": "0", | |
165 | "daemon_type": "osd", | |
166 | "version": "15.2.0", | |
167 | "status": 1, | |
168 | "status_desc": "running", | |
169 | "last_refresh": "2020-04-03T15:31:48.726088", | |
170 | "created": "2020-04-02T20:35:02.991435", | |
171 | "started": "2020-04-03T07:29:19.373956" | |
172 | }, | |
173 | { | |
174 | "hostname": "ceph-001", | |
175 | "container_id": "f82505bae0f1", | |
176 | "container_image_id": "204a01f9b0b6710dd0c0af7f37ce7139c47ff0f0105d778d7104c69282dfbbf1", | |
177 | "container_image_name": "docker.io/ceph/ceph:v15", | |
178 | "daemon_id": "1", | |
179 | "daemon_type": "osd", | |
180 | "version": "15.2.0", | |
181 | "status": 1, | |
182 | "status_desc": "running", | |
183 | "last_refresh": "2020-04-03T15:31:48.726134", | |
184 | "created": "2020-04-02T20:35:17.142272", | |
185 | "started": "2020-04-03T07:29:19.374002" | |
186 | }, | |
187 | { | |
188 | "hostname": "ceph-001", | |
189 | "container_id": "2708d84cd484", | |
190 | "container_image_id": "358a0d2395fe711bb8258e8fb4b2d7865c0a9a6463969bcd1452ee8869ea6653", | |
191 | "container_image_name": "docker.io/prom/prometheus:latest", | |
192 | "daemon_id": "ceph-001", | |
193 | "daemon_type": "prometheus", | |
194 | "version": "2.17.1", | |
195 | "status": 1, | |
196 | "status_desc": "running", | |
197 | "last_refresh": "2020-04-03T15:31:48.726042", | |
198 | "created": "2020-04-02T19:24:10.281163", | |
199 | "started": "2020-04-03T07:29:16.926292" | |
200 | }, | |
201 | { | |
202 | "hostname": "ceph-001", | |
203 | "daemon_id": "default-rgw-realm.eu-central-1.1.ceph-001.ytywjo", | |
204 | "daemon_type": "rgw", | |
205 | "status": 1, | |
206 | "status_desc": "starting" | |
207 | } | |
208 | ]""" | |
209 | specs_json = json.loads(specs_text) | |
210 | dds_json = json.loads(dds_text) | |
211 | specs = [ServiceSpec.from_json(j) for j in specs_json] | |
212 | dds = [DaemonDescription.from_json(j) for j in dds_json] | |
213 | ||
214 | # just some verification that we can sill read old octopus specs | |
215 | def remove_service_name(j): | |
216 | if 'service_name' in j: | |
217 | j_c = j.copy() | |
218 | del j_c['service_name'] | |
219 | return j_c | |
220 | return j | |
221 | assert specs_json == [remove_service_name(s.to_json()) for s in specs] | |
222 | assert dds_json == [d.to_json() for d in dds] | |
223 | ||
224 | ||
225 | @pytest.mark.parametrize("spec,dd,valid", | |
226 | [ | |
227 | ( | |
228 | # https://tracker.ceph.com/issues/44934 | |
229 | RGWSpec( | |
230 | rgw_realm="default-rgw-realm", | |
231 | rgw_zone="eu-central-1", | |
232 | subcluster='1', | |
233 | ), | |
234 | DaemonDescription( | |
235 | daemon_type='rgw', | |
236 | daemon_id="default-rgw-realm.eu-central-1.1.ceph-001.ytywjo", | |
237 | hostname="ceph-001", | |
238 | ), | |
239 | True | |
240 | ), | |
241 | ( | |
242 | # no subcluster | |
243 | RGWSpec( | |
244 | rgw_realm="default-rgw-realm", | |
245 | rgw_zone="eu-central-1", | |
246 | ), | |
247 | DaemonDescription( | |
248 | daemon_type='rgw', | |
249 | daemon_id="default-rgw-realm.eu-central-1.ceph-001.ytywjo", | |
250 | hostname="ceph-001", | |
251 | ), | |
252 | True | |
253 | ), | |
254 | ( | |
255 | # with tld | |
256 | RGWSpec( | |
257 | rgw_realm="default-rgw-realm", | |
258 | rgw_zone="eu-central-1", | |
259 | subcluster='1', | |
260 | ), | |
261 | DaemonDescription( | |
262 | daemon_type='rgw', | |
263 | daemon_id="default-rgw-realm.eu-central-1.1.host.domain.tld.ytywjo", | |
264 | hostname="host.domain.tld", | |
265 | ), | |
266 | True | |
267 | ), | |
268 | ( | |
269 | # without host | |
270 | RGWSpec( | |
271 | service_type='rgw', | |
272 | rgw_realm="default-rgw-realm", | |
273 | rgw_zone="eu-central-1", | |
274 | subcluster='1', | |
275 | ), | |
276 | DaemonDescription( | |
277 | daemon_type='rgw', | |
278 | daemon_id="default-rgw-realm.eu-central-1.1.hostname.ytywjo", | |
279 | hostname=None, | |
280 | ), | |
281 | False | |
282 | ), | |
283 | ]) | |
284 | def test_rgw_service_name(spec: RGWSpec, dd: DaemonDescription, valid): | |
285 | if valid: | |
286 | assert spec.service_name() == dd.service_name() | |
287 | else: | |
288 | with pytest.raises(OrchestratorError): | |
289 | dd.service_name() | |
290 |