Revert "Allow using lockfile per jenkins master"

This reverts commit d1df3359b3.

The lockfile management code attempts to do IO on a closed file and
throws errors.

Change-Id: Ied58185758fd7c8c822624e169216441341a75d0
This commit is contained in:
Clark Boylan 2016-03-16 10:25:39 -07:00
parent 5c7e306349
commit 5407302fdc
2 changed files with 1 additions and 29 deletions

View File

@ -16,7 +16,6 @@
# Manage jobs in Jenkins server
import errno
import fcntl
import hashlib
import io
import logging
@ -48,7 +47,6 @@ class CacheStorage(object):
# removed global module references during teardown.
_yaml = yaml
_logger = logger
_fcntl = fcntl
def __init__(self, jenkins_url, flush=False):
cache_dir = self.get_cache_dir()
@ -56,11 +54,6 @@ class CacheStorage(object):
host_vary = re.sub('[^A-Za-z0-9\-\~]', '_', jenkins_url)
self.cachefilename = os.path.join(
cache_dir, 'cache-host-jobs-' + host_vary + '.yml')
# generate named lockfile if not exists, and lock it
while not self._lock(cache_dir, host_vary):
time.sleep(1)
if flush or not os.path.isfile(self.cachefilename):
self.data = {}
else:
@ -68,25 +61,6 @@ class CacheStorage(object):
self.data = yaml.load(yfile)
logger.debug("Using cache: '{0}'".format(self.cachefilename))
def _lock(self, cache_dir, jenkins_master):
path = os.path.join(cache_dir, "lock-jjb.%s" % jenkins_master)
self.lockfile = open(path, 'w')
try:
self._fcntl.lockf(self.lockfile,
self._fcntl.LOCK_EX | self._fcntl.LOCK_NB)
except IOError:
return False
return True
def _unlock(self):
if getattr(self, 'lockfile', None) is not None:
try:
self._fcntl.lockf(self.lockfile, self._fcntl.LOCK_UN)
self.lockfile.close()
except IOError:
pass
@staticmethod
def get_cache_dir():
home = os.path.expanduser('~')
@ -137,7 +111,6 @@ class CacheStorage(object):
self._logger.info("Cache saved")
self._logger.debug("Cache written out to '%s'" %
self.cachefilename)
self._unlock()
def __del__(self):
self.save()

View File

@ -32,8 +32,7 @@ class TestCaseCacheStorage(LoggingFixture, testtools.TestCase):
with mock.patch('jenkins_jobs.builder.CacheStorage.save') as save_mock:
with mock.patch('os.path.isfile', return_value=False):
with mock.patch('jenkins_jobs.builder.CacheStorage._lock'):
jenkins_jobs.builder.CacheStorage("dummy")
jenkins_jobs.builder.CacheStorage("dummy")
save_mock.assert_called_with()
@mock.patch('jenkins_jobs.builder.CacheStorage.get_cache_dir',