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
This commit is contained in:
John Griffith 2015-06-20 07:58:51 -06:00 committed by John Griffith
parent 2b61c33054
commit 7c6e41833d
2 changed files with 20 additions and 4 deletions

View 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'))

View 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,