fixed bug in internal_proxy; added test

This commit is contained in:
Clay Gerrard 2010-11-04 15:57:34 -05:00
commit e351c9403d
2 changed files with 42 additions and 2 deletions

View File

@ -73,8 +73,7 @@ class LogProcessor(object):
self._internal_proxy = InternalProxy(proxy_server_conf,
self.logger,
retries=3)
else:
return self._internal_proxy
return self._internal_proxy
def process_one_file(self, plugin_name, account, container, object_name):
self.logger.info('Processing %s/%s/%s with plugin "%s"' % (account,

View File

@ -14,9 +14,32 @@
# limitations under the License.
import unittest
import os
from contextlib import contextmanager
from tempfile import NamedTemporaryFile
from swift.common.utils import readconf
from swift.common import internal_proxy
from swift.stats import log_processor
@contextmanager
def tmpfile(content):
with NamedTemporaryFile('w', delete=False) as f:
file_name = f.name
f.write(str(content))
try:
yield file_name
finally:
os.unlink(file_name)
class FakeApp(object):
def __init__(self, *args, **kwargs):
pass
def __call__(self, env, start_response):
return "FAKE APP"
class DumbLogger(object):
def __getattr__(self, n):
return self.foo
@ -63,6 +86,24 @@ class TestLogProcessor(unittest.TestCase):
}
}
def test_create_internal_proxy(self):
internal_proxy.BaseApplication = FakeApp
dummy_proxy_config = """[app:proxy-server]
use = egg:swift#proxy
"""
dummy_config_template = """[log-processor]
proxy_server_conf = %s
swift_account =
"""
with tmpfile(dummy_proxy_config) as proxy_config_file:
dummy_config = dummy_config_template % proxy_config_file
with tmpfile(dummy_config) as config_file:
conf = readconf(config_file)
d = log_processor.LogProcessorDaemon(conf)
self.assert_(isinstance(d.log_processor.internal_proxy,
log_processor.InternalProxy))
def test_access_log_line_parser(self):
access_proxy_config = self.proxy_config.copy()
access_proxy_config.update({