2 # Copyright 2020 Canonical Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # For those usages not covered by the Apache License, Version 2.0 please
17 # contact: legal@canonical.com
19 # To get in touch with the maintainers, please contact:
20 # osm-charmers@lists.launchpad.net
23 from typing
import NoReturn
29 class TestPodSpec(unittest
.TestCase
):
30 """Pod spec unit tests."""
32 def test_make_pod_ports(self
) -> NoReturn
:
33 """Testing make pod ports."""
39 "containerPort": port
,
44 pod_ports
= pod_spec
._make
_pod
_ports
(port
)
46 self
.assertListEqual(expected_result
, pod_ports
)
48 def test_make_pod_envconfig_ng_ro(self
) -> NoReturn
:
49 """Teting make pod envconfig."""
52 "database_commonkey": "osm",
56 "kafka_host": "kafka",
58 "mongodb_connection_string": "mongodb://mongo",
62 "OSMRO_LOG_LEVEL": config
["log_level"],
63 "OSMRO_MESSAGE_DRIVER": "kafka",
64 "OSMRO_MESSAGE_HOST": relation_state
["kafka_host"],
65 "OSMRO_MESSAGE_PORT": relation_state
["kafka_port"],
66 "OSMRO_DATABASE_DRIVER": "mongo",
67 "OSMRO_DATABASE_URI": relation_state
["mongodb_connection_string"],
68 "OSMRO_DATABASE_COMMONKEY": config
["database_commonkey"],
71 pod_envconfig
= pod_spec
._make
_pod
_envconfig
(config
, relation_state
)
73 self
.assertDictEqual(expected_result
, pod_envconfig
)
75 def test_make_pod_envconfig_no_ng_ro(self
) -> NoReturn
:
76 """Teting make pod envconfig."""
79 "enable_ng_ro": False,
80 "vim_database": "mano_vim_db",
81 "ro_database": "mano_db",
82 "openmano_tenant": "osm",
85 "mysql_host": "mysql",
88 "mysql_password": "manopw",
89 "mysql_root_password": "rootmanopw",
93 "OSMRO_LOG_LEVEL": config
["log_level"],
94 "RO_DB_HOST": relation_state
["mysql_host"],
95 "RO_DB_OVIM_HOST": relation_state
["mysql_host"],
96 "RO_DB_PORT": relation_state
["mysql_port"],
97 "RO_DB_OVIM_PORT": relation_state
["mysql_port"],
98 "RO_DB_USER": relation_state
["mysql_user"],
99 "RO_DB_OVIM_USER": relation_state
["mysql_user"],
100 "RO_DB_PASSWORD": relation_state
["mysql_password"],
101 "RO_DB_OVIM_PASSWORD": relation_state
["mysql_password"],
102 "RO_DB_ROOT_PASSWORD": relation_state
["mysql_root_password"],
103 "RO_DB_OVIM_ROOT_PASSWORD": relation_state
["mysql_root_password"],
104 "RO_DB_NAME": config
["ro_database"],
105 "RO_DB_OVIM_NAME": config
["vim_database"],
106 "OPENMANO_TENANT": config
["openmano_tenant"],
109 pod_envconfig
= pod_spec
._make
_pod
_envconfig
(config
, relation_state
)
111 self
.assertDictEqual(expected_result
, pod_envconfig
)
113 def test_make_startup_probe(self
) -> NoReturn
:
114 """Testing make startup probe."""
116 "exec": {"command": ["/usr/bin/pgrep", "python3"]},
117 "initialDelaySeconds": 60,
121 startup_probe
= pod_spec
._make
_startup
_probe
()
123 self
.assertDictEqual(expected_result
, startup_probe
)
125 def test_make_readiness_probe(self
) -> NoReturn
:
126 """Testing make readiness probe."""
131 "path": "/openmano/tenants",
136 "successThreshold": 1,
137 "failureThreshold": 3,
140 readiness_probe
= pod_spec
._make
_readiness
_probe
(port
)
142 self
.assertDictEqual(expected_result
, readiness_probe
)
144 def test_make_liveness_probe(self
) -> NoReturn
:
145 """Testing make liveness probe."""
150 "path": "/openmano/tenants",
153 "initialDelaySeconds": 600,
156 "successThreshold": 1,
157 "failureThreshold": 3,
160 liveness_probe
= pod_spec
._make
_liveness
_probe
(port
)
162 self
.assertDictEqual(expected_result
, liveness_probe
)
164 def test_make_pod_spec_ng_ro(self
) -> NoReturn
:
165 """Testing make pod spec."""
166 image_info
= {"upstream-source": "opensourcemano/ro:8"}
168 "database_commonkey": "osm",
170 "enable_ng_ro": True,
173 "kafka_host": "kafka",
174 "kafka_port": "9090",
175 "mongodb_connection_string": "mongodb://mongo",
185 "imageDetails": image_info
,
186 "imagePullPolicy": "Always",
190 "containerPort": port
,
195 "OSMRO_LOG_LEVEL": config
["log_level"],
196 "OSMRO_MESSAGE_DRIVER": "kafka",
197 "OSMRO_MESSAGE_HOST": relation_state
["kafka_host"],
198 "OSMRO_MESSAGE_PORT": relation_state
["kafka_port"],
199 "OSMRO_DATABASE_DRIVER": "mongo",
200 "OSMRO_DATABASE_URI": relation_state
[
201 "mongodb_connection_string"
203 "OSMRO_DATABASE_COMMONKEY": config
["database_commonkey"],
207 "exec": {"command": ["/usr/bin/pgrep", "python3"]},
208 "initialDelaySeconds": 60,
213 "path": "/openmano/tenants",
218 "successThreshold": 1,
219 "failureThreshold": 3,
223 "path": "/openmano/tenants",
226 "initialDelaySeconds": 600,
229 "successThreshold": 1,
230 "failureThreshold": 3,
235 "kubernetesResources": {"ingressResources": []},
238 spec
= pod_spec
.make_pod_spec(
239 image_info
, config
, relation_state
, app_name
, port
242 self
.assertDictEqual(expected_result
, spec
)
244 def test_make_pod_spec_no_ng_ro(self
) -> NoReturn
:
245 """Testing make pod spec."""
246 image_info
= {"upstream-source": "opensourcemano/ro:8"}
249 "enable_ng_ro": False,
250 "vim_database": "mano_vim_db",
251 "ro_database": "mano_db",
252 "openmano_tenant": "osm",
255 "mysql_host": "mysql",
257 "mysql_user": "mano",
258 "mysql_password": "manopw",
259 "mysql_root_password": "rootmanopw",
269 "imageDetails": image_info
,
270 "imagePullPolicy": "Always",
274 "containerPort": port
,
279 "OSMRO_LOG_LEVEL": config
["log_level"],
280 "RO_DB_HOST": relation_state
["mysql_host"],
281 "RO_DB_OVIM_HOST": relation_state
["mysql_host"],
282 "RO_DB_PORT": relation_state
["mysql_port"],
283 "RO_DB_OVIM_PORT": relation_state
["mysql_port"],
284 "RO_DB_USER": relation_state
["mysql_user"],
285 "RO_DB_OVIM_USER": relation_state
["mysql_user"],
286 "RO_DB_PASSWORD": relation_state
["mysql_password"],
287 "RO_DB_OVIM_PASSWORD": relation_state
["mysql_password"],
288 "RO_DB_ROOT_PASSWORD": relation_state
["mysql_root_password"],
289 "RO_DB_OVIM_ROOT_PASSWORD": relation_state
[
290 "mysql_root_password"
292 "RO_DB_NAME": config
["ro_database"],
293 "RO_DB_OVIM_NAME": config
["vim_database"],
294 "OPENMANO_TENANT": config
["openmano_tenant"],
298 "exec": {"command": ["/usr/bin/pgrep", "python3"]},
299 "initialDelaySeconds": 60,
304 "path": "/openmano/tenants",
309 "successThreshold": 1,
310 "failureThreshold": 3,
314 "path": "/openmano/tenants",
317 "initialDelaySeconds": 600,
320 "successThreshold": 1,
321 "failureThreshold": 3,
326 "kubernetesResources": {"ingressResources": []},
329 spec
= pod_spec
.make_pod_spec(
330 image_info
, config
, relation_state
, app_name
, port
333 self
.assertDictEqual(expected_result
, spec
)
335 def test_make_pod_spec_without_image_info(self
) -> NoReturn
:
336 """Testing make pod spec without image_info."""
339 "enable_ng_ro": True,
340 "database_commonkey": "osm",
344 "kafka_host": "kafka",
346 "mongodb_connection_string": "mongodb://mongo",
351 spec
= pod_spec
.make_pod_spec(
352 image_info
, config
, relation_state
, app_name
, port
355 self
.assertIsNone(spec
)
357 def test_make_pod_spec_without_config(self
) -> NoReturn
:
358 """Testing make pod spec without config."""
359 image_info
= {"upstream-source": "opensourcemano/ro:8"}
362 "kafka_host": "kafka",
364 "mongodb_connection_string": "mongodb://mongo",
369 with self
.assertRaises(ValueError):
370 pod_spec
.make_pod_spec(image_info
, config
, relation_state
, app_name
, port
)
372 def test_make_pod_spec_without_relation_state(self
) -> NoReturn
:
373 """Testing make pod spec without relation_state."""
374 image_info
= {"upstream-source": "opensourcemano/ro:8"}
376 "enable_ng_ro": True,
377 "database_commonkey": "osm",
384 with self
.assertRaises(ValueError):
385 pod_spec
.make_pod_spec(image_info
, config
, relation_state
, app_name
, port
)
388 if __name__
== "__main__":