diff options
author | Takashi Kajinami <tkajinam@redhat.com> | 2023-02-21 15:57:58 +0900 |
---|---|---|
committer | Takashi Kajinami <tkajinam@redhat.com> | 2023-02-21 17:38:57 +0900 |
commit | 7dc94f7a85e976a9c66f997f944c6ede06d7984a (patch) | |
tree | 752d9b87220995bbffb6fdc9324ef0af51b472a0 | |
parent | 64e25979a904e468e1e89d8727e9554662596acf (diff) | |
download | glance_store-7dc94f7a85e976a9c66f997f944c6ede06d7984a.tar.gz |
Do not always import boto3
Currently boto3 is not part of requirements but stevedore always tries
to import it and shows error in case boto3 is missing. This is not
a real error unless users actually enable s3 backends and can be quite
confusing.
This makes the driver code ignore ImportError and actually fail only
if users try to enable s3 backend without installing boto3.
Closes-Bug: #2007924
Change-Id: Ia94dd1d12a3d723f6263bdfb0966d416dfbae1af
-rw-r--r-- | glance_store/_drivers/s3.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/glance_store/_drivers/s3.py b/glance_store/_drivers/s3.py index 2988bae..8af1344 100644 --- a/glance_store/_drivers/s3.py +++ b/glance_store/_drivers/s3.py @@ -21,10 +21,17 @@ import math import re import urllib -from boto3 import session as boto_session -from botocore import client as boto_client -from botocore import exceptions as boto_exceptions -from botocore import utils as boto_utils +try: + from boto3 import session as boto_session + from botocore import client as boto_client + from botocore import exceptions as boto_exceptions + from botocore import utils as boto_utils +except ImportError: + boto_session = None + boto_client = None + boto_exceptions = None + boto_utils = None + import eventlet from oslo_config import cfg from oslo_utils import encodeutils @@ -390,6 +397,12 @@ class Store(glance_store.driver.Store): this method. If the store was not able to successfully configure itself, it should raise `exceptions.BadStoreConfiguration` """ + if boto_session is None: + reason = _("boto3 or botocore is not available.") + LOG.error(reason) + raise exceptions.BadStoreConfiguration(store_name="s3", + reason=reason) + self.s3_host = self._option_get('s3_store_host') self.region_name = self._option_get('s3_store_region_name') self.access_key = self._option_get('s3_store_access_key') |