From 70aaae222bffcff82c57266eef27205bf9d4aebe Mon Sep 17 00:00:00 2001 From: Dmitry Borodaenko Date: Tue, 1 Jul 2014 22:14:16 -0700 Subject: [PATCH] write_conf() overwrite logic fixed for python 2.6 Closes-Bug: #1333814 --- ceph_deploy/hosts/remotes.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ceph_deploy/hosts/remotes.py b/ceph_deploy/hosts/remotes.py index b11f7c6..e3d6650 100644 --- a/ceph_deploy/hosts/remotes.py +++ b/ceph_deploy/hosts/remotes.py @@ -5,6 +5,8 @@ import os import shutil import tempfile import platform +from ceph_deploy import conf +from StringIO import StringIO def platform_information(_linux_distribution=None): @@ -85,7 +87,7 @@ def set_repo_priority(sections, path='/etc/yum.repos.d/ceph.repo', priority='1') remove_whitespace_from_assignments() -def write_conf(cluster, conf, overwrite): +def write_conf(cluster, conf_data, overwrite): """ write cluster configuration to /etc/ceph/{cluster}.conf """ path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster) tmp_file = tempfile.NamedTemporaryFile(delete=False) @@ -93,17 +95,20 @@ def write_conf(cluster, conf, overwrite): if os.path.exists(path): with file(path, 'rb') as f: - old = f.read() - if old != conf and not overwrite: + old_conf = conf.ceph.parse(f) + old_data = StringIO() + old_conf.write(old_data) + if old_data != conf_data and not overwrite: raise RuntimeError(err_msg) - tmp_file.write(conf) - tmp_file.close() - shutil.move(tmp_file.name, path) - os.chmod(path, 0644) + if overwrite: + tmp_file.write(conf_data) + tmp_file.close() + shutil.move(tmp_file.name, path) + os.chmod(path, 0644) return if os.path.exists('/etc/ceph'): with open(path, 'w') as f: - f.write(conf) + f.write(conf_data) os.chmod(path, 0644) else: err_msg = '/etc/ceph/ does not exist - could not write config' -- 2.0.1