Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 1 | # |
| 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 | |
| 14 | import time |
| 15 | |
| 16 | import requests |
| 17 | |
| 18 | from heat_integrationtests.common import test |
| 19 | from heat_integrationtests.scenario import scenario_base |
| 20 | |
| 21 | |
| 22 | class AutoscalingLoadBalancerTest(scenario_base.ScenarioTestsBase): |
Mark Vanderwiel | 6d8e086 | 2015-10-15 12:51:07 -0500 | [diff] [blame] | 23 | """The class is responsible for testing ASG + LBv1 scenario. |
Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 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(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' |
Mark Vanderwiel | 6d8e086 | 2015-10-15 12:51:07 -0500 | [diff] [blame] | 34 | if not self.is_network_extension_supported('lbaas'): |
| 35 | self.skipTest('LBaas v1 extension not available, skipping') |
Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 36 | |
| 37 | def check_num_responses(self, url, expected_num, retries=10): |
| 38 | resp = set() |
| 39 | for count in range(retries): |
| 40 | time.sleep(1) |
Thomas Herve | 983fcf6 | 2016-02-18 13:15:37 +0100 | [diff] [blame] | 41 | try: |
tyagi | 39aa11a | 2016-03-07 04:47:00 -0800 | [diff] [blame] | 42 | r = requests.get(url, verify=self.verify_cert) |
Thomas Herve | 983fcf6 | 2016-02-18 13:15:37 +0100 | [diff] [blame] | 43 | except requests.exceptions.ConnectionError: |
| 44 | # The LB may not be up yet, let's retry |
| 45 | continue |
venkatamahesh | a9d3fdd | 2016-02-03 13:18:17 +0530 | [diff] [blame] | 46 | # skip unsuccessful requests |
Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 47 | if r.status_code == 200: |
| 48 | resp.add(r.text) |
| 49 | self.assertEqual(expected_num, len(resp)) |
| 50 | |
Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 51 | def test_autoscaling_loadbalancer_neutron(self): |
Mark Vanderwiel | 6d8e086 | 2015-10-15 12:51:07 -0500 | [diff] [blame] | 52 | """Check work of AutoScaing and Neutron LBaaS v1 resource in Heat. |
Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 53 | |
| 54 | The scenario is the following: |
| 55 | 1. Launch a stack with a load balancer and autoscaling group |
| 56 | of one server, wait until stack create is complete. |
| 57 | 2. Check that there is only one distinctive response from |
| 58 | loadbalanced IP. |
| 59 | 3. Signal the scale_up policy, wait until all resources in |
| 60 | autoscaling group are complete. |
| 61 | 4. Check that now there are two distinctive responses from |
| 62 | loadbalanced IP. |
| 63 | """ |
| 64 | |
| 65 | parameters = { |
| 66 | 'flavor': self.conf.minimal_instance_type, |
| 67 | 'image': self.conf.minimal_image_ref, |
| 68 | 'net': self.conf.fixed_network_name, |
| 69 | 'subnet': self.conf.fixed_subnet_name, |
| 70 | 'public_net': self.conf.floating_network_name, |
| 71 | 'app_port': 8080, |
| 72 | 'lb_port': 80, |
| 73 | 'timeout': 600 |
| 74 | } |
| 75 | |
| 76 | app_server_template = self._load_template( |
| 77 | __file__, self.app_server_template_name, self.sub_dir |
| 78 | ) |
| 79 | webapp_template = self._load_template( |
| 80 | __file__, self.webapp_template_name, self.sub_dir |
| 81 | ) |
| 82 | files = {'appserver.yaml': app_server_template, |
| 83 | 'webapp.yaml': webapp_template} |
| 84 | env = {'resource_registry': |
| 85 | {'OS::Test::NeutronAppServer': 'appserver.yaml', |
| 86 | 'OS::Test::WebAppConfig': 'webapp.yaml'}} |
| 87 | # Launch stack |
| 88 | sid = self.launch_stack( |
| 89 | template_name=self.template_name, |
| 90 | parameters=parameters, |
| 91 | files=files, |
| 92 | environment=env |
| 93 | ) |
| 94 | stack = self.client.stacks.get(sid) |
| 95 | lb_url = self._stack_output(stack, 'lburl') |
| 96 | # Check number of distinctive responces, must be 1 |
| 97 | self.check_num_responses(lb_url, 1) |
| 98 | |
| 99 | # Signal the scaling hook |
| 100 | self.client.resources.signal(sid, 'scale_up') |
| 101 | |
| 102 | # Wait for AutoScalingGroup update to finish |
| 103 | asg = self.client.resources.get(sid, 'asg') |
| 104 | test.call_until_true(self.conf.build_timeout, |
| 105 | self.conf.build_interval, |
Rakesh H S | c5735a8 | 2016-04-28 15:38:09 +0530 | [diff] [blame] | 106 | self.check_autoscale_complete, |
Pavlo Shchelokovskyy | 9ede185 | 2015-03-19 17:54:52 +0000 | [diff] [blame] | 107 | asg.physical_resource_id, 2) |
| 108 | |
| 109 | # Check number of distinctive responses, must now be 2 |
| 110 | self.check_num_responses(lb_url, 2) |