Skip to content

Commit

Permalink
REST session validity not checked in get_volume_info
Browse files Browse the repository at this point in the history
The fix for bug 1157242 introduced a new bug in Coraid cinder driver
_get_volume_info that the login session is not checked for
validity/timeout.  This change addressesthat issue for all
methods in the CoraidRESTClient class.

Fixes bug 1160459

Change-Id: Ib2d7ebbf3ef8ec35071f51c6168eb9b3af9405e6
  • Loading branch information
Larry Matter committed Mar 31, 2013
1 parent b7986d0 commit b78fb08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cinder/tests/test_coraid.py
Expand Up @@ -183,14 +183,14 @@ def test__get_group_id(self):
def test__set_group(self):
setattr(self.rest_mock, '_set_group',
lambda *_: fake_group_id)
self.stubs.Set(CoraidRESTClient, '_esm',
self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
lambda *_: fake_login_reply)
self.drv._set_group(fake_login_reply)

def test__set_group_fails_no_group(self):
setattr(self.rest_mock, '_set_group',
lambda *_: False)
self.stubs.Set(CoraidRESTClient, '_esm',
self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
lambda *_: fake_login_reply_group_fail)
self.assertRaises(CoraidESMException,
self.drv._set_group,
Expand All @@ -199,14 +199,14 @@ def test__set_group_fails_no_group(self):
def test__configure(self):
setattr(self.rest_mock, '_configure',
lambda *_: True)
self.stubs.Set(CoraidRESTClient, '_esm',
self.stubs.Set(CoraidRESTClient, '_esm_cmd',
lambda *_: fake_esm_success)
self.drv._configure(fake_configure_data)

def test__get_volume_info(self):
setattr(self.rest_mock, '_get_volume_info',
lambda *_: fake_volume_info)
self.stubs.Set(CoraidRESTClient, '_esm',
self.stubs.Set(CoraidRESTClient, '_esm_cmd',
lambda *_: fake_esm_fetch)
self.drv._get_volume_info(fake_volume_name)

Expand Down
19 changes: 11 additions & 8 deletions cinder/volume/drivers/coraid.py
Expand Up @@ -95,7 +95,7 @@ def _login(self):
url = ('admin?op=login&username=%s&password=%s' %
(self.user, self.password))
data = 'Login'
reply = self._esm(url, data)
reply = self._admin_esm_cmd(url, data)
if reply.get('state') == 'adminSucceed':
self.session = time.time() + 1100
msg = _('Update session cookie %(session)s')
Expand All @@ -116,7 +116,7 @@ def _set_group(self, reply):
if groupId:
url = ('admin?op=setRbacGroup&groupId=%s' % (groupId))
data = 'Group'
reply = self._esm(url, data)
reply = self._admin_esm_cmd(url, data)
if reply.get('state') == 'adminSucceed':
return True
else:
Expand All @@ -139,10 +139,14 @@ def _get_group_id(self, groupName, loginResult):
return kid['groupId']
return False

def _esm(self, url=False, data=None):
def _esm_cmd(self, url=False, data=None):
self._login()
return self._admin_esm_cmd(url, data)

def _admin_esm_cmd(self, url=False, data=None):
"""
_esm represent the entry point to send requests to ESM Appliance.
Send the HTTPS call, get response in JSON
_admin_esm_cmd represent the entry point to send requests to ESM
Appliance. Send the HTTPS call, get response in JSON
convert response into Python Object and return it.
"""
if url:
Expand All @@ -166,10 +170,9 @@ def _esm(self, url=False, data=None):

def _configure(self, data):
"""In charge of all commands into 'configure'."""
self._login()
url = 'configure'
LOG.debug(_('Configure data : %s'), data)
response = self._esm(url, data)
response = self._esm_cmd(url, data)
LOG.debug(_("Configure response : %s"), response)
if response:
if response.get('configState') == 'completedSuccessfully':
Expand All @@ -184,7 +187,7 @@ def _get_volume_info(self, volume_name):
"""Retrive volume informations for a given volume name."""
url = 'fetch?shelf=cms&orchStrRepo&lv=%s' % (volume_name)
try:
response = self._esm(url)
response = self._esm_cmd(url)
info = response[0][1]['reply'][0]
return {"pool": info['lv']['containingPool'],
"repo": info['repoName'],
Expand Down

0 comments on commit b78fb08

Please sign in to comment.