Update configuration

driver arguments were moved to separate 'args' field in cloud_config

Change-Id: If8100b19b56a127b448052e9a8ece5677e9f8ce5
This commit is contained in:
Anton Studenov
2016-10-10 17:08:43 +03:00
parent 5126c62456
commit 0ff915cc04
10 changed files with 97 additions and 57 deletions

View File

@@ -26,15 +26,19 @@ library:
cloud_config = {
'cloud_management': {
'driver': 'devstack',
'args': {
'address': 'devstack.local',
'username': 'root',
}
},
'power_management': {
'driver': 'libvirt',
'args': {
'address': 'host.local',
'username': 'root',
}
}
}
Establish a connection to the cloud and verify it:

View File

@@ -14,15 +14,19 @@ library:
cloud_config = {
'cloud_management': {
'driver': 'devstack',
'args': {
'address': 'devstack.local',
'username': 'root',
}
},
'power_management': {
'driver': 'libvirt',
'args': {
'address': 'host.local',
'username': 'root',
}
}
}
Establish a connection to the cloud and verify it:

View File

@@ -20,10 +20,12 @@ def main():
cloud_config = {
'cloud_management': {
'driver': 'devstack',
'args': {
'address': 'devstack.local',
'username': 'developer',
}
}
}
logging.info('# Create connection to the cloud')
destructor = os_faults.connect(cloud_config)

View File

@@ -20,11 +20,14 @@ def main():
cloud_config = {
'cloud_management': {
'driver': 'fuel',
'args': {
'address': 'fuel.local',
'username': 'root',
}
},
'power_management': {
'driver': 'ipmi',
'args': {
'mac_to_bmc': {
'00:00:00:00:00:00': {
'address': '55.55.55.55',
@@ -34,6 +37,7 @@ def main():
}
}
}
}
logging.info('Create connection to the cluster')
destructor = os_faults.connect(cloud_config)

View File

@@ -20,14 +20,18 @@ def main():
cloud_config = {
'cloud_management': {
'driver': 'fuel',
'args': {
'address': 'fuel.local',
'username': 'root',
}
},
'power_management': {
'driver': 'libvirt',
'args': {
'connection_uri': "qemu+ssh://ubuntu@host.local/system"
}
}
}
logging.info('Create connection to the cluster')
destructor = os_faults.connect(cloud_config)
@@ -44,6 +48,7 @@ def main():
one.poweroff()
one.poweron()
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
level=logging.DEBUG)

View File

@@ -20,15 +20,19 @@ def main():
cloud_config = {
'cloud_management': {
'driver': 'fuel',
'args': {
'address': 'fuel.local',
'username': 'root',
'private_key_file': '~/.ssh/os_faults',
}
},
'power_management': {
'driver': 'libvirt',
'args': {
'connection_uri': 'qemu+ssh://ubuntu@host.local/system'
}
}
}
logging.info('# Create connection to the cloud')
destructor = os_faults.connect(cloud_config)

View File

@@ -52,16 +52,8 @@ def _read_config(config_filename):
def _init_driver(params):
all_drivers = registry.get_drivers()
name = params.get('driver')
if not name:
return None
if name not in all_drivers:
raise error.OSFError('Driver %s is not found' % name)
return all_drivers[name](params)
driver_cls = registry.get_driver(params['driver'])
return driver_cls(params.get('args', {}))
def connect(cloud_config=None, config_filename=None):
@@ -71,18 +63,18 @@ def connect(cloud_config=None, config_filename=None):
:param config_filename: name of the file where to read config from
:return: CloudManagement object
"""
if not cloud_config:
if cloud_config is None:
cloud_config = _read_config(config_filename)
cloud_management_params = cloud_config.get('cloud_management') or {}
cloud_management = _init_driver(cloud_management_params)
if not cloud_management:
if 'cloud_management' not in cloud_config:
raise error.OSFError('Cloud management driver name is not specified')
power_management_params = cloud_config.get('power_management') or {}
power_management = _init_driver(power_management_params)
cloud_management_conf = cloud_config['cloud_management']
cloud_management = _init_driver(cloud_management_conf)
power_management_conf = cloud_config.get('power_management', {})
if power_management_conf:
power_management = _init_driver(power_management_conf)
cloud_management.set_power_management(power_management)
return cloud_management

View File

@@ -30,3 +30,7 @@ class ServiceError(OSFError):
class NodeCollectionError(OSFError):
"""Base Error class for NodeCollection API"""
class OSFDriverNotFound(OSFError):
"""Driver Not Found by os-faults registry"""

View File

@@ -18,6 +18,7 @@ import sys
from oslo_utils import importutils
from os_faults.api import base_driver
from os_faults.api import error
from os_faults import drivers
DRIVERS = {}
@@ -57,7 +58,7 @@ def _list_drivers():
klazz = class_info[1]
if issubclass(klazz, base_driver.BaseDriver):
yield class_info[1]
yield klazz
def get_drivers():
@@ -67,3 +68,12 @@ def get_drivers():
DRIVERS = dict((k.get_driver_name(), k) for k in _list_drivers())
return DRIVERS
def get_driver(name):
all_drivers = get_drivers()
if name not in all_drivers:
raise error.OSFDriverNotFound('Driver %s is not found' % name)
return all_drivers[name]

View File

@@ -31,23 +31,29 @@ class OSFaultsTestCase(test.TestCase):
self.cloud_config = {
'cloud_management': {
'driver': 'fuel',
'args': {
'address': '10.30.00.5',
'username': 'root',
}
},
'power_management': {
'driver': 'libvirt',
'args': {
'connection_uri': "qemu+ssh://user@10.30.20.21/system"
}
}
}
def test_connect_devstack(self):
cloud_config = {
'cloud_management': {
'driver': 'devstack',
'args': {
'address': 'devstack.local',
'username': 'developer',
}
}
}
destructor = os_faults.connect(cloud_config)
self.assertIsInstance(destructor, devstack.DevStackManagement)
@@ -61,11 +67,14 @@ class OSFaultsTestCase(test.TestCase):
cloud_config = {
'cloud_management': {
'driver': 'fuel',
'args': {
'address': '10.30.00.5',
'username': 'root',
}
},
'power_management': {
'driver': 'ipmi',
'args': {
'mac_to_bmc': {
'00:00:00:00:00:00': {
'address': '55.55.55.55',
@@ -75,6 +84,7 @@ class OSFaultsTestCase(test.TestCase):
}
}
}
}
destructor = os_faults.connect(cloud_config)
self.assertIsInstance(destructor, fuel.FuelManagement)
self.assertIsInstance(destructor.power_management, ipmi.IPMIDriver)
@@ -85,10 +95,11 @@ class OSFaultsTestCase(test.TestCase):
'driver': 'non-existing',
}
}
self.assertRaises(error.OSFError, os_faults.connect, cloud_config)
self.assertRaises(
error.OSFDriverNotFound, os_faults.connect, cloud_config)
def test_connect_driver_not_specified(self):
cloud_config = {}
cloud_config = {'foo': 'bar'}
self.assertRaises(error.OSFError, os_faults.connect, cloud_config)
@mock.patch('os.path.exists', return_value=True)