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