2019-02-13 14:01:25 +00:00
|
|
|
import errno
|
2019-01-28 15:57:38 +00:00
|
|
|
import json
|
2018-11-23 13:55:15 +00:00
|
|
|
import logging
|
2019-09-09 09:21:54 +00:00
|
|
|
from time import sleep
|
2019-01-28 15:57:38 +00:00
|
|
|
|
|
|
|
from teuthology.exceptions import CommandFailedError
|
2018-11-23 13:55:15 +00:00
|
|
|
|
2020-03-27 05:57:37 +00:00
|
|
|
from .mgr_test_case import MgrTestCase
|
2018-11-23 13:55:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrchestratorCli(MgrTestCase):
|
|
|
|
MGRS_REQUIRED = 1
|
|
|
|
|
2019-03-05 14:46:34 +00:00
|
|
|
def _cmd(self, module, *args):
|
|
|
|
return self.mgr_cluster.mon_manager.raw_cluster_cmd(module, *args)
|
|
|
|
|
2018-11-23 13:55:15 +00:00
|
|
|
def _orch_cmd(self, *args):
|
2020-02-07 19:20:42 +00:00
|
|
|
return self._cmd("orch", *args)
|
2019-01-28 15:57:38 +00:00
|
|
|
|
2019-02-26 16:27:53 +00:00
|
|
|
def _progress_cmd(self, *args):
|
|
|
|
return self.mgr_cluster.mon_manager.raw_cluster_cmd("progress", *args)
|
|
|
|
|
2019-01-28 15:57:38 +00:00
|
|
|
def _orch_cmd_result(self, *args, **kwargs):
|
|
|
|
"""
|
2019-02-13 14:01:25 +00:00
|
|
|
raw_cluster_cmd doesn't support kwargs.
|
2019-01-28 15:57:38 +00:00
|
|
|
"""
|
2020-02-07 19:20:42 +00:00
|
|
|
return self.mgr_cluster.mon_manager.raw_cluster_cmd_result("orch", *args, **kwargs)
|
2018-11-23 13:55:15 +00:00
|
|
|
|
2019-08-12 03:58:43 +00:00
|
|
|
def _test_orchestrator_cmd_result(self, *args, **kwargs):
|
|
|
|
return self.mgr_cluster.mon_manager.raw_cluster_cmd_result("test_orchestrator", *args, **kwargs)
|
|
|
|
|
2018-11-23 13:55:15 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestOrchestratorCli, self).setUp()
|
|
|
|
|
2020-01-24 12:08:02 +00:00
|
|
|
self._load_module("orchestrator")
|
2018-11-23 13:55:15 +00:00
|
|
|
self._load_module("test_orchestrator")
|
|
|
|
self._orch_cmd("set", "backend", "test_orchestrator")
|
|
|
|
|
|
|
|
def test_status(self):
|
|
|
|
ret = self._orch_cmd("status")
|
|
|
|
self.assertIn("test_orchestrator", ret)
|
|
|
|
|
|
|
|
def test_device_ls(self):
|
|
|
|
ret = self._orch_cmd("device", "ls")
|
2019-12-20 22:14:34 +00:00
|
|
|
self.assertIn("localhost", ret)
|
2018-11-23 13:55:15 +00:00
|
|
|
|
2019-02-08 23:25:55 +00:00
|
|
|
def test_device_ls_refresh(self):
|
|
|
|
ret = self._orch_cmd("device", "ls", "--refresh")
|
2019-12-20 22:14:34 +00:00
|
|
|
self.assertIn("localhost", ret)
|
2019-02-08 23:25:55 +00:00
|
|
|
|
2019-01-22 15:30:01 +00:00
|
|
|
def test_device_ls_hoshs(self):
|
|
|
|
ret = self._orch_cmd("device", "ls", "localhost", "host1")
|
2019-12-20 22:14:34 +00:00
|
|
|
self.assertIn("localhost", ret)
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_device_ls_json(self):
|
|
|
|
ret = self._orch_cmd("device", "ls", "--format", "json")
|
|
|
|
self.assertIn("localhost", ret)
|
|
|
|
self.assertIsInstance(json.loads(ret), list)
|
|
|
|
|
2020-02-11 16:01:33 +00:00
|
|
|
def test_ps(self):
|
|
|
|
ret = self._orch_cmd("ps")
|
2020-03-05 14:00:42 +00:00
|
|
|
self.assertIn("mgr", ret)
|
2018-12-21 06:06:57 +00:00
|
|
|
|
2020-02-11 16:01:33 +00:00
|
|
|
def test_ps_json(self):
|
|
|
|
ret = self._orch_cmd("ps", "--format", "json")
|
2019-01-22 15:30:01 +00:00
|
|
|
self.assertIsInstance(json.loads(ret), list)
|
2020-03-05 14:00:42 +00:00
|
|
|
self.assertIn("mgr", ret)
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
|
2018-12-21 06:06:57 +00:00
|
|
|
def test_service_action(self):
|
2020-03-01 17:52:36 +00:00
|
|
|
self._orch_cmd("restart", "mds.cephfs")
|
|
|
|
self._orch_cmd("stop", "mds.cephfs")
|
|
|
|
self._orch_cmd("start", "mds.cephfs")
|
2018-12-21 06:06:57 +00:00
|
|
|
|
|
|
|
def test_service_instance_action(self):
|
2020-03-01 17:52:36 +00:00
|
|
|
self._orch_cmd("daemon", "restart", "mds.a")
|
|
|
|
self._orch_cmd("daemon", "stop", "mds.a")
|
|
|
|
self._orch_cmd("daemon", "start", "mds.a")
|
2019-01-28 15:57:38 +00:00
|
|
|
|
|
|
|
def test_osd_create(self):
|
2020-03-13 19:29:01 +00:00
|
|
|
drive_group = """
|
|
|
|
service_type: osd
|
|
|
|
service_id: any.sda
|
|
|
|
placement:
|
|
|
|
host_pattern: '*'
|
|
|
|
data_devices:
|
|
|
|
all: True
|
|
|
|
"""
|
|
|
|
res = self._orch_cmd_result("apply", "osd", "-i", "-",
|
|
|
|
stdin=drive_group)
|
2019-02-13 14:01:25 +00:00
|
|
|
self.assertEqual(res, 0)
|
2019-01-28 15:57:38 +00:00
|
|
|
|
2019-03-05 14:46:34 +00:00
|
|
|
def test_blink_device_light(self):
|
|
|
|
def _ls_lights(what):
|
|
|
|
return json.loads(self._cmd("device", "ls-lights"))[what]
|
|
|
|
|
|
|
|
metadata = json.loads(self._cmd("osd", "metadata"))
|
|
|
|
dev_name_ids = [osd["device_ids"] for osd in metadata]
|
|
|
|
_, dev_id = [d.split('=') for d in dev_name_ids if len(d.split('=')) == 2][0]
|
|
|
|
|
|
|
|
for t in ["ident", "fault"]:
|
|
|
|
self.assertNotIn(dev_id, _ls_lights(t))
|
2019-10-25 13:31:07 +00:00
|
|
|
self._cmd("device", "light", "on", dev_id, t)
|
2019-03-05 14:46:34 +00:00
|
|
|
self.assertIn(dev_id, _ls_lights(t))
|
2019-05-02 09:59:42 +00:00
|
|
|
|
|
|
|
health = {
|
|
|
|
'ident': 'DEVICE_IDENT_ON',
|
|
|
|
'fault': 'DEVICE_FAULT_ON',
|
|
|
|
}[t]
|
|
|
|
self.wait_for_health(health, 30)
|
|
|
|
|
2019-10-25 13:31:07 +00:00
|
|
|
self._cmd("device", "light", "off", dev_id, t)
|
2019-03-05 14:46:34 +00:00
|
|
|
self.assertNotIn(dev_id, _ls_lights(t))
|
|
|
|
|
2019-05-02 09:59:42 +00:00
|
|
|
self.wait_for_health_clear(30)
|
|
|
|
|
2019-01-22 15:30:01 +00:00
|
|
|
def test_mds_add(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd('daemon', 'add', 'mds', 'fsname')
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
def test_rgw_add(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd('daemon', 'add', 'rgw', 'realm', 'zone')
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
def test_nfs_add(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd('daemon', 'add', "nfs", "service_name", "pool", "--namespace", "ns")
|
|
|
|
self._orch_cmd('daemon', 'add', "nfs", "service_name", "pool")
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
def test_osd_rm(self):
|
2020-03-14 14:10:13 +00:00
|
|
|
self._orch_cmd('daemon', "rm", "osd.0", '--force')
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
def test_mds_rm(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd("daemon", "rm", "mds.fsname")
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
def test_rgw_rm(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd("daemon", "rm", "rgw.myrealm.myzone")
|
2019-01-22 15:30:01 +00:00
|
|
|
|
|
|
|
def test_nfs_rm(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd("daemon", "rm", "nfs.service_name")
|
2019-02-07 11:23:51 +00:00
|
|
|
|
|
|
|
def test_host_ls(self):
|
2019-12-02 08:07:18 +00:00
|
|
|
out = self._orch_cmd("host", "ls", "--format=json")
|
|
|
|
hosts = json.loads(out)
|
|
|
|
self.assertEqual(len(hosts), 1)
|
2020-02-22 01:16:06 +00:00
|
|
|
self.assertEqual(hosts[0]["hostname"], "localhost")
|
2019-02-07 11:23:51 +00:00
|
|
|
|
|
|
|
def test_host_add(self):
|
|
|
|
self._orch_cmd("host", "add", "hostname")
|
|
|
|
|
|
|
|
def test_host_rm(self):
|
|
|
|
self._orch_cmd("host", "rm", "hostname")
|
|
|
|
|
|
|
|
def test_mon_update(self):
|
2020-03-05 01:18:06 +00:00
|
|
|
self._orch_cmd("apply", "mon", "3 host1:1.2.3.0/24 host2:1.2.3.0/24 host3:10.0.0.0/8")
|
|
|
|
self._orch_cmd("apply", "mon", "3 host1:1.2.3.4 host2:1.2.3.4 host3:10.0.0.1")
|
2019-02-07 11:23:51 +00:00
|
|
|
|
|
|
|
def test_mgr_update(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd("apply", "mgr", "3")
|
2019-02-25 14:21:08 +00:00
|
|
|
|
|
|
|
def test_nfs_update(self):
|
2020-02-29 23:37:18 +00:00
|
|
|
self._orch_cmd("apply", "nfs", "service_name", "2")
|
2019-02-13 14:01:25 +00:00
|
|
|
|
|
|
|
def test_error(self):
|
|
|
|
ret = self._orch_cmd_result("host", "add", "raise_no_support")
|
|
|
|
self.assertEqual(ret, errno.ENOENT)
|
|
|
|
ret = self._orch_cmd_result("host", "add", "raise_bug")
|
|
|
|
self.assertEqual(ret, errno.EINVAL)
|
|
|
|
ret = self._orch_cmd_result("host", "add", "raise_not_implemented")
|
|
|
|
self.assertEqual(ret, errno.ENOENT)
|
|
|
|
ret = self._orch_cmd_result("host", "add", "raise_no_orchestrator")
|
|
|
|
self.assertEqual(ret, errno.ENOENT)
|
|
|
|
ret = self._orch_cmd_result("host", "add", "raise_import_error")
|
|
|
|
self.assertEqual(ret, errno.ENOENT)
|
2019-02-26 16:27:53 +00:00
|
|
|
|
2019-08-12 03:58:43 +00:00
|
|
|
def test_load_data(self):
|
|
|
|
data = {
|
|
|
|
'inventory': [
|
|
|
|
{
|
|
|
|
'name': 'host0',
|
|
|
|
'devices': [
|
|
|
|
{
|
|
|
|
'type': 'hdd',
|
|
|
|
'id': '/dev/sda',
|
|
|
|
'size': 1024**4 * 4,
|
|
|
|
'rotates': True
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'host1',
|
|
|
|
'devices': [
|
|
|
|
{
|
|
|
|
'type': 'hdd',
|
|
|
|
'id': '/dev/sda',
|
|
|
|
'size': 1024**4 * 4,
|
|
|
|
'rotates': True
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2020-02-24 20:02:17 +00:00
|
|
|
'daemons': [
|
2019-08-12 03:58:43 +00:00
|
|
|
{
|
2020-02-24 20:02:17 +00:00
|
|
|
'hostname': 'host0',
|
|
|
|
'daemon_type': 'mon',
|
|
|
|
'daemon_id': 'a'
|
2019-08-12 03:58:43 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-24 20:02:17 +00:00
|
|
|
'hostname': 'host1',
|
|
|
|
'daemon_type': 'osd',
|
|
|
|
'daemon_id': '1'
|
2019-08-12 03:58:43 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin=json.dumps(data))
|
|
|
|
self.assertEqual(ret, 0)
|
|
|
|
out = self._orch_cmd('device', 'ls', '--format=json')
|
|
|
|
inventory = data['inventory']
|
|
|
|
inventory_result = json.loads(out)
|
|
|
|
self.assertEqual(len(inventory), len(inventory_result))
|
|
|
|
|
|
|
|
out = self._orch_cmd('device', 'ls', 'host0', '--format=json')
|
|
|
|
inventory_result = json.loads(out)
|
|
|
|
self.assertEqual(len(inventory_result), 1)
|
|
|
|
self.assertEqual(inventory_result[0]['name'], 'host0')
|
|
|
|
|
2020-02-15 10:41:16 +00:00
|
|
|
out = self._orch_cmd('ps', '--format=json')
|
2020-02-24 20:02:17 +00:00
|
|
|
daemons = data['daemons']
|
|
|
|
daemons_result = json.loads(out)
|
|
|
|
self.assertEqual(len(daemons), len(daemons_result))
|
2019-08-12 03:58:43 +00:00
|
|
|
|
2020-02-15 10:41:16 +00:00
|
|
|
out = self._orch_cmd('ps', 'host0', '--format=json')
|
2020-02-24 20:02:17 +00:00
|
|
|
daemons_result = json.loads(out)
|
|
|
|
self.assertEqual(len(daemons_result), 1)
|
|
|
|
self.assertEqual(daemons_result[0]['hostname'], 'host0')
|
2019-08-12 03:58:43 +00:00
|
|
|
|
|
|
|
# test invalid input file: invalid json
|
|
|
|
json_str = '{ "inventory: '
|
|
|
|
ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin=json_str)
|
|
|
|
self.assertEqual(ret, errno.EINVAL)
|
|
|
|
|
|
|
|
# test invalid input file: missing key
|
|
|
|
json_str = '{ "inventory": [{"devices": []}] }'
|
|
|
|
ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin=json_str)
|
|
|
|
self.assertEqual(ret, errno.EINVAL)
|
|
|
|
|
|
|
|
# load empty data for other tests
|
|
|
|
ret = self._test_orchestrator_cmd_result('load_data', '-i', '-', stdin='{}')
|
|
|
|
self.assertEqual(ret, 0)
|