]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/mgr/test_orchestrator_cli.py
5232af29905e6e294e78b3e1d7ed55c42273c2c7
6 from teuthology
.exceptions
import CommandFailedError
8 from mgr_test_case
import MgrTestCase
11 log
= logging
.getLogger(__name__
)
14 class TestOrchestratorCli(MgrTestCase
):
17 def _cmd(self
, module
, *args
):
18 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(module
, *args
)
20 def _orch_cmd(self
, *args
):
21 return self
._cmd
("orch", *args
)
23 def _progress_cmd(self
, *args
):
24 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("progress", *args
)
26 def _orch_cmd_result(self
, *args
, **kwargs
):
28 raw_cluster_cmd doesn't support kwargs.
30 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd_result("orch", *args
, **kwargs
)
32 def _test_orchestrator_cmd_result(self
, *args
, **kwargs
):
33 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd_result("test_orchestrator", *args
, **kwargs
)
36 super(TestOrchestratorCli
, self
).setUp()
38 self
._load
_module
("orchestrator")
39 self
._load
_module
("test_orchestrator")
40 self
._orch
_cmd
("set", "backend", "test_orchestrator")
42 def test_status(self
):
43 ret
= self
._orch
_cmd
("status")
44 self
.assertIn("test_orchestrator", ret
)
46 def test_device_ls(self
):
47 ret
= self
._orch
_cmd
("device", "ls")
48 self
.assertIn("localhost", ret
)
50 def test_device_ls_refresh(self
):
51 ret
= self
._orch
_cmd
("device", "ls", "--refresh")
52 self
.assertIn("localhost", ret
)
54 def test_device_ls_hoshs(self
):
55 ret
= self
._orch
_cmd
("device", "ls", "localhost", "host1")
56 self
.assertIn("localhost", ret
)
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)
65 ret
= self
._orch
_cmd
("ps")
66 self
.assertIn("mgr", ret
)
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
)
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")
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")
84 def test_osd_create(self
):
93 res
= self
._orch
_cmd
_result
("apply", "osd", "-i", "-",
95 self
.assertEqual(res
, 0)
97 def test_blink_device_light(self
):
99 return json
.loads(self
._cmd
("device", "ls-lights"))[what
]
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]
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
))
111 'ident': 'DEVICE_IDENT_ON',
112 'fault': 'DEVICE_FAULT_ON',
114 self
.wait_for_health(health
, 30)
116 self
._cmd
("device", "light", "off", dev_id
, t
)
117 self
.assertNotIn(dev_id
, _ls_lights(t
))
119 self
.wait_for_health_clear(30)
121 def test_mds_add(self
):
122 self
._orch
_cmd
('daemon', 'add', 'mds', 'fsname')
124 def test_rgw_add(self
):
125 self
._orch
_cmd
('daemon', 'add', 'rgw', 'realm', 'zone')
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")
131 def test_osd_rm(self
):
132 self
._orch
_cmd
('daemon', "rm", "osd.0", '--force')
134 def test_mds_rm(self
):
135 self
._orch
_cmd
("daemon", "rm", "mds.fsname")
137 def test_rgw_rm(self
):
138 self
._orch
_cmd
("daemon", "rm", "rgw.myrealm.myzone")
140 def test_nfs_rm(self
):
141 self
._orch
_cmd
("daemon", "rm", "nfs.service_name")
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")
149 def test_host_add(self
):
150 self
._orch
_cmd
("host", "add", "hostname")
152 def test_host_rm(self
):
153 self
._orch
_cmd
("host", "rm", "hostname")
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")
159 def test_mgr_update(self
):
160 self
._orch
_cmd
("apply", "mgr", "3")
162 def test_nfs_update(self
):
163 self
._orch
_cmd
("apply", "nfs", "service_name", "2")
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
)
177 def test_load_data(self
):
206 'daemon_type': 'mon',
211 'daemon_type': 'osd',
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
))
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')
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
))
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')
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
)
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
)
249 # load empty data for other tests
250 ret
= self
._test
_orchestrator
_cmd
_result
('load_data', '-i', '-', stdin
='{}')
251 self
.assertEqual(ret
, 0)