From 3d8525f459792f626a218b5ec2217e717b34d294 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 21 Mar 2017 19:28:24 +0000 Subject: [PATCH] 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 --- requirements.txt | 1 + snap_openstack/base.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/requirements.txt b/requirements.txt index 7045cb8..eb35569 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/snap_openstack/base.py b/snap_openstack/base.py index 8a488c5..ddbf8d6 100644 --- a/snap_openstack/base.py +++ b/snap_openstack/base.py @@ -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