devserver: DevServerUtil suffix renamed
To retain consistency with a recent cleanup CL, in which devserver_util
was renamed common_util, we change class names starting with
DevServerUtil into CommonUtil.
BUG=None
TEST=Unit tests; devserver starts and serves content
Change-Id: I7bbc1d88d2e11d5c0def970c2a4226b1efe1bb59
Reviewed-on: https://gerrit.chromium.org/gerrit/34427
Reviewed-by: Scott Zawalski <scottz@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/common_util.py b/common_util.py
index 29a9563..e740d63 100644
--- a/common_util.py
+++ b/common_util.py
@@ -49,7 +49,7 @@
else:
return ''
-class DevServerUtilError(Exception):
+class CommonUtilError(Exception):
"""Exception classes used by this module."""
pass
@@ -65,7 +65,7 @@
Tuple of 3 payloads URLs: (full, nton, mton).
Raises:
- DevServerUtilError: If payloads missing or invalid.
+ CommonUtilError: If payloads missing or invalid.
"""
full_payload_url = None
mton_payload_url = None
@@ -82,7 +82,7 @@
mton_payload_url = '/'.join([archive_url, payload])
if not full_payload_url:
- raise DevServerUtilError(
+ raise CommonUtilError(
'Full payload is missing or has unexpected name format.', payload_list)
return full_payload_url, nton_payload_url, mton_payload_url
@@ -143,7 +143,7 @@
The list of artifacts in the Google Storage bucket.
Raises:
- DevServerUtilError: If timeout occurs.
+ CommonUtilError: If timeout occurs.
"""
cmd = 'gsutil cat %s/%s' % (archive_url, UPLOADED_LIST)
@@ -171,7 +171,7 @@
_Log('Retrying in %f seconds...%s' % (to_delay, err_str))
time.sleep(to_delay)
- raise DevServerUtilError('Missing %s for %s.' % (err_str, archive_url))
+ raise CommonUtilError('Missing %s for %s.' % (err_str, archive_url))
def GatherArtifactDownloads(main_staging_dir, archive_url, build_dir, build,
@@ -353,11 +353,11 @@
Path to the created directory or None if creation failed.
Raises:
- DevServerUtilError: If lock can't be acquired.
+ CommonUtilError: If lock can't be acquired.
"""
build_dir = os.path.join(static_dir, tag)
if not SafeSandboxAccess(static_dir, build_dir):
- raise DevServerUtilError('Invalid tag "%s".' % tag)
+ raise CommonUtilError('Invalid tag "%s".' % tag)
# Create the directory.
is_created = False
@@ -367,7 +367,7 @@
except OSError, e:
if e.errno == errno.EEXIST:
if create_once:
- raise DevServerUtilError(str(e))
+ raise CommonUtilError(str(e))
else:
raise
@@ -376,7 +376,7 @@
lock = lockfile.FileLock(os.path.join(build_dir, DEVSERVER_LOCK_FILE))
lock.acquire(timeout=0)
except lockfile.AlreadyLocked, e:
- raise DevServerUtilError(str(e))
+ raise CommonUtilError(str(e))
except:
# In any other case, remove the directory if we actually created it, so
# that subsequent attempts won't fail to re-create it.
@@ -399,11 +399,11 @@
entirely.
Raises:
- DevServerUtilError: If lock can't be released.
+ CommonUtilError: If lock can't be released.
"""
build_dir = os.path.join(static_dir, tag)
if not SafeSandboxAccess(static_dir, build_dir):
- raise DevServerUtilError('Invaid tag "%s".' % tag)
+ raise CommonUtilError('Invaid tag "%s".' % tag)
lock = lockfile.FileLock(os.path.join(build_dir, DEVSERVER_LOCK_FILE))
try:
@@ -411,7 +411,7 @@
if destroy:
shutil.rmtree(build_dir)
except Exception, e:
- raise DevServerUtilError(str(e))
+ raise CommonUtilError(str(e))
def FindMatchingBoards(static_dir, board):
@@ -461,13 +461,13 @@
If no latest is found for some reason or another a '' string is returned.
Raises:
- DevServerUtilError: If for some reason the latest build cannot be
+ CommonUtilError: If for some reason the latest build cannot be
deteremined, this could be due to the dir not existing or no builds
being present after filtering on milestone.
"""
target_path = os.path.join(static_dir, target)
if not os.path.isdir(target_path):
- raise DevServerUtilError('Cannot find path %s' % target_path)
+ raise CommonUtilError('Cannot find path %s' % target_path)
builds = [distutils.version.LooseVersion(build) for build in
os.listdir(target_path)]
@@ -477,7 +477,7 @@
builds = filter(lambda x: milestone.upper() in str(x), builds)
if not builds:
- raise DevServerUtilError('Could not determine build for %s' % target)
+ raise CommonUtilError('Could not determine build for %s' % target)
return str(max(builds))
@@ -505,7 +505,7 @@
dev_build_exists = False
try:
AcquireLock(dev_static_dir, tag)
- except DevServerUtilError:
+ except CommonUtilError:
dev_build_exists = True
if force:
dev_build_exists = False
@@ -532,7 +532,7 @@
control_path: Path to control file on Dev Server relative to Autotest root.
Raises:
- DevServerUtilError: If lock can't be acquired.
+ CommonUtilError: If lock can't be acquired.
Returns:
Content of the requested control file.
@@ -542,7 +542,7 @@
control_path = os.path.join(static_dir, build, 'autotest',
control_path)
if not SafeSandboxAccess(static_dir, control_path):
- raise DevServerUtilError('Invaid control file "%s".' % control_path)
+ raise CommonUtilError('Invaid control file "%s".' % control_path)
if not os.path.exists(control_path):
# TODO(scottz): Come up with some sort of error mechanism.
@@ -561,14 +561,14 @@
build: Fully qualified build string; e.g. R17-1234.0.0-a1-b983.
Raises:
- DevServerUtilError: If path is outside of sandbox.
+ CommonUtilError: If path is outside of sandbox.
Returns:
String of each file separated by a newline.
"""
autotest_dir = os.path.join(static_dir, build, 'autotest/')
if not SafeSandboxAccess(static_dir, autotest_dir):
- raise DevServerUtilError('Autotest dir not in sandbox "%s".' % autotest_dir)
+ raise CommonUtilError('Autotest dir not in sandbox "%s".' % autotest_dir)
control_files = set()
if not os.path.exists(autotest_dir):
diff --git a/common_util_unittest.py b/common_util_unittest.py
index fb0774d..8ba8fbd 100755
--- a/common_util_unittest.py
+++ b/common_util_unittest.py
@@ -27,7 +27,7 @@
}
-class DevServerUtilTest(mox.MoxTestBase):
+class CommonUtilTest(mox.MoxTestBase):
def setUp(self):
mox.MoxTestBase.setUp(self)
@@ -189,7 +189,7 @@
# Attempt to freshly create and lock an existing directory.
common_util.AcquireLock(self._static_dir, 'test-lock')
common_util.ReleaseLock(self._static_dir, 'test-lock')
- self.assertRaises(common_util.DevServerUtilError, common_util.AcquireLock,
+ self.assertRaises(common_util.CommonUtilError, common_util.AcquireLock,
self._static_dir, 'test-lock')
common_util.AcquireLock(self._static_dir, 'test-lock', create_once=False)
common_util.ReleaseLock(self._static_dir, 'test-lock', destroy=True)
@@ -202,7 +202,7 @@
# Attempt to lock an already locked directory.
common_util.AcquireLock(self._static_dir, 'test-lock')
- self.assertRaises(common_util.DevServerUtilError, common_util.AcquireLock,
+ self.assertRaises(common_util.CommonUtilError, common_util.AcquireLock,
self._static_dir, 'test-lock')
common_util.ReleaseLock(self._static_dir, 'test-lock', destroy=True)
@@ -242,14 +242,14 @@
'R17-1413.0.0-a1-b1346')
def testGetLatestBuildVersionLatest(self):
- """Test that we raise DevServerUtilError when a build dir is empty."""
- self.assertRaises(common_util.DevServerUtilError,
+ """Test that we raise CommonUtilError when a build dir is empty."""
+ self.assertRaises(common_util.CommonUtilError,
common_util.GetLatestBuildVersion,
self._static_dir, 'test-board-3')
def testGetLatestBuildVersionUnknownBuild(self):
- """Test that we raise DevServerUtilError when a build dir does not exist."""
- self.assertRaises(common_util.DevServerUtilError,
+ """Test that we raise CommonUtilError when a build dir does not exist."""
+ self.assertRaises(common_util.CommonUtilError,
common_util.GetLatestBuildVersion,
self._static_dir, 'bad-dir')
@@ -534,7 +534,7 @@
common_util.IsAvailable(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False)
self.mox.ReplayAll()
- self.assertRaises(common_util.DevServerUtilError,
+ self.assertRaises(common_util.CommonUtilError,
common_util.WaitUntilAvailable,
to_wait_list,
archive_url,
diff --git a/devserver.py b/devserver.py
index 7a45959..95bcfb6 100755
--- a/devserver.py
+++ b/devserver.py
@@ -396,7 +396,7 @@
return common_util.GetLatestBuildVersion(
updater.static_dir, params['target'],
milestone=params.get('milestone'))
- except common_util.DevServerUtilError as errmsg:
+ except common_util.CommonUtilError as errmsg:
raise cherrypy.HTTPError('500 Internal Server Error', str(errmsg))
@cherrypy.expose