u'mapped': False,
u'cmmSource': False}
+ VOLUME_LIST = [{u'instanceId': u'64702.3494',
+ u'scSerialNumber': 64702,
+ u'replicationSource': False,
+ u'liveVolume': False,
+ u'vpdId': 3496,
+ u'objectType': u'ScVolume',
+ u'index': 3494,
+ u'volumeFolderPath': u'devstackvol/fcvm/',
+ u'hostCacheEnabled': False,
+ u'usedByLegacyFluidFsNasVolume': False,
+ u'inRecycleBin': False,
+ u'volumeFolderIndex': 17,
+ u'instanceName':
+ u'volume-37883deb-85cd-426a-9a98-62eaad8671ea',
+ u'statusMessage': u'',
+ u'status': u'Up',
+ u'storageType': {u'instanceId': u'64702.1',
+ u'instanceName':
+ u'Assigned - Redundant - 2 MB',
+ u'objectType': u'ScStorageType'},
+ u'cmmDestination': False,
+ u'replicationDestination': False,
+ u'volumeFolder': {u'instanceId': u'64702.17',
+ u'instanceName': u'fcvm',
+ u'objectType': u'ScVolumeFolder'},
+ u'deviceId': u'6000d31000fcbe000000000000000da8',
+ u'active': True,
+ u'portableVolumeDestination': False,
+ u'deleteAllowed': True,
+ u'name': u'volume-37883deb-85cd-426a-9a98-62eaad8671ea',
+ u'scName': u'Storage Center 64702',
+ u'secureDataUsed': False,
+ u'serialNumber': u'0000fcbe-00000da8',
+ u'replayAllowed': True,
+ u'flashOptimized': False,
+ u'configuredSize': u'1.073741824E9 Bytes',
+ u'mapped': False,
+ u'cmmSource': False}]
+
+ # Volume list that contains multiple volumes
+ VOLUME_LIST_MULTI_VOLS = [
+ {u'instanceId': u'64702.3494',
+ u'scSerialNumber': 64702,
+ u'replicationSource': False,
+ u'liveVolume': False,
+ u'vpdId': 3496,
+ u'objectType': u'ScVolume',
+ u'index': 3494,
+ u'volumeFolderPath': u'devstackvol/fcvm/',
+ u'hostCacheEnabled': False,
+ u'usedByLegacyFluidFsNasVolume': False,
+ u'inRecycleBin': False,
+ u'volumeFolderIndex': 17,
+ u'instanceName':
+ u'volume-37883deb-85cd-426a-9a98-62eaad8671ea',
+ u'statusMessage': u'',
+ u'status': u'Up',
+ u'storageType': {u'instanceId': u'64702.1',
+ u'instanceName':
+ u'Assigned - Redundant - 2 MB',
+ u'objectType': u'ScStorageType'},
+ u'cmmDestination': False,
+ u'replicationDestination': False,
+ u'volumeFolder': {u'instanceId': u'64702.17',
+ u'instanceName': u'fcvm',
+ u'objectType': u'ScVolumeFolder'},
+ u'deviceId': u'6000d31000fcbe000000000000000da8',
+ u'active': True,
+ u'portableVolumeDestination': False,
+ u'deleteAllowed': True,
+ u'name': u'volume-37883deb-85cd-426a-9a98-62eaad8671ea',
+ u'scName': u'Storage Center 64702',
+ u'secureDataUsed': False,
+ u'serialNumber': u'0000fcbe-00000da8',
+ u'replayAllowed': True,
+ u'flashOptimized': False,
+ u'configuredSize': u'1.073741824E9 Bytes',
+ u'mapped': False,
+ u'cmmSource': False},
+ {u'instanceId': u'64702.3495',
+ u'scSerialNumber': 64702,
+ u'replicationSource': False,
+ u'liveVolume': False,
+ u'vpdId': 3496,
+ u'objectType': u'ScVolume',
+ u'index': 3495,
+ u'volumeFolderPath': u'devstackvol/fcvm/',
+ u'hostCacheEnabled': False,
+ u'usedByLegacyFluidFsNasVolume': False,
+ u'inRecycleBin': False,
+ u'volumeFolderIndex': 17,
+ u'instanceName':
+ u'volume-37883deb-85cd-426a-9a98-62eaad8671ea',
+ u'statusMessage': u'',
+ u'status': u'Up',
+ u'storageType': {u'instanceId': u'64702.1',
+ u'instanceName':
+ u'Assigned - Redundant - 2 MB',
+ u'objectType': u'ScStorageType'},
+ u'cmmDestination': False,
+ u'replicationDestination': False,
+ u'volumeFolder': {u'instanceId': u'64702.17',
+ u'instanceName': u'fcvm',
+ u'objectType': u'ScVolumeFolder'},
+ u'deviceId': u'6000d31000fcbe000000000000000da9',
+ u'active': True,
+ u'portableVolumeDestination': False,
+ u'deleteAllowed': True,
+ u'name': u'volume-37883deb-85cd-426a-9a98-62eaad8671ea',
+ u'scName': u'Storage Center 64702',
+ u'secureDataUsed': False,
+ u'serialNumber': u'0000fcbe-00000da8',
+ u'replayAllowed': True,
+ u'flashOptimized': False,
+ u'configuredSize': u'1.073741824E9 Bytes',
+ u'mapped': False,
+ u'cmmSource': False}]
+
VOLUME_CONFIG = \
{u'instanceId': u'64702.3494',
u'scSerialNumber': 64702,
self.configuration.san_login,
self.configuration.san_password)
+ # Set up the scapi configuration vars
+ self.scapi.ssn = self.configuration.dell_sc_ssn
+ self.scapi.sfname = self.configuration.dell_sc_server_folder
+ self.scapi.vfname = self.configuration.dell_sc_volume_folder
+
self.volid = str(uuid.uuid4())
self.volume_name = "volume" + self.volid
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.find_sc(64702)
+ res = self.scapi.find_sc()
mock_get.assert_called_once_with('StorageCenter/StorageCenter')
self.assertTrue(mock_get_result.called)
self.assertEqual(u'64702', res, 'Unexpected SSN')
mock_open_connection,
mock_init):
self.assertRaises(exception.VolumeBackendAPIException,
- self.scapi.find_sc, 12345)
+ self.scapi.find_sc)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_first_result',
mock_open_connection,
mock_init):
res = self.scapi._create_folder(
- 'StorageCenter/ScVolumeFolder', 12345, '',
+ 'StorageCenter/ScVolumeFolder',
+ '',
self.configuration.dell_sc_volume_folder)
self.assertTrue(mock_post.called)
self.assertTrue(mock_first_result.called)
mock_init):
# Test case where parent folder name is specified
res = self.scapi._create_folder(
- 'StorageCenter/ScVolumeFolder', 12345, 'parentFolder',
+ 'StorageCenter/ScVolumeFolder', 'parentFolder',
self.configuration.dell_sc_volume_folder)
self.assertTrue(mock_post.called)
self.assertTrue(mock_first_result.called)
mock_open_connection,
mock_init):
res = self.scapi._create_folder(
- 'StorageCenter/ScVolumeFolder', 12345, '',
+ 'StorageCenter/ScVolumeFolder', '',
self.configuration.dell_sc_volume_folder)
self.assertIsNone(res, 'Test Create folder - None expected')
mock_open_connection,
mock_init):
res = self.scapi._create_folder_path(
- 'StorageCenter/ScVolumeFolder', 12345,
+ 'StorageCenter/ScVolumeFolder',
self.configuration.dell_sc_volume_folder)
mock_path_to_array.assert_called_once_with(
self.configuration.dell_sc_volume_folder)
mock_init):
# Test case where folder is not found and must be created
res = self.scapi._create_folder_path(
- 'StorageCenter/ScVolumeFolder', 12345,
+ 'StorageCenter/ScVolumeFolder',
self.configuration.dell_sc_volume_folder)
mock_path_to_array.assert_called_once_with(
self.configuration.dell_sc_volume_folder)
# Test case where folder is not found, must be created
# and creation fails
res = self.scapi._create_folder_path(
- 'StorageCenter/ScVolumeFolder', 12345,
+ 'StorageCenter/ScVolumeFolder',
self.configuration.dell_sc_volume_folder)
mock_path_to_array.assert_called_once_with(
self.configuration.dell_sc_volume_folder)
mock_open_connection,
mock_init):
res = self.scapi._find_folder(
- 'StorageCenter/ScVolumeFolder', 12345,
+ 'StorageCenter/ScVolumeFolder',
self.configuration.dell_sc_volume_folder)
self.assertTrue(mock_post.called)
self.assertTrue(mock_get_result.called)
mock_init):
# Test case for folder path with multiple folders
res = self.scapi._find_folder(
- 'StorageCenter/ScVolumeFolder', 12345,
+ 'StorageCenter/ScVolumeFolder',
u'testParentFolder/opnstktst')
self.assertTrue(mock_post.called)
self.assertTrue(mock_get_result.called)
mock_open_connection,
mock_init):
res = self.scapi._find_folder(
- 'StorageCenter/ScVolumeFolder', 12345,
+ 'StorageCenter/ScVolumeFolder',
self.configuration.dell_sc_volume_folder)
self.assertIsNone(res, 'Test find folder - None expected')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_folder_path',
- return_value=FLDR)
- def test_create_volume_folder_path(self,
- mock_create_vol_fldr_path,
- mock_close_connection,
- mock_open_connection,
- mock_init):
- res = self.scapi._create_volume_folder_path(
- 12345,
- self.configuration.dell_sc_volume_folder)
- mock_create_vol_fldr_path.assert_called_once_with(
- 'StorageCenter/ScVolumeFolder',
- 12345,
+ '_find_folder',
+ return_value=None)
+ def test_find_volume_folder_fail(self,
+ mock_find_folder,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where _find_volume_folder returns none
+ res = self.scapi._find_volume_folder(
+ False)
+ mock_find_folder.assert_called_once_with(
+ 'StorageCenter/ScVolumeFolder/GetList',
self.configuration.dell_sc_volume_folder)
- self.assertEqual(self.FLDR, res, 'Unexpected ScFolder')
+ self.assertIsNone(res, 'Expected None')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_folder',
mock_open_connection,
mock_init):
res = self.scapi._find_volume_folder(
- 12345,
+ False)
+ mock_find_folder.assert_called_once_with(
+ 'StorageCenter/ScVolumeFolder/GetList',
self.configuration.dell_sc_volume_folder)
+ self.assertEqual(self.FLDR, res, 'Unexpected Folder')
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_create_folder_path',
+ return_value=FLDR)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_find_folder',
+ return_value=None)
+ def test_find_volume_folder_create_folder(self,
+ mock_find_folder,
+ mock_create_folder_path,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where _find_volume_folder returns none and folder must be
+ # created
+ res = self.scapi._find_volume_folder(
+ True)
mock_find_folder.assert_called_once_with(
'StorageCenter/ScVolumeFolder/GetList',
- 12345,
self.configuration.dell_sc_volume_folder)
+ self.assertTrue(mock_create_folder_path.called)
self.assertEqual(self.FLDR, res, 'Unexpected Folder')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
mock_init):
res = self.scapi.create_volume(
self.volume_name,
- 1,
- 12345,
- self.configuration.dell_sc_volume_folder)
+ 1)
self.assertTrue(mock_post.called)
self.assertTrue(mock_get_json.called)
- mock_find_volume_folder.assert_called_once_with(
- 12345, self.configuration.dell_sc_volume_folder)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_get_json',
+ 'find_volume',
return_value=VOLUME)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_volume_folder_path',
- return_value=FLDR)
+ '_get_json',
+ return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_volume_folder',
- return_value=None)
+ return_value=FLDR)
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_201)
- def test_create_vol_and_folder(self,
- mock_post,
- mock_find_volume_folder,
- mock_create_vol_folder_path,
- mock_get_json,
- mock_close_connection,
- mock_open_connection,
- mock_init):
- # Test calling create_volume where volume folder has to be created
+ def test_create_volume_retry_find(self,
+ mock_post,
+ mock_find_volume_folder,
+ mock_get_json,
+ mock_find_volume,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where find_volume is used to do a retry of finding the
+ # created volume
res = self.scapi.create_volume(
self.volume_name,
- 1,
- 12345,
- self.configuration.dell_sc_volume_folder)
+ 1)
self.assertTrue(mock_post.called)
self.assertTrue(mock_get_json.called)
- mock_create_vol_folder_path.assert_called_once_with(
- 12345,
- self.configuration.dell_sc_volume_folder)
- mock_find_volume_folder.assert_called_once_with(
- 12345, self.configuration.dell_sc_volume_folder)
+ self.assertTrue(mock_find_volume.called)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_get_json',
return_value=VOLUME)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_volume_folder_path',
- return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_volume_folder',
return_value=None)
def test_create_vol_folder_fail(self,
mock_post,
mock_find_volume_folder,
- mock_create_vol_folder_path,
mock_get_json,
mock_close_connection,
mock_open_connection,
# fails to be created
res = self.scapi.create_volume(
self.volume_name,
- 1,
- 12345,
- self.configuration.dell_sc_volume_folder)
+ 1)
self.assertTrue(mock_post.called)
self.assertTrue(mock_get_json.called)
- mock_create_vol_folder_path.assert_called_once_with(
- 12345,
- self.configuration.dell_sc_volume_folder)
- mock_find_volume_folder.assert_called_once_with(
- 12345, self.configuration.dell_sc_volume_folder)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
mock_init):
res = self.scapi.create_volume(
self.volume_name,
- 1,
- 12345,
- self.configuration.dell_sc_volume_folder)
- mock_find_volume_folder.assert_called_once_with(
- 12345, self.configuration.dell_sc_volume_folder)
+ 1)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertIsNone(res, 'None expected')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_first_result',
- return_value=VOLUME)
+ '_get_json',
+ return_value=VOLUME_LIST)
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
- def test_find_volume_by_name(self,
- mock_post,
- mock_first_result,
- mock_close_connection,
- mock_open_connection,
- mock_init):
- # Test case to find volume by name
- res = self.scapi.find_volume(12345,
- self.volume_name)
+ def test__get_volume_list_enforce_vol_fldr(self,
+ mock_post,
+ mock_get_json,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case to find volume in the configured volume folder
+ res = self.scapi._get_volume_list(self.volume_name, True)
self.assertTrue(mock_post.called)
- self.assertTrue(mock_first_result.called)
- self.assertEqual(self.VOLUME, res, 'Unexpected volume')
+ self.assertTrue(mock_get_json.called)
+ self.assertEqual(self.VOLUME_LIST, res, 'Unexpected volume list')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_first_result',
- return_value=VOLUME)
+ '_get_json',
+ return_value=VOLUME_LIST)
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
- # Test case to find volume by InstancedId
- def test_find_volume_by_instanceid(self,
+ def test__get_volume_list_any_fldr(self,
mock_post,
- mock_first_result,
+ mock_get_json,
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.find_volume(12345,
- None,
- '64702.3494')
+ # Test case to find volume anywhere in the configured SC
+ res = self.scapi._get_volume_list(self.volume_name, False)
self.assertTrue(mock_post.called)
- self.assertTrue(mock_first_result.called)
+ self.assertTrue(mock_get_json.called)
+ self.assertEqual(self.VOLUME_LIST, res, 'Unexpected volume list')
+
+ def test__get_volume_list_no_name(self,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case specified volume name is None
+ res = self.scapi._get_volume_list(None, True)
+ self.assertIsNone(res, 'None expected')
+
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'post',
+ return_value=RESPONSE_204)
+ def test__get_volume_list_failure(self,
+ mock_post,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case to find volume in the configured volume folder
+ res = self.scapi._get_volume_list(self.volume_name, True)
+ self.assertTrue(mock_post.called)
+ self.assertIsNone(res, 'None expected')
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_volume_list',
+ return_value=VOLUME_LIST)
+ def test_find_volume(self,
+ mock_get_vol_list,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case to find volume by name
+ res = self.scapi.find_volume(self.volume_name)
+ self.assertTrue(mock_get_vol_list.called)
self.assertEqual(self.VOLUME, res, 'Unexpected volume')
- def test_find_volume_no_name_or_instance(self,
- mock_close_connection,
- mock_open_connection,
- mock_init):
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_volume_list',
+ return_value=None)
+ def test_find_volume_no_name(self,
+ mock_get_volume_list,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
# Test calling find_volume with no name or instanceid
- res = self.scapi.find_volume(12345)
+ res = self.scapi.find_volume(None)
self.assertEqual(res, None, 'Expected None')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_first_result',
- return_value=None)
- @mock.patch.object(dell_storagecenter_api.HttpClient,
- 'post',
- return_value=RESPONSE_204)
+ '_get_volume_list')
def test_find_volume_not_found(self,
- mock_post,
- mock_first_result,
+ mock_get_volume_list,
mock_close_connection,
mock_open_connection,
mock_init):
# Test calling find_volume with result of no volume found
- res = self.scapi.find_volume(12345,
- self.volume_name)
+ mock_get_volume_list.side_effect = [[], []]
+ res = self.scapi.find_volume(self.volume_name)
self.assertEqual(None, res, 'None expected')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_volume_list',
+ return_value=VOLUME_LIST_MULTI_VOLS)
+ def test_find_volume_multi_vols_found(self,
+ mock_get_volume_list,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where multiple volumes are found
+ self.assertRaises(exception.VolumeBackendAPIException,
+ self.scapi.find_volume, self.volume_name)
+
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_get_json',
return_value=True)
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.delete_volume(12345,
- self.volume_name)
+ res = self.scapi.delete_volume(self.volume_name)
self.assertTrue(mock_delete.called)
- mock_find_volume.assert_called_once_with(12345, self.volume_name, None)
+ mock_find_volume.assert_called_once_with(self.volume_name)
self.assertTrue(mock_get_json.called)
self.assertTrue(res)
mock_open_connection,
mock_init):
self.assertRaises(exception.VolumeBackendAPIException,
- self.scapi.delete_volume, 12345, self.volume_name)
+ self.scapi.delete_volume, self.volume_name)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_volume',
mock_open_connection,
mock_init):
# Test case where volume to be deleted does not exist
- res = self.scapi.delete_volume(12345,
- self.volume_name)
+ res = self.scapi.delete_volume(self.volume_name)
self.assertTrue(res, 'Expected True')
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_folder_path',
- return_value=SVR_FLDR)
- def test_create_server_folder_path(self,
- mock_create_svr_fldr_path,
- mock_close_connection,
- mock_open_connection,
- mock_init):
- res = self.scapi._create_server_folder_path(
- 12345,
- self.configuration.dell_sc_server_folder)
- mock_create_svr_fldr_path.assert_called_once_with(
- 'StorageCenter/ScServerFolder',
- 12345,
- self.configuration.dell_sc_server_folder)
- self.assertEqual(self.SVR_FLDR, res, 'Unexpected server folder')
-
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_folder',
return_value=SVR_FLDR)
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi._find_server_folder(
- 12345,
+ res = self.scapi._find_server_folder(False)
+ mock_find_folder.assert_called_once_with(
+ 'StorageCenter/ScServerFolder/GetList',
self.configuration.dell_sc_server_folder)
+ self.assertEqual(self.SVR_FLDR, res, 'Unexpected server folder')
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_create_folder_path',
+ return_value=SVR_FLDR)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_find_folder',
+ return_value=None)
+ def test_find_server_folder_create_folder(self,
+ mock_find_folder,
+ mock_create_folder_path,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where specified server folder is not found and must be
+ # created
+ res = self.scapi._find_server_folder(True)
mock_find_folder.assert_called_once_with(
'StorageCenter/ScServerFolder/GetList',
- 12345,
self.configuration.dell_sc_server_folder)
+ self.assertTrue(mock_create_folder_path.called)
self.assertEqual(self.SVR_FLDR, res, 'Unexpected server folder')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_find_folder',
+ return_value=None)
+ def test_find_server_folder_fail(self,
+ mock_find_folder,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where _find_server_folder returns none
+ res = self.scapi._find_server_folder(
+ False)
+ mock_find_folder.assert_called_once_with(
+ 'StorageCenter/ScServerFolder/GetList',
+ self.configuration.dell_sc_volume_folder)
+ self.assertIsNone(res, 'Expected None')
+
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi._find_serveros(12345, 'Red Hat Linux 6.x')
+ res = self.scapi._find_serveros('Red Hat Linux 6.x')
self.assertTrue(mock_get_json.called)
self.assertTrue(mock_post.called)
self.assertEqual('64702.38', res, 'Wrong InstanceId')
mock_open_connection,
mock_init):
# Test requesting a Server OS that will not be found
- res = self.scapi._find_serveros(12345, 'Non existent OS')
+ res = self.scapi._find_serveros('Non existent OS')
self.assertTrue(mock_get_json.called)
self.assertTrue(mock_post.called)
self.assertIsNone(res, 'None expected')
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi._find_serveros(12345, 'Red Hat Linux 6.x')
+ res = self.scapi._find_serveros('Red Hat Linux 6.x')
self.assertEqual(None, res, 'None expected')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
mock_open_connection,
mock_init):
res = self.scapi.create_server_multiple_hbas(
- 12345,
- self.configuration.dell_sc_server_folder,
self.WWNS)
self.assertTrue(mock_create_server.called)
self.assertTrue(mock_add_hba.called)
mock_open_connection,
mock_init):
res = self.scapi.create_server(
- 12345,
- self.configuration.dell_sc_server_folder,
self.IQN,
False)
self.assertTrue(mock_find_serveros.called)
mock_open_connection,
mock_init):
res = self.scapi.create_server(
- 12345,
- self.configuration.dell_sc_server_folder,
self.IQN,
False)
self.assertTrue(mock_find_serveros.called)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_first_result',
return_value=SCSERVER)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_server_folder_path',
- return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_server_folder',
return_value=None)
mock_post,
mock_find_serveros,
mock_find_server_folder,
- mock_create_svr_fldr_path,
mock_first_result,
mock_add_hba,
mock_close_connection,
mock_open_connection,
mock_init):
res = self.scapi.create_server(
- 12345,
- self.configuration.dell_sc_server_folder,
self.IQN,
False)
self.assertTrue(mock_find_server_folder.called)
- self.assertTrue(mock_create_svr_fldr_path.called)
self.assertEqual(self.SCSERVER, res, 'Unexpected ScServer')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_first_result',
return_value=SCSERVER)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_server_folder_path',
- return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_server_folder',
return_value=None)
mock_post,
mock_find_serveros,
mock_find_server_folder,
- mock_create_svr_fldr_path,
mock_first_result,
mock_add_hba,
mock_close_connection,
mock_open_connection,
mock_init):
res = self.scapi.create_server(
- 12345,
- self.configuration.dell_sc_server_folder,
self.IQN,
False)
self.assertIsNone(res, 'None expected')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_first_result',
return_value=None)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_server_folder_path',
- return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_server_folder',
return_value=None)
mock_post,
mock_find_serveros,
mock_find_server_folder,
- mock_create_svr_fldr_path,
mock_first_result,
mock_add_hba,
mock_close_connection,
mock_init):
# Test create server where _first_result is None
res = self.scapi.create_server(
- 12345,
- self.configuration.dell_sc_server_folder,
self.IQN,
False)
self.assertIsNone(res, 'None expected')
mock_init):
# Tests create server where add hba fails
res = self.scapi.create_server(
- 12345,
- self.configuration.dell_sc_server_folder,
self.IQN,
False)
self.assertTrue(mock_delete_server.called)
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.find_server(12345,
- self.IQN)
+ res = self.scapi.find_server(self.IQN)
self.assertTrue(mock_find_serverhba.called)
self.assertTrue(mock_first_result.called)
self.assertIsNotNone(res, 'Expected ScServer')
mock_init):
# Test case where a ScServer HBA does not exist with the specified IQN
# or WWN
- res = self.scapi.find_server(12345,
- self.IQN)
+ res = self.scapi.find_server(self.IQN)
self.assertTrue(mock_find_serverhba.called)
self.assertIsNone(res, 'Expected None')
mock_init):
# Test case where a ScServer does not exist with the specified
# ScServerHba
- res = self.scapi.find_server(12345,
- self.IQN)
+ res = self.scapi.find_server(self.IQN)
self.assertTrue(mock_find_serverhba.called)
self.assertIsNone(res, 'Expected None')
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.find_server(12345,
- self.IQN)
+ res = self.scapi.find_server(self.IQN)
self.assertTrue(mock_post.called)
self.assertTrue(mock_first_result.called)
self.assertIsNotNone(res, 'Expected ScServerHba')
mock_init):
# Test case where a ScServer does not exist with the specified
# ScServerHba
- res = self.scapi.find_server(12345,
- self.IQN)
+ res = self.scapi.find_server(self.IQN)
self.assertIsNone(res, 'Expected None')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
self.assertTrue(mock_first_result.called)
self.assertEqual(self.MAP_PROFILE, res, 'Incorrect ScMappingProfile')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_id')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_first_result')
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'post')
+ def test_map_volume_no_vol_id(self,
+ mock_post,
+ mock_first_result,
+ mock_get_id,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where ScVolume instanceId is None
+ mock_get_id.side_effect = [None, '64702.47']
+ res = self.scapi.map_volume(self.VOLUME,
+ self.SCSERVER)
+ self.assertFalse(mock_post.called)
+ self.assertFalse(mock_first_result.called)
+ self.assertIsNone(res, 'None expected')
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_id')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_first_result')
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'post')
+ def test_map_volume_no_server_id(self,
+ mock_post,
+ mock_first_result,
+ mock_get_id,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where ScVolume instanceId is None
+ mock_get_id.side_effect = ['64702.3494', None]
+ res = self.scapi.map_volume(self.VOLUME,
+ self.SCSERVER)
+ self.assertFalse(mock_post.called)
+ self.assertFalse(mock_first_result.called)
+ self.assertIsNone(res, 'None expected')
+
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_204)
self.assertTrue(mock_delete.called)
self.assertFalse(res, False)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_id')
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'delete',
+ return_value=RESPONSE_200)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_json',
+ return_value=MAP_PROFILES)
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'get',
+ return_value=RESPONSE_200)
+ def test_unmap_volume_no_vol_id(self,
+ mock_get,
+ mock_get_json,
+ mock_delete,
+ mock_get_id,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where ScVolume instanceId = None
+ mock_get_id.side_effect = [None, '64702.47']
+ res = self.scapi.unmap_volume(self.VOLUME,
+ self.SCSERVER)
+ self.assertFalse(mock_get.called)
+ self.assertFalse(mock_get_json.called)
+ self.assertFalse(mock_delete.called)
+ self.assertTrue(res)
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_id')
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'delete',
+ return_value=RESPONSE_200)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_json',
+ return_value=MAP_PROFILES)
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'get',
+ return_value=RESPONSE_200)
+ def test_unmap_volume_no_server_id(self,
+ mock_get,
+ mock_get_json,
+ mock_delete,
+ mock_get_id,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ # Test case where ScVolume instanceId = None
+ mock_get_id.side_effect = ['64702.3494', None]
+ res = self.scapi.unmap_volume(self.VOLUME,
+ self.SCSERVER)
+ self.assertFalse(mock_get.called)
+ self.assertFalse(mock_get_json.called)
+ self.assertFalse(mock_delete.called)
+ self.assertTrue(res)
+
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_get_json',
return_value=STRG_USAGE)
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.get_storage_usage(64702)
+ res = self.scapi.get_storage_usage()
self.assertTrue(mock_get.called)
self.assertTrue(mock_get_json.called)
self.assertEqual(self.STRG_USAGE, res, 'Unexpected ScStorageUsage')
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'get',
+ return_value=RESPONSE_204)
def test_get_storage_usage_no_ssn(self,
+ mock_get,
mock_close_connection,
mock_open_connection,
mock_init):
# Test case where SSN is none
- res = self.scapi.get_storage_usage(None)
+ self.scapi.ssn = None
+ res = self.scapi.get_storage_usage()
+ self.scapi.ssn = 12345
+ self.assertFalse(mock_get.called)
self.assertIsNone(res, 'None expected')
@mock.patch.object(dell_storagecenter_api.HttpClient,
mock_close_connection,
mock_open_connection,
mock_init):
- res = self.scapi.get_storage_usage(64702)
+ res = self.scapi.get_storage_usage()
self.assertTrue(mock_get.called)
self.assertIsNone(res, 'None expected')
vol_name = u'Test_create_vol'
res = self.scapi.create_view_volume(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.TST_RPLAY)
self.assertTrue(mock_post.called)
- mock_find_volume_folder.assert_called_once_with(
- 64702,
- self.configuration.dell_sc_volume_folder)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertTrue(mock_first_result.called)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_first_result',
return_value=VOLUME)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_volume_folder_path',
- return_value=FLDR)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_volume_folder',
return_value=None)
def test_create_view_volume_create_fldr(self,
mock_post,
mock_find_volume_folder,
- mock_create_volume_folder,
mock_first_result,
mock_close_connection,
mock_open_connection,
vol_name = u'Test_create_vol'
res = self.scapi.create_view_volume(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.TST_RPLAY)
self.assertTrue(mock_post.called)
- mock_find_volume_folder.assert_called_once_with(
- 64702,
- self.configuration.dell_sc_volume_folder)
- mock_create_volume_folder.assert_called_once_with(
- 64702,
- self.configuration.dell_sc_volume_folder)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertTrue(mock_first_result.called)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_first_result',
return_value=VOLUME)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- '_create_volume_folder_path',
- return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_find_volume_folder',
return_value=None)
def test_create_view_volume_no_vol_fldr(self,
mock_post,
mock_find_volume_folder,
- mock_create_volume_folder,
mock_first_result,
mock_close_connection,
mock_open_connection,
vol_name = u'Test_create_vol'
res = self.scapi.create_view_volume(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.TST_RPLAY)
self.assertTrue(mock_post.called)
- mock_find_volume_folder.assert_called_once_with(
- 64702,
- self.configuration.dell_sc_volume_folder)
- mock_create_volume_folder.assert_called_once_with(
- 64702,
- self.configuration.dell_sc_volume_folder)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertTrue(mock_first_result.called)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
vol_name = u'Test_create_vol'
res = self.scapi.create_view_volume(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.TST_RPLAY)
self.assertTrue(mock_post.called)
- mock_find_volume_folder.assert_called_once_with(
- 64702,
- self.configuration.dell_sc_volume_folder)
+ mock_find_volume_folder.assert_called_once_with(True)
self.assertIsNone(res, 'Expected None')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
vol_name = u'Test_create_clone_vol'
res = self.scapi.create_cloned_volume(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.VOLUME)
mock_create_replay.assert_called_once_with(self.VOLUME,
'Cinder Clone Replay',
60)
mock_create_view_volume.assert_called_once_with(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.RPLAY)
self.assertEqual(self.VOLUME, res, 'Unexpected ScVolume')
vol_name = u'Test_create_clone_vol'
res = self.scapi.create_cloned_volume(
vol_name,
- self.configuration.dell_sc_volume_folder,
self.VOLUME)
mock_create_replay.assert_called_once_with(self.VOLUME,
'Cinder Clone Replay',
self.configuration.san_login = "admin"
self.configuration.san_password = "mmm"
self.configuration.dell_sc_ssn = 12345
- self.configuration.dell_sc_server_folder = 'opnstktst'
- self.configuration.dell_sc_volume_folder = 'opnstktst'
+ self.configuration.dell_sc_server_folder = 'openstack'
+ self.configuration.dell_sc_volume_folder = 'openstack'
self.configuration.dell_sc_api_port = 3033
self.configuration.iscsi_ip_address = '192.168.1.1'
self.configuration.iscsi_port = 3260
self.configuration.san_login,
self.configuration.san_password)
+ # Set up the scapi configuration vars
+ self.scapi.ssn = self.configuration.dell_sc_ssn
+ self.scapi.sfname = self.configuration.dell_sc_server_folder
+ self.scapi.vfname = self.configuration.dell_sc_volume_folder
+
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
self.config = config
def open_connection(self):
- '''Open connection to Enterprise Manager.'''
- connection = StorageCenterApi(self.config.san_ip,
- self.config.dell_sc_api_port,
- self.config.san_login,
- self.config.san_password)
- connection.open_connection()
+ connection = None
+ ssn = self.config.dell_sc_ssn
+ LOG.info(_LI('open_connection to %(s)s at %(ip)s'),
+ {'s': ssn,
+ 'ip': self.config.san_ip})
+ if ssn:
+ '''Open connection to Enterprise Manager.'''
+ connection = StorageCenterApi(self.config.san_ip,
+ self.config.dell_sc_api_port,
+ self.config.san_login,
+ self.config.san_password)
+ # This instance is for a single backend. That backend has a
+ # few items of information we should save rather than passing them
+ # about.
+ connection.ssn = ssn
+ connection.vfname = self.config.dell_sc_volume_folder
+ connection.sfname = self.config.dell_sc_server_folder
+ connection.open_connection()
+ else:
+ raise exception.VolumeBackendAPIException('Configuration error. '
+ 'dell_sc_ssn not set.')
return connection
def __init__(self, host, port, user, password):
self.notes = 'Created by Dell Cinder Driver'
+ self.ssn = None
+ self.vfname = 'openstack'
+ self.sfname = 'openstack'
self.client = HttpClient(host,
port,
user,
'r': r.reason})
self.client = None
- def find_sc(self, ssn):
- '''This is really just a check that the sc is there and being managed by
- EM.
+ def find_sc(self):
+ '''This is really just a check that the sc is there and being managed
+ by EM.
'''
r = self.client.get('StorageCenter/StorageCenter')
result = self._get_result(r,
'scSerialNumber',
- ssn)
+ self.ssn)
if result is None:
LOG.error(_LE('Failed to find %(s)s. Result %(r)s'),
- {'s': ssn,
+ {'s': self.ssn,
'r': r})
raise exception.VolumeBackendAPIException(
_('Failed to find Storage Center'))
return self._get_id(result)
- # Volume functions
+ # Folder functions
- def _create_folder(self, url, ssn, parent, folder):
+ def _create_folder(self, url, parent, folder):
'''This is generic to server and volume folders.
'''
f = None
payload = {}
payload['Name'] = folder
- payload['StorageCenter'] = ssn
+ payload['StorageCenter'] = self.ssn
if parent != '':
payload['Parent'] = parent
payload['Notes'] = self.notes
f = self._first_result(r)
return f
- def _create_folder_path(self, url, ssn, foldername):
+ def _create_folder_path(self, url, foldername):
'''This is generic to server and volume folders.
'''
path = self._path_to_array(foldername)
if found:
listurl = url + '/GetList'
f = self._find_folder(listurl,
- ssn,
folderpath)
if f is None:
found = False
# We didn't find it so create it
if found is False:
f = self._create_folder(url,
- ssn,
instanceId,
folder)
# If we haven't found a folder or created it then leave
folderpath = folderpath + '/'
return f
- def _find_folder(self, url, ssn, foldername):
+ def _find_folder(self, url, foldername):
'''Most of the time the folder will already have been created so
we look for the end folder and check that the rest of the path is
right.
This is generic to server and volume folders.
'''
pf = PayloadFilter()
- pf.append('scSerialNumber', ssn)
+ pf.append('scSerialNumber', self.ssn)
basename = os.path.basename(foldername)
pf.append('Name', basename)
- # If we have any kind of path we add '/' to match the storage
- # center's convention and throw it into the filters.
+ # If we have any kind of path we throw it into the filters.
folderpath = os.path.dirname(foldername)
if folderpath != '':
+ # SC convention is to end with a '/' so make sure we do.
folderpath += '/'
pf.append('folderPath', folderpath)
folder = None
'r': r.reason})
return folder
- def _create_volume_folder_path(self, ssn, foldername):
- return self._create_folder_path('StorageCenter/ScVolumeFolder',
- ssn,
- foldername)
-
- def _find_volume_folder(self, ssn, foldername):
- return self._find_folder('StorageCenter/ScVolumeFolder/GetList',
- ssn,
- foldername)
+ def _find_volume_folder(self, create=False):
+ folder = self._find_folder('StorageCenter/ScVolumeFolder/GetList',
+ self.vfname)
+ # Doesn't exist? make it
+ if folder is None and create is True:
+ folder = self._create_folder_path('StorageCenter/ScVolumeFolder',
+ self.vfname)
+ return folder
def _init_volume(self, scvolume):
'''Maps the volume to a random server and immediately unmaps
scserver)
break
- def create_volume(self, name, size, ssn, volfolder):
+ def create_volume(self, name, size):
'''This creates a new volume on the storage center. It
- will create it in volfolder. If volfolder does not
- exist it will create it. If it cannot create volfolder
+ will create it in a folder called self.vfname. If self.vfname
+ does not exist it will create it. If it cannot create it
the volume will be created in the root.
'''
- scvolume = None
- # Find our folder
LOG.debug('Create Volume %(name)s %(ssn)s %(folder)s',
{'name': name,
- 'ssn': ssn,
- 'folder': volfolder})
- folder = self._find_volume_folder(ssn,
- volfolder)
+ 'ssn': self.ssn,
+ 'folder': self.vfname})
- # Doesn't exist? make it
- if folder is None:
- folder = self._create_volume_folder_path(ssn,
- volfolder)
+ # Find our folder
+ folder = self._find_volume_folder(True)
# If we actually have a place to put our volume create it
if folder is None:
- LOG.error(_LE('Unable to create folder %s'),
- volfolder)
+ LOG.warning(_LW('Unable to create folder %s'),
+ self.vfname)
+
+ # Init our return.
+ scvolume = None
# Create the volume
payload = {}
payload['Name'] = name
payload['Notes'] = self.notes
payload['Size'] = '%d GB' % size
- payload['StorageCenter'] = ssn
+ payload['StorageCenter'] = self.ssn
if folder is not None:
payload['VolumeFolder'] = self._get_id(folder)
r = self.client.post('StorageCenter/ScVolume',
{'name': name,
'c': r.status_code,
'r': r.reason})
+ return None
if scvolume:
LOG.info(_LI('Created volume %(instanceId)s: %(name)s'),
{'instanceId': scvolume['instanceId'],
' Attempting to locate volume'))
# In theory it is there since success was returned.
# Try one last time to find it before returning.
- scvolume = self.find_volume(ssn, name, None)
+ scvolume = self.find_volume(name)
return scvolume
- def find_volume(self, ssn, name=None, instanceid=None):
- '''search ssn for volume of name and/or instance id
+ def _get_volume_list(self, name, filterbyvfname=True):
+ '''Return the list of volumes with name of name.
+ :param name: Volume name.
+ :param filterbyvfname: If true filters by the preset folder name.
+ :return: Returns the scvolume or None.
'''
- LOG.debug('finding volume %(sn)s : %(name)s : %(id)s',
- {'sn': ssn,
- 'name': name,
- 'id': instanceid})
+ result = None
pf = PayloadFilter()
- pf.append('scSerialNumber', ssn)
- # We need at least a name and or an instance id. If we have
- # that we can find a volume.
- if instanceid is not None:
- pf.append('instanceId', instanceid)
- elif name is not None:
+ pf.append('scSerialNumber', self.ssn)
+ # We need a name to find a volume.
+ if name is not None:
pf.append('Name', name)
else:
return None
+ # set folderPath
+ if filterbyvfname:
+ vfname = (self.vfname if self.vfname.endswith('/')
+ else self.vfname + '/')
+ pf.append('volumeFolderPath', vfname)
r = self.client.post('StorageCenter/ScVolume/GetList',
pf.payload)
if r.status_code != 200:
- LOG.debug('ScVolume GetList error %(i)s: %(c)d %(r)s',
- {'i': instanceid,
+ LOG.debug('ScVolume GetList error %(n)s: %(c)d %(r)s',
+ {'n': name,
'c': r.status_code,
'r': r.reason})
- return self._first_result(r)
+ else:
+ result = self._get_json(r)
+ # We return None if there was an error and a list if the command
+ # succeeded. It might be an empty list.
+ return result
- def delete_volume(self, ssn, name):
- # find our volume
- vol = self.find_volume(ssn, name, None)
+ def find_volume(self, name):
+ '''Search self.ssn for volume of name.
+ '''
+ LOG.debug('Searching %(sn)s for %(name)s',
+ {'sn': self.ssn,
+ 'name': name})
+
+ # Cannot find a volume without the name
+ if name is None:
+ return None
+
+ # Look for our volume in our folder.
+ vollist = self._get_volume_list(name,
+ True)
+ # If an empty list was returned they probably moved the volumes or
+ # changed the folder name so try again without the folder.
+ if not vollist:
+ LOG.debug('Cannot find volume %(n)s in %(v)s. Searching SC.',
+ {'n': name,
+ 'v': self.vfname})
+ vollist = self._get_volume_list(name,
+ False)
+
+ # If multiple volumes of the same name are found we need to error.
+ if len(vollist) > 1:
+ # blow up
+ raise exception.VolumeBackendAPIException(
+ _('Multiple copies of volume %s found.') % name)
+
+ # We made it and should have a valid volume.
+ return None if not vollist else vollist[0]
+
+ def delete_volume(self, name):
+ # Delete our volume.
+ vol = self.find_volume(name)
if vol is not None:
r = self.client.delete('StorageCenter/ScVolume/%s'
% self._get_id(vol))
if r.status_code != 200:
raise exception.VolumeBackendAPIException(
_('Error deleting volume %(ssn)s: %(sn)s: %(c)d %(r)s') %
- {'ssn': ssn,
+ {'ssn': self.ssn,
'sn': name,
'c': r.status_code,
'r': r.reason})
# If we can't find the volume then it is effectively gone.
return True
- def _create_server_folder_path(self, ssn, foldername):
- return self._create_folder_path('StorageCenter/ScServerFolder',
- ssn,
- foldername)
-
- def _find_server_folder(self, ssn, foldername):
- return self._find_folder('StorageCenter/ScServerFolder/GetList',
- ssn,
- foldername)
+ def _find_server_folder(self, create=False):
+ folder = self._find_folder('StorageCenter/ScServerFolder/GetList',
+ self.sfname)
+ if folder is None and create is True:
+ folder = self._create_folder_path('StorageCenter/ScServerFolder',
+ self.sfname)
+ return folder
def _add_hba(self, scserver, wwnoriscsiname, isfc=False):
'''Adds an HBA to the scserver. The HBA will be added
# We do not know that we are red hat linux 6.x but that works
# best for red hat and ubuntu. So, there.
- def _find_serveros(self, ssn, osname='Red Hat Linux 6.x'):
+ def _find_serveros(self, osname='Red Hat Linux 6.x'):
'''Returns the serveros instance id of the specified osname.
Required to create a server.
'''
pf = PayloadFilter()
- pf.append('scSerialNumber', ssn)
+ pf.append('scSerialNumber', self.ssn)
r = self.client.post('StorageCenter/ScServerOperatingSystem/GetList',
pf.payload)
if r.status_code == 200:
'r': r.reason})
return None
- def create_server_multiple_hbas(self, ssn, foldername, wwns):
+ def create_server_multiple_hbas(self, wwns):
'''Same as create_server except it can take a list of hbas. hbas
can be wwns or iqns.
'''
for wwn in wwns:
if scserver is None:
# Use the fist wwn to create the server.
- scserver = self.create_server(ssn,
- foldername,
- wwn,
+ scserver = self.create_server(wwn,
True)
else:
# Add the wwn to our server
True)
return scserver
- def create_server(self, ssn, foldername, wwnoriscsiname, isfc=False):
- '''creates a server on the the storage center ssn. Adds the first
+ def create_server(self, wwnoriscsiname, isfc=False):
+ '''creates a server on the the storage center self.ssn. Adds the first
HBA to it.
'''
scserver = None
payload = {}
payload['Name'] = 'Server_' + wwnoriscsiname
- payload['StorageCenter'] = ssn
+ payload['StorageCenter'] = self.ssn
payload['Notes'] = self.notes
# We pick Red Hat Linux 6.x because it supports multipath and
# will attach luns to paths as they are found.
- scserveros = self._find_serveros(ssn, 'Red Hat Linux 6.x')
+ scserveros = self._find_serveros('Red Hat Linux 6.x')
if scserveros is not None:
payload['OperatingSystem'] = scserveros
# Find our folder or make it
- folder = self._find_server_folder(ssn,
- foldername)
- if folder is None:
- folder = self._create_server_folder_path(ssn,
- foldername)
+ folder = self._find_server_folder(True)
# At this point it doesn't matter if the folder was created or not.
# We just attempt to create the server. Let it be in the root if
# Success or failure is determined by the caller
return scserver
- def find_server(self, ssn, instance_name):
+ def find_server(self, instance_name):
'''Hunts for a server by looking for an HBA with the server's IQN
or wwn.
'''
scserver = None
# We search for our server by first finding our HBA
- hba = self._find_serverhba(ssn, instance_name)
+ hba = self._find_serverhba(instance_name)
# Once created hbas stay in the system. So it isn't enough
# that we found one it actually has to be attached to a
# server.
if hba is not None and hba.get('server') is not None:
pf = PayloadFilter()
- pf.append('scSerialNumber', ssn)
+ pf.append('scSerialNumber', self.ssn)
pf.append('instanceId', self._get_id(hba['server']))
r = self.client.post('StorageCenter/ScServer/GetList',
pf.payload)
instance_name)
return scserver
- def _find_serverhba(self, ssn, instance_name):
+ def _find_serverhba(self, instance_name):
'''Hunts for a sc server HBA by looking for an HBA with the
server's IQN or wwn.
scserverhba = None
# We search for our server by first finding our HBA
pf = PayloadFilter()
- pf.append('scSerialNumber', ssn)
+ pf.append('scSerialNumber', self.ssn)
pf.append('instanceName', instance_name)
r = self.client.post('StorageCenter/ScServerHba/GetList',
pf.payload)
rtn = False
return rtn
- def get_storage_usage(self, ssn):
+ def get_storage_usage(self):
'''get_storage_usage'''
storageusage = None
- if ssn is not None:
+ if self.ssn is not None:
r = self.client.get('StorageCenter/StorageCenter/%s/StorageUsage'
- % ssn)
+ % self.ssn)
if r.status_code == 200:
storageusage = self._get_json(r)
else:
# We either couldn't find it or expired it.
return True
- def create_view_volume(self, volname, volfolder, screplay):
+ def create_view_volume(self, volname, screplay):
'''create_view_volume
- creates a new volume named volname in the folder
- volfolder from the screplay.
+ creates a new volume named volname from the screplay.
'''
- # find our ssn and get our folder
- ssn = screplay.get('scSerialNumber')
- folder = self._find_volume_folder(ssn,
- volfolder)
-
- # Doesn't exist? make it
- if folder is None:
- folder = self._create_volume_folder_path(ssn,
- volfolder)
+ folder = self._find_volume_folder(True)
# payload is just the volume name and folder if we have one.
payload = {}
return volume
- def create_cloned_volume(self, volumename, volumefolder, scvolume):
+ def create_cloned_volume(self, volumename, scvolume):
'''create_cloned_volume
creates a temporary replay and then creates a
60)
if replay is not None:
clone = self.create_view_volume(volumename,
- volumefolder,
replay)
else:
LOG.error(_LE('Error: unable to snap replay'))