Ejemplo n.º 1
0
    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),
            },
        }
Ejemplo n.º 2
0
    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),
            },
        }
Ejemplo n.º 3
0
    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,
                )
            },
        }
Ejemplo n.º 4
0
    def rename_volume(self, volume, name):
        url = "/instances/Volume::%(id)s/action/setVolumeName"

        new_name = flex_utils.id_to_base64(name)
        vol_id = volume["provider_id"]
        params = {"newName": new_name}
        r, response = self.execute_vxflexos_post_request(url,
                                                         params,
                                                         id=vol_id)
        if r.status_code != http_client.OK:
            error_code = response["errorCode"]
            if ((error_code == VOLUME_NOT_FOUND_ERROR
                 or error_code == OLD_VOLUME_NOT_FOUND_ERROR
                 or error_code == ILLEGAL_SYNTAX)):
                LOG.info(
                    "Ignore renaming action because the volume "
                    "%(vol_id)s is not a VxFlex OS volume.",
                    {"vol_id": vol_id})
            else:
                msg = (_("Failed to rename volume %(vol_id)s: %(err)s.") % {
                    "vol_id": vol_id,
                    "err": response["message"]
                })
                LOG.error(msg)
                raise exception.VolumeBackendAPIException(data=msg)
        else:
            LOG.info(
                "VxFlex OS volume %(vol_id)s was renamed to "
                "%(new_name)s.", {
                    "vol_id": vol_id,
                    "new_name": new_name
                })
Ejemplo n.º 5
0
    def create_volume(self, protection_domain_name, storage_pool_name,
                      volume_id, volume_size, provisioning, compression):
        url = "/types/Volume/instances"

        domain_id = self._get_protection_domain_id(protection_domain_name)
        LOG.info("Protection Domain id: %s.", domain_id)
        pool_id = self.get_storage_pool_id(protection_domain_name,
                                           storage_pool_name)
        LOG.info("Storage Pool id: %s.", pool_id)
        volume_name = flex_utils.id_to_base64(volume_id)
        # units.Mi = 1024 ** 2
        volume_size_kb = volume_size * units.Mi
        params = {
            "protectionDomainId": domain_id,
            "storagePoolId": pool_id,
            "name": volume_name,
            "volumeType": provisioning,
            "volumeSizeInKb": six.text_type(volume_size_kb),
            "compressionMethod": compression,
        }
        r, response = self.execute_vxflexos_post_request(url, params)
        if r.status_code != http_client.OK and "errorCode" in response:
            msg = (_("Failed to create volume: %s.") % response["message"])
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        return response["id"]
Ejemplo n.º 6
0
    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,
            },
        }
Ejemplo n.º 7
0
    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),
            },
        }
Ejemplo n.º 8
0
    def snapshot_volume(self, volume_provider_id, snapshot_id):
        url = "/instances/System/action/snapshotVolumes"

        snap_name = flex_utils.id_to_base64(snapshot_id)
        params = {
            "snapshotDefs": [
                {
                    "volumeId": volume_provider_id,
                    "snapshotName": snap_name,
                },
            ],
        }
        r, response = self.execute_vxflexos_post_request(url, params)
        if r.status_code != http_client.OK and "errorCode" in response:
            msg = (_("Failed to create snapshot for volume %(vol_name)s: "
                     "%(response)s.") %
                   {"vol_name": volume_provider_id,
                    "response": response["message"]})
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        return response["volumeIdList"][0]
Ejemplo n.º 9
0
    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)
            }
        }