diff --git a/nova/tests/test_SolidFireSanISCSIDriver.py b/nova/tests/test_solidfire.py similarity index 50% rename from nova/tests/test_SolidFireSanISCSIDriver.py rename to nova/tests/test_solidfire.py index 60c1a63e0..73018031a 100644 --- a/nova/tests/test_SolidFireSanISCSIDriver.py +++ b/nova/tests/test_solidfire.py @@ -18,7 +18,7 @@ from nova import exception from nova.openstack.common import log as logging from nova import test -from nova.volume import san +from nova.volume.solidfire import SolidFire LOG = logging.getLogger(__name__) @@ -28,83 +28,104 @@ class SolidFireVolumeTestCase(test.TestCase): super(SolidFireVolumeTestCase, self).setUp() def fake_issue_api_request(obj, method, params): - if method == 'GetClusterInfo': + if method is 'GetClusterInfo': LOG.info('Called Fake GetClusterInfo...') results = {'result': {'clusterInfo': - {'name': 'fake-cluster', - 'mvip': '1.1.1.1', - 'svip': '1.1.1.1', - 'uniqueID': 'unqid', - 'repCount': 2, - 'attributes': {}}}} + {'name': 'fake-cluster', + 'mvip': '1.1.1.1', + 'svip': '1.1.1.1', + 'uniqueID': 'unqid', + 'repCount': 2, + 'attributes': {}}}} return results - elif method == 'AddAccount': + elif method is 'AddAccount': LOG.info('Called Fake AddAccount...') return {'result': {'accountID': 25}, 'id': 1} - elif method == 'GetAccountByName': + elif method is 'GetAccountByName': LOG.info('Called Fake GetAccountByName...') - results = {'result': {'account': { - 'accountID': 25, - 'username': params['username'], - 'status': 'active', - 'initiatorSecret': '123456789012', - 'targetSecret': '123456789012', - 'attributes': {}, - 'volumes': [6, 7, 20]}}, - "id": 1} + 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 == 'CreateVolume': + elif method is 'CreateVolume': LOG.info('Called Fake CreateVolume...') return {'result': {'volumeID': 5}, 'id': 1} - elif method == 'DeleteVolume': + elif method is 'DeleteVolume': LOG.info('Called Fake DeleteVolume...') return {'result': {}, 'id': 1} - elif method == 'ListVolumesForAccount': + elif method is 'ListVolumesForAccount': + test_name = 'OS-VOLID-a720b3c0-d1f0-11e1-9b23-0800200c9a66' LOG.info('Called Fake ListVolumesForAccount...') - result = {'result': {'volumes': [{ - 'volumeID': '5', - 'name': 'test_volume', - 'accountID': 25, - 'sliceCount': 1, - 'totalSize': 1048576 * 1024, - 'enable512e': False, - 'access': "readWrite", - 'status': "active", - 'attributes':None, - 'qos':None}]}} + result = {'result': { + 'volumes': [{'volumeID': 5, + 'name': test_name, + 'accountID': 25, + 'sliceCount': 1, + 'totalSize': 1048576 * 1024, + 'enable512e': True, + 'access': "readWrite", + 'status': "active", + 'attributes':None, + 'qos': None, + 'iqn': test_name}]}} return result else: - LOG.error('Unimplemented API call in Fake:%s' % method) + LOG.error('Crap, unimplemented API call in Fake:%s' % method) def fake_issue_api_request_fails(obj, method, params): - return {'error': { - 'code': 000, - 'name': 'DummyError', - 'message': 'This is a fake error response'}, - 'id': 1} + return {'error': {'code': 000, + 'name': 'DummyError', + 'message': 'This is a fake error response'}, + 'id': 1} + + def fake_volume_get(obj, key, default=None): + return {'qos': 'fast'} def test_create_volume(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'testvol', - 'size': 1} - sfv = san.SolidFireSanISCSIDriver() + 'size': 1, + 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} + sfv = SolidFire() + model_update = sfv.create_volume(testvol) + + def test_create_volume_with_qos(self): + preset_qos = {} + preset_qos['qos'] = 'fast' + self.stubs.Set(SolidFire, '_issue_api_request', + self.fake_issue_api_request) + + testvol = {'project_id': 'testprjid', + 'name': 'testvol', + 'size': 1, + 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66', + 'metadata': [preset_qos]} + + sfv = SolidFire() model_update = sfv.create_volume(testvol) def test_create_volume_fails(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request_fails) testvol = {'project_id': 'testprjid', 'name': 'testvol', - 'size': 1} - sfv = san.SolidFireSanISCSIDriver() + 'size': 1, + 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} + sfv = SolidFire() try: sfv.create_volume(testvol) self.fail("Should have thrown Error") @@ -112,49 +133,51 @@ class SolidFireVolumeTestCase(test.TestCase): pass def test_create_sfaccount(self): - sfv = san.SolidFireSanISCSIDriver() - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + sfv = SolidFire() + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request) account = sfv._create_sfaccount('project-id') self.assertNotEqual(account, None) def test_create_sfaccount_fails(self): - sfv = san.SolidFireSanISCSIDriver() - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + sfv = SolidFire() + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request_fails) account = sfv._create_sfaccount('project-id') self.assertEqual(account, None) def test_get_sfaccount_by_name(self): - sfv = san.SolidFireSanISCSIDriver() - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + sfv = SolidFire() + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request) account = sfv._get_sfaccount_by_name('some-name') self.assertNotEqual(account, None) def test_get_sfaccount_by_name_fails(self): - sfv = san.SolidFireSanISCSIDriver() - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + sfv = SolidFire() + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request_fails) account = sfv._get_sfaccount_by_name('some-name') self.assertEqual(account, None) def test_delete_volume(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'test_volume', - 'size': 1} - sfv = san.SolidFireSanISCSIDriver() + 'size': 1, + 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} + sfv = SolidFire() model_update = sfv.delete_volume(testvol) def test_delete_volume_fails_no_volume(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'no-name', - 'size': 1} - sfv = san.SolidFireSanISCSIDriver() + 'size': 1, + 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} + sfv = SolidFire() try: model_update = sfv.delete_volume(testvol) self.fail("Should have thrown Error") @@ -162,25 +185,26 @@ class SolidFireVolumeTestCase(test.TestCase): pass def test_delete_volume_fails_account_lookup(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', - self.fake_issue_api_request) + self.stubs.Set(SolidFire, '_issue_api_request', + self.fake_issue_api_request_fails) testvol = {'project_id': 'testprjid', 'name': 'no-name', - 'size': 1} - sfv = san.SolidFireSanISCSIDriver() - self.assertRaises(exception.DuplicateSfVolumeNames, + 'size': 1, + 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} + sfv = SolidFire() + self.assertRaises(exception.SfAccountNotFound, sfv.delete_volume, testvol) def test_get_cluster_info(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request) - sfv = san.SolidFireSanISCSIDriver() + sfv = SolidFire() sfv._get_cluster_info() def test_get_cluster_info_fail(self): - self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.stubs.Set(SolidFire, '_issue_api_request', self.fake_issue_api_request_fails) - sfv = san.SolidFireSanISCSIDriver() + sfv = SolidFire() self.assertRaises(exception.SolidFireAPIException, sfv._get_cluster_info)