8 from ceph
.deployment
.service_spec
import ServiceSpec
9 from ceph
.deployment
import inventory
10 from ceph
.utils
import datetime_now
11 from mgr_module
import HandleCommandResult
13 from test_orchestrator
import TestOrchestrator
as _TestOrchestrator
15 from orchestrator
import InventoryHost
, DaemonDescription
, ServiceDescription
, DaemonDescriptionStatus
, OrchResult
16 from orchestrator
import OrchestratorValidationError
17 from orchestrator
.module
import to_format
, Format
, OrchestratorCli
, preview_table_osd
18 from unittest
import mock
21 def _test_resource(data
, resource_class
, extra
=None):
22 # ensure we can deserialize and serialize
23 rsc
= resource_class
.from_json(data
)
24 assert rsc
.to_json() == resource_class
.from_json(rsc
.to_json()).to_json()
27 # if there is an unexpected data provided
28 data_copy
= data
.copy()
29 data_copy
.update(extra
)
30 with pytest
.raises(OrchestratorValidationError
):
31 resource_class
.from_json(data_copy
)
46 'rejected_reasons': [],
51 _test_resource(json_data
, InventoryHost
, {'abc': False})
52 for devices
in json_data
['devices']:
53 _test_resource(devices
, inventory
.Device
)
55 json_data
= [{}, {'name': 'host0', 'addr': '1.2.3.4'}, {'devices': []}]
56 for data
in json_data
:
57 with pytest
.raises(OrchestratorValidationError
):
58 InventoryHost
.from_json(data
)
61 def test_daemon_description():
68 _test_resource(json_data
, DaemonDescription
, {'abc': False})
70 dd
= DaemonDescription
.from_json(json_data
)
71 assert dd
.status
.value
== DaemonDescriptionStatus
.error
.value
75 to
= _TestOrchestrator('', 0, 0)
76 completion
= to
.apply([
77 ServiceSpec(service_type
='nfs', service_id
='foo'),
78 ServiceSpec(service_type
='nfs', service_id
='foo'),
79 ServiceSpec(service_type
='nfs', service_id
='foo'),
81 res
= '<NFSServiceSpec for service_name=nfs.foo>'
82 assert completion
.result
== [res
, res
, res
]
86 y
= """daemon_type: crash
88 daemon_name: crash.ubuntu
94 - 2020-06-10T10:08:22.933241Z daemon:crash.ubuntu [INFO] "Deployed crash.ubuntu on
102 container_image_id: 74803e884bea289d2d2d3ebdf6d37cd560499e955595695b1390a89800f4e37a
103 container_image_name: docker.io/ceph/daemon-base:latest-master-devel
104 created: '2020-06-10T10:37:31.051288Z'
105 last_refresh: '2020-06-10T10:57:40.715637Z'
109 - 2020-06-10T10:37:31.139159Z service:crash [INFO] "service was created"
111 types
= (DaemonDescription
, ServiceDescription
)
113 for y
, cls
in zip(y
.split('---\n'), types
):
114 data
= yaml
.safe_load(y
)
115 object = cls
.from_json(data
)
117 assert to_format(object, Format
.yaml
, False, cls
) == y
118 assert to_format([object], Format
.yaml
, True, cls
) == y
120 j
= json
.loads(to_format(object, Format
.json
, False, cls
))
121 assert to_format(cls
.from_json(j
), Format
.yaml
, False, cls
) == y
124 def test_event_multiline():
125 from .._interface
import OrchestratorEvent
126 e
= OrchestratorEvent(datetime_now(), 'service', 'subject', 'ERROR', 'message')
127 assert OrchestratorEvent
.from_json(e
.to_json()) == e
129 e
= OrchestratorEvent(datetime_now(), 'service',
130 'subject', 'ERROR', 'multiline\nmessage')
131 assert OrchestratorEvent
.from_json(e
.to_json()) == e
134 def test_handle_command():
136 'prefix': 'orch daemon add',
137 'daemon_type': 'mon',
138 'placement': 'smithi044:[v2:172.21.15.44:3301,v1:172.21.15.44:6790]=c',
140 m
= OrchestratorCli('orchestrator', 0, 0)
141 r
= m
._handle
_command
(None, cmd
)
142 assert r
== HandleCommandResult(
143 retval
=-2, stdout
='', stderr
='No orchestrator configured (try `ceph orch set backend`)')
146 r
= OrchResult([ServiceDescription(spec
=ServiceSpec(service_type
='osd'), running
=123)])
149 @mock.patch("orchestrator.OrchestratorCli.describe_service", return_value
=r
)
150 def test_orch_ls(_describe_service
):
154 m
= OrchestratorCli('orchestrator', 0, 0)
155 r
= m
._handle
_command
(None, cmd
)
156 out
= 'NAME PORTS RUNNING REFRESHED AGE PLACEMENT \n' \
158 assert r
== HandleCommandResult(retval
=0, stdout
=out
, stderr
='')
164 m
= OrchestratorCli('orchestrator', 0, 0)
165 r
= m
._handle
_command
(None, cmd
)
166 out
= textwrap
.dedent("""
171 objectstore: bluestore
176 assert r
== HandleCommandResult(retval
=0, stdout
=out
, stderr
='')
179 def test_preview_table_osd_smoke():
182 'service_type': 'osd',
193 "block_db": "/dev/nvme0n1",
194 "block_db_size": "66.67 GB",
196 "data_size": "300.00 GB",
200 "block_db": "/dev/nvme0n1",
201 "block_db_size": "66.67 GB",
203 "data_size": "300.00 GB",
207 "block_db": "/dev/nvme0n1",
208 "block_db_size": "66.67 GB",
210 "data_size": "300.00 GB",
219 preview_table_osd(data
)