Cleanup based on pyflakes.
pyflakes itself can't be used in any automated gating way, because there are two sets of false errors it raises. However, as an exercise, cleaning up the 'valid' ones uncovered three actual bugs. The other changes (mostly unused variables) are included here for fun. Command run: pyflakes swift | grep -v "undefined name '_'" Change-Id: I18696bf047dedad1a9fdbde3463e214fba95f7c6
This commit is contained in:
parent
c9b24df5d6
commit
abe70e8323
swift
account
common
container
obj
proxy
test/unit/proxy
@ -112,7 +112,7 @@ class AccountAuditor(Daemon):
|
|||||||
return
|
return
|
||||||
broker = AccountBroker(path)
|
broker = AccountBroker(path)
|
||||||
if not broker.is_deleted():
|
if not broker.is_deleted():
|
||||||
info = broker.get_info()
|
broker.get_info()
|
||||||
self.logger.increment('passes')
|
self.logger.increment('passes')
|
||||||
self.account_passes += 1
|
self.account_passes += 1
|
||||||
self.logger.debug(_('Audit passed for %s') % broker.db_file)
|
self.logger.debug(_('Audit passed for %s') % broker.db_file)
|
||||||
|
@ -18,7 +18,6 @@ from __future__ import with_statement
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from urllib import unquote
|
|
||||||
from xml.sax import saxutils
|
from xml.sax import saxutils
|
||||||
|
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
@ -32,11 +32,7 @@ from swift.common.utils import config_true_value, LogAdapter
|
|||||||
import swiftclient as client
|
import swiftclient as client
|
||||||
from swift.common import direct_client
|
from swift.common import direct_client
|
||||||
from swift.common.http import HTTP_CONFLICT
|
from swift.common.http import HTTP_CONFLICT
|
||||||
|
from swift.common.utils import json
|
||||||
try:
|
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
def _func_on_containers(logger, conf, concurrency_key, func):
|
def _func_on_containers(logger, conf, concurrency_key, func):
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import urllib
|
import urllib
|
||||||
from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
|
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
||||||
RawConfigParser
|
|
||||||
|
|
||||||
from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \
|
from swift.common.swob import HTTPBadRequest, HTTPLengthRequired, \
|
||||||
HTTPRequestEntityTooLarge
|
HTTPRequestEntityTooLarge
|
||||||
|
@ -37,7 +37,7 @@ from swift.common.bufferedhttp import BufferedHTTPConnection
|
|||||||
from swift.common.exceptions import DriveNotMounted, ConnectionTimeout
|
from swift.common.exceptions import DriveNotMounted, ConnectionTimeout
|
||||||
from swift.common.daemon import Daemon
|
from swift.common.daemon import Daemon
|
||||||
from swift.common.swob import Response, HTTPNotFound, HTTPNoContent, \
|
from swift.common.swob import Response, HTTPNotFound, HTTPNoContent, \
|
||||||
HTTPAccepted, HTTPInsufficientStorage, HTTPBadRequest
|
HTTPAccepted, HTTPBadRequest
|
||||||
|
|
||||||
|
|
||||||
DEBUG_TIMINGS_THRESHOLD = 10
|
DEBUG_TIMINGS_THRESHOLD = 10
|
||||||
|
@ -27,10 +27,7 @@ import time
|
|||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
try:
|
from swift.common.utils import json
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
import json
|
|
||||||
|
|
||||||
DEFAULT_MEMCACHED_PORT = 11211
|
DEFAULT_MEMCACHED_PORT = 11211
|
||||||
|
|
||||||
|
@ -17,14 +17,10 @@ import errno
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from swift.common.swob import Request, Response
|
from swift.common.swob import Request, Response
|
||||||
from swift.common.utils import get_logger, config_true_value
|
from swift.common.utils import get_logger, config_true_value, json
|
||||||
from swift.common.constraints import check_mount
|
from swift.common.constraints import check_mount
|
||||||
from resource import getpagesize
|
from resource import getpagesize
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
try:
|
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class ReconMiddleware(object):
|
class ReconMiddleware(object):
|
||||||
|
@ -110,18 +110,13 @@ Example usage of this middleware via ``swift``:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
import json
|
|
||||||
|
|
||||||
import cgi
|
import cgi
|
||||||
import time
|
import time
|
||||||
from urllib import unquote, quote as urllib_quote
|
from urllib import unquote, quote as urllib_quote
|
||||||
|
|
||||||
|
|
||||||
from swift.common.utils import cache_from_env, get_logger, human_readable, \
|
from swift.common.utils import cache_from_env, get_logger, human_readable, \
|
||||||
split_path, config_true_value
|
split_path, config_true_value, json
|
||||||
from swift.common.wsgi import make_pre_authed_env, make_pre_authed_request, \
|
from swift.common.wsgi import make_pre_authed_env, make_pre_authed_request, \
|
||||||
WSGIContext
|
WSGIContext
|
||||||
from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND
|
from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND
|
||||||
|
@ -27,7 +27,7 @@ from swift.common.swob import HTTPBadRequest, HTTPForbidden, HTTPNotFound, \
|
|||||||
HTTPUnauthorized
|
HTTPUnauthorized
|
||||||
|
|
||||||
from swift.common.middleware.acl import clean_acl, parse_acl, referrer_allowed
|
from swift.common.middleware.acl import clean_acl, parse_acl, referrer_allowed
|
||||||
from swift.common.utils import cache_from_env, get_logger, get_remote_client, \
|
from swift.common.utils import cache_from_env, get_logger, \
|
||||||
split_path, config_true_value
|
split_path, config_true_value
|
||||||
from swift.common.http import HTTP_CLIENT_CLOSED_REQUEST
|
from swift.common.http import HTTP_CLIENT_CLOSED_REQUEST
|
||||||
|
|
||||||
|
@ -1,2 +1,8 @@
|
|||||||
from ring import RingData, Ring
|
from ring import RingData, Ring
|
||||||
from builder import RingBuilder
|
from builder import RingBuilder
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'RingData',
|
||||||
|
'Ring',
|
||||||
|
'RingBuilder',
|
||||||
|
]
|
||||||
|
@ -23,14 +23,9 @@ from time import time
|
|||||||
import os
|
import os
|
||||||
from io import BufferedReader
|
from io import BufferedReader
|
||||||
|
|
||||||
from swift.common.utils import hash_path, validate_configuration
|
from swift.common.utils import hash_path, validate_configuration, json
|
||||||
from swift.common.ring.utils import tiers_for_dev
|
from swift.common.ring.utils import tiers_for_dev
|
||||||
|
|
||||||
try:
|
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class RingData(object):
|
class RingData(object):
|
||||||
"""Partitioned consistent hashing ring data (used for serialization)."""
|
"""Partitioned consistent hashing ring data (used for serialization)."""
|
||||||
|
@ -26,7 +26,7 @@ from cStringIO import StringIO
|
|||||||
import UserDict
|
import UserDict
|
||||||
import time
|
import time
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from datetime import datetime, date, timedelta, tzinfo
|
from datetime import datetime, timedelta, tzinfo
|
||||||
from email.utils import parsedate
|
from email.utils import parsedate
|
||||||
import urlparse
|
import urlparse
|
||||||
import urllib2
|
import urllib2
|
||||||
@ -1067,19 +1067,20 @@ def wsgify(func):
|
|||||||
argspec = inspect.getargspec(func)
|
argspec = inspect.getargspec(func)
|
||||||
if argspec.args and argspec.args[0] == 'self':
|
if argspec.args and argspec.args[0] == 'self':
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def _wsgify(self, env, start_response):
|
def _wsgify_self(self, env, start_response):
|
||||||
try:
|
try:
|
||||||
return func(self, Request(env))(env, start_response)
|
return func(self, Request(env))(env, start_response)
|
||||||
except HTTPException, err_resp:
|
except HTTPException, err_resp:
|
||||||
return err_resp(env, start_response)
|
return err_resp(env, start_response)
|
||||||
|
return _wsgify_self
|
||||||
else:
|
else:
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def _wsgify(env, start_response):
|
def _wsgify_bare(env, start_response):
|
||||||
try:
|
try:
|
||||||
return func(Request(env))(env, start_response)
|
return func(Request(env))(env, start_response)
|
||||||
except HTTPException, err_resp:
|
except HTTPException, err_resp:
|
||||||
return err_resp(env, start_response)
|
return err_resp(env, start_response)
|
||||||
return _wsgify
|
return _wsgify_bare
|
||||||
|
|
||||||
|
|
||||||
class StatusMap(object):
|
class StatusMap(object):
|
||||||
|
@ -39,9 +39,7 @@ except ImportError:
|
|||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
import glob
|
import glob
|
||||||
from urlparse import urlparse as stdlib_urlparse, ParseResult
|
from urlparse import urlparse as stdlib_urlparse, ParseResult
|
||||||
import socket
|
|
||||||
import itertools
|
import itertools
|
||||||
import types
|
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import GreenPool, sleep, Timeout
|
from eventlet import GreenPool, sleep, Timeout
|
||||||
@ -286,7 +284,7 @@ def renamer(old, new):
|
|||||||
try:
|
try:
|
||||||
mkdirs(os.path.dirname(new))
|
mkdirs(os.path.dirname(new))
|
||||||
os.rename(old, new)
|
os.rename(old, new)
|
||||||
except OSError, err:
|
except OSError:
|
||||||
mkdirs(os.path.dirname(new))
|
mkdirs(os.path.dirname(new))
|
||||||
os.rename(old, new)
|
os.rename(old, new)
|
||||||
|
|
||||||
@ -1558,8 +1556,8 @@ def reiterate(iterable):
|
|||||||
try:
|
try:
|
||||||
chunk = ''
|
chunk = ''
|
||||||
while not chunk:
|
while not chunk:
|
||||||
chunk = next(iterable)
|
chunk = next(iterator)
|
||||||
return itertools.chain([chunk], iterable)
|
return itertools.chain([chunk], iterator)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ class ContainerAuditor(Daemon):
|
|||||||
return
|
return
|
||||||
broker = ContainerBroker(path)
|
broker = ContainerBroker(path)
|
||||||
if not broker.is_deleted():
|
if not broker.is_deleted():
|
||||||
info = broker.get_info()
|
broker.get_info()
|
||||||
self.logger.increment('passes')
|
self.logger.increment('passes')
|
||||||
self.container_passes += 1
|
self.container_passes += 1
|
||||||
self.logger.debug(_('Audit passed for %s'), broker.db_file)
|
self.logger.debug(_('Audit passed for %s'), broker.db_file)
|
||||||
|
@ -15,11 +15,9 @@
|
|||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
import itertools
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from urllib import unquote
|
|
||||||
from xml.sax import saxutils
|
from xml.sax import saxutils
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -566,7 +566,7 @@ class ObjectReplicator(Daemon):
|
|||||||
if not os.path.exists(obj_path):
|
if not os.path.exists(obj_path):
|
||||||
try:
|
try:
|
||||||
mkdirs(obj_path)
|
mkdirs(obj_path)
|
||||||
except Exception, err:
|
except Exception:
|
||||||
self.logger.exception('ERROR creating %s' % obj_path)
|
self.logger.exception('ERROR creating %s' % obj_path)
|
||||||
continue
|
continue
|
||||||
for partition in os.listdir(obj_path):
|
for partition in os.listdir(obj_path):
|
||||||
@ -589,7 +589,7 @@ class ObjectReplicator(Daemon):
|
|||||||
nodes=nodes,
|
nodes=nodes,
|
||||||
delete=len(nodes) > len(part_nodes) - 1,
|
delete=len(nodes) > len(part_nodes) - 1,
|
||||||
partition=partition))
|
partition=partition))
|
||||||
except ValueError, OSError:
|
except (ValueError, OSError):
|
||||||
continue
|
continue
|
||||||
random.shuffle(jobs)
|
random.shuffle(jobs)
|
||||||
self.job_count = len(jobs)
|
self.job_count = len(jobs)
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
import errno
|
import errno
|
||||||
import itertools
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@ -224,8 +223,8 @@ class DiskFile(object):
|
|||||||
def _handle_close_quarantine(self):
|
def _handle_close_quarantine(self):
|
||||||
"""Check if file needs to be quarantined"""
|
"""Check if file needs to be quarantined"""
|
||||||
try:
|
try:
|
||||||
obj_size = self.get_data_file_size()
|
self.get_data_file_size()
|
||||||
except DiskFileError, e:
|
except DiskFileError:
|
||||||
self.quarantine()
|
self.quarantine()
|
||||||
return
|
return
|
||||||
except DiskFileNotExist:
|
except DiskFileNotExist:
|
||||||
@ -505,8 +504,8 @@ class ObjectController(object):
|
|||||||
self.logger.error(_('ERROR Container update failed: different '
|
self.logger.error(_('ERROR Container update failed: different '
|
||||||
'numbers of hosts and devices in request: '
|
'numbers of hosts and devices in request: '
|
||||||
'"%s" vs "%s"' %
|
'"%s" vs "%s"' %
|
||||||
(req.headers.get('X-Container-Host', ''),
|
(headers_in.get('X-Container-Host', ''),
|
||||||
req.headers.get('X-Container-Device', ''))))
|
headers_in.get('X-Container-Device', ''))))
|
||||||
return
|
return
|
||||||
|
|
||||||
if contpartition:
|
if contpartition:
|
||||||
@ -590,7 +589,7 @@ class ObjectController(object):
|
|||||||
if file.is_deleted() or file.is_expired():
|
if file.is_deleted() or file.is_expired():
|
||||||
return HTTPNotFound(request=request)
|
return HTTPNotFound(request=request)
|
||||||
try:
|
try:
|
||||||
file_size = file.get_data_file_size()
|
file.get_data_file_size()
|
||||||
except (DiskFileError, DiskFileNotExist):
|
except (DiskFileError, DiskFileNotExist):
|
||||||
file.quarantine()
|
file.quarantine()
|
||||||
return HTTPNotFound(request=request)
|
return HTTPNotFound(request=request)
|
||||||
|
@ -2,3 +2,10 @@ from swift.proxy.controllers.base import Controller
|
|||||||
from swift.proxy.controllers.obj import ObjectController
|
from swift.proxy.controllers.obj import ObjectController
|
||||||
from swift.proxy.controllers.account import AccountController
|
from swift.proxy.controllers.account import AccountController
|
||||||
from swift.proxy.controllers.container import ContainerController
|
from swift.proxy.controllers.container import ContainerController
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'AccountController',
|
||||||
|
'ContainerController',
|
||||||
|
'Controller',
|
||||||
|
'ObjectController',
|
||||||
|
]
|
||||||
|
@ -28,7 +28,7 @@ import time
|
|||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from eventlet import spawn_n, GreenPile, Timeout
|
from eventlet import spawn_n, GreenPile
|
||||||
from eventlet.queue import Queue, Empty, Full
|
from eventlet.queue import Queue, Empty, Full
|
||||||
from eventlet.timeout import Timeout
|
from eventlet.timeout import Timeout
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ from swift.common.http import is_informational, is_success, is_redirection, \
|
|||||||
is_server_error, HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_MULTIPLE_CHOICES, \
|
is_server_error, HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_MULTIPLE_CHOICES, \
|
||||||
HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVICE_UNAVAILABLE, \
|
HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVICE_UNAVAILABLE, \
|
||||||
HTTP_INSUFFICIENT_STORAGE, HTTP_UNAUTHORIZED
|
HTTP_INSUFFICIENT_STORAGE, HTTP_UNAUTHORIZED
|
||||||
from swift.common.swob import Request, Response, status_map
|
from swift.common.swob import Request, Response
|
||||||
|
|
||||||
|
|
||||||
def update_headers(response, headers):
|
def update_headers(response, headers):
|
||||||
@ -330,7 +330,7 @@ class Controller(object):
|
|||||||
path, headers)
|
path, headers)
|
||||||
with Timeout(self.app.node_timeout):
|
with Timeout(self.app.node_timeout):
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
body = resp.read()
|
resp.read()
|
||||||
if is_success(resp.status):
|
if is_success(resp.status):
|
||||||
result_code = HTTP_OK
|
result_code = HTTP_OK
|
||||||
container_count = int(
|
container_count = int(
|
||||||
@ -421,7 +421,7 @@ class Controller(object):
|
|||||||
path, headers)
|
path, headers)
|
||||||
with Timeout(self.app.node_timeout):
|
with Timeout(self.app.node_timeout):
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
body = resp.read()
|
resp.read()
|
||||||
if is_success(resp.status):
|
if is_success(resp.status):
|
||||||
container_info.update(
|
container_info.update(
|
||||||
headers_to_container_info(resp.getheaders()))
|
headers_to_container_info(resp.getheaders()))
|
||||||
|
@ -33,7 +33,7 @@ from urllib import unquote, quote
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
|
|
||||||
from eventlet import sleep, GreenPile, Timeout
|
from eventlet import sleep, GreenPile
|
||||||
from eventlet.queue import Queue
|
from eventlet.queue import Queue
|
||||||
from eventlet.timeout import Timeout
|
from eventlet.timeout import Timeout
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
from ConfigParser import ConfigParser
|
from ConfigParser import ConfigParser
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -37,11 +36,10 @@ from swift.common.utils import cache_from_env, get_logger, \
|
|||||||
get_remote_client, split_path, config_true_value
|
get_remote_client, split_path, config_true_value
|
||||||
from swift.common.constraints import check_utf8
|
from swift.common.constraints import check_utf8
|
||||||
from swift.proxy.controllers import AccountController, ObjectController, \
|
from swift.proxy.controllers import AccountController, ObjectController, \
|
||||||
ContainerController, Controller
|
ContainerController
|
||||||
from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPForbidden, \
|
from swift.common.swob import HTTPBadRequest, HTTPForbidden, \
|
||||||
HTTPMethodNotAllowed, HTTPNotFound, HTTPPreconditionFailed, \
|
HTTPMethodNotAllowed, HTTPNotFound, HTTPPreconditionFailed, \
|
||||||
HTTPRequestEntityTooLarge, HTTPRequestTimeout, HTTPServerError, \
|
HTTPServerError, Request
|
||||||
HTTPServiceUnavailable, HTTPClientDisconnect, status_map, Request, Response
|
|
||||||
|
|
||||||
|
|
||||||
class Application(object):
|
class Application(object):
|
||||||
|
@ -28,7 +28,7 @@ from cStringIO import StringIO
|
|||||||
from gzip import GzipFile
|
from gzip import GzipFile
|
||||||
from httplib import HTTPException
|
from httplib import HTTPException
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from time import time
|
import time
|
||||||
from urllib import unquote, quote
|
from urllib import unquote, quote
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
@ -150,7 +150,7 @@ def setup():
|
|||||||
_test_coros = \
|
_test_coros = \
|
||||||
(prospa, acc1spa, acc2spa, con1spa, con2spa, obj1spa, obj2spa)
|
(prospa, acc1spa, acc2spa, con1spa, con2spa, obj1spa, obj2spa)
|
||||||
# Create account
|
# Create account
|
||||||
ts = normalize_timestamp(time())
|
ts = normalize_timestamp(time.time())
|
||||||
partition, nodes = prosrv.account_ring.get_nodes('a')
|
partition, nodes = prosrv.account_ring.get_nodes('a')
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
conn = swift.proxy.controllers.obj.http_connect(node['ip'],
|
conn = swift.proxy.controllers.obj.http_connect(node['ip'],
|
||||||
@ -390,11 +390,12 @@ class FakeMemcacheReturnsNone(FakeMemcache):
|
|||||||
def save_globals():
|
def save_globals():
|
||||||
orig_http_connect = getattr(swift.proxy.controllers.base, 'http_connect',
|
orig_http_connect = getattr(swift.proxy.controllers.base, 'http_connect',
|
||||||
None)
|
None)
|
||||||
orig_account_info = getattr(proxy_server.Controller, 'account_info', None)
|
orig_account_info = getattr(swift.proxy.controllers.Controller,
|
||||||
|
'account_info', None)
|
||||||
try:
|
try:
|
||||||
yield True
|
yield True
|
||||||
finally:
|
finally:
|
||||||
proxy_server.Controller.account_info = orig_account_info
|
swift.proxy.controllers.Controller.account_info = orig_account_info
|
||||||
swift.proxy.controllers.base.http_connect = orig_http_connect
|
swift.proxy.controllers.base.http_connect = orig_http_connect
|
||||||
swift.proxy.controllers.obj.http_connect = orig_http_connect
|
swift.proxy.controllers.obj.http_connect = orig_http_connect
|
||||||
swift.proxy.controllers.account.http_connect = orig_http_connect
|
swift.proxy.controllers.account.http_connect = orig_http_connect
|
||||||
@ -430,7 +431,7 @@ class TestController(unittest.TestCase):
|
|||||||
account_ring=self.account_ring,
|
account_ring=self.account_ring,
|
||||||
container_ring=self.container_ring,
|
container_ring=self.container_ring,
|
||||||
object_ring=FakeRing())
|
object_ring=FakeRing())
|
||||||
self.controller = proxy_server.Controller(app)
|
self.controller = swift.proxy.controllers.Controller(app)
|
||||||
|
|
||||||
self.account = 'some_account'
|
self.account = 'some_account'
|
||||||
self.container = 'some_container'
|
self.container = 'some_container'
|
||||||
@ -580,7 +581,7 @@ class TestController(unittest.TestCase):
|
|||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
with save_globals():
|
with save_globals():
|
||||||
proxy_server.Controller.account_info = account_info
|
swift.proxy.controllers.Controller.account_info = account_info
|
||||||
ret = self.controller.container_info(self.account,
|
ret = self.controller.container_info(self.account,
|
||||||
self.container)
|
self.container)
|
||||||
self.check_container_info_return(ret, True)
|
self.check_container_info_return(ret, True)
|
||||||
@ -593,7 +594,7 @@ class TestController(unittest.TestCase):
|
|||||||
with save_globals():
|
with save_globals():
|
||||||
headers = {'x-container-read': self.read_acl,
|
headers = {'x-container-read': self.read_acl,
|
||||||
'x-container-write': self.write_acl}
|
'x-container-write': self.write_acl}
|
||||||
proxy_server.Controller.account_info = account_info
|
swift.proxy.controllers.Controller.account_info = account_info
|
||||||
set_http_connect(200, headers=headers)
|
set_http_connect(200, headers=headers)
|
||||||
ret = self.controller.container_info(self.account,
|
ret = self.controller.container_info(self.account,
|
||||||
self.container)
|
self.container)
|
||||||
@ -616,7 +617,7 @@ class TestController(unittest.TestCase):
|
|||||||
return True, True, 0
|
return True, True, 0
|
||||||
|
|
||||||
with save_globals():
|
with save_globals():
|
||||||
proxy_server.Controller.account_info = account_info
|
swift.proxy.controllers.Controller.account_info = account_info
|
||||||
set_http_connect(404, 404, 404)
|
set_http_connect(404, 404, 404)
|
||||||
ret = self.controller.container_info(self.account,
|
ret = self.controller.container_info(self.account,
|
||||||
self.container)
|
self.container)
|
||||||
@ -1831,7 +1832,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
|
|
||||||
for dev in self.app.account_ring.devs.values():
|
for dev in self.app.account_ring.devs.values():
|
||||||
dev['errors'] = self.app.error_suppression_limit + 1
|
dev['errors'] = self.app.error_suppression_limit + 1
|
||||||
dev['last_error'] = time()
|
dev['last_error'] = time.time()
|
||||||
set_http_connect(200)
|
set_http_connect(200)
|
||||||
# acct [isn't actually called since everything
|
# acct [isn't actually called since everything
|
||||||
# is error limited]
|
# is error limited]
|
||||||
@ -1842,7 +1843,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
dev['errors'] = 0
|
dev['errors'] = 0
|
||||||
for dev in self.app.container_ring.devs.values():
|
for dev in self.app.container_ring.devs.values():
|
||||||
dev['errors'] = self.app.error_suppression_limit + 1
|
dev['errors'] = self.app.error_suppression_limit + 1
|
||||||
dev['last_error'] = time()
|
dev['last_error'] = time.time()
|
||||||
set_http_connect(200, 200)
|
set_http_connect(200, 200)
|
||||||
# acct cont [isn't actually called since
|
# acct cont [isn't actually called since
|
||||||
# everything is error limited]
|
# everything is error limited]
|
||||||
@ -3423,10 +3424,10 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'container', 'object')
|
'container', 'object')
|
||||||
set_http_connect(200, 200, 200, 200, 200, 202, 202, 202)
|
set_http_connect(200, 200, 200, 200, 200, 202, 202, 202)
|
||||||
self.app.memcache.store = {}
|
self.app.memcache.store = {}
|
||||||
orig_time = proxy_server.time.time
|
orig_time = time.time
|
||||||
try:
|
try:
|
||||||
t = time()
|
t = time.time()
|
||||||
proxy_server.time.time = lambda: t
|
time.time = lambda: t
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Type': 'foo/bar',
|
headers={'Content-Type': 'foo/bar',
|
||||||
'X-Delete-After': '60'})
|
'X-Delete-After': '60'})
|
||||||
@ -3451,7 +3452,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertEquals(req.headers.get('x-delete-at'),
|
self.assertEquals(req.headers.get('x-delete-at'),
|
||||||
str(int(t + 60)))
|
str(int(t + 60)))
|
||||||
finally:
|
finally:
|
||||||
proxy_server.time.time = orig_time
|
time.time = orig_time
|
||||||
|
|
||||||
def test_POST_non_int_delete_after(self):
|
def test_POST_non_int_delete_after(self):
|
||||||
with save_globals():
|
with save_globals():
|
||||||
@ -3495,7 +3496,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
controller.make_requests = fake_make_requests
|
controller.make_requests = fake_make_requests
|
||||||
set_http_connect(200, 200)
|
set_http_connect(200, 200)
|
||||||
self.app.memcache.store = {}
|
self.app.memcache.store = {}
|
||||||
t = str(int(time() + 100))
|
t = str(int(time.time() + 100))
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Type': 'foo/bar',
|
headers={'Content-Type': 'foo/bar',
|
||||||
'X-Delete-At': t})
|
'X-Delete-At': t})
|
||||||
@ -3506,7 +3507,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertTrue('X-Delete-At-Device' in given_headers)
|
self.assertTrue('X-Delete-At-Device' in given_headers)
|
||||||
self.assertTrue('X-Delete-At-Partition' in given_headers)
|
self.assertTrue('X-Delete-At-Partition' in given_headers)
|
||||||
|
|
||||||
t = str(int(time() + 100)) + '.1'
|
t = str(int(time.time() + 100)) + '.1'
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Type': 'foo/bar',
|
headers={'Content-Type': 'foo/bar',
|
||||||
'X-Delete-At': t})
|
'X-Delete-At': t})
|
||||||
@ -3515,7 +3516,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertEquals(resp.status_int, 400)
|
self.assertEquals(resp.status_int, 400)
|
||||||
self.assertTrue('Non-integer X-Delete-At' in resp.body)
|
self.assertTrue('Non-integer X-Delete-At' in resp.body)
|
||||||
|
|
||||||
t = str(int(time() - 100))
|
t = str(int(time.time() - 100))
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Type': 'foo/bar',
|
headers={'Content-Type': 'foo/bar',
|
||||||
'X-Delete-At': t})
|
'X-Delete-At': t})
|
||||||
@ -3530,10 +3531,10 @@ class TestObjectController(unittest.TestCase):
|
|||||||
'container', 'object')
|
'container', 'object')
|
||||||
set_http_connect(200, 200, 201, 201, 201)
|
set_http_connect(200, 200, 201, 201, 201)
|
||||||
self.app.memcache.store = {}
|
self.app.memcache.store = {}
|
||||||
orig_time = proxy_server.time.time
|
orig_time = time.time
|
||||||
try:
|
try:
|
||||||
t = time()
|
t = time.time()
|
||||||
proxy_server.time.time = lambda: t
|
time.time = lambda: t
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Length': '0',
|
headers={'Content-Length': '0',
|
||||||
'Content-Type': 'foo/bar',
|
'Content-Type': 'foo/bar',
|
||||||
@ -3544,7 +3545,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertEquals(req.headers.get('x-delete-at'),
|
self.assertEquals(req.headers.get('x-delete-at'),
|
||||||
str(int(t + 60)))
|
str(int(t + 60)))
|
||||||
finally:
|
finally:
|
||||||
proxy_server.time.time = orig_time
|
time.time = orig_time
|
||||||
|
|
||||||
def test_PUT_non_int_delete_after(self):
|
def test_PUT_non_int_delete_after(self):
|
||||||
with save_globals():
|
with save_globals():
|
||||||
@ -3589,7 +3590,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
controller._connect_put_node = fake_connect_put_node
|
controller._connect_put_node = fake_connect_put_node
|
||||||
set_http_connect(200, 200)
|
set_http_connect(200, 200)
|
||||||
self.app.memcache.store = {}
|
self.app.memcache.store = {}
|
||||||
t = str(int(time() + 100))
|
t = str(int(time.time() + 100))
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Length': '0',
|
headers={'Content-Length': '0',
|
||||||
'Content-Type': 'foo/bar',
|
'Content-Type': 'foo/bar',
|
||||||
@ -3601,7 +3602,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertTrue('X-Delete-At-Device' in given_headers)
|
self.assertTrue('X-Delete-At-Device' in given_headers)
|
||||||
self.assertTrue('X-Delete-At-Partition' in given_headers)
|
self.assertTrue('X-Delete-At-Partition' in given_headers)
|
||||||
|
|
||||||
t = str(int(time() + 100)) + '.1'
|
t = str(int(time.time() + 100)) + '.1'
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Length': '0',
|
headers={'Content-Length': '0',
|
||||||
'Content-Type': 'foo/bar',
|
'Content-Type': 'foo/bar',
|
||||||
@ -3611,7 +3612,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
self.assertEquals(resp.status_int, 400)
|
self.assertEquals(resp.status_int, 400)
|
||||||
self.assertTrue('Non-integer X-Delete-At' in resp.body)
|
self.assertTrue('Non-integer X-Delete-At' in resp.body)
|
||||||
|
|
||||||
t = str(int(time() - 100))
|
t = str(int(time.time() - 100))
|
||||||
req = Request.blank('/a/c/o', {},
|
req = Request.blank('/a/c/o', {},
|
||||||
headers={'Content-Length': '0',
|
headers={'Content-Length': '0',
|
||||||
'Content-Type': 'foo/bar',
|
'Content-Type': 'foo/bar',
|
||||||
@ -3977,7 +3978,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||||
headers={'Content-Type': 'application/stuff',
|
headers={'Content-Type': 'application/stuff',
|
||||||
'Content-Length': '0',
|
'Content-Length': '0',
|
||||||
'X-Delete-At': int(time()) + 100000})
|
'X-Delete-At': int(time.time()) + 100000})
|
||||||
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
|
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
|
||||||
seen_headers = self._gather_x_container_headers(
|
seen_headers = self._gather_x_container_headers(
|
||||||
controller.PUT, req,
|
controller.PUT, req,
|
||||||
@ -4005,7 +4006,7 @@ class TestObjectController(unittest.TestCase):
|
|||||||
req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
|
||||||
headers={'Content-Type': 'application/stuff',
|
headers={'Content-Type': 'application/stuff',
|
||||||
'Content-Length': 0,
|
'Content-Length': 0,
|
||||||
'X-Delete-At': int(time()) + 100000})
|
'X-Delete-At': int(time.time()) + 100000})
|
||||||
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
|
controller = proxy_server.ObjectController(self.app, 'a', 'c', 'o')
|
||||||
seen_headers = self._gather_x_container_headers(
|
seen_headers = self._gather_x_container_headers(
|
||||||
controller.PUT, req,
|
controller.PUT, req,
|
||||||
@ -4179,7 +4180,7 @@ class TestContainerController(unittest.TestCase):
|
|||||||
|
|
||||||
for dev in self.app.account_ring.devs.values():
|
for dev in self.app.account_ring.devs.values():
|
||||||
dev['errors'] = self.app.error_suppression_limit + 1
|
dev['errors'] = self.app.error_suppression_limit + 1
|
||||||
dev['last_error'] = time()
|
dev['last_error'] = time.time()
|
||||||
set_http_connect(200, 200, 200, 200, 200, 200)
|
set_http_connect(200, 200, 200, 200, 200, 200)
|
||||||
resp = getattr(controller, meth)(req)
|
resp = getattr(controller, meth)(req)
|
||||||
self.assertEquals(resp.status_int, 404)
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user