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.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request) self.stubs.Set(volume_types, 'get_volume_type', _fake_get_volume_type) self.stubs.Set(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 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) self.assertTrue(sfv.retype(self.ctxt, testvol, test_type, diff, host))
def test_get_sfaccount_by_name_fails(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request_fails) account = sfv._get_sfaccount_by_name('some-name') self.assertIsNone(account)
def test_create_sfaccount_fails(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request_fails) account = sfv._create_sfaccount('project-id') self.assertIsNone(account)
def test_create_clone(self, _mock_create_template_account, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data _mock_create_template_account.return_value = 1 _fake_get_snaps = [{'snapshotID': 5, 'name': 'testvol'}] testvol = {'project_id': 'testprjid', 'name': 'testvol', 'size': 1, 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66', 'volume_type_id': None, 'created_at': timeutils.utcnow()} testvol_b = {'project_id': 'testprjid', 'name': 'testvol', 'size': 1, 'id': 'b831c4d1-d1f0-11e1-9b23-0800200c9a66', 'volume_type_id': None, 'created_at': timeutils.utcnow()} sfv = solidfire.SolidFireDriver(configuration=self.configuration) with mock.patch.object(sfv, '_get_sf_snapshots', return_value=_fake_get_snaps), \ 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={}): sfv.create_cloned_volume(testvol_b, testvol)
def test_create_volume_for_migration(self): def _fake_do_v_create(self, project_id, params): return project_id, params self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request) self.stubs.Set(solidfire.SolidFireDriver, '_do_volume_create', _fake_do_v_create) 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'} sfv = solidfire.SolidFireDriver(configuration=self.configuration) proj_id, 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'])
def test_delete_volume(self, _mock_create_template_account, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data _mock_create_template_account.return_value = 1 testvol = {'project_id': 'testprjid', 'name': 'test_volume', 'size': 1, 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66', 'created_at': timeutils.utcnow()} fake_sfaccounts = [{'accountID': 5, 'name': 'testprjid', 'targetSecret': 'shhhh', 'username': '******'}] def _fake_do_v_create(project_id, params): return project_id, params 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]), \ mock.patch.object(sfv, '_do_volume_create', side_effect=_fake_do_v_create): sfv.delete_volume(testvol)
def test_configured_svip(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) def _fake_get_volumes(account_id): return [{'volumeID': 1, 'iqn': ''}] def _fake_get_cluster_info(): return {'clusterInfo': {'svip': 1}} with mock.patch.object(sfv, '_get_volumes_by_sfaccount', side_effect=_fake_get_volumes),\ mock.patch.object(sfv, '_issue_api_request', side_effect=self.fake_issue_api_request): sfaccount = { 'targetSecret': 'yakitiyak', 'accountID': 5, 'username': '******' } v = sfv._get_model_info(sfaccount, 1) self.assertEqual('1.1.1.1:3260 0', v['provider_location']) configured_svip = '9.9.9.9:6500' self.configuration.sf_svip = configured_svip v = sfv._get_model_info(sfaccount, 1) self.assertEqual('%s 0' % configured_svip, v['provider_location'])
def test_clone_image_not_configured(self, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data 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_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'])
def test_update_cluster_status(self): self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request) sfv = solidfire.SolidFireDriver(configuration=self.configuration) sfv._update_cluster_status() self.assertEqual(99.0, sfv.cluster_stats['free_capacity_gb']) self.assertEqual(100.0, sfv.cluster_stats['total_capacity_gb'])
def test_create_snapshot(self): self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request) self.stubs.Set(solidfire.SolidFireDriver, '_get_model_info', self.fake_get_model_info) testvol = {'project_id': 'testprjid', 'name': 'testvol', 'size': 1, 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66', 'volume_type_id': None, 'created_at': timeutils.utcnow()} testsnap = {'project_id': 'testprjid', 'name': 'testvol', 'volume_size': 1, 'id': 'b831c4d1-d1f0-11e1-9b23-0800200c9a66', 'volume_id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66', 'volume_type_id': None, 'created_at': timeutils.utcnow()} sfv = solidfire.SolidFireDriver(configuration=self.configuration) sfv.create_volume(testvol) sfv.create_snapshot(testsnap)
def test_create_volume_non_512e(self, _mock_create_template_account, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data _mock_create_template_account.return_value = 1 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, 'name': 'testprjid', 'targetSecret': 'shhhh', 'username': '******' }] 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_verify_image_volume_ok(self, _mock_create_image_volume, _mock_get_sf_volume, _mock_get_sfaccount, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data _mock_get_sfaccount.return_value = { 'username': '******', 'accountID': 7777 } _mock_get_sf_volume.return_value =\ {'status': 'active', 'volumeID': 1, 'attributes': { 'image_info': {'image_updated_at': '2013-09-28T15:27:36.325355', 'image_id': '17c550bb-a411-44c0-9aaf-0d96dd47f501', 'image_name': 'fake-image', 'image_created_at': '2014-12-17T00:16:23+00:00'}}} _mock_create_image_volume.return_value = None image_meta = { 'id': '17c550bb-a411-44c0-9aaf-0d96dd47f501', 'updated_at': datetime.datetime(2013, 9, 28, 15, 27, 36, 325355) } image_service = 'null' sfv = solidfire.SolidFireDriver(configuration=self.configuration) _mock_issue_api_request.return_value = {'result': 'ok'} sfv._verify_image_volume(self.ctxt, image_meta, image_service) self.assertFalse(_mock_create_image_volume.called)
def test_retype(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) self.stubs.Set(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 testvol = { 'project_id': 'testprjid', 'name': 'test_volume', 'size': 1, 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66', 'created_at': timeutils.utcnow() } self.assertTrue(sfv.retype(self.ctxt, testvol, type_ref, diff, host))
def test_get_cluster_info_fail(self): # NOTE(JDG) This test just fakes update_cluster_status # this is inentional for this test self.stubs.Set(solidfire.SolidFireDriver, '_update_cluster_status', self.fake_update_cluster_status) self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request_fails) sfv = solidfire.SolidFireDriver(configuration=self.configuration) self.assertRaises(exception.SolidFireAPIException, sfv._get_cluster_info)
def test_set_by_qos_by_type_only(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) type_ref = volume_types.create(self.ctxt, "type1", {"qos:minIOPS": "100", "qos:burstIOPS": "300", "qos:maxIOPS": "200"}) qos = sfv._set_qos_by_volume_type(self.ctxt, type_ref['id']) self.assertEqual({'minIOPS': 100, 'maxIOPS': 200, 'burstIOPS': 300}, qos)
def test_extend_volume(self): self.stubs.Set(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_create_template_no_account(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) def _fake_issue_api_req(method, params, version=0): if 'GetAccountByName' in method: raise exception.SolidFireAPIException return {'result': {'accountID': 1}} with mock.patch.object(sfv, '_issue_api_request', side_effect=_fake_issue_api_req): self.assertEqual(1, sfv._create_template_account('foo'))
def test_extend_volume_fails_no_volume(self): self.stubs.Set(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_accept_transfer_volume_not_found_raises(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) self.stubs.Set(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_manage_existing_volume(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()} self.stubs.Set(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.assertIsNone(model_update.get('provider_geometry', None))
def test_accept_transfer(self): sfv = solidfire.SolidFireDriver(configuration=self.configuration) self.stubs.Set(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_set_by_qos_spec(self): 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']) self.assertEqual(self.expected_qos_results, qos)
def test_create_volume(self): self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', 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()} sfv = solidfire.SolidFireDriver(configuration=self.configuration) model_update = sfv.create_volume(testvol) self.assertIsNotNone(model_update) self.assertIsNone(model_update.get('provider_geometry', None))
def test_delete_volume_fails_no_volume(self): self.stubs.Set(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) try: sfv.delete_volume(testvol) self.fail("Should have thrown Error") except Exception: pass
def test_create_volume_for_migration(self, _mock_create_template_account, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data _mock_create_template_account.return_value = 1 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' } fake_sfaccounts = [{ 'accountID': 5, 'name': 'testprjid', 'targetSecret': 'shhhh', 'username': '******' }] def _fake_do_v_create(project_id, params): return project_id, params 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]), \ mock.patch.object(sfv, '_do_volume_create', side_effect=_fake_do_v_create): proj_id, 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'])
def test_extend_volume_fails_account_lookup(self): # NOTE(JDG) This test just fakes update_cluster_status # this is intentional for this test self.stubs.Set(solidfire.SolidFireDriver, '_update_cluster_status', self.fake_update_cluster_status) self.stubs.Set(solidfire.SolidFireDriver, '_issue_api_request', self.fake_issue_api_request_fails) 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.assertRaises(exception.SolidFireAccountNotFound, sfv.extend_volume, testvol, 2)
def test_create_volume_with_qos(self): preset_qos = {} preset_qos['qos'] = 'fast' self.stubs.Set(solidfire.SolidFireDriver, '_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], 'volume_type_id': None, 'created_at': timeutils.utcnow()} sfv = solidfire.SolidFireDriver(configuration=self.configuration) model_update = sfv.create_volume(testvol) self.assertIsNotNone(model_update)
def test_clone_image_virt_size_not_set(self, _mock_create_template_account, _mock_issue_api_request): _mock_issue_api_request.return_value = self.mock_stats_data _mock_create_template_account.return_value = 1 self.configuration.sf_allow_template_caching = True sfv = solidfire.SolidFireDriver(configuration=self.configuration) # Don't run clone_image if virtual_size property not on image _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.assertEqual((None, False), sfv.clone_image(self.ctxt, self.mock_volume, 'fake', _fake_image_meta, 'fake'))
def test_verify_image_volume_out_of_date(self, _mock_create_image_volume, _mock_get_sf_volume, _mock_get_sfaccount, _mock_issue_api_request): fake_sf_vref = { 'status': 'active', 'volumeID': 1, 'attributes': { 'image_info': { 'image_updated_at': '2014-12-17T00:16:23+00:00', 'image_id': '17c550bb-a411-44c0-9aaf-0d96dd47f501', 'image_name': 'fake-image', 'image_created_at': '2014-12-17T00:16:23+00:00' } } } stats_data =\ {'result': {'clusterCapacity': {'maxProvisionedSpace': 107374182400, 'usedSpace': 1073741824, 'compressionPercent': 100, 'deDuplicationPercent': 100, 'thinProvisioningPercent': 100}}} _mock_issue_api_request.return_value = stats_data _mock_get_sfaccount.return_value = { 'username': '******', 'accountID': 7777 } _mock_get_sf_volume.return_value = fake_sf_vref _mock_create_image_volume.return_value = fake_sf_vref image_meta = { 'id': '17c550bb-a411-44c0-9aaf-0d96dd47f501', 'updated_at': datetime.datetime(2013, 9, 28, 15, 27, 36, 325355) } image_service = 'null' sfv = solidfire.SolidFireDriver(configuration=self.configuration) _mock_issue_api_request.return_value = {'result': 'ok'} sfv._verify_image_volume(self.ctxt, image_meta, image_service) self.assertTrue(_mock_create_image_volume.called)