7 from ceph
.deployment
.service_spec
import HostPlacementSpec
, PlacementSpec
, \
8 ServiceSpec
, ServiceSpecValidationError
, RGWSpec
, NFSServiceSpec
, IscsiServiceSpec
9 from ceph
.deployment
.drive_group
import DriveGroupSpec
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),
24 def 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
29 ps
= PlacementSpec
.from_string(test_input
)
30 assert ps
.pretty_str() == test_input
31 assert ps
== PlacementSpec
.from_string(ps
.pretty_str())
33 # Testing the old verbose way of generating json. Don't remove:
34 assert ret
== HostPlacementSpec
.from_json({
35 'hostname': ret
.hostname
,
36 'network': ret
.network
,
40 assert ret
== HostPlacementSpec
.from_json(ret
.to_json())
45 @pytest.mark
.parametrize(
46 "test_input,expected",
48 ('', "PlacementSpec()"),
49 ("count:2", "PlacementSpec(count=2)"),
50 ("3", "PlacementSpec(count=3)"),
51 ("host1 host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
52 ("host1;host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
53 ("host1,host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
54 ("host1 host2=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='b')])"),
55 ("host1=a host2=b", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name='a'), HostPlacementSpec(hostname='host2', network='', name='b')])"),
56 ("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')])"),
57 ("myhost:[v1:10.1.1.10:6789]", "PlacementSpec(hosts=[HostPlacementSpec(hostname='myhost', network='[v1:10.1.1.10:6789]', name='')])"),
58 ('2 host1 host2', "PlacementSpec(count=2, hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
59 ('label:foo', "PlacementSpec(label='foo')"),
60 ('3 label:foo', "PlacementSpec(count=3, label='foo')"),
61 ('*', "PlacementSpec(host_pattern='*')"),
62 ('3 data[1-3]', "PlacementSpec(count=3, host_pattern='data[1-3]')"),
63 ('3 data?', "PlacementSpec(count=3, host_pattern='data?')"),
64 ('3 data*', "PlacementSpec(count=3, host_pattern='data*')"),
66 def test_parse_placement_specs(test_input
, expected
):
67 ret
= PlacementSpec
.from_string(test_input
)
68 assert str(ret
) == expected
69 assert PlacementSpec
.from_string(ret
.pretty_str()) == ret
, f
'"{ret.pretty_str()}" != "{test_input}"'
71 @pytest.mark
.parametrize(
75 ("host=a label:wrong"),
79 def test_parse_placement_specs_raises(test_input
):
80 with pytest
.raises(ServiceSpecValidationError
):
81 PlacementSpec
.from_string(test_input
)
83 @pytest.mark
.parametrize("test_input",
85 [("myhost:1.1.1.1/24"),
89 def test_parse_host_placement_specs_raises_wrong_format(test_input
):
90 with pytest
.raises(ValueError):
91 HostPlacementSpec
.parse(test_input
)
94 def _get_dict_spec(s_type
, s_id
):
97 "service_type": s_type
,
99 dict(hosts
=["host1:1.1.1.1"])
102 dict_spec
['pool'] = 'pool'
103 elif s_type
== 'iscsi':
104 dict_spec
['pool'] = 'pool'
105 dict_spec
['api_user'] = 'api_user'
106 dict_spec
['api_password'] = 'api_password'
107 elif s_type
== 'osd':
108 dict_spec
['spec'] = {
113 elif s_type
== 'rgw':
114 dict_spec
['rgw_realm'] = 'realm'
115 dict_spec
['rgw_zone'] = 'zone'
120 @pytest.mark
.parametrize(
121 "s_type,o_spec,s_id",
123 ("mgr", ServiceSpec
, 'test'),
124 ("mon", ServiceSpec
, 'test'),
125 ("mds", ServiceSpec
, 'test'),
126 ("rgw", RGWSpec
, 'realm.zone'),
127 ("nfs", NFSServiceSpec
, 'test'),
128 ("iscsi", IscsiServiceSpec
, 'test'),
129 ("osd", DriveGroupSpec
, 'test'),
131 def test_servicespec_map_test(s_type
, o_spec
, s_id
):
132 spec
= ServiceSpec
.from_json(_get_dict_spec(s_type
, s_id
))
133 assert isinstance(spec
, o_spec
)
134 assert isinstance(spec
.placement
, PlacementSpec
)
135 assert isinstance(spec
.placement
.hosts
[0], HostPlacementSpec
)
136 assert spec
.placement
.hosts
[0].hostname
== 'host1'
137 assert spec
.placement
.hosts
[0].network
== '1.1.1.1'
138 assert spec
.placement
.hosts
[0].name
== ''
139 assert spec
.validate() is None
140 ServiceSpec
.from_json(spec
.to_json())
144 y
= """service_type: crash
156 service_id: default-rgw-realm.eu-central-1.1
157 service_name: rgw.default-rgw-realm.eu-central-1.1
162 rgw_realm: default-rgw-realm
163 rgw_zone: eu-central-1
167 service_id: osd_spec_default
168 service_name: osd.osd_spec_default
177 objectstore: bluestore
182 for y
in y
.split('---\n'):
183 data
= yaml
.safe_load(y
)
184 object = ServiceSpec
.from_json(data
)
186 assert yaml
.dump(object) == y
187 assert yaml
.dump(ServiceSpec
.from_json(object.to_json())) == y
189 @pytest.mark
.parametrize("spec1, spec2, eq",
210 # Add service_type='mgr'
245 def test_spec_hash_eq(spec1
: ServiceSpec
,
249 assert (spec1
== spec2
) is eq
251 @pytest.mark
.parametrize(
252 "s_type,s_id,s_name",
254 ('mgr', 's_id', 'mgr'),
255 ('mon', 's_id', 'mon'),
256 ('mds', 's_id', 'mds.s_id'),
257 ('rgw', 's_id', 'rgw.s_id'),
258 ('nfs', 's_id', 'nfs.s_id'),
259 ('iscsi', 's_id', 'iscsi.s_id'),
260 ('osd', 's_id', 'osd.s_id'),
262 def test_service_name(s_type
, s_id
, s_name
):
263 spec
= ServiceSpec
.from_json(_get_dict_spec(s_type
, s_id
))
265 assert spec
.service_name() == s_name