diff --git a/README.rst b/README.rst index 53339dd..fadd670 100644 --- a/README.rst +++ b/README.rst @@ -14,6 +14,20 @@ IPMI driver). * Source: https://github.com/openstack/os-faults * Bugs: http://bugs.launchpad.net/os-faults + +Installation +------------ + +Reqular installation:: + + pip install os-faults + +The library contains optional libvirt driver, if you plan to use it, +please use the following command to install os-faults with extra dependencies:: + + pip install os-faults[libvirt] + + Configuration ------------- diff --git a/doc/source/installation.rst b/doc/source/installation.rst index 9d6dcf8..ab94a72 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -10,3 +10,8 @@ Or, if you have virtualenvwrapper installed:: $ mkvirtualenv os-faults $ pip install os-faults + +The library contains optional libvirt driver, if you plan to use it, +please use the following command to install os-faults with extra dependencies:: + + pip install os-faults[libvirt] diff --git a/os_faults/drivers/libvirt_driver.py b/os_faults/drivers/libvirt_driver.py index e9cd698..f76322f 100644 --- a/os_faults/drivers/libvirt_driver.py +++ b/os_faults/drivers/libvirt_driver.py @@ -13,8 +13,6 @@ import logging -import libvirt - from os_faults.api import error from os_faults.api import power_management from os_faults import utils @@ -44,6 +42,11 @@ class LibvirtDriver(power_management.PowerManagement): def _get_connection(self): if self._cached_conn is None: + try: + import libvirt + except ImportError: + raise error.OSFError('libvirt-python is required ' + 'to use LibvirtDriver') self._cached_conn = libvirt.open(self.connection_uri) return self._cached_conn diff --git a/requirements.txt b/requirements.txt index 37a9d1f..a07dacb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ oslo.i18n>=1.5.0 # Apache-2.0 oslo.log>=1.12.0 # Apache-2.0 oslo.serialization>=1.10.0 # Apache-2.0 oslo.utils!=2.6.0,>=2.4.0 # Apache-2.0 -libvirt-python>=1.2.5 # LGPLv2+ pyghmi>=1.0.3 # Apache-2.0 PyYAML>=3.1.0 # MIT six>=1.9.0 diff --git a/setup.cfg b/setup.cfg index 0afe37f..46a4ff3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,6 +24,10 @@ packages = console_scripts = os-inject-fault = os_faults.cmd.cmd:main +[extras] +libvirt = + libvirt-python>=1.2.5 # LGPLv2+ + [build_sphinx] source-dir = doc/source build-dir = doc/build diff --git a/tox.ini b/tox.ini index 2ae467a..62e13ca 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,10 @@ install_command = setenv = VIRTUAL_ENV={envdir} whitelist_externals = find -deps = -r{toxinidir}/test-requirements.txt +# TODO(astudenov): replace libvirt-python with extras option from tox 2.4 +deps = + -r{toxinidir}/test-requirements.txt + libvirt-python>=1.2.5 commands = find . -type f -name "*.pyc" -delete py.test -vvvv --html={envlogdir}/pytest_results.html --self-contained-html --durations=10 "os_faults/tests/unit" {posargs}