Add a create_router utility function
Similary to other neutron resources, add a utility function for
creating a logical router in tempest.api.network.base.BaseNetworkClient
Also, adapt test_floating_ips to use this function
Change-Id: I36f60028f75f7d4b2ed814a965431d2d4138cfbd
Partial-Bug: #1228091
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index cfac257..c3a66c5 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -56,6 +56,7 @@
cls.networks = []
cls.subnets = []
cls.ports = []
+ cls.routers = []
cls.pools = []
cls.vips = []
cls.members = []
@@ -73,6 +74,8 @@
cls.client.delete_pool(pool['id'])
for port in cls.ports:
cls.client.delete_port(port['id'])
+ for router in cls.routers:
+ cls.client.delete_router(router['id'])
for subnet in cls.subnets:
cls.client.delete_subnet(subnet['id'])
for network in cls.networks:
@@ -125,6 +128,21 @@
return port
@classmethod
+ def create_router(cls, router_name=None, admin_state_up=False,
+ external_network_id=None, enable_snat=None):
+ ext_gw_info = {}
+ if external_network_id:
+ ext_gw_info['network_id'] = external_network_id
+ if enable_snat:
+ ext_gw_info['enable_snat'] = enable_snat
+ resp, body = cls.client.create_router(
+ router_name, external_gateway_info=ext_gw_info,
+ admin_state_up=admin_state_up)
+ router = body['router']
+ cls.routers.append(router)
+ return router
+
+ @classmethod
def create_pool(cls, name, lb_method, protocol, subnet):
"""Wrapper utility that returns a test pool."""
resp, body = cls.client.create_pool(name, lb_method, protocol,
diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py
index ca2c879..9acb6c5 100644
--- a/tempest/api/network/test_floating_ips.py
+++ b/tempest/api/network/test_floating_ips.py
@@ -47,11 +47,9 @@
# Create network, subnet, router and add interface
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
- resp, router = cls.client.create_router(
+ cls.router = cls.create_router(
rand_name('router-'),
- external_gateway_info={"network_id":
- cls.network_cfg.public_network_id})
- cls.router = router['router']
+ external_network_id=cls.network_cfg.public_network_id)
resp, _ = cls.client.add_router_interface_with_subnet_id(
cls.router['id'], cls.subnet['id'])
cls.port = list()
@@ -66,7 +64,6 @@
cls.subnet['id'])
for i in range(2):
cls.client.delete_port(cls.port[i]['id'])
- cls.client.delete_router(cls.router['id'])
super(FloatingIPTestJSON, cls).tearDownClass()
def _delete_floating_ip(self, floating_ip_id):
diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py
index 8b939fe..2cfbf61 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -52,6 +52,8 @@
@attr(type='smoke')
def test_create_show_list_update_delete_router(self):
# Create a router
+ # NOTE(salv-orlando): Do not invoke self.create_router
+ # as we need to check the response code
name = rand_name('router-')
resp, create_body = self.client.create_router(
name, external_gateway_info={
@@ -94,41 +96,37 @@
def test_add_remove_router_interface_with_subnet_id(self):
network = self.create_network()
subnet = self.create_subnet(network)
- name = rand_name('router-')
- resp, create_body = self.client.create_router(name)
- self.addCleanup(self.client.delete_router, create_body['router']['id'])
+ router = self.create_router(rand_name('router-'))
# Add router interface with subnet id
resp, interface = self.client.add_router_interface_with_subnet_id(
- create_body['router']['id'], subnet['id'])
+ router['id'], subnet['id'])
self.assertEqual('200', resp['status'])
self.addCleanup(self._remove_router_interface_with_subnet_id,
- create_body['router']['id'], subnet['id'])
+ router['id'], subnet['id'])
self.assertTrue('subnet_id' in interface.keys())
self.assertTrue('port_id' in interface.keys())
# Verify router id is equal to device id in port details
resp, show_port_body = self.client.show_port(
interface['port_id'])
self.assertEqual(show_port_body['port']['device_id'],
- create_body['router']['id'])
+ router['id'])
@attr(type='smoke')
def test_add_remove_router_interface_with_port_id(self):
network = self.create_network()
self.create_subnet(network)
- name = rand_name('router-')
- resp, create_body = self.client.create_router(name)
- self.addCleanup(self.client.delete_router, create_body['router']['id'])
+ router = self.create_router(rand_name('router-'))
resp, port_body = self.client.create_port(network['id'])
# add router interface to port created above
resp, interface = self.client.add_router_interface_with_port_id(
- create_body['router']['id'], port_body['port']['id'])
+ router['id'], port_body['port']['id'])
self.assertEqual('200', resp['status'])
self.addCleanup(self._remove_router_interface_with_port_id,
- create_body['router']['id'], port_body['port']['id'])
+ router['id'], port_body['port']['id'])
self.assertTrue('subnet_id' in interface.keys())
self.assertTrue('port_id' in interface.keys())
# Verify router id is equal to device id in port details
resp, show_port_body = self.client.show_port(
interface['port_id'])
self.assertEqual(show_port_body['port']['device_id'],
- create_body['router']['id'])
+ router['id'])