756a5e4213c3b199d093a9ee1878d696e7e92714
2 # Copyright 2021 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
24 from typing
import NoReturn
26 from ops
.model
import ActiveStatus
, BlockedStatus
27 from ops
.testing
import Harness
29 from charm
import KeystoneCharm
32 class TestCharm(unittest
.TestCase
):
33 """Keystone Charm unit tests."""
35 def setUp(self
) -> NoReturn
:
37 self
.image_info
= sys
.modules
["oci_image"].OCIImageResource().fetch()
38 self
.harness
= Harness(KeystoneCharm
)
39 self
.harness
.set_leader(is_leader
=True)
43 "keystone_db_password": "str",
44 "admin_username": "str",
45 "admin_password": "str",
46 "admin_project": "str",
47 "service_username": "str",
48 "service_password": "str",
49 "service_project": "str",
50 "user_domain_name": "str",
51 "project_domain_name": "str",
52 "token_expiration": 10,
54 "site_url": "http://keystone.com",
55 "ldap_enabled": False,
57 self
.harness
.update_config(self
.config
)
59 def test_config_changed_no_relations(
62 """Test ingress resources without HTTP."""
64 self
.harness
.charm
.on
.config_changed
.emit()
67 self
.assertIsInstance(self
.harness
.charm
.unit
.status
, BlockedStatus
)
70 relation
in self
.harness
.charm
.unit
.status
.message
71 for relation
in ["mysql"]
75 def test_config_changed_non_leader(
78 """Test ingress resources without HTTP."""
79 self
.harness
.set_leader(is_leader
=False)
80 self
.harness
.charm
.on
.config_changed
.emit()
83 self
.assertIsInstance(self
.harness
.charm
.unit
.status
, ActiveStatus
)
85 def test_with_relations(
89 self
.initialize_mysql_relation()
91 self
.assertNotIsInstance(self
.harness
.charm
.unit
.status
, BlockedStatus
)
93 def initialize_mysql_relation(self
):
94 relation_id
= self
.harness
.add_relation("db", "mysql")
95 self
.harness
.add_relation_unit(relation_id
, "mysql/0")
96 self
.harness
.update_relation_data(
103 "password": "manopw",
104 "root_password": "rootmanopw",
109 if __name__
== "__main__":
113 # class TestCharm(unittest.TestCase):
114 # """Prometheus Charm unit tests."""
116 # def setUp(self) -> NoReturn:
118 # self.image_info = sys.modules["oci_image"].OCIImageResource().fetch()
119 # self.harness = Harness(KeystoneCharm)
120 # self.harness.set_leader(is_leader=True)
121 # self.harness.begin()
123 # "enable_ng_ro": True,
124 # "database_commonkey": "commonkey",
125 # "log_level": "INFO",
126 # "vim_database": "db_name",
127 # "ro_database": "ro_db_name",
128 # "openmano_tenant": "mano",
131 # def test_config_changed_no_relations(
134 # """Test ingress resources without HTTP."""
136 # self.harness.charm.on.config_changed.emit()
139 # self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
142 # relation in self.harness.charm.unit.status.message
143 # for relation in ["mongodb", "kafka"]
148 # self.harness.update_config({"enable_ng_ro": False})
149 # self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
152 # relation in self.harness.charm.unit.status.message
153 # for relation in ["mysql"]
157 # def test_config_changed_non_leader(
160 # """Test ingress resources without HTTP."""
161 # self.harness.set_leader(is_leader=False)
162 # self.harness.charm.on.config_changed.emit()
165 # self.assertIsInstance(self.harness.charm.unit.status, ActiveStatus)
167 # def test_with_relations_ng(
170 # "Test with relations (ng-ro)"
172 # # Initializing the kafka relation
173 # kafka_relation_id = self.harness.add_relation("kafka", "kafka")
174 # self.harness.add_relation_unit(kafka_relation_id, "kafka/0")
175 # self.harness.update_relation_data(
176 # kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092}
179 # # Initializing the mongo relation
180 # mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb")
181 # self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0")
182 # self.harness.update_relation_data(
183 # mongodb_relation_id,
185 # {"connection_string": "mongodb://mongo:27017"},
188 # self.harness.charm.on.config_changed.emit()
191 # self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus)
194 # if __name__ == "__main__":