Avoid unnecessary rewrites of ceph.conf

Charm should avoid writing ceph.conf unless it absolutely needs
to since this can clash with other processes that might be
reading the file (such as ceph-disk called by udev).

Change-Id: I3790b5b16fa1473f1c3271b795b3d32c5e8d2fad
Closes-Bug: #1783113
This commit is contained in:
Edward Hope-Morley 2018-07-23 12:46:07 +01:00
parent 63f9ac2c7c
commit 42c9b7a625
2 changed files with 24 additions and 3 deletions

View File

@ -394,9 +394,9 @@ def emit_cephconf(upgrading=False):
charm_ceph_conf = "/var/lib/charm/{}/ceph.conf".format(service_name())
mkdir(os.path.dirname(charm_ceph_conf), owner=ceph.ceph_user(),
group=ceph.ceph_user())
with open(charm_ceph_conf, 'w') as cephconf:
context = get_ceph_context(upgrading)
cephconf.write(render_template('ceph.conf', context))
context = get_ceph_context(upgrading)
write_file(charm_ceph_conf, render_template('ceph.conf', context),
ceph.ceph_user(), ceph.ceph_user(), 0o644)
install_alternative('ceph.conf', '/etc/ceph/ceph.conf',
charm_ceph_conf, 90)

View File

@ -522,6 +522,27 @@ class CephHooksTestCase(unittest.TestCase):
config = {'osd-devices': '/srv/osd', 'osd-format': 'ext4'}
self.assertTrue(ceph_hooks.use_short_objects())
@patch.object(ceph_hooks, 'write_file')
@patch.object(ceph_hooks.ceph, 'ceph_user')
@patch.object(ceph_hooks, 'install_alternative')
@patch.object(ceph_hooks, 'render_template')
@patch.object(ceph_hooks, 'get_ceph_context')
@patch.object(ceph_hooks, 'service_name')
@patch.object(ceph_hooks, 'mkdir')
def test_emit_ceph_conf(self, mock_mkdir, mock_service_name,
mock_get_ceph_context, mock_render_template,
mock_install_alternative, mock_ceph_user,
mock_write_file):
mock_service_name.return_value = 'testsvc'
mock_ceph_user.return_value = 'ceph'
mock_get_ceph_context.return_value = {}
mock_render_template.return_value = "awesome ceph config"
ceph_hooks.emit_cephconf()
self.assertTrue(mock_write_file.called)
self.assertTrue(mock_install_alternative.called)
@patch.object(ceph_hooks, 'relation_get')
@patch.object(ceph_hooks, 'relation_set')