diff --git a/charms/aodh-k8s/pyproject.toml b/charms/aodh-k8s/pyproject.toml index 2edc519a..2896bc05 100644 --- a/charms/aodh-k8s/pyproject.toml +++ b/charms/aodh-k8s/pyproject.toml @@ -1,3 +1,6 @@ +# Copyright 2022 Canonical Ltd. +# See LICENSE file for licensing details. + # Testing tools configuration [tool.coverage.run] branch = true @@ -11,23 +14,26 @@ log_cli_level = "INFO" # Formatting tools configuration [tool.black] -line-length = 99 -target-version = ["py38"] +line-length = 79 [tool.isort] -line_length = 99 profile = "black" +multi_line_output = 3 +force_grid_wrap = true # Linting tools configuration [tool.flake8] -max-line-length = 99 +max-line-length = 79 max-doc-length = 99 max-complexity = 10 exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"] select = ["E", "W", "F", "C", "N", "R", "D", "H"] # Ignore W503, E501 because using black creates errors with this # Ignore D107 Missing docstring in __init__ -ignore = ["W503", "E501", "D107"] -# D100, D101, D102, D103: Ignore missing docstrings in tests -per-file-ignores = ["tests/*:D100,D101,D102,D103,D104"] +ignore = ["W503", "E501", "D107", "E402"] +per-file-ignores = [] docstring-convention = "google" +# Check for properly formatted copyright header in each file +copyright-check = "True" +copyright-author = "Canonical Ltd." +copyright-regexp = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+%(author)s" diff --git a/charms/aodh-k8s/src/charm.py b/charms/aodh-k8s/src/charm.py index 75db039d..19992c3b 100755 --- a/charms/aodh-k8s/src/charm.py +++ b/charms/aodh-k8s/src/charm.py @@ -1,18 +1,38 @@ #!/usr/bin/env python3 +# Copyright 2023 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 a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """Aodh Operator Charm. This charm provide Aodh services as part of an OpenStack deployment """ import logging -from typing import List +from typing import ( + List, +) import ops.pebble import ops_sunbeam.charm as sunbeam_charm import ops_sunbeam.container_handlers as sunbeam_chandlers import ops_sunbeam.core as sunbeam_core -from ops.framework import StoredState -from ops.main import main +from ops.framework import ( + StoredState, +) +from ops.main import ( + main, +) logger = logging.getLogger(__name__) @@ -169,7 +189,9 @@ class AODHExpirerPebbleHandler(sunbeam_chandlers.ServicePebbleHandler): "aodh-expirer": { "override": "replace", "summary": "AODH Expirer", - "command": ('/bin/bash -c "while true; do aodh-expirer; sleep 60; done"'), + "command": ( + '/bin/bash -c "while true; do aodh-expirer; sleep 60; done"' + ), "startup": "enabled", "user": "aodh", "group": "aodh", @@ -201,6 +223,13 @@ class AodhOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm): db_sync_cmds = [["aodh-dbsync"]] + mandatory_relations = { + "database", + "identity-service", + "ingress-public", + "amqp", + } + @property def service_conf(self) -> str: """Service default configuration file.""" diff --git a/charms/aodh-k8s/src/templates/aodh.conf.j2 b/charms/aodh-k8s/src/templates/aodh.conf.j2 index f0335337..a66848a7 100644 --- a/charms/aodh-k8s/src/templates/aodh.conf.j2 +++ b/charms/aodh-k8s/src/templates/aodh.conf.j2 @@ -1,9 +1,14 @@ [DEFAULT] debug = {{ options.debug }} +{% if amqp.transport_url -%} +transport_url = {{ amqp.transport_url }} +{%- endif %} + +[api] gnocchi_external_project_owner = services -{% if identity_service.service_domain -%} -gnocchi_external_domain_name = {{ identity_service.service_domain }} +{% if identity_service.service_domain_name -%} +gnocchi_external_domain_name = {{ identity_service.service_domain_name }} {% endif %} {% include "parts/section-database" %} @@ -12,5 +17,4 @@ alarm_histories_delete_batch_size = {{ options.alarm_histories_delete_batch_size {% include "parts/section-identity" %} -{% include "parts/section-service-user" %} - +{% include "parts/section-service-credentials" %} diff --git a/charms/aodh-k8s/src/templates/parts/section-service-credentials b/charms/aodh-k8s/src/templates/parts/section-service-credentials new file mode 100644 index 00000000..bc4b357b --- /dev/null +++ b/charms/aodh-k8s/src/templates/parts/section-service-credentials @@ -0,0 +1,14 @@ +{% if identity_service.service_domain_id -%} +[service_credentials] +{% if identity_service.internal_auth_url -%} +auth_url = {{ identity_service.internal_auth_url }} +{% elif identity_service.internal_host -%} +auth_url = {{ identity_service.internal_protocol }}://{{ identity_service.internal_host }}:{{ identity_service.internal_port }} +{% endif -%} +auth_type = password +project_domain_id = {{ identity_service.service_domain_id }} +user_domain_id = {{ identity_service.service_domain_id }} +project_name = {{ identity_service.service_project_name }} +username = {{ identity_service.service_user_name }} +password = {{ identity_service.service_password }} +{% endif -%} diff --git a/charms/aodh-k8s/tests/integration/test_charm.py b/charms/aodh-k8s/tests/integration/test_charm.py index 18f24d39..72f304fa 100644 --- a/charms/aodh-k8s/tests/integration/test_charm.py +++ b/charms/aodh-k8s/tests/integration/test_charm.py @@ -1,14 +1,32 @@ #!/usr/bin/env python3 -# Copyright 2023 liam -# See LICENSE file for licensing details. + +# Copyright 2023 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 a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for aodh charm.""" import asyncio import logging -from pathlib import Path +from pathlib import ( + Path, +) import pytest import yaml -from pytest_operator.plugin import OpsTest +from pytest_operator.plugin import ( + OpsTest, +) logger = logging.getLogger(__name__) @@ -24,12 +42,21 @@ async def test_build_and_deploy(ops_test: OpsTest): """ # Build and deploy charm from local source folder charm = await ops_test.build_charm(".") - resources = {"httpbin-image": METADATA["resources"]["httpbin-image"]["upstream-source"]} + resources = { + "httpbin-image": METADATA["resources"]["httpbin-image"][ + "upstream-source" + ] + } # Deploy the charm and wait for active/idle status await asyncio.gather( - ops_test.model.deploy(await charm, resources=resources, application_name=APP_NAME), + ops_test.model.deploy( + await charm, resources=resources, application_name=APP_NAME + ), ops_test.model.wait_for_idle( - apps=[APP_NAME], status="active", raise_on_blocked=True, timeout=1000 + apps=[APP_NAME], + status="active", + raise_on_blocked=True, + timeout=1000, ), ) diff --git a/charms/aodh-k8s/tests/unit/test_charm.py b/charms/aodh-k8s/tests/unit/test_charm.py index a90d1106..a5967b30 100644 --- a/charms/aodh-k8s/tests/unit/test_charm.py +++ b/charms/aodh-k8s/tests/unit/test_charm.py @@ -53,7 +53,9 @@ class TestAodhOperatorCharm(test_utils.CharmTestCase): # clean up events that were dynamically defined, # otherwise we get issues because they'll be redefined, # which is not allowed. - from charms.data_platform_libs.v0.database_requires import DatabaseEvents + from charms.data_platform_libs.v0.database_requires import ( + DatabaseEvents, + ) for attr in ( "database_database_created", @@ -78,16 +80,9 @@ class TestAodhOperatorCharm(test_utils.CharmTestCase): def test_all_relations(self): """Test all the charms relations.""" self.harness.begin_with_initial_hooks() - test_utils.add_db_relation_credentials( - self.harness, test_utils.add_base_db_relation(self.harness) - ) - test_utils.add_identity_service_relation_response( - self.harness, - test_utils.add_base_identity_service_relation(self.harness), - ) - self.harness.set_leader() test_utils.set_all_pebbles_ready(self.harness) + test_utils.add_api_relations(self.harness) app_setup_cmds = [ ["a2ensite", "wsgi-aodh-api"], @@ -97,5 +92,11 @@ class TestAodhOperatorCharm(test_utils.CharmTestCase): for cmd in app_setup_cmds: self.assertIn(cmd, self.container_calls.execute["aodh-api"]) - for c in ["aodh-api", "aodh-evaluator", "aodh-notifier", "aodh-listener", "aodh-expirer"]: + for c in [ + "aodh-api", + "aodh-evaluator", + "aodh-notifier", + "aodh-listener", + "aodh-expirer", + ]: self.check_file(c, "/etc/aodh/aodh.conf")