blob: 978068a681d594b1a6b04579b0b8b1ae6012f3e1 [file] [log] [blame]
Jude Cross986e3f52017-07-24 14:57:20 -07001# Copyright 2018 Rackspace US Inc. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import ipaddress
16import pkg_resources
17import random
18import shlex
19import six
20import string
21import subprocess
22import tempfile
23
24from oslo_log import log as logging
25from oslo_utils import uuidutils
26from tempest import config
27from tempest.lib.common.utils import data_utils
28from tempest.lib.common.utils.linux import remote_client
29from tempest.lib.common.utils import test_utils
30from tempest.lib import exceptions
31from tempest import test
32
33from octavia_tempest_plugin import clients
34from octavia_tempest_plugin.common import constants as const
35from octavia_tempest_plugin.tests import validators
36from octavia_tempest_plugin.tests import waiters
37
38CONF = config.CONF
39LOG = logging.getLogger(__name__)
40
41
42class LoadBalancerBaseTest(test.BaseTestCase):
43 """Base class for load balancer tests."""
44
45 # Setup cls.os_roles_lb_member. cls.os_primary, cls.os_roles_lb_member,
46 # and cls.os_roles_lb_admin credentials.
47 credentials = ['admin', 'primary',
48 ['lb_member', CONF.load_balancer.member_role],
49 ['lb_member2', CONF.load_balancer.member_role],
50 ['lb_admin', CONF.load_balancer.admin_role]]
51
52 client_manager = clients.ManagerV2
53
54 @classmethod
55 def skip_checks(cls):
56 """Check if we should skip all of the children tests."""
57 super(LoadBalancerBaseTest, cls).skip_checks()
58
59 service_list = {
60 'load_balancer': CONF.service_available.load_balancer,
61 }
62
63 live_service_list = {
64 'compute': CONF.service_available.nova,
65 'image': CONF.service_available.glance,
66 'neutron': CONF.service_available.neutron
67 }
68
69 if not CONF.load_balancer.test_with_noop:
70 service_list.update(live_service_list)
71
72 for service, available in service_list.items():
73 if not available:
74 skip_msg = ("{0} skipped as {1} serivce is not "
75 "available.".format(cls.__name__, service))
76 raise cls.skipException(skip_msg)
77
78 # We must be able to reach our VIP and instances
79 if not (CONF.network.project_networks_reachable
80 or CONF.network.public_network_id):
81 msg = ('Either project_networks_reachable must be "true", or '
82 'public_network_id must be defined.')
83 raise cls.skipException(msg)
84
85 @classmethod
86 def setup_credentials(cls):
87 """Setup test credentials and network resources."""
88 # Do not auto create network resources
89 cls.set_network_resources()
90 super(LoadBalancerBaseTest, cls).setup_credentials()
91
92 @classmethod
93 def setup_clients(cls):
94 """Setup client aliases."""
95 super(LoadBalancerBaseTest, cls).setup_clients()
96 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
97 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
98 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
99 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
100 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
101 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
102 cls.lb_mem_SGr_client = (
103 cls.os_roles_lb_member.security_group_rules_client)
104 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
105 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
106 cls.mem_lb_client = cls.os_roles_lb_member.loadbalancer_client
107
108 @classmethod
109 def resource_setup(cls):
110 """Setup resources needed by the tests."""
111 super(LoadBalancerBaseTest, cls).resource_setup()
112
113 conf_lb = CONF.load_balancer
114
115 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
116 raise exceptions.InvalidConfiguration(
117 "Configuration value test_network_override must be "
118 "specified if test_subnet_override is used.")
119
120 show_subnet = cls.lb_mem_subnet_client.show_subnet
121 if CONF.load_balancer.test_with_noop:
122 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
123 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
124 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
125 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
126 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
127 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
128 if CONF.load_balancer.test_with_ipv6:
129 cls.lb_member_vip_ipv6_subnet = {'id':
130 uuidutils.generate_uuid()}
131 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
132 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
133 return
134 elif CONF.load_balancer.test_network_override:
135 if conf_lb.test_subnet_override:
136 override_subnet = show_subnet(conf_lb.test_subnet_override)
137 else:
138 override_subnet = None
139
140 show_net = cls.lb_mem_net_client.show_network
141 override_network = show_net(conf_lb.test_network_override)
142 override_network = override_network.get('network')
143
144 cls.lb_member_vip_net = override_network
145 cls.lb_member_vip_subnet = override_subnet
146 cls.lb_member_1_net = override_network
147 cls.lb_member_1_subnet = override_subnet
148 cls.lb_member_2_net = override_network
149 cls.lb_member_2_subnet = override_subnet
150
151 if (CONF.load_balancer.test_with_ipv6 and
152 conf_lb.test_IPv6_subnet_override):
153 override_ipv6_subnet = show_subnet(
154 conf_lb.test_IPv6_subnet_override)
155 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
156 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
157 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
158 else:
159 cls.lb_member_vip_ipv6_subnet = None
160 cls.lb_member_1_ipv6_subnet = None
161 cls.lb_member_2_ipv6_subnet = None
162 else:
163 cls._create_networks()
164
165 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
166 cls.lb_member_vip_net[const.ID]))
167 if cls.lb_member_vip_subnet:
168 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
169 cls.lb_member_vip_subnet[const.ID]))
170 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
171 cls.lb_member_1_net[const.ID]))
172 if cls.lb_member_1_subnet:
173 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
174 cls.lb_member_1_subnet[const.ID]))
175 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
176 cls.lb_member_2_net[const.ID]))
177 if cls.lb_member_2_subnet:
178 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
179 cls.lb_member_2_subnet[const.ID]))
180 if cls.lb_member_vip_ipv6_subnet:
181 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = {}'.format(
182 cls.lb_member_vip_ipv6_subnet[const.ID]))
183 if cls.lb_member_1_ipv6_subnet:
184 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
185 cls.lb_member_1_ipv6_subnet[const.ID]))
186 if cls.lb_member_2_ipv6_subnet:
187 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
188 cls.lb_member_2_ipv6_subnet[const.ID]))
189
190 # If validation is disabled in this cloud, we won't be able to
191 # start the webservers, so don't even boot them.
192 if not CONF.validation.run_validation:
193 return
194
195 # Create a keypair for the webservers
196 keypair_name = data_utils.rand_name('lb_member_keypair')
197 result = cls.lb_mem_keypairs_client.create_keypair(
198 name=keypair_name)
199 cls.lb_member_keypair = result['keypair']
200 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
201 cls.addClassResourceCleanup(
202 waiters.wait_for_not_found,
203 cls.lb_mem_keypairs_client.delete_keypair,
204 cls.lb_mem_keypairs_client.show_keypair,
205 keypair_name)
206
207 if (CONF.load_balancer.enable_security_groups and
208 CONF.network_feature_enabled.port_security):
209 # Set up the security group for the webservers
210 SG_name = data_utils.rand_name('lb_member_SG')
211 cls.lb_member_sec_group = (
212 cls.lb_mem_SG_client.create_security_group(
213 name=SG_name)['security_group'])
214 cls.addClassResourceCleanup(
215 waiters.wait_for_not_found,
216 cls.lb_mem_SG_client.delete_security_group,
217 cls.lb_mem_SG_client.show_security_group,
218 cls.lb_member_sec_group['id'])
219
220 # Create a security group rule to allow 80-81 (test webservers)
221 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
222 direction='ingress',
223 security_group_id=cls.lb_member_sec_group['id'],
224 protocol='tcp',
225 ethertype='IPv4',
226 port_range_min=80,
227 port_range_max=81)['security_group_rule']
228 cls.addClassResourceCleanup(
229 waiters.wait_for_not_found,
230 cls.lb_mem_SGr_client.delete_security_group_rule,
231 cls.lb_mem_SGr_client.show_security_group_rule,
232 SGr['id'])
233 # Create a security group rule to allow 22 (ssh)
234 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
235 direction='ingress',
236 security_group_id=cls.lb_member_sec_group['id'],
237 protocol='tcp',
238 ethertype='IPv4',
239 port_range_min=22,
240 port_range_max=22)['security_group_rule']
241 cls.addClassResourceCleanup(
242 waiters.wait_for_not_found,
243 cls.lb_mem_SGr_client.delete_security_group_rule,
244 cls.lb_mem_SGr_client.show_security_group_rule,
245 SGr['id'])
246 if CONF.load_balancer.test_with_ipv6:
247 # Create a security group rule to allow 80-81 (test webservers)
248 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
249 direction='ingress',
250 security_group_id=cls.lb_member_sec_group['id'],
251 protocol='tcp',
252 ethertype='IPv6',
253 port_range_min=80,
254 port_range_max=81)['security_group_rule']
255 cls.addClassResourceCleanup(
256 waiters.wait_for_not_found,
257 cls.lb_mem_SGr_client.delete_security_group_rule,
258 cls.lb_mem_SGr_client.show_security_group_rule,
259 SGr['id'])
260 # Create a security group rule to allow 22 (ssh)
261 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
262 direction='ingress',
263 security_group_id=cls.lb_member_sec_group['id'],
264 protocol='tcp',
265 ethertype='IPv6',
266 port_range_min=22,
267 port_range_max=22)['security_group_rule']
268 cls.addClassResourceCleanup(
269 waiters.wait_for_not_found,
270 cls.lb_mem_SGr_client.delete_security_group_rule,
271 cls.lb_mem_SGr_client.show_security_group_rule,
272 SGr['id'])
273
274 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
275
276 # Create webserver 1 instance
277 server_details = cls._create_webserver('lb_member_webserver1',
278 cls.lb_member_1_net)
279
280 cls.lb_member_webserver1 = server_details['server']
281 cls.webserver1_ip = server_details.get('ipv4_address')
282 cls.webserver1_ipv6 = server_details.get('ipv6_address')
283 cls.webserver1_public_ip = server_details['public_ipv4_address']
284
285 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
286 cls.lb_member_webserver1[const.ID]))
287 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
288 cls.webserver1_ip))
289 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
290 cls.webserver1_ipv6))
291 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
292 cls.webserver1_public_ip))
293
294 cls._install_start_webserver(cls.webserver1_public_ip,
295 cls.lb_member_keypair['private_key'], 1)
296
297 # Validate webserver 1
298 cls._validate_webserver(cls.webserver1_public_ip, 1)
299
300 # Create webserver 2 instance
301 server_details = cls._create_webserver('lb_member_webserver2',
302 cls.lb_member_2_net)
303
304 cls.lb_member_webserver2 = server_details['server']
305 cls.webserver2_ip = server_details.get('ipv4_address')
306 cls.webserver2_ipv6 = server_details.get('ipv6_address')
307 cls.webserver2_public_ip = server_details['public_ipv4_address']
308
309 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
310 cls.lb_member_webserver2[const.ID]))
311 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
312 cls.webserver2_ip))
313 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
314 cls.webserver2_ipv6))
315 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
316 cls.webserver2_public_ip))
317
318 cls._install_start_webserver(cls.webserver2_public_ip,
319 cls.lb_member_keypair['private_key'], 5)
320
321 # Validate webserver 2
322 cls._validate_webserver(cls.webserver2_public_ip, 5)
323
324 @classmethod
325 def _install_start_webserver(cls, ip_address, ssh_key, start_id):
326 local_file = pkg_resources.resource_filename(
327 'octavia_tempest_plugin.contrib.httpd', 'httpd.bin')
328 dest_file = '/dev/shm/httpd.bin'
329
330 linux_client = remote_client.RemoteClient(
331 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
332 linux_client.validate_authentication()
333
334 with tempfile.NamedTemporaryFile() as key:
335 key.write(ssh_key.encode('utf-8'))
336 key.flush()
337 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
338 "-o StrictHostKeyChecking=no "
339 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
340 "-i {2} {3} {4}@{5}:{6}").format(
341 CONF.load_balancer.scp_connection_timeout,
342 CONF.load_balancer.scp_connection_attempts,
343 key.name, local_file, CONF.validation.image_ssh_user,
344 ip_address, dest_file)
345 args = shlex.split(cmd)
346 subprocess_args = {'stdout': subprocess.PIPE,
347 'stderr': subprocess.STDOUT,
348 'cwd': None}
349 proc = subprocess.Popen(args, **subprocess_args)
350 stdout, stderr = proc.communicate()
351 if proc.returncode != 0:
352 raise exceptions.CommandFailed(proc.returncode, cmd,
353 stdout, stderr)
354 linux_client.exec_command('sudo screen -d -m {0} -port 80 '
355 '-id {1}'.format(dest_file, start_id))
356 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
357 '-id {1}'.format(dest_file, start_id + 1))
358
359 @classmethod
360 def _create_networks(cls):
361 """Creates networks, subnets, and routers used in tests.
362
363 The following are expected to be defined and available to the tests:
364 cls.lb_member_vip_net
365 cls.lb_member_vip_subnet
366 cls.lb_member_vip_ipv6_subnet (optional)
367 cls.lb_member_1_net
368 cls.lb_member_1_subnet
369 cls.lb_member_1_ipv6_subnet (optional)
370 cls.lb_member_2_net
371 cls.lb_member_2_subnet
372 cls.lb_member_2_ipv6_subnet (optional)
373 """
374
375 # Create tenant VIP network
376 network_kwargs = {
377 'name': data_utils.rand_name("lb_member_vip_network")}
378 if CONF.network_feature_enabled.port_security:
379 # Note: Allowed Address Pairs requires port security
380 network_kwargs['port_security_enabled'] = True
381 result = cls.lb_mem_net_client.create_network(**network_kwargs)
382 cls.lb_member_vip_net = result['network']
383 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
384 cls.addClassResourceCleanup(
385 waiters.wait_for_not_found,
386 cls.lb_mem_net_client.delete_network,
387 cls.lb_mem_net_client.show_network,
388 cls.lb_member_vip_net['id'])
389
390 # Create tenant VIP subnet
391 subnet_kwargs = {
392 'name': data_utils.rand_name("lb_member_vip_subnet"),
393 'network_id': cls.lb_member_vip_net['id'],
394 'cidr': CONF.load_balancer.vip_subnet_cidr,
395 'ip_version': 4}
396 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
397 cls.lb_member_vip_subnet = result['subnet']
398 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
399 cls.addClassResourceCleanup(
400 waiters.wait_for_not_found,
401 cls.lb_mem_subnet_client.delete_subnet,
402 cls.lb_mem_subnet_client.show_subnet,
403 cls.lb_member_vip_subnet['id'])
404
405 # Create tenant VIP IPv6 subnet
406 if CONF.load_balancer.test_with_ipv6:
407 subnet_kwargs = {
408 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
409 'network_id': cls.lb_member_vip_net['id'],
410 'cidr': CONF.load_balancer.vip_ipv6_subnet_cidr,
411 'ip_version': 6}
412 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
413 cls.lb_member_vip_ipv6_subnet = result['subnet']
414 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
415 cls.lb_member_vip_ipv6_subnet))
416 cls.addClassResourceCleanup(
417 waiters.wait_for_not_found,
418 cls.lb_mem_subnet_client.delete_subnet,
419 cls.lb_mem_subnet_client.show_subnet,
420 cls.lb_member_vip_ipv6_subnet['id'])
421
422 # Create tenant member 1 network
423 network_kwargs = {
424 'name': data_utils.rand_name("lb_member_1_network")}
425 if CONF.network_feature_enabled.port_security:
426 if CONF.load_balancer.enable_security_groups:
427 network_kwargs['port_security_enabled'] = True
428 else:
429 network_kwargs['port_security_enabled'] = False
430 result = cls.lb_mem_net_client.create_network(**network_kwargs)
431 cls.lb_member_1_net = result['network']
432 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
433 cls.addClassResourceCleanup(
434 waiters.wait_for_not_found,
435 cls.lb_mem_net_client.delete_network,
436 cls.lb_mem_net_client.show_network,
437 cls.lb_member_1_net['id'])
438
439 # Create tenant member 1 subnet
440 subnet_kwargs = {
441 'name': data_utils.rand_name("lb_member_1_subnet"),
442 'network_id': cls.lb_member_1_net['id'],
443 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
444 'ip_version': 4}
445 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
446 cls.lb_member_1_subnet = result['subnet']
447 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
448 cls.addClassResourceCleanup(
449 waiters.wait_for_not_found,
450 cls.lb_mem_subnet_client.delete_subnet,
451 cls.lb_mem_subnet_client.show_subnet,
452 cls.lb_member_1_subnet['id'])
453
454 # Create tenant member 1 ipv6 subnet
455 if CONF.load_balancer.test_with_ipv6:
456 subnet_kwargs = {
457 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
458 'network_id': cls.lb_member_1_net['id'],
459 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
460 'ip_version': 6}
461 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
462 cls.lb_member_1_ipv6_subnet = result['subnet']
463 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
464 cls.lb_member_1_ipv6_subnet))
465 cls.addClassResourceCleanup(
466 waiters.wait_for_not_found,
467 cls.lb_mem_subnet_client.delete_subnet,
468 cls.lb_mem_subnet_client.show_subnet,
469 cls.lb_member_1_ipv6_subnet['id'])
470
471 # Create tenant member 2 network
472 network_kwargs = {
473 'name': data_utils.rand_name("lb_member_2_network")}
474 if CONF.network_feature_enabled.port_security:
475 if CONF.load_balancer.enable_security_groups:
476 network_kwargs['port_security_enabled'] = True
477 else:
478 network_kwargs['port_security_enabled'] = False
479 result = cls.lb_mem_net_client.create_network(**network_kwargs)
480 cls.lb_member_2_net = result['network']
481 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
482 cls.addClassResourceCleanup(
483 waiters.wait_for_not_found,
484 cls.lb_mem_net_client.delete_network,
485 cls.lb_mem_net_client.show_network,
486 cls.lb_member_2_net['id'])
487
488 # Create tenant member 2 subnet
489 subnet_kwargs = {
490 'name': data_utils.rand_name("lb_member_2_subnet"),
491 'network_id': cls.lb_member_2_net['id'],
492 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
493 'ip_version': 4}
494 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
495 cls.lb_member_2_subnet = result['subnet']
496 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
497 cls.addClassResourceCleanup(
498 waiters.wait_for_not_found,
499 cls.lb_mem_subnet_client.delete_subnet,
500 cls.lb_mem_subnet_client.show_subnet,
501 cls.lb_member_2_subnet['id'])
502
503 # Create tenant member 2 ipv6 subnet
504 if CONF.load_balancer.test_with_ipv6:
505 subnet_kwargs = {
506 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
507 'network_id': cls.lb_member_2_net['id'],
508 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
509 'ip_version': 6}
510 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
511 cls.lb_member_2_ipv6_subnet = result['subnet']
512 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
513 cls.lb_member_2_ipv6_subnet))
514 cls.addClassResourceCleanup(
515 waiters.wait_for_not_found,
516 cls.lb_mem_subnet_client.delete_subnet,
517 cls.lb_mem_subnet_client.show_subnet,
518 cls.lb_member_2_ipv6_subnet['id'])
519
520 # Create a router for the subnets (required for the floating IP)
521 router_name = data_utils.rand_name("lb_member_router")
522 result = cls.lb_mem_routers_client.create_router(
523 name=router_name, admin_state_up=True,
524 external_gateway_info=dict(
525 network_id=CONF.network.public_network_id))
526 cls.lb_member_router = result['router']
527 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
528 cls.addClassResourceCleanup(
529 waiters.wait_for_not_found,
530 cls.lb_mem_routers_client.delete_router,
531 cls.lb_mem_routers_client.show_router,
532 cls.lb_member_router['id'])
533
534 # Add VIP subnet to router
535 cls.lb_mem_routers_client.add_router_interface(
536 cls.lb_member_router['id'],
537 subnet_id=cls.lb_member_vip_subnet['id'])
538 cls.addClassResourceCleanup(
539 waiters.wait_for_not_found,
540 cls.lb_mem_routers_client.remove_router_interface,
541 cls.lb_mem_routers_client.remove_router_interface,
542 cls.lb_member_router['id'],
543 subnet_id=cls.lb_member_vip_subnet['id'])
544
545 # Add member subnet 1 to router
546 cls.lb_mem_routers_client.add_router_interface(
547 cls.lb_member_router['id'],
548 subnet_id=cls.lb_member_1_subnet['id'])
549 cls.addClassResourceCleanup(
550 waiters.wait_for_not_found,
551 test_utils.call_and_ignore_notfound_exc,
552 cls.lb_mem_routers_client.remove_router_interface,
553 cls.lb_mem_routers_client.remove_router_interface,
554 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
555
556 # Add member subnet 2 to router
557 cls.lb_mem_routers_client.add_router_interface(
558 cls.lb_member_router['id'],
559 subnet_id=cls.lb_member_2_subnet['id'])
560 cls.addClassResourceCleanup(
561 waiters.wait_for_not_found,
562 cls.lb_mem_routers_client.remove_router_interface,
563 cls.lb_mem_routers_client.remove_router_interface,
564 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
565
566 @classmethod
567 def _create_webserver(cls, name, network):
568 """Creates a webserver with two ports.
569
570 webserver_details dictionary contains:
571 server - The compute server object
572 ipv4_address - The IPv4 address for the server (optional)
573 ipv6_address - The IPv6 address for the server (optional)
574 public_ipv4_address - The publicly accessible IPv4 address for the
575 server, this may be a floating IP (optional)
576
577 :param name: The name of the server to create.
578 :param network: The network to boot the server on.
579 :returns: webserver_details dictionary.
580 """
581 server_kwargs = {
582 'name': data_utils.rand_name(name),
583 'flavorRef': CONF.compute.flavor_ref,
584 'imageRef': CONF.compute.image_ref,
585 'key_name': cls.lb_member_keypair['name']}
586 if (CONF.load_balancer.enable_security_groups and
587 CONF.network_feature_enabled.port_security):
588 server_kwargs['security_groups'] = [
589 {'name': cls.lb_member_sec_group['name']}]
590 if not CONF.load_balancer.disable_boot_network:
591 server_kwargs['networks'] = [{'uuid': network['id']}]
592
593 # Replace the name for clouds that have limitations
594 if CONF.load_balancer.random_server_name_length:
595 r = random.SystemRandom()
596 server_kwargs['name'] = "m{}".format("".join(
597 [r.choice(string.ascii_uppercase + string.digits)
598 for _ in range(
599 CONF.load_balancer.random_server_name_length - 1)]
600 ))
601 if CONF.load_balancer.availability_zone:
602 server_kwargs['availability_zone'] = (
603 CONF.load_balancer.availability_zone)
604
605 server = cls.lb_mem_servers_client.create_server(
606 **server_kwargs)['server']
607 cls.addClassResourceCleanup(
608 waiters.wait_for_not_found,
609 cls.lb_mem_servers_client.delete_server,
610 cls.lb_mem_servers_client.show_server,
611 server['id'])
612 server = waiters.wait_for_status(
613 cls.lb_mem_servers_client.show_server,
614 server['id'], 'status', 'ACTIVE',
615 CONF.load_balancer.build_interval,
616 CONF.load_balancer.build_timeout,
617 root_tag='server')
618 webserver_details = {'server': server}
619 LOG.info('Created server: {}'.format(server))
620
621 addresses = server['addresses']
622 if CONF.load_balancer.disable_boot_network:
623 instance_network = addresses.values()[0]
624 else:
625 instance_network = addresses[network['name']]
626 for addr in instance_network:
627 if addr['version'] == 4:
628 webserver_details['ipv4_address'] = addr['addr']
629 if addr['version'] == 6:
630 webserver_details['ipv6_address'] = addr['addr']
631
632 if CONF.validation.connect_method == 'floating':
633 result = cls.lb_mem_ports_client.list_ports(
634 network_id=network['id'],
635 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
636 port_id = result['ports'][0]['id']
637 result = cls.lb_mem_float_ip_client.create_floatingip(
638 floating_network_id=CONF.network.public_network_id,
639 port_id=port_id)
640 floating_ip = result['floatingip']
641 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
642 cls.addClassResourceCleanup(
643 waiters.wait_for_not_found,
644 cls.lb_mem_float_ip_client.delete_floatingip,
645 cls.lb_mem_float_ip_client.show_floatingip,
646 floatingip_id=floating_ip['id'])
647 webserver_details['public_ipv4_address'] = (
648 floating_ip['floating_ip_address'])
649 else:
650 webserver_details['public_ipv4_address'] = (
651 instance_network[0]['addr'])
652
653 return webserver_details
654
655 @classmethod
656 def _validate_webserver(cls, ip_address, start_id):
657 URL = 'http://{0}'.format(ip_address)
658 validators.validate_URL_response(URL, expected_body=str(start_id))
659 URL = 'http://{0}:81'.format(ip_address)
660 validators.validate_URL_response(URL, expected_body=str(start_id + 1))
661
662 @classmethod
663 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version):
664 if cls.lb_member_vip_subnet:
665 ip_index = data_utils.rand_int_id(start=10, end=100)
666 if ip_version == 4:
667 network = ipaddress.IPv4Network(
668 six.u(CONF.load_balancer.vip_subnet_cidr))
669 lb_vip_address = str(network[ip_index])
670 subnet_id = cls.lb_member_vip_subnet[const.ID]
671 else:
672 network = ipaddress.IPv6Network(
673 six.u(CONF.load_balancer.vip_ipv6_subnet_cidr))
674 lb_vip_address = str(network[ip_index])
675 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
676 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
677 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
678 if CONF.load_balancer.test_with_noop:
679 lb_kwargs[const.VIP_NETWORK_ID] = (
680 cls.lb_member_vip_net[const.ID])
681 else:
682 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
683 lb_kwargs[const.VIP_SUBNET_ID] = None