]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make S3 optional since swiftclient is not available in all distributions
authorSteven Dake <sdake@redhat.com>
Tue, 11 Sep 2012 20:49:09 +0000 (13:49 -0700)
committerSteven Dake <sdake@redhat.com>
Tue, 11 Sep 2012 21:14:34 +0000 (14:14 -0700)
Change-Id: Ic5f61ac41090fd599f01b3eaae4ffb03aac2ebdd
Signed-off-by: Steven Dake <sdake@redhat.com>
heat/engine/resources.py
heat/engine/s3.py

index 5c39033a8b2afdcb54f4bcd5e228b10945f03b67..428cd736ad0da79db7d15bfe7d461110f8bccc61 100644 (file)
@@ -18,7 +18,14 @@ from datetime import datetime
 
 from novaclient.v1_1 import client as nc
 from keystoneclient.v2_0 import client as kc
-from swiftclient import client as swiftclient
+
+# swiftclient not available in all distributions - make s3 an optional
+# feature
+try:
+    from swiftclient import client as swiftclient
+    swiftclient_present = True
+except:
+    swiftclient_present = False
 
 from heat.common import exception
 from heat.common import config
@@ -230,6 +237,8 @@ class Resource(object):
         return self._nova[service_type]
 
     def swift(self):
+        if swiftclient_present == False:
+            return None
         if self._swift:
             return self._swift
 
index 37271fb6b8354e368034798c85f9b386d694ea7f..7a1816357472f596b26e7e13ba4abb383408e148 100644 (file)
@@ -20,7 +20,11 @@ from urlparse import urlparse
 from heat.common import exception
 from heat.engine.resources import Resource
 from heat.openstack.common import log as logging
-from swiftclient.client import ClientException
+try:
+    from swiftclient.client import ClientException
+    swiftclient_present = True
+except:
+    swiftclient_present = False
 
 logger = logging.getLogger('heat.engine.s3')
 
@@ -46,6 +50,15 @@ class S3Bucket(Resource):
     def __init__(self, name, json_snippet, stack):
         super(S3Bucket, self).__init__(name, json_snippet, stack)
 
+    def validate(self):
+        '''
+        Validate any of the provided params
+        '''
+        #check if swiftclient is installed
+        if swiftclient_present == False:
+            return {'Error':
+                    'S3 services unavaialble because of missing swiftclient.'}
+
     def handle_create(self):
         """Create a bucket."""
         container = 'heat-%s-%s' % (self.name,