2019-10-26 03:47:05 +08:00
|
|
|
import sys
|
2018-02-19 17:13:06 +08:00
|
|
|
import pytest
|
|
|
|
|
2020-10-02 04:28:17 +08:00
|
|
|
sys.path.append('./library')
|
|
|
|
import ceph_crush # noqa: E402
|
|
|
|
|
2018-02-19 17:13:06 +08:00
|
|
|
|
|
|
|
class TestCephCrushModule(object):
|
|
|
|
|
|
|
|
def test_no_host(self):
|
|
|
|
location = [
|
|
|
|
("chassis", "monchassis"),
|
|
|
|
("rack", "monrack"),
|
|
|
|
("row", "marow"),
|
|
|
|
("pdu", "monpdu"),
|
|
|
|
("pod", "monpod"),
|
|
|
|
("room", "maroom"),
|
|
|
|
("datacenter", "mondc"),
|
|
|
|
("region", "maregion"),
|
|
|
|
("root", "maroute"),
|
|
|
|
]
|
|
|
|
with pytest.raises(Exception):
|
2020-10-02 04:28:17 +08:00
|
|
|
ceph_crush.sort_osd_crush_location(location, None)
|
2018-02-19 17:13:06 +08:00
|
|
|
|
|
|
|
def test_lower_than_two_bucket(self):
|
|
|
|
location = [
|
|
|
|
("chassis", "monchassis"),
|
|
|
|
]
|
|
|
|
with pytest.raises(Exception):
|
2020-10-02 04:28:17 +08:00
|
|
|
ceph_crush.sort_osd_crush_location(location, None)
|
2018-02-19 17:13:06 +08:00
|
|
|
|
|
|
|
def test_invalid_bucket_type(self):
|
|
|
|
location = [
|
|
|
|
("host", "monhost"),
|
|
|
|
("chassis", "monchassis"),
|
|
|
|
("rackyyyyy", "monrack"),
|
|
|
|
]
|
|
|
|
with pytest.raises(Exception):
|
2020-10-02 04:28:17 +08:00
|
|
|
ceph_crush.sort_osd_crush_location(location, None)
|
2018-02-19 17:13:06 +08:00
|
|
|
|
|
|
|
def test_ordering(self):
|
|
|
|
expected_result = [
|
|
|
|
("host", "monhost"),
|
|
|
|
("chassis", "monchassis"),
|
|
|
|
("rack", "monrack"),
|
|
|
|
("row", "marow"),
|
|
|
|
("pdu", "monpdu"),
|
|
|
|
("pod", "monpod"),
|
|
|
|
("room", "maroom"),
|
|
|
|
("datacenter", "mondc"),
|
|
|
|
("region", "maregion"),
|
|
|
|
("root", "maroute"),
|
|
|
|
]
|
|
|
|
expected_result_reverse = expected_result[::-1]
|
|
|
|
result = ceph_crush.sort_osd_crush_location(expected_result_reverse, None)
|
|
|
|
assert expected_result == result
|
|
|
|
|
|
|
|
def test_generate_commands(self):
|
|
|
|
cluster = "test"
|
|
|
|
expected_command_list = [
|
|
|
|
['ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monhost", "host"],
|
|
|
|
['ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monchassis", "chassis"],
|
|
|
|
['ceph', '--cluster', cluster, 'osd', 'crush', "move", "monhost", "chassis=monchassis"],
|
|
|
|
['ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monrack", "rack"],
|
|
|
|
['ceph', '--cluster', cluster, 'osd', 'crush', "move", "monchassis", "rack=monrack"],
|
|
|
|
]
|
|
|
|
|
|
|
|
location = [
|
|
|
|
("host", "monhost"),
|
|
|
|
("chassis", "monchassis"),
|
|
|
|
("rack", "monrack"),
|
|
|
|
]
|
|
|
|
result = ceph_crush.create_and_move_buckets_list(cluster, location)
|
|
|
|
assert result == expected_command_list
|
|
|
|
|
|
|
|
def test_generate_commands_container(self):
|
|
|
|
cluster = "test"
|
|
|
|
containerized = "docker exec -ti ceph-mon"
|
|
|
|
expected_command_list = [
|
|
|
|
['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monhost", "host"],
|
|
|
|
['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monchassis", "chassis"],
|
|
|
|
['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "move", "monhost", "chassis=monchassis"],
|
|
|
|
['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "add-bucket", "monrack", "rack"],
|
|
|
|
['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '--cluster', cluster, 'osd', 'crush', "move", "monchassis", "rack=monrack"],
|
|
|
|
]
|
|
|
|
|
|
|
|
location = [
|
|
|
|
("host", "monhost"),
|
|
|
|
("chassis", "monchassis"),
|
|
|
|
("rack", "monrack"),
|
|
|
|
]
|
|
|
|
result = ceph_crush.create_and_move_buckets_list(cluster, location, containerized)
|
|
|
|
assert result == expected_command_list
|