Browse Source

Merge "Cleanup tests' import of debug_logger"

changes/02/774002/15
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
b709a1d4aa
57 changed files with 278 additions and 246 deletions
  1. +2
    -1
      test/functional/__init__.py
  2. +1
    -2
      test/unit/__init__.py
  3. +2
    -1
      test/unit/account/test_auditor.py
  4. +7
    -6
      test/unit/account/test_reaper.py
  5. +8
    -9
      test/unit/account/test_server.py
  6. +2
    -2
      test/unit/common/middleware/crypto/test_crypto_utils.py
  7. +3
    -3
      test/unit/common/middleware/crypto/test_decrypter.py
  8. +3
    -2
      test/unit/common/middleware/crypto/test_encrypter.py
  9. +3
    -2
      test/unit/common/middleware/crypto/test_encryption.py
  10. +3
    -2
      test/unit/common/middleware/helpers.py
  11. +1
    -1
      test/unit/common/middleware/s3api/__init__.py
  12. +1
    -1
      test/unit/common/middleware/s3api/test_s3api.py
  13. +2
    -2
      test/unit/common/middleware/s3api/test_s3request.py
  14. +1
    -1
      test/unit/common/middleware/test_bulk.py
  15. +3
    -3
      test/unit/common/middleware/test_container_sync.py
  16. +2
    -1
      test/unit/common/middleware/test_copy.py
  17. +9
    -9
      test/unit/common/middleware/test_keystoneauth.py
  18. +1
    -1
      test/unit/common/middleware/test_listing_formats.py
  19. +1
    -1
      test/unit/common/middleware/test_proxy_logging.py
  20. +3
    -3
      test/unit/common/middleware/test_ratelimit.py
  21. +12
    -12
      test/unit/common/middleware/test_read_only.py
  22. +2
    -2
      test/unit/common/middleware/test_subrequest_logging.py
  23. +11
    -10
      test/unit/common/test_container_sync_realms.py
  24. +1
    -1
      test/unit/common/test_daemon.py
  25. +1
    -1
      test/unit/common/test_db_auditor.py
  26. +33
    -35
      test/unit/common/test_db_replicator.py
  27. +2
    -1
      test/unit/common/test_direct_client.py
  28. +2
    -2
      test/unit/common/test_internal_client.py
  29. +1
    -1
      test/unit/common/test_memcached.py
  30. +5
    -4
      test/unit/common/test_storage_policy.py
  31. +32
    -28
      test/unit/common/test_utils.py
  32. +5
    -4
      test/unit/common/test_wsgi.py
  33. +2
    -1
      test/unit/container/test_auditor.py
  34. +6
    -5
      test/unit/container/test_backend.py
  35. +2
    -1
      test/unit/container/test_reconciler.py
  36. +5
    -5
      test/unit/container/test_replicator.py
  37. +2
    -1
      test/unit/container/test_server.py
  38. +3
    -3
      test/unit/container/test_sharder.py
  39. +1
    -1
      test/unit/container/test_sync.py
  40. +1
    -1
      test/unit/container/test_sync_store.py
  41. +2
    -1
      test/unit/container/test_updater.py
  42. +3
    -2
      test/unit/helpers.py
  43. +3
    -2
      test/unit/obj/test_auditor.py
  44. +3
    -3
      test/unit/obj/test_diskfile.py
  45. +2
    -2
      test/unit/obj/test_expirer.py
  46. +5
    -4
      test/unit/obj/test_reconstructor.py
  47. +3
    -2
      test/unit/obj/test_replicator.py
  48. +4
    -3
      test/unit/obj/test_server.py
  49. +3
    -2
      test/unit/obj/test_ssync.py
  50. +3
    -2
      test/unit/obj/test_ssync_receiver.py
  51. +2
    -2
      test/unit/obj/test_ssync_sender.py
  52. +4
    -4
      test/unit/obj/test_updater.py
  53. +2
    -1
      test/unit/proxy/controllers/test_base.py
  54. +2
    -1
      test/unit/proxy/controllers/test_container.py
  55. +6
    -5
      test/unit/proxy/controllers/test_obj.py
  56. +41
    -36
      test/unit/proxy/test_server.py
  57. +3
    -2
      test/unit/proxy/test_sysmeta.py

+ 2
- 1
test/functional/__init__.py View File

@ -44,7 +44,8 @@ from swift.common.utils import set_swift_dir
from test import get_config, listen_zero
from test.unit import debug_logger, FakeMemcache
from test.debug_logger import debug_logger
from test.unit import FakeMemcache
# importing skip_if_no_xattrs so that functional tests can grab it from the
# test.functional namespace. Importing SkipTest so this works under both
# nose and testr test runners.


+ 1
- 2
test/unit/__init__.py View File

@ -49,8 +49,7 @@ from swift.common.storage_policy import (StoragePolicy, ECStoragePolicy,
VALID_EC_TYPES)
from swift.common.utils import Timestamp, md5
from test import get_config
# import to namespace for backward compat
from test.debug_logger import debug_logger, DebugLogger, FakeLogger # noqa
from test.debug_logger import FakeLogger
from swift.common.header_key_dict import HeaderKeyDict
from swift.common.ring import Ring, RingData, RingBuilder
from swift.obj import server


+ 2
- 1
test/unit/account/test_auditor.py View File

@ -23,7 +23,8 @@ import random
from swift.account import auditor
from swift.common.storage_policy import POLICIES
from swift.common.utils import Timestamp
from test.unit import debug_logger, patch_policies, with_tempdir
from test.debug_logger import debug_logger
from test.unit import patch_policies, with_tempdir
from test.unit.account.test_backend import (
AccountBrokerPreTrackContainerCountSetup)


+ 7
- 6
test/unit/account/test_reaper.py View File

@ -29,6 +29,7 @@ from swift.common.exceptions import ClientException
from swift.common.utils import normalize_timestamp, Timestamp
from test import unit
from test.debug_logger import debug_logger
from swift.common.storage_policy import StoragePolicy, POLICIES
@ -208,7 +209,7 @@ class TestReaper(unittest.TestCase):
r = reaper.AccountReaper(conf)
r.myips = myips
if fakelogger:
r.logger = unit.debug_logger('test-reaper')
r.logger = debug_logger('test-reaper')
return r
def fake_reap_account(self, *args, **kwargs):
@ -302,7 +303,7 @@ class TestReaper(unittest.TestCase):
conf = {
'mount_check': 'false',
}
r = reaper.AccountReaper(conf, logger=unit.debug_logger())
r = reaper.AccountReaper(conf, logger=debug_logger())
mock_path = 'swift.account.reaper.direct_delete_object'
for policy in POLICIES:
r.reset_stats()
@ -566,7 +567,7 @@ class TestReaper(unittest.TestCase):
def test_reap_account(self):
containers = ('c1', 'c2', 'c3', 'c4')
broker = FakeAccountBroker(containers, unit.FakeLogger())
broker = FakeAccountBroker(containers, debug_logger())
self.called_amount = 0
self.r = r = self.init_reaper({}, fakelogger=True)
r.start_time = time.time()
@ -602,7 +603,7 @@ class TestReaper(unittest.TestCase):
self.assertEqual(len(self.r.account_ring.devs), 3)
def test_reap_account_no_container(self):
broker = FakeAccountBroker(tuple(), unit.FakeLogger())
broker = FakeAccountBroker(tuple(), debug_logger())
self.r = r = self.init_reaper({}, fakelogger=True)
self.called_amount = 0
r.start_time = time.time()
@ -739,7 +740,7 @@ class TestReaper(unittest.TestCase):
container_reaped[0] += 1
fake_ring = FakeRing()
fake_logger = unit.FakeLogger()
fake_logger = debug_logger()
with patch('swift.account.reaper.AccountBroker',
FakeAccountBroker), \
patch(
@ -804,7 +805,7 @@ class TestReaper(unittest.TestCase):
self.assertFalse(foo.called)
with patch('swift.account.reaper.AccountReaper.reap_device') as foo:
r.logger = unit.debug_logger('test-reaper')
r.logger = debug_logger('test-reaper')
r.devices = 'thisdeviceisbad'
r.run_once()
self.assertTrue(r.logger.get_lines_for_level(


+ 8
- 9
test/unit/account/test_server.py View File

@ -20,7 +20,6 @@ import posix
import unittest
from tempfile import mkdtemp
from shutil import rmtree
from test.unit import FakeLogger
import itertools
import random
from io import BytesIO
@ -38,8 +37,8 @@ from swift.account.server import AccountController
from swift.common.utils import (normalize_timestamp, replication, public,
mkdirs, storage_directory, Timestamp)
from swift.common.request_helpers import get_sys_meta_prefix, get_reserved_name
from test.unit import patch_policies, debug_logger, mock_check_drive, \
make_timestamp_iter
from test.debug_logger import debug_logger
from test.unit import patch_policies, mock_check_drive, make_timestamp_iter
from swift.common.storage_policy import StoragePolicy, POLICIES
@ -2626,7 +2625,7 @@ class TestAccountController(unittest.TestCase):
self.assertEqual(self.logger.get_lines_for_level('info'), [])
def test_GET_log_requests_true(self):
self.controller.logger = FakeLogger()
self.controller.logger = debug_logger()
self.controller.log_requests = True
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'GET'})
@ -2635,7 +2634,7 @@ class TestAccountController(unittest.TestCase):
self.assertTrue(self.controller.logger.log_dict['info'])
def test_GET_log_requests_false(self):
self.controller.logger = FakeLogger()
self.controller.logger = debug_logger()
self.controller.log_requests = False
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller)
@ -2646,7 +2645,7 @@ class TestAccountController(unittest.TestCase):
req = Request.blank(
'/sda1/p/a',
environ={'REQUEST_METHOD': 'HEAD', 'REMOTE_ADDR': '1.2.3.4'})
self.controller.logger = FakeLogger()
self.controller.logger = debug_logger()
with mock.patch(
'time.time',
mock.MagicMock(side_effect=[10000.0, 10001.0, 10002.0,
@ -2655,9 +2654,9 @@ class TestAccountController(unittest.TestCase):
'os.getpid', mock.MagicMock(return_value=1234)):
req.get_response(self.controller)
self.assertEqual(
self.controller.logger.log_dict['info'],
[(('1.2.3.4 - - [01/Jan/1970:02:46:42 +0000] "HEAD /sda1/p/a" 404 '
'- "-" "-" "-" 2.0000 "-" 1234 -',), {})])
self.controller.logger.get_lines_for_level('info'),
['1.2.3.4 - - [01/Jan/1970:02:46:42 +0000] "HEAD /sda1/p/a" 404 '
'- "-" "-" "-" 2.0000 "-" 1234 -'])
def test_policy_stats_with_legacy(self):
ts = itertools.count()


+ 2
- 2
test/unit/common/middleware/crypto/test_crypto_utils.py View File

@ -24,7 +24,7 @@ from swift.common.middleware.crypto import crypto_utils
from swift.common.middleware.crypto.crypto_utils import (
CRYPTO_KEY_CALLBACK, Crypto, CryptoWSGIContext)
from swift.common.swob import HTTPException
from test.unit import FakeLogger
from test.debug_logger import debug_logger
from test.unit.common.middleware.crypto.crypto_helpers import fetch_crypto_keys
@ -34,7 +34,7 @@ class TestCryptoWsgiContext(unittest.TestCase):
app = None
crypto = Crypto({})
self.fake_logger = FakeLogger()
self.fake_logger = debug_logger()
self.crypto_context = CryptoWSGIContext(
FakeFilter(), 'object', self.fake_logger)


+ 3
- 3
test/unit/common/middleware/crypto/test_decrypter.py View File

@ -28,7 +28,7 @@ from swift.common.middleware.crypto.crypto_utils import CRYPTO_KEY_CALLBACK, \
from swift.common.swob import Request, HTTPException, HTTPOk, \
HTTPPreconditionFailed, HTTPNotFound, HTTPPartialContent, bytes_to_wsgi
from test.unit import FakeLogger
from test.debug_logger import debug_logger
from test.unit.common.middleware.crypto.crypto_helpers import md5hex, \
fetch_crypto_keys, FAKE_IV, encrypt, fake_get_crypto_meta
from test.unit.common.middleware.helpers import FakeSwift, FakeAppThatExcepts
@ -52,7 +52,7 @@ class TestDecrypterObjectRequests(unittest.TestCase):
def setUp(self):
self.app = FakeSwift()
self.decrypter = decrypter.Decrypter(self.app, {})
self.decrypter.logger = FakeLogger()
self.decrypter.logger = debug_logger()
def _make_response_headers(self, content_length, plaintext_etag, keys,
body_key, key_id=None):
@ -983,7 +983,7 @@ class TestDecrypterContainerRequests(unittest.TestCase):
def setUp(self):
self.app = FakeSwift()
self.decrypter = decrypter.Decrypter(self.app, {})
self.decrypter.logger = FakeLogger()
self.decrypter.logger = debug_logger()
def _make_cont_get_req(self, resp_body, format, override=False,
callback=fetch_crypto_keys):


+ 3
- 2
test/unit/common/middleware/crypto/test_encrypter.py View File

@ -30,7 +30,8 @@ from swift.common.swob import (
wsgi_to_bytes, bytes_to_wsgi)
from swift.common.utils import FileLikeIter
from test.unit import FakeLogger, EMPTY_ETAG
from test.debug_logger import debug_logger
from test.unit import EMPTY_ETAG
from test.unit.common.middleware.crypto.crypto_helpers import (
fetch_crypto_keys, md5hex, FAKE_IV, encrypt)
from test.unit.common.middleware.helpers import FakeSwift, FakeAppThatExcepts
@ -42,7 +43,7 @@ class TestEncrypter(unittest.TestCase):
def setUp(self):
self.app = FakeSwift()
self.encrypter = encrypter.Encrypter(self.app, {})
self.encrypter.logger = FakeLogger()
self.encrypter.logger = debug_logger()
def _verify_user_metadata(self, req_hdrs, name, value, key):
# verify encrypted version of user metadata


+ 3
- 2
test/unit/common/middleware/crypto/test_encryption.py View File

@ -29,7 +29,8 @@ from swift.common.ring import Ring
from swift.common.swob import Request, str_to_wsgi
from swift.obj import diskfile
from test.unit import FakeLogger, skip_if_no_xattrs
from test.debug_logger import debug_logger
from test.unit import skip_if_no_xattrs
from test.unit.common.middleware.crypto.crypto_helpers import (
md5hex, encrypt, TEST_KEYMASTER_CONF)
from test.unit.helpers import setup_servers, teardown_servers
@ -438,7 +439,7 @@ class TestCryptoPipelineChanges(unittest.TestCase):
partition, nodes = ring_object.get_nodes('a', self.container_name, 'o')
conf = {'devices': self._test_context["testdir"],
'mount_check': 'false'}
df_mgr = diskfile.DiskFileRouter(conf, FakeLogger())[policy]
df_mgr = diskfile.DiskFileRouter(conf, debug_logger())[policy]
ondisk_data = []
exp_enc_body = None
for node_index, node in enumerate(nodes):


+ 3
- 2
test/unit/common/middleware/helpers.py View File

@ -24,7 +24,8 @@ from swift.common.request_helpers import is_user_meta, \
from swift.common.swob import HTTPNotImplemented
from swift.common.utils import split_path, md5
from test.unit import FakeLogger, FakeRing
from test.debug_logger import debug_logger
from test.unit import FakeRing
class LeakTrackingIter(object):
@ -88,7 +89,7 @@ class FakeSwift(object):
self.uploaded = {}
# mapping of (method, path) --> (response class, headers, body)
self._responses = {}
self.logger = FakeLogger('fake-swift')
self.logger = debug_logger('fake-swift')
self.account_ring = FakeRing()
self.container_ring = FakeRing()
self.get_object_ring = lambda policy_index: FakeRing()


+ 1
- 1
test/unit/common/middleware/s3api/__init__.py View File

@ -24,7 +24,7 @@ from swift.common import swob
from swift.common.middleware.s3api.s3api import filter_factory
from swift.common.middleware.s3api.etree import fromstring
from test.unit import debug_logger
from test.debug_logger import debug_logger
from test.unit.common.middleware.s3api.helpers import FakeSwift


+ 1
- 1
test/unit/common/middleware/s3api/test_s3api.py View File

@ -35,7 +35,7 @@ from swift.common.utils import md5
from keystonemiddleware.auth_token import AuthProtocol
from keystoneauth1.access import AccessInfoV2
from test.unit import debug_logger
from test.debug_logger import debug_logger
from test.unit.common.middleware.s3api import S3ApiTestCase
from test.unit.common.middleware.s3api.helpers import FakeSwift
from test.unit.common.middleware.s3api.test_s3token import \


+ 2
- 2
test/unit/common/middleware/s3api/test_s3request.py View File

@ -35,7 +35,7 @@ from swift.common.middleware.s3api.s3response import InvalidArgument, \
AccessDenied, SignatureDoesNotMatch, RequestTimeTooSkewed, BadDigest
from swift.common.utils import md5
from test.unit import DebugLogger
from test.debug_logger import debug_logger
Fake_ACL_MAP = {
# HEAD Bucket
@ -110,7 +110,7 @@ class TestRequest(S3ApiTestCase):
'Date': self.get_date_header()})
s3_req = req_klass(req.environ, conf=self.s3api.conf)
s3_req.set_acl_handler(
get_acl_handler(s3_req.controller_name)(s3_req, DebugLogger()))
get_acl_handler(s3_req.controller_name)(s3_req, debug_logger()))
with patch('swift.common.middleware.s3api.s3request.S3Request.'
'_get_response') as mock_get_resp, \
patch('swift.common.middleware.s3api.subresource.ACL.'


+ 1
- 1
test/unit/common/middleware/test_bulk.py View File

@ -27,7 +27,7 @@ from shutil import rmtree
from tempfile import mkdtemp
from eventlet import sleep
from mock import patch, call
from test.unit import debug_logger
from test.debug_logger import debug_logger
from test.unit.common.middleware.helpers import FakeSwift
from swift.common import utils, constraints
from swift.common.header_key_dict import HeaderKeyDict


+ 3
- 3
test/unit/common/middleware/test_container_sync.py View File

@ -26,7 +26,7 @@ from swift.common.middleware import container_sync
from swift.proxy.controllers.base import get_cache_key
from swift.proxy.controllers.info import InfoController
from test.unit import FakeLogger
from test.debug_logger import debug_logger
class FakeApp(object):
@ -90,7 +90,7 @@ cluster_dfw1 = http://dfw1.host/v1/
def test_current_invalid(self):
self.conf = {'swift_dir': self.tempdir, 'current': 'foo'}
self.sync = container_sync.ContainerSync(self.app, self.conf,
logger=FakeLogger())
logger=debug_logger())
self.assertIsNone(self.sync.realm)
self.assertIsNone(self.sync.cluster)
info = {}
@ -136,7 +136,7 @@ cluster_dfw1 = http://dfw1.host/v1/
def test_missing_from_realms_conf(self):
self.conf = {'swift_dir': self.tempdir, 'current': 'foo/bar'}
self.sync = container_sync.ContainerSync(self.app, self.conf,
logger=FakeLogger())
logger=debug_logger())
self.assertEqual('FOO', self.sync.realm)
self.assertEqual('BAR', self.sync.cluster)
info = {}


+ 2
- 1
test/unit/common/middleware/test_copy.py View File

@ -23,7 +23,8 @@ from swift.common.middleware import copy
from swift.common.storage_policy import POLICIES
from swift.common.swob import Request, HTTPException
from swift.common.utils import closing_if_possible, md5
from test.unit import patch_policies, debug_logger, FakeRing
from test.debug_logger import debug_logger
from test.unit import patch_policies, FakeRing
from test.unit.common.middleware.helpers import FakeSwift
from test.unit.proxy.controllers.test_obj import set_http_connect, \
PatchedObjControllerApp


+ 9
- 9
test/unit/common/middleware/test_keystoneauth.py View File

@ -20,7 +20,7 @@ from swift.common.swob import Request, Response
from swift.common.http import HTTP_FORBIDDEN
from swift.common.utils import split_path
from swift.proxy.controllers.base import get_cache_key
from test.unit import FakeLogger
from test.debug_logger import debug_logger
UNKNOWN_ID = keystoneauth.UNKNOWN_ID
@ -97,7 +97,7 @@ class FakeApp(object):
class SwiftAuth(unittest.TestCase):
def setUp(self):
self.test_auth = keystoneauth.filter_factory({})(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
def _make_request(self, path=None, headers=None, **kwargs):
if not path:
@ -352,7 +352,7 @@ class SwiftAuthMultiple(SwiftAuth):
def setUp(self):
self.test_auth = keystoneauth.filter_factory(
{'reseller_prefix': 'AUTH, PRE2'})(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
class ServiceTokenFunctionality(unittest.TestCase):
@ -541,7 +541,7 @@ class ServiceTokenFunctionality(unittest.TestCase):
class BaseTestAuthorize(unittest.TestCase):
def setUp(self):
self.test_auth = keystoneauth.filter_factory({})(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
def _make_request(self, path, **kwargs):
return Request.blank(path, **kwargs)
@ -929,7 +929,7 @@ class TestAuthorize(BaseTestAuthorizeCheck):
def test_names_allowed_in_acls_inside_default_domain_with_config(self):
conf = {'allow_names_in_acls': 'yes'}
self.test_auth = keystoneauth.filter_factory(conf)(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
id = self._get_identity_for_v2(user_domain_id='default',
project_domain_id='default')
env = {'keystone.token_info': _fake_token_info(version='3')}
@ -956,7 +956,7 @@ class TestAuthorize(BaseTestAuthorizeCheck):
def test_names_disallowed_in_acls_inside_default_domain(self):
conf = {'allow_names_in_acls': 'false'}
self.test_auth = keystoneauth.filter_factory(conf)(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
id = self._get_identity_for_v2(user_domain_id='default',
project_domain_id='default')
env = {'keystone.token_info': _fake_token_info(version='3')}
@ -1278,7 +1278,7 @@ class TestIsNameAllowedInACLWithConfiguredDomain(TestIsNameAllowedInACL):
super(TestIsNameAllowedInACLWithConfiguredDomain, self).setUp()
conf = {'default_domain_id': 'mydefault'}
self.test_auth = keystoneauth.filter_factory(conf)(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
self.default_id = 'mydefault'
@ -1303,7 +1303,7 @@ class TestSetProjectDomain(BaseTestAuthorize):
project_domain_id=req_project_domain_id)
# reset fake logger
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
num_warnings = 0
# check account requests
@ -1519,7 +1519,7 @@ class TestAuthorizeReader(BaseTestAuthorizeCheck):
def _setup(self, system_reader_roles):
self.test_auth = keystoneauth.filter_factory(
{}, system_reader_roles=system_reader_roles)(FakeApp())
self.test_auth.logger = FakeLogger()
self.test_auth.logger = debug_logger()
# Zero test: make sure that reader role has no default access
# when not in the list of system_reader_roles[].


+ 1
- 1
test/unit/common/middleware/test_listing_formats.py View File

@ -19,7 +19,7 @@ import unittest
from swift.common.swob import Request, HTTPOk, HTTPNoContent
from swift.common.middleware import listing_formats
from swift.common.request_helpers import get_reserved_name
from test.unit import debug_logger
from test.debug_logger import debug_logger
from test.unit.common.middleware.helpers import FakeSwift


+ 1
- 1
test/unit/common/middleware/test_proxy_logging.py View File

@ -26,7 +26,7 @@ from swift.common.middleware import proxy_logging
from swift.common.swob import Request, Response
from swift.common import constraints
from swift.common.storage_policy import StoragePolicy
from test.unit import debug_logger
from test.debug_logger import debug_logger
from test.unit import patch_policies
from test.unit.common.middleware.helpers import FakeAppThatExcepts


+ 3
- 3
test/unit/common/middleware/test_ratelimit.py View File

@ -19,7 +19,7 @@ import eventlet
import mock
from contextlib import contextmanager
from test.unit import FakeLogger
from test.debug_logger import debug_logger
from swift.common.middleware import ratelimit
from swift.proxy.controllers.base import get_cache_key, \
headers_to_container_info
@ -147,7 +147,7 @@ class TestRateLimit(unittest.TestCase):
'container_ratelimit_50': 100,
'container_ratelimit_75': 30}
test_ratelimit = ratelimit.filter_factory(conf_dict)(FakeApp())
test_ratelimit.logger = FakeLogger()
test_ratelimit.logger = debug_logger()
self.assertIsNone(ratelimit.get_maxrate(
test_ratelimit.container_ratelimits, 0))
self.assertIsNone(ratelimit.get_maxrate(
@ -319,7 +319,7 @@ class TestRateLimit(unittest.TestCase):
'account_whitelist': 'a',
'account_blacklist': 'b'}
self.test_ratelimit = ratelimit.filter_factory(conf_dict)(FakeApp())
self.test_ratelimit.logger = FakeLogger()
self.test_ratelimit.logger = debug_logger()
self.test_ratelimit.BLACK_LIST_SLEEP = 0
req = Request.blank('/v1/b/c')
req.environ['swift.cache'] = FakeMemcache()


+ 12
- 12
test/unit/common/middleware/test_read_only.py View File

@ -18,7 +18,7 @@ import unittest
from swift.common.middleware import read_only
from swift.common.swob import Request
from test.unit import FakeLogger
from test.debug_logger import debug_logger
class FakeApp(object):
@ -43,7 +43,7 @@ class TestReadOnly(unittest.TestCase):
}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={}):
@ -59,7 +59,7 @@ class TestReadOnly(unittest.TestCase):
}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={}):
@ -79,7 +79,7 @@ class TestReadOnly(unittest.TestCase):
conf = {}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={'sysmeta': {'read-only': 'true'}}):
@ -99,7 +99,7 @@ class TestReadOnly(unittest.TestCase):
conf = {}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={'sysmeta': {'read-only': 'false'}}):
@ -115,7 +115,7 @@ class TestReadOnly(unittest.TestCase):
}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={'sysmeta': {'read-only': 'false'}}):
@ -132,7 +132,7 @@ class TestReadOnly(unittest.TestCase):
}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={}):
@ -147,7 +147,7 @@ class TestReadOnly(unittest.TestCase):
}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch('swift.common.middleware.read_only.get_info',
return_value={'sysmeta': {'read-only': 'on'}}):
@ -162,7 +162,7 @@ class TestReadOnly(unittest.TestCase):
}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
def get_fake_read_only(*args, **kwargs):
if 'b' in args:
@ -181,7 +181,7 @@ class TestReadOnly(unittest.TestCase):
conf = {}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
def get_fake_read_only(*args, **kwargs):
if 'b' in args:
@ -200,7 +200,7 @@ class TestReadOnly(unittest.TestCase):
conf = {}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
def fake_account_read_only(self, req, account):
if account == 'a':
@ -221,7 +221,7 @@ class TestReadOnly(unittest.TestCase):
conf = {}
ro = read_only.filter_factory(conf)(FakeApp())
ro.logger = FakeLogger()
ro.logger = debug_logger()
with mock.patch(
'swift.common.middleware.read_only.ReadOnlyMiddleware.' +


+ 2
- 2
test/unit/common/middleware/test_subrequest_logging.py View File

@ -18,7 +18,7 @@ from swift.common.middleware import copy, proxy_logging
from swift.common.swob import Request, HTTPOk
from swift.common.utils import close_if_possible
from swift.common.wsgi import make_subrequest
from test.unit import FakeLogger
from test.debug_logger import debug_logger
from test.unit.common.middleware.helpers import FakeSwift
@ -57,7 +57,7 @@ class FakeFilter(object):
class FakeApp(object):
def __init__(self, conf):
self.fake_logger = FakeLogger()
self.fake_logger = debug_logger()
self.fake_swift = self.app = FakeSwift()
self.register = self.fake_swift.register
for filter in reversed([


+ 11
- 10
test/unit/common/test_container_sync_realms.py View File

@ -22,14 +22,15 @@ import six
from mock import patch
from swift.common.container_sync_realms import ContainerSyncRealms
from test.unit import FakeLogger, temptree
from test.debug_logger import debug_logger
from test.unit import temptree
class TestUtils(unittest.TestCase):
def test_no_file_there(self):
unique = uuid.uuid4().hex
logger = FakeLogger()
logger = debug_logger()
csr = ContainerSyncRealms(unique, logger)
self.assertEqual(
logger.all_log_lines(),
@ -43,7 +44,7 @@ class TestUtils(unittest.TestCase):
fname = 'container-sync-realms.conf'
fcontents = ''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
def _mock_getmtime(path):
@ -65,7 +66,7 @@ class TestUtils(unittest.TestCase):
fname = 'container-sync-realms.conf'
fcontents = ''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
self.assertEqual(logger.all_log_lines(), {})
@ -76,7 +77,7 @@ class TestUtils(unittest.TestCase):
fname = 'container-sync-realms.conf'
fcontents = 'invalid'
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
if six.PY2:
@ -103,7 +104,7 @@ key = 9ff3b71c849749dbaec4ccdd3cbab62b
cluster_dfw1 = http://dfw1.host/v1/
'''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
self.assertEqual(logger.all_log_lines(), {})
@ -131,7 +132,7 @@ key2 = f6351bd1cc36413baa43f7ba1b45e51d
cluster_lon3 = http://lon3.host/v1/
'''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
self.assertEqual(logger.all_log_lines(), {})
@ -155,7 +156,7 @@ cluster_lon3 = http://lon3.host/v1/
[US]
'''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
self.assertEqual(logger.all_log_lines(), {})
@ -173,7 +174,7 @@ cluster_lon3 = http://lon3.host/v1/
mtime_check_interval = invalid
'''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
self.assertEqual(
@ -187,7 +188,7 @@ mtime_check_interval = invalid
fname = 'container-sync-realms.conf'
fcontents = ''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
self.assertEqual(


+ 1
- 1
test/unit/common/test_daemon.py View File

@ -28,7 +28,7 @@ from collections import defaultdict
import errno
from swift.common import daemon, utils
from test.unit import debug_logger
from test.debug_logger import debug_logger
class MyDaemon(daemon.Daemon):


+ 1
- 1
test/unit/common/test_db_auditor.py View File

@ -23,7 +23,7 @@ from shutil import rmtree
from eventlet import Timeout
from swift.common.db_auditor import DatabaseAuditor
from test.unit import debug_logger
from test.debug_logger import debug_logger
class FakeDatabaseBroker(object):


+ 33
- 35
test/unit/common/test_db_replicator.py View File

@ -40,7 +40,8 @@ from swift.common.exceptions import DriveNotMounted
from swift.common.swob import HTTPException
from test import unit
from test.unit import FakeLogger, attach_fake_replication_rpc
from test.debug_logger import debug_logger
from test.unit import attach_fake_replication_rpc
from test.unit.common.test_db import ExampleBroker
@ -303,7 +304,7 @@ class TestDBReplicator(unittest.TestCase):
self.recon_cache = mkdtemp()
rmtree(self.recon_cache, ignore_errors=1)
os.mkdir(self.recon_cache)
self.logger = unit.debug_logger('test-replicator')
self.logger = debug_logger('test-replicator')
def tearDown(self):
for patcher in self._patchers:
@ -509,9 +510,8 @@ class TestDBReplicator(unittest.TestCase):
FakeBroker(), -1)), False)
def test_run_once_no_local_device_in_ring(self):
logger = unit.debug_logger('test-replicator')
replicator = TestReplicator({'recon_cache_path': self.recon_cache},
logger=logger)
logger=self.logger)
with patch('swift.common.db_replicator.whataremyips',
return_value=['127.0.0.1']):
replicator.run_once()
@ -519,29 +519,28 @@ class TestDBReplicator(unittest.TestCase):
"Can't find itself 127.0.0.1 with port 1000 "
"in ring file, not replicating",
]
self.assertEqual(expected, logger.get_lines_for_level('error'))
self.assertEqual(expected, self.logger.get_lines_for_level('error'))
def test_run_once_with_local_device_in_ring(self):
logger = unit.debug_logger('test-replicator')
base = 'swift.common.db_replicator.'
with patch(base + 'whataremyips', return_value=['1.1.1.1']), \
patch(base + 'ring', FakeRingWithNodes()):
replicator = TestReplicator({'bind_port': 6200,
'recon_cache_path': self.recon_cache},
logger=logger)
logger=self.logger)
replicator.run_once()
self.assertFalse(logger.get_lines_for_level('error'))
self.assertFalse(self.logger.get_lines_for_level('error'))
def test_run_once_no_ips(self):
replicator = TestReplicator({}, logger=unit.FakeLogger())
replicator = TestReplicator({}, logger=self.logger)
self._patch(patch.object, db_replicator, 'whataremyips',
lambda *a, **kw: [])
replicator.run_once()
self.assertEqual(
replicator.logger.log_dict['error'],
[(('ERROR Failed to get my own IPs?',), {})])
replicator.logger.get_lines_for_level('error'),
['ERROR Failed to get my own IPs?'])
def test_run_once_node_is_not_mounted(self):
db_replicator.ring = FakeRingWithSingleNode()
@ -549,7 +548,7 @@ class TestDBReplicator(unittest.TestCase):
# returned by itself.
conf = {'mount_check': 'true', 'bind_ip': '1.1.1.1',
'bind_port': 6200}
replicator = TestReplicator(conf, logger=unit.FakeLogger())
replicator = TestReplicator(conf, logger=self.logger)
self.assertEqual(replicator.mount_check, True)
self.assertEqual(replicator.port, 6200)
@ -566,13 +565,13 @@ class TestDBReplicator(unittest.TestCase):
replicator.run_once()
self.assertEqual(
replicator.logger.log_dict['warning'],
[(('Skipping: %s', (err, )), {})])
replicator.logger.get_lines_for_level('warning'),
['Skipping: %s' % (err,)])
def test_run_once_node_is_mounted(self):
db_replicator.ring = FakeRingWithSingleNode()
conf = {'mount_check': 'true', 'bind_port': 6200}
replicator = TestReplicator(conf, logger=unit.FakeLogger())
replicator = TestReplicator(conf, logger=self.logger)
self.assertEqual(replicator.mount_check, True)
self.assertEqual(replicator.port, 6200)
@ -631,12 +630,11 @@ class TestDBReplicator(unittest.TestCase):
@mock.patch('swift.common.db_replicator.dump_recon_cache')
@mock.patch('swift.common.db_replicator.time.time', return_value=1234.5678)
def test_stats(self, mock_time, mock_recon_cache):
logger = unit.debug_logger('test-replicator')
replicator = TestReplicator({}, logger=logger)
replicator = TestReplicator({}, logger=self.logger)
replicator._zero_stats()
self.assertEqual(replicator.stats['start'], mock_time.return_value)
replicator._report_stats()
self.assertEqual(logger.get_lines_for_level('info'), [
self.assertEqual(self.logger.get_lines_for_level('info'), [
'Attempted to replicate 0 dbs in 0.00000 seconds (0.00000/s)',
'Removed 0 dbs',
'0 successes, 0 failures',
@ -651,7 +649,7 @@ class TestDBReplicator(unittest.TestCase):
})
mock_recon_cache.reset_mock()
logger.clear()
self.logger.clear()
replicator.stats.update({
'attempted': 30,
'success': 25,
@ -670,7 +668,7 @@ class TestDBReplicator(unittest.TestCase):
mock_time.return_value += 246.813576
replicator._report_stats()
self.maxDiff = None
self.assertEqual(logger.get_lines_for_level('info'), [
self.assertEqual(self.logger.get_lines_for_level('info'), [
'Attempted to replicate 30 dbs in 246.81358 seconds (0.12155/s)',
'Removed 9 dbs',
'25 successes, 1 failures',
@ -688,7 +686,7 @@ class TestDBReplicator(unittest.TestCase):
# verify return values from replicate_object
db_replicator.ring = FakeRingWithNodes()
db_path = '/path/to/file'
replicator = TestReplicator({}, logger=FakeLogger())
replicator = TestReplicator({}, logger=self.logger)
info = FakeBroker().get_replication_info()
# make remote appear to be in sync
rinfo = {'point': info['max_row'], 'id': 'remote_id'}
@ -991,7 +989,7 @@ class TestDBReplicator(unittest.TestCase):
self.assertEqual(5, replicator._repl_to_node.call_count)
def test_replicate_account_out_of_place(self):
replicator = TestReplicator({}, logger=unit.FakeLogger())
replicator = TestReplicator({}, logger=self.logger)
replicator.ring = FakeRingWithNodes().Ring('path')
replicator.brokerclass = FakeAccountBroker
replicator._repl_to_node = lambda *args: True
@ -1007,7 +1005,7 @@ class TestDBReplicator(unittest.TestCase):
self.assertEqual(error_msgs, [expected])
def test_replicate_container_out_of_place(self):
replicator = TestReplicator({}, logger=unit.FakeLogger())
replicator = TestReplicator({}, logger=self.logger)
replicator.ring = FakeRingWithNodes().Ring('path')
replicator._repl_to_node = lambda *args: True
replicator.delete_db = self.stub_delete_db
@ -1018,12 +1016,12 @@ class TestDBReplicator(unittest.TestCase):
replicator._replicate_object(str(part), '/path/to/file', node_id)
self.assertEqual(['/path/to/file'], self.delete_db_calls)
self.assertEqual(
replicator.logger.log_dict['error'],
[(('Found /path/to/file for /a%20c%20t/c%20o%20n when it should '
'be on partition 0; will replicate out and remove.',), {})])
replicator.logger.get_lines_for_level('error'),
['Found /path/to/file for /a%20c%20t/c%20o%20n when it should '
'be on partition 0; will replicate out and remove.'])
def test_replicate_container_out_of_place_no_node(self):
replicator = TestReplicator({}, logger=unit.FakeLogger())
replicator = TestReplicator({}, logger=self.logger)
replicator.ring = FakeRingWithSingleNode().Ring('path')
replicator._repl_to_node = lambda *args: True
@ -1062,7 +1060,7 @@ class TestDBReplicator(unittest.TestCase):
def test_delete_db(self):
db_replicator.lock_parent_directory = lock_parent_directory
replicator = TestReplicator({}, logger=unit.FakeLogger())
replicator = TestReplicator({}, logger=self.logger)
replicator._zero_stats()
replicator.extract_device = lambda _: 'some_device'
@ -1373,8 +1371,8 @@ class TestDBReplicator(unittest.TestCase):
def test_replicator_sync_with_broker_replication_missing_table(self):
rpc = db_replicator.ReplicatorRpc('/', '/', FakeBroker,
mount_check=False)
rpc.logger = unit.debug_logger()
mount_check=False,
logger=self.logger)
broker = FakeBroker()
broker.get_repl_missing_table = True
@ -1808,6 +1806,7 @@ class TestHandoffsOnly(unittest.TestCase):
def setUp(self):
self.root = mkdtemp()
self.logger = debug_logger()
# object disks; they're just here to make sure they don't trip us up
os.mkdir(os.path.join(self.root, 'sdc'))
@ -1831,13 +1830,12 @@ class TestHandoffsOnly(unittest.TestCase):
rmtree(self.root, ignore_errors=True)
def test_scary_warnings(self):
logger = unit.FakeLogger()
replicator = TestReplicator({
'handoffs_only': 'yes',
'devices': self.root,
'bind_port': 6201,
'mount_check': 'no',
}, logger=logger)
}, logger=self.logger)
with patch.object(db_replicator, 'whataremyips',
return_value=['10.0.0.1']), \
@ -1846,7 +1844,7 @@ class TestHandoffsOnly(unittest.TestCase):
replicator.run_once()
self.assertEqual(
logger.get_lines_for_level('warning'),
self.logger.get_lines_for_level('warning'),
[('Starting replication pass with handoffs_only enabled. This '
'mode is not intended for normal operation; use '
'handoffs_only with care.'),
@ -2081,14 +2079,14 @@ class TestReplicatorSync(unittest.TestCase):
self.root = mkdtemp()
self.rpc = self.replicator_rpc(
self.root, self.datadir, self.backend, mount_check=False,
logger=unit.debug_logger())
logger=debug_logger())
FakeReplConnection = attach_fake_replication_rpc(self.rpc)
self._orig_ReplConnection = db_replicator.ReplConnection
db_replicator.ReplConnection = FakeReplConnection
self._orig_Ring = db_replicator.ring.Ring
self._ring = unit.FakeRing()
db_replicator.ring.Ring = lambda *args, **kwargs: self._get_ring()
self.logger = unit.debug_logger()
self.logger = debug_logger()
def tearDown(self):
db_replicator.ReplConnection = self._orig_ReplConnection


+ 2
- 1
test/unit/common/test_direct_client.py View File

@ -33,7 +33,8 @@ from swift.common.swob import RESPONSE_REASONS
from swift.common.storage_policy import POLICIES
from six.moves.http_client import HTTPException
from test.unit import patch_policies, debug_logger
from test.debug_logger import debug_logger
from test.unit import patch_policies
class FakeConn(object):


+ 2
- 2
test/unit/common/test_internal_client.py View File

@ -30,8 +30,8 @@ from swift.common.header_key_dict import HeaderKeyDict
from swift.common.storage_policy import StoragePolicy
from swift.common.middleware.proxy_logging import ProxyLoggingMiddleware
from test.unit import with_tempdir, write_fake_ring, patch_policies, \
debug_logger
from test.debug_logger import debug_logger
from test.unit import with_tempdir, write_fake_ring, patch_policies
from test.unit.common.middleware.helpers import FakeSwift, LeakTrackingIter
if six.PY3:


+ 1
- 1
test/unit/common/test_memcached.py View File

@ -35,7 +35,7 @@ from eventlet.pools import Pool
from swift.common import memcached
from swift.common.utils import md5
from mock import patch, MagicMock
from test.unit import debug_logger
from test.debug_logger import debug_logger
class MockedMemcachePool(memcached.MemcacheConnPool):


+ 5
- 4
test/unit/common/test_storage_policy.py View File

@ -22,8 +22,9 @@ from functools import partial
from six.moves.configparser import ConfigParser
from tempfile import NamedTemporaryFile
from test.debug_logger import debug_logger
from test.unit import (
patch_policies, FakeRing, temptree, DEFAULT_TEST_EC_TYPE, FakeLogger)
patch_policies, FakeRing, temptree, DEFAULT_TEST_EC_TYPE)
import swift.common.storage_policy
from swift.common.storage_policy import (
StoragePolicyCollection, POLICIES, PolicyError, parse_storage_policies,
@ -1495,11 +1496,11 @@ class TestStoragePolicies(unittest.TestCase):
policy = StoragePolicy(0, name='zero', is_default=True,
diskfile_module='replication.fs')
dfm = policy.get_diskfile_manager({'devices': 'sdb1'}, FakeLogger())
dfm = policy.get_diskfile_manager({'devices': 'sdb1'}, debug_logger())
self.assertEqual('sdb1', dfm.devices)
dfm = policy.get_diskfile_manager({'devices': 'sdb2'}, FakeLogger())
dfm = policy.get_diskfile_manager({'devices': 'sdb2'}, debug_logger())
self.assertEqual('sdb2', dfm.devices)
dfm2 = policy.get_diskfile_manager({'devices': 'sdb2'}, FakeLogger())
dfm2 = policy.get_diskfile_manager({'devices': 'sdb2'}, debug_logger())
self.assertEqual('sdb2', dfm2.devices)
self.assertIsNot(dfm, dfm2)


+ 32
- 28
test/unit/common/test_utils.py View File

@ -18,8 +18,9 @@ from __future__ import print_function
import hashlib
from test.unit import temptree, debug_logger, make_timestamp_iter, \
with_tempdir, mock_timestamp_now, FakeIterable
from test.debug_logger import debug_logger
from test.unit import temptree, make_timestamp_iter, with_tempdir, \
mock_timestamp_now, FakeIterable
import ctypes
import contextlib
@ -79,7 +80,7 @@ from swift.common.container_sync_realms import ContainerSyncRealms
from swift.common.header_key_dict import HeaderKeyDict
from swift.common.storage_policy import POLICIES, reload_storage_policies
from swift.common.swob import Request, Response
from test.unit import FakeLogger, requires_o_tmpfile_support_in_tmp, \
from test.unit import requires_o_tmpfile_support_in_tmp, \
quiet_eventlet_exceptions
threading = eventlet.patcher.original('threading')
@ -1519,7 +1520,8 @@ class TestUtils(unittest.TestCase):
self.handleError(record)
logger = logging.getLogger()
logger.addHandler(CrashyLogger())
handler = CrashyLogger()
logger.addHandler(handler)
# Set up some real file descriptors for stdio. If you run
# nosetests with "-s", you already have real files there, but
@ -1547,6 +1549,8 @@ class TestUtils(unittest.TestCase):
logger.info("I like ham")
self.assertGreater(crashy_calls[0], 1)
logger.removeHandler(handler)
def test_parse_options(self):
# Get a file that is definitely on disk
with NamedTemporaryFile() as f:
@ -2895,7 +2899,7 @@ key = 9ff3b71c849749dbaec4ccdd3cbab62b
cluster_dfw1 = http://dfw1.host/v1/
'''
with temptree([fname], [fcontents]) as tempdir:
logger = FakeLogger()
logger = debug_logger()
fpath = os.path.join(tempdir, fname)
csr = ContainerSyncRealms(fpath, logger)
for realms_conf in (None, csr):
@ -3633,7 +3637,7 @@ cluster_dfw1 = http://dfw1.host/v1/
'bytes': 1234, 'hash': 'asdf', 'name': 'zxcv',
'content_type': 'text/plain; hello="world"; swift_bytes=15'}
utils.override_bytes_from_content_type(listing_dict,
logger=FakeLogger())
logger=debug_logger())
self.assertEqual(listing_dict['bytes'], 15)
self.assertEqual(listing_dict['content_type'],
'text/plain;hello="world"')
@ -3642,7 +3646,7 @@ cluster_dfw1 = http://dfw1.host/v1/
'bytes': 1234, 'hash': 'asdf', 'name': 'zxcv',
'content_type': 'text/plain; hello="world"; swift_bytes=hey'}
utils.override_bytes_from_content_type(listing_dict,
logger=FakeLogger())
logger=debug_logger())
self.assertEqual(listing_dict['bytes'], 1234)
self.assertEqual(listing_dict['content_type'],
'text/plain;hello="world"')
@ -3941,15 +3945,15 @@ cluster_dfw1 = http://dfw1.host/v1/
def test_cache_from_env(self):
# should never get logging when swift.cache is found
env = {'swift.cache': 42}
logger = FakeLogger()
logger = debug_logger()
with mock.patch('swift.common.utils.logging', logger):
self.assertEqual(42, utils.cache_from_env(env))
self.assertEqual(0, len(logger.get_lines_for_level('error')))
logger = FakeLogger()
logger = debug_logger()
with mock.patch('swift.common.utils.logging', logger):
self.assertEqual(42, utils.cache_from_env(env, False))
self.assertEqual(0, len(logger.get_lines_for_level('error')))
logger = FakeLogger()
logger = debug_logger()
with mock.patch('swift.common.utils.logging', logger):
self.assertEqual(42, utils.cache_from_env(env, True))
self.assertEqual(0, len(logger.get_lines_for_level('error')))
@ -3957,15 +3961,15 @@ cluster_dfw1 = http://dfw1.host/v1/
# check allow_none controls logging when swift.cache is not found
err_msg = 'ERROR: swift.cache could not be found in env!'
env = {}
logger = FakeLogger()
logger = debug_logger()
with mock.patch('swift.common.utils.logging', logger):
self.assertIsNone(utils.cache_from_env(env))
self.assertTrue(err_msg in logger.get_lines_for_level('error'))
logger = FakeLogger()
logger = debug_logger()
with mock.patch('swift.common.utils.logging', logger):
self.assertIsNone(utils.cache_from_env(env, False))
self.assertTrue(err_msg in logger.get_lines_for_level('error'))
logger = FakeLogger()
logger = debug_logger()
with mock.patch('swift.common.utils.logging', logger):
self.assertIsNone(utils.cache_from_env(env, True))
self.assertEqual(0, len(logger.get_lines_for_level('error')))
@ -3993,7 +3997,7 @@ cluster_dfw1 = http://dfw1.host/v1/
# Not a directory - arg is file path
self.assertRaises(OSError, utils.fsync_dir, temppath)
logger = FakeLogger()
logger = debug_logger()
def _mock_fsync(fd):
raise OSError(errno.EBADF, os.strerror(errno.EBADF))
@ -5566,7 +5570,7 @@ class TestStatsdLogging(unittest.TestCase):
}, 'some-name', log_route='some-route')
statsd_client = logger.logger.statsd_client
fl = FakeLogger()
fl = debug_logger()
statsd_client.logger = fl
mock_socket = MockUdpSocket()
@ -5579,7 +5583,7 @@ class TestStatsdLogging(unittest.TestCase):
def test_no_exception_when_cant_send_udp_packet(self):
logger = utils.get_logger({'log_statsd_host': 'some.host.com'})
statsd_client = logger.logger.statsd_client
fl = FakeLogger()
fl = debug_logger()
statsd_client.logger = fl
mock_socket = MockUdpSocket(sendto_errno=errno.EPERM)
statsd_client._open_socket = lambda *_: mock_socket
@ -6327,7 +6331,7 @@ class TestAuditLocationGenerator(unittest.TestCase):
def test_non_dir_drive(self):
with temptree([]) as tmpdir:
logger = FakeLogger()
logger = debug_logger()
data = os.path.join(tmpdir, "drive", "data")
os.makedirs(data)
# Create a file, that represents a non-dir drive
@ -6345,7 +6349,7 @@ class TestAuditLocationGenerator(unittest.TestCase):
def test_mount_check_drive(self):
with temptree([]) as tmpdir: