Fix race condition with the object-store relation

The `CONFIGS.write(GLANCE_SWIFT_CONF)` is missing in the object-store
hook. This config file is used when the `swift` backend is enabled.

This bug is only encountered on some deployments, because there are multiple
places where `CONFIGS.write_all()` is called.

If the `object-store` relation is established, and another hook calls
`CONFIGS.write_all()`, this problem wouldn't reproduce. However, if
`object-store` relation is executed last, this issue will pop up.

Closes-Bug: #1915300
Change-Id: Ie52b18fc4dc637dbeec5ecfb8d5930a24c5f72cf
This commit is contained in:
Ionut Balutoiu 2021-02-10 16:54:15 +00:00 committed by Billy Olsen
parent 22f2ff3fcf
commit 7a69693752
2 changed files with 9 additions and 2 deletions

View File

@ -46,6 +46,7 @@ from glance_utils import (
CHARM,
GLANCE_REGISTRY_CONF,
GLANCE_API_CONF,
GLANCE_SWIFT_CONF,
HAPROXY_CONF,
ceph_config_file,
setup_ipv6,
@ -294,6 +295,9 @@ def object_store_joined():
[image_service_joined(rid) for rid in relation_ids('image-service')]
update_image_location_policy(CONFIGS)
CONFIGS.write(GLANCE_API_CONF)
cmp_release = CompareOpenStackReleases(os_release('glance-common'))
if cmp_release >= 'mitaka':
CONFIGS.write(GLANCE_SWIFT_CONF)
@hooks.hook('ceph-relation-joined')

View File

@ -294,9 +294,12 @@ class GlanceRelationTests(CharmTestCase):
configs.complete_contexts.return_value = ['identity-service',
'object-store']
configs.write = MagicMock()
self.os_release.return_value = 'victoria'
relations.object_store_joined()
self.assertEqual([call('/etc/glance/glance-api.conf')],
configs.write.call_args_list)
configs.write.assert_has_calls([
call('/etc/glance/glance-api.conf'),
call('/etc/glance/glance-swift.conf'),
])
self.assertTrue(mock_update_image_location_policy.called)
@patch.object(relations, 'update_image_location_policy')