# limitations under the License.
#######################################################################################
+import asyncio
import logging
+import shlex
from pathlib import Path
import pytest
logger = logging.getLogger(__name__)
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
+VCA_APP = "osm-vca"
+
+LCM_CHARM = "osm-lcm"
+LCM_APP = "lcm"
+KAFKA_CHARM = "kafka-k8s"
+KAFKA_APP = "kafka"
+MONGO_DB_CHARM = "mongodb-k8s"
+MONGO_DB_APP = "mongodb"
+RO_CHARM = "osm-ro"
+RO_APP = "ro"
+ZOOKEEPER_CHARM = "zookeeper-k8s"
+ZOOKEEPER_APP = "zookeeper"
+LCM_APPS = [KAFKA_APP, MONGO_DB_APP, ZOOKEEPER_APP, RO_APP, LCM_APP]
+MON_CHARM = "osm-mon"
+MON_APP = "mon"
+KEYSTONE_CHARM = "osm-keystone"
+KEYSTONE_APP = "keystone"
+MARIADB_CHARM = "charmed-osm-mariadb-k8s"
+MARIADB_APP = "mariadb"
+PROMETHEUS_CHARM = "osm-prometheus"
+PROMETHEUS_APP = "prometheus"
+MON_APPS = [
+ KAFKA_APP,
+ ZOOKEEPER_APP,
+ KEYSTONE_APP,
+ MONGO_DB_APP,
+ MARIADB_APP,
+ PROMETHEUS_APP,
+ MON_APP,
+]
@pytest.mark.abort_on_fail
Assert on the unit status before any relations/configurations take place.
"""
- await ops_test.model.set_config({"update-status-hook-interval": "10s"})
-
charm = await ops_test.build_charm(".")
- await ops_test.model.deploy(charm, application_name="osm-vca-integrator-k8s")
- await ops_test.model.wait_for_idle(
- apps=["osm-vca-integrator-k8s"], status="blocked", timeout=1000
+ await ops_test.model.deploy(charm, application_name=VCA_APP)
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=[VCA_APP],
+ status="blocked",
+ )
+ assert ops_test.model.applications[VCA_APP].units[0].workload_status == "blocked"
+
+
+@pytest.mark.abort_on_fail
+async def test_vca_configuration(ops_test: OpsTest):
+ controllers = (Path.home() / ".local/share/juju/controllers.yaml").read_text()
+ accounts = (Path.home() / ".local/share/juju/accounts.yaml").read_text()
+ public_key = (Path.home() / ".local/share/juju/ssh/juju_id_rsa.pub").read_text()
+ await ops_test.model.applications[VCA_APP].set_config(
+ {
+ "controllers": controllers,
+ "accounts": accounts,
+ "public-key": public_key,
+ "k8s-cloud": "microk8s",
+ }
)
- assert (
- ops_test.model.applications["osm-vca-integrator-k8s"].units[0].workload_status == "blocked"
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=[VCA_APP],
+ status="active",
+ )
+
+
+@pytest.mark.abort_on_fail
+async def test_vca_integration_lcm(ops_test: OpsTest):
+ lcm_deploy_cmd = f"juju deploy {LCM_CHARM} {LCM_APP} --resource lcm-image=opensourcemano/lcm:testing-daily --channel=latest/beta --series=focal"
+ ro_deploy_cmd = f"juju deploy {RO_CHARM} {RO_APP} --resource ro-image=opensourcemano/ro:testing-daily --channel=latest/beta --series=focal"
+
+ await asyncio.gather(
+ # LCM and RO charms have to be deployed differently since
+ # bug https://github.com/juju/python-libjuju/pull/820
+ # fails to parse assumes
+ ops_test.run(*shlex.split(lcm_deploy_cmd), check=True),
+ ops_test.run(*shlex.split(ro_deploy_cmd), check=True),
+ ops_test.model.deploy(KAFKA_CHARM, application_name=KAFKA_APP, channel="stable"),
+ ops_test.model.deploy(MONGO_DB_CHARM, application_name=MONGO_DB_APP, channel="edge"),
+ ops_test.model.deploy(ZOOKEEPER_CHARM, application_name=ZOOKEEPER_APP, channel="stable"),
)
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=LCM_APPS,
+ )
+ # wait for MongoDB to be active before relating RO to it
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(apps=[MONGO_DB_APP], status="active")
+ logger.info("Adding relations")
+ await ops_test.model.add_relation(KAFKA_APP, ZOOKEEPER_APP)
+ await ops_test.model.add_relation(RO_APP, MONGO_DB_APP)
+ await ops_test.model.add_relation(RO_APP, KAFKA_APP)
+ # LCM specific
+ await ops_test.model.add_relation(LCM_APP, MONGO_DB_APP)
+ await ops_test.model.add_relation(LCM_APP, KAFKA_APP)
+ await ops_test.model.add_relation(LCM_APP, RO_APP)
+
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=LCM_APPS,
+ status="active",
+ )
+
+ logger.info("Adding relation VCA LCM")
+ await ops_test.model.add_relation(VCA_APP, LCM_APP)
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=[VCA_APP, LCM_APP],
+ status="active",
+ )
+
+
+@pytest.mark.abort_on_fail
+async def test_vca_integration_mon(ops_test: OpsTest):
+ keystone_deploy_cmd = f"juju deploy {KEYSTONE_CHARM} {KEYSTONE_APP} --resource keystone-image=opensourcemano/keystone:testing-daily"
+ mon_deploy_cmd = f"juju deploy {MON_CHARM} {MON_APP} --resource mon-image=opensourcemano/mon:testing-daily --channel=latest/beta --series=focal"
+ await asyncio.gather(
+ # MON charm has to be deployed differently since
+ # bug https://github.com/juju/python-libjuju/issues/820
+ # fails to parse assumes
+ ops_test.run(*shlex.split(mon_deploy_cmd), check=True),
+ ops_test.model.deploy(MARIADB_CHARM, application_name=MARIADB_APP, channel="stable"),
+ ops_test.model.deploy(PROMETHEUS_CHARM, application_name=PROMETHEUS_APP, channel="stable"),
+ # Keystone charm has to be deployed differently since
+ # bug https://github.com/juju/python-libjuju/issues/766
+ # prevents setting correctly the resources
+ ops_test.run(*shlex.split(keystone_deploy_cmd), check=True),
+ )
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=MON_APPS,
+ )
+
+ logger.info("Adding relations")
+ await ops_test.model.add_relation(MARIADB_APP, KEYSTONE_APP)
+ # MON specific
+ await ops_test.model.add_relation(MON_APP, MONGO_DB_APP)
+ await ops_test.model.add_relation(MON_APP, KAFKA_APP)
+ await ops_test.model.add_relation(MON_APP, KEYSTONE_APP)
+ await ops_test.model.add_relation(MON_APP, PROMETHEUS_APP)
+
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=MON_APPS,
+ status="active",
+ )
- logger.debug("Setting update-status-hook-interval to 60m")
- await ops_test.model.set_config({"update-status-hook-interval": "60m"})
+ logger.info("Adding relation VCA MON")
+ await ops_test.model.add_relation(VCA_APP, MON_APP)
+ async with ops_test.fast_forward():
+ await ops_test.model.wait_for_idle(
+ apps=[VCA_APP, MON_APP],
+ status="active",
+ )