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