Ensure atomic inventory file rename runs on the same mountpoint

Linux rename system call is only supported on the same mountpoint [1].
/tmp is often a tmpfs mount, so instead generate the temp inventory file in
the same directory as the target inventory file.

[1] See EXDEV in https://man7.org/linux/man-pages/man2/rename.2.html

Change-Id: Id306243352f310f9054506577aa9bbce3790a7e5
Closes-bug: #1892008
This commit is contained in:
Oliver Walsh 2020-08-18 14:31:18 +01:00
parent cd427883bb
commit fbd575cbe8
2 changed files with 10 additions and 2 deletions

View File

@ -129,7 +129,11 @@ class TripleoInventories(object):
inventory[var]['vars'].update(value)
# Atomic update as concurrent tripleoclient commands can call this
with tempfile.NamedTemporaryFile('w', delete=False) as inventory_file:
inventory_file_dir = os.path.dirname(inventory_file_path)
with tempfile.NamedTemporaryFile(
'w',
dir=inventory_file_dir,
delete=False) as inventory_file:
yaml.dump(inventory, inventory_file, TemplateDumper)
os.rename(inventory_file.name, inventory_file_path)

View File

@ -379,7 +379,11 @@ class TripleoInventory(object):
inventory[var]['vars'].update(value)
# Atomic update as concurrent tripleoclient commands can call this
with tempfile.NamedTemporaryFile('w', delete=False) as inventory_file:
inventory_file_dir = os.path.dirname(inventory_file_path)
with tempfile.NamedTemporaryFile(
'w',
dir=inventory_file_dir,
delete=False) as inventory_file:
yaml.dump(inventory, inventory_file, TemplateDumper)
os.rename(inventory_file.name, inventory_file_path)