blob: 21b27dd526ae65ad8aa699bc3b7085ee8b20fbd9 [file] [log] [blame]
Pavlo Shchelokovskyy9ede1852015-03-19 17:54:52 +00001#
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
14import time
15
16import requests
17
18from heat_integrationtests.common import test
19from heat_integrationtests.scenario import scenario_base
20
21
22class AutoscalingLoadBalancerTest(scenario_base.ScenarioTestsBase):
23 """
24 The class is responsible for testing ASG + LB scenario.
25
26 The very common use case tested is an autoscaling group
27 of some web application servers behind a loadbalancer.
28 """
29
30 def setUp(self):
31 super(AutoscalingLoadBalancerTest, self).setUp()
32 self.template_name = 'test_autoscaling_lb_neutron.yaml'
33 self.app_server_template_name = 'app_server_neutron.yaml'
34 self.webapp_template_name = 'netcat-webapp.yaml'
35
36 def check_num_responses(self, url, expected_num, retries=10):
37 resp = set()
38 for count in range(retries):
39 time.sleep(1)
40 r = requests.get(url)
41 # skip unsuccessfull requests
42 if r.status_code == 200:
43 resp.add(r.text)
44 self.assertEqual(expected_num, len(resp))
45
46 def autoscale_complete(self, stack_id, expected_num):
47 res_list = self.client.resources.list(stack_id)
48 all_res_complete = all(res.resource_status in ('UPDATE_COMPLETE',
49 'CREATE_COMPLETE')
50 for res in res_list)
51 all_res = len(res_list) == expected_num
52 return all_res and all_res_complete
53
54 def test_autoscaling_loadbalancer_neutron(self):
55 """
56 Check work of AutoScaing and Neutron LBaaS resource in Heat.
57
58 The scenario is the following:
59 1. Launch a stack with a load balancer and autoscaling group
60 of one server, wait until stack create is complete.
61 2. Check that there is only one distinctive response from
62 loadbalanced IP.
63 3. Signal the scale_up policy, wait until all resources in
64 autoscaling group are complete.
65 4. Check that now there are two distinctive responses from
66 loadbalanced IP.
67 """
68
69 parameters = {
70 'flavor': self.conf.minimal_instance_type,
71 'image': self.conf.minimal_image_ref,
72 'net': self.conf.fixed_network_name,
73 'subnet': self.conf.fixed_subnet_name,
74 'public_net': self.conf.floating_network_name,
75 'app_port': 8080,
76 'lb_port': 80,
77 'timeout': 600
78 }
79
80 app_server_template = self._load_template(
81 __file__, self.app_server_template_name, self.sub_dir
82 )
83 webapp_template = self._load_template(
84 __file__, self.webapp_template_name, self.sub_dir
85 )
86 files = {'appserver.yaml': app_server_template,
87 'webapp.yaml': webapp_template}
88 env = {'resource_registry':
89 {'OS::Test::NeutronAppServer': 'appserver.yaml',
90 'OS::Test::WebAppConfig': 'webapp.yaml'}}
91 # Launch stack
92 sid = self.launch_stack(
93 template_name=self.template_name,
94 parameters=parameters,
95 files=files,
96 environment=env
97 )
98 stack = self.client.stacks.get(sid)
99 lb_url = self._stack_output(stack, 'lburl')
100 # Check number of distinctive responces, must be 1
101 self.check_num_responses(lb_url, 1)
102
103 # Signal the scaling hook
104 self.client.resources.signal(sid, 'scale_up')
105
106 # Wait for AutoScalingGroup update to finish
107 asg = self.client.resources.get(sid, 'asg')
108 test.call_until_true(self.conf.build_timeout,
109 self.conf.build_interval,
110 self.autoscale_complete,
111 asg.physical_resource_id, 2)
112
113 # Check number of distinctive responses, must now be 2
114 self.check_num_responses(lb_url, 2)