<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.

import time

import requests

from heat_integrationtests.common import test
from heat_integrationtests.scenario import scenario_base


class AutoscalingLoadBalancerTest(scenario_base.ScenarioTestsBase):
    """The class is responsible for testing ASG + LBv1 scenario.

    The very common use case tested is an autoscaling group
    of some web application servers behind a loadbalancer.
    """

    def setUp(self):
        super(AutoscalingLoadBalancerTest, self).setUp()
        self.template_name = 'test_autoscaling_lb_neutron.yaml'
        self.app_server_template_name = 'app_server_neutron.yaml'
        self.webapp_template_name = 'netcat-webapp.yaml'
        if not self.is_network_extension_supported('lbaas'):
            self.skipTest('LBaas v1 extension not available, skipping')

    def check_num_responses(self, url, expected_num, retries=10):
        resp = set()
        for count in range(retries):
            time.sleep(1)
            r = requests.get(url)
            # skip unsuccessful requests
            if r.status_code == 200:
                resp.add(r.text)
        self.assertEqual(expected_num, len(resp))

    def autoscale_complete(self, stack_id, expected_num):
        res_list = self.client.resources.list(stack_id)
        all_res_complete = all(res.resource_status in ('UPDATE_COMPLETE',
                                                       'CREATE_COMPLETE')
                               for res in res_list)
        all_res = len(res_list) == expected_num
        return all_res and all_res_complete<commit_msg>Ignore connection error when testing load balancer<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.

import time

import requests

from heat_integrationtests.common import test
from heat_integrationtests.scenario import scenario_base


class AutoscalingLoadBalancerTest(scenario_base.ScenarioTestsBase):
    """The class is responsible for testing ASG + LBv1 scenario.

    The very common use case tested is an autoscaling group
    of some web application servers behind a loadbalancer.
    """

    def setUp(self):
        super(AutoscalingLoadBalancerTest, self).setUp()
        self.template_name = 'test_autoscaling_lb_neutron.yaml'
        self.app_server_template_name = 'app_server_neutron.yaml'
        self.webapp_template_name = 'netcat-webapp.yaml'
        if not self.is_network_extension_supported('lbaas'):
            self.skipTest('LBaas v1 extension not available, skipping')

    def check_num_responses(self, url, expected_num, retries=10):
        resp = set()
        for count in range(retries):
            time.sleep(1)
            try:
                r = requests.get(url)
            except requests.exceptions.ConnectionError:
                # The LB may not be up yet, let's retry
                continue
            # skip unsuccessful requests
            if r.status_code == 200:
                resp.add(r.text)
        self.assertEqual(expected_num, len(resp))

    def autoscale_complete(self, stack_id, expected_num):
        res_list = self.client.resources.list(stack_id)
        all_res_complete = all(res.resource_status in ('UPDATE_COMPLETE',
                                                       'CREATE_COMPLETE')
                               for res in res_list)
        all_res = len(res_list) == expected_num
        return all_res and all_res_complete
{'fraction_non_alphanumeric': 0.07028969234224118, 'fraction_numerical': 0.005389624971929036, 'mean_word_length': 2.758649789029536, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6197886', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1183, 'n_words': 386}