Integration tests for VCA Integrator Operator
[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)
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=focal"
102 ro_deploy_cmd = f"juju deploy {RO_CHARM} {RO_APP} --resource ro-image=opensourcemano/ro:testing-daily --channel=latest/beta --series=focal"
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="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(RO_APP, MONGO_DB_APP)
124 await ops_test.model.add_relation(RO_APP, KAFKA_APP)
125 # LCM specific
126 await ops_test.model.add_relation(LCM_APP, MONGO_DB_APP)
127 await ops_test.model.add_relation(LCM_APP, KAFKA_APP)
128 await ops_test.model.add_relation(LCM_APP, RO_APP)
129
130 async with ops_test.fast_forward():
131 await ops_test.model.wait_for_idle(
132 apps=LCM_APPS,
133 status="active",
134 )
135
136 logger.info("Adding relation VCA LCM")
137 await ops_test.model.add_relation(VCA_APP, LCM_APP)
138 async with ops_test.fast_forward():
139 await ops_test.model.wait_for_idle(
140 apps=[VCA_APP, LCM_APP],
141 status="active",
142 )
143
144
145 @pytest.mark.abort_on_fail
146 async def test_vca_integration_mon(ops_test: OpsTest):
147 keystone_deploy_cmd = f"juju deploy {KEYSTONE_CHARM} {KEYSTONE_APP} --resource keystone-image=opensourcemano/keystone:testing-daily"
148 mon_deploy_cmd = f"juju deploy {MON_CHARM} {MON_APP} --resource mon-image=opensourcemano/mon:testing-daily --channel=latest/beta --series=focal"
149 await asyncio.gather(
150 # MON charm has to be deployed differently since
151 # bug https://github.com/juju/python-libjuju/issues/820
152 # fails to parse assumes
153 ops_test.run(*shlex.split(mon_deploy_cmd), check=True),
154 ops_test.model.deploy(MARIADB_CHARM, application_name=MARIADB_APP, channel="stable"),
155 ops_test.model.deploy(PROMETHEUS_CHARM, application_name=PROMETHEUS_APP, channel="stable"),
156 # Keystone charm has to be deployed differently since
157 # bug https://github.com/juju/python-libjuju/issues/766
158 # prevents setting correctly the resources
159 ops_test.run(*shlex.split(keystone_deploy_cmd), check=True),
160 )
161 async with ops_test.fast_forward():
162 await ops_test.model.wait_for_idle(
163 apps=MON_APPS,
164 )
165
166 logger.info("Adding relations")
167 await ops_test.model.add_relation(MARIADB_APP, KEYSTONE_APP)
168 # MON specific
169 await ops_test.model.add_relation(MON_APP, MONGO_DB_APP)
170 await ops_test.model.add_relation(MON_APP, KAFKA_APP)
171 await ops_test.model.add_relation(MON_APP, KEYSTONE_APP)
172 await ops_test.model.add_relation(MON_APP, PROMETHEUS_APP)
173
174 async with ops_test.fast_forward():
175 await ops_test.model.wait_for_idle(
176 apps=MON_APPS,
177 status="active",
178 )
179
180 logger.info("Adding relation VCA MON")
181 await ops_test.model.add_relation(VCA_APP, MON_APP)
182 async with ops_test.fast_forward():
183 await ops_test.model.wait_for_idle(
184 apps=[VCA_APP, MON_APP],
185 status="active",
186 )