¡@

Home 

OpenStack Study: lockutils.py

OpenStack Index

**** CubicPower OpenStack Study ****

# Copyright 2011 OpenStack Foundation.

# All Rights Reserved.

#

# Licensed under the Apache License, Version 2.0 (the "License"); you may

# not use this file except in compliance with the License. You may obtain

# a copy of the License at

#

# http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

# License for the specific language governing permissions and limitations

# under the License.

import fixtures

from keystone.openstack.common import lockutils

**** CubicPower OpenStack Study ****

class LockFixture(fixtures.Fixture):

"""External locking fixture.

This fixture is basically an alternative to the synchronized decorator with

the external flag so that tearDowns and addCleanups will be included in

the lock context for locking between tests. The fixture is recommended to

be the first line in a test method, like so::

**** CubicPower OpenStack Study ****

    def __init__(self, name, lock_file_prefix=None):

        self.mgr = lockutils.lock(name, lock_file_prefix, True)

**** CubicPower OpenStack Study ****

    def setUp(self):

        super(LockFixture, self).setUp()

        self.addCleanup(self.mgr.__exit__, None, None, None)

        self.mgr.__enter__()