Ensure tripleo ansible inventory file update is atomic
Multiple python-tripleoclient commands can run concurrently and all attempt to update the same inventory file in ~/tripleo-ansible-inventory.yaml. Make the update atomic to ensure the inventory file is always complete/valid. Change-Id: I28628100e1300e789114af420bf3ea0dfe9c0d70
This commit is contained in:
parent
f34782381c
commit
8e082f45dd
|
@ -16,7 +16,8 @@
|
|||
# under the License.
|
||||
|
||||
from collections import OrderedDict
|
||||
import os.path
|
||||
import os
|
||||
import tempfile
|
||||
import yaml
|
||||
|
||||
|
||||
|
@ -127,8 +128,10 @@ class TripleoInventories(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
|
||||
with tempfile.NamedTemporaryFile('w', delete=False) as inventory_file:
|
||||
yaml.dump(inventory, inventory_file, TemplateDumper)
|
||||
os.rename(inventory_file.name, inventory_file_path)
|
||||
|
||||
def host(self):
|
||||
# Dynamic inventory scripts must return empty json if they don't
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import os.path
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import yaml
|
||||
|
@ -378,8 +378,10 @@ 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
|
||||
with tempfile.NamedTemporaryFile('w', delete=False) as inventory_file:
|
||||
yaml.dump(inventory, inventory_file, TemplateDumper)
|
||||
os.rename(inventory_file.name, inventory_file_path)
|
||||
|
||||
|
||||
def generate_tripleo_ansible_inventory(heat, auth_url,
|
||||
|
|
Loading…
Reference in New Issue