blob: 0591e5bddad637e2bb9ee3eeaa28bfca9265cfb8 [file] [log] [blame]
Anastasia Kuznetsova3e0ab4d2015-03-06 18:10:13 +04001#
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
15import urllib
16
17from heat_integrationtests.scenario import scenario_base
18
19
20class 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 Shchelokovskyy6fa23802015-03-23 11:22:35 +000027 self.public_net = self._get_network(self.conf.floating_network_name)
Anastasia Kuznetsova3e0ab4d2015-03-06 18:10:13 +040028 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
Sergey Krayneve0ad3632015-03-19 11:34:32 -040067 stack = self.client.stacks.get(sid)
68 floating_ip = self._stack_output(stack, 'fip')
69 vip = self._stack_output(stack, 'vip')
70 server1_ip = self._stack_output(stack, 'serv1_ip')
71 server2_ip = self._stack_output(stack, 'serv2_ip')
Anastasia Kuznetsova3e0ab4d2015-03-06 18:10:13 +040072
73 # Check connection and info about received responces
74 self.check_connectivity(server1_ip)
75 self.collect_responses(server1_ip, {'server1\n'})
76
77 self.check_connectivity(server2_ip)
78 self.collect_responses(server2_ip, {'server2\n'})
79
80 self.check_connectivity(vip)
81 self.collect_responses(vip, {'server1\n'})
82
83 self.check_connectivity(floating_ip)
84 self.collect_responses(floating_ip, {'server1\n'})
85
86 # Include 'server2' to LB and update the stack
87 template = self._load_template(
88 __file__, self.template_name, self.sub_dir
89 )
90
91 template = template.replace(
92 '- { get_resource: server1 }',
93 '- { get_resource: server1 }\n - { get_resource: server2 }\n'
94 )
95
96 self.update_stack(
97 sid,
98 template=template,
99 parameters=parameters
100 )
101
102 self.check_connectivity(vip)
103 self.collect_responses(vip, {'server1\n', 'server2\n'})
104
105 self.check_connectivity(floating_ip)
106 self.collect_responses(floating_ip, {'server1\n', 'server2\n'})