Merge "REST session validity not checked in get_volume_info"
This commit is contained in:
commit
3aa947d763
|
@ -183,14 +183,14 @@ class TestCoraidRESTClient(test.TestCase):
|
||||||
def test__set_group(self):
|
def test__set_group(self):
|
||||||
setattr(self.rest_mock, '_set_group',
|
setattr(self.rest_mock, '_set_group',
|
||||||
lambda *_: fake_group_id)
|
lambda *_: fake_group_id)
|
||||||
self.stubs.Set(CoraidRESTClient, '_esm',
|
self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
|
||||||
lambda *_: fake_login_reply)
|
lambda *_: fake_login_reply)
|
||||||
self.drv._set_group(fake_login_reply)
|
self.drv._set_group(fake_login_reply)
|
||||||
|
|
||||||
def test__set_group_fails_no_group(self):
|
def test__set_group_fails_no_group(self):
|
||||||
setattr(self.rest_mock, '_set_group',
|
setattr(self.rest_mock, '_set_group',
|
||||||
lambda *_: False)
|
lambda *_: False)
|
||||||
self.stubs.Set(CoraidRESTClient, '_esm',
|
self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
|
||||||
lambda *_: fake_login_reply_group_fail)
|
lambda *_: fake_login_reply_group_fail)
|
||||||
self.assertRaises(CoraidESMException,
|
self.assertRaises(CoraidESMException,
|
||||||
self.drv._set_group,
|
self.drv._set_group,
|
||||||
|
@ -199,14 +199,14 @@ class TestCoraidRESTClient(test.TestCase):
|
||||||
def test__configure(self):
|
def test__configure(self):
|
||||||
setattr(self.rest_mock, '_configure',
|
setattr(self.rest_mock, '_configure',
|
||||||
lambda *_: True)
|
lambda *_: True)
|
||||||
self.stubs.Set(CoraidRESTClient, '_esm',
|
self.stubs.Set(CoraidRESTClient, '_esm_cmd',
|
||||||
lambda *_: fake_esm_success)
|
lambda *_: fake_esm_success)
|
||||||
self.drv._configure(fake_configure_data)
|
self.drv._configure(fake_configure_data)
|
||||||
|
|
||||||
def test__get_volume_info(self):
|
def test__get_volume_info(self):
|
||||||
setattr(self.rest_mock, '_get_volume_info',
|
setattr(self.rest_mock, '_get_volume_info',
|
||||||
lambda *_: fake_volume_info)
|
lambda *_: fake_volume_info)
|
||||||
self.stubs.Set(CoraidRESTClient, '_esm',
|
self.stubs.Set(CoraidRESTClient, '_esm_cmd',
|
||||||
lambda *_: fake_esm_fetch)
|
lambda *_: fake_esm_fetch)
|
||||||
self.drv._get_volume_info(fake_volume_name)
|
self.drv._get_volume_info(fake_volume_name)
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ class CoraidRESTClient(object):
|
||||||
url = ('admin?op=login&username=%s&password=%s' %
|
url = ('admin?op=login&username=%s&password=%s' %
|
||||||
(self.user, self.password))
|
(self.user, self.password))
|
||||||
data = 'Login'
|
data = 'Login'
|
||||||
reply = self._esm(url, data)
|
reply = self._admin_esm_cmd(url, data)
|
||||||
if reply.get('state') == 'adminSucceed':
|
if reply.get('state') == 'adminSucceed':
|
||||||
self.session = time.time() + 1100
|
self.session = time.time() + 1100
|
||||||
msg = _('Update session cookie %(session)s')
|
msg = _('Update session cookie %(session)s')
|
||||||
|
@ -116,7 +116,7 @@ class CoraidRESTClient(object):
|
||||||
if groupId:
|
if groupId:
|
||||||
url = ('admin?op=setRbacGroup&groupId=%s' % (groupId))
|
url = ('admin?op=setRbacGroup&groupId=%s' % (groupId))
|
||||||
data = 'Group'
|
data = 'Group'
|
||||||
reply = self._esm(url, data)
|
reply = self._admin_esm_cmd(url, data)
|
||||||
if reply.get('state') == 'adminSucceed':
|
if reply.get('state') == 'adminSucceed':
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -139,10 +139,14 @@ class CoraidRESTClient(object):
|
||||||
return kid['groupId']
|
return kid['groupId']
|
||||||
return False
|
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.
|
_admin_esm_cmd represent the entry point to send requests to ESM
|
||||||
Send the HTTPS call, get response in JSON
|
Appliance. Send the HTTPS call, get response in JSON
|
||||||
convert response into Python Object and return it.
|
convert response into Python Object and return it.
|
||||||
"""
|
"""
|
||||||
if url:
|
if url:
|
||||||
|
@ -166,10 +170,9 @@ class CoraidRESTClient(object):
|
||||||
|
|
||||||
def _configure(self, data):
|
def _configure(self, data):
|
||||||
"""In charge of all commands into 'configure'."""
|
"""In charge of all commands into 'configure'."""
|
||||||
self._login()
|
|
||||||
url = 'configure'
|
url = 'configure'
|
||||||
LOG.debug(_('Configure data : %s'), data)
|
LOG.debug(_('Configure data : %s'), data)
|
||||||
response = self._esm(url, data)
|
response = self._esm_cmd(url, data)
|
||||||
LOG.debug(_("Configure response : %s"), response)
|
LOG.debug(_("Configure response : %s"), response)
|
||||||
if response:
|
if response:
|
||||||
if response.get('configState') == 'completedSuccessfully':
|
if response.get('configState') == 'completedSuccessfully':
|
||||||
|
@ -184,7 +187,7 @@ class CoraidRESTClient(object):
|
||||||
"""Retrive volume informations for a given volume name."""
|
"""Retrive volume informations for a given volume name."""
|
||||||
url = 'fetch?shelf=cms&orchStrRepo&lv=%s' % (volume_name)
|
url = 'fetch?shelf=cms&orchStrRepo&lv=%s' % (volume_name)
|
||||||
try:
|
try:
|
||||||
response = self._esm(url)
|
response = self._esm_cmd(url)
|
||||||
info = response[0][1]['reply'][0]
|
info = response[0][1]['reply'][0]
|
||||||
return {"pool": info['lv']['containingPool'],
|
return {"pool": info['lv']['containingPool'],
|
||||||
"repo": info['repoName'],
|
"repo": info['repoName'],
|
||||||
|
|
Loading…
Reference in New Issue