Slawek Kaplonski | b1a3289 | 2018-08-27 07:24:00 +0200 | [diff] [blame] | 1 | # Copyright 2018 Red Hat, Inc. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from tempest.common import compute |
| 17 | from tempest.common import utils |
| 18 | from tempest.lib.common.utils import data_utils |
| 19 | from tempest.lib import decorators |
| 20 | |
| 21 | from neutron_tempest_plugin.common import ssh |
| 22 | from neutron_tempest_plugin import config |
| 23 | from neutron_tempest_plugin.scenario import base |
| 24 | |
| 25 | CONF = config.CONF |
| 26 | |
| 27 | |
| 28 | class NetworkConnectivityTest(base.BaseTempestTestCase): |
| 29 | credentials = ['primary', 'admin'] |
| 30 | |
| 31 | @classmethod |
| 32 | @utils.requires_ext(extension="router", service="network") |
| 33 | def resource_setup(cls): |
| 34 | super(NetworkConnectivityTest, cls).resource_setup() |
| 35 | # Create keypair with admin privileges |
| 36 | cls.keypair = cls.create_keypair() |
| 37 | # Create security group with admin privileges |
| 38 | cls.secgroup = cls.create_security_group( |
| 39 | name=data_utils.rand_name('secgroup')) |
| 40 | # Execute funcs to achieve ssh and ICMP capabilities |
| 41 | cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 42 | cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 43 | |
| 44 | def _create_servers(self, port_1, port_2): |
| 45 | params = { |
| 46 | 'flavor_ref': CONF.compute.flavor_ref, |
| 47 | 'image_ref': CONF.compute.image_ref, |
| 48 | 'key_name': self.keypair['name'] |
| 49 | } |
| 50 | vm1 = self.create_server(networks=[{'port': port_1['id']}], **params) |
| 51 | |
| 52 | if (CONF.compute.min_compute_nodes > 1 and |
| 53 | compute.is_scheduler_filter_enabled("DifferentHostFilter")): |
| 54 | params['scheduler_hints'] = { |
| 55 | 'different_host': [vm1['server']['id']]} |
| 56 | |
| 57 | self.create_server(networks=[{'port': port_2['id']}], **params) |
| 58 | |
| 59 | @decorators.idempotent_id('8944b90d-1766-4669-bd8a-672b5d106bb7') |
| 60 | def test_connectivity_through_2_routers(self): |
| 61 | ap1_net = self.create_network() |
| 62 | ap2_net = self.create_network() |
| 63 | wan_net = self.create_network() |
| 64 | ap1_subnet = self.create_subnet( |
| 65 | ap1_net, cidr="10.10.210.0/24", gateway="10.10.210.254") |
| 66 | ap2_subnet = self.create_subnet( |
| 67 | ap2_net, cidr="10.10.220.0/24", gateway="10.10.220.254") |
| 68 | self.create_subnet( |
| 69 | wan_net, cidr="10.10.200.0/24", gateway="10.10.200.254") |
| 70 | |
| 71 | ap1_rt = self.create_router( |
| 72 | router_name=data_utils.rand_name("ap1_rt"), |
| 73 | admin_state_up=True, |
| 74 | external_network_id=CONF.network.public_network_id) |
| 75 | ap2_rt = self.create_router( |
| 76 | router_name=data_utils.rand_name("ap2_rt"), |
| 77 | admin_state_up=True) |
| 78 | |
| 79 | ap1_internal_port = self.create_port( |
| 80 | ap1_net, security_groups=[self.secgroup['id']]) |
| 81 | ap2_internal_port = self.create_port( |
| 82 | ap2_net, security_groups=[self.secgroup['id']]) |
| 83 | ap1_wan_port = self.create_port(wan_net) |
| 84 | ap2_wan_port = self.create_port(wan_net) |
| 85 | |
| 86 | self._create_servers(ap1_internal_port, ap2_internal_port) |
| 87 | |
| 88 | self.client.add_router_interface_with_port_id( |
| 89 | ap1_rt['id'], ap1_wan_port['id']) |
| 90 | self.client.add_router_interface_with_port_id( |
| 91 | ap2_rt['id'], ap2_wan_port['id']) |
| 92 | self.create_router_interface(ap1_rt['id'], ap1_subnet['id']) |
| 93 | self.create_router_interface(ap2_rt['id'], ap2_subnet['id']) |
| 94 | |
| 95 | self.client.update_router( |
| 96 | ap1_rt['id'], |
| 97 | routes=[{"destination": ap2_subnet['cidr'], |
| 98 | "nexthop": ap2_wan_port['fixed_ips'][0]['ip_address']}]) |
| 99 | self.client.update_router( |
| 100 | ap2_rt['id'], |
| 101 | routes=[{"destination": ap1_subnet['cidr'], |
| 102 | "nexthop": ap1_wan_port['fixed_ips'][0]['ip_address']}]) |
| 103 | |
| 104 | ap1_fip = self.create_and_associate_floatingip( |
| 105 | ap1_internal_port['id']) |
| 106 | ap1_sshclient = ssh.Client( |
| 107 | ap1_fip['floating_ip_address'], CONF.validation.image_ssh_user, |
| 108 | pkey=self.keypair['private_key']) |
| 109 | |
| 110 | self.check_remote_connectivity( |
| 111 | ap1_sshclient, ap2_internal_port['fixed_ips'][0]['ip_address']) |