<commit_before>#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest.api.volume import base
from tempest.common.utils import data_utils
from tempest import config
from tempest.openstack.common import log as logging
from tempest.services.volume.json.admin import volume_types_client
from tempest.services.volume.json import volumes_client
from tempest.test import attr

CONF = config.CONF

LOG = logging.getLogger(__name__)


class VolumeMultiBackendTest(base.BaseVolumeV1AdminTest):
    _interface = "json"

    @classmethod
    def setUpClass(cls):
        super(VolumeMultiBackendTest, cls).setUpClass()
        if not CONF.volume_feature_enabled.multi_backend:
            cls.tearDownClass()
            raise cls.skipException("Cinder multi-backend feature disabled")

        cls.backend1_name = CONF.volume.backend1_name
        cls.backend2_name = CONF.volume.backend2_name

        adm_user = CONF.identity.admin_username
        adm_pass = CONF.identity.admin_password
        adm_tenant = CONF.identity.admin_tenant_name
        auth_url = CONF.identity.uri

        cls.volume_client = volumes_client.VolumesClientJSON(adm_user,
                                                             adm_pass,
                                                             auth_url,
                                                             adm_tenant)
        cls.type_client = volume_types_client.VolumeTypesClientJSON(adm_user,
                                                                    adm_pass,
                                                                    auth_url,
                                                                    adm_tenant)

        cls.volume_type_id_list = []
        cls.volume_id_list = []
        try:
            # Volume/Type creation (uses backend1_name)
            type1_name = data_utils.rand_name('Type-')
            vol1_name = data_utils.rand_name('Volume-')
            extra_specs1 = {"volume_backend_name": cls.backend1_name}
            resp, cls.type1 = cls.type_client.create_volume_type(
                type1_name, extra_specs=extra_specs1)
            cls.volume_type_id_list.append(cls.type1['id'])

            resp, cls.volume1 = cls.volume_client.create_volume(
                size=1, display_name=vol1_name, volume_type=type1_name)
            cls.volume_id_list.append(cls.volume1['id'])
            cls.volume_client.wait_for_volume_status(cls.volume1['id'],
                                                     'available')

            if cls.backend1_name != cls.backend2_name:
                # Volume/Type creation (uses backend2_name)
                type2_name = data_utils.rand_name('Type-')
                vol2_name = data_utils.rand_name('Volume-')
                extra_specs2 = {"volume_backend_name": cls.backend2_name}
                resp, cls.type2 = cls.type_client.create_volume_type(
                    type2_name, extra_specs=extra_specs2)
                cls.volume_type_id_list.append(cls.type2['id'])

                resp, cls.volume2 = cls.volume_client.create_volume(
                    size=1, display_name=vol2_name, volume_type=type2_name)
                cls.volume_id_list.append(cls.volume2['id'])
                cls.volume_client.wait_for_volume_status(cls.volume2['id'],
                                                         'available')
        except Exception as e:
            LOG.exception("setup failed: %s" % e)
            cls.tearDownClass()
            raise

    @classmethod
    def tearDownClass(cls):
        # volumes deletion
        volume_id_list = getattr(cls, 'volume_id_list', [])
        for volume_id in volume_id_list:
            cls.volume_client.delete_volume(volume_id)
            cls.volume_client.wait_for_resource_deletion(volume_id)

        # volume types deletion
        volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
        for volume_type_id in volume_type_id_list:
            cls.type_client.delete_volume_type(volume_type_id)

        super(VolumeMultiBackendTest, cls).tearDownClass()<commit_msg>Fix client usage in multibackend volume test<commit_after>#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest.api.volume import base
from tempest.common.utils import data_utils
from tempest import config
from tempest.openstack.common import log as logging
from tempest.test import attr

CONF = config.CONF

LOG = logging.getLogger(__name__)


class VolumeMultiBackendTest(base.BaseVolumeV1AdminTest):
    _interface = "json"

    @classmethod
    def setUpClass(cls):
        super(VolumeMultiBackendTest, cls).setUpClass()
        if not CONF.volume_feature_enabled.multi_backend:
            cls.tearDownClass()
            raise cls.skipException("Cinder multi-backend feature disabled")

        cls.backend1_name = CONF.volume.backend1_name
        cls.backend2_name = CONF.volume.backend2_name

        cls.volume_client = cls.os_adm.volumes_client
        cls.volume_type_id_list = []
        cls.volume_id_list = []
        try:
            # Volume/Type creation (uses backend1_name)
            type1_name = data_utils.rand_name('Type-')
            vol1_name = data_utils.rand_name('Volume-')
            extra_specs1 = {"volume_backend_name": cls.backend1_name}
            resp, cls.type1 = cls.client.create_volume_type(
                type1_name, extra_specs=extra_specs1)
            cls.volume_type_id_list.append(cls.type1['id'])

            resp, cls.volume1 = cls.volume_client.create_volume(
                size=1, display_name=vol1_name, volume_type=type1_name)
            cls.volume_id_list.append(cls.volume1['id'])
            cls.volume_client.wait_for_volume_status(cls.volume1['id'],
                                                     'available')

            if cls.backend1_name != cls.backend2_name:
                # Volume/Type creation (uses backend2_name)
                type2_name = data_utils.rand_name('Type-')
                vol2_name = data_utils.rand_name('Volume-')
                extra_specs2 = {"volume_backend_name": cls.backend2_name}
                resp, cls.type2 = cls.client.create_volume_type(
                    type2_name, extra_specs=extra_specs2)
                cls.volume_type_id_list.append(cls.type2['id'])

                resp, cls.volume2 = cls.volume_client.create_volume(
                    size=1, display_name=vol2_name, volume_type=type2_name)
                cls.volume_id_list.append(cls.volume2['id'])
                cls.volume_client.wait_for_volume_status(cls.volume2['id'],
                                                         'available')
        except Exception as e:
            LOG.exception("setup failed: %s" % e)
            cls.tearDownClass()
            raise

    @classmethod
    def tearDownClass(cls):
        # volumes deletion
        volume_id_list = getattr(cls, 'volume_id_list', [])
        for volume_id in volume_id_list:
            cls.volume_client.delete_volume(volume_id)
            cls.volume_client.wait_for_resource_deletion(volume_id)

        # volume types deletion
        volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
        for volume_type_id in volume_type_id_list:
            cls.client.delete_volume_type(volume_type_id)

        super(VolumeMultiBackendTest, cls).tearDownClass()
{'fraction_non_alphanumeric': 0.07874298004540567, 'fraction_numerical': 0.009798064284860795, 'mean_word_length': 2.1430717236199777, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '245691', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2312, 'n_words': 477}