From 9eb6995af280224668fb7611da9df2524bc6f849 Mon Sep 17 00:00:00 2001 From: Enis Afgan Date: Sat, 30 Jan 2016 08:03:50 -0500 Subject: [PATCH] Let a provider import raise an exception on a missing library and fix imports for non-dev library installs --- cloudbridge/cloud/factory.py | 9 +++------ cloudbridge/cloud/providers/aws/provider.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cloudbridge/cloud/factory.py b/cloudbridge/cloud/factory.py index 34883dcd..4b60a079 100644 --- a/cloudbridge/cloud/factory.py +++ b/cloudbridge/cloud/factory.py @@ -68,14 +68,11 @@ def register_provider_class(self, cls): def discover_providers(self): """ Discover all available providers within the - cloudbridge.cloud.providers package. + ``cloudbridge.cloud.providers`` package. + Note that this methods does not guard against a failed import. """ for _, modname, _ in pkgutil.iter_modules(providers.__path__): - try: - self._import_provider(modname) - except: - log.exception("Could not import providers from module: %s", - modname) + self._import_provider(modname) def _import_provider(self, module_name): """ diff --git a/cloudbridge/cloud/providers/aws/provider.py b/cloudbridge/cloud/providers/aws/provider.py index ccb0a045..a959567e 100644 --- a/cloudbridge/cloud/providers/aws/provider.py +++ b/cloudbridge/cloud/providers/aws/provider.py @@ -6,9 +6,14 @@ import boto from boto.ec2.regioninfo import RegionInfo -from httpretty import HTTPretty -from moto.ec2 import mock_ec2 -from moto.s3 import mock_s3 +try: + # These are installed only for the case of a dev instance + from httpretty import HTTPretty + from moto.ec2 import mock_ec2 + from moto.s3 import mock_s3 +except ImportError: + # TODO: Once library logging is configured, change this + print("[aws provider] moto library not available!") from cloudbridge.cloud.base import BaseCloudProvider from cloudbridge.cloud.interfaces import TestMockHelperMixin