Don't overwrite last relation key when username not found

When rotating a password, the code updates the password on the relation
bag for the associated relation. However, if the username wasn't found
in the relation data (e.g. if it was in app-data instead) then the code
unfortunately overwrote the last key it looked at (and this was,
randomly, private-address). This was due to a bug in the code. This
patch fixes that problem.

However, the charm (or at least certainly the rotating passwords code)
doesn't support app data bags as it doesn't find the matching username
to update the relation data. This means that it doesn't support rotating
passwords with charms that use app-data. This is the note added to the
README.

Change-Id: I05dac3ae89318ceb28724f4a75d1377a62d32d1c
Closes-Bug: #2051365
This commit is contained in:
Alex Kavanagh 2024-02-01 11:05:43 +00:00
parent f9e1f451bf
commit 26cb8350e8
2 changed files with 9 additions and 2 deletions

View File

@ -10,6 +10,10 @@ charms can be obtained from the [Charm Store][charms-requires-rabbitmq] (the
charms officially supported by the OpenStack Charms project are published by
'openstack-charmers').
NOTE: the charm doesn't officially support application data bags, and thus may
not work correctly with them. See [this bug][app-data-bag-bug] for more
details.
# Usage
## Configuration
@ -107,6 +111,8 @@ Actions allow specific operations to be performed on a per-unit basis.
* `list-unconsumed-queues`
* `pause`
* `resume`
* `list-service-usernames`
* `rotate-service-user-password`
To display action descriptions run `juju actions --schema rabbitmq-server`. If
the charm is not deployed then see file ``actions.yaml``.
@ -135,3 +141,4 @@ For general charm questions refer to the [OpenStack Charm Guide][cg].
[uca]: https://wiki.ubuntu.com/OpenStack/CloudArchive
[cdg-ha-rabbitmq]: https://docs.openstack.org/project-deploy-guide/charm-deployment-guide/latest/app-ha.html#rabbitmq
[juju-docs-config-apps]: https://juju.is/docs/configuring-applications
[app-data-bag-bug]: https://bugs.launchpad.net/charm-rabbitmq-server/+bug/2051930

View File

@ -363,8 +363,8 @@ def rotate_service_user_password(service_username):
if 'username' in current:
key = 'password'
break
for key in current.keys():
match = pattern.match(key)
for inner_key in current.keys():
match = pattern.match(inner_key)
if match:
key = '_'.join((match[1], 'password'))
break