Make external dependencies optional

This change makes driver dependencies optional thus allowing
sushy-tools to install and run test suite even if some of
these not-always-required dependencies would not otherwise
be met failing the entire installation run.

If the patch is merged, we would need to update sushy-tools
users (mainly, CI jobs) to install the drivers dependencies
of their choice or just all of them.

Story: 2004342
Task: 27929
Change-Id: Ibd05a19d66f372eaa8fc916af98722f7fe701f3c
This commit is contained in:
Ilya Etingof 2018-10-19 14:58:16 +02:00
parent 7aaa76d188
commit 483fefed8f
7 changed files with 40 additions and 22 deletions

View File

@ -15,3 +15,18 @@ Or, if you have virtualenvwrapper installed:
$ mkvirtualenv sushy-tools
$ pip install sushy-tools
The *Virtual Redfish BMC* tool relies upon one or more hypervisors to mimic
bare metal nodes. Depending on the virtualization backend you are planning
to use, certain third-party dependencies should also be installed.
The dependencies for the virtualization backends that should be installed
for the corresponding drivers to become operational are:
* `libvirt-python` for the libvirt driver
* `openstacksdk` for the nova driver
.. note::
The dependencies for at least one virtualization backend should be
satisfied to have *Virtual Redfish BMC* emulator operational.

View File

@ -4,5 +4,3 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
Flask>=1.0.2 # BSD
libvirt-python!=4.1.0,>=3.5.0 # LGPLv2+
openstacksdk>=0.11.2 # Apache-2.0

View File

@ -19,7 +19,14 @@ from collections import namedtuple
from sushy_tools.emulator.drivers.base import AbstractDriver
from sushy_tools.error import FishyError
import libvirt
try:
import libvirt
except ImportError:
libvirt = None
is_loaded = bool(libvirt)
BiosProcessResult = namedtuple('BiosProcessResult',
['tree',

View File

@ -19,8 +19,14 @@ import math
from sushy_tools.emulator.drivers.base import AbstractDriver
from sushy_tools.error import FishyError
import openstack
try:
import openstack
except ImportError:
openstack = None
is_loaded = bool(openstack)
logger = logging.getLogger(__name__)

View File

@ -20,17 +20,8 @@ import os
import ssl
import sys
try:
from sushy_tools.emulator.drivers import libvirtdriver
except ImportError:
libvirtdriver = None
try:
from sushy_tools.emulator.drivers import novadriver
except ImportError:
novadriver = None
from sushy_tools.emulator.drivers import libvirtdriver
from sushy_tools.emulator.drivers import novadriver
import flask
@ -50,14 +41,14 @@ def init_virt_driver(decorated_func):
if driver is None:
if 'OS_CLOUD' in os.environ:
if not novadriver:
if not novadriver.is_loaded:
app.logger.error('Nova driver not loaded')
sys.exit(1)
driver = novadriver.OpenStackDriver(os.environ['OS_CLOUD'])
else:
if not libvirtdriver:
if not libvirtdriver.is_loaded:
app.logger.error('libvirt driver not loaded')
sys.exit(1)
@ -294,14 +285,14 @@ def main():
args = parse_args()
if args.os_cloud:
if not novadriver:
if not novadriver.is_loaded:
app.logger.error('Nova driver not loaded')
return 1
driver = novadriver.OpenStackDriver(args.os_cloud)
else:
if not libvirtdriver:
if not libvirtdriver.is_loaded:
app.logger.error('libvirt driver not loaded')
return 1

View File

@ -11,7 +11,6 @@
# under the License.
import libvirt
from oslotest import base
from six.moves import mock
@ -26,8 +25,6 @@ class EmulatorTestCase(base.BaseTestCase):
def setUp(self):
self.app = main.app.test_client()
# This enables libvirt driver
main.driver = None
self.test_driver = LibvirtDriver()
super(EmulatorTestCase, self).setUp()

View File

@ -5,9 +5,13 @@
hacking>=1.0.0,<1.2.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
# used by libvirt driver
libvirt-python!=4.1.0,>=3.5.0 # LGPLv2+
python-subunit>=1.0.0 # Apache-2.0/BSD
sphinx!=1.6.6,>=1.6.2 # BSD
openstackdocstheme>=1.18.1 # Apache-2.0
# used by nova driver
openstacksdk>=0.11.2 # Apache-2.0
oslotest>=3.2.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0
testscenarios>=0.4 # Apache-2.0/BSD