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