fixing after review
This commit is contained in:
parent
3dcfd4a3b4
commit
2ff7a179c3
@ -75,6 +75,15 @@ class SwiftBackend(glance.store.Backend):
|
||||
|
||||
return resp_body
|
||||
|
||||
@classmethod
|
||||
def _option_get(cls, options, param):
|
||||
result = options.get(param)
|
||||
if not result:
|
||||
msg = ("Could not find %s in configuration options." % param)
|
||||
logger.error(msg)
|
||||
raise glance.store.BackendException(msg)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def add(cls, id, data, options):
|
||||
"""
|
||||
@ -101,36 +110,19 @@ class SwiftBackend(glance.store.Backend):
|
||||
from swift.common import client as swift_client
|
||||
container = options.get('swift_store_container',
|
||||
DEFAULT_SWIFT_CONTAINER)
|
||||
auth_address = options.get('swift_store_auth_address')
|
||||
user = options.get('swift_store_user')
|
||||
key = options.get('swift_store_key')
|
||||
|
||||
# TODO(jaypipes): This needs to be checked every time
|
||||
# because of the decision to make glance.store.Backend's
|
||||
# interface all @classmethods. This is inefficient. Backend
|
||||
# should be a stateful object with options parsed once in
|
||||
# a constructor.
|
||||
if not auth_address:
|
||||
msg = ("Could not find swift_store_auth_address in configuration "
|
||||
"options.")
|
||||
logger.error(msg)
|
||||
raise glance.store.BackendException(msg)
|
||||
else:
|
||||
full_auth_address = auth_address
|
||||
if not full_auth_address.startswith('http'):
|
||||
full_auth_address = 'https://' + full_auth_address
|
||||
auth_address = cls._option_get(options, 'swift_store_auth_address')
|
||||
user = cls._option_get(options, 'swift_store_user')
|
||||
key = cls._option_get(options, 'swift_store_key')
|
||||
|
||||
if not user:
|
||||
msg = ("Could not find swift_store_user in configuration "
|
||||
"options.")
|
||||
logger.error(msg)
|
||||
raise glance.store.BackendException(msg)
|
||||
|
||||
if not key:
|
||||
msg = ("Could not find swift_store_key in configuration "
|
||||
"options.")
|
||||
logger.error(msg)
|
||||
raise glance.store.BackendException(msg)
|
||||
full_auth_address = auth_address
|
||||
if not full_auth_address.startswith('http'):
|
||||
full_auth_address = 'https://' + full_auth_address
|
||||
|
||||
swift_conn = swift_client.Connection(
|
||||
authurl=full_auth_address, user=user, key=key, snet=False)
|
||||
|
@ -324,41 +324,33 @@ class TestSwiftBackend(unittest.TestCase):
|
||||
SwiftBackend.add,
|
||||
2, image_swift, SWIFT_OPTIONS)
|
||||
|
||||
def _assertOptionRequiredForSwift(self, key):
|
||||
image_swift = StringIO.StringIO("nevergonnamakeit")
|
||||
options = SWIFT_OPTIONS.copy()
|
||||
del options[key]
|
||||
self.assertRaises(BackendException, SwiftBackend.add,
|
||||
2, image_swift, options)
|
||||
|
||||
def test_add_no_user(self):
|
||||
"""
|
||||
Tests that adding options without user raises
|
||||
an appropriate exception
|
||||
"""
|
||||
image_swift = StringIO.StringIO("nevergonnamakeit")
|
||||
options = SWIFT_OPTIONS.copy()
|
||||
del options['swift_store_user']
|
||||
self.assertRaises(BackendException,
|
||||
SwiftBackend.add,
|
||||
2, image_swift, options)
|
||||
self._assertOptionRequiredForSwift('swift_store_user')
|
||||
|
||||
def test_no_key(self):
|
||||
"""
|
||||
Tests that adding options without key raises
|
||||
an appropriate exception
|
||||
"""
|
||||
image_swift = StringIO.StringIO("nevergonnamakeit")
|
||||
options = SWIFT_OPTIONS.copy()
|
||||
del options['swift_store_key']
|
||||
self.assertRaises(BackendException,
|
||||
SwiftBackend.add,
|
||||
2, image_swift, options)
|
||||
self._assertOptionRequiredForSwift('swift_store_key')
|
||||
|
||||
def test_add_no_auth_address(self):
|
||||
"""
|
||||
Tests that adding options without auth address raises
|
||||
an appropriate exception
|
||||
"""
|
||||
image_swift = StringIO.StringIO("nevergonnamakeit")
|
||||
options = SWIFT_OPTIONS.copy()
|
||||
del options['swift_store_auth_address']
|
||||
self.assertRaises(BackendException,
|
||||
SwiftBackend.add,
|
||||
2, image_swift, options)
|
||||
self._assertOptionRequiredForSwift('swift_store_auth_address')
|
||||
|
||||
def test_delete(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user