<commit_before># Copyright 2015 Cloudbase Solutions Srl
# All Rights Reserved.
#
#    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.


import abc
import os
import unittest

import six

from argus import util
from argus.backends import base as base_backend

with util.restore_excepthook():
    from tempest import clients
    from tempest.common import credentials
    from tempest.common import waiters


CONF = util.get_config()
LOG = util.get_logger()

# Starting size as number of lines and tolerance.
OUTPUT_SIZE = 128
OUTPUT_EPSILON = int(OUTPUT_SIZE / 10)
OUTPUT_STATUS_OK = [200]


@six.add_metaclass(abc.ABCMeta)
class BaseTempestScenario(base_backend.BaseBackend):
    """Base class for scenarios that use the tempest backend"""

    def __init__(self):
        self._userdata = None
        self._metadata = None
        self._server = None
        self._keypair = None
        self._security_group = None
        self._security_groups_rules = []
        self._subnets = []
        self._routers = []
        self._floating_ip = None
        self._networks = None    # list with UUIDs for future attached NICs

    def _prepare_run(self):
        # pylint: disable=attribute-defined-outside-init
        self._isolated_creds = credentials.get_isolated_credentials(
            self.__class__.__name__, network_resources={})
        self._manager = clients.Manager(credentials=self._credentials())

        # Clients (in alphabetical order)
        self._flavors_client = self._manager.flavors_client
        self._floating_ips_client = self._manager.floating_ips_client

        # Glance image client v1
        self._image_client = self._manager.image_client

        # Compute image client
        self._images_client = self._manager.images_client
        self._keypairs_client = self._manager.keypairs_client

        # Nova security groups client
        self._security_groups_client = self._manager.security_groups_client
        self._servers_client = self._manager.servers_client
        self._volumes_client = self._manager.volumes_client
        self._snapshots_client = self._manager.snapshots_client
        self._interface_client = self._manager.interfaces_client

        # Neutron network client
        self._network_client = self._manager.network_client

        # Heat client
        self._orchestration_client = self._manager.orchestration_client

    def _credentials(self):
        return self._isolated_creds.get_primary_creds()

    def _configure_networking(self):
        subnet_id = self._credentials().subnet["id"]
        self._network_client.update_subnet(
            subnet_id,
            dns_nameservers=CONF.argus.dns_nameservers)

    def _create_server(self, wait_until='ACTIVE', **kwargs):
        server = self._servers_client.create_server(
            util.rand_name(self.__class__.__name__) + "-instance",
            self._image.image_ref,
            self._image.flavor_ref,
            **kwargs)
        waiters.wait_for_server_status(
            self._servers_client, server['id'], wait_until)
        return server

    def _create_keypair(self):<commit_msg>bug fixes<commit_after># Copyright 2015 Cloudbase Solutions Srl
# All Rights Reserved.
#
#    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.


import abc
import os
import unittest

import six

from argus import util
from argus.backends import base as base_backend

with util.restore_excepthook():
    from tempest import clients
    from tempest.common import credentials
    from tempest.common import waiters


CONF = util.get_config()
LOG = util.get_logger()

# Starting size as number of lines and tolerance.
OUTPUT_SIZE = 128
OUTPUT_EPSILON = int(OUTPUT_SIZE / 10)
OUTPUT_STATUS_OK = [200]


@six.add_metaclass(abc.ABCMeta)
class BaseTempestScenario(base_backend.BaseBackend):
    """Base class for scenarios that use the tempest backend"""

    def __init__(self):
        self._userdata = None
        self._metadata = None
        self._server = None
        self._keypair = None
        self._security_group = None
        self._security_groups_rules = []
        self._subnets = []
        self._routers = []
        self._floating_ip = None
        self._networks = None    # list with UUIDs for future attached NICs

    def _prepare_run(self):
        # pylint: disable=attribute-defined-outside-init
        self._isolated_creds = credentials.get_isolated_credentials(
            self.__class__.__name__, network_resources={})
        self._manager = clients.Manager(credentials=self._credentials())

        # Clients (in alphabetical order)
        self._flavors_client = self._manager.flavors_client
        self._floating_ips_client = self._manager.floating_ips_client

        # Glance image client v1
        self._image_client = self._manager.image_client

        # Compute image client
        self._images_client = self._manager.images_client
        self._keypairs_client = self._manager.keypairs_client

        # Nova security groups client
        self._security_groups_client = self._manager.security_groups_client
        self._servers_client = self._manager.servers_client
        self._volumes_client = self._manager.volumes_client
        self._snapshots_client = self._manager.snapshots_client
        self._interface_client = self._manager.interfaces_client

        # Neutron network client
        self._network_client = self._manager.network_client

        # Heat client
        self._orchestration_client = self._manager.orchestration_client

    def _credentials(self):
        return self._isolated_creds.get_primary_creds()

    def _configure_networking(self):
        subnet_id = self._credentials().subnet["id"]
        self._network_client.update_subnet(
            subnet_id,
            dns_nameservers=CONF.argus.dns_nameservers)

    def _create_server(self, wait_until='ACTIVE', **kwargs):
        server = self._servers_client.create_server(
            util.rand_name(self.__class__.__name__) + "-instance",
            **kwargs)
        waiters.wait_for_server_status(
            self._servers_client, server['id'], wait_until)
        return server

    def _create_keypair(self):
{'fraction_non_alphanumeric': 0.07423884331989435, 'fraction_numerical': 0.004726817739468928, 'mean_word_length': 3.032511210762332, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5303735', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1992, 'n_words': 518}