Rewrite floating IP test case

Change-Id: I05cd4bed9082cd9f9b3dfc48233418e1756191d2
This commit is contained in:
Federico Ressi 2019-03-27 09:13:44 +01:00
parent 9b4dadbfa6
commit 404e0e2e0b
7 changed files with 258 additions and 3 deletions

View File

@ -0,0 +1,46 @@
# Copyright (c) 2019 Red Hat
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import os
from tobiko import config
from tobiko.openstack import heat
from tobiko.tests import base
CONF = config.CONF
TEMPLATE_DIRS = [os.path.join(os.path.dirname(__file__), 'templates')]
def heat_template_file(template_file):
return heat.heat_template_file(template_file=template_file,
template_dirs=TEMPLATE_DIRS)
class InternalNetworkFixture(heat.HeatStackFixture):
template = heat_template_file('internal_network.yaml')
parameters = {
'floating_network': CONF.tobiko.neutron.floating_network,
}
class SecurityGroupsFixture(heat.HeatStackFixture):
template = heat_template_file('security_groups.yaml')
class NeutronTest(base.TobikoTest):
pass

View File

@ -0,0 +1,56 @@
heat_template_version: newton
description: |
Stack of resources used to test floating IP
parameters:
flavor:
type: string
image:
type: string
floating_network:
type: string
internal_network:
type: string
port_security_enabled:
type: boolean
default: false
security_groups:
type: comma_delimited_list
default: []
resources:
port:
type: OS::Neutron::Port
properties:
network: {get_param: internal_network}
port_security_enabled: {get_param: port_security_enabled}
security_groups: {get_param: security_groups}
server:
type: OS::Nova::Server
properties:
image: {get_param: image}
flavor: {get_param: flavor}
networks:
- port: {get_resource: port}
floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network: {get_param: floating_network}
floating_ip_association:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id: {get_resource: floating_ip}
port_id: {get_resource: port}
outputs:
floating_ip_address:
value: {get_attr: [floating_ip, floating_ip_address]}

View File

@ -0,0 +1,47 @@
heat_template_version: newton
description: |
Creates an internal network with a route to a floating IP external network
parameters:
floating_network:
type: string
subnet_ipv4_cidr:
type: string
default: 190.40.2.0/24
dns_nameservers:
type: comma_delimited_list
default: ["8.8.8.8", "8.8.4.4"]
resources:
network:
type: OS::Neutron::Net
subnet_ipv4:
type: OS::Neutron::Subnet
properties:
network: {get_resource: network}
ip_version: 4
cidr: {get_param: subnet_ipv4_cidr}
dns_nameservers: {get_param: dns_nameservers}
router:
type: OS::Neutron::Router
properties:
external_gateway_info:
network: {get_param: floating_network}
router_interface_ipv4:
type: OS::Neutron::RouterInterface
properties:
router: {get_resource: router}
subnet: {get_resource: subnet_ipv4}
outputs:
network_id:
value: {get_resource: network}

View File

@ -0,0 +1,32 @@
heat_template_version: newton
description: |
Stack of resources used to test floating IP
resources:
icmp_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: icmp
rules:
- protocol: icmp
ssh_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: ssh
rules:
- protocol: tcp
port_range_min: 22
port_range_max: 22
outputs:
icmp_security_group_id:
value: {get_resource: icmp_security_group}
ssh_security_group_id:
value: {get_resource: ssh_security_group}

View File

@ -0,0 +1,76 @@
# Copyright (c) 2019 Red Hat
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import tobiko
from tobiko import config
from tobiko.common import asserts
from tobiko.openstack import heat
from tobiko.tests.scenario.neutron import base
CONF = config.CONF
class FloatingIPFixture(heat.HeatStackFixture):
template = base.heat_template_file('floating_ip.yaml')
parameters = {'floating_network': CONF.tobiko.neutron.floating_network,
'image': CONF.tobiko.nova.image,
'flavor': CONF.tobiko.nova.flavor}
def setup_parameters(self):
super(FloatingIPFixture, self).setup_parameters()
internal_network = tobiko.setup_fixture(
base.InternalNetworkFixture).wait_for_outputs()
self.parameters['internal_network'] = internal_network.network_id
class FloatingIPWithPortSecurityFixture(FloatingIPFixture):
parameters = {'port_security_enabled': True}
class FloatingIPWithSecurityGroupFixture(FloatingIPFixture):
parameters = {'port_security_enabled': True}
def setup_parameters(self):
super(FloatingIPWithSecurityGroupFixture, self).setup_parameters()
security_groups = tobiko.setup_fixture(
base.SecurityGroupsFixture).wait_for_outputs()
self.parameters['security_groups'] = [
security_groups.icmp_security_group_id]
class FloatingIPTest(base.NeutronTest):
"""Tests server connectivity"""
def test_ping_floating_ip(self,
fixture_type=FloatingIPFixture,
should_fail=False):
"""Validates connectivity to a server post upgrade."""
stack = tobiko.setup_fixture(fixture_type)
outputs = stack.wait_for_outputs()
asserts.assert_ping(outputs.floating_ip_address,
should_fail=should_fail)
def test_ping_floating_ip_with_port_security(self):
"""Validates connectivity to a server post upgrade."""
self.test_ping_floating_ip(
fixture_type=FloatingIPWithPortSecurityFixture,
should_fail=True)
def test_ping_floating_ip_security_group(self):
"""Validates connectivity to a server post upgrade."""
self.test_ping_floating_ip(
fixture_type=FloatingIPWithSecurityGroupFixture)

View File

@ -49,9 +49,7 @@ whitelist_externals=
[testenv:neutron]
commands =
tobiko-delete --all
tobiko-create --all
stestr --test-path ./tobiko/tests/scenario run {posargs}
stestr --test-path ./tobiko/tests/scenario/neutron run {posargs}
deps =
{[tobiko]deps}