blob: 89c48775c9aa6a059829ad4c9da9b6e3b28615b5 [file] [log] [blame]
Mark Vanderwiel6d8e0862015-10-15 12:51:07 -05001#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
Mark Vanderwiel2e923a72015-10-19 16:12:05 -050014import time
15
16import requests
17
18from heat_integrationtests.common import test
Mark Vanderwiel6d8e0862015-10-15 12:51:07 -050019from heat_integrationtests.scenario import scenario_base
20
21
22class AutoscalingLoadBalancerv2Test(scenario_base.ScenarioTestsBase):
23 """The class is responsible for testing ASG + LBv2 scenario.
24
25 The very common use case tested is an autoscaling group
26 of some web application servers behind a loadbalancer.
27 """
28
29 def setUp(self):
30 super(AutoscalingLoadBalancerv2Test, self).setUp()
31 self.template_name = 'test_autoscaling_lbv2_neutron.yaml'
32 self.app_server_template_name = 'app_server_lbv2_neutron.yaml'
33 self.webapp_template_name = 'netcat-webapp.yaml'
34 if not self.is_network_extension_supported('lbaasv2'):
35 self.skipTest('LBaasv2 extension not available, skipping')
36
Mark Vanderwiel2e923a72015-10-19 16:12:05 -050037 def check_num_responses(self, url, expected_num, retries=20):
38 resp = set()
39 for count in range(retries):
40 time.sleep(2)
41 try:
42 r = requests.get(url, verify=self.verify_cert)
43 except requests.exceptions.ConnectionError:
44 # The LB may not be up yet, let's retry
45 continue
46 # skip unsuccessful requests
47 if r.status_code == 200:
48 resp.add(r.text)
49 self.assertEqual(expected_num, len(resp))
50
51 def autoscale_complete(self, stack_id, expected_num):
52 res_list = self.client.resources.list(stack_id)
53 all_res_complete = all(res.resource_status in ('UPDATE_COMPLETE',
54 'CREATE_COMPLETE')
55 for res in res_list)
56 all_res = len(res_list) == expected_num
57 return all_res and all_res_complete
58
Mark Vanderwiel6d8e0862015-10-15 12:51:07 -050059 def test_autoscaling_loadbalancer_neutron(self):
60 """Check work of AutoScaing and Neutron LBaaS v2 resource in Heat.
61
62 The scenario is the following:
63 1. Launch a stack with a load balancer and autoscaling group
64 of one server, wait until stack create is complete.
65 2. Check that there is only one distinctive response from
66 loadbalanced IP.
67 3. Signal the scale_up policy, wait until all resources in
68 autoscaling group are complete.
69 4. Check that now there are two distinctive responses from
70 loadbalanced IP.
71 """
72
Mark Vanderwiel2e923a72015-10-19 16:12:05 -050073 parameters = {
74 'flavor': self.conf.minimal_instance_type,
75 'image': self.conf.minimal_image_ref,
76 'net': self.conf.fixed_network_name,
77 'subnet': self.conf.fixed_subnet_name,
78 'public_net': self.conf.floating_network_name
79 }
80
81 app_server_template = self._load_template(
82 __file__, self.app_server_template_name, self.sub_dir
83 )
84 webapp_template = self._load_template(
85 __file__, self.webapp_template_name, self.sub_dir
86 )
87 files = {'appserver.yaml': app_server_template,
88 'webapp.yaml': webapp_template}
89 env = {'resource_registry':
90 {'OS::Test::NeutronAppServer': 'appserver.yaml',
91 'OS::Test::WebAppConfig': 'webapp.yaml'}}
92
93 # Launch stack
94 sid = self.launch_stack(
95 template_name=self.template_name,
96 parameters=parameters,
97 files=files,
98 environment=env
99 )
100 stack = self.client.stacks.get(sid)
101 lb_url = self._stack_output(stack, 'lburl')
102 # Check number of distinctive responces, must be 1
103 self.check_num_responses(lb_url, 1)
104
105 # Signal the scaling hook
106 self.client.resources.signal(sid, 'scale_up')
107
108 # Wait for AutoScalingGroup update to finish
109 asg = self.client.resources.get(sid, 'asg')
110 test.call_until_true(self.conf.build_timeout,
111 self.conf.build_interval,
112 self.autoscale_complete,
113 asg.physical_resource_id, 2)
114
115 # Check number of distinctive responses, must now be 2
116 self.check_num_responses(lb_url, 2)