OpenStack Block Storage (Cinder)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

3347 lines
149 KiB

#
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import re
import six
from ddt import data
from ddt import ddt
from ddt import file_data
from ddt import unpack
import mock
from oslo_utils import timeutils
from oslo_utils import units
from cinder import context
from cinder import exception
from cinder.objects import fields
from cinder import test
from cinder.tests.unit.api import fakes
from cinder.tests.unit import fake_group_snapshot
from cinder.tests.unit import fake_snapshot
from cinder.tests.unit import fake_volume
from cinder.tests.unit.image import fake as fake_image
from cinder.tests.unit import utils as test_utils
from cinder.volume import configuration as conf
from cinder.volume.drivers import solidfire
from cinder.volume import qos_specs
from cinder.volume import volume_types
class mock_vref(object):
def __init__(self):
self._name_id = None
self.admin_metadata = {}
self.attach_status = 'detached'
self.id = '262b9ce2-a71a-4fbe-830c-c20c5596caea'
self.project_id = '52423d9394ad4c67b3b9034da58cedbc'
self.provider_id = '5 4 6ecebf5d-5521-4ce1-80f3-358ebc1b9cdc'
self.size = 20
def __setitem__(self, item, value):
self.__dict__[item] = value
def __getitem__(self, item):
return self.__dict__[item]
def get(self, item, arg2 = None):
return self.__dict__[item]
f_uuid = ['262b9ce2-a71a-4fbe-830c-c20c5596caea',
'362b9ce2-a71a-4fbe-830c-c20c5596caea']
@ddt
class SolidFireVolumeTestCase(test.TestCase):
EXPECTED_QOS = {'minIOPS': 110, 'burstIOPS': 1530, 'maxIOPS': 1020}
def setUp(self):
self.ctxt = context.get_admin_context()
self.configuration = conf.BackendGroupConfiguration(
[], conf.SHARED_CONF_GROUP)
self.configuration.sf_allow_tenant_qos = True
self.configuration.san_is_local = True
self.configuration.sf_emulate_512 = True
self.configuration.sf_account_prefix = 'cinder'
self.configuration.reserved_percentage = 25
self.configuration.target_helper = None
self.configuration.sf_template_account_name = 'openstack-vtemplate'
self.configuration.sf_allow_template_caching = False
self.configuration.sf_svip = None
self.configuration.sf_volume_prefix = 'UUID-'
self.configuration.sf_enable_vag = False
self.configuration.replication_device = []
self.configuration.max_over_subscription_ratio = 2
super(SolidFireVolumeTestCase, self).setUp()
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
self.mock_object(solidfire.SolidFireDriver,
'_get_provisioned_capacity_iops',
return_value=(0, 0))
self.expected_qos_results = {'minIOPS': 1000,
'maxIOPS': 10000,
'burstIOPS': 20000}
self.mock_stats_data =\
{'result':
{'clusterCapacity': {'maxProvisionedSpace': 107374182400,
'usedSpace': 1073741824,
'compressionPercent': 100,
'deDuplicationPercent': 100,
'thinProvisioningPercent': 100}}}
vol_updates = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': 'fast',
'created_at': timeutils.utcnow(),
'attributes':
{'uuid': '262b9ce2-a71a-4fbe-830c-c20c5596caea'}}
ctx = context.get_admin_context()
self.mock_volume = fake_volume.fake_volume_obj(ctx, **vol_updates)
self.fake_image_meta = {'id': '17c550bb-a411-44c0-9aaf-0d96dd47f501',
'updated_at': datetime.datetime(2013, 9,
28, 15,
27, 36,
325355),
'is_public': True,
'owner': 'testprjid'}
self.fake_image_service = fake_image.FakeImageService()
self.vol = test_utils.create_volume(
self.ctxt, volume_id='b831c4d1-d1f0-11e1-9b23-0800200c9a66')
self.snap = test_utils.create_snapshot(
self.ctxt, volume_id=self.vol.id)
self.fake_sfaccount = {'accountID': 25,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid',
'volumes': [6, 7, 20]}
self.fake_sfvol = {'volumeID': 6,
'name': 'test_volume',
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {'uuid': f_uuid[0]},
'qos': None,
'iqn': 'super_fake_iqn'}
self.cluster_pairs = (
[{'uniqueID': 'lu9f',
'endpoint': {'passwd': 'admin', 'port': 443,
'url': 'https://192.168.139.102:443',
'svip': '10.10.8.134',
'mvip': '192.168.139.102',
'login': 'admin'},
'name': 'AutoTest2-6AjG-FOR-TEST-ONLY',
'clusterPairID': 33,
'clusterAPIVersion': '9.4',
'uuid': '9c499d4b-8fff-48b4-b875-27601d5d9889',
'svip': '10.10.23.2',
'mvipNodeID': 1,
'repCount': 1,
'encryptionAtRestState': 'disabled',
'attributes': {},
'mvip': '192.168.139.102',
'ensemble': ['10.10.5.130'],
'svipNodeID': 1}])
self.mvip = '192.168.139.102'
self.svip = '10.10.8.134'
self.fake_sfsnap_name = '%s%s' % (self.configuration.sf_volume_prefix,
self.snap.id)
self.fake_sfsnaps = [{'snapshotID': '5',
'name': self.fake_sfsnap_name,
'volumeID': 6}]
def fake_issue_api_request(self, method, params, version='1.0',
endpoint=None, timeout=None):
if method == 'GetClusterCapacity':
data = {}
if version == '1.0':
data = {'result': {'clusterCapacity': {
'maxProvisionedSpace': 107374182400,
'usedSpace': 1073741824,
'compressionPercent': 100,
'deDuplicationPercent': 100,
'thinProvisioningPercent': 100,
'maxUsedSpace': 53687091200}}}
elif version == '8.0':
data = {'result': {'clusterCapacity': {
'usedMetadataSpaceInSnapshots': 16476454912,
'maxUsedMetadataSpace': 432103337164,
'activeBlockSpace': 616690857535,
'uniqueBlocksUsedSpace': 628629229316,
'totalOps': 7092186135,
'peakActiveSessions': 0,
'uniqueBlocks': 519489473,
'maxOverProvisionableSpace': 276546135777280,
'zeroBlocks': 8719571984,
'provisionedSpace': 19938551005184,
'maxUsedSpace': 8402009333760,
'peakIOPS': 0,
'timestamp': '2019-04-24T12:08:22Z',
'currentIOPS': 0,
'usedSpace': 628629229316,
'activeSessions': 0,
'nonZeroBlocks': 1016048624,
'maxProvisionedSpace': 55309227155456,
'usedMetadataSpace': 16476946432,
'averageIOPS': 0,
'snapshotNonZeroBlocks': 1606,
'maxIOPS': 200000,
'clusterRecentIOSize': 0}}}
return data
elif method is 'GetClusterInfo':
results = {
'result':
{'clusterInfo':
{'name': 'fake-cluster',
'mvip': '1.1.1.1',
'svip': '1.1.1.1',
'uniqueID': 'unqid',
'repCount': 2,
'uuid': '53c8be1e-89e2-4f7f-a2e3-7cb84c47e0ec',
'attributes': {}}}}
return results
elif method is 'GetClusterVersionInfo':
return {'id': None, 'result': {'softwareVersionInfo':
{'pendingVersion': '8.2.1.4',
'packageName': '',
'currentVersion': '8.2.1.4',
'nodeID': 0, 'startTime': ''},
'clusterVersion': '8.2.1.4',
'clusterAPIVersion': '8.2'}}
elif method is 'AddAccount' and version == '1.0':
return {'result': {'accountID': 25}, 'id': 1}
elif method is 'GetAccountByName' and version == '1.0':
results = {'result': {'account':
{'accountID': 25,
'username': params['username'],
'status': 'active',
'initiatorSecret': '123456789012',
'targetSecret': '123456789012',
'attributes': {},
'volumes': [6, 7, 20]}},
"id": 1}
return results
elif method is 'CreateVolume' and version == '1.0':
return {'result': {'volumeID': 5}, 'id': 1}
elif method is 'CreateSnapshot' and version == '6.0':
return {'result': {'snapshotID': 5}, 'id': 1}
elif method is 'DeleteVolume' and version == '1.0':
return {'result': {}, 'id': 1}
elif method is 'ModifyVolume' and version == '5.0':
return {'result': {}, 'id': 1}
elif method is 'CloneVolume':
return {'result': {'volumeID': 6}, 'id': 2}
elif method is 'ModifyVolume':
return {'result': {}, 'id': 1}
elif method is 'ListVolumesForAccount' and version == '1.0':
test_name = 'OS-VOLID-a720b3c0-d1f0-11e1-9b23-0800200c9a66'
result = {'result': {
'volumes': [{'volumeID': 5,
'name': test_name,
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {'uuid': f_uuid[0]},
'qos': None,
'iqn': test_name}]}}
return result
elif method is 'ListActiveVolumes':
test_name = "existing_volume"
result = {'result': {
'volumes': [{'volumeID': 5,
'name': test_name,
'accountID': 8,
'sliceCount': 1,
'totalSize': int(1.75 * units.Gi),
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {},
'qos': None,
'iqn': test_name}]}}
return result
elif method is 'ListVolumes':
test_name = "get_sfvol_by_cinder"
result = {'result': {
'volumes': [{'volumeID': 5,
'name': test_name,
'accountID': 8,
'sliceCount': 1,
'totalSize': int(1.75 * units.Gi),
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {'uuid': f_uuid[0]},
'qos': None,
'iqn': test_name},
{'volumeID': 15,
'name': test_name,
'accountID': 8,
'sliceCount': 1,
'totalSize': int(1.75 * units.Gi),
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {'uuid': f_uuid[1]},
'qos': None,
'iqn': test_name}]}}
if params and params['startVolumeID']:
volumes = result['result']['volumes']
selected_volumes = [v for v in volumes if v.get('volumeID')
!= params['startVolumeID']]
result['result']['volumes'] = selected_volumes
return result
elif method is 'DeleteSnapshot':
return {'result': {}}
elif method is 'GetClusterVersionInfo':
return {'result': {'clusterAPIVersion': '8.0'}}
elif method is 'StartVolumePairing':
return {'result': {'volumePairingKey': 'fake-pairing-key'}}
elif method is 'RollbackToSnapshot':
return {
"id": 1,
"result": {
"checksum": "0x0",
"snapshot": {
"attributes": {},
"checksum": "0x0",
"createTime": "2016-04-04T17:27:32Z",
"enableRemoteReplication": "false",
"expirationReason": "None",
"expirationTime": "null",
"groupID": 0,
"groupSnapshotUUID": f_uuid[0],
"name": "test1-copy",
"snapshotID": 1,
"snapshotUUID": f_uuid[1],
"status": "done",
"totalSize": 5000658944,
"virtualVolumeID": "null",
"volumeID": 1
},
"snapshotID": 1
}
}
elif method is 'ListAccounts':
return {
'result': {
'accounts': [{
'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'
}]
}
}
elif method == 'ListSnapshots':
raise exception.VolumeNotFound('test clone unconfigured image')
else:
# Crap, unimplemented API call in Fake
return None
def fake_issue_api_request_fails(self, method,
params, version='1.0',
endpoint=None):
response = {'error': {'code': 000,
'name': 'DummyError',
'message': 'This is a fake error response'},
'id': 1}
msg = ('Error (%s) encountered during '
'SolidFire API call.' % response['error']['name'])
raise solidfire.SolidFireAPIException(message=msg)
def fake_set_qos_by_volume_type(self, type_id, ctxt):
return {'minIOPS': 500,
'maxIOPS': 1000,
'burstIOPS': 1000}
def fake_volume_get(self, key, default=None):
return {'qos': 'fast'}
def fake_update_cluster_status(self):
return
def fake_get_cluster_version_info(self):
return
def fake_get_model_info(self, account, vid, endpoint=None):
return {'fake': 'fake-model'}
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
def test_create_volume_with_qos_type(self,
_mock_issue_api_request):
_mock_issue_api_request.side_effect = self.fake_issue_api_request
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': 'fast',
'created_at': timeutils.utcnow()}
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
test_type = {'name': 'sf-1',
'qos_specs_id': 'fb0576d7-b4b5-4cad-85dc-ca92e6a497d1',
'deleted': False,
'created_at': '2014-02-06 04:58:11',
'updated_at': None,
'extra_specs': {},
'deleted_at': None,
'id': 'e730e97b-bc7d-4af3-934a-32e59b218e81'}
test_qos_spec = {'id': 'asdfafdasdf',
'specs': {'minIOPS': '1000',
'maxIOPS': '2000',
'burstIOPS': '3000'}}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **testvol)
def _fake_get_volume_type(ctxt, type_id):
return test_type
def _fake_get_qos_spec(ctxt, spec_id):
return test_qos_spec
def _fake_do_volume_create(account, params):
params['provider_location'] = '1.1.1.1 iqn 0'
return params
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_account_create_availability',
return_value=fake_sfaccounts[0]), \
mock.patch.object(sfv,
'_do_volume_create',
side_effect=_fake_do_volume_create), \
mock.patch.object(volume_types,
'get_volume_type',
side_effect=_fake_get_volume_type), \
mock.patch.object(qos_specs,
'get_qos_specs',
side_effect=_fake_get_qos_spec):
self.assertEqual({'burstIOPS': 3000,
'minIOPS': 1000,
'maxIOPS': 2000},
sfv.create_volume(testvol)['qos'])
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
def test_create_volume(self,
_mock_issue_api_request):
_mock_issue_api_request.side_effect = self.fake_issue_api_request
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'created_at': timeutils.utcnow()}
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **testvol)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_account_create_availability',
return_value=fake_sfaccounts[0]):
model_update = sfv.create_volume(testvol)
self.assertIsNotNone(model_update)
self.assertNotIn('provider_geometry', model_update)
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
def test_create_volume_non_512e(self,
_mock_issue_api_request):
_mock_issue_api_request.side_effect = self.fake_issue_api_request
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'created_at': timeutils.utcnow()}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **testvol)
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_issue_api_request',
side_effect=self.fake_issue_api_request), \
mock.patch.object(sfv,
'_get_account_create_availability',
return_value=fake_sfaccounts[0]):
self.configuration.sf_emulate_512 = False
model_update = sfv.create_volume(testvol)
self.configuration.sf_emulate_512 = True
self.assertEqual('4096 4096',
model_update.get('provider_geometry', None))
def test_create_delete_snapshot(self):
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx)
testsnap_dict = {'project_id': 'testprjid',
'name': testvol.name,
'volume_size': testvol.size,
'id': 'b831c4d1-d1f0-11e1-9b23-0800200c9a66',
'volume_id': testvol.id,
'volume_type_id': None,
'created_at': timeutils.utcnow(),
'provider_id': '8 99 None',
'volume': testvol}
testsnap = fake_snapshot.fake_snapshot_obj(ctx, **testsnap_dict)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
fake_uuid = 'UUID-b831c4d1-d1f0-11e1-9b23-0800200c9a66'
with mock.patch.object(
solidfire.SolidFireDriver,
'_get_sf_snapshots',
return_value=[{'snapshotID': '5',
'name': fake_uuid,
'volumeID': 5}]), \
mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=[{'accountID': 5,
'username':
'prefix-testprjid'}]),\
mock.patch.object(sfv, '_retrieve_replication_settings',
return_value=["Async", {}]),\
mock.patch.object(sfv, '_get_sf_volume',
return_value={'volumeID': 33}):
sfv.create_snapshot(testsnap)
sfv.delete_snapshot(testsnap)
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
def test_create_clone(self,
_mock_issue_api_request):
_mock_issue_api_request.side_effect = self.fake_issue_api_request
_fake_get_snaps = [{'snapshotID': 5, 'name': 'testvol'}]
_fake_get_volume = (
{'volumeID': 99,
'name': 'UUID-a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'attributes': {}})
updates_vol_a = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'created_at': timeutils.utcnow()}
updates_vol_b = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'b831c4d1-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'created_at': timeutils.utcnow()}
fake_model_info = {
'provider_id': '%s %s cluster-id-01' % (
self.fake_sfvol['volumeID'],
self.fake_sfaccount['accountID'])
}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **updates_vol_a)
testvol_b = fake_volume.fake_volume_obj(ctx, **updates_vol_b)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sf_snapshots',
return_value=_fake_get_snaps), \
mock.patch.object(sfv,
'_get_sf_volume',
return_value=_fake_get_volume), \
mock.patch.object(sfv,
'_issue_api_request',
side_effect=self.fake_issue_api_request), \
mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=[]), \
mock.patch.object(sfv,
'_get_model_info',
return_value=fake_model_info):
sfv.create_cloned_volume(testvol_b, testvol)
def test_initialize_connector_with_blocksizes(self):
connector = {'initiator': 'iqn.2012-07.org.fake:01'}
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'provider_location': '10.10.7.1:3260 iqn.2010-01.com.'
'solidfire:87hg.uuid-2cc06226-cc'
'74-4cb7-bd55-14aed659a0cc.4060 0',
'provider_auth': 'CHAP stack-1-a60e2611875f40199931f2'
'c76370d66b 2FE0CQ8J196R',
'provider_geometry': '4096 4096',
'created_at': timeutils.utcnow(),
}
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
properties = sfv.initialize_connection(testvol, connector)
self.assertEqual('4096', properties['data']['physical_block_size'])
self.assertEqual('4096', properties['data']['logical_block_size'])
self.assertTrue(properties['data']['discard'])
def test_create_volume_fails(self):
# NOTE(JDG) This test just fakes update_cluster_status
# this is inentional for this test
self.mock_object(solidfire.SolidFireDriver,
'_update_cluster_status',
self.fake_update_cluster_status)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request_fails)
try:
sfv.create_volume(testvol)
self.fail("Should have thrown Error")
except Exception:
pass
def test_create_sfaccount(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
account = sfv._create_sfaccount('some-name')
self.assertIsNotNone(account)
def test_create_sfaccount_fails(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request_fails)
self.assertRaises(solidfire.SolidFireAPIException,
sfv._create_sfaccount, 'project-id')
def test_get_sfaccounts_for_tenant(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
accounts = sfv._get_sfaccounts_for_tenant('some-name')
self.assertIsNotNone(accounts)
def test_get_sfaccounts_for_tenant_fails(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request_fails)
self.assertRaises(solidfire.SolidFireAPIException,
sfv._get_sfaccounts_for_tenant, 'some-name')
def test_get_sfaccount_by_name(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
account = sfv._get_sfaccount_by_name('some-name')
self.assertIsNotNone(account)
def test_get_account_create_availability_no_account(self):
fake_sfaccounts = []
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfaccount = sfv._get_account_create_availability(fake_sfaccounts)
self.assertIsNone(sfaccount)
def test_get_account_create_availability(self):
fake_sfaccounts = [{'accountID': 29,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid',
'volumes': [6, 7, 20]}]
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfaccount = sfv._get_account_create_availability(fake_sfaccounts)
self.assertIsNotNone(sfaccount)
self.assertEqual(sfaccount['accountID'],
fake_sfaccounts[0]['accountID'])
def test_get_account_create_availability_primary_full(self):
fake_sfaccounts = [{'accountID': 30,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
get_sfaccount_result = {'accountID': 31,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid_'}
get_vol_result = list(range(1, 2001))
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_volumes_for_account',
return_value=get_vol_result):
sfaccount = sfv._get_account_create_availability(fake_sfaccounts)
self.assertIsNotNone(sfaccount)
self.assertEqual(sfaccount['username'],
get_sfaccount_result['username'])
def test_get_account_create_availability_both_full(self):
fake_sfaccounts = [{'accountID': 32,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'},
{'accountID': 33,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid_'}]
get_vol_result = list(range(1, 2001))
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_volumes_for_account',
return_value=get_vol_result):
sfaccount = sfv._get_account_create_availability(fake_sfaccounts)
self.assertIsNone(sfaccount)
def test_get_create_account(self):
fake_sfaccounts = [{'accountID': 34,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'},
{'accountID': 35,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid_'}]
get_vol_result = list(range(1, 2001))
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_volumes_for_account',
return_value=get_vol_result):
sfaccount = sfv._get_account_create_availability(fake_sfaccounts)
self.assertRaises(solidfire.SolidFireDriverException,
sfv._get_create_account, sfaccount)
def test_get_sfaccount_by_name_fails(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request_fails)
self.assertRaises(solidfire.SolidFireAPIException,
sfv._get_sfaccount_by_name, 'some-name')
def test_get_sfvol_by_cinder_vref_no_provider_id(self):
fake_sfaccounts = [{'accountID': 25,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid',
'volumes': [6, 7, 20]}]
self.mock_vref = mock_vref()
vol_result = {'volumeID': 5,
'name': 'test_volume',
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {'uuid': f_uuid[0]},
'qos': None,
'iqn': 'super_fake_iqn'}
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value = fake_sfaccounts), \
mock.patch.object(sfv, '_issue_api_request',
side_effect = self.fake_issue_api_request):
self.mock_vref['provider_id'] = None
sfvol = sfv._get_sfvol_by_cinder_vref(self.mock_vref)
self.assertIsNotNone(sfvol)
self.assertEqual(sfvol['attributes']['uuid'],
vol_result['attributes']['uuid'])
self.assertEqual(sfvol['volumeID'], vol_result['volumeID'])
def test_get_sfvol_by_cinder_vref_no_provider_id_nomatch(self):
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid',
'volumes': [5, 6, 7, 8]}]
self.mock_vref = mock_vref()
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value = fake_sfaccounts), \
mock.patch.object(sfv, '_issue_api_request',
side_effect = self.fake_issue_api_request):
self.mock_vref['provider_id'] = None
self.mock_vref['id'] = '142b9c32-a71A-4fbe-830c-c20c5596caea'
sfvol = sfv._get_sfvol_by_cinder_vref(self.mock_vref)
self.assertIsNone(sfvol)
def test_get_sfvol_by_cinder_vref_nomatch(self):
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid',
'volumes': [5, 6, 7, 8]}]
self.mock_vref = mock_vref()
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value = fake_sfaccounts), \
mock.patch.object(sfv, '_issue_api_request',
side_effect = self.fake_issue_api_request):
p_i = '324 8 6ecebf5d-5521-4ce1-80f3-358ebc1b9cdc'
self.mock_vref['provider_id'] = p_i
self.mock_vref['id'] = '142b9c32-a71A-4fbe-830c-c20c5596caea'
sfvol = sfv._get_sfvol_by_cinder_vref(self.mock_vref)
self.assertIsNone(sfvol)
def test_get_sfvol_by_cinder_vref(self):
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid',
'volumes': [5, 6, 7, 8]}]
self.mock_vref = mock_vref()
get_vol_result = {'volumeID': 5,
'name': 'test_volume',
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {'uuid': f_uuid[0]},
'qos': None,
'iqn': 'super_fake_iqn'}
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv, '_get_sfaccounts_for_tenant',
return_value = fake_sfaccounts), \
mock.patch.object(sfv, '_issue_api_request',
side_effect = self.fake_issue_api_request):
sfvol = sfv._get_sfvol_by_cinder_vref(self.mock_vref)
self.assertIsNotNone(sfvol)
self.assertEqual(get_vol_result['volumeID'], sfvol['volumeID'])
def test_delete_volume(self):
vol_id = 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'
testvol = test_utils.create_volume(
self.ctxt,
id=vol_id,
display_name='test_volume',
provider_id='1 5 None',
multiattach=False)
fake_sfaccounts = [{'accountID': 5,
'name': 'testprjid',
'targetSecret': 'shhhh',
'username': 'john-wayne'}]
get_vol_result = {'volumeID': 5,
'name': 'test_volume',
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {},
'qos': None,
'iqn': 'super_fake_iqn'}
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_sfvol_by_cinder_vref',
return_value=get_vol_result), \
mock.patch.object(sfv,
'_issue_api_request'), \
mock.patch.object(sfv,
'_remove_volume_from_vags') as rem_vol:
sfv.delete_volume(testvol)
rem_vol.not_called(get_vol_result['volumeID'])
def test_delete_multiattach_volume(self):
vol_id = 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'
testvol = test_utils.create_volume(
self.ctxt,
id=vol_id,
display_name='test_volume',
provider_id='1 5 None',
multiattach=True)
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
get_vol_result = {'volumeID': 5,
'name': 'test_volume',
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {},
'qos': None,
'iqn': 'super_fake_iqn'}
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_sfvol_by_cinder_vref',
return_value=get_vol_result), \
mock.patch.object(sfv,
'_issue_api_request'), \
mock.patch.object(sfv,
'_remove_volume_from_vags') as rem_vol:
sfv.delete_volume(testvol)
rem_vol.assert_called_with(get_vol_result['volumeID'])
def test_delete_volume_no_volume_on_backend(self):
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
fake_no_volumes = []
testvol = test_utils.create_volume(self.ctxt)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_volumes_for_account',
return_value=fake_no_volumes):
sfv.delete_volume(testvol)
def test_delete_snapshot_no_snapshot_on_backend(self):
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
fake_no_volumes = []
testvol = test_utils.create_volume(
self.ctxt,
volume_id='b831c4d1-d1f0-11e1-9b23-0800200c9a66')
testsnap = test_utils.create_snapshot(
self.ctxt,
volume_id=testvol.id)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_volumes_for_account',
return_value=fake_no_volumes):
sfv.delete_snapshot(testsnap)
def fake_ext_qos_issue_api_request(self, method, params, version='1.0',
endpoint=None):
EXPECTED_SIZE = 2 << 30 # 2147483648 size + increase
if method == 'ModifyVolume':
response = {'error': {'code': 0,
'name': 'Extend Volume',
'message': 'extend fail, size/scale-iops'},
'id': 1}
if params.get('totalSize', None) != EXPECTED_SIZE:
msg = ('Error (%s) encountered during '
'SolidFire API call.' % response['error']['name'])
raise solidfire.SolidFireAPIException(message=msg)
if params.get('qos', None) != SolidFireVolumeTestCase.EXPECTED_QOS:
msg = ('Error (%s) encountered during '
'SolidFire API call.' % response['error']['name'])
raise solidfire.SolidFireAPIException(message=msg)
return {'result': {}, 'id': 1}
elif method == 'GetAccountByName' and version == '1.0':
results = {'result': {'account':
{'accountID': 25,
'username': params['username'],
'status': 'active',
'initiatorSecret': '123456789012',
'targetSecret': '123456789012',
'attributes': {},
'volumes': [6, 7, 20]}},
"id": 1}
return results
elif method == 'ListVolumesForAccount' and version == '1.0':
test_name = 'OS-VOLID-a720b3c0-d1f0-11e1-9b23-0800200c9a66'
result = {'result': {
'volumes': [{'volumeID': 5,
'name': test_name,
'accountID': 25,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'attributes': {},
'qos': None,
'iqn': test_name}]}}
return result
else:
return None
def test_extend_volume(self):
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
testvol = {'project_id': 'testprjid',
'name': 'test_volume',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv.extend_volume(testvol, 2)
def test_extend_volume_with_scaled_qos(self):
size = 1
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
qos_ref = qos_specs.create(self.ctxt,
'qos-specs-1', {'minIOPS': '100',
'maxIOPS': '1000',
'burstIOPS': '1500',
'scaledIOPS': 'True',
'scaleMin': '10',
'scaleMax': '20',
'scaleBurst': '30'})
type_ref = volume_types.create(self.ctxt, "type1",
{'qos:minIOPS': '1000',
'qos:maxIOPS': '10000',
'qos:burstIOPS': '20000'})
qos_specs.associate_qos_with_type(self.ctxt,
qos_ref['id'],
type_ref['id'])
qos = sfv._set_qos_by_volume_type(self.ctxt, type_ref['id'], size + 1)
self.assertEqual(SolidFireVolumeTestCase.EXPECTED_QOS, qos)
def test_extend_volume_fails_no_volume(self):
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
testvol = {'project_id': 'testprjid',
'name': 'no-name',
'size': 1,
'id': 'not-found'}
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.assertRaises(exception.VolumeNotFound,
sfv.extend_volume,
testvol, 2)
def test_extend_volume_fails_account_lookup(self):
# NOTE(JDG) This test just fakes update_cluster_status
# this is intentional for this test
self.mock_object(solidfire.SolidFireDriver,
'_update_cluster_status',
self.fake_update_cluster_status)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
testvol = {'project_id': 'testprjid',
'name': 'no-name',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request_fails)
self.assertRaises(solidfire.SolidFireAPIException,
sfv.extend_volume,
testvol, 2)
@mock.patch.object(solidfire.SolidFireDriver, '_get_sfaccount')
@mock.patch.object(solidfire.SolidFireDriver, '_get_sf_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_retrieve_qos_setting')
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
@mock.patch.object(solidfire.SolidFireDriver,
'_retrieve_replication_settings')
@mock.patch.object(solidfire.SolidFireDriver, '_create_cluster_reference')
def test_extend_replicated_volume(self, mock_create_cluster_reference,
mock_retrieve_replication_settings,
mock_issue_api_request,
mock_retrieve_qos_setting,
mock_get_sf_volume,
mock_get_sfaccount):
mock_create_cluster_reference.return_value = {
'mvip': self.mvip,
'svip': self.svip}
mock_retrieve_replication_settings.return_value = "Async"
mock_retrieve_qos_setting.return_value = None
self.fake_sfvol['volumePairs'] = [{'remoteVolumeID': 26}]
mock_get_sf_volume.return_value = self.fake_sfvol
mock_get_sfaccount.return_value = self.fake_sfaccount
ctx = context.get_admin_context()
utc_now = timeutils.utcnow().isoformat()
vol_fields = {
'id': f_uuid,
'created_at': utc_now
}
vol = fake_volume.fake_volume_obj(ctx, **vol_fields)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv.replication_enabled = True
sfv.cluster_pairs = self.cluster_pairs
sfv.active_cluster['mvip'] = self.mvip
sfv.active_cluster['svip'] = self.svip
mock_issue_api_request.reset_mock()
# pylint: disable=assignment-from-no-return
updates = sfv.extend_volume(vol, vol.size + 10)
# pylint: enable=assignment-from-no-return
self.assertIsNone(updates)
modify_params = {
'volumeID': self.fake_sfvol['volumeID'],
'totalSize': int((vol.size + 10) * units.Gi),
'qos': None
}
modify_params2 = modify_params.copy()
modify_params2['volumeID'] = 26
expected_calls = [
mock.call("ModifyVolume", modify_params, version='5.0'),
mock.call("ModifyVolume", modify_params2, version='5.0',
endpoint=self.cluster_pairs[0]['endpoint'])
]
mock_issue_api_request.assert_has_calls(expected_calls)
mock_create_cluster_reference.assert_called()
mock_retrieve_replication_settings.assert_called_with(vol)
mock_retrieve_qos_setting.assert_called_with(vol, vol.size + 10)
mock_get_sf_volume.assert_called_with(
vol.id, {'accountID': self.fake_sfaccount['accountID']})
mock_get_sfaccount.assert_called_with(vol.project_id)
def test_set_by_qos_spec_with_scoping(self):
size = 1
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
qos_ref = qos_specs.create(self.ctxt,
'qos-specs-1', {'qos:minIOPS': '1000',
'qos:maxIOPS': '10000',
'qos:burstIOPS': '20000'})
type_ref = volume_types.create(self.ctxt,
"type1", {"qos:minIOPS": "100",
"qos:burstIOPS": "300",
"qos:maxIOPS": "200"})
qos_specs.associate_qos_with_type(self.ctxt,
qos_ref['id'],
type_ref['id'])
qos = sfv._set_qos_by_volume_type(self.ctxt, type_ref['id'], size)
self.assertEqual(self.expected_qos_results, qos)
def test_set_by_qos_spec(self):
size = 1
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
qos_ref = qos_specs.create(self.ctxt,
'qos-specs-1', {'minIOPS': '1000',
'maxIOPS': '10000',
'burstIOPS': '20000'})
type_ref = volume_types.create(self.ctxt,
"type1", {"qos:minIOPS": "100",
"qos:burstIOPS": "300",
"qos:maxIOPS": "200"})
qos_specs.associate_qos_with_type(self.ctxt,
qos_ref['id'],
type_ref['id'])
qos = sfv._set_qos_by_volume_type(self.ctxt, type_ref['id'], size)
self.assertEqual(self.expected_qos_results, qos)
@file_data("scaled_iops_test_data.json")
@unpack
def test_scaled_qos_spec_by_type(self, argument):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
size = argument[0].pop('size')
type_ref = volume_types.create(self.ctxt, "type1", argument[0])
qos = sfv._set_qos_by_volume_type(self.ctxt, type_ref['id'], size)
self.assertEqual(argument[1], qos)
@file_data("scaled_iops_invalid_data.json")
@unpack
def test_set_scaled_qos_by_type_invalid(self, inputs):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
size = inputs[0].pop('size')
type_ref = volume_types.create(self.ctxt, "type1", inputs[0])
self.assertRaises(exception.InvalidQoSSpecs,
sfv._set_qos_by_volume_type,
self.ctxt,
type_ref['id'],
size)
def test_accept_transfer(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
testvol = {'project_id': 'testprjid',
'name': 'test_volume',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
expected = {'provider_auth': 'CHAP cinder-new_project 123456789012'}
self.assertEqual(expected,
sfv.accept_transfer(self.ctxt,
testvol,
'new_user', 'new_project'))
def test_accept_transfer_volume_not_found_raises(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
testvol = {'project_id': 'testprjid',
'name': 'test_volume',
'size': 1,
'id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'created_at': timeutils.utcnow()}
self.assertRaises(exception.VolumeNotFound,
sfv.accept_transfer,
self.ctxt,
testvol,
'new_user',
'new_project')
def test_retype(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
type_ref = volume_types.create(self.ctxt,
"type1", {"qos:minIOPS": "500",
"qos:burstIOPS": "2000",
"qos:maxIOPS": "1000"})
diff = {'encryption': {}, 'qos_specs': {},
'extra_specs': {'qos:burstIOPS': ('10000', u'2000'),
'qos:minIOPS': ('1000', u'500'),
'qos:maxIOPS': ('10000', u'1000')}}
host = None
updates = {'project_id': 'testprjid',
'name': 'test_volume',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **updates)
migrated, updates = sfv.retype(self.ctxt, testvol, type_ref,
diff, host)
self.assertTrue(migrated)
self.assertEqual({}, updates)
@data(None, 'Success', 'Error', 'target:{}'.format(f_uuid[0]))
@mock.patch.object(solidfire.SolidFireDriver, '_get_sf_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_get_sfaccount')
def test_attach_volume(self, mig_status, mock_get_sfaccount,
mock_get_sf_volume):
mock_get_sfaccount.return_value = self.fake_sfaccount
i_uuid = 'fake_instance_uuid'
ctx = context.get_admin_context()
type_fields = {}
vol_type = fake_volume.fake_volume_type_obj(ctx, **type_fields)
utc_now = timeutils.utcnow().isoformat()
vol_fields = {
'id': f_uuid[0],
'created_at': utc_now,
'volume_type': vol_type,
'volume_type_id': vol_type.id,
'migration_status': mig_status,
}
vol = fake_volume.fake_volume_obj(ctx, **vol_fields)
sf_vol = self.fake_sfvol
mock_get_sf_volume.return_value = sf_vol
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv.attach_volume(ctx, vol, i_uuid, 'fake_host', '/dev/sdf')
self.assertEqual(sf_vol['attributes']['attached_to'],
i_uuid)
mock_get_sfaccount.assert_called()
mock_get_sf_volume.assert_called()
def test_retype_with_qos_spec(self):
test_type = {'name': 'sf-1',
'qos_specs_id': 'fb0576d7-b4b5-4cad-85dc-ca92e6a497d1',
'deleted': False,
'created_at': '2014-02-06 04:58:11',
'updated_at': None,
'extra_specs': {},
'deleted_at': None,
'id': 'e730e97b-bc7d-4af3-934a-32e59b218e81'}
test_qos_spec = {'id': 'asdfafdasdf',
'specs': {'minIOPS': '1000',
'maxIOPS': '2000',
'burstIOPS': '3000'}}
def _fake_get_volume_type(ctxt, type_id):
return test_type
def _fake_get_qos_spec(ctxt, spec_id):
return test_qos_spec
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
self.mock_object(volume_types, 'get_volume_type',
_fake_get_volume_type)
self.mock_object(qos_specs, 'get_qos_specs',
_fake_get_qos_spec)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
diff = {'encryption': {}, 'extra_specs': {},
'qos_specs': {'burstIOPS': ('10000', '2000'),
'minIOPS': ('1000', '500'),
'maxIOPS': ('10000', '1000')}}
host = None
updates = {'project_id': 'testprjid',
'name': 'test_volume',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **updates)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
migrated, updates = sfv.retype(self.ctxt, testvol, test_type,
diff, host)
self.assertTrue(migrated)
self.assertEqual({}, updates)
@mock.patch.object(solidfire.SolidFireDriver, '_get_sfaccount')
@mock.patch.object(solidfire.SolidFireDriver, '_get_sf_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_set_rep_by_volume_type')
@mock.patch.object(solidfire.SolidFireDriver,
'_retrieve_replication_settings')
@mock.patch.object(solidfire.SolidFireDriver, '_get_default_volume_params')
@mock.patch.object(solidfire.SolidFireDriver, '_replicate_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_disable_replication')
@mock.patch.object(solidfire.SolidFireDriver, '_set_qos_by_volume_type')
def test_retype_replicated(self,
mock_set_qos_by_volume_type,
mock_disable_replication,
mock_replicate_volume,
mock_get_default_volume_params,
mock_retrieve_replication_settings,
mock_set_rep_by_volume_type,
mock_get_sf_volume,
mock_get_sfaccount):
all_mocks = locals()
mock_get_sf_volume.return_value = None
mock_get_sfaccount.return_value = self.fake_sfaccount
mock_retrieve_replication_settings.return_value = 'Async'
ctx = context.get_admin_context()
type_fields = {'extra_specs': {'replication_enabled': '<is> True'},
'id': fakes.get_fake_uuid()}
src_vol_type = fake_volume.fake_volume_type_obj(ctx, **type_fields)
fake_provider_id = "%s %s %s" % (
self.fake_sfvol['volumeID'],
fakes.FAKE_UUID,
self.cluster_pairs[0]['uuid'])
utc_now = timeutils.utcnow().isoformat()
vol_fields = {
'id': fakes.FAKE_UUID,
'created_at': utc_now,
'volume_type': src_vol_type,
'volume_type_id': src_vol_type.id,
'provider_id': fake_provider_id
}
vol = fake_volume.fake_volume_obj(ctx, **vol_fields)
dst_vol_type = fake_volume.fake_volume_type_obj(ctx)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv.replication_enabled = True
sfv.cluster_pairs = self.cluster_pairs
sfv.active_cluster['mvip'] = self.mvip
sfv.active_cluster['svip'] = self.svip
self.assertRaises(exception.VolumeNotFound,
sfv.retype, ctx, vol, dst_vol_type, None, None)
mock_get_sfaccount.assert_called_once_with(vol.project_id)
mock_get_sf_volume.assert_called_once_with(
vol.id, {'accountID': self.fake_sfaccount['accountID']})
mock_get_sfaccount.reset_mock()
mock_get_sf_volume.reset_mock()
expected = {"key": "value"}
mock_get_sf_volume.return_value = self.fake_sfvol
mock_replicate_volume.return_value = expected
mock_set_rep_by_volume_type.side_effect = [src_vol_type, dst_vol_type]
retyped, updates = sfv.retype(ctx, vol, dst_vol_type, None, None)
self.assertDictEqual(expected, updates)
mock_get_sfaccount.assert_called_once_with(vol.project_id)
mock_get_sf_volume.assert_called_once_with(
vol.id, {'accountID': self.fake_sfaccount['accountID']})
mock_get_default_volume_params.assert_called()
mock_disable_replication.assert_not_called()
mock_replicate_volume.assert_called_once()
mock_retrieve_replication_settings.assert_called_once()
mock_set_qos_by_volume_type.assert_called_once()
expected = {}
for mk in all_mocks.values():
if isinstance(mk, mock.MagicMock):
mk.reset_mock()
mock_set_rep_by_volume_type.side_effect = [src_vol_type, None]
retyped, updates = sfv.retype(ctx, vol, dst_vol_type, None, None)
self.assertDictEqual(expected, updates)
mock_get_sfaccount.assert_called_once_with(vol.project_id)
mock_get_sf_volume.assert_called_once_with(
vol.id, {'accountID': self.fake_sfaccount['accountID']})
mock_get_default_volume_params.assert_not_called()
mock_disable_replication.assert_called_with(vol)
mock_replicate_volume.assert_not_called()
mock_retrieve_replication_settings.assert_not_called()
mock_set_qos_by_volume_type.assert_called_once()
def test_update_cluster_status(self):
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
driver_defined_stats = ['volume_backend_name', 'vendor_name',
'driver_version', 'storage_protocol',
'consistencygroup_support',
'consistent_group_snapshot_enabled',
'replication_enabled', 'active_cluster_mvip',
'reserved_percentage', 'QoS_support',
'multiattach', 'total_capacity_gb',
'free_capacity_gb', 'compression_percent',
'deduplicaton_percent',
'thin_provision_percent', 'provisioned_iops',
'current_iops', 'average_iops', 'max_iops',
'peak_iops']
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv._update_cluster_status()
for key in driver_defined_stats:
if sfv.cluster_stats.get(key, None) is None:
msg = 'Key %s should be present at driver stats.' % key
raise exception.CinderException(message=msg)
sfv.configuration.sf_provisioning_calc = 'usedSpace'
sfv._update_cluster_status()
driver_defined_stats += ['thin_provisioning_support',
'provisioned_capacity_gb',
'max_over_subscription_ratio']
for key in driver_defined_stats:
self.assertIn(key, driver_defined_stats)
def test_update_cluster_status_mvip_unreachable(self):
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=self.fake_issue_api_request_fails):
sfv._update_cluster_status()
self.assertEqual(0, sfv.cluster_stats['free_capacity_gb'])
self.assertEqual(0, sfv.cluster_stats['total_capacity_gb'])
def test_manage_existing_volume(self):
external_ref = {'name': 'existing volume', 'source-id': 5}
updates = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **updates)
self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request',
self.fake_issue_api_request)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
model_update = sfv.manage_existing(testvol, external_ref)
self.assertIsNotNone(model_update)
self.assertNotIn('provider_geometry', model_update)
def test_manage_existing_get_size(self):
external_ref = {'name': 'existing volume', 'source-id': 5}
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'created_at': timeutils.utcnow()}
mock_issue_api_request = self.mock_object(solidfire.SolidFireDriver,
'_issue_api_request')
mock_issue_api_request.side_effect = self.fake_issue_api_request
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
size = sfv.manage_existing_get_size(testvol, external_ref)
self.assertEqual(2, size)
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
@mock.patch.object(solidfire.SolidFireDriver, '_get_create_account')
@mock.patch.object(solidfire.SolidFireDriver, '_get_default_volume_params')
@mock.patch.object(solidfire.SolidFireDriver,
'_retrieve_replication_settings')
@mock.patch.object(solidfire.SolidFireDriver, '_replicate_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_get_model_info')
@mock.patch.object(solidfire.SolidFireDriver, '_update_cluster_status')
@mock.patch.object(solidfire.SolidFireDriver, '_create_cluster_reference')
def test_manage_existing_replicated_fail(
self,
mock_create_cluster_reference,
mock_update_cluster_status,
mock_get_model_info,
mock_replicate_volume,
mock_retrieve_replication_settings,
mock_get_default_volume_params,
mock_get_create_account,
mock_issue_api_request):
mock_retrieve_replication_settings.return_value = 'Async'
mock_get_default_volume_params.return_value = {'totalSize': 50}
mock_get_create_account.return_value = self.fake_sfaccount
mock_replicate_volume.side_effect = solidfire.SolidFireAPIException
ctx = context.get_admin_context()
type_fields = {'extra_specs': {'replication_enabled': '<is> True'},
'id': fakes.get_fake_uuid()}
vol_type = fake_volume.fake_volume_type_obj(ctx, **type_fields)
fake_provider_id = "%s %s %s" % (
self.fake_sfvol['volumeID'],
fakes.FAKE_UUID,
self.cluster_pairs[0]['uuid'])
utc_now = timeutils.utcnow().isoformat()
vol_fields = {
'id': fakes.FAKE_UUID,
'created_at': utc_now,
'volume_type': vol_type,
'volume_type_id': vol_type.id,
'provider_id': fake_provider_id
}
vol = fake_volume.fake_volume_obj(ctx, **vol_fields)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv.replication_enabled = True
sfv.active_cluster['mvip'] = self.mvip
sfv.active_cluster['svip'] = self.svip
external_ref = {}
self.assertRaises(solidfire.SolidFireAPIException,
sfv.manage_existing, vol, external_ref)
self.fake_sfvol['volumePairs'] = [{'remoteVolumeID': 26}]
mock_issue_api_request.return_value = {
'result': {'volumes': [self.fake_sfvol]}}
external_ref = {'source-id': 6, 'name': 'new-being-managed'}
self.assertRaises(solidfire.SolidFireDriverException,
sfv.manage_existing, vol, external_ref)
mock_get_default_volume_params.return_value = {'totalSize': 50}
self.fake_sfvol['volumePairs'] = []
mock_issue_api_request.return_value = {
'result': {'volumes': [self.fake_sfvol]}}
self.assertRaises(solidfire.SolidFireAPIException,
sfv.manage_existing, vol, external_ref)
modify_attributes = {'uuid': vol.id,
'is_clone': 'False',
'os_imported_at': utc_now + "+00:00",
'old_name': 'new-being-managed'}
modify_params1 = {'volumeID': self.fake_sfvol['volumeID'],
'attributes': modify_attributes}
modify_params2 = {'volumeID': self.fake_sfvol['volumeID'],
'attributes': self.fake_sfvol['attributes']}
calls = [mock.call('ListActiveVolumes',
{'startVolumeID': self.fake_sfvol['volumeID'],
'limit': 1}),
mock.call('ModifyVolume', modify_params1, version='5.0'),
mock.call('ModifyVolume', modify_params2, version='5.0')]
mock_issue_api_request.assert_has_calls(calls)
mock_get_model_info.assert_not_called()
mock_create_cluster_reference.assert_called_once()
mock_update_cluster_status.assert_called_once()
mock_replicate_volume.assert_called()
mock_retrieve_replication_settings.assert_called_with(vol)
mock_get_default_volume_params.assert_called_with(vol)
mock_get_create_account.assert_called_with(vol.project_id)
@mock.patch.object(solidfire.SolidFireDriver, '_get_sfaccount')
@mock.patch.object(solidfire.SolidFireDriver, '_get_sf_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_set_rep_by_volume_type')
@mock.patch.object(solidfire.SolidFireDriver,
'_retrieve_replication_settings')
@mock.patch.object(solidfire.SolidFireDriver, '_get_default_volume_params')
@mock.patch.object(solidfire.SolidFireDriver, '_replicate_volume')
@mock.patch.object(solidfire.SolidFireDriver, '_disable_replication')
@mock.patch.object(solidfire.SolidFireDriver, '_set_qos_by_volume_type')
def test_manage_existing_replicated(
self,
mock_set_qos_by_volume_type,
mock_disable_replication,
mock_replicate_volume,
mock_get_default_volume_params,
mock_retrieve_replication_settings,
mock_set_rep_by_volume_type,
mock_get_sf_volume,
mock_get_sfaccount):
mock_get_sf_volume.return_value = None
mock_get_sfaccount.return_value = self.fake_sfaccount
mock_retrieve_replication_settings.return_value = 'Async'
ctx = context.get_admin_context()
type_fields = {'extra_specs': {'replication_enabled': '<is> True'},
'id': fakes.get_fake_uuid()}
src_vol_type = fake_volume.fake_volume_type_obj(ctx, **type_fields)
fake_provider_id = "%s %s %s" % (
self.fake_sfvol['volumeID'],
fakes.FAKE_UUID,
self.cluster_pairs[0]['uuid'])
utc_now = timeutils.utcnow().isoformat()
vol_fields = {
'id': fakes.FAKE_UUID,
'created_at': utc_now,
'volume_type': src_vol_type,
'volume_type_id': src_vol_type.id,
'provider_id': fake_provider_id
}
vol = fake_volume.fake_volume_obj(ctx, **vol_fields)
dst_vol_type = fake_volume.fake_volume_type_obj(ctx)
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
sfv.replication_enabled = True
sfv.cluster_pairs = self.cluster_pairs
sfv.active_cluster['mvip'] = self.mvip
sfv.active_cluster['svip'] = self.svip
self.assertRaises(exception.VolumeNotFound,
sfv.retype, ctx, vol, dst_vol_type, None, None)
mock_get_sfaccount.assert_called_once_with(vol.project_id)
mock_get_sf_volume.assert_called_once_with(
vol.id, {'accountID': self.fake_sfaccount['accountID']})
mock_get_sfaccount.reset_mock()
mock_get_sf_volume.reset_mock()
expected = {"key": "value"}
mock_get_sf_volume.return_value = self.fake_sfvol
mock_replicate_volume.return_value = expected
mock_set_rep_by_volume_type.side_effect = [src_vol_type, dst_vol_type]
retyped, updates = sfv.retype(ctx, vol, dst_vol_type, None, None)
self.assertDictEqual(expected, updates)
mock_get_sfaccount.assert_called_once_with(vol.project_id)
mock_get_sf_volume.assert_called_once_with(
vol.id, {'accountID': self.fake_sfaccount['accountID']})
mock_get_default_volume_params.assert_called()
mock_disable_replication.assert_not_called()
mock_replicate_volume.assert_called_once()
mock_retrieve_replication_settings.assert_called_once()
mock_set_qos_by_volume_type.assert_called_once()
mock_set_rep_by_volume_type.assert_called()
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
def test_create_volume_for_migration(self,
_mock_issue_api_request):
_mock_issue_api_request.side_effect = self.fake_issue_api_request
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'b830b3c0-d1f0-11e1-9b23-1900200c9a77',
'volume_type_id': None,
'created_at': timeutils.utcnow(),
'migration_status': 'target:'
'a720b3c0-d1f0-11e1-9b23-0800200c9a66'}
ctx = context.get_admin_context()
testvol = fake_volume.fake_volume_obj(ctx, **testvol)
fake_sfaccounts = [{'accountID': 5,
'targetSecret': 'shhhh',
'username': 'prefix-testprjid'}]
def _fake_do_v_create(project_id, params):
cvol = {
'name': 'UUID-a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'attributes': {
'uuid': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'migration_uuid': 'b830b3c0-d1f0-11e1-9b23-1900200c9a77'
}
}
return cvol
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
with mock.patch.object(sfv,
'_get_sfaccounts_for_tenant',
return_value=fake_sfaccounts), \
mock.patch.object(sfv,
'_get_account_create_availability',
return_value=fake_sfaccounts[0]), \
mock.patch.object(sfv,
'_do_volume_create',
side_effect=_fake_do_v_create):
sf_vol_object = sfv.create_volume(testvol)
self.assertEqual('a720b3c0-d1f0-11e1-9b23-0800200c9a66',
sf_vol_object['attributes']['uuid'])
self.assertEqual('b830b3c0-d1f0-11e1-9b23-1900200c9a77',
sf_vol_object['attributes']['migration_uuid'])
self.assertEqual('UUID-a720b3c0-d1f0-11e1-9b23-0800200c9a66',
sf_vol_object['name'])
@mock.patch.object(solidfire.SolidFireDriver, '_issue_api_request')
def test_clone_image_not_configured(self, _mock_issue_api_request):
_mock_issue_api_request.side_effect = self.fake_issue_api_request
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
self.assertEqual((None, False),
sfv.clone_image(self.ctxt,
self.mock_volume,
'fake',
self.fake_image_meta,
'fake'))
def test_init_volume_mappings(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
vid_1 = 'c9125d6d-22ff-4cc3-974d-d4e350df9c91'
vid_2 = '79883868-6933-47a1-a362-edfbf8d55a18'
sid_1 = 'e3caa4fa-485e-45ca-970e-1d3e693a2520'
project_1 = 'e6fb073c-11f0-4f4c-897c-90e7c7c4bcf8'
project_2 = '4ff32607-305c-4a6b-a51a-0dd33124eecf'
vrefs = [{'id': vid_1,
'project_id': project_1,
'provider_id': None},
{'id': vid_2,
'project_id': project_2,
'provider_id': 22}]
snaprefs = [{'id': sid_1,
'project_id': project_1,
'provider_id': None,
'volume_id': vid_1}]
sf_vols = [{'volumeID': 99,
'name': 'UUID-' + vid_1,
'accountID': 100},
{'volumeID': 22,
'name': 'UUID-' + vid_2,
'accountID': 200}]
sf_snaps = [{'snapshotID': 1,
'name': 'UUID-' + sid_1,
'volumeID': 99}]
def _fake_issue_api_req(method, params, version=0):
if 'ListActiveVolumes' in method:
return {'result': {'volumes': sf_vols}}
if 'ListSnapshots'in method:
return {'result': {'snapshots': sf_snaps}}
with mock.patch.object(sfv, '_issue_api_request',
side_effect=_fake_issue_api_req):
volume_updates, snapshot_updates = sfv.update_provider_info(
vrefs, snaprefs)
self.assertEqual('99 100 53c8be1e-89e2-4f7f-a2e3-7cb84c47e0ec',
volume_updates[0]['provider_id'])
self.assertEqual(1, len(volume_updates))
self.assertEqual('1 99 53c8be1e-89e2-4f7f-a2e3-7cb84c47e0ec',
snapshot_updates[0]['provider_id'])
self.assertEqual(1, len(snapshot_updates))
def test_get_sf_volume_missing_attributes(self):
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
test_name = "existing_volume"
fake_response = {'result': {
'volumes': [{'volumeID': 5,
'name': test_name,
'accountID': 8,
'sliceCount': 1,
'totalSize': 1 * units.Gi,
'enable512e': True,
'access': "readWrite",
'status': "active",
'qos': None,
'iqn': test_name}]}}
def _fake_issue_api_req(method, params, version=0, endpoint=None):
return fake_response
with mock.patch.object(
sfv, '_issue_api_request', side_effect=_fake_issue_api_req):
self.assertEqual(5, sfv._get_sf_volume(test_name, 8)['volumeID'])
def test_sf_init_conn_with_vag(self):
# Verify with the _enable_vag conf set that we correctly create a VAG.
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'provider_location': '10.10.7.1:3260 iqn.2010-01.com.'
'solidfire:87hg.uuid-2cc06226-cc'
'74-4cb7-bd55-14aed659a0cc.4060 0',
'provider_auth': 'CHAP stack-1-a60e2611875f40199931f2'
'c76370d66b 2FE0CQ8J196R',
'provider_geometry': '4096 4096',
'created_at': timeutils.utcnow(),
'provider_id': "1 1 1"
}
connector = {'initiator': 'iqn.2012-07.org.fake:01'}
provider_id = testvol['provider_id']
vol_id = int(provider_id.split()[0])
vag_id = 1
with mock.patch.object(sfv,
'_safe_create_vag',
return_value=vag_id) as create_vag, \
mock.patch.object(sfv,
'_add_volume_to_vag') as add_vol:
sfv._sf_initialize_connection(testvol, connector)
create_vag.assert_called_with(connector['initiator'],
vol_id)
add_vol.assert_called_with(vol_id,
connector['initiator'],
vag_id)
def test_sf_term_conn_with_vag_rem_vag(self):
# Verify we correctly remove an empty VAG on detach.
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'provider_location': '10.10.7.1:3260 iqn.2010-01.com.'
'solidfire:87hg.uuid-2cc06226-cc'
'74-4cb7-bd55-14aed659a0cc.4060 0',
'provider_auth': 'CHAP stack-1-a60e2611875f40199931f2'
'c76370d66b 2FE0CQ8J196R',
'provider_geometry': '4096 4096',
'created_at': timeutils.utcnow(),
'provider_id': "1 1 1",
'multiattach': False
}
connector = {'initiator': 'iqn.2012-07.org.fake:01'}
vag_id = 1
vags = [{'attributes': {},
'deletedVolumes': [],
'initiators': [connector['initiator']],
'name': 'fakeiqn',
'volumeAccessGroupID': vag_id,
'volumes': [1],
'virtualNetworkIDs': []}]
with mock.patch.object(sfv,
'_get_vags_by_name',
return_value=vags), \
mock.patch.object(sfv,
'_remove_vag') as rem_vag:
sfv._sf_terminate_connection(testvol, connector, False)
rem_vag.assert_called_with(vag_id)
def test_sf_term_conn_with_vag_rem_vol(self):
# Verify we correctly remove a the volume from a non-empty VAG.
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'provider_location': '10.10.7.1:3260 iqn.2010-01.com.'
'solidfire:87hg.uuid-2cc06226-cc'
'74-4cb7-bd55-14aed659a0cc.4060 0',
'provider_auth': 'CHAP stack-1-a60e2611875f40199931f2'
'c76370d66b 2FE0CQ8J196R',
'provider_geometry': '4096 4096',
'created_at': timeutils.utcnow(),
'provider_id': "1 1 1",
'multiattach': False
}
provider_id = testvol['provider_id']
vol_id = int(provider_id.split()[0])
connector = {'initiator': 'iqn.2012-07.org.fake:01'}
vag_id = 1
vags = [{'attributes': {},
'deletedVolumes': [],
'initiators': [connector['initiator']],
'name': 'fakeiqn',
'volumeAccessGroupID': vag_id,
'volumes': [1, 2],
'virtualNetworkIDs': []}]
with mock.patch.object(sfv,
'_get_vags_by_name',
return_value=vags), \
mock.patch.object(sfv,
'_remove_volume_from_vag') as rem_vag:
sfv._sf_terminate_connection(testvol, connector, False)
rem_vag.assert_called_with(vol_id, vag_id)
def test_sf_term_conn_without_connector(self):
# Verify we correctly force the deletion of a volume.
mod_conf = self.configuration
mod_conf.sf_enable_vag = True
sfv = solidfire.SolidFireDriver(configuration=mod_conf)
testvol = {'project_id': 'testprjid',
'name': 'testvol',
'size': 1,
'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66',
'volume_type_id': None,
'provider_location': '10.10.7.1:3260 iqn.2010-01.com.'
'solidfire:87hg.uuid-2cc06226-cc'
'74-4cb7-bd55-14aed659a0cc.4060 0',
'provider_auth': 'CHAP stack-1-a60e2611875f40199931f2'
'c76370d66b 2FE0CQ8J196R',
'provider_geometry': '4096 4096',
'created_at': timeutils.utcnow(),
'provider_id': "1 1 1",
'multiattach': False
}
provider_id = testvol['provider_id']
vol_id = int(provider_id.split()[0])
vag_id = 1
vags = [{'attributes': {},
'deletedVolumes': [],
'initiators': ['iqn.2012-07.org.fake:01'],
'name': 'fakeiqn',
'volumeAccessGroupID': vag_id,
'volumes': [1, 2],
'virtualNetworkIDs': []}]
with mock.patch.object(sfv,
'_get_vags_by_volume',
return_value=vags), \
mock.patch.object(sfv,
'_remove_volume_from_vags') as rem_vags:
sfv._sf_terminate_connection(testvol, None, False)
rem_vags.assert_called_with(vol_id)
def test_safe_create_vag_simple(self):
# Test the sunny day call straight into _create_vag.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'fake_iqn'
vol_id = 1
with mock.patch.object(sfv,
'_get_vags_by_name',
return_value=[]), \
mock.patch.object(sfv,
'_create_vag') as mock_create_vag:
sfv._safe_create_vag(iqn, vol_id)
mock_create_vag.assert_called_with(iqn, vol_id)
def test_safe_create_vag_matching_vag(self):
# Vag exists, resuse.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vags = [{'attributes': {},
'deletedVolumes': [],
'initiators': [iqn],
'name': iqn,
'volumeAccessGroupID': 1,
'volumes': [1, 2],
'virtualNetworkIDs': []}]
with mock.patch.object(sfv,
'_get_vags_by_name',
return_value=vags), \
mock.patch.object(sfv,
'_create_vag') as create_vag, \
mock.patch.object(sfv,
'_add_initiator_to_vag') as add_iqn:
vag_id = sfv._safe_create_vag(iqn, None)
self.assertEqual(vag_id, vags[0]['volumeAccessGroupID'])
create_vag.assert_not_called()
add_iqn.assert_not_called()
def test_safe_create_vag_reuse_vag(self):
# Reuse a matching vag.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vags = [{'attributes': {},
'deletedVolumes': [],
'initiators': [],
'name': iqn,
'volumeAccessGroupID': 1,
'volumes': [1, 2],
'virtualNetworkIDs': []}]
vag_id = vags[0]['volumeAccessGroupID']
with mock.patch.object(sfv,
'_get_vags_by_name',
return_value=vags), \
mock.patch.object(sfv,
'_add_initiator_to_vag',
return_value=vag_id) as add_init:
res_vag_id = sfv._safe_create_vag(iqn, None)
self.assertEqual(res_vag_id, vag_id)
add_init.assert_called_with(iqn, vag_id)
def test_create_vag_iqn_fail(self):
# Attempt to create a VAG with an already in-use initiator.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vag_id = 1
vol_id = 42
def throw_request(method, params, version):
msg = 'xExceededLimit: {}'.format(params['initiators'][0])
raise solidfire.SolidFireAPIException(message=msg)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=throw_request), \
mock.patch.object(sfv,
'_safe_create_vag',
return_value=vag_id) as create_vag, \
mock.patch.object(sfv,
'_purge_vags') as purge_vags:
res_vag_id = sfv._create_vag(iqn, vol_id)
self.assertEqual(res_vag_id, vag_id)
create_vag.assert_called_with(iqn, vol_id)
purge_vags.assert_not_called()
def test_create_vag_limit_fail(self):
# Attempt to create a VAG with VAG limit reached.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vag_id = 1
vol_id = 42
def throw_request(method, params, version):
msg = 'xExceededLimit'
raise solidfire.SolidFireAPIException(message=msg)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=throw_request), \
mock.patch.object(sfv,
'_safe_create_vag',
return_value=vag_id) as create_vag, \
mock.patch.object(sfv,
'_purge_vags') as purge_vags:
res_vag_id = sfv._create_vag(iqn, vol_id)
self.assertEqual(res_vag_id, vag_id)
create_vag.assert_called_with(iqn, vol_id)
purge_vags.assert_called_with()
def test_add_initiator_duplicate(self):
# Thrown exception should yield vag_id.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vag_id = 1
def throw_request(method, params, version):
msg = 'xAlreadyInVolumeAccessGroup'
raise solidfire.SolidFireAPIException(message=msg)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=throw_request):
res_vag_id = sfv._add_initiator_to_vag(iqn, vag_id)
self.assertEqual(vag_id, res_vag_id)
def test_add_initiator_missing_vag(self):
# Thrown exception should result in create_vag call.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vag_id = 1
def throw_request(method, params, version):
msg = 'xVolumeAccessGroupIDDoesNotExist'
raise solidfire.SolidFireAPIException(message=msg)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=throw_request), \
mock.patch.object(sfv,
'_safe_create_vag',
return_value=vag_id) as mock_create_vag:
res_vag_id = sfv._add_initiator_to_vag(iqn, vag_id)
self.assertEqual(vag_id, res_vag_id)
mock_create_vag.assert_called_with(iqn)
def test_add_volume_to_vag_duplicate(self):
# Thrown exception should yield vag_id
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vag_id = 1
vol_id = 42
def throw_request(method, params, version):
msg = 'xAlreadyInVolumeAccessGroup'
raise solidfire.SolidFireAPIException(message=msg)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=throw_request):
res_vag_id = sfv._add_volume_to_vag(vol_id, iqn, vag_id)
self.assertEqual(res_vag_id, vag_id)
def test_add_volume_to_vag_missing_vag(self):
# Thrown exception should yield vag_id
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
iqn = 'TESTIQN'
vag_id = 1
vol_id = 42
def throw_request(method, params, version):
msg = 'xVolumeAccessGroupIDDoesNotExist'
raise solidfire.SolidFireAPIException(message=msg)
with mock.patch.object(sfv,
'_issue_api_request',
side_effect=throw_request), \
mock.patch.object(sfv,
'_safe_create_vag',
return_value=vag_id) as mock_create_vag:
res_vag_id = sfv._add_volume_to_vag(vol_id, iqn, vag_id)
self.assertEqual(res_vag_id, vag_id)
mock_create_vag.assert_called_with(iqn, vol_id)
def test_remove_volume_from_vag_missing_volume(self):
# Volume not in VAG, throws.
sfv = solidfire.SolidFireDriver(configuration=self.configuration)
vag_id = 1
vol_id = 42
def throw_request(method, params, version):
msg =