From e67adc385ce6997249fbf70e9402264f758fc6f4 Mon Sep 17 00:00:00 2001 From: Matthew Edmonds Date: Fri, 17 Jul 2015 16:42:35 -0400 Subject: [PATCH] mark oslo.vmware as optional dependency Driver-specific requirements are not hard requirements, since the choice of drivers is up to the operator. The oslo.vmware module is herein moved out of requirements.txt and instead listed as an optional dependency using the extras functionality in setup.cfg. A check is added to the vmdk driver to gracefully handle import errors if the vmdk driver is used and oslo.vmware is not found. Change-Id: I9b00edc38f0700304a1a164f0679a734f8701ebe Closes-Bug: #1475739 --- cinder/volume/drivers/vmware/vmdk.py | 20 +++++++++++++++----- requirements.txt | 1 - setup.cfg | 4 ++++ tox.ini | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cinder/volume/drivers/vmware/vmdk.py b/cinder/volume/drivers/vmware/vmdk.py index 20cdc5933..e894ef289 100644 --- a/cinder/volume/drivers/vmware/vmdk.py +++ b/cinder/volume/drivers/vmware/vmdk.py @@ -32,11 +32,16 @@ from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import units from oslo_utils import uuidutils -from oslo_vmware import api -from oslo_vmware import exceptions -from oslo_vmware import image_transfer -from oslo_vmware import pbm -from oslo_vmware import vim_util +try: + import oslo_vmware +except ImportError: + oslo_vmware = None +else: + from oslo_vmware import api + from oslo_vmware import exceptions + from oslo_vmware import image_transfer + from oslo_vmware import pbm + from oslo_vmware import vim_util import six from cinder import exception @@ -268,6 +273,11 @@ class VMwareEsxVmdkDriver(driver.VolumeDriver): :param context: Context information """ + if oslo_vmware is None: + msg = _("Missing 'oslo_vmware' python module, ensure the library" + " is installed and available.") + raise exception.VolumeDriverException(message=msg) + # Throw error if required parameters are not set. required_params = ['vmware_host_ip', 'vmware_host_username', diff --git a/requirements.txt b/requirements.txt index 8fb04cc87..d2a2f1e32 100644 --- a/requirements.txt +++ b/requirements.txt @@ -50,5 +50,4 @@ stevedore>=1.5.0 # Apache-2.0 suds-jurko>=0.6 WebOb>=1.2.3 oslo.i18n>=1.5.0 # Apache-2.0 -oslo.vmware>=1.16.0 # Apache-2.0 os-brick>=0.3.2 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index c7f7e5e26..f5190acd3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,10 @@ setup-hooks = packages = cinder +[extras] +vmdk = + oslo.vmware>=1.16.0 # Apache-2.0 + [entry_points] cinder.scheduler.filters = AvailabilityZoneFilter = cinder.openstack.common.scheduler.filters.availability_zone_filter:AvailabilityZoneFilter diff --git a/tox.ini b/tox.ini index 6dc68978d..5ee31eb48 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,7 @@ install_command = pip install {opts} {packages} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt + .[vmdk] # By default ostestr will set concurrency # to ncpu, to specify something else use -- 2.45.2