From b3dcd0334237eaeaf7517199301065041c28ecc7 Mon Sep 17 00:00:00 2001 From: Shay Halsband Date: Thu, 28 Jan 2016 11:45:35 +0200 Subject: [PATCH] Fix XtremIO multi cluster support * By default all client4 calls are routed to API V2 * renamed request_typ to a clearer parameter name "method" liberty-backport-potential Change-Id: I2d4a0cb7caeec5377e623ae4e431cfb57d5a1fce Closes-Bug: #1538984 --- cinder/tests/unit/test_emc_xtremio.py | 30 ++++++++++++++++----------- cinder/volume/drivers/emc/xtremio.py | 17 +++++++++------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/cinder/tests/unit/test_emc_xtremio.py b/cinder/tests/unit/test_emc_xtremio.py index d0c17856c..e1d054954 100644 --- a/cinder/tests/unit/test_emc_xtremio.py +++ b/cinder/tests/unit/test_emc_xtremio.py @@ -124,7 +124,7 @@ def get_obj(typ, name, idx): return {"content": xms_data[typ][idx]} -def xms_request(object_type='volumes', request_typ='GET', data=None, +def xms_request(object_type='volumes', method='GET', data=None, name=None, idx=None, ver='v1'): if object_type == 'snapshots': object_type = 'volumes' @@ -133,7 +133,7 @@ def xms_request(object_type='volumes', request_typ='GET', data=None, res = xms_data[object_type] except KeyError: raise exception.VolumeDriverException - if request_typ == 'GET': + if method == 'GET': if name or idx: return get_obj(object_type, name, idx) else: @@ -144,7 +144,7 @@ def xms_request(object_type='volumes', request_typ='GET', data=None, obj['index']), "name": obj.get('name')} for obj in res.values()]} - elif request_typ == 'POST': + elif method == 'POST': data = fix_data(data, object_type) name_key = get_xms_obj_key(data) try: @@ -164,7 +164,7 @@ def xms_request(object_type='volumes', request_typ='GET', data=None, return {"links": [{"href": "/%s/%d" % (object_type, data[typ2id[object_type]][2])}]} - elif request_typ == 'DELETE': + elif method == 'DELETE': if object_type == 'consistency-group-volumes': data = [cgv for cgv in xms_data['consistency-group-volumes'].values() @@ -176,34 +176,34 @@ def xms_request(object_type='volumes', request_typ='GET', data=None, del xms_data[object_type][data['index']] else: raise exception.NotFound() - elif request_typ == 'PUT': + elif method == 'PUT': obj = get_obj(object_type, name, idx)['content'] data = fix_data(data, object_type) del data['index'] obj.update(data) -def xms_bad_request(object_type='volumes', request_typ='GET', data=None, +def xms_bad_request(object_type='volumes', method='GET', data=None, name=None, idx=None, ver='v1'): - if request_typ == 'GET': + if method == 'GET': raise exception.NotFound() - elif request_typ == 'POST': + elif method == 'POST': raise exception.VolumeBackendAPIException('Failed to create ig') def xms_failed_rename_snapshot_request(object_type='volumes', - request_typ='GET', data=None, + method='GET', data=None, name=None, idx=None, ver='v1'): - if request_typ == 'POST': + if method == 'POST': xms_data['volumes'][27] = {} return { "links": [ { "href": "https://host/api/json/v2/types/snapshots/27", "rel": "self"}]} - elif request_typ == 'PUT': + elif method == 'PUT': raise exception.VolumeBackendAPIException(data='Failed to delete') - elif request_typ == 'DELETE': + elif method == 'DELETE': del xms_data['volumes'][27] @@ -320,6 +320,12 @@ class EMCXIODriverISCSITestCase(test.TestCase): xms_data['clusters'] = clusters self.driver.check_for_setup_error() + def test_client4_uses_v2(self, req): + def base_req(*args, **kwargs): + self.assertIn('v2', args) + req.side_effect = base_req + self.driver.client.req('volumes') + def test_create_extend_delete_volume(self, req): req.side_effect = xms_request self.driver.create_volume(self.data.test_volume) diff --git a/cinder/volume/drivers/emc/xtremio.py b/cinder/volume/drivers/emc/xtremio.py index d46473315..7cfbb42ba 100644 --- a/cinder/volume/drivers/emc/xtremio.py +++ b/cinder/volume/drivers/emc/xtremio.py @@ -104,7 +104,7 @@ class XtremIOClient(object): @utils.retry(exception.XtremIOArrayBusy, CONF.xtremio_array_busy_retry_count, CONF.xtremio_array_busy_retry_interval, 1) - def req(self, object_type='volumes', request_typ='GET', data=None, + def req(self, object_type='volumes', method='GET', data=None, name=None, idx=None, ver='v1'): if not data: data = {} @@ -122,15 +122,15 @@ class XtremIOClient(object): elif idx: url = '%s/%d' % (url, idx) key = str(idx) - if request_typ in ('GET', 'DELETE'): + if method in ('GET', 'DELETE'): params.update(data) self.update_url(params, self.cluster_id) - if request_typ != 'GET': + if method != 'GET': self.update_data(data, self.cluster_id) LOG.debug('data: %s', data) - LOG.debug('%(type)s %(url)s', {'type': request_typ, 'url': url}) + LOG.debug('%(type)s %(url)s', {'type': method, 'url': url}) try: - response = requests.request(request_typ, url, params=params, + response = requests.request(method, url, params=params, data=json.dumps(data), verify=self.verify, auth=(self.configuration.san_login, @@ -140,7 +140,7 @@ class XtremIOClient(object): raise exception.VolumeDriverException(message=msg) if 200 <= response.status_code < 300: - if request_typ in ('GET', 'POST'): + if method in ('GET', 'POST'): return response.json() else: return '' @@ -279,6 +279,11 @@ class XtremIOClient4(XtremIOClient): super(XtremIOClient4, self).__init__(configuration, cluster_id) self._cluster_name = None + def req(self, object_type='volumes', method='GET', data=None, + name=None, idx=None, ver='v2'): + return super(XtremIOClient4, self).req(object_type, method, data, + name, idx, ver) + def get_extra_capabilities(self): return {'consistencygroup_support': True} -- 2.45.2