]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Modify template account creation in SolidFire drvr
authorJohn Griffith <john.griffith8@gmail.com>
Sat, 20 Jun 2015 13:58:51 +0000 (07:58 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Tue, 23 Jun 2015 23:36:41 +0000 (16:36 -0700)
On a fresh cluster with no template account, we'll hit
an exception when doing the initial "check for account".

This patch modifies the create_template account method slightly
to use a try/except block to set this up.

Change-Id: I8ff7ff893412f5b30f8a88dc3b44ea592db01ced

cinder/tests/unit/test_solidfire.py
cinder/volume/drivers/solidfire.py

index f788ee72f33c2bad008268229fd247a1e81dc285..6afab604e26816bd392cad4149058b638ad2b5cd 100644 (file)
@@ -970,3 +970,17 @@ class SolidFireVolumeTestCase(test.TestCase):
                                          'fake',
                                          _fake_image_meta,
                                          'fake'))
+
+    def test_create_template_no_account(self):
+        sfv = solidfire.SolidFireDriver(configuration=self.configuration)
+
+        def _fake_issue_api_req(method, params, version=0):
+            if 'GetAccountByName' in method:
+                raise exception.SolidFireAPIException
+            return {'result': {'accountID': 1}}
+
+        with mock.patch.object(sfv,
+                               '_issue_api_request',
+                               side_effect=_fake_issue_api_req):
+            self.assertEqual(1,
+                             sfv._create_template_account('foo'))
index bbf29c75244586d7c477e552dd94b8307db0c404..fc677851f1fcd330d43bc5b1109286c4bcaeb988 100644 (file)
@@ -165,10 +165,12 @@ class SolidFireDriver(san.SanISCSIDriver):
                 configuration=self.configuration))
 
     def _create_template_account(self, account_name):
-        id = self._issue_api_request(
-            'GetAccountByName',
-            {'username': account_name})['result']['account']['accountID']
-        if not id:
+        # We raise an API exception if the account doesn't exist
+        try:
+            id = self._issue_api_request(
+                'GetAccountByName',
+                {'username': account_name})['result']['account']['accountID']
+        except exception.SolidFireAPIException:
             chap_secret = self._generate_random_string(12)
             params = {'username': account_name,
                       'initiatorSecret': chap_secret,