From 404e0e2e0b430d3cc8fdecc39db4e3f4b023e0c5 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 27 Mar 2019 09:13:44 +0100 Subject: [PATCH] Rewrite floating IP test case Change-Id: I05cd4bed9082cd9f9b3dfc48233418e1756191d2 --- tobiko/tests/scenario/neutron/__init__.py | 0 tobiko/tests/scenario/neutron/base.py | 46 +++++++++++ .../neutron/templates/floating_ip.yaml | 56 ++++++++++++++ .../neutron/templates/internal_network.yaml | 47 ++++++++++++ .../neutron/templates/security_groups.yaml | 32 ++++++++ .../scenario/neutron/test_floating_ip.py | 76 +++++++++++++++++++ tox.ini | 4 +- 7 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 tobiko/tests/scenario/neutron/__init__.py create mode 100644 tobiko/tests/scenario/neutron/base.py create mode 100644 tobiko/tests/scenario/neutron/templates/floating_ip.yaml create mode 100644 tobiko/tests/scenario/neutron/templates/internal_network.yaml create mode 100644 tobiko/tests/scenario/neutron/templates/security_groups.yaml create mode 100644 tobiko/tests/scenario/neutron/test_floating_ip.py diff --git a/tobiko/tests/scenario/neutron/__init__.py b/tobiko/tests/scenario/neutron/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tobiko/tests/scenario/neutron/base.py b/tobiko/tests/scenario/neutron/base.py new file mode 100644 index 000000000..65ab54a21 --- /dev/null +++ b/tobiko/tests/scenario/neutron/base.py @@ -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 diff --git a/tobiko/tests/scenario/neutron/templates/floating_ip.yaml b/tobiko/tests/scenario/neutron/templates/floating_ip.yaml new file mode 100644 index 000000000..903fe7007 --- /dev/null +++ b/tobiko/tests/scenario/neutron/templates/floating_ip.yaml @@ -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]} diff --git a/tobiko/tests/scenario/neutron/templates/internal_network.yaml b/tobiko/tests/scenario/neutron/templates/internal_network.yaml new file mode 100644 index 000000000..03a87bea1 --- /dev/null +++ b/tobiko/tests/scenario/neutron/templates/internal_network.yaml @@ -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} diff --git a/tobiko/tests/scenario/neutron/templates/security_groups.yaml b/tobiko/tests/scenario/neutron/templates/security_groups.yaml new file mode 100644 index 000000000..b2a751624 --- /dev/null +++ b/tobiko/tests/scenario/neutron/templates/security_groups.yaml @@ -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} diff --git a/tobiko/tests/scenario/neutron/test_floating_ip.py b/tobiko/tests/scenario/neutron/test_floating_ip.py new file mode 100644 index 000000000..e025d38da --- /dev/null +++ b/tobiko/tests/scenario/neutron/test_floating_ip.py @@ -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) diff --git a/tox.ini b/tox.ini index 915c46331..dc9b92dd6 100644 --- a/tox.ini +++ b/tox.ini @@ -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}