Fix config-flags support

This change puts the specified key/value config-flags into
the [DEFAULT] section of the config file rather than the [api]
section, as they were supposed to be in the [DEFAULT] section.

Additionally, this change switches to using the config-flags
support from charms.openstack.

Closes-Bug: #1986943
Change-Id: I77a35c074e234c3bdfa78800b05ee770492e0694
This commit is contained in:
Corey Bryant 2022-10-12 13:10:11 +00:00
parent ad630b1c0f
commit e7fd6815c9
6 changed files with 10 additions and 22 deletions

4
bindep.txt Normal file
View File

@ -0,0 +1,4 @@
libffi-dev [platform:dpkg]
libpq-dev [platform:dpkg]
libxml2-dev [platform:dpkg]
libxslt1-dev [platform:dpkg]

View File

@ -7,7 +7,5 @@ options:
type: string
default:
description: |
Setting multiple arbitrary config variables and these
will be converted into dictionary and masakarimonitors.conf will be populated
accordingly. This will enable an operator to have the flexibility for having
multiple arbitrary config flags.
Comma-separated list of key=value config flags. These values will be
placed in the masakarimonitors.conf [DEFAULT] section.

View File

@ -59,9 +59,3 @@ class MasakariMonitorsCharm(charms_openstack.charm.OpenStackCharm):
def install(self):
super(MasakariMonitorsCharm, self).install()
# convert comma seprated list of config_flags into a dictionary
@charms_openstack.adapters.config_property
def user_config_flags(self):
return dict(map(lambda x: x.split('='),
self.config.get('config-flags').split(', ')))

View File

@ -4,6 +4,9 @@
[DEFAULT]
debug = {{ options.debug }}
host = {{ options.hostname }}
{% for key, value in options.user_config_flags.items() -%}
{{ key }} = {{ value }}
{% endfor -%}
[api]
{% if options.use_internal_endpoints == True -%}
api_interface = internal
@ -19,9 +22,6 @@ password = {{ identity_credentials.credentials_password }}
project_domain_id = {{ identity_credentials.credentials_project_domain_id }}
user_domain_id = {{ identity_credentials.credentials_user_domain_id }}
region = {{ options.region }}
{% for key, value in options.config_flags.items() -%}
{{ key }} = {{ value }}
{% endfor -%}
[callback]
[cors]
[healthcheck]

View File

@ -91,7 +91,7 @@ commands = stestr run --slowest {posargs}
[testenv:pep8]
basepython = python3
deps = flake8==3.9.2
charm-tools==2.8.3
git+https://github.com/juju/charm-tools.git
commands = flake8 {posargs} src unit_tests
[testenv:func-target]

View File

@ -51,11 +51,3 @@ class TestMasakariMonitorsCharm(Helper):
c.request_credentials()
keystone_relation.request_credentials.assert_called_once_with(
'masakari-monitors', project='services')
def test_user_config_flags(self):
charm = self.\
_patch_config_and_charm({'config-flags': 'k1=v1, k2=v2'})
config = charm.user_config_flags()
# Add check here that configuration is as expected.
self.assertEqual(config.get('k1'), "v1")
self.assertEqual(config.get('k2'), "v2")