Integrate MON and Prometheus
[osm/devops.git] / installers / charm / osm-mon / tests / integration / test_charm.py
index e14e191..f5d0cea 100644 (file)
@@ -42,7 +42,7 @@ MARIADB_CHARM = "charmed-osm-mariadb-k8s"
 MARIADB_APP = "mariadb"
 MONGO_DB_CHARM = "mongodb-k8s"
 MONGO_DB_APP = "mongodb"
-PROMETHEUS_CHARM = "osm-prometheus"
+PROMETHEUS_CHARM = "prometheus-k8s"
 PROMETHEUS_APP = "prometheus"
 ZOOKEEPER_CHARM = "zookeeper-k8s"
 ZOOKEEPER_APP = "zookeeper"
@@ -63,7 +63,7 @@ async def test_mon_and_other_charms_are_idle(ops_test: OpsTest):
         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="5/edge"),
         ops_test.model.deploy(MARIADB_CHARM, application_name=MARIADB_APP, channel="stable"),
-        ops_test.model.deploy(PROMETHEUS_CHARM, application_name=PROMETHEUS_APP, channel="stable"),
+        ops_test.model.deploy(PROMETHEUS_CHARM, application_name=PROMETHEUS_APP, channel="edge"),
         ops_test.model.deploy(ZOOKEEPER_CHARM, application_name=ZOOKEEPER_APP, channel="stable"),
     )
     keystone_image = "opensourcemano/keystone:testing-daily"
@@ -75,9 +75,17 @@ async def test_mon_and_other_charms_are_idle(ops_test: OpsTest):
 
 
 @pytest.mark.abort_on_fail
-async def test_mon_is_blocked_due_to_missing_grafana_config(ops_test: OpsTest):
+async def test_mon_is_blocked_due_to_missing_mandatory_config(ops_test: OpsTest):
     assert ops_test.model.applications[MON_APP].status == "blocked"
     unit = ops_test.model.applications[MON_APP].units[0]
+    assert (
+        unit.workload_status_message
+        == "need grafana-url, grafana-user, grafana-password, prometheus-url config"
+    )
+
+    await ops_test.model.applications[MON_APP].set_config({"prometheus-url": "a_value"})
+    async with ops_test.fast_forward():
+        await ops_test.model.wait_for_idle(apps=[MON_APP], status="blocked")
     assert (
         unit.workload_status_message == "need grafana-url, grafana-user, grafana-password config"
     )
@@ -99,6 +107,12 @@ async def test_mon_is_blocked_due_to_missing_grafana_config(ops_test: OpsTest):
     assert unit.workload_status_message == "Invalid value for grafana-url config: 'new_value'"
     await ops_test.model.applications[MON_APP].set_config({"grafana-url": "http://valid:92"})
 
+    async with ops_test.fast_forward():
+        await ops_test.model.wait_for_idle(apps=[MON_APP], status="blocked")
+
+    assert unit.workload_status_message == "Invalid value for prometheus-url config: 'a_value'"
+    await ops_test.model.applications[MON_APP].set_config({"prometheus-url": "http://valid:95"})
+
 
 @pytest.mark.abort_on_fail
 async def test_mon_is_blocked_due_to_missing_relations(ops_test: OpsTest):
@@ -135,25 +149,26 @@ async def test_mon_scales_up(ops_test: OpsTest):
         )
 
 
+app_to_relation = {
+    KAFKA_APP: KAFKA_APP,
+    MONGO_DB_APP: "database",
+    PROMETHEUS_APP: "metrics-endpoint",
+    KEYSTONE_APP: KEYSTONE_APP,
+}
+
+
 @pytest.mark.abort_on_fail
-@pytest.mark.parametrize(
-    "relation_to_remove", [KAFKA_APP, MONGO_DB_APP, PROMETHEUS_APP, KEYSTONE_APP]
-)
-async def test_mon_blocks_without_relation(ops_test: OpsTest, relation_to_remove):
-    logger.info("Removing relation: %s", relation_to_remove)
-    # mongoDB relation is named "database"
-    local_relation = relation_to_remove
-    if relation_to_remove == MONGO_DB_APP:
-        local_relation = "database"
-    await asyncio.gather(
-        ops_test.model.applications[relation_to_remove].remove_relation(local_relation, MON_APP)
-    )
+@pytest.mark.parametrize("app", app_to_relation.keys())
+async def test_mon_blocks_without_relation(ops_test: OpsTest, app):
+    logger.info("Removing relation with: %s", app)
+    relation = app_to_relation[app]
+    await ops_test.model.applications[app].remove_relation(relation, MON_APP)
     async with ops_test.fast_forward():
         await ops_test.model.wait_for_idle(apps=[MON_APP])
     assert ops_test.model.applications[MON_APP].status == "blocked"
     for unit in ops_test.model.applications[MON_APP].units:
-        assert unit.workload_status_message == f"need {relation_to_remove} relation"
-    await ops_test.model.add_relation(MON_APP, relation_to_remove)
+        assert unit.workload_status_message == f"need {app} relation"
+    await ops_test.model.add_relation(MON_APP, app)
     async with ops_test.fast_forward():
         await ops_test.model.wait_for_idle(apps=APPS, status="active")
 
@@ -201,11 +216,10 @@ async def test_mon_action_debug_mode_enabled(ops_test: OpsTest):
 
 @pytest.mark.abort_on_fail
 async def test_mon_integration_vca(ops_test: OpsTest):
-    await asyncio.gather(
-        ops_test.model.deploy(
-            VCA_CHARM, application_name=VCA_APP, channel="latest/beta", series="jammy"
-        ),
+    await ops_test.model.deploy(
+        VCA_CHARM, application_name=VCA_APP, channel="latest/beta", series="jammy"
     )
+
     async with ops_test.fast_forward():
         await ops_test.model.wait_for_idle(apps=[VCA_APP])
     controllers = (Path.home() / ".local/share/juju/controllers.yaml").read_text()