Remove unused util functions
Change-Id: I3ed84b277f7bb7207d2c242d8040a30fb0f8a754
This commit is contained in:
@@ -19,16 +19,12 @@
|
||||
"""
|
||||
System-level utilities and helper functions.
|
||||
"""
|
||||
|
||||
import errno
|
||||
|
||||
try:
|
||||
from eventlet import sleep
|
||||
except ImportError:
|
||||
from time import sleep
|
||||
from eventlet.green import socket
|
||||
|
||||
import functools
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
@@ -42,7 +38,6 @@ from oslo_utils import excutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_versionedobjects import fields
|
||||
import six
|
||||
from webob import exc
|
||||
|
||||
from glare.common import exception
|
||||
from glare.i18n import _, _LE, _LW
|
||||
@@ -234,49 +229,6 @@ class LimitingReader(object):
|
||||
return res
|
||||
|
||||
|
||||
def safe_mkdirs(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
def mutating(func):
|
||||
"""Decorator to enforce read-only logic"""
|
||||
@functools.wraps(func)
|
||||
def wrapped(self, req, *args, **kwargs):
|
||||
if req.context.read_only:
|
||||
msg = "Read-only access"
|
||||
LOG.debug(msg)
|
||||
raise exc.HTTPForbidden(msg, request=req,
|
||||
content_type="text/plain")
|
||||
return func(self, req, *args, **kwargs)
|
||||
return wrapped
|
||||
|
||||
|
||||
def setup_remote_pydev_debug(host, port):
|
||||
error_msg = _LE('Error setting up the debug environment. Verify that the'
|
||||
' option pydev_worker_debug_host is pointing to a valid '
|
||||
'hostname or IP on which a pydev server is listening on'
|
||||
' the port indicated by pydev_worker_debug_port.')
|
||||
|
||||
try:
|
||||
try:
|
||||
from pydev import pydevd
|
||||
except ImportError:
|
||||
import pydevd
|
||||
|
||||
pydevd.settrace(host,
|
||||
port=port,
|
||||
stdoutToServer=True,
|
||||
stderrToServer=True)
|
||||
return True
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(error_msg)
|
||||
|
||||
|
||||
def validate_key_cert(key_file, cert_file):
|
||||
try:
|
||||
error_key_name = "private key"
|
||||
@@ -485,33 +437,6 @@ def split_filter_value_for_quotes(value):
|
||||
return [val[0] or val[1] for val in re.findall(tmp, value)]
|
||||
|
||||
|
||||
def evaluate_filter_op(value, operator, threshold):
|
||||
"""Evaluate a comparison operator.
|
||||
Designed for use on a comparative-filtering query field.
|
||||
|
||||
:param value: evaluated against the operator, as left side of expression
|
||||
:param operator: any supported filter operation
|
||||
:param threshold: to compare value against, as right side of expression
|
||||
:raises: InvalidFilterOperatorValue if an unknown operator is provided
|
||||
:return: boolean result of applied comparison
|
||||
"""
|
||||
if operator == 'gt':
|
||||
return value > threshold
|
||||
elif operator == 'gte':
|
||||
return value >= threshold
|
||||
elif operator == 'lt':
|
||||
return value < threshold
|
||||
elif operator == 'lte':
|
||||
return value <= threshold
|
||||
elif operator == 'neq':
|
||||
return value != threshold
|
||||
elif operator == 'eq':
|
||||
return value == threshold
|
||||
|
||||
msg = _("Unable to filter on a unknown operator.")
|
||||
raise exception.InvalidFilterOperatorValue(msg)
|
||||
|
||||
|
||||
class error_handler(object):
|
||||
def __init__(self, error_map, default_exception=None):
|
||||
"""Init method of the class.
|
||||
|
||||
@@ -107,7 +107,7 @@ class Server(object):
|
||||
paste_conf_filepath = conf_filepath.replace(".conf", "-paste.ini")
|
||||
if os.path.exists(paste_conf_filepath):
|
||||
os.unlink(paste_conf_filepath)
|
||||
utils.safe_mkdirs(conf_dir)
|
||||
test_utils.safe_mkdirs(conf_dir)
|
||||
|
||||
def override_conf(filepath, overridden):
|
||||
with open(filepath, 'w') as conf_file:
|
||||
@@ -199,7 +199,7 @@ class Server(object):
|
||||
"""Create database if required for this server"""
|
||||
if self.needs_database:
|
||||
conf_dir = os.path.join(self.test_dir, 'etc')
|
||||
utils.safe_mkdirs(conf_dir)
|
||||
test_utils.safe_mkdirs(conf_dir)
|
||||
conf_filepath = os.path.join(conf_dir, 'glare.conf')
|
||||
|
||||
glare_db_env = 'GLARE_DB_TEST_SQLITE_FILE'
|
||||
@@ -356,7 +356,7 @@ class FunctionalTest(test_utils.BaseTestCase):
|
||||
self.tracecmd = tracecmd_osmap.get(platform.system())
|
||||
|
||||
conf_dir = os.path.join(self.test_dir, 'etc')
|
||||
utils.safe_mkdirs(conf_dir)
|
||||
test_utils.safe_mkdirs(conf_dir)
|
||||
self.copy_data_file('policy.json', conf_dir)
|
||||
self.policy_file = os.path.join(conf_dir, 'policy.json')
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ from oslo_log import log
|
||||
import testtools
|
||||
|
||||
from glare.common import config
|
||||
from glare.common import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
try:
|
||||
@@ -61,7 +60,7 @@ class BaseTestCase(testtools.TestCase):
|
||||
self.addCleanup(CONF.reset)
|
||||
self.test_dir = self.useFixture(fixtures.TempDir()).path
|
||||
self.conf_dir = os.path.join(self.test_dir, 'etc')
|
||||
utils.safe_mkdirs(self.conf_dir)
|
||||
safe_mkdirs(self.conf_dir)
|
||||
self.set_policy()
|
||||
|
||||
def set_policy(self):
|
||||
@@ -367,3 +366,11 @@ def xattr_writes_supported(path):
|
||||
os.unlink(fake_filepath)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def safe_mkdirs(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user