From 7c6e41833dc9d348be0b64bfbbc2375121bd7873 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Sat, 20 Jun 2015 07:58:51 -0600 Subject: [PATCH] Modify template account creation in SolidFire drvr 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 | 14 ++++++++++++++ cinder/volume/drivers/solidfire.py | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cinder/tests/unit/test_solidfire.py b/cinder/tests/unit/test_solidfire.py index f788ee72f..6afab604e 100644 --- a/cinder/tests/unit/test_solidfire.py +++ b/cinder/tests/unit/test_solidfire.py @@ -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')) diff --git a/cinder/volume/drivers/solidfire.py b/cinder/volume/drivers/solidfire.py index bbf29c752..fc677851f 100644 --- a/cinder/volume/drivers/solidfire.py +++ b/cinder/volume/drivers/solidfire.py @@ -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, -- 2.45.2