update functional tests configuration
This commit is contained in:
commit
27c559c89a
@ -740,7 +740,7 @@ def readconf(conf, section_name=None, log_name=None, defaults=None):
|
||||
"""
|
||||
Read config file and return config items as a dict
|
||||
|
||||
:param conf: path to config file
|
||||
:param conf: path to config file, or a file-like object (hasattr readline)
|
||||
:param section_name: config section to read (will return all sections if
|
||||
not defined)
|
||||
:param log_name: name to be used with logging (will use section_name if
|
||||
@ -751,9 +751,12 @@ def readconf(conf, section_name=None, log_name=None, defaults=None):
|
||||
if defaults is None:
|
||||
defaults = {}
|
||||
c = ConfigParser(defaults)
|
||||
if not c.read(conf):
|
||||
print _("Unable to read config file %s") % conf
|
||||
sys.exit(1)
|
||||
if hasattr(conf, 'readline'):
|
||||
c.readfp(conf)
|
||||
else:
|
||||
if not c.read(conf):
|
||||
print _("Unable to read config file %s") % conf
|
||||
sys.exit(1)
|
||||
if section_name:
|
||||
if c.has_section(section_name):
|
||||
conf = dict(c.items(section_name))
|
||||
|
@ -2,6 +2,29 @@
|
||||
# The code below enables nosetests to work with i18n _() blocks
|
||||
|
||||
import __builtin__
|
||||
import sys
|
||||
import os
|
||||
from ConfigParser import MissingSectionHeaderError
|
||||
from StringIO import StringIO
|
||||
|
||||
from swift.common.utils import readconf
|
||||
|
||||
setattr(__builtin__, '_', lambda x: x)
|
||||
|
||||
|
||||
def get_config():
|
||||
"""
|
||||
Attempt to get a functional config dictionary.
|
||||
"""
|
||||
config_file = os.environ.get('SWIFT_TEST_CONFIG_FILE',
|
||||
'/etc/swift/func_test.conf')
|
||||
config = {}
|
||||
try:
|
||||
try:
|
||||
config = readconf(config_file, 'func_test')
|
||||
except MissingSectionHeaderError:
|
||||
config_fp = StringIO('[func_test]\n' + open(config_file).read())
|
||||
config = readconf(config_fp, 'func_test')
|
||||
except SystemExit:
|
||||
print >>sys.stderr, 'UNABLE TO READ FUNCTIONAL TESTS CONFIG FILE'
|
||||
return config
|
||||
|
0
test/functional/__init__.py
Normal file
0
test/functional/__init__.py
Normal file
@ -1,3 +1,4 @@
|
||||
[func_test]
|
||||
# sample config
|
||||
auth_host = 127.0.0.1
|
||||
# For DevAuth:
|
||||
|
@ -78,9 +78,10 @@ def listing_items(method):
|
||||
else:
|
||||
items = []
|
||||
|
||||
|
||||
class Connection(object):
|
||||
def __init__(self, config):
|
||||
for key in 'auth_host auth_port auth_ssl account username password'.split():
|
||||
for key in 'auth_host auth_port auth_ssl username password'.split():
|
||||
if not config.has_key(key):
|
||||
raise SkipTest
|
||||
|
||||
@ -89,7 +90,7 @@ class Connection(object):
|
||||
self.auth_ssl = config['auth_ssl'] in ('on', 'true', 'yes', '1')
|
||||
self.auth_prefix = config.get('auth_prefix', '/')
|
||||
|
||||
self.account = config['account']
|
||||
self.account = config.get('account')
|
||||
self.username = config['username']
|
||||
self.password = config['password']
|
||||
|
||||
@ -110,8 +111,12 @@ class Connection(object):
|
||||
self.storage_token = clone_conn.storage_token
|
||||
return
|
||||
|
||||
if self.account:
|
||||
auth_user = '%s:%s' % (self.account, self.username)
|
||||
else:
|
||||
auth_user = self.username
|
||||
headers = {
|
||||
'x-auth-user': '%s:%s' % (self.account, self.username),
|
||||
'x-auth-user': auth_user,
|
||||
'x-auth-key': self.password,
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import array
|
||||
import configobj
|
||||
from datetime import datetime
|
||||
import locale
|
||||
import os
|
||||
@ -29,22 +28,15 @@ import uuid
|
||||
import unittest
|
||||
import urllib
|
||||
|
||||
from test import get_config
|
||||
from swift import Account, AuthenticationFailed, Connection, Container, \
|
||||
File, ResponseError
|
||||
|
||||
config_file_env_var = 'SWIFT_TEST_CONFIG_FILE'
|
||||
default_config_file = '/etc/swift/func_test.conf'
|
||||
config = get_config()
|
||||
|
||||
if os.environ.has_key(config_file_env_var):
|
||||
config_file = os.environ[config_file_env_var]
|
||||
elif os.path.isfile(default_config_file):
|
||||
config_file = default_config_file
|
||||
else:
|
||||
print >>sys.stderr, 'SKIPPING FUNCTIONAL TESTS DUE TO NO CONFIG'
|
||||
|
||||
config = configobj.ConfigObj(config_file)
|
||||
locale.setlocale(locale.LC_COLLATE, config.get('collate', 'C'))
|
||||
|
||||
|
||||
class Base:
|
||||
pass
|
||||
|
||||
@ -136,7 +128,8 @@ class TestAccountEnv:
|
||||
def setUp(cls):
|
||||
cls.conn = Connection(config)
|
||||
cls.conn.authenticate()
|
||||
cls.account = Account(cls.conn, config['account'])
|
||||
cls.account = Account(cls.conn, config.get('account',
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
cls.containers = []
|
||||
@ -314,7 +307,8 @@ class TestAccountNoContainersEnv:
|
||||
def setUp(cls):
|
||||
cls.conn = Connection(config)
|
||||
cls.conn.authenticate()
|
||||
cls.account = Account(cls.conn, config['account'])
|
||||
cls.account = Account(cls.conn, config.get('account',
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
class TestAccountNoContainers(Base):
|
||||
@ -339,7 +333,8 @@ class TestContainerEnv:
|
||||
def setUp(cls):
|
||||
cls.conn = Connection(config)
|
||||
cls.conn.authenticate()
|
||||
cls.account = Account(cls.conn, config['account'])
|
||||
cls.account = Account(cls.conn, config.get('account',
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
cls.container = cls.account.container(Utils.create_name())
|
||||
@ -624,7 +619,8 @@ class TestContainerPathsEnv:
|
||||
def setUp(cls):
|
||||
cls.conn = Connection(config)
|
||||
cls.conn.authenticate()
|
||||
cls.account = Account(cls.conn, config['account'])
|
||||
cls.account = Account(cls.conn, config.get('account',
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
cls.file_size = 8
|
||||
@ -784,7 +780,8 @@ class TestFileEnv:
|
||||
def setUp(cls):
|
||||
cls.conn = Connection(config)
|
||||
cls.conn.authenticate()
|
||||
cls.account = Account(cls.conn, config['account'])
|
||||
cls.account = Account(cls.conn, config.get('account',
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
cls.container = cls.account.container(Utils.create_name())
|
||||
@ -1430,7 +1427,8 @@ class TestFileComparisonEnv:
|
||||
def setUp(cls):
|
||||
cls.conn = Connection(config)
|
||||
cls.conn.authenticate()
|
||||
cls.account = Account(cls.conn, config['account'])
|
||||
cls.account = Account(cls.conn, config.get('account',
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
cls.container = cls.account.container(Utils.create_name())
|
||||
|
@ -2,54 +2,50 @@ import errno
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
from ConfigParser import ConfigParser
|
||||
from httplib import HTTPException
|
||||
from time import sleep
|
||||
from nose import SkipTest
|
||||
from ConfigParser import MissingSectionHeaderError
|
||||
|
||||
from test import get_config
|
||||
|
||||
from swift.common.client import get_auth, http_connection
|
||||
|
||||
conf = get_config()
|
||||
|
||||
# If no conf was read, we will fall back to old school env vars
|
||||
swift_test_auth = os.environ.get('SWIFT_TEST_AUTH')
|
||||
swift_test_user = [os.environ.get('SWIFT_TEST_USER'), None, None]
|
||||
swift_test_key = [os.environ.get('SWIFT_TEST_KEY'), None, None]
|
||||
|
||||
# If no environment set, fall back to old school conf file
|
||||
if not all([swift_test_auth, swift_test_user[0], swift_test_key[0]]):
|
||||
conf = ConfigParser()
|
||||
class Sectionizer(object):
|
||||
def __init__(self, fp):
|
||||
self.sent_section = False
|
||||
self.fp = fp
|
||||
def readline(self):
|
||||
if self.sent_section:
|
||||
return self.fp.readline()
|
||||
self.sent_section = True
|
||||
return '[func_test]\n'
|
||||
if conf:
|
||||
swift_test_auth = 'http'
|
||||
if conf.get('auth_ssl', 'no').lower() in ('yes', 'true', 'on', '1'):
|
||||
swift_test_auth = 'https'
|
||||
if 'auth_prefix' not in conf:
|
||||
conf['auth_prefix'] = '/'
|
||||
try:
|
||||
conf.readfp(Sectionizer(open('/etc/swift/func_test.conf')))
|
||||
conf = dict(conf.items('func_test'))
|
||||
swift_test_auth = 'http'
|
||||
if conf.get('auth_ssl', 'no').lower() in ('yes', 'true', 'on', '1'):
|
||||
swift_test_auth = 'https'
|
||||
if 'auth_prefix' not in conf:
|
||||
conf['auth_prefix'] = '/'
|
||||
swift_test_auth += \
|
||||
'://%(auth_host)s:%(auth_port)s%(auth_prefix)sv1.0' % conf
|
||||
'://%(auth_host)s:%(auth_port)s%(auth_prefix)sv1.0' % conf
|
||||
except KeyError:
|
||||
pass # skip
|
||||
if 'account' in conf:
|
||||
swift_test_user[0] = '%(account)s:%(username)s' % conf
|
||||
swift_test_key[0] = conf['password']
|
||||
try:
|
||||
swift_test_user[1] = '%(account2)s:%(username2)s' % conf
|
||||
swift_test_key[1] = conf['password2']
|
||||
except KeyError, err:
|
||||
pass # old conf, no second account tests can be run
|
||||
try:
|
||||
swift_test_user[2] = '%(account)s:%(username3)s' % conf
|
||||
swift_test_key[2] = conf['password3']
|
||||
except KeyError, err:
|
||||
pass # old conf, no third account tests can be run
|
||||
except IOError, err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
else:
|
||||
swift_test_user[0] = '%(username)s' % conf
|
||||
swift_test_key[0] = conf['password']
|
||||
try:
|
||||
swift_test_user[1] = '%s%s' % ('%s:' % conf['account2'] if 'account2'
|
||||
in conf else '', conf['username2'])
|
||||
swift_test_key[1] = conf['password2']
|
||||
except KeyError, err:
|
||||
pass # old conf, no second account tests can be run
|
||||
try:
|
||||
swift_test_user[2] = '%s%s' % ('%s:' % conf['account'] if 'account'
|
||||
in conf else '', conf['username3'])
|
||||
swift_test_key[2] = conf['password3']
|
||||
except KeyError, err:
|
||||
pass # old conf, no third account tests can be run
|
||||
|
||||
skip = not all([swift_test_auth, swift_test_user[0], swift_test_key[0]])
|
||||
if skip:
|
||||
@ -77,7 +73,8 @@ class InternalServerError(Exception):
|
||||
url = [None, None, None]
|
||||
token = [None, None, None]
|
||||
parsed = [None, None, None]
|
||||
conn = [None, None, None]
|
||||
conn = [None, None, None]
|
||||
|
||||
|
||||
def retry(func, *args, **kwargs):
|
||||
"""
|
||||
|
@ -477,29 +477,36 @@ foo = bar
|
||||
|
||||
[section2]
|
||||
log_name = yarr'''
|
||||
f = open('/tmp/test', 'wb')
|
||||
f.write(conf)
|
||||
f.close()
|
||||
result = utils.readconf('/tmp/test')
|
||||
expected = {'log_name': None,
|
||||
'section1': {'foo': 'bar'},
|
||||
'section2': {'log_name': 'yarr'}}
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf('/tmp/test', 'section1')
|
||||
expected = {'log_name': 'section1', 'foo': 'bar'}
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf('/tmp/test', 'section2').get('log_name')
|
||||
expected = 'yarr'
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf('/tmp/test', 'section1',
|
||||
log_name='foo').get('log_name')
|
||||
expected = 'foo'
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf('/tmp/test', 'section1',
|
||||
defaults={'bar': 'baz'})
|
||||
expected = {'log_name': 'section1', 'foo': 'bar', 'bar': 'baz'}
|
||||
self.assertEquals(result, expected)
|
||||
# setup a real file
|
||||
with open('/tmp/test', 'wb') as f:
|
||||
f.write(conf)
|
||||
make_filename = lambda: '/tmp/test'
|
||||
# setup a file stream
|
||||
make_fp = lambda: StringIO(conf)
|
||||
for conf_object_maker in (make_filename, make_fp):
|
||||
result = utils.readconf(conf_object_maker())
|
||||
expected = {'log_name': None,
|
||||
'section1': {'foo': 'bar'},
|
||||
'section2': {'log_name': 'yarr'}}
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf(conf_object_maker(), 'section1')
|
||||
expected = {'log_name': 'section1', 'foo': 'bar'}
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf(conf_object_maker(),
|
||||
'section2').get('log_name')
|
||||
expected = 'yarr'
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf(conf_object_maker(), 'section1',
|
||||
log_name='foo').get('log_name')
|
||||
expected = 'foo'
|
||||
self.assertEquals(result, expected)
|
||||
result = utils.readconf(conf_object_maker(), 'section1',
|
||||
defaults={'bar': 'baz'})
|
||||
expected = {'log_name': 'section1', 'foo': 'bar', 'bar': 'baz'}
|
||||
self.assertEquals(result, expected)
|
||||
self.assertRaises(SystemExit, utils.readconf, '/tmp/test', 'section3')
|
||||
os.unlink('/tmp/test')
|
||||
self.assertRaises(SystemExit, utils.readconf, '/tmp/test')
|
||||
|
||||
def test_drop_privileges(self):
|
||||
user = getuser()
|
||||
@ -650,7 +657,6 @@ log_name = yarr'''
|
||||
# make sure its accurate to 10th of a second
|
||||
self.assertTrue(abs(100 - (time.time() - start) * 100) < 10)
|
||||
|
||||
|
||||
def test_search_tree(self):
|
||||
# file match & ext miss
|
||||
with temptree(['asdf.conf', 'blarg.conf', 'asdf.cfg']) as t:
|
||||
|
Loading…
Reference in New Issue
Block a user