]> git.proxmox.com Git - ceph.git/blame - ceph/src/python-common/ceph/tests/test_service_spec.py
bump version to 15.2.1-pve1
[ceph.git] / ceph / src / python-common / ceph / tests / test_service_spec.py
CommitLineData
9f95a23c
TL
1# flake8: noqa
2import json
3
4import pytest
5
6from ceph.deployment.service_spec import HostPlacementSpec, PlacementSpec, RGWSpec, \
7 servicespec_validate_add, ServiceSpecValidationError
8
9
10@pytest.mark.parametrize("test_input,expected, require_network",
11 [("myhost", ('myhost', '', ''), False),
12 ("myhost=sname", ('myhost', '', 'sname'), False),
13 ("myhost:10.1.1.10", ('myhost', '10.1.1.10', ''), True),
14 ("myhost:10.1.1.10=sname", ('myhost', '10.1.1.10', 'sname'), True),
15 ("myhost:10.1.1.0/32", ('myhost', '10.1.1.0/32', ''), True),
16 ("myhost:10.1.1.0/32=sname", ('myhost', '10.1.1.0/32', 'sname'), True),
17 ("myhost:[v1:10.1.1.10:6789]", ('myhost', '[v1:10.1.1.10:6789]', ''), True),
18 ("myhost:[v1:10.1.1.10:6789]=sname", ('myhost', '[v1:10.1.1.10:6789]', 'sname'), True),
19 ("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),
20 ("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),
21 ])
22def test_parse_host_placement_specs(test_input, expected, require_network):
23 ret = HostPlacementSpec.parse(test_input, require_network=require_network)
24 assert ret == expected
25 assert str(ret) == test_input
26
27@pytest.mark.parametrize(
28 "test_input,expected",
29 [
30 ('', "PlacementSpec()"),
31 ("count:2", "PlacementSpec(count=2)"),
32 ("3", "PlacementSpec(count=3)"),
33 ("host1 host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
34 ("host1;host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
35 ("host1,host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
36 ("host1 host2=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='b')])"),
37 ("host1=a host2=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name='a'), HostPlacementSpec(hostname='host2', network='', name='b')])"),
38 ("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')])"),
39 ("myhost:[v1:10.1.1.10:6789]", "PlacementSpec(hosts=[HostPlacementSpec(hostname='myhost', network='[v1:10.1.1.10:6789]', name='')])"),
40 ('2 host1 host2', "PlacementSpec(count=2, hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
41 ('label:foo', "PlacementSpec(label='foo')"),
42 ('3 label:foo', "PlacementSpec(count=3, label='foo')"),
43 ('*', "PlacementSpec(host_pattern='*')"),
44 ('3 data[1-3]', "PlacementSpec(count=3, host_pattern='data[1-3]')"),
45 ('3 data?', "PlacementSpec(count=3, host_pattern='data?')"),
46 ('3 data*', "PlacementSpec(count=3, host_pattern='data*')"),
47 ])
48def test_parse_placement_specs(test_input, expected):
49 ret = PlacementSpec.from_string(test_input)
50 assert str(ret) == expected
51
52@pytest.mark.parametrize(
53 "test_input",
54 [
55 ("host=a host*"),
56 ("host=a label:wrong"),
57 ("host? host*"),
58 ]
59)
60def test_parse_placement_specs_raises(test_input):
61 with pytest.raises(ServiceSpecValidationError):
62 PlacementSpec.from_string(test_input)
63
64@pytest.mark.parametrize("test_input",
65 # wrong subnet
66 [("myhost:1.1.1.1/24"),
67 # wrong ip format
68 ("myhost:1"),
69 # empty string
70 ("myhost=1"),
71 ])
72def test_parse_host_placement_specs_raises(test_input):
73 with pytest.raises(ValueError):
74 ret = HostPlacementSpec.parse(test_input)
75
76
77def test_rgwspec():
78 """
79 {
80 "rgw_zone": "zonename",
81 "service_type": "rgw",
82 "rgw_frontend_port": 8080,
83 "rgw_realm": "realm"
84 }
85 """
86 example = json.loads(test_rgwspec.__doc__.strip())
87 spec = RGWSpec.from_json(example)
88 assert servicespec_validate_add(spec) is None