2 #######################################################################################
3 # Copyright ETSI Contributors and Others.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #######################################################################################
22 from pathlib
import Path
26 from pytest_operator
.plugin
import OpsTest
28 logger
= logging
.getLogger(__name__
)
30 METADATA
= yaml
.safe_load(Path("./metadata.yaml").read_text())
35 KAFKA_CHARM
= "kafka-k8s"
37 MONGO_DB_CHARM
= "mongodb-k8s"
38 MONGO_DB_APP
= "mongodb"
41 ZOOKEEPER_CHARM
= "zookeeper-k8s"
42 ZOOKEEPER_APP
= "zookeeper"
43 LCM_APPS
= [KAFKA_APP
, MONGO_DB_APP
, ZOOKEEPER_APP
, RO_APP
, LCM_APP
]
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"
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.
67 Assert on the unit status before any relations/configurations take place.
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(
76 assert ops_test
.model
.applications
[VCA_APP
].units
[0].workload_status
== "blocked"
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(
86 "controllers": controllers
,
88 "public-key": public_key
,
89 "k8s-cloud": "microk8s",
92 async with ops_test
.fast_forward():
93 await ops_test
.model
.wait_for_idle(
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"
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"),
114 async with ops_test
.fast_forward():
115 await ops_test
.model
.wait_for_idle(
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
)
126 await ops_test
.model
.add_relation(RO_APP
, KAFKA_APP
)
128 await ops_test
.model
.add_relation(
129 "{}:mongodb".format(LCM_APP
), "{}:database".format(MONGO_DB_APP
)
131 await ops_test
.model
.add_relation(LCM_APP
, KAFKA_APP
)
132 await ops_test
.model
.add_relation(LCM_APP
, RO_APP
)
134 async with ops_test
.fast_forward():
135 await ops_test
.model
.wait_for_idle(
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
],
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),
166 async with ops_test
.fast_forward():
167 await ops_test
.model
.wait_for_idle(
171 logger
.info("Adding relations")
172 await ops_test
.model
.add_relation(MARIADB_APP
, KEYSTONE_APP
)
174 await ops_test
.model
.add_relation(
175 "{}:mongodb".format(MON_APP
), "{}:database".format(MONGO_DB_APP
)
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
)
181 async with ops_test
.fast_forward():
182 await ops_test
.model
.wait_for_idle(
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
],