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
)
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=focal"
102 ro_deploy_cmd
= f
"juju deploy {RO_CHARM} {RO_APP} --resource ro-image=opensourcemano/ro:testing-daily --channel=latest/beta --series=focal"
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"),
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(RO_APP
, MONGO_DB_APP
)
124 await ops_test
.model
.add_relation(RO_APP
, KAFKA_APP
)
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
)
130 async with ops_test
.fast_forward():
131 await ops_test
.model
.wait_for_idle(
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
],
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),
161 async with ops_test
.fast_forward():
162 await ops_test
.model
.wait_for_idle(
166 logger
.info("Adding relations")
167 await ops_test
.model
.add_relation(MARIADB_APP
, KEYSTONE_APP
)
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
)
174 async with ops_test
.fast_forward():
175 await ops_test
.model
.wait_for_idle(
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
],