Build jammy charms for osm
[osm/devops.git] / installers / charm / vca-integrator-operator / tests / integration / test_charm.py
1 #!/usr/bin/env python3
2 #######################################################################################
3 # Copyright ETSI Contributors and Others.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #######################################################################################
18
19 import asyncio
20 import logging
21 import shlex
22 from pathlib import Path
23
24 import pytest
25 import yaml
26 from pytest_operator.plugin import OpsTest
27
28 logger = logging.getLogger(__name__)
29
30 METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
31 VCA_APP = "osm-vca"
32
33 LCM_CHARM = "osm-lcm"
34 LCM_APP = "lcm"
35 KAFKA_CHARM = "kafka-k8s"
36 KAFKA_APP = "kafka"
37 MONGO_DB_CHARM = "mongodb-k8s"
38 MONGO_DB_APP = "mongodb"
39 RO_CHARM = "osm-ro"
40 RO_APP = "ro"
41 ZOOKEEPER_CHARM = "zookeeper-k8s"
42 ZOOKEEPER_APP = "zookeeper"
43 LCM_APPS = [KAFKA_APP, MONGO_DB_APP, ZOOKEEPER_APP, RO_APP, LCM_APP]
44 MON_CHARM = "osm-mon"
45 MON_APP = "mon"
46 KEYSTONE_CHARM = "osm-keystone"
47 KEYSTONE_APP = "keystone"
48 MARIADB_CHARM = "charmed-osm-mariadb-k8s"
49 MARIADB_APP = "mariadb"
50 PROMETHEUS_CHARM = "osm-prometheus"
51 PROMETHEUS_APP = "prometheus"
52 MON_APPS = [
53 KAFKA_APP,
54 ZOOKEEPER_APP,
55 KEYSTONE_APP,
56 MONGO_DB_APP,
57 MARIADB_APP,
58 PROMETHEUS_APP,
59 MON_APP,
60 ]
61
62
63 @pytest.mark.abort_on_fail
64 async def test_build_and_deploy(ops_test: OpsTest):
65 """Build the charm osm-vca-integrator-k8s and deploy it together with related charms.
66
67 Assert on the unit status before any relations/configurations take place.
68 """
69 charm = await ops_test.build_charm(".")
70 await ops_test.model.deploy(charm, application_name=VCA_APP, series="jammy")
71 async with ops_test.fast_forward():
72 await ops_test.model.wait_for_idle(
73 apps=[VCA_APP],
74 status="blocked",
75 )
76 assert ops_test.model.applications[VCA_APP].units[0].workload_status == "blocked"
77
78
79 @pytest.mark.abort_on_fail
80 async def test_vca_configuration(ops_test: OpsTest):
81 controllers = (Path.home() / ".local/share/juju/controllers.yaml").read_text()
82 accounts = (Path.home() / ".local/share/juju/accounts.yaml").read_text()
83 public_key = (Path.home() / ".local/share/juju/ssh/juju_id_rsa.pub").read_text()
84 await ops_test.model.applications[VCA_APP].set_config(
85 {
86 "controllers": controllers,
87 "accounts": accounts,
88 "public-key": public_key,
89 "k8s-cloud": "microk8s",
90 }
91 )
92 async with ops_test.fast_forward():
93 await ops_test.model.wait_for_idle(
94 apps=[VCA_APP],
95 status="active",
96 )
97
98
99 @pytest.mark.abort_on_fail
100 async def test_vca_integration_lcm(ops_test: OpsTest):
101 lcm_deploy_cmd = f"juju deploy {LCM_CHARM} {LCM_APP} --resource lcm-image=opensourcemano/lcm:testing-daily --channel=latest/beta --series=jammy"
102 ro_deploy_cmd = f"juju deploy {RO_CHARM} {RO_APP} --resource ro-image=opensourcemano/ro:testing-daily --channel=latest/beta --series=jammy"
103
104 await asyncio.gather(
105 # LCM and RO charms have to be deployed differently since
106 # bug https://github.com/juju/python-libjuju/pull/820
107 # fails to parse assumes
108 ops_test.run(*shlex.split(lcm_deploy_cmd), check=True),
109 ops_test.run(*shlex.split(ro_deploy_cmd), check=True),
110 ops_test.model.deploy(KAFKA_CHARM, application_name=KAFKA_APP, channel="stable"),
111 ops_test.model.deploy(MONGO_DB_CHARM, application_name=MONGO_DB_APP, channel="5/edge"),
112 ops_test.model.deploy(ZOOKEEPER_CHARM, application_name=ZOOKEEPER_APP, channel="stable"),
113 )
114 async with ops_test.fast_forward():
115 await ops_test.model.wait_for_idle(
116 apps=LCM_APPS,
117 )
118 # wait for MongoDB to be active before relating RO to it
119 async with ops_test.fast_forward():
120 await ops_test.model.wait_for_idle(apps=[MONGO_DB_APP], status="active")
121 logger.info("Adding relations")
122 await ops_test.model.add_relation(KAFKA_APP, ZOOKEEPER_APP)
123 await ops_test.model.add_relation(
124 "{}:mongodb".format(RO_APP), "{}:database".format(MONGO_DB_APP)
125 )
126 await ops_test.model.add_relation(RO_APP, KAFKA_APP)
127 # LCM specific
128 await ops_test.model.add_relation(
129 "{}:mongodb".format(LCM_APP), "{}:database".format(MONGO_DB_APP)
130 )
131 await ops_test.model.add_relation(LCM_APP, KAFKA_APP)
132 await ops_test.model.add_relation(LCM_APP, RO_APP)
133
134 async with ops_test.fast_forward():
135 await ops_test.model.wait_for_idle(
136 apps=LCM_APPS,
137 status="active",
138 )
139
140 logger.info("Adding relation VCA LCM")
141 await ops_test.model.add_relation(VCA_APP, LCM_APP)
142 async with ops_test.fast_forward():
143 await ops_test.model.wait_for_idle(
144 apps=[VCA_APP, LCM_APP],
145 status="active",
146 )
147
148
149 @pytest.mark.abort_on_fail
150 async def test_vca_integration_mon(ops_test: OpsTest):
151 keystone_image = "opensourcemano/keystone:testing-daily"
152 keystone_deploy_cmd = f"juju deploy {KEYSTONE_CHARM} {KEYSTONE_APP} --resource keystone-image={keystone_image} --channel=latest/beta --series jammy"
153 mon_deploy_cmd = f"juju deploy {MON_CHARM} {MON_APP} --resource mon-image=opensourcemano/mon:testing-daily --channel=latest/beta --series=jammy"
154 await asyncio.gather(
155 # MON charm has to be deployed differently since
156 # bug https://github.com/juju/python-libjuju/issues/820
157 # fails to parse assumes
158 ops_test.run(*shlex.split(mon_deploy_cmd), check=True),
159 ops_test.model.deploy(MARIADB_CHARM, application_name=MARIADB_APP, channel="stable"),
160 ops_test.model.deploy(PROMETHEUS_CHARM, application_name=PROMETHEUS_APP, channel="stable"),
161 # Keystone charm has to be deployed differently since
162 # bug https://github.com/juju/python-libjuju/issues/766
163 # prevents setting correctly the resources
164 ops_test.run(*shlex.split(keystone_deploy_cmd), check=True),
165 )
166 async with ops_test.fast_forward():
167 await ops_test.model.wait_for_idle(
168 apps=MON_APPS,
169 )
170
171 logger.info("Adding relations")
172 await ops_test.model.add_relation(MARIADB_APP, KEYSTONE_APP)
173 # MON specific
174 await ops_test.model.add_relation(
175 "{}:mongodb".format(MON_APP), "{}:database".format(MONGO_DB_APP)
176 )
177 await ops_test.model.add_relation(MON_APP, KAFKA_APP)
178 await ops_test.model.add_relation(MON_APP, KEYSTONE_APP)
179 await ops_test.model.add_relation(MON_APP, PROMETHEUS_APP)
180
181 async with ops_test.fast_forward():
182 await ops_test.model.wait_for_idle(
183 apps=MON_APPS,
184 status="active",
185 )
186
187 logger.info("Adding relation VCA MON")
188 await ops_test.model.add_relation(VCA_APP, MON_APP)
189 async with ops_test.fast_forward():
190 await ops_test.model.wait_for_idle(
191 apps=[VCA_APP, MON_APP],
192 status="active",
193 )