Commit 4cd71845 authored by Matthieu Lamalle's avatar Matthieu Lamalle

Merge branch 'temp_file' into 'develop'

write file has tmp file in salt before rename it to destfile

See merge request !14
parents 00516d7b a42a8b02
Pipeline #769 passed with stage
in 0 seconds
......@@ -5,7 +5,8 @@ import asyncio
import signal
import time
import json, yaml
from os import path, makedirs, getpid, unlink, remove, walk, path, stat
from os import path, makedirs, getpid, remove, walk, path, stat, rename
from os.path import isfile
from shutil import rmtree
import tarfile
import base64
......@@ -112,11 +113,14 @@ class SaltRunner(ZephirCommonController):
configuration=True)
pillar_file_path = '/srv/pillar/pillars_{0}.sls'.format(server_id)
with open(pillar_file_path, 'w') as fh:
with open(pillar_file_path + '.tmp', 'w') as fh:
if json.loads(server['configuration']):
yaml.dump(json.loads(server['configuration']), fh, allow_unicode=True)
else:
yaml.dump({}, fh)
if isfile(pillar_file_path):
remove(pillar_file_path)
rename(pillar_file_path + '.tmp', pillar_file_path)
self.pillar_clear_cache(str(server_id))
......@@ -193,8 +197,7 @@ class SaltRunner(ZephirCommonController):
rmtree(minion_dir)
makedirs(minion_dir)
with open(creolefuncs_file_path, 'w') as fh:
fh.write(servermodel['creolefuncs'])
self._write_file(creolefuncs_file_path, servermodel['creolefuncs'])
eoleconfig = {"eole":{"configuration": { "files":{}}}}
......@@ -214,8 +217,7 @@ class SaltRunner(ZephirCommonController):
eoleconfig['eole']['configuration']['files'][pathtofile]['group'] = 'root'
eoleconfig['eole']['configuration']['files'][pathtofile]['mode'] = mode
# if json.loads(server['configuration']):
with open(pillar_file_path, 'w') as fh:
fh.write(yaml.dump(eoleconfig, default_flow_style=False))
self._write_file(pillar_file_path, yaml.dump(eoleconfig, default_flow_style=False))
self._download_env(server_id, servermodel)
def _download_env(self, server_id, servermodel):
......@@ -223,9 +225,14 @@ class SaltRunner(ZephirCommonController):
makedirs(minion_dir, exist_ok=True)
env_file_path = '{0}/config.env'.format(minion_dir)
with open(env_file_path, 'w') as fh:
fh.write(servermodel['probes'])
self._write_file(env_file_path, servermodel['probes'])
def _write_file(self, filename, content):
with open(filename + '.tmp', 'w') as fh:
fh.write(content)
if isfile(filename):
remove(filename)
rename(filename + '.tmp', filename)
async def download_env(self,server_id):
server = await self.call('v1.server.describe',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment