Browse Source

Merge "Ensure tripleo ansible inventory file update is atomic" into stable/rocky

stable/rocky
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
5bef2ca344
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      tripleo_common/inventory.py

+ 9
- 2
tripleo_common/inventory.py View File

@ -16,7 +16,8 @@
# under the License.
from collections import OrderedDict
import os.path
import os
import tempfile
import yaml
from heatclient.exc import HTTPNotFound
@ -309,5 +310,11 @@ class TripleoInventory(object):
if var in inventory:
inventory[var]['vars'].update(value)
with open(inventory_file_path, 'w') as inventory_file:
# Atomic update as concurrent tripleoclient commands can call this
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