]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/mgr/test_orchestrator_cli.py
5232af29905e6e294e78b3e1d7ed55c42273c2c7
[ceph.git] / ceph / qa / tasks / mgr / test_orchestrator_cli.py
1 import errno
2 import json
3 import logging
4 from time import sleep
5
6 from teuthology.exceptions import CommandFailedError
7
8 from mgr_test_case import MgrTestCase
9
10
11 log = logging.getLogger(__name__)
12
13
14 class TestOrchestratorCli(MgrTestCase):
15 MGRS_REQUIRED = 1
16
17 def _cmd(self, module, *args):
18 return self.mgr_cluster.mon_manager.raw_cluster_cmd(module, *args)
19
20 def _orch_cmd(self, *args):
21 return self._cmd("orch", *args)
22
23 def _progress_cmd(self, *args):
24 return self.mgr_cluster.mon_manager.raw_cluster_cmd("progress", *args)
25
26 def _orch_cmd_result(self, *args, **kwargs):
27 """
28 raw_cluster_cmd doesn't support kwargs.
29 """
30 return self.mgr_cluster.mon_manager.raw_cluster_cmd_result("orch", *args, **kwargs)
31
32 def _test_orchestrator_cmd_result(self, *args, **kwargs):
33 return self.mgr_cluster.mon_manager.raw_cluster_cmd_result("test_orchestrator", *args, **kwargs)
34
35 def setUp(self):
36 super(TestOrchestratorCli, self).setUp()
37
38 self._load_module("orchestrator")
39 self._load_module("test_orchestrator")
40 self._orch_cmd("set", "backend", "test_orchestrator")
41
42 def test_status(self):
43 ret = self._orch_cmd("status")
44 self.assertIn("test_orchestrator", ret)
45
46 def test_device_ls(self):
47 ret = self._orch_cmd("device", "ls")
48 self.assertIn("localhost", ret)
49
50 def test_device_ls_refresh(self):
51 ret = self._orch_cmd("device", "ls", "--refresh")
52 self.assertIn("localhost", ret)
53
54 def test_device_ls_hoshs(self):
55 ret = self._orch_cmd("device", "ls", "localhost", "host1")
56 self.assertIn("localhost", ret)
57
58
59 def test_device_ls_json(self):
60 ret = self._orch_cmd("device", "ls", "--format", "json")
61 self.assertIn("localhost", ret)
62 self.assertIsInstance(json.loads(ret), list)
63
64 def test_ps(self):
65 ret = self._orch_cmd("ps")
66 self.assertIn("mgr", ret)
67
68 def test_ps_json(self):
69 ret = self._orch_cmd("ps", "--format", "json")
70 self.assertIsInstance(json.loads(ret), list)
71 self.assertIn("mgr", ret)
72
73
74 def test_service_action(self):
75 self._orch_cmd("restart", "mds.cephfs")
76 self._orch_cmd("stop", "mds.cephfs")
77 self._orch_cmd("start", "mds.cephfs")
78
79 def test_service_instance_action(self):
80 self._orch_cmd("daemon", "restart", "mds.a")
81 self._orch_cmd("daemon", "stop", "mds.a")
82 self._orch_cmd("daemon", "start", "mds.a")
83
84 def test_osd_create(self):
85 drive_group = """
86 service_type: osd
87 service_id: any.sda
88 placement:
89 host_pattern: '*'
90 data_devices:
91 all: True
92 """
93 res = self._orch_cmd_result("apply", "osd", "-i", "-",
94 stdin=drive_group)
95 self.assertEqual(res, 0)
96
97 def test_blink_device_light(self):
98 def _ls_lights(what):
99 return json.loads(self._cmd("device", "ls-lights"))[what]
100
101 metadata = json.loads(self._cmd("osd", "metadata"))
102 dev_name_ids = [osd["device_ids"] for osd in metadata]
103 _, dev_id = [d.split('=') for d in dev_name_ids if len(d.split('=')) == 2][0]
104
105 for t in ["ident", "fault"]:
106 self.assertNotIn(dev_id, _ls_lights(t))
107 self._cmd("device", "light", "on", dev_id, t)
108 self.assertIn(dev_id, _ls_lights(t))
109
110 health = {
111 'ident': 'DEVICE_IDENT_ON',
112 'fault': 'DEVICE_FAULT_ON',
113 }[t]
114 self.wait_for_health(health, 30)
115
116 self._cmd("device", "light", "off", dev_id, t)
117 self.assertNotIn(dev_id, _ls_lights(t))
118
119 self.wait_for_health_clear(30)
120
121 def test_mds_add(self):
122 self._orch_cmd('daemon', 'add', 'mds', 'fsname')
123
124 def test_rgw_add(self):
125 self._orch_cmd('daemon', 'add', 'rgw', 'realm', 'zone')
126
127 def test_nfs_add(self):
128 self._orch_cmd('daemon', 'add', "nfs", "service_name", "pool", "--namespace", "ns")
129 self._orch_cmd('daemon', 'add', "nfs", "service_name", "pool")
130
131 def test_osd_rm(self):
132 self._orch_cmd('daemon', "rm", "osd.0", '--force')
133
134 def test_mds_rm(self):
135 self._orch_cmd("daemon", "rm", "mds.fsname")
136
137 def test_rgw_rm(self):
138 self._orch_cmd("daemon", "rm", "rgw.myrealm.myzone")
139
140 def test_nfs_rm(self):
141 self._orch_cmd("daemon", "rm", "nfs.service_name")
142
143 def test_host_ls(self):
144 out = self._orch_cmd("host", "ls", "--format=json")
145 hosts = json.loads(out)
146 self.assertEqual(len(hosts), 1)
147 self.assertEqual(hosts[0]["hostname"], "localhost")
148
149 def test_host_add(self):
150 self._orch_cmd("host", "add", "hostname")
151
152 def test_host_rm(self):
153 self._orch_cmd("host", "rm", "hostname")
154
155 def test_mon_update(self):
156 self._orch_cmd("apply", "mon", "3 host1:1.2.3.0/24 host2:1.2.3.0/24 host3:10.0.0.0/8")
157 self._orch_cmd("apply", "mon", "3 host1:1.2.3.4 host2:1.2.3.4 host3:10.0.0.1")
158
159 def test_mgr_update(self):
160 self._orch_cmd("apply", "mgr", "3")
161
162 def test_nfs_update(self):
163 self._orch_cmd("apply", "nfs", "service_name", "2")
164
165 def test_error(self):
166 ret = self._orch_cmd_result("host", "add", "raise_no_support")
167 self.assertEqual(ret, errno.ENOENT)
168 ret = self._orch_cmd_result("host", "add", "raise_bug")
169 self.assertEqual(ret, errno.EINVAL)
170 ret = self._orch_cmd_result("host", "add", "raise_not_implemented")
171 self.assertEqual(ret, errno.ENOENT)
172 ret = self._orch_cmd_result("host", "add", "raise_no_orchestrator")
173 self.assertEqual(ret, errno.ENOENT)
174 ret = self._orch_cmd_result("host", "add", "raise_import_error")
175 self.assertEqual(ret, errno.ENOENT)
176
177 def test_load_data(self):
178 data = {
179 'inventory': [
180 {
181 'name': 'host0',
182 'devices': [
183 {
184 'type': 'hdd',
185 'id': '/dev/sda',
186 'size': 1024**4 * 4,
187 'rotates': True
188 }
189 ]
190 },
191 {
192 'name': 'host1',
193 'devices': [
194 {
195 'type': 'hdd',
196 'id': '/dev/sda',
197 'size': 1024**4 * 4,
198 'rotates': True
199 }
200 ]
201 }
202 ],
203 'daemons': [
204 {
205 'hostname': 'host0',
206 'daemon_type': 'mon',
207 'daemon_id': 'a'
208 },
209 {
210 'hostname': 'host1',
211 'daemon_type': 'osd',
212 'daemon_id': '1'
213 }
214 ]
215 }
216
217 ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin=json.dumps(data))
218 self.assertEqual(ret, 0)
219 out = self._orch_cmd('device', 'ls', '--format=json')
220 inventory = data['inventory']
221 inventory_result = json.loads(out)
222 self.assertEqual(len(inventory), len(inventory_result))
223
224 out = self._orch_cmd('device', 'ls', 'host0', '--format=json')
225 inventory_result = json.loads(out)
226 self.assertEqual(len(inventory_result), 1)
227 self.assertEqual(inventory_result[0]['name'], 'host0')
228
229 out = self._orch_cmd('ps', '--format=json')
230 daemons = data['daemons']
231 daemons_result = json.loads(out)
232 self.assertEqual(len(daemons), len(daemons_result))
233
234 out = self._orch_cmd('ps', 'host0', '--format=json')
235 daemons_result = json.loads(out)
236 self.assertEqual(len(daemons_result), 1)
237 self.assertEqual(daemons_result[0]['hostname'], 'host0')
238
239 # test invalid input file: invalid json
240 json_str = '{ "inventory: '
241 ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin=json_str)
242 self.assertEqual(ret, errno.EINVAL)
243
244 # test invalid input file: missing key
245 json_str = '{ "inventory": [{"devices": []}] }'
246 ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin=json_str)
247 self.assertEqual(ret, errno.EINVAL)
248
249 # load empty data for other tests
250 ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin='{}')
251 self.assertEqual(ret, 0)