Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sweep:integration] Make writing the CS atomic #7947

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import _thread
import time
import datetime
import secrets

from diraccfg import CFG

Expand Down Expand Up @@ -342,11 +343,15 @@ def __backupCurrentConfiguration(self, backupName):

def writeRemoteConfigurationToDisk(self, backupName=False):
configurationFile = os.path.join(DIRAC.rootPath, "etc", f"{self.getName()}.cfg")
configurationFileTmp = f"{configurationFile}.{secrets.token_hex(8)}"
try:
with open(configurationFile, "w") as fd:
with open(configurationFileTmp, "w") as fd:
fd.write(str(self.remoteCFG))
os.rename(configurationFileTmp, configurationFile)
except Exception as e:
gLogger.fatal("Cannot write new configuration to disk!", f"file {configurationFile} exception {repr(e)}")
if os.path.isfile(configurationFileTmp):
os.remove(configurationFileTmp)
return S_ERROR(f"Can't write cs file {configurationFile}!: {repr(e).replace(',)', ')')}")
if backupName:
self.__backupCurrentConfiguration(backupName)
Expand Down
Loading