Major improvement in OSM charms
- Adapt all new operator charms to use the same pattern. They are all
using now this library that encapsulates the common logic for all
charms: https://github.com/davigar15/ops-lib-charmed-osm. That will be
eventually moved to gitlab, when it has a PyPI repository available
- Add unit tests to all charms
- Modify installer and bundles to point to the new charms
- Improve the build.sh script for building the charms
Change-Id: I0896ceb082d1b6a76b3560c07482a4135a220a3f
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/installers/charm/ng-ui/tests/test_charm.py b/installers/charm/ng-ui/tests/test_charm.py
index 1cde2df..d9a4d3e 100644
--- a/installers/charm/ng-ui/tests/test_charm.py
+++ b/installers/charm/ng-ui/tests/test_charm.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright 2020 Canonical Ltd.
+# Copyright 2021 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -20,27 +20,77 @@
# osm-charmers@lists.launchpad.net
##
+import sys
from typing import NoReturn
import unittest
-
+from ops.model import ActiveStatus, BlockedStatus
from ops.testing import Harness
from charm import NgUiCharm
class TestCharm(unittest.TestCase):
- """PLA Charm unit tests."""
+ """Prometheus Charm unit tests."""
def setUp(self) -> NoReturn:
"""Test setup"""
+ self.image_info = sys.modules["oci_image"].OCIImageResource().fetch()
self.harness = Harness(NgUiCharm)
self.harness.set_leader(is_leader=True)
self.harness.begin()
+ self.config = {
+ "server_name": "localhost",
+ "port": 80,
+ "max_file_size": 0,
+ "ingress_whitelist_source_range": "",
+ "tls_secret_name": "",
+ "site_url": "https://ui.192.168.100.100.xip.io",
+ }
+ self.harness.update_config(self.config)
- def test_on_start_without_relations(self) -> NoReturn:
- """Test installation without any relation."""
+ def test_config_changed_no_relations(
+ self,
+ ) -> NoReturn:
+ """Test ingress resources without HTTP."""
+
self.harness.charm.on.config_changed.emit()
+ # Assertions
+ self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
+ self.assertTrue(
+ all(
+ relation in self.harness.charm.unit.status.message
+ for relation in ["nbi"]
+ )
+ )
+
+ def test_config_changed_non_leader(
+ self,
+ ) -> NoReturn:
+ """Test ingress resources without HTTP."""
+ self.harness.set_leader(is_leader=False)
+ self.harness.charm.on.config_changed.emit()
+
+ # Assertions
+ self.assertIsInstance(self.harness.charm.unit.status, ActiveStatus)
+
+ def test_with_relations(
+ self,
+ ) -> NoReturn:
+ "Test with relations (internal)"
+ self.initialize_nbi_relation()
+ # Verifying status
+ self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus)
+
+ def initialize_nbi_relation(self):
+ http_relation_id = self.harness.add_relation("nbi", "nbi")
+ self.harness.add_relation_unit(http_relation_id, "nbi")
+ self.harness.update_relation_data(
+ http_relation_id,
+ "nbi",
+ {"host": "nbi", "port": 9999},
+ )
+
if __name__ == "__main__":
unittest.main()