Update configuration
driver arguments were moved to separate 'args' field in cloud_config Change-Id: If8100b19b56a127b448052e9a8ece5677e9f8ce5
This commit is contained in:
@@ -26,15 +26,19 @@ library:
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'devstack',
|
'driver': 'devstack',
|
||||||
|
'args': {
|
||||||
'address': 'devstack.local',
|
'address': 'devstack.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'libvirt',
|
'driver': 'libvirt',
|
||||||
|
'args': {
|
||||||
'address': 'host.local',
|
'address': 'host.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Establish a connection to the cloud and verify it:
|
Establish a connection to the cloud and verify it:
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,19 @@ library:
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'devstack',
|
'driver': 'devstack',
|
||||||
|
'args': {
|
||||||
'address': 'devstack.local',
|
'address': 'devstack.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'libvirt',
|
'driver': 'libvirt',
|
||||||
|
'args': {
|
||||||
'address': 'host.local',
|
'address': 'host.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Establish a connection to the cloud and verify it:
|
Establish a connection to the cloud and verify it:
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ def main():
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'devstack',
|
'driver': 'devstack',
|
||||||
|
'args': {
|
||||||
'address': 'devstack.local',
|
'address': 'devstack.local',
|
||||||
'username': 'developer',
|
'username': 'developer',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logging.info('# Create connection to the cloud')
|
logging.info('# Create connection to the cloud')
|
||||||
destructor = os_faults.connect(cloud_config)
|
destructor = os_faults.connect(cloud_config)
|
||||||
|
|||||||
@@ -20,11 +20,14 @@ def main():
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'fuel',
|
'driver': 'fuel',
|
||||||
|
'args': {
|
||||||
'address': 'fuel.local',
|
'address': 'fuel.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'ipmi',
|
'driver': 'ipmi',
|
||||||
|
'args': {
|
||||||
'mac_to_bmc': {
|
'mac_to_bmc': {
|
||||||
'00:00:00:00:00:00': {
|
'00:00:00:00:00:00': {
|
||||||
'address': '55.55.55.55',
|
'address': '55.55.55.55',
|
||||||
@@ -34,6 +37,7 @@ def main():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logging.info('Create connection to the cluster')
|
logging.info('Create connection to the cluster')
|
||||||
destructor = os_faults.connect(cloud_config)
|
destructor = os_faults.connect(cloud_config)
|
||||||
|
|||||||
@@ -20,14 +20,18 @@ def main():
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'fuel',
|
'driver': 'fuel',
|
||||||
|
'args': {
|
||||||
'address': 'fuel.local',
|
'address': 'fuel.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'libvirt',
|
'driver': 'libvirt',
|
||||||
|
'args': {
|
||||||
'connection_uri': "qemu+ssh://ubuntu@host.local/system"
|
'connection_uri': "qemu+ssh://ubuntu@host.local/system"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logging.info('Create connection to the cluster')
|
logging.info('Create connection to the cluster')
|
||||||
destructor = os_faults.connect(cloud_config)
|
destructor = os_faults.connect(cloud_config)
|
||||||
@@ -44,6 +48,7 @@ def main():
|
|||||||
one.poweroff()
|
one.poweroff()
|
||||||
one.poweron()
|
one.poweron()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
||||||
level=logging.DEBUG)
|
level=logging.DEBUG)
|
||||||
|
|||||||
@@ -20,15 +20,19 @@ def main():
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'fuel',
|
'driver': 'fuel',
|
||||||
|
'args': {
|
||||||
'address': 'fuel.local',
|
'address': 'fuel.local',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
'private_key_file': '~/.ssh/os_faults',
|
'private_key_file': '~/.ssh/os_faults',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'libvirt',
|
'driver': 'libvirt',
|
||||||
|
'args': {
|
||||||
'connection_uri': 'qemu+ssh://ubuntu@host.local/system'
|
'connection_uri': 'qemu+ssh://ubuntu@host.local/system'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logging.info('# Create connection to the cloud')
|
logging.info('# Create connection to the cloud')
|
||||||
destructor = os_faults.connect(cloud_config)
|
destructor = os_faults.connect(cloud_config)
|
||||||
|
|||||||
@@ -52,16 +52,8 @@ def _read_config(config_filename):
|
|||||||
|
|
||||||
|
|
||||||
def _init_driver(params):
|
def _init_driver(params):
|
||||||
all_drivers = registry.get_drivers()
|
driver_cls = registry.get_driver(params['driver'])
|
||||||
|
return driver_cls(params.get('args', {}))
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def connect(cloud_config=None, config_filename=None):
|
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
|
:param config_filename: name of the file where to read config from
|
||||||
:return: CloudManagement object
|
:return: CloudManagement object
|
||||||
"""
|
"""
|
||||||
if not cloud_config:
|
if cloud_config is None:
|
||||||
cloud_config = _read_config(config_filename)
|
cloud_config = _read_config(config_filename)
|
||||||
|
|
||||||
cloud_management_params = cloud_config.get('cloud_management') or {}
|
if 'cloud_management' not in cloud_config:
|
||||||
cloud_management = _init_driver(cloud_management_params)
|
|
||||||
|
|
||||||
if not cloud_management:
|
|
||||||
raise error.OSFError('Cloud management driver name is not specified')
|
raise error.OSFError('Cloud management driver name is not specified')
|
||||||
|
|
||||||
power_management_params = cloud_config.get('power_management') or {}
|
cloud_management_conf = cloud_config['cloud_management']
|
||||||
power_management = _init_driver(power_management_params)
|
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)
|
cloud_management.set_power_management(power_management)
|
||||||
|
|
||||||
return cloud_management
|
return cloud_management
|
||||||
|
|||||||
@@ -30,3 +30,7 @@ class ServiceError(OSFError):
|
|||||||
|
|
||||||
class NodeCollectionError(OSFError):
|
class NodeCollectionError(OSFError):
|
||||||
"""Base Error class for NodeCollection API"""
|
"""Base Error class for NodeCollection API"""
|
||||||
|
|
||||||
|
|
||||||
|
class OSFDriverNotFound(OSFError):
|
||||||
|
"""Driver Not Found by os-faults registry"""
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import sys
|
|||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
from os_faults.api import base_driver
|
from os_faults.api import base_driver
|
||||||
|
from os_faults.api import error
|
||||||
from os_faults import drivers
|
from os_faults import drivers
|
||||||
|
|
||||||
DRIVERS = {}
|
DRIVERS = {}
|
||||||
@@ -57,7 +58,7 @@ def _list_drivers():
|
|||||||
klazz = class_info[1]
|
klazz = class_info[1]
|
||||||
|
|
||||||
if issubclass(klazz, base_driver.BaseDriver):
|
if issubclass(klazz, base_driver.BaseDriver):
|
||||||
yield class_info[1]
|
yield klazz
|
||||||
|
|
||||||
|
|
||||||
def get_drivers():
|
def get_drivers():
|
||||||
@@ -67,3 +68,12 @@ def get_drivers():
|
|||||||
DRIVERS = dict((k.get_driver_name(), k) for k in _list_drivers())
|
DRIVERS = dict((k.get_driver_name(), k) for k in _list_drivers())
|
||||||
|
|
||||||
return 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]
|
||||||
|
|||||||
@@ -31,23 +31,29 @@ class OSFaultsTestCase(test.TestCase):
|
|||||||
self.cloud_config = {
|
self.cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'fuel',
|
'driver': 'fuel',
|
||||||
|
'args': {
|
||||||
'address': '10.30.00.5',
|
'address': '10.30.00.5',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'libvirt',
|
'driver': 'libvirt',
|
||||||
|
'args': {
|
||||||
'connection_uri': "qemu+ssh://user@10.30.20.21/system"
|
'connection_uri': "qemu+ssh://user@10.30.20.21/system"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def test_connect_devstack(self):
|
def test_connect_devstack(self):
|
||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'devstack',
|
'driver': 'devstack',
|
||||||
|
'args': {
|
||||||
'address': 'devstack.local',
|
'address': 'devstack.local',
|
||||||
'username': 'developer',
|
'username': 'developer',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
destructor = os_faults.connect(cloud_config)
|
destructor = os_faults.connect(cloud_config)
|
||||||
self.assertIsInstance(destructor, devstack.DevStackManagement)
|
self.assertIsInstance(destructor, devstack.DevStackManagement)
|
||||||
|
|
||||||
@@ -61,11 +67,14 @@ class OSFaultsTestCase(test.TestCase):
|
|||||||
cloud_config = {
|
cloud_config = {
|
||||||
'cloud_management': {
|
'cloud_management': {
|
||||||
'driver': 'fuel',
|
'driver': 'fuel',
|
||||||
|
'args': {
|
||||||
'address': '10.30.00.5',
|
'address': '10.30.00.5',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'power_management': {
|
'power_management': {
|
||||||
'driver': 'ipmi',
|
'driver': 'ipmi',
|
||||||
|
'args': {
|
||||||
'mac_to_bmc': {
|
'mac_to_bmc': {
|
||||||
'00:00:00:00:00:00': {
|
'00:00:00:00:00:00': {
|
||||||
'address': '55.55.55.55',
|
'address': '55.55.55.55',
|
||||||
@@ -75,6 +84,7 @@ class OSFaultsTestCase(test.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
destructor = os_faults.connect(cloud_config)
|
destructor = os_faults.connect(cloud_config)
|
||||||
self.assertIsInstance(destructor, fuel.FuelManagement)
|
self.assertIsInstance(destructor, fuel.FuelManagement)
|
||||||
self.assertIsInstance(destructor.power_management, ipmi.IPMIDriver)
|
self.assertIsInstance(destructor.power_management, ipmi.IPMIDriver)
|
||||||
@@ -85,10 +95,11 @@ class OSFaultsTestCase(test.TestCase):
|
|||||||
'driver': 'non-existing',
|
'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):
|
def test_connect_driver_not_specified(self):
|
||||||
cloud_config = {}
|
cloud_config = {'foo': 'bar'}
|
||||||
self.assertRaises(error.OSFError, os_faults.connect, cloud_config)
|
self.assertRaises(error.OSFError, os_faults.connect, cloud_config)
|
||||||
|
|
||||||
@mock.patch('os.path.exists', return_value=True)
|
@mock.patch('os.path.exists', return_value=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user