X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/d693c8647cc89694ba61bd48bb74f967fbe3bc5a..087ed2edee08da7bd3c4872cabde13c57585ca5a:/lib/config.py diff --git a/lib/config.py b/lib/config.py index edc76a6..91621b9 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1041,14 +1041,12 @@ class ConfigWriter: """Read the config data from disk. """ - f = open(self._cfg_file, 'r') + raw_data = utils.ReadFile(self._cfg_file) + try: - try: - data = objects.ConfigData.FromDict(serializer.Load(f.read())) - except Exception, err: - raise errors.ConfigurationError(err) - finally: - f.close() + data = objects.ConfigData.FromDict(serializer.Load(raw_data)) + except Exception, err: + raise errors.ConfigurationError(err) # Make sure the configuration has the right version _ValidateConfig(data) @@ -1092,7 +1090,7 @@ class ConfigWriter: result = rpc.RpcRunner.call_upload_file(node_list, self._cfg_file, address_list=addr_list) for to_node, to_result in result.items(): - msg = to_result.RemoteFailMsg() + msg = to_result.fail_msg if msg: msg = ("Copy of file %s to node %s failed: %s" % (self._cfg_file, to_node, msg)) @@ -1113,16 +1111,9 @@ class ConfigWriter: destination = self._cfg_file self._BumpSerialNo() txt = serializer.Dump(self._config_data.ToDict()) - dir_name, file_name = os.path.split(destination) - fd, name = tempfile.mkstemp('.newconfig', file_name, dir_name) - f = os.fdopen(fd, 'w') - try: - f.write(txt) - os.fsync(f.fileno()) - finally: - f.close() - # we don't need to do os.close(fd) as f.close() did it - os.rename(name, destination) + + utils.WriteFile(destination, data=txt) + self.write_count += 1 # and redistribute the config file to master candidates @@ -1135,7 +1126,7 @@ class ConfigWriter: self._UnlockedGetNodeList(), self._UnlockedGetSsconfValues()) for nname, nresu in result.items(): - msg = nresu.RemoteFailMsg() + msg = nresu.fail_msg if msg: logging.warning("Error while uploading ssconf files to" " node %s: %s", nname, msg)