Add locking to enable single process code execution

The code in OpenStackSnap.setup() creates users, files,
directories, symlinks, etc. Locking support is added to ensure
that setup() code is only executed by a single process at a time.

Change-Id: Ia7ea6251d68284f5ea6e726e474f65d393b296ea
This commit is contained in:
Corey Bryant 2017-03-21 19:28:24 +00:00
parent 144b820f53
commit 3d8525f459
2 changed files with 5 additions and 0 deletions

View File

@ -7,3 +7,4 @@ pbr>=1.6 # Apache-2.0
# Left unversioned as designed to align with OpenStack component being snapped
jinja2
jsonschema
oslo.concurrency

View File

@ -19,6 +19,8 @@ import os
import shutil
import yaml
from oslo_concurrency import lockutils
from snap_openstack.renderer import SnapFileRenderer
LOG = logging.getLogger(__name__)
@ -79,6 +81,8 @@ class OpenStackSnap(object):
self.configuration = yaml.load(config)
self.snap_env = snap_env()
@lockutils.synchronized('setup.lock', external=True,
lock_path="/var/lock/snap-openstack")
def setup(self):
'''Perform any pre-execution snap setup