Merge "Avoid unnecessary rewrites of ceph.conf"

This commit is contained in:
Zuul 2018-11-07 09:53:35 +00:00 committed by Gerrit Code Review
commit f2b1b942f7
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')