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() |
| 27 | self.public_net = self._get_network('public') |
| 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, |
| 55 | 'flavor': self.conf.instance_type, |
| 56 | 'image': self.conf.image_ref, |
| 57 | 'private_subnet_id': self.net['subnets'][0], |
| 58 | 'external_network_id': self.public_net['id'] |
| 59 | } |
| 60 | |
| 61 | # Launch stack |
| 62 | sid = self.launch_stack( |
| 63 | template_name=self.template_name, |
| 64 | parameters=parameters |
| 65 | ) |
| 66 | |
| 67 | server1_id = self.client.resources.get( |
| 68 | sid, 'server1').physical_resource_id |
| 69 | server2_id = self.client.resources.get( |
| 70 | sid, 'server2').physical_resource_id |
| 71 | floating_ip_id = self.client.resources.get( |
| 72 | sid, 'floating_ip').physical_resource_id |
| 73 | floating_ip = self.network_client.show_floatingip( |
| 74 | floating_ip_id)['floatingip']['floating_ip_address'] |
| 75 | pool_id = self.client.resources.get( |
| 76 | sid, 'test_pool').physical_resource_id |
| 77 | vip_id = self.network_client.show_pool(pool_id)['pool']['vip_id'] |
| 78 | |
| 79 | vip = self.network_client.show_vip(vip_id)['vip']['address'] |
| 80 | server1_ip = self.compute_client.servers.get( |
| 81 | server1_id).networks['private'][0] |
| 82 | server2_ip = self.compute_client.servers.get( |
| 83 | server2_id).networks['private'][0] |
| 84 | |
| 85 | # Check connection and info about received responces |
| 86 | self.check_connectivity(server1_ip) |
| 87 | self.collect_responses(server1_ip, {'server1\n'}) |
| 88 | |
| 89 | self.check_connectivity(server2_ip) |
| 90 | self.collect_responses(server2_ip, {'server2\n'}) |
| 91 | |
| 92 | self.check_connectivity(vip) |
| 93 | self.collect_responses(vip, {'server1\n'}) |
| 94 | |
| 95 | self.check_connectivity(floating_ip) |
| 96 | self.collect_responses(floating_ip, {'server1\n'}) |
| 97 | |
| 98 | # Include 'server2' to LB and update the stack |
| 99 | template = self._load_template( |
| 100 | __file__, self.template_name, self.sub_dir |
| 101 | ) |
| 102 | |
| 103 | template = template.replace( |
| 104 | '- { get_resource: server1 }', |
| 105 | '- { get_resource: server1 }\n - { get_resource: server2 }\n' |
| 106 | ) |
| 107 | |
| 108 | self.update_stack( |
| 109 | sid, |
| 110 | template=template, |
| 111 | parameters=parameters |
| 112 | ) |
| 113 | |
| 114 | self.check_connectivity(vip) |
| 115 | self.collect_responses(vip, {'server1\n', 'server2\n'}) |
| 116 | |
| 117 | self.check_connectivity(floating_ip) |
| 118 | self.collect_responses(floating_ip, {'server1\n', 'server2\n'}) |