]> git.proxmox.com Git - ceph.git/blame - ceph/src/python-common/ceph/tests/test_service_spec.py
bump version to 15.2.4-pve1
[ceph.git] / ceph / src / python-common / ceph / tests / test_service_spec.py
CommitLineData
9f95a23c
TL
1# flake8: noqa
2import json
1911f103 3import yaml
9f95a23c
TL
4
5import pytest
6
1911f103
TL
7from ceph.deployment.service_spec import HostPlacementSpec, PlacementSpec, RGWSpec, NFSServiceSpec, \
8 servicespec_validate_add, ServiceSpec, ServiceSpecValidationError
9from ceph.deployment.drive_group import DriveGroupSpec
9f95a23c
TL
10
11
12@pytest.mark.parametrize("test_input,expected, require_network",
13 [("myhost", ('myhost', '', ''), False),
14 ("myhost=sname", ('myhost', '', 'sname'), False),
15 ("myhost:10.1.1.10", ('myhost', '10.1.1.10', ''), True),
16 ("myhost:10.1.1.10=sname", ('myhost', '10.1.1.10', 'sname'), True),
17 ("myhost:10.1.1.0/32", ('myhost', '10.1.1.0/32', ''), True),
18 ("myhost:10.1.1.0/32=sname", ('myhost', '10.1.1.0/32', 'sname'), True),
19 ("myhost:[v1:10.1.1.10:6789]", ('myhost', '[v1:10.1.1.10:6789]', ''), True),
20 ("myhost:[v1:10.1.1.10:6789]=sname", ('myhost', '[v1:10.1.1.10:6789]', 'sname'), True),
21 ("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', ''), True),
22 ("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]=sname", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', 'sname'), True),
23 ])
24def test_parse_host_placement_specs(test_input, expected, require_network):
25 ret = HostPlacementSpec.parse(test_input, require_network=require_network)
26 assert ret == expected
27 assert str(ret) == test_input
28
1911f103 29
9f95a23c
TL
30@pytest.mark.parametrize(
31 "test_input,expected",
32 [
33 ('', "PlacementSpec()"),
34 ("count:2", "PlacementSpec(count=2)"),
35 ("3", "PlacementSpec(count=3)"),
36 ("host1 host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
37 ("host1;host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
38 ("host1,host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
39 ("host1 host2=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='b')])"),
40 ("host1=a host2=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name='a'), HostPlacementSpec(hostname='host2', network='', name='b')])"),
41 ("host1:1.2.3.4=a host2:1.2.3.5=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='1.2.3.4', name='a'), HostPlacementSpec(hostname='host2', network='1.2.3.5', name='b')])"),
42 ("myhost:[v1:10.1.1.10:6789]", "PlacementSpec(hosts=[HostPlacementSpec(hostname='myhost', network='[v1:10.1.1.10:6789]', name='')])"),
43 ('2 host1 host2', "PlacementSpec(count=2, hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
44 ('label:foo', "PlacementSpec(label='foo')"),
45 ('3 label:foo', "PlacementSpec(count=3, label='foo')"),
46 ('*', "PlacementSpec(host_pattern='*')"),
47 ('3 data[1-3]', "PlacementSpec(count=3, host_pattern='data[1-3]')"),
48 ('3 data?', "PlacementSpec(count=3, host_pattern='data?')"),
49 ('3 data*', "PlacementSpec(count=3, host_pattern='data*')"),
50 ])
51def test_parse_placement_specs(test_input, expected):
52 ret = PlacementSpec.from_string(test_input)
53 assert str(ret) == expected
54
55@pytest.mark.parametrize(
56 "test_input",
57 [
58 ("host=a host*"),
59 ("host=a label:wrong"),
60 ("host? host*"),
61 ]
62)
63def test_parse_placement_specs_raises(test_input):
64 with pytest.raises(ServiceSpecValidationError):
65 PlacementSpec.from_string(test_input)
66
67@pytest.mark.parametrize("test_input",
68 # wrong subnet
69 [("myhost:1.1.1.1/24"),
70 # wrong ip format
71 ("myhost:1"),
9f95a23c 72 ])
1911f103 73def test_parse_host_placement_specs_raises_wrong_format(test_input):
9f95a23c 74 with pytest.raises(ValueError):
1911f103 75 HostPlacementSpec.parse(test_input)
9f95a23c
TL
76
77
1911f103
TL
78@pytest.mark.parametrize(
79 "s_type,o_spec,s_id",
80 [
81 ("mgr", ServiceSpec, 'test'),
82 ("mon", ServiceSpec, 'test'),
83 ("mds", ServiceSpec, 'test'),
84 ("rgw", RGWSpec, 'realm.zone'),
85 ("nfs", NFSServiceSpec, 'test'),
86 ("osd", DriveGroupSpec, 'test'),
87 ])
88def test_servicespec_map_test(s_type, o_spec, s_id):
89 dict_spec = {
90 "service_id": s_id,
91 "service_type": s_type,
92 "placement":
93 dict(hosts=["host1:1.1.1.1"])
9f95a23c 94 }
1911f103
TL
95 spec = ServiceSpec.from_json(dict_spec)
96 assert isinstance(spec, o_spec)
97 assert isinstance(spec.placement, PlacementSpec)
98 assert isinstance(spec.placement.hosts[0], HostPlacementSpec)
99 assert spec.placement.hosts[0].hostname == 'host1'
100 assert spec.placement.hosts[0].network == '1.1.1.1'
101 assert spec.placement.hosts[0].name == ''
102 assert servicespec_validate_add(spec) is None
103 ServiceSpec.from_json(spec.to_json())
104