Anastasia Kuznetsova | 3e0ab4d | 2015-03-06 18:10:13 +0400 | [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 | import urllib |
| 16 | |
| 17 | from heat_integrationtests.scenario import scenario_base |
| 18 | |
| 19 | |
| 20 | class NeutronLoadBalancerTest(scenario_base.ScenarioTestsBase): |
| 21 | """ |
| 22 | The class is responsible for testing of neutron resources balancer. |
| 23 | """ |
| 24 | |
| 25 | def setUp(self): |
| 26 | super(NeutronLoadBalancerTest, self).setUp() |
Pavlo Shchelokovskyy | 6fa2380 | 2015-03-23 11:22:35 +0000 | [diff] [blame] | 27 | self.public_net = self._get_network(self.conf.floating_network_name) |
Anastasia Kuznetsova | 3e0ab4d | 2015-03-06 18:10:13 +0400 | [diff] [blame] | 28 | self.template_name = 'test_neutron_loadbalancer.yaml' |
| 29 | |
| 30 | def collect_responses(self, ip, expected_resp): |
| 31 | resp = set() |
| 32 | for count in range(10): |
| 33 | time.sleep(1) |
| 34 | resp.add(urllib.urlopen('http://%s/' % ip).read()) |
| 35 | |
| 36 | self.assertEqual(expected_resp, resp) |
| 37 | |
| 38 | def test_neutron_loadbalancer(self): |
| 39 | """ |
| 40 | Check work of Neutron LBaaS resource in Heat. |
| 41 | |
| 42 | The alternative scenario is the following: |
| 43 | 1. Launch a stack with a load balancer, two servers, |
| 44 | but use only one as a LB member. |
| 45 | 2. Check connection to the servers and LB. |
| 46 | 3. Collect info about responces, which were received by LB from |
| 47 | its members (responces have to be received only from 'server1'). |
| 48 | 4. Update stack definition: include 'server2' into LBaaS. |
| 49 | 5. Check that number of members in LB was increased and |
| 50 | responces were received from 'server1' and 'server2'. |
| 51 | """ |
| 52 | |
| 53 | parameters = { |
| 54 | 'key_name': self.keypair_name, |
Pavlo Shchelokovskyy | 46e5cb2 | 2015-03-23 12:01:25 +0000 | [diff] [blame] | 55 | 'flavor': self.conf.minimal_instance_type, |
Anastasia Kuznetsova | 3e0ab4d | 2015-03-06 18:10:13 +0400 | [diff] [blame] | 56 | 'image': self.conf.image_ref, |
| 57 | 'private_subnet_id': self.net['subnets'][0], |
Rabi Mishra | 7205fee | 2015-04-06 07:57:34 +0530 | [diff] [blame^] | 58 | 'external_network_id': self.public_net['id'], |
| 59 | 'timeout': self.conf.build_timeout |
Anastasia Kuznetsova | 3e0ab4d | 2015-03-06 18:10:13 +0400 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | # Launch stack |
| 63 | sid = self.launch_stack( |
| 64 | template_name=self.template_name, |
| 65 | parameters=parameters |
| 66 | ) |
| 67 | |
Sergey Kraynev | e0ad363 | 2015-03-19 11:34:32 -0400 | [diff] [blame] | 68 | stack = self.client.stacks.get(sid) |
| 69 | floating_ip = self._stack_output(stack, 'fip') |
| 70 | vip = self._stack_output(stack, 'vip') |
| 71 | server1_ip = self._stack_output(stack, 'serv1_ip') |
| 72 | server2_ip = self._stack_output(stack, 'serv2_ip') |
Anastasia Kuznetsova | 3e0ab4d | 2015-03-06 18:10:13 +0400 | [diff] [blame] | 73 | |
Rabi Mishra | 7205fee | 2015-04-06 07:57:34 +0530 | [diff] [blame^] | 74 | # Check connection and info about received responses |
Anastasia Kuznetsova | 3e0ab4d | 2015-03-06 18:10:13 +0400 | [diff] [blame] | 75 | self.check_connectivity(server1_ip) |
| 76 | self.collect_responses(server1_ip, {'server1\n'}) |
| 77 | |
| 78 | self.check_connectivity(server2_ip) |
| 79 | self.collect_responses(server2_ip, {'server2\n'}) |
| 80 | |
| 81 | self.check_connectivity(vip) |
| 82 | self.collect_responses(vip, {'server1\n'}) |
| 83 | |
| 84 | self.check_connectivity(floating_ip) |
| 85 | self.collect_responses(floating_ip, {'server1\n'}) |
| 86 | |
| 87 | # Include 'server2' to LB and update the stack |
| 88 | template = self._load_template( |
| 89 | __file__, self.template_name, self.sub_dir |
| 90 | ) |
| 91 | |
| 92 | template = template.replace( |
| 93 | '- { get_resource: server1 }', |
| 94 | '- { get_resource: server1 }\n - { get_resource: server2 }\n' |
| 95 | ) |
| 96 | |
| 97 | self.update_stack( |
| 98 | sid, |
| 99 | template=template, |
| 100 | parameters=parameters |
| 101 | ) |
| 102 | |
| 103 | self.check_connectivity(vip) |
| 104 | self.collect_responses(vip, {'server1\n', 'server2\n'}) |
| 105 | |
| 106 | self.check_connectivity(floating_ip) |
| 107 | self.collect_responses(floating_ip, {'server1\n', 'server2\n'}) |