Handle optional dependency in vmware store
oslo_vmware is an optional dependency for glance_store. Hence, we should be able to register the store options even if the library is not installed. There are two problems addressed here :- 1. The import error was not handled. 2. One of the store opt referenced a constant from the library. Change-Id: I234a935f33e1cf8c3d6123994447bfca2365c3bb
This commit is contained in:
		@@ -24,12 +24,14 @@ import socket
 | 
				
			|||||||
from oslo_config import cfg
 | 
					from oslo_config import cfg
 | 
				
			||||||
from oslo_utils import excutils
 | 
					from oslo_utils import excutils
 | 
				
			||||||
from oslo_utils import units
 | 
					from oslo_utils import units
 | 
				
			||||||
from oslo_vmware import api
 | 
					try:
 | 
				
			||||||
from oslo_vmware import constants
 | 
					    from oslo_vmware import api
 | 
				
			||||||
import oslo_vmware.exceptions as vexc
 | 
					    import oslo_vmware.exceptions as vexc
 | 
				
			||||||
from oslo_vmware.objects import datacenter as oslo_datacenter
 | 
					    from oslo_vmware.objects import datacenter as oslo_datacenter
 | 
				
			||||||
from oslo_vmware.objects import datastore as oslo_datastore
 | 
					    from oslo_vmware.objects import datastore as oslo_datastore
 | 
				
			||||||
from oslo_vmware import vim_util
 | 
					    from oslo_vmware import vim_util
 | 
				
			||||||
 | 
					except ImportError:
 | 
				
			||||||
 | 
					    api = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import six
 | 
					import six
 | 
				
			||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
 | 
					# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
 | 
				
			||||||
@@ -66,7 +68,7 @@ _VMWARE_OPTS = [
 | 
				
			|||||||
                      'VMware ESX/VC server.'),
 | 
					                      'VMware ESX/VC server.'),
 | 
				
			||||||
               secret=True),
 | 
					               secret=True),
 | 
				
			||||||
    cfg.StrOpt('vmware_datacenter_path',
 | 
					    cfg.StrOpt('vmware_datacenter_path',
 | 
				
			||||||
               default=constants.ESX_DATACENTER_PATH,
 | 
					               default='ha-datacenter',
 | 
				
			||||||
               help=_('DEPRECATED. Inventory path to a datacenter. '
 | 
					               help=_('DEPRECATED. Inventory path to a datacenter. '
 | 
				
			||||||
                      'If the vmware_server_host specified is an ESX/ESXi, '
 | 
					                      'If the vmware_server_host specified is an ESX/ESXi, '
 | 
				
			||||||
                      'the vmware_datacenter_path is optional. If specified, '
 | 
					                      'the vmware_datacenter_path is optional. If specified, '
 | 
				
			||||||
@@ -320,6 +322,10 @@ class Store(glance_store.Store):
 | 
				
			|||||||
        self.api_retry_count = self.conf.glance_store.vmware_api_retry_count
 | 
					        self.api_retry_count = self.conf.glance_store.vmware_api_retry_count
 | 
				
			||||||
        self.tpoll_interval = self.conf.glance_store.vmware_task_poll_interval
 | 
					        self.tpoll_interval = self.conf.glance_store.vmware_task_poll_interval
 | 
				
			||||||
        self.api_insecure = self.conf.glance_store.vmware_api_insecure
 | 
					        self.api_insecure = self.conf.glance_store.vmware_api_insecure
 | 
				
			||||||
 | 
					        if api is None:
 | 
				
			||||||
 | 
					            msg = _("Missing dependencies: oslo_vmware")
 | 
				
			||||||
 | 
					            raise exceptions.BadStoreConfiguration(
 | 
				
			||||||
 | 
					                store_name="vmware_datastore", reason=msg)
 | 
				
			||||||
        self.session = self.reset_session()
 | 
					        self.session = self.reset_session()
 | 
				
			||||||
        super(Store, self).configure()
 | 
					        super(Store, self).configure()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user