Merge "Refactor config setup to reduce complexity"
This commit is contained in:
commit
8aad2ec3b2
@ -18,25 +18,28 @@ class Config(object):
|
|||||||
"""Parses configuration to attributes required for auth and test data"""
|
"""Parses configuration to attributes required for auth and test data"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def set_admin_creds(cls, config):
|
||||||
config = ConfigParser.RawConfigParser()
|
|
||||||
if config.read('functional_creds.conf'):
|
|
||||||
# admin creds
|
|
||||||
cls.admin_user = config.get('admin', 'user')
|
cls.admin_user = config.get('admin', 'user')
|
||||||
cls.admin_passwd = config.get('admin', 'pass')
|
cls.admin_passwd = config.get('admin', 'pass')
|
||||||
cls.admin_tenant = config.get('admin', 'tenant')
|
cls.admin_tenant = config.get('admin', 'tenant')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_user_creds(cls, config):
|
||||||
# normal user creds
|
# normal user creds
|
||||||
cls.user = config.get('auth', 'username')
|
cls.user = config.get('auth', 'username')
|
||||||
cls.passwd = config.get('auth', 'password')
|
cls.passwd = config.get('auth', 'password')
|
||||||
cls.tenant = config.get('auth', 'tenant_name')
|
cls.tenant = config.get('auth', 'tenant_name')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_auth_version(cls, config):
|
||||||
# auth version for client authentication
|
# auth version for client authentication
|
||||||
if config.has_option('auth', 'auth_version'):
|
if config.has_option('auth', 'auth_version'):
|
||||||
cls.auth_version = config.get('auth', 'auth_version')
|
cls.auth_version = config.get('auth', 'auth_version')
|
||||||
else:
|
else:
|
||||||
cls.auth_version = 'v3'
|
cls.auth_version = 'v3'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_auth_url(cls, config):
|
||||||
# auth_url for client authentication
|
# auth_url for client authentication
|
||||||
if cls.auth_version == 'v3':
|
if cls.auth_version == 'v3':
|
||||||
if not config.has_option('auth', 'auth_v3_url'):
|
if not config.has_option('auth', 'auth_v3_url'):
|
||||||
@ -47,25 +50,46 @@ class Config(object):
|
|||||||
raise Exception('config missing auth_url key')
|
raise Exception('config missing auth_url key')
|
||||||
cls.auth_url = config.get('auth', 'auth_url')
|
cls.auth_url = config.get('auth', 'auth_url')
|
||||||
|
|
||||||
# optional magnum bypass url
|
@classmethod
|
||||||
cls.magnum_url = config.get('auth', 'magnum_url')
|
def set_region(cls, config):
|
||||||
|
|
||||||
if config.has_option('auth', 'region'):
|
if config.has_option('auth', 'region'):
|
||||||
cls.region = config.get('auth', 'region')
|
cls.region = config.get('auth', 'region')
|
||||||
else:
|
else:
|
||||||
cls.region = 'RegionOne'
|
cls.region = 'RegionOne'
|
||||||
|
|
||||||
# magnum functional test variables
|
@classmethod
|
||||||
|
def set_image_id(cls, config):
|
||||||
cls.image_id = config.get('magnum', 'image_id')
|
cls.image_id = config.get('magnum', 'image_id')
|
||||||
if not config.has_option('magnum', 'image_id'):
|
if not config.has_option('magnum', 'image_id'):
|
||||||
raise Exception('config missing image_id key')
|
raise Exception('config missing image_id key')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_nic_id(cls, config):
|
||||||
cls.nic_id = config.get('magnum', 'nic_id')
|
cls.nic_id = config.get('magnum', 'nic_id')
|
||||||
if not config.has_option('magnum', 'nic_id'):
|
if not config.has_option('magnum', 'nic_id'):
|
||||||
raise Exception('config missing nic_id key')
|
raise Exception('config missing nic_id key')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_keypair_id(cls, config):
|
||||||
cls.keypair_id = config.get('magnum', 'keypair_id')
|
cls.keypair_id = config.get('magnum', 'keypair_id')
|
||||||
if not config.has_option('magnum', 'keypair_id'):
|
if not config.has_option('magnum', 'keypair_id'):
|
||||||
raise Exception('config missing keypair_id key')
|
raise Exception('config missing keypair_id key')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUp(cls):
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
if config.read('functional_creds.conf'):
|
||||||
|
cls.set_admin_creds(config)
|
||||||
|
cls.set_user_creds(config)
|
||||||
|
cls.set_auth_version(config)
|
||||||
|
cls.set_auth_url(config)
|
||||||
|
|
||||||
|
# optional magnum bypass url
|
||||||
|
cls.magnum_url = config.get('auth', 'magnum_url')
|
||||||
|
|
||||||
|
cls.set_region(config)
|
||||||
|
cls.set_image_id(config)
|
||||||
|
cls.set_nic_id(config)
|
||||||
|
cls.set_keypair_id(config)
|
||||||
else:
|
else:
|
||||||
raise Exception('missing functional_creds.conf file')
|
raise Exception('missing functional_creds.conf file')
|
||||||
|
2
tox.ini
2
tox.ini
@ -26,7 +26,7 @@ deps =
|
|||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands =
|
commands =
|
||||||
doc8 -e .rst specs/ doc/source/ contrib/ CONTRIBUTING.rst HACKING.rst README.rst
|
doc8 -e .rst specs/ doc/source/ contrib/ CONTRIBUTING.rst HACKING.rst README.rst
|
||||||
flake8 --max-complexity 12 {posargs}
|
flake8 --max-complexity 11 {posargs}
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
Loading…
Reference in New Issue
Block a user