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
28 from charm
import KeystoneCharm
29 from ops
.model
import ActiveStatus
, BlockedStatus
30 from ops
.testing
import Harness
33 class TestCharm(unittest
.TestCase
):
34 """Keystone Charm unit tests."""
36 def setUp(self
) -> NoReturn
:
38 self
.image_info
= sys
.modules
["oci_image"].OCIImageResource().fetch()
39 self
.harness
= Harness(KeystoneCharm
)
40 self
.harness
.set_leader(is_leader
=True)
44 "keystone_db_password": "str",
45 "admin_username": "str",
46 "admin_password": "str",
47 "admin_project": "str",
48 "service_username": "str",
49 "service_password": "str",
50 "service_project": "str",
51 "user_domain_name": "str",
52 "project_domain_name": "str",
53 "token_expiration": 10,
55 "site_url": "http://keystone.com",
56 "ldap_enabled": False,
58 self
.harness
.update_config(self
.config
)
60 def test_config_changed_no_relations(
63 """Test ingress resources without HTTP."""
65 self
.harness
.charm
.on
.config_changed
.emit()
68 self
.assertIsInstance(self
.harness
.charm
.unit
.status
, BlockedStatus
)
71 relation
in self
.harness
.charm
.unit
.status
.message
72 for relation
in ["mysql"]
76 def test_config_changed_non_leader(
79 """Test ingress resources without HTTP."""
80 self
.harness
.set_leader(is_leader
=False)
81 self
.harness
.charm
.on
.config_changed
.emit()
84 self
.assertIsInstance(self
.harness
.charm
.unit
.status
, ActiveStatus
)
86 def test_with_relations(
90 self
.initialize_mysql_relation()
92 self
.assertNotIsInstance(self
.harness
.charm
.unit
.status
, BlockedStatus
)
94 def initialize_mysql_relation(self
):
95 relation_id
= self
.harness
.add_relation("db", "mysql")
96 self
.harness
.add_relation_unit(relation_id
, "mysql/0")
97 self
.harness
.update_relation_data(
104 "password": "manopw",
105 "root_password": "rootmanopw",
110 if __name__
== "__main__":
114 # class TestCharm(unittest.TestCase):
115 # """Prometheus Charm unit tests."""
117 # def setUp(self) -> NoReturn:
119 # self.image_info = sys.modules["oci_image"].OCIImageResource().fetch()
120 # self.harness = Harness(KeystoneCharm)
121 # self.harness.set_leader(is_leader=True)
122 # self.harness.begin()
124 # "enable_ng_ro": True,
125 # "database_commonkey": "commonkey",
126 # "log_level": "INFO",
127 # "vim_database": "db_name",
128 # "ro_database": "ro_db_name",
129 # "openmano_tenant": "mano",
132 # def test_config_changed_no_relations(
135 # """Test ingress resources without HTTP."""
137 # self.harness.charm.on.config_changed.emit()
140 # self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
143 # relation in self.harness.charm.unit.status.message
144 # for relation in ["mongodb", "kafka"]
149 # self.harness.update_config({"enable_ng_ro": False})
150 # self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
153 # relation in self.harness.charm.unit.status.message
154 # for relation in ["mysql"]
158 # def test_config_changed_non_leader(
161 # """Test ingress resources without HTTP."""
162 # self.harness.set_leader(is_leader=False)
163 # self.harness.charm.on.config_changed.emit()
166 # self.assertIsInstance(self.harness.charm.unit.status, ActiveStatus)
168 # def test_with_relations_ng(
171 # "Test with relations (ng-ro)"
173 # # Initializing the kafka relation
174 # kafka_relation_id = self.harness.add_relation("kafka", "kafka")
175 # self.harness.add_relation_unit(kafka_relation_id, "kafka/0")
176 # self.harness.update_relation_data(
177 # kafka_relation_id, "kafka/0", {"host": "kafka", "port": 9092}
180 # # Initializing the mongo relation
181 # mongodb_relation_id = self.harness.add_relation("mongodb", "mongodb")
182 # self.harness.add_relation_unit(mongodb_relation_id, "mongodb/0")
183 # self.harness.update_relation_data(
184 # mongodb_relation_id,
186 # {"connection_string": "mongodb://mongo:27017"},
189 # self.harness.charm.on.config_changed.emit()
192 # self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus)
195 # if __name__ == "__main__":