"""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)
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))
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
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)