From b696725f7a5bcd5a07d5f254cf26a4142b3b3b0d Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Mon, 8 Apr 2019 13:04:54 +0200 Subject: [PATCH] Test net-mtu-writable networking API extension Change-Id: Iff28e2aaa728d9e5eef4339bb439f42f4987a723 --- tobiko/tests/scenario/neutron/base.py | 49 ------------ tobiko/tests/scenario/neutron/stacks.py | 76 +++++++++++++++++++ .../neutron/templates/floating_ip.yaml | 5 ++ .../neutron/templates/internal_network.yaml | 19 +++++ .../scenario/neutron/test_floating_ip.py | 43 ++++++++--- 5 files changed, 134 insertions(+), 58 deletions(-) delete mode 100644 tobiko/tests/scenario/neutron/base.py create mode 100644 tobiko/tests/scenario/neutron/stacks.py diff --git a/tobiko/tests/scenario/neutron/base.py b/tobiko/tests/scenario/neutron/base.py deleted file mode 100644 index 3c99130be..000000000 --- a/tobiko/tests/scenario/neutron/base.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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 - -import tobiko -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') - floating_network = CONF.tobiko.neutron.floating_network - - -class SecurityGroupsFixture(heat.HeatStackFixture): - template = heat_template_file('security_groups.yaml') - - -class NeutronTest(base.TobikoTest): - - def setup_fixture(self, fixture_type): - stack = tobiko.setup_fixture(fixture_type) - stack.wait_for_outputs() - return stack diff --git a/tobiko/tests/scenario/neutron/stacks.py b/tobiko/tests/scenario/neutron/stacks.py new file mode 100644 index 000000000..6d2ea1f61 --- /dev/null +++ b/tobiko/tests/scenario/neutron/stacks.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 os + +from tobiko import config +from tobiko.openstack import heat +from tobiko.openstack import neutron + + +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') + floating_network = CONF.tobiko.neutron.floating_network + port_security_enabled = False + mtu = None + + def setup_parameters(self): + super(InternalNetworkFixture, self).setup_parameters() + if self.port_security_enabled or neutron.has_networking_extensions( + 'port-security'): + self.setup_port_security() + if neutron.has_networking_extensions('net-mtu'): + self.setup_net_mtu() + if self.mtu: + self.setup_net_mtu_writable() + + @neutron.skip_if_missing_networking_extensions('port-security') + def setup_port_security(self): + self.parameters.update( + port_security_enabled=self.port_security_enabled) + + @neutron.skip_if_missing_networking_extensions('net-mtu') + def setup_net_mtu(self): + self.parameters.update(has_net_mtu=True) + + @neutron.skip_if_missing_networking_extensions('net-mtu-writable') + def setup_net_mtu_writable(self): + self.parameters.setdefault('value_specs', {}).update(mtu=self.mtu) + + +class InternalNetworkFixtureWithPortSecurity(InternalNetworkFixture): + port_security_enabled = True + + +@neutron.skip_if_missing_networking_extensions('net-mtu-writable') +class InternalNetworkWithNetMtuWritableFixture(InternalNetworkFixture): + mtu = 1000 + + +@neutron.skip_if_missing_networking_extensions('security-group') +class SecurityGroupsFixture(heat.HeatStackFixture): + template = heat_template_file('security_groups.yaml') diff --git a/tobiko/tests/scenario/neutron/templates/floating_ip.yaml b/tobiko/tests/scenario/neutron/templates/floating_ip.yaml index 903fe7007..a52f0bcf0 100644 --- a/tobiko/tests/scenario/neutron/templates/floating_ip.yaml +++ b/tobiko/tests/scenario/neutron/templates/floating_ip.yaml @@ -8,15 +8,20 @@ description: | 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: [] diff --git a/tobiko/tests/scenario/neutron/templates/internal_network.yaml b/tobiko/tests/scenario/neutron/templates/internal_network.yaml index 9db9aa7a9..28ca45923 100644 --- a/tobiko/tests/scenario/neutron/templates/internal_network.yaml +++ b/tobiko/tests/scenario/neutron/templates/internal_network.yaml @@ -8,22 +8,38 @@ description: | 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"] + + port_security_enabled: + type: boolean + default: false + value_specs: type: json default: {} + has_net_mtu: + type: boolean + default: false + + +conditions: + has_net_mtu: {get_param: has_net_mtu} + resources: network: type: OS::Neutron::Net properties: + port_security_enabled: {get_param: port_security_enabled} value_specs: {get_param: value_specs} subnet_ipv4: @@ -48,7 +64,10 @@ resources: outputs: + network_id: value: {get_resource: network} + mtu: value: {get_attr: [network, mtu]} + condition: has_net_mtu diff --git a/tobiko/tests/scenario/neutron/test_floating_ip.py b/tobiko/tests/scenario/neutron/test_floating_ip.py index 930deedc2..f4db8ee37 100644 --- a/tobiko/tests/scenario/neutron/test_floating_ip.py +++ b/tobiko/tests/scenario/neutron/test_floating_ip.py @@ -16,36 +16,50 @@ from __future__ import absolute_import import tobiko from tobiko import config -from tobiko.openstack import heat -from tobiko.tests.scenario.neutron import base from tobiko.shell import ping +from tobiko.openstack import heat +from tobiko.openstack import neutron +from tobiko.tests import base +from tobiko.tests.scenario.neutron import stacks CONF = config.CONF class FloatingIPFixture(heat.HeatStackFixture): - template = base.heat_template_file('floating_ip.yaml') + template = stacks.heat_template_file('floating_ip.yaml') # template parameters floating_network = CONF.tobiko.neutron.floating_network image = CONF.tobiko.nova.image flavor = CONF.tobiko.nova.flavor - internal_network_fixture = base.InternalNetworkFixture + internal_network_fixture = stacks.InternalNetworkFixture + + # derived attributes internal_network = None + port_security_enabled = False + security_groups = None def setup_parameters(self): super(FloatingIPFixture, self).setup_parameters() self.setup_internal_network() - self.parameters['internal_network'] = self.internal_network.network_id + if self.port_security_enabled: + self.setup_port_security() def setup_internal_network(self): self.internal_network = tobiko.setup_fixture( self.internal_network_fixture).wait_for_outputs() + self.parameters['internal_network'] = self.internal_network.network_id + + @neutron.skip_if_missing_networking_extensions('port-security') + def setup_port_security(self): + self.parameters.update( + port_security_enabled=self.port_security_enabled, + security_groups=self.security_groups or []) -class FloatingIPTest(base.NeutronTest): +class FloatingIPTest(base.TobikoTest): """Tests server connectivity""" floating_ip_fixture = FloatingIPFixture @@ -61,11 +75,13 @@ class FloatingIPTest(base.NeutronTest): def test_ping(self): ping.ping_until_received(self.floating_ip_address).assert_replied() + @neutron.skip_if_missing_networking_extensions('net-mtu') def test_ping_with_mtu_packet(self): ping.ping_until_received(self.floating_ip_address, packet_size=self.mtu, fragmentation=False).assert_replied() + @neutron.skip_if_missing_networking_extensions('net-mtu') def test_ping_with_oversized_packet(self): # Wait for VM to get ready ping.ping_until_received(self.floating_ip_address) @@ -76,11 +92,12 @@ class FloatingIPTest(base.NeutronTest): check=False).assert_not_replied() +@neutron.skip_if_missing_networking_extensions('port-security') class FloatingIPWithPortSecurityFixture(FloatingIPFixture): port_security_enabled = True -class FloatingIPWithPortSecurityTest(base.NeutronTest): +class FloatingIPWithPortSecurityTest(base.TobikoTest): floating_ip_fixture = FloatingIPFixture floating_ip_with_securtity_fixture = FloatingIPWithPortSecurityFixture @@ -101,11 +118,11 @@ class FloatingIPWithPortSecurityTest(base.NeutronTest): def test_ping(self): ping.ping_until_received(self.floating_ip_address).assert_replied() ping.ping(self.floating_ip_address_with_security, - count=5).assert_not_replied() + count=5, check=False).assert_not_replied() class FloatingIPWithSecurityGroupFixture(FloatingIPWithPortSecurityFixture): - security_groups_fixture = base.SecurityGroupsFixture + security_groups_fixture = stacks.SecurityGroupsFixture security_groups = None def setup_parameters(self): @@ -121,3 +138,11 @@ class FloatingIPWithSecurityGroupFixture(FloatingIPWithPortSecurityFixture): class FloatingIPWithSecurityGroupTest(FloatingIPTest): floating_ip_fixture = FloatingIPWithSecurityGroupFixture + + +class FloatingIPWithNetMtuWritableFixture(FloatingIPFixture): + internal_network_fixture = stacks.InternalNetworkWithNetMtuWritableFixture + + +class FlatingIpWithMtuWritableTest(FloatingIPTest): + floating_ip_fixture = FloatingIPWithNetMtuWritableFixture