Fix configuration issues

Add following to configuration file:
 - service_credentials
 - gnocchi external domain name.
 - transport_url

Run tox -e fmt for code formatting.

Change-Id: I2c77053ef73cfc82e884dbcd5666f307d11db2c3
This commit is contained in:
Hemanth Nakkina
2023-08-25 16:49:45 +05:30
parent 022c6c52c1
commit 0fe60eafb8
6 changed files with 113 additions and 32 deletions

View File

@@ -1,3 +1,6 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
# Testing tools configuration # Testing tools configuration
[tool.coverage.run] [tool.coverage.run]
branch = true branch = true
@@ -11,23 +14,26 @@ log_cli_level = "INFO"
# Formatting tools configuration # Formatting tools configuration
[tool.black] [tool.black]
line-length = 99 line-length = 79
target-version = ["py38"]
[tool.isort] [tool.isort]
line_length = 99
profile = "black" profile = "black"
multi_line_output = 3
force_grid_wrap = true
# Linting tools configuration # Linting tools configuration
[tool.flake8] [tool.flake8]
max-line-length = 99 max-line-length = 79
max-doc-length = 99 max-doc-length = 99
max-complexity = 10 max-complexity = 10
exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"] exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"]
select = ["E", "W", "F", "C", "N", "R", "D", "H"] select = ["E", "W", "F", "C", "N", "R", "D", "H"]
# Ignore W503, E501 because using black creates errors with this # Ignore W503, E501 because using black creates errors with this
# Ignore D107 Missing docstring in __init__ # Ignore D107 Missing docstring in __init__
ignore = ["W503", "E501", "D107"] ignore = ["W503", "E501", "D107", "E402"]
# D100, D101, D102, D103: Ignore missing docstrings in tests per-file-ignores = []
per-file-ignores = ["tests/*:D100,D101,D102,D103,D104"]
docstring-convention = "google" 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"

View File

@@ -1,18 +1,38 @@
#!/usr/bin/env python3 #!/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. """Aodh Operator Charm.
This charm provide Aodh services as part of an OpenStack deployment This charm provide Aodh services as part of an OpenStack deployment
""" """
import logging import logging
from typing import List from typing import (
List,
)
import ops.pebble import ops.pebble
import ops_sunbeam.charm as sunbeam_charm import ops_sunbeam.charm as sunbeam_charm
import ops_sunbeam.container_handlers as sunbeam_chandlers import ops_sunbeam.container_handlers as sunbeam_chandlers
import ops_sunbeam.core as sunbeam_core import ops_sunbeam.core as sunbeam_core
from ops.framework import StoredState from ops.framework import (
from ops.main import main StoredState,
)
from ops.main import (
main,
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -169,7 +189,9 @@ class AODHExpirerPebbleHandler(sunbeam_chandlers.ServicePebbleHandler):
"aodh-expirer": { "aodh-expirer": {
"override": "replace", "override": "replace",
"summary": "AODH Expirer", "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", "startup": "enabled",
"user": "aodh", "user": "aodh",
"group": "aodh", "group": "aodh",
@@ -201,6 +223,13 @@ class AodhOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
db_sync_cmds = [["aodh-dbsync"]] db_sync_cmds = [["aodh-dbsync"]]
mandatory_relations = {
"database",
"identity-service",
"ingress-public",
"amqp",
}
@property @property
def service_conf(self) -> str: def service_conf(self) -> str:
"""Service default configuration file.""" """Service default configuration file."""

View File

@@ -1,9 +1,14 @@
[DEFAULT] [DEFAULT]
debug = {{ options.debug }} debug = {{ options.debug }}
{% if amqp.transport_url -%}
transport_url = {{ amqp.transport_url }}
{%- endif %}
[api]
gnocchi_external_project_owner = services gnocchi_external_project_owner = services
{% if identity_service.service_domain -%} {% if identity_service.service_domain_name -%}
gnocchi_external_domain_name = {{ identity_service.service_domain }} gnocchi_external_domain_name = {{ identity_service.service_domain_name }}
{% endif %} {% endif %}
{% include "parts/section-database" %} {% 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-identity" %}
{% include "parts/section-service-user" %} {% include "parts/section-service-credentials" %}

View File

@@ -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 -%}

View File

@@ -1,14 +1,32 @@
#!/usr/bin/env python3 #!/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 asyncio
import logging import logging
from pathlib import Path from pathlib import (
Path,
)
import pytest import pytest
import yaml import yaml
from pytest_operator.plugin import OpsTest from pytest_operator.plugin import (
OpsTest,
)
logger = logging.getLogger(__name__) 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 # Build and deploy charm from local source folder
charm = await ops_test.build_charm(".") 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 # Deploy the charm and wait for active/idle status
await asyncio.gather( 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( 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,
), ),
) )

View File

@@ -53,7 +53,9 @@ class TestAodhOperatorCharm(test_utils.CharmTestCase):
# clean up events that were dynamically defined, # clean up events that were dynamically defined,
# otherwise we get issues because they'll be redefined, # otherwise we get issues because they'll be redefined,
# which is not allowed. # 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 ( for attr in (
"database_database_created", "database_database_created",
@@ -78,16 +80,9 @@ class TestAodhOperatorCharm(test_utils.CharmTestCase):
def test_all_relations(self): def test_all_relations(self):
"""Test all the charms relations.""" """Test all the charms relations."""
self.harness.begin_with_initial_hooks() 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() self.harness.set_leader()
test_utils.set_all_pebbles_ready(self.harness) test_utils.set_all_pebbles_ready(self.harness)
test_utils.add_api_relations(self.harness)
app_setup_cmds = [ app_setup_cmds = [
["a2ensite", "wsgi-aodh-api"], ["a2ensite", "wsgi-aodh-api"],
@@ -97,5 +92,11 @@ class TestAodhOperatorCharm(test_utils.CharmTestCase):
for cmd in app_setup_cmds: for cmd in app_setup_cmds:
self.assertIn(cmd, self.container_calls.execute["aodh-api"]) 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") self.check_file(c, "/etc/aodh/aodh.conf")