Update fixtures for creating networks.
Change-Id: I947b81dc5d3960b4c4dd0c1f3a56e0cd7d13de6d
This commit is contained in:
parent
d037d9e913
commit
d380816f81
|
@ -19,6 +19,11 @@ from tobiko.openstack.neutron import _extension
|
|||
|
||||
get_neutron_client = _client.get_neutron_client
|
||||
NeutronClientFixture = _client.NeutronClientFixture
|
||||
find_network = _client.find_network
|
||||
list_network = _client.list_network
|
||||
show_network = _client.show_network
|
||||
show_router = _client.show_router
|
||||
show_subnet = _client.show_subnet
|
||||
|
||||
get_networking_extensions = _extension.get_networking_extensions
|
||||
missing_networking_extensions = _extension.missing_networking_extensions
|
||||
|
|
|
@ -16,6 +16,7 @@ from __future__ import absolute_import
|
|||
from neutronclient.v2_0 import client as neutronclient
|
||||
|
||||
from tobiko.openstack import _client
|
||||
from tobiko.openstack.neutron import _exceptions
|
||||
|
||||
|
||||
class NeutronClientFixture(_client.OpenstackClientFixture):
|
||||
|
@ -34,3 +35,40 @@ def get_neutron_client(session=None, shared=True, init_client=None,
|
|||
init_client=init_client)
|
||||
client.setUp()
|
||||
return client.client
|
||||
|
||||
|
||||
def find_network(network, session=None, **params):
|
||||
networks = [n
|
||||
for n in list_network(session=session, **params)
|
||||
if network in (n['name'], n['id'])]
|
||||
|
||||
if not networks:
|
||||
raise _exceptions.NoSuchNetwork(network=network)
|
||||
|
||||
elif len(networks) > 1:
|
||||
network_ids = [n['id'] for n in networks]
|
||||
raise _exceptions.MoreNetworksFound(
|
||||
network=network,
|
||||
netowrk_ids=(', '.join(network_ids)))
|
||||
|
||||
return networks[0]
|
||||
|
||||
|
||||
def list_network(session=None, **params):
|
||||
return get_neutron_client(session=session).list_networks(**params)[
|
||||
'networks']
|
||||
|
||||
|
||||
def show_network(network, session=None, **params):
|
||||
return get_neutron_client(session=session).show_network(
|
||||
network, **params)['network']
|
||||
|
||||
|
||||
def show_router(router, session=None, **params):
|
||||
return get_neutron_client(session=session).show_router(
|
||||
router, **params)['router']
|
||||
|
||||
|
||||
def show_subnet(subnet, session=None, **params):
|
||||
return get_neutron_client(session=session).show_subnet(
|
||||
subnet, **params)['subnet']
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright 2019 Red Hat
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
class NoSuchNetwork(tobiko.TobikoException):
|
||||
message = "No such network found for {network!r}"
|
||||
|
||||
|
||||
class MoreNetworksFound(tobiko.TobikoException):
|
||||
message = "More than one network found for {network!r}: {network_ids!s}"
|
|
@ -21,5 +21,6 @@ from tobiko.openstack.stacks import _nova
|
|||
KeyPairStackFixture = _nova.KeyPairStackFixture
|
||||
|
||||
NetworkStackFixture = _neutron.NetworkStackFixture
|
||||
NetworkNetMtuWriteStackFixture = _neutron.NetworkNetMtuWriteStackFixture
|
||||
FloatingIpServerStackFixture = _neutron.FloatingIpServerStackFixture
|
||||
SecurityGroupsFixture = _neutron.SecurityGroupsFixture
|
||||
|
|
|
@ -65,12 +65,39 @@ class NetworkStackFixture(heat.HeatStackFixture):
|
|||
# Whenever cat obtain network MTU value
|
||||
has_net_mtu = neutron.has_networking_extensions('net-mtu')
|
||||
|
||||
@property
|
||||
def network_details(self):
|
||||
return neutron.show_network(self.network_id)
|
||||
|
||||
@property
|
||||
def ipv4_subnet_details(self):
|
||||
return neutron.show_subnet(self.ipv4_subnet_id)
|
||||
|
||||
@property
|
||||
def gateway_details(self):
|
||||
return neutron.show_router(self.gateway_id)
|
||||
|
||||
@property
|
||||
def gateway_network_id(self):
|
||||
return neutron.find_network(self.gateway_network)['id']
|
||||
|
||||
@property
|
||||
def gateway_network_details(self):
|
||||
return neutron.show_network(self.gateway_network_id)
|
||||
|
||||
|
||||
@neutron.skip_if_missing_networking_extensions('net-mtu-writable')
|
||||
class NetworkNetMtuWriteStackFixture(heat.HeatStackFixture):
|
||||
|
||||
# Whenever cat obtain network MTU value
|
||||
has_net_mtu = True
|
||||
|
||||
#: Value for maximum transfer unit on the internal network
|
||||
mtu = None
|
||||
mtu = 1000
|
||||
|
||||
def setup_parameters(self):
|
||||
"""Setup Heat template parameters"""
|
||||
super(NetworkStackFixture, self).setup_parameters()
|
||||
super(NetworkNetMtuWriteStackFixture, self).setup_parameters()
|
||||
if self.mtu:
|
||||
self.setup_net_mtu_writable()
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import netaddr
|
||||
import testtools
|
||||
|
||||
import tobiko
|
||||
|
@ -27,27 +28,42 @@ from tobiko.shell import sh
|
|||
class NetworkTestCase(testtools.TestCase):
|
||||
"""Tests network creation"""
|
||||
|
||||
#: Stack of resources with a server attached to a floating IP
|
||||
#: Stack of resources with a network with a gateway router
|
||||
stack = tobiko.required_setup_fixture(stacks.NetworkStackFixture)
|
||||
|
||||
@property
|
||||
def network_details(self):
|
||||
return neutron.get_neutron_client().show_network(
|
||||
self.stack.network_id)['network']
|
||||
|
||||
@neutron.skip_if_missing_networking_extensions('port-security')
|
||||
def test_port_security_enabled(self):
|
||||
port_security_enabled = self.stack.port_security_enabled
|
||||
self.assertEqual(port_security_enabled,
|
||||
self.network_details['port_security_enabled'])
|
||||
self.assertEqual(port_security_enabled,
|
||||
self.assertEqual(self.stack.port_security_enabled,
|
||||
self.stack.network_details['port_security_enabled'])
|
||||
self.assertEqual(self.stack.port_security_enabled,
|
||||
self.stack.outputs.port_security_enabled)
|
||||
|
||||
@neutron.skip_if_missing_networking_extensions('net-mtu')
|
||||
def test_net_mtu(self):
|
||||
self.assertEqual(self.network_details['mtu'], self.stack.outputs.mtu)
|
||||
self.assertEqual(self.stack.network_details['mtu'],
|
||||
self.stack.outputs.mtu)
|
||||
|
||||
def test_ipv4_subnet_cidr(self):
|
||||
self.assertEqual(self.stack.ipv4_cidr,
|
||||
self.stack.ipv4_subnet_details['cidr'])
|
||||
|
||||
def test_ipv4_subnet_gateway_ip(self):
|
||||
self.assertEqual(str(netaddr.IPNetwork(self.stack.ipv4_cidr).ip + 1),
|
||||
self.stack.ipv4_subnet_details['gateway_ip'])
|
||||
|
||||
def test_gateway_network(self):
|
||||
self.assertEqual(
|
||||
self.stack.gateway_network_id,
|
||||
self.stack.gateway_details['external_gateway_info']['network_id'])
|
||||
|
||||
|
||||
@neutron.skip_if_missing_networking_extensions('net-mtu-write')
|
||||
class NetworkNetMtuWriteTestCase(NetworkTestCase):
|
||||
|
||||
#: Stack of resources with a network with a gateway router
|
||||
stack = tobiko.required_setup_fixture(
|
||||
stacks.NetworkNetMtuWriteStackFixture)
|
||||
|
||||
@neutron.skip_if_missing_networking_extensions('net-mtu-write')
|
||||
def test_net_mtu_write(self):
|
||||
self.assertEqual(self.stack.mtu, self.stack.outputs.mtu)
|
||||
|
||||
|
|
Loading…
Reference in New Issue