def setUp(self): """Setup a test case environment. Creates fake volume and snapshot objects and sets up the required API responses. """ super(TestDeleteSnapShot, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.fake_volume = fake_volume_obj(ctx, **{'provider_id': fake.PROVIDER_ID}) self.snapshot = fake_snapshot_obj( ctx, **{ 'volume': self.fake_volume, 'provider_id': fake.SNAPSHOT_ID }) self.snapshot_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.snapshot.id))) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: self.snapshot.id, 'instances/Volume::' + self.snapshot.provider_id: {}, 'instances/Volume::{}/action/removeMappedSdc'.format(self.snapshot.provider_id): self.snapshot.id, 'instances/Volume::{}/action/removeVolume'.format(self.snapshot.provider_id): self.snapshot.id, }, self.RESPONSE_MODE.BadStatus: { 'instances/Volume::' + self.snapshot.provider_id: self.BAD_STATUS_RESPONSE, 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: self.BAD_STATUS_RESPONSE, 'instances/Volume::{}/action/removeVolume'.format(self.snapshot.provider_id): self.BAD_STATUS_RESPONSE, }, self.RESPONSE_MODE.Invalid: { 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: mocks.MockHTTPSResponse( { 'errorCode': self.OLD_VOLUME_NOT_FOUND_ERROR, 'message': 'Test Delete Invalid Snapshot', }, 400), 'instances/Volume::{}/action/removeVolume'.format(self.snapshot.provider_id): mocks.MockHTTPSResponse( { 'errorCode': self.OLD_VOLUME_NOT_FOUND_ERROR, 'message': 'Test Delete Invalid Snapshot', }, 400, ) }, }
def setUp(self): """Setup a test case environment. Creates a fake volume object and sets up the required API responses. """ super(TestDeleteVolume, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.volume = fake_volume.fake_volume_obj( ctx, **{'provider_id': fake.PROVIDER_ID}) self.volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.volume.id)) ) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'instances/Volume::' + self.volume.provider_id: {}, 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: self.volume.id, 'instances/Volume::{}/action/removeMappedSdc'.format( self.volume.provider_id): self.volume.provider_id, 'instances/Volume::{}/action/removeVolume'.format( self.volume.provider_id ): self.volume.provider_id, }, self.RESPONSE_MODE.BadStatus: { 'instances/Volume::' + self.volume.provider_id: self.BAD_STATUS_RESPONSE, 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: mocks.MockHTTPSResponse( { 'errorCode': 401, 'message': 'BadStatus Volume Test', }, 401 ), 'instances/Volume::{}/action/removeVolume'.format( self.volume.provider_id ): mocks.MockHTTPSResponse( { 'errorCode': 401, 'message': 'BadStatus Volume Test', }, 401 ), }, }
def setUp(self): """Setup a test case environment. Creates fake volume and snapshot objects and sets up the required API responses. """ super(TestCreateSnapShot, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.fake_volume = fake_volume.fake_volume_obj( ctx, **{'provider_id': fake.PROVIDER_ID}) self.snapshot = fake_snapshot.fake_snapshot_obj( ctx, **{'volume': self.fake_volume}) self.mock_object(db.sqlalchemy.api, 'volume_get', self.return_fake_volume) snap_vol_id = self.snapshot.volume_id self.volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(snap_vol_id))) self.snapshot_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.snapshot.id))) self.snapshot_reply = json.dumps({ 'volumeIdList': ['cloned'], 'snapshotGroupId': 'cloned_snapshot' }) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: '"{}"'.format(self.snapshot.volume_id), 'instances/System/action/snapshotVolumes': self.snapshot_reply, 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: self.snapshot.id, }, self.RESPONSE_MODE.BadStatus: { 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: self.BAD_STATUS_RESPONSE, 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: self.BAD_STATUS_RESPONSE, 'instances/System/action/snapshotVolumes': self.BAD_STATUS_RESPONSE, }, self.RESPONSE_MODE.Invalid: { 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: None, 'instances/System/action/snapshotVolumes': mocks.MockHTTPSResponse( { 'errorCode': 400, 'message': 'Invalid Volume Snapshot Test' }, 400), }, }
def setUp(self): """Setup a test case environment. Creates fake volume object and sets up the required API responses. """ super(TestExtendVolume, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.volume = fake_volume_obj( ctx, **{ 'id': fake.VOLUME_ID, 'provider_id': fake.PROVIDER_ID }) self.volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.volume.id))) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: '"{}"'.format(self.volume.id), 'instances/Volume::{}/action/setVolumeSize'.format(self.volume.provider_id): mocks.MockHTTPSResponse({}, 200), }, self.RESPONSE_MODE.BadStatus: { 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: self.BAD_STATUS_RESPONSE, 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: self.BAD_STATUS_RESPONSE, 'instances/Volume::{}/action/setVolumeSize'.format(self.volume.provider_id): self.BAD_STATUS_RESPONSE, }, self.RESPONSE_MODE.Invalid: { 'types/Volume/instances/getByName::' + self.volume_name_2x_enc: None, 'instances/Volume::{}/action/setVolumeSize'.format(self.volume.provider_id): mocks.MockHTTPSResponse( { 'errorCode': self.OLD_VOLUME_NOT_FOUND_ERROR, 'message': 'BadStatus Volume Test', }, 400), }, }
def setUp(self): """Setup a test case environment. Creates a fake volume object and sets up the required API responses. """ super(TestManageExisting, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.volume = fake_volume.fake_volume_obj( ctx, **{'provider_id': fake.PROVIDER_ID}) self.volume_attached = fake_volume.fake_volume_obj( ctx, **{'provider_id': fake.PROVIDER2_ID}) self.volume_no_provider_id = fake_volume.fake_volume_obj(ctx) self.volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.volume.id))) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'instances/Volume::' + self.volume['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER_ID, 'sizeInKb': 8000000, 'mappedSdcInfo': None }, 200) }, self.RESPONSE_MODE.BadStatus: { 'instances/Volume::' + self.volume['provider_id']: mocks.MockHTTPSResponse( { 'errorCode': 401, 'message': 'BadStatus Volume Test', }, 401), 'instances/Volume::' + self.volume_attached['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER2_ID, 'sizeInKb': 8388608, 'mappedSdcInfo': 'Mapped' }, 200) } }
def test_get_volume_stats_v3(self, mock_version): self.driver.storage_pools = self.STORAGE_POOLS zero_data = { 'types/StoragePool/instances/action/querySelectedStatistics': mocks.MockHTTPSResponse(content=json.dumps( {'"{}"'.format(self.STORAGE_POOL_NAME): { 'snapCapacityInUseInKb': 0, 'thickCapacityInUseInKb': 0, 'netCapacityInUseInKb': 0, 'netUnusedCapacityInKb': 0, 'thinCapacityAllocatedInKb': 0} } )) } with self.custom_response_mode(**zero_data): stats = self.driver.get_volume_stats(True) for s in ["total_capacity_gb", "free_capacity_gb", "provisioned_capacity_gb"]: self.assertEqual(0, stats[s]) data = { 'types/StoragePool/instances/action/querySelectedStatistics': mocks.MockHTTPSResponse(content=json.dumps( {'"{}"'.format(self.STORAGE_POOL_NAME): { 'snapCapacityInUseInKb': 2097152, 'thickCapacityInUseInKb': 67108864, 'netCapacityInUseInKb': 34578432, 'netUnusedCapacityInKb': 102417408, 'thinCapacityAllocatedInKb': 218103808} } )) } with self.custom_response_mode(**data): stats = self.driver.get_volume_stats(True) self.assertEqual(130, stats['total_capacity_gb']) self.assertEqual(97, stats['free_capacity_gb']) self.assertEqual(137, stats['provisioned_capacity_gb'])
def setUp(self): """Setup a test case environment. Creates fake volume objects and sets up the required API responses. """ super(TestCreateClonedVolume, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.src_volume = fake_volume.fake_volume_obj( ctx, **{'provider_id': fake.PROVIDER_ID}) self.src_volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.src_volume.id))) self.new_volume_extras = { 'volumeIdList': ['cloned'], 'snapshotGroupId': 'cloned_snapshot' } self.new_volume = fake_volume.fake_volume_obj(ctx, **self.new_volume_extras) self.new_volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.new_volume.id))) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'types/Volume/instances/getByName::' + self.src_volume_name_2x_enc: self.src_volume.id, 'instances/System/action/snapshotVolumes': '{}'.format(json.dumps(self.new_volume_extras)), 'instances/Volume::cloned/action/setVolumeSize': None }, self.RESPONSE_MODE.BadStatus: { 'instances/System/action/snapshotVolumes': self.BAD_STATUS_RESPONSE, 'types/Volume/instances/getByName::' + self.src_volume['provider_id']: self.BAD_STATUS_RESPONSE, }, self.RESPONSE_MODE.Invalid: { 'types/Volume/instances/getByName::' + self.src_volume_name_2x_enc: None, 'instances/System/action/snapshotVolumes': mocks.MockHTTPSResponse( { 'errorCode': 400, 'message': 'Invalid Volume Snapshot Test' }, 400), }, }
def setUp(self): """Setup a test case environment. Creates fake volume and snapshot objects and sets up the required API responses. """ super(TestCreateVolumeFromSnapShot, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.snapshot = fake_snapshot.fake_snapshot_obj(ctx) self.snapshot_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.snapshot.id))) self.volume = fake_volume.fake_volume_obj(ctx) self.volume_name_2x_enc = urllib.parse.quote( urllib.parse.quote(flex_utils.id_to_base64(self.volume.id))) self.snapshot_reply = json.dumps({ 'volumeIdList': [self.volume.id], 'snapshotGroupId': 'snap_group' }) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: self.snapshot.id, 'instances/System/action/snapshotVolumes': self.snapshot_reply, 'instances/Volume::{}/action/setVolumeSize'.format(self.volume.id): None, }, self.RESPONSE_MODE.BadStatus: { 'instances/System/action/snapshotVolumes': self.BAD_STATUS_RESPONSE, 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: self.BAD_STATUS_RESPONSE, }, self.RESPONSE_MODE.Invalid: { 'instances/System/action/snapshotVolumes': mocks.MockHTTPSResponse( { 'errorCode': self.OLD_VOLUME_NOT_FOUND_ERROR, 'message': 'BadStatus Volume Test', }, 400), 'types/Volume/instances/getByName::' + self.snapshot_name_2x_enc: None, }, }
def get_https_response(self, api_path, mode=None): if mode is None: mode = self.__https_response_mode try: response = self.HTTPS_MOCK_RESPONSES[mode][api_path] except KeyError: try: response = self.__COMMON_HTTPS_MOCK_RESPONSES[mode][api_path] except KeyError: raise test.TestingException( 'Mock API Endpoint not implemented: [{}]{}'.format( self.__RESPONSE_MODE_NAMES[mode], api_path)) if not isinstance(response, mocks.MockHTTPSResponse): return mocks.MockHTTPSResponse(response, 200) return response
def setUp(self): """Setup a test case environment. Creates a fake volume object and sets up the required API responses. """ super(TestGroups, self).setUp() self.ctx = context.RequestContext('fake', 'fake', auth_token=True) self.fake_grp_snap = {'id': 'group_snap_id', 'name': 'test_group_snapshot', 'group_id': fake.GROUP_ID, 'status': fields.GroupSnapshotStatus.AVAILABLE } self.group = ( fake_group.fake_group_obj( self.ctx, **{'id': fake.GROUP_ID})) fake_volume1 = fake_volume.fake_volume_obj( self.ctx, **{'id': fake.VOLUME_ID, 'provider_id': fake.PROVIDER_ID}) fake_volume2 = fake_volume.fake_volume_obj( self.ctx, **{'id': fake.VOLUME2_ID, 'provider_id': fake.PROVIDER2_ID}) fake_volume3 = fake_volume.fake_volume_obj( self.ctx, **{'id': fake.VOLUME3_ID, 'provider_id': fake.PROVIDER3_ID}) fake_volume4 = fake_volume.fake_volume_obj( self.ctx, **{'id': fake.VOLUME4_ID, 'provider_id': fake.PROVIDER4_ID}) self.volumes = [fake_volume1, fake_volume2] self.volumes2 = [fake_volume3, fake_volume4] fake_snapshot1 = fake_snapshot.fake_snapshot_obj( self.ctx, **{'id': fake.SNAPSHOT_ID, 'volume_id': fake.VOLUME_ID, 'volume': fake_volume1}) fake_snapshot2 = fake_snapshot.fake_snapshot_obj( self.ctx, **{'id': fake.SNAPSHOT2_ID, 'volume_id': fake.VOLUME2_ID, 'volume': fake_volume2}) self.snapshots = [fake_snapshot1, fake_snapshot2] self.snapshot_reply = json.dumps({ 'volumeIdList': ['sid1', 'sid2'], 'snapshotGroupId': 'sgid1'}) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'instances/Volume::' + fake_volume1['provider_id']: {}, 'instances/Volume::' + fake_volume2['provider_id']: {}, 'instances/Volume::{}/action/removeVolume'.format( fake_volume1['provider_id'] ): fake_volume1['provider_id'], 'instances/Volume::{}/action/removeVolume'.format( fake_volume2['provider_id'] ): fake_volume2['provider_id'], 'instances/Volume::{}/action/removeMappedSdc'.format( fake_volume1['provider_id'] ): fake_volume1['provider_id'], 'instances/Volume::{}/action/removeMappedSdc'.format( fake_volume2['provider_id'] ): fake_volume2['provider_id'], 'instances/System/action/snapshotVolumes': self.snapshot_reply, }, self.RESPONSE_MODE.BadStatus: { 'instances/Volume::{}/action/removeVolume'.format( fake_volume1['provider_id'] ): mocks.MockHTTPSResponse( { 'errorCode': 401, 'message': 'BadStatus Volume Test', }, 401 ), 'instances/Volume::{}/action/removeVolume'.format( fake_volume2['provider_id'] ): mocks.MockHTTPSResponse( { 'errorCode': 401, 'message': 'BadStatus Volume Test', }, 401 ), 'instances/System/action/snapshotVolumes': self.BAD_STATUS_RESPONSE }, }
def setUp(self): """Set up the test case environment. Defines the mock HTTPS responses for the REST API calls. """ super(TestMisc, self).setUp() self.ctx = context.RequestContext('fake', 'fake', auth_token=True) self.volume = fake_volume.fake_volume_obj( self.ctx, **{'name': 'vol1', 'provider_id': fake.PROVIDER_ID} ) self.new_volume = fake_volume.fake_volume_obj( self.ctx, **{'name': 'vol2', 'provider_id': fake.PROVIDER2_ID} ) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'types/Domain/instances/getByName::{}'.format( self.PROT_DOMAIN_NAME ): '"{}"'.format(self.PROT_DOMAIN_ID), 'types/Pool/instances/getByName::{},{}'.format( self.PROT_DOMAIN_ID, self.STORAGE_POOL_NAME ): '"{}"'.format(self.STORAGE_POOL_ID), 'types/StoragePool/instances/action/querySelectedStatistics': { '"{}"'.format(self.STORAGE_POOL_NAME): { 'capacityAvailableForVolumeAllocationInKb': 5000000, 'capacityLimitInKb': 16000000, 'spareCapacityInKb': 6000000, 'thickCapacityInUseInKb': 266, 'thinCapacityAllocatedInKm': 0, 'snapCapacityInUseInKb': 266, }, }, 'instances/Volume::{}/action/setVolumeName'.format( self.volume['provider_id']): self.new_volume['provider_id'], 'instances/Volume::{}/action/setVolumeName'.format( self.new_volume['provider_id']): self.volume['provider_id'], 'version': '"{}"'.format('2.0.1'), 'instances/StoragePool::{}'.format( self.STORAGE_POOL_ID ): { 'name': self.STORAGE_POOL_NAME, 'id': self.STORAGE_POOL_ID, 'protectionDomainId': self.PROT_DOMAIN_ID, 'zeroPaddingEnabled': 'true', }, 'instances/ProtectionDomain::{}'.format( self.PROT_DOMAIN_ID ): { 'name': self.PROT_DOMAIN_NAME, 'id': self.PROT_DOMAIN_ID }, }, self.RESPONSE_MODE.BadStatus: { 'types/Domain/instances/getByName::' + self.PROT_DOMAIN_NAME: self.BAD_STATUS_RESPONSE, 'instances/Volume::{}/action/setVolumeName'.format( self.volume['provider_id']): mocks.MockHTTPSResponse( { 'message': 'Invalid volume.', 'httpStatusCode': 400, 'errorCode': self.VOLUME_NOT_FOUND_ERROR }, 400), }, self.RESPONSE_MODE.Invalid: { 'types/Domain/instances/getByName::' + self.PROT_DOMAIN_NAME: None, 'instances/Volume::{}/action/setVolumeName'.format( self.volume['provider_id']): mocks.MockHTTPSResponse( { 'message': 'Invalid volume.', 'httpStatusCode': 400, 'errorCode': 0 }, 400), }, }
class TestPowerFlexDriver(test.TestCase): """Base ``TestCase`` subclass for the ``PowerFlexDriver``""" RESPONSE_MODE = type( str('ResponseMode'), (object, ), dict( Valid='0', Invalid='1', BadStatus='2', ValidVariant='3', )) __RESPONSE_MODE_NAMES = { '0': 'Valid', '1': 'Invalid', '2': 'BadStatus', '3': 'ValidVariant', } BAD_STATUS_RESPONSE = mocks.MockHTTPSResponse( { 'errorCode': 500, 'message': 'BadStatus Response Test', }, 500) OLD_VOLUME_NOT_FOUND_ERROR = 78 VOLUME_NOT_FOUND_ERROR = 79 HTTPS_MOCK_RESPONSES = {} __COMMON_HTTPS_MOCK_RESPONSES = { RESPONSE_MODE.Valid: { 'login': '******', 'version': '3.5' }, RESPONSE_MODE.BadStatus: { 'login': mocks.MockHTTPSResponse( { 'errorCode': 403, 'message': 'Bad Login Response Test', }, 403), 'version': '3.5' }, } __https_response_mode = RESPONSE_MODE.Valid log = None STORAGE_POOL_ID = six.text_type('1') STORAGE_POOL_NAME = 'SP1' PROT_DOMAIN_ID = six.text_type('1') PROT_DOMAIN_NAME = 'PD1' STORAGE_POOLS = ['{}:{}'.format(PROT_DOMAIN_NAME, STORAGE_POOL_NAME)] def setUp(self): """Setup a test case environment. Creates a ``PowerFlexDriver`` instance Mocks the ``requests.get/post`` methods to return ``MockHTTPSResponse``'s instead. """ super(TestPowerFlexDriver, self).setUp() self.configuration = conf.Configuration(driver.powerflex_opts, conf.SHARED_CONF_GROUP) self._set_overrides() self.driver = mocks.PowerFlexDriver(configuration=self.configuration) self.driver.primary_client = mocks.PowerFlexClient(self.configuration) self.driver.secondary_client = mocks.PowerFlexClient( self.configuration, is_primary=False) self.driver.do_setup({}) self.mock_object(requests, 'get', self.do_request) self.mock_object(requests, 'post', self.do_request) self.driver.primary_client.do_setup() self.driver.secondary_client.do_setup() def _set_overrides(self): # Override the defaults to fake values self.override_config('san_ip', override='127.0.0.1', group=conf.SHARED_CONF_GROUP) self.override_config('powerflex_rest_server_port', override='8888', group=conf.SHARED_CONF_GROUP) self.override_config('san_login', override='test', group=conf.SHARED_CONF_GROUP) self.override_config('san_password', override='pass', group=conf.SHARED_CONF_GROUP) self.override_config('powerflex_storage_pools', override='PD1:SP1', group=conf.SHARED_CONF_GROUP) self.override_config('max_over_subscription_ratio', override=5.0, group=conf.SHARED_CONF_GROUP) self.override_config('powerflex_server_api_version', override='2.0.0', group=conf.SHARED_CONF_GROUP) def do_request(self, url, *args, **kwargs): """Do a fake GET/POST API request. Splits `url` on '/api/' to get the what API call is, then returns the value of `self.HTTPS_MOCK_RESPONSES[<response_mode>][<api_call>]` converting to a `MockHTTPSResponse` if necessary. :raises test.TestingException: If the current mode/api_call does not exist. :returns MockHTTPSResponse: """ return self.get_https_response(url.split('/api/')[1]) def set_https_response_mode(self, mode=RESPONSE_MODE.Valid): """Set the HTTPS response mode. RESPONSE_MODE.Valid: Respond with valid data RESPONSE_MODE.Invalid: Respond with invalid data RESPONSE_MODE.BadStatus: Response with not-OK status code. """ self.__https_response_mode = mode def get_https_response(self, api_path, mode=None): if mode is None: mode = self.__https_response_mode try: response = self.HTTPS_MOCK_RESPONSES[mode][api_path] except KeyError: try: response = self.__COMMON_HTTPS_MOCK_RESPONSES[mode][api_path] except KeyError: raise test.TestingException( 'Mock API Endpoint not implemented: [{}]{}'.format( self.__RESPONSE_MODE_NAMES[mode], api_path)) if not isinstance(response, mocks.MockHTTPSResponse): return mocks.MockHTTPSResponse(response, 200) return response @property def current_https_response_mode(self): return self.__https_response_mode def https_response_mode_name(self, mode): return self.__RESPONSE_MODE_NAMES[mode] def custom_response_mode(self, **kwargs): return CustomResponseMode(self, **kwargs)
def setUp(self): """Setup a test case environment. Creates a fake volume object and sets up the required API responses. """ super(TestManageExistingSnapshot, self).setUp() ctx = context.RequestContext('fake', 'fake', auth_token=True) self.volume = fake_volume.fake_volume_obj( ctx, **{'provider_id': fake.PROVIDER_ID}) self.snapshot = fake_snapshot.fake_snapshot_obj( ctx, **{'provider_id': fake.PROVIDER2_ID}) self.snapshot2 = fake_snapshot.fake_snapshot_obj( ctx, **{'provider_id': fake.PROVIDER3_ID}) self.snapshot.volume = self.snapshot2.volume = self.volume self.snapshot['volume_type_id'] = fake.VOLUME_TYPE_ID self.snapshot2['volume_type_id'] = fake.VOLUME_TYPE_ID self.snapshot_attached = fake_snapshot.fake_snapshot_obj( ctx, **{'provider_id': fake.PROVIDER4_ID}) self.HTTPS_MOCK_RESPONSES = { self.RESPONSE_MODE.Valid: { 'instances/Volume::' + self.volume['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER_ID, 'sizeInKb': 8388608, 'mappedSdcInfo': None, 'ancestorVolumeId': None }, 200), 'instances/Volume::' + self.snapshot['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER2_ID, 'sizeInKb': 8000000, 'mappedSdcInfo': None, 'ancestorVolumeId': fake.PROVIDER_ID }, 200), 'instances/Volume::' + self.snapshot2['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER3_ID, 'sizeInKb': 8388608, 'mappedSdcInfo': None, 'ancestorVolumeId': fake.PROVIDER2_ID }, 200) }, self.RESPONSE_MODE.BadStatus: { 'instances/Volume::' + self.snapshot['provider_id']: mocks.MockHTTPSResponse( { 'errorCode': 401, 'message': 'BadStatus Volume Test', }, 401), 'instances/Volume::' + self.snapshot2['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER3_ID, 'sizeInKb': 8388608, 'ancestorVolumeId': fake.PROVIDER2_ID }, 200), 'instances/Volume::' + self.snapshot_attached['provider_id']: mocks.MockHTTPSResponse( { 'id': fake.PROVIDER4_ID, 'sizeInKb': 8388608, 'mappedSdcInfo': 'Mapped', 'ancestorVolumeId': fake.PROVIDER_ID }, 200) } }