Browse Source

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
(cherry picked from commit fbd575cbe8)
changes/42/746842/1
Oliver Walsh 1 month ago
committed by Chandan Kumar (raukadah)
parent
commit
662b0acd91
2 changed files with 10 additions and 2 deletions
  1. +5
    -1
      tripleo_common/inventories.py
  2. +5
    -1
      tripleo_common/inventory.py

+ 5
- 1
tripleo_common/inventories.py View File

@@ -139,7 +139,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)



+ 5
- 1
tripleo_common/inventory.py View File

@@ -385,6 +385,10 @@ 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)

Loading…
Cancel
Save