| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright 2020 Canonical Ltd. |
| 3 | # |
| 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 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 |
| 14 | # under the License. |
| 15 | # |
| 16 | # For those usages not covered by the Apache License, Version 2.0 please |
| 17 | # contact: legal@canonical.com |
| 18 | # |
| 19 | # To get in touch with the maintainers, please contact: |
| 20 | # osm-charmers@lists.launchpad.net |
| 21 | ## |
| 22 | |
| 23 | from typing import NoReturn |
| 24 | import unittest |
| 25 | from ops.model import BlockedStatus |
| 26 | |
| 27 | from ops.testing import Harness |
| 28 | |
| 29 | from charm import NbiCharm |
| 30 | |
| 31 | |
| 32 | class TestCharm(unittest.TestCase): |
| 33 | """NBI Charm unit tests.""" |
| 34 | |
| 35 | def setUp(self) -> NoReturn: |
| 36 | """Test setup""" |
| 37 | self.harness = Harness(NbiCharm) |
| 38 | self.harness.set_leader(is_leader=True) |
| 39 | self.harness.begin() |
| 40 | |
| 41 | def test_on_start_without_relations(self) -> NoReturn: |
| 42 | """Test installation without any relation.""" |
| 43 | self.harness.charm.on.start.emit() |
| 44 | |
| 45 | # Verifying status |
| 46 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 47 | |
| 48 | # Verifying status message |
| 49 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 50 | self.assertTrue( |
| 51 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 52 | ) |
| 53 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 54 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 55 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 56 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 57 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 58 | |
| 59 | def test_on_start_without_relations_with_keystone(self) -> NoReturn: |
| 60 | """Test installation without any relation and keystone enabled.""" |
| 61 | self.harness.update_config({"auth_backend": "keystone"}) |
| 62 | |
| 63 | self.harness.charm.on.start.emit() |
| 64 | |
| 65 | # Verifying status |
| 66 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 67 | |
| 68 | # Verifying status message |
| 69 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 70 | self.assertTrue( |
| 71 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 72 | ) |
| 73 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 74 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 75 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 76 | self.assertIn("keystone", self.harness.charm.unit.status.message) |
| 77 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 78 | |
| 79 | def test_on_start_with_relations(self) -> NoReturn: |
| 80 | """Test deployment without keystone.""" |
| 81 | expected_result = { |
| 82 | "version": 3, |
| 83 | "containers": [ |
| 84 | { |
| 85 | "name": "nbi", |
| 86 | "imageDetails": self.harness.charm.image.fetch(), |
| 87 | "imagePullPolicy": "Always", |
| 88 | "ports": [ |
| 89 | { |
| 90 | "name": "nbi", |
| 91 | "containerPort": 9999, |
| 92 | "protocol": "TCP", |
| 93 | } |
| 94 | ], |
| 95 | "envConfig": { |
| 96 | "ALLOW_ANONYMOUS_LOGIN": "yes", |
| 97 | "OSMNBI_SERVER_ENABLE_TEST": False, |
| 98 | "OSMNBI_STATIC_DIR": "/app/osm_nbi/html_public", |
| 99 | "OSMNBI_MESSAGE_HOST": "kafka", |
| 100 | "OSMNBI_MESSAGE_DRIVER": "kafka", |
| 101 | "OSMNBI_MESSAGE_PORT": 9092, |
| 102 | "OSMNBI_DATABASE_DRIVER": "mongo", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 103 | "OSMNBI_DATABASE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 104 | "OSMNBI_DATABASE_COMMONKEY": "osm", |
| 105 | "OSMNBI_STORAGE_DRIVER": "mongo", |
| 106 | "OSMNBI_STORAGE_PATH": "/app/storage", |
| 107 | "OSMNBI_STORAGE_COLLECTION": "files", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 108 | "OSMNBI_STORAGE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 109 | "OSMNBI_PROMETHEUS_HOST": "prometheus", |
| 110 | "OSMNBI_PROMETHEUS_PORT": 9090, |
| 111 | "OSMNBI_LOG_LEVEL": "INFO", |
| 112 | "OSMNBI_AUTHENTICATION_BACKEND": "internal", |
| 113 | }, |
| 114 | } |
| 115 | ], |
| 116 | "kubernetesResources": { |
| 117 | "ingressResources": [], |
| 118 | }, |
| 119 | } |
| 120 | |
| 121 | self.harness.charm.on.start.emit() |
| 122 | |
| 123 | # Check if kafka datastore is initialized |
| 124 | self.assertIsNone(self.harness.charm.state.message_host) |
| 125 | self.assertIsNone(self.harness.charm.state.message_port) |
| 126 | |
| 127 | # Check if mongodb datastore is initialized |
| 128 | self.assertIsNone(self.harness.charm.state.database_uri) |
| 129 | |
| 130 | # Check if prometheus datastore is initialized |
| 131 | self.assertIsNone(self.harness.charm.state.prometheus_host) |
| 132 | self.assertIsNone(self.harness.charm.state.prometheus_port) |
| 133 | |
| 134 | # Initializing the kafka relation |
| 135 | kafka_relation_id = self.harness.add_relation("kafka", "kafka") |
| 136 | self.harness.add_relation_unit(kafka_relation_id, "kafka/0") |
| 137 | self.harness.update_relation_data( |
| 138 | kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 139 | ) |
| 140 | |
| 141 | # Initializing the mongo relation |
| 142 | mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 143 | self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0") |
| 144 | self.harness.update_relation_data( |
| 145 | mongodb_relation_id, |
| 146 | "mongodb/0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 147 | {"connection_string": "mongodb://mongo:27017"}, |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 148 | ) |
| 149 | |
| 150 | # Initializing the prometheus relation |
| 151 | prometheus_relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 152 | self.harness.add_relation_unit(prometheus_relation_id, "prometheus/0") |
| 153 | self.harness.update_relation_data( |
| 154 | prometheus_relation_id, |
| 155 | "prometheus/0", |
| 156 | {"hostname": "prometheus", "port": 9090}, |
| 157 | ) |
| 158 | |
| 159 | # Checking if kafka data is stored |
| 160 | self.assertEqual(self.harness.charm.state.message_host, "kafka") |
| 161 | self.assertEqual(self.harness.charm.state.message_port, 9092) |
| 162 | |
| 163 | # Checking if mongodb data is stored |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 164 | self.assertEqual(self.harness.charm.state.database_uri, "mongodb://mongo:27017") |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 165 | |
| 166 | # Checking if prometheus data is stored |
| 167 | self.assertEqual(self.harness.charm.state.prometheus_host, "prometheus") |
| 168 | self.assertEqual(self.harness.charm.state.prometheus_port, 9090) |
| 169 | |
| 170 | # Verifying status |
| 171 | self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 172 | |
| 173 | pod_spec, _ = self.harness.get_pod_spec() |
| 174 | |
| 175 | self.assertDictEqual(expected_result, pod_spec) |
| 176 | |
| 177 | def test_on_start_with_relations_with_keystone(self) -> NoReturn: |
| 178 | """Test deployment with keystone.""" |
| 179 | expected_result = { |
| 180 | "version": 3, |
| 181 | "containers": [ |
| 182 | { |
| 183 | "name": "nbi", |
| 184 | "imageDetails": self.harness.charm.image.fetch(), |
| 185 | "imagePullPolicy": "Always", |
| 186 | "ports": [ |
| 187 | { |
| 188 | "name": "nbi", |
| 189 | "containerPort": 9999, |
| 190 | "protocol": "TCP", |
| 191 | } |
| 192 | ], |
| 193 | "envConfig": { |
| 194 | "ALLOW_ANONYMOUS_LOGIN": "yes", |
| 195 | "OSMNBI_SERVER_ENABLE_TEST": False, |
| 196 | "OSMNBI_STATIC_DIR": "/app/osm_nbi/html_public", |
| 197 | "OSMNBI_MESSAGE_HOST": "kafka", |
| 198 | "OSMNBI_MESSAGE_DRIVER": "kafka", |
| 199 | "OSMNBI_MESSAGE_PORT": 9092, |
| 200 | "OSMNBI_DATABASE_DRIVER": "mongo", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 201 | "OSMNBI_DATABASE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 202 | "OSMNBI_DATABASE_COMMONKEY": "osm", |
| 203 | "OSMNBI_STORAGE_DRIVER": "mongo", |
| 204 | "OSMNBI_STORAGE_PATH": "/app/storage", |
| 205 | "OSMNBI_STORAGE_COLLECTION": "files", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 206 | "OSMNBI_STORAGE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 207 | "OSMNBI_PROMETHEUS_HOST": "prometheus", |
| 208 | "OSMNBI_PROMETHEUS_PORT": 9090, |
| 209 | "OSMNBI_LOG_LEVEL": "INFO", |
| 210 | "OSMNBI_AUTHENTICATION_BACKEND": "keystone", |
| 211 | "OSMNBI_AUTHENTICATION_AUTH_URL": "keystone", |
| 212 | "OSMNBI_AUTHENTICATION_AUTH_PORT": 5000, |
| 213 | "OSMNBI_AUTHENTICATION_USER_DOMAIN_NAME": "default", |
| 214 | "OSMNBI_AUTHENTICATION_PROJECT_DOMAIN_NAME": "default", |
| 215 | "OSMNBI_AUTHENTICATION_SERVICE_USERNAME": "nbi", |
| 216 | "OSMNBI_AUTHENTICATION_SERVICE_PASSWORD": "nbi", |
| 217 | "OSMNBI_AUTHENTICATION_SERVICE_PROJECT": "service", |
| 218 | }, |
| 219 | } |
| 220 | ], |
| 221 | "kubernetesResources": { |
| 222 | "ingressResources": [], |
| 223 | }, |
| 224 | } |
| 225 | |
| 226 | self.harness.update_config({"auth_backend": "keystone"}) |
| 227 | |
| 228 | self.harness.charm.on.start.emit() |
| 229 | |
| 230 | # Check if kafka datastore is initialized |
| 231 | self.assertIsNone(self.harness.charm.state.message_host) |
| 232 | self.assertIsNone(self.harness.charm.state.message_port) |
| 233 | |
| 234 | # Check if mongodb datastore is initialized |
| 235 | self.assertIsNone(self.harness.charm.state.database_uri) |
| 236 | |
| 237 | # Check if prometheus datastore is initialized |
| 238 | self.assertIsNone(self.harness.charm.state.prometheus_host) |
| 239 | self.assertIsNone(self.harness.charm.state.prometheus_port) |
| 240 | |
| 241 | # Check if keystone datastore is initialized |
| 242 | self.assertIsNone(self.harness.charm.state.keystone_host) |
| 243 | self.assertIsNone(self.harness.charm.state.keystone_port) |
| 244 | self.assertIsNone(self.harness.charm.state.keystone_user_domain_name) |
| 245 | self.assertIsNone(self.harness.charm.state.keystone_project_domain_name) |
| 246 | self.assertIsNone(self.harness.charm.state.keystone_username) |
| 247 | self.assertIsNone(self.harness.charm.state.keystone_password) |
| 248 | self.assertIsNone(self.harness.charm.state.keystone_service) |
| 249 | |
| 250 | # Initializing the kafka relation |
| 251 | kafka_relation_id = self.harness.add_relation("kafka", "kafka") |
| 252 | self.harness.add_relation_unit(kafka_relation_id, "kafka/0") |
| 253 | self.harness.update_relation_data( |
| 254 | kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 255 | ) |
| 256 | |
| 257 | # Initializing the mongodb relation |
| 258 | mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 259 | self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0") |
| 260 | self.harness.update_relation_data( |
| 261 | mongodb_relation_id, |
| 262 | "mongodb/0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 263 | {"connection_string": "mongodb://mongo:27017"}, |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 264 | ) |
| 265 | |
| 266 | # Initializing the prometheus relation |
| 267 | promethues_relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 268 | self.harness.add_relation_unit(promethues_relation_id, "prometheus/0") |
| 269 | self.harness.update_relation_data( |
| 270 | promethues_relation_id, |
| 271 | "prometheus/0", |
| 272 | {"hostname": "prometheus", "port": 9090}, |
| 273 | ) |
| 274 | |
| 275 | # Initializing the keystone relation |
| 276 | keystone_relation_id = self.harness.add_relation("keystone", "keystone") |
| 277 | self.harness.add_relation_unit(keystone_relation_id, "keystone/0") |
| 278 | self.harness.update_relation_data( |
| 279 | keystone_relation_id, |
| 280 | "keystone/0", |
| 281 | { |
| 282 | "host": "keystone", |
| 283 | "port": 5000, |
| 284 | "user_domain_name": "default", |
| 285 | "project_domain_name": "default", |
| 286 | "username": "nbi", |
| 287 | "password": "nbi", |
| 288 | "service": "service", |
| 289 | }, |
| 290 | ) |
| 291 | |
| 292 | # Checking if kafka data is stored |
| 293 | self.assertEqual(self.harness.charm.state.message_host, "kafka") |
| 294 | self.assertEqual(self.harness.charm.state.message_port, 9092) |
| 295 | |
| 296 | # Checking if mongodb data is stored |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 297 | self.assertEqual(self.harness.charm.state.database_uri, "mongodb://mongo:27017") |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 298 | |
| 299 | # Checking if prometheus data is stored |
| 300 | self.assertEqual(self.harness.charm.state.prometheus_host, "prometheus") |
| 301 | self.assertEqual(self.harness.charm.state.prometheus_port, 9090) |
| 302 | |
| 303 | # Checking if keystone data is stored |
| 304 | self.assertEqual(self.harness.charm.state.keystone_host, "keystone") |
| 305 | self.assertEqual(self.harness.charm.state.keystone_port, 5000) |
| 306 | self.assertEqual(self.harness.charm.state.keystone_user_domain_name, "default") |
| 307 | self.assertEqual( |
| 308 | self.harness.charm.state.keystone_project_domain_name, "default" |
| 309 | ) |
| 310 | self.assertEqual(self.harness.charm.state.keystone_username, "nbi") |
| 311 | self.assertEqual(self.harness.charm.state.keystone_password, "nbi") |
| 312 | self.assertEqual(self.harness.charm.state.keystone_service, "service") |
| 313 | |
| 314 | # Verifying status |
| 315 | self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 316 | |
| 317 | pod_spec, _ = self.harness.get_pod_spec() |
| 318 | |
| 319 | self.assertDictEqual(expected_result, pod_spec) |
| 320 | |
| 321 | def test_ingress_resources_without_http(self) -> NoReturn: |
| 322 | """Test ingress resources without HTTP.""" |
| 323 | expected_result = { |
| 324 | "version": 3, |
| 325 | "containers": [ |
| 326 | { |
| 327 | "name": "nbi", |
| 328 | "imageDetails": self.harness.charm.image.fetch(), |
| 329 | "imagePullPolicy": "Always", |
| 330 | "ports": [ |
| 331 | { |
| 332 | "name": "nbi", |
| 333 | "containerPort": 9999, |
| 334 | "protocol": "TCP", |
| 335 | } |
| 336 | ], |
| 337 | "envConfig": { |
| 338 | "ALLOW_ANONYMOUS_LOGIN": "yes", |
| 339 | "OSMNBI_SERVER_ENABLE_TEST": False, |
| 340 | "OSMNBI_STATIC_DIR": "/app/osm_nbi/html_public", |
| 341 | "OSMNBI_MESSAGE_HOST": "kafka", |
| 342 | "OSMNBI_MESSAGE_DRIVER": "kafka", |
| 343 | "OSMNBI_MESSAGE_PORT": 9092, |
| 344 | "OSMNBI_DATABASE_DRIVER": "mongo", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 345 | "OSMNBI_DATABASE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 346 | "OSMNBI_DATABASE_COMMONKEY": "osm", |
| 347 | "OSMNBI_STORAGE_DRIVER": "mongo", |
| 348 | "OSMNBI_STORAGE_PATH": "/app/storage", |
| 349 | "OSMNBI_STORAGE_COLLECTION": "files", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 350 | "OSMNBI_STORAGE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 351 | "OSMNBI_PROMETHEUS_HOST": "prometheus", |
| 352 | "OSMNBI_PROMETHEUS_PORT": 9090, |
| 353 | "OSMNBI_LOG_LEVEL": "INFO", |
| 354 | "OSMNBI_AUTHENTICATION_BACKEND": "internal", |
| 355 | }, |
| 356 | } |
| 357 | ], |
| 358 | "kubernetesResources": { |
| 359 | "ingressResources": [], |
| 360 | }, |
| 361 | } |
| 362 | |
| 363 | self.harness.charm.on.start.emit() |
| 364 | |
| 365 | # Initializing the kafka relation |
| 366 | kafka_relation_id = self.harness.add_relation("kafka", "kafka") |
| 367 | self.harness.add_relation_unit(kafka_relation_id, "kafka/0") |
| 368 | self.harness.update_relation_data( |
| 369 | kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 370 | ) |
| 371 | |
| 372 | # Initializing the mongodb relation |
| 373 | mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 374 | self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0") |
| 375 | self.harness.update_relation_data( |
| 376 | mongodb_relation_id, |
| 377 | "mongodb/0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 378 | {"connection_string": "mongodb://mongo:27017"}, |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 379 | ) |
| 380 | |
| 381 | # Initializing the prometheus relation |
| 382 | promethues_relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 383 | self.harness.add_relation_unit(promethues_relation_id, "prometheus/0") |
| 384 | self.harness.update_relation_data( |
| 385 | promethues_relation_id, |
| 386 | "prometheus/0", |
| 387 | {"hostname": "prometheus", "port": 9090}, |
| 388 | ) |
| 389 | |
| 390 | self.harness.update_config({"site_url": "nbi"}) |
| 391 | |
| 392 | pod_spec, _ = self.harness.get_pod_spec() |
| 393 | |
| 394 | self.assertDictEqual(expected_result, pod_spec) |
| 395 | |
| 396 | def test_ingress_resources_with_http(self) -> NoReturn: |
| 397 | """Test ingress resources with HTTP.""" |
| 398 | expected_result = { |
| 399 | "version": 3, |
| 400 | "containers": [ |
| 401 | { |
| 402 | "name": "nbi", |
| 403 | "imageDetails": self.harness.charm.image.fetch(), |
| 404 | "imagePullPolicy": "Always", |
| 405 | "ports": [ |
| 406 | { |
| 407 | "name": "nbi", |
| 408 | "containerPort": 9999, |
| 409 | "protocol": "TCP", |
| 410 | } |
| 411 | ], |
| 412 | "envConfig": { |
| 413 | "ALLOW_ANONYMOUS_LOGIN": "yes", |
| 414 | "OSMNBI_SERVER_ENABLE_TEST": False, |
| 415 | "OSMNBI_STATIC_DIR": "/app/osm_nbi/html_public", |
| 416 | "OSMNBI_MESSAGE_HOST": "kafka", |
| 417 | "OSMNBI_MESSAGE_DRIVER": "kafka", |
| 418 | "OSMNBI_MESSAGE_PORT": 9092, |
| 419 | "OSMNBI_DATABASE_DRIVER": "mongo", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 420 | "OSMNBI_DATABASE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 421 | "OSMNBI_DATABASE_COMMONKEY": "osm", |
| 422 | "OSMNBI_STORAGE_DRIVER": "mongo", |
| 423 | "OSMNBI_STORAGE_PATH": "/app/storage", |
| 424 | "OSMNBI_STORAGE_COLLECTION": "files", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 425 | "OSMNBI_STORAGE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 426 | "OSMNBI_PROMETHEUS_HOST": "prometheus", |
| 427 | "OSMNBI_PROMETHEUS_PORT": 9090, |
| 428 | "OSMNBI_LOG_LEVEL": "INFO", |
| 429 | "OSMNBI_AUTHENTICATION_BACKEND": "internal", |
| 430 | }, |
| 431 | } |
| 432 | ], |
| 433 | "kubernetesResources": { |
| 434 | "ingressResources": [ |
| 435 | { |
| 436 | "name": "nbi-ingress", |
| 437 | "annotations": { |
| 438 | "nginx.ingress.kubernetes.io/proxy-body-size": "0", |
| 439 | "nginx.ingress.kubernetes.io/ssl-redirect": "false", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 440 | "nginx.ingress.kubernetes.io/backend-protocol": "HTTPS", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 441 | }, |
| 442 | "spec": { |
| 443 | "rules": [ |
| 444 | { |
| 445 | "host": "nbi", |
| 446 | "http": { |
| 447 | "paths": [ |
| 448 | { |
| 449 | "path": "/", |
| 450 | "backend": { |
| 451 | "serviceName": "nbi", |
| 452 | "servicePort": 9999, |
| 453 | }, |
| 454 | } |
| 455 | ] |
| 456 | }, |
| 457 | } |
| 458 | ] |
| 459 | }, |
| 460 | } |
| 461 | ], |
| 462 | }, |
| 463 | } |
| 464 | |
| 465 | self.harness.charm.on.start.emit() |
| 466 | |
| 467 | # Initializing the kafka relation |
| 468 | kafka_relation_id = self.harness.add_relation("kafka", "kafka") |
| 469 | self.harness.add_relation_unit(kafka_relation_id, "kafka/0") |
| 470 | self.harness.update_relation_data( |
| 471 | kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 472 | ) |
| 473 | |
| 474 | # Initializing the mongodb relation |
| 475 | mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 476 | self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0") |
| 477 | self.harness.update_relation_data( |
| 478 | mongodb_relation_id, |
| 479 | "mongodb/0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 480 | {"connection_string": "mongodb://mongo:27017"}, |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 481 | ) |
| 482 | |
| 483 | # Initializing the prometheus relation |
| 484 | promethues_relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 485 | self.harness.add_relation_unit(promethues_relation_id, "prometheus/0") |
| 486 | self.harness.update_relation_data( |
| 487 | promethues_relation_id, |
| 488 | "prometheus/0", |
| 489 | {"hostname": "prometheus", "port": 9090}, |
| 490 | ) |
| 491 | |
| 492 | self.harness.update_config({"site_url": "http://nbi"}) |
| 493 | |
| 494 | pod_spec, _ = self.harness.get_pod_spec() |
| 495 | |
| 496 | self.assertDictEqual(expected_result, pod_spec) |
| 497 | |
| 498 | def test_ingress_resources_with_https(self) -> NoReturn: |
| 499 | """Test ingress resources with HTTPS.""" |
| 500 | expected_result = { |
| 501 | "version": 3, |
| 502 | "containers": [ |
| 503 | { |
| 504 | "name": "nbi", |
| 505 | "imageDetails": self.harness.charm.image.fetch(), |
| 506 | "imagePullPolicy": "Always", |
| 507 | "ports": [ |
| 508 | { |
| 509 | "name": "nbi", |
| 510 | "containerPort": 9999, |
| 511 | "protocol": "TCP", |
| 512 | } |
| 513 | ], |
| 514 | "envConfig": { |
| 515 | "ALLOW_ANONYMOUS_LOGIN": "yes", |
| 516 | "OSMNBI_SERVER_ENABLE_TEST": False, |
| 517 | "OSMNBI_STATIC_DIR": "/app/osm_nbi/html_public", |
| 518 | "OSMNBI_MESSAGE_HOST": "kafka", |
| 519 | "OSMNBI_MESSAGE_DRIVER": "kafka", |
| 520 | "OSMNBI_MESSAGE_PORT": 9092, |
| 521 | "OSMNBI_DATABASE_DRIVER": "mongo", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 522 | "OSMNBI_DATABASE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 523 | "OSMNBI_DATABASE_COMMONKEY": "osm", |
| 524 | "OSMNBI_STORAGE_DRIVER": "mongo", |
| 525 | "OSMNBI_STORAGE_PATH": "/app/storage", |
| 526 | "OSMNBI_STORAGE_COLLECTION": "files", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 527 | "OSMNBI_STORAGE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 528 | "OSMNBI_PROMETHEUS_HOST": "prometheus", |
| 529 | "OSMNBI_PROMETHEUS_PORT": 9090, |
| 530 | "OSMNBI_LOG_LEVEL": "INFO", |
| 531 | "OSMNBI_AUTHENTICATION_BACKEND": "internal", |
| 532 | }, |
| 533 | } |
| 534 | ], |
| 535 | "kubernetesResources": { |
| 536 | "ingressResources": [ |
| 537 | { |
| 538 | "name": "nbi-ingress", |
| 539 | "annotations": { |
| 540 | "nginx.ingress.kubernetes.io/proxy-body-size": "0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 541 | "nginx.ingress.kubernetes.io/backend-protocol": "HTTPS", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 542 | }, |
| 543 | "spec": { |
| 544 | "rules": [ |
| 545 | { |
| 546 | "host": "nbi", |
| 547 | "http": { |
| 548 | "paths": [ |
| 549 | { |
| 550 | "path": "/", |
| 551 | "backend": { |
| 552 | "serviceName": "nbi", |
| 553 | "servicePort": 9999, |
| 554 | }, |
| 555 | } |
| 556 | ] |
| 557 | }, |
| 558 | } |
| 559 | ], |
| 560 | "tls": [{"hosts": ["nbi"], "secretName": "nbi"}], |
| 561 | }, |
| 562 | } |
| 563 | ], |
| 564 | }, |
| 565 | } |
| 566 | |
| 567 | self.harness.charm.on.start.emit() |
| 568 | |
| 569 | # Initializing the kafka relation |
| 570 | kafka_relation_id = self.harness.add_relation("kafka", "kafka") |
| 571 | self.harness.add_relation_unit(kafka_relation_id, "kafka/0") |
| 572 | self.harness.update_relation_data( |
| 573 | kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 574 | ) |
| 575 | |
| 576 | # Initializing the mongodb relation |
| 577 | mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 578 | self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0") |
| 579 | self.harness.update_relation_data( |
| 580 | mongodb_relation_id, |
| 581 | "mongodb/0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 582 | {"connection_string": "mongodb://mongo:27017"}, |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 583 | ) |
| 584 | |
| 585 | # Initializing the prometheus relation |
| 586 | promethues_relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 587 | self.harness.add_relation_unit(promethues_relation_id, "prometheus/0") |
| 588 | self.harness.update_relation_data( |
| 589 | promethues_relation_id, |
| 590 | "prometheus/0", |
| 591 | {"hostname": "prometheus", "port": 9090}, |
| 592 | ) |
| 593 | |
| 594 | self.harness.update_config( |
| 595 | {"site_url": "https://nbi", "tls_secret_name": "nbi"} |
| 596 | ) |
| 597 | |
| 598 | pod_spec, _ = self.harness.get_pod_spec() |
| 599 | |
| 600 | self.assertDictEqual(expected_result, pod_spec) |
| 601 | |
| 602 | def test_ingress_resources_with_https_and_ingress_whitelist(self) -> NoReturn: |
| 603 | """Test ingress resources with HTTPS and ingress whitelist.""" |
| 604 | expected_result = { |
| 605 | "version": 3, |
| 606 | "containers": [ |
| 607 | { |
| 608 | "name": "nbi", |
| 609 | "imageDetails": self.harness.charm.image.fetch(), |
| 610 | "imagePullPolicy": "Always", |
| 611 | "ports": [ |
| 612 | { |
| 613 | "name": "nbi", |
| 614 | "containerPort": 9999, |
| 615 | "protocol": "TCP", |
| 616 | } |
| 617 | ], |
| 618 | "envConfig": { |
| 619 | "ALLOW_ANONYMOUS_LOGIN": "yes", |
| 620 | "OSMNBI_SERVER_ENABLE_TEST": False, |
| 621 | "OSMNBI_STATIC_DIR": "/app/osm_nbi/html_public", |
| 622 | "OSMNBI_MESSAGE_HOST": "kafka", |
| 623 | "OSMNBI_MESSAGE_DRIVER": "kafka", |
| 624 | "OSMNBI_MESSAGE_PORT": 9092, |
| 625 | "OSMNBI_DATABASE_DRIVER": "mongo", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 626 | "OSMNBI_DATABASE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 627 | "OSMNBI_DATABASE_COMMONKEY": "osm", |
| 628 | "OSMNBI_STORAGE_DRIVER": "mongo", |
| 629 | "OSMNBI_STORAGE_PATH": "/app/storage", |
| 630 | "OSMNBI_STORAGE_COLLECTION": "files", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 631 | "OSMNBI_STORAGE_URI": "mongodb://mongo:27017", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 632 | "OSMNBI_PROMETHEUS_HOST": "prometheus", |
| 633 | "OSMNBI_PROMETHEUS_PORT": 9090, |
| 634 | "OSMNBI_LOG_LEVEL": "INFO", |
| 635 | "OSMNBI_AUTHENTICATION_BACKEND": "internal", |
| 636 | }, |
| 637 | } |
| 638 | ], |
| 639 | "kubernetesResources": { |
| 640 | "ingressResources": [ |
| 641 | { |
| 642 | "name": "nbi-ingress", |
| 643 | "annotations": { |
| 644 | "nginx.ingress.kubernetes.io/proxy-body-size": "0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 645 | "nginx.ingress.kubernetes.io/backend-protocol": "HTTPS", |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 646 | "nginx.ingress.kubernetes.io/whitelist-source-range": "0.0.0.0/0", |
| 647 | }, |
| 648 | "spec": { |
| 649 | "rules": [ |
| 650 | { |
| 651 | "host": "nbi", |
| 652 | "http": { |
| 653 | "paths": [ |
| 654 | { |
| 655 | "path": "/", |
| 656 | "backend": { |
| 657 | "serviceName": "nbi", |
| 658 | "servicePort": 9999, |
| 659 | }, |
| 660 | } |
| 661 | ] |
| 662 | }, |
| 663 | } |
| 664 | ], |
| 665 | "tls": [{"hosts": ["nbi"], "secretName": "nbi"}], |
| 666 | }, |
| 667 | } |
| 668 | ], |
| 669 | }, |
| 670 | } |
| 671 | |
| 672 | self.harness.charm.on.start.emit() |
| 673 | |
| 674 | # Initializing the kafka relation |
| 675 | kafka_relation_id = self.harness.add_relation("kafka", "kafka") |
| 676 | self.harness.add_relation_unit(kafka_relation_id, "kafka/0") |
| 677 | self.harness.update_relation_data( |
| 678 | kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 679 | ) |
| 680 | |
| 681 | # Initializing the mongodb relation |
| 682 | mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 683 | self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0") |
| 684 | self.harness.update_relation_data( |
| 685 | mongodb_relation_id, |
| 686 | "mongodb/0", |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 687 | {"connection_string": "mongodb://mongo:27017"}, |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 688 | ) |
| 689 | |
| 690 | # Initializing the prometheus relation |
| 691 | promethues_relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 692 | self.harness.add_relation_unit(promethues_relation_id, "prometheus/0") |
| 693 | self.harness.update_relation_data( |
| 694 | promethues_relation_id, |
| 695 | "prometheus/0", |
| 696 | {"hostname": "prometheus", "port": 9090}, |
| 697 | ) |
| 698 | |
| 699 | self.harness.update_config( |
| 700 | { |
| 701 | "site_url": "https://nbi", |
| 702 | "tls_secret_name": "nbi", |
| 703 | "ingress_whitelist_source_range": "0.0.0.0/0", |
| 704 | } |
| 705 | ) |
| 706 | |
| 707 | pod_spec, _ = self.harness.get_pod_spec() |
| 708 | |
| 709 | self.assertDictEqual(expected_result, pod_spec) |
| 710 | |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 711 | def test_on_kafka_unit_relation_changed(self) -> NoReturn: |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 712 | """Test to see if kafka relation is updated.""" |
| 713 | self.harness.charm.on.start.emit() |
| 714 | |
| 715 | self.assertIsNone(self.harness.charm.state.message_host) |
| 716 | self.assertIsNone(self.harness.charm.state.message_port) |
| 717 | |
| 718 | relation_id = self.harness.add_relation("kafka", "kafka") |
| 719 | self.harness.add_relation_unit(relation_id, "kafka/0") |
| 720 | self.harness.update_relation_data( |
| 721 | relation_id, "kafka/0", {"host": "kafka", "port": 9092} |
| 722 | ) |
| 723 | |
| 724 | self.assertEqual(self.harness.charm.state.message_host, "kafka") |
| 725 | self.assertEqual(self.harness.charm.state.message_port, 9092) |
| 726 | |
| 727 | # Verifying status |
| 728 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 729 | |
| 730 | # Verifying status message |
| 731 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 732 | self.assertTrue( |
| 733 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 734 | ) |
| 735 | self.assertNotIn("kafka", self.harness.charm.unit.status.message) |
| 736 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 737 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 738 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 739 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 740 | |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 741 | def test_on_kafka_app_relation_changed(self) -> NoReturn: |
| 742 | """Test to see if kafka relation is updated.""" |
| 743 | self.harness.charm.on.start.emit() |
| 744 | |
| 745 | self.assertIsNone(self.harness.charm.state.message_host) |
| 746 | self.assertIsNone(self.harness.charm.state.message_port) |
| 747 | |
| 748 | relation_id = self.harness.add_relation("kafka", "kafka") |
| 749 | self.harness.add_relation_unit(relation_id, "kafka/0") |
| 750 | self.harness.update_relation_data( |
| 751 | relation_id, "kafka", {"host": "kafka", "port": 9092} |
| 752 | ) |
| 753 | |
| 754 | self.assertEqual(self.harness.charm.state.message_host, "kafka") |
| 755 | self.assertEqual(self.harness.charm.state.message_port, 9092) |
| 756 | |
| 757 | # Verifying status |
| 758 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 759 | |
| 760 | # Verifying status message |
| 761 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 762 | self.assertTrue( |
| 763 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 764 | ) |
| 765 | self.assertNotIn("kafka", self.harness.charm.unit.status.message) |
| 766 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 767 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 768 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 769 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 770 | |
| 771 | def test_on_mongodb_unit_relation_changed(self) -> NoReturn: |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 772 | """Test to see if mongodb relation is updated.""" |
| 773 | self.harness.charm.on.start.emit() |
| 774 | |
| 775 | self.assertIsNone(self.harness.charm.state.database_uri) |
| 776 | |
| 777 | relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 778 | self.harness.add_relation_unit(relation_id, "mongodb/0") |
| 779 | self.harness.update_relation_data( |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 780 | relation_id, "mongodb/0", {"connection_string": "mongodb://mongo:27017"} |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 781 | ) |
| 782 | |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 783 | self.assertEqual(self.harness.charm.state.database_uri, "mongodb://mongo:27017") |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 784 | |
| 785 | # Verifying status |
| 786 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 787 | |
| 788 | # Verifying status message |
| 789 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 790 | self.assertTrue( |
| 791 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 792 | ) |
| 793 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 794 | self.assertNotIn("mongodb", self.harness.charm.unit.status.message) |
| 795 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 796 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 797 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 798 | |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 799 | def test_on_mongodb_app_relation_changed(self) -> NoReturn: |
| 800 | """Test to see if mongodb relation is updated.""" |
| 801 | self.harness.charm.on.start.emit() |
| 802 | |
| 803 | self.assertIsNone(self.harness.charm.state.database_uri) |
| 804 | |
| 805 | relation_id = self.harness.add_relation("mongodb", "mongodb") |
| 806 | self.harness.add_relation_unit(relation_id, "mongodb/0") |
| 807 | self.harness.update_relation_data( |
| 808 | relation_id, "mongodb", {"connection_string": "mongodb://mongo:27017"} |
| 809 | ) |
| 810 | |
| 811 | self.assertEqual(self.harness.charm.state.database_uri, "mongodb://mongo:27017") |
| 812 | |
| 813 | # Verifying status |
| 814 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 815 | |
| 816 | # Verifying status message |
| 817 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 818 | self.assertTrue( |
| 819 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 820 | ) |
| 821 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 822 | self.assertNotIn("mongodb", self.harness.charm.unit.status.message) |
| 823 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 824 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 825 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 826 | |
| 827 | def test_on_prometheus_unit_relation_changed(self) -> NoReturn: |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 828 | """Test to see if prometheus relation is updated.""" |
| 829 | self.harness.charm.on.start.emit() |
| 830 | |
| 831 | self.assertIsNone(self.harness.charm.state.prometheus_host) |
| 832 | self.assertIsNone(self.harness.charm.state.prometheus_port) |
| 833 | |
| 834 | relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 835 | self.harness.add_relation_unit(relation_id, "prometheus/0") |
| 836 | self.harness.update_relation_data( |
| 837 | relation_id, "prometheus/0", {"hostname": "prometheus", "port": 9090} |
| 838 | ) |
| 839 | |
| 840 | self.assertEqual(self.harness.charm.state.prometheus_host, "prometheus") |
| 841 | self.assertEqual(self.harness.charm.state.prometheus_port, 9090) |
| 842 | |
| 843 | # Verifying status |
| 844 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 845 | |
| 846 | # Verifying status message |
| 847 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 848 | self.assertTrue( |
| 849 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 850 | ) |
| 851 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 852 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 853 | self.assertNotIn("prometheus", self.harness.charm.unit.status.message) |
| 854 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 855 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 856 | |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 857 | def test_on_prometheus_app_relation_changed(self) -> NoReturn: |
| 858 | """Test to see if prometheus relation is updated.""" |
| 859 | self.harness.charm.on.start.emit() |
| 860 | |
| 861 | self.assertIsNone(self.harness.charm.state.prometheus_host) |
| 862 | self.assertIsNone(self.harness.charm.state.prometheus_port) |
| 863 | |
| 864 | relation_id = self.harness.add_relation("prometheus", "prometheus") |
| 865 | self.harness.add_relation_unit(relation_id, "prometheus/0") |
| 866 | self.harness.update_relation_data( |
| 867 | relation_id, "prometheus", {"hostname": "prometheus", "port": 9090} |
| 868 | ) |
| 869 | |
| 870 | self.assertEqual(self.harness.charm.state.prometheus_host, "prometheus") |
| 871 | self.assertEqual(self.harness.charm.state.prometheus_port, 9090) |
| 872 | |
| 873 | # Verifying status |
| 874 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 875 | |
| 876 | # Verifying status message |
| 877 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 878 | self.assertTrue( |
| 879 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 880 | ) |
| 881 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 882 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 883 | self.assertNotIn("prometheus", self.harness.charm.unit.status.message) |
| 884 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 885 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 886 | |
| 887 | def test_on_keystone_unit_relation_changed(self) -> NoReturn: |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 888 | """Test to see if keystone relation is updated.""" |
| 889 | self.harness.update_config({"auth_backend": "keystone"}) |
| 890 | |
| 891 | self.harness.charm.on.start.emit() |
| 892 | |
| 893 | self.assertIsNone(self.harness.charm.state.keystone_host) |
| 894 | self.assertIsNone(self.harness.charm.state.keystone_port) |
| 895 | self.assertIsNone(self.harness.charm.state.keystone_user_domain_name) |
| 896 | self.assertIsNone(self.harness.charm.state.keystone_project_domain_name) |
| 897 | self.assertIsNone(self.harness.charm.state.keystone_username) |
| 898 | self.assertIsNone(self.harness.charm.state.keystone_password) |
| 899 | self.assertIsNone(self.harness.charm.state.keystone_service) |
| 900 | |
| 901 | relation_id = self.harness.add_relation("keystone", "keystone") |
| 902 | self.harness.add_relation_unit(relation_id, "keystone/0") |
| 903 | self.harness.update_relation_data( |
| 904 | relation_id, |
| 905 | "keystone/0", |
| 906 | { |
| 907 | "host": "keystone", |
| 908 | "port": 5000, |
| 909 | "user_domain_name": "default", |
| 910 | "project_domain_name": "default", |
| 911 | "username": "nbi", |
| 912 | "password": "nbi", |
| 913 | "service": "service", |
| 914 | }, |
| 915 | ) |
| 916 | |
| 917 | self.assertEqual(self.harness.charm.state.keystone_host, "keystone") |
| 918 | self.assertEqual(self.harness.charm.state.keystone_port, 5000) |
| 919 | self.assertEqual(self.harness.charm.state.keystone_user_domain_name, "default") |
| 920 | self.assertEqual( |
| 921 | self.harness.charm.state.keystone_project_domain_name, "default" |
| 922 | ) |
| 923 | self.assertEqual(self.harness.charm.state.keystone_username, "nbi") |
| 924 | self.assertEqual(self.harness.charm.state.keystone_password, "nbi") |
| 925 | self.assertEqual(self.harness.charm.state.keystone_service, "service") |
| 926 | |
| 927 | # Verifying status |
| 928 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 929 | |
| 930 | # Verifying status message |
| 931 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 932 | self.assertTrue( |
| 933 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 934 | ) |
| 935 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 936 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 937 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 938 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 939 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 940 | |
| sousaedu | 4df5a46 | 2020-11-17 14:30:47 +0000 | [diff] [blame] | 941 | def test_on_keystone_app_relation_changed(self) -> NoReturn: |
| 942 | """Test to see if keystone relation is updated.""" |
| 943 | self.harness.update_config({"auth_backend": "keystone"}) |
| 944 | |
| 945 | self.harness.charm.on.start.emit() |
| 946 | |
| 947 | self.assertIsNone(self.harness.charm.state.keystone_host) |
| 948 | self.assertIsNone(self.harness.charm.state.keystone_port) |
| 949 | self.assertIsNone(self.harness.charm.state.keystone_user_domain_name) |
| 950 | self.assertIsNone(self.harness.charm.state.keystone_project_domain_name) |
| 951 | self.assertIsNone(self.harness.charm.state.keystone_username) |
| 952 | self.assertIsNone(self.harness.charm.state.keystone_password) |
| 953 | self.assertIsNone(self.harness.charm.state.keystone_service) |
| 954 | |
| 955 | relation_id = self.harness.add_relation("keystone", "keystone") |
| 956 | self.harness.add_relation_unit(relation_id, "keystone/0") |
| 957 | self.harness.update_relation_data( |
| 958 | relation_id, |
| 959 | "keystone", |
| 960 | { |
| 961 | "host": "keystone", |
| 962 | "port": 5000, |
| 963 | "user_domain_name": "default", |
| 964 | "project_domain_name": "default", |
| 965 | "username": "nbi", |
| 966 | "password": "nbi", |
| 967 | "service": "service", |
| 968 | }, |
| 969 | ) |
| 970 | |
| 971 | self.assertEqual(self.harness.charm.state.keystone_host, "keystone") |
| 972 | self.assertEqual(self.harness.charm.state.keystone_port, 5000) |
| 973 | self.assertEqual(self.harness.charm.state.keystone_user_domain_name, "default") |
| 974 | self.assertEqual( |
| 975 | self.harness.charm.state.keystone_project_domain_name, "default" |
| 976 | ) |
| 977 | self.assertEqual(self.harness.charm.state.keystone_username, "nbi") |
| 978 | self.assertEqual(self.harness.charm.state.keystone_password, "nbi") |
| 979 | self.assertEqual(self.harness.charm.state.keystone_service, "service") |
| 980 | |
| 981 | # Verifying status |
| 982 | self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus) |
| 983 | |
| 984 | # Verifying status message |
| 985 | self.assertGreater(len(self.harness.charm.unit.status.message), 0) |
| 986 | self.assertTrue( |
| 987 | self.harness.charm.unit.status.message.startswith("Waiting for ") |
| 988 | ) |
| 989 | self.assertIn("kafka", self.harness.charm.unit.status.message) |
| 990 | self.assertIn("mongodb", self.harness.charm.unit.status.message) |
| 991 | self.assertIn("prometheus", self.harness.charm.unit.status.message) |
| 992 | self.assertNotIn("keystone", self.harness.charm.unit.status.message) |
| 993 | self.assertTrue(self.harness.charm.unit.status.message.endswith(" relations")) |
| 994 | |
| sousaedu | 6248fe6 | 2020-10-13 23:46:51 +0100 | [diff] [blame] | 995 | def test_publish_nbi_info(self) -> NoReturn: |
| 996 | """Test to see if nbi relation is updated.""" |
| 997 | expected_result = { |
| 998 | "host": "nbi", |
| 999 | "port": "9999", |
| 1000 | } |
| 1001 | |
| 1002 | self.harness.charm.on.start.emit() |
| 1003 | |
| 1004 | relation_id = self.harness.add_relation("nbi", "ng-ui") |
| 1005 | self.harness.add_relation_unit(relation_id, "ng-ui/0") |
| 1006 | relation_data = self.harness.get_relation_data(relation_id, "nbi") |
| 1007 | |
| 1008 | self.assertDictEqual(expected_result, relation_data) |
| 1009 | |
| 1010 | |
| 1011 | if __name__ == "__main__": |
| 1012 | unittest.main() |