Skip to content

Commit

Permalink
Merge "Separate admin test from RoutersNegativeTest"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed May 8, 2017
2 parents 01545ff + 6627827 commit a93a8e9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 33 deletions.
63 changes: 63 additions & 0 deletions tempest/api/network/admin/test_routers_negative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2013 OpenStack Foundation
# 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.

import testtools

from tempest.api.network import base
from tempest import config
from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
from tempest import test

CONF = config.CONF


class RoutersAdminNegativeTest(base.BaseAdminNetworkTest):

@classmethod
def skip_checks(cls):
super(RoutersAdminNegativeTest, cls).skip_checks()
if not test.is_extension_enabled('router', 'network'):
msg = "router extension not enabled."
raise cls.skipException(msg)

@decorators.attr(type=['negative'])
@decorators.idempotent_id('7101cc02-058a-11e7-93e1-fa163e4fa634')
@test.requires_ext(extension='ext-gw-mode', service='network')
@testtools.skipUnless(CONF.network.public_network_id,
'The public_network_id option must be specified.')
def test_router_set_gateway_used_ip_returns_409(self):
# At first create a address from public_network_id
port = self.admin_ports_client.create_port(
network_id=CONF.network.public_network_id)['port']
self.addCleanup(self.admin_ports_client.delete_port,
port_id=port['id'])
# Add used ip and subnet_id in external_fixed_ips
fixed_ip = {
'subnet_id': port['fixed_ips'][0]['subnet_id'],
'ip_address': port['fixed_ips'][0]['ip_address']
}
external_gateway_info = {
'network_id': CONF.network.public_network_id,
'external_fixed_ips': [fixed_ip]
}
# Create a router and set gateway to used ip
self.assertRaises(lib_exc.Conflict,
self.admin_routers_client.create_router,
external_gateway_info=external_gateway_info)


class RoutersAdminNegativeIpV6Test(RoutersAdminNegativeTest):
_ip_version = 6
43 changes: 10 additions & 33 deletions tempest/api/network/test_routers_negative.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
# under the License.

import netaddr
import testtools

from tempest.api.network import base_routers as base
from tempest.api.network import base
from tempest import config
from tempest.lib.common.utils import data_utils
from tempest.lib import decorators
Expand All @@ -26,7 +25,7 @@
CONF = config.CONF


class RoutersNegativeTest(base.BaseRouterTest):
class RoutersNegativeTest(base.BaseNetworkTest):

@classmethod
def skip_checks(cls):
Expand Down Expand Up @@ -75,37 +74,15 @@ def test_add_router_interfaces_on_overlapping_subnets_returns_400(self):
network_name=data_utils.rand_name('router-network02-'))
subnet01 = self.create_subnet(network01)
subnet02 = self.create_subnet(network02)
self._add_router_interface_with_subnet_id(self.router['id'],
subnet01['id'])
interface = self.routers_client.add_router_interface(
self.router['id'], subnet_id=subnet01['id'])
self.addCleanup(self.routers_client.remove_router_interface,
self.router['id'], subnet_id=subnet01['id'])
self.assertEqual(subnet01['id'], interface['subnet_id'])
self.assertRaises(lib_exc.BadRequest,
self._add_router_interface_with_subnet_id,
self.routers_client.add_router_interface,
self.router['id'],
subnet02['id'])

@decorators.attr(type=['negative'])
@decorators.idempotent_id('7101cc02-058a-11e7-93e1-fa163e4fa634')
@test.requires_ext(extension='ext-gw-mode', service='network')
@testtools.skipUnless(CONF.network.public_network_id,
'The public_network_id option must be specified.')
def test_router_set_gateway_used_ip_returns_409(self):
# At first create a address from public_network_id
port = self.admin_ports_client.create_port(
network_id=CONF.network.public_network_id)['port']
self.addCleanup(self.admin_ports_client.delete_port,
port_id=port['id'])
# Add used ip and subnet_id in external_fixed_ips
fixed_ip = {
'subnet_id': port['fixed_ips'][0]['subnet_id'],
'ip_address': port['fixed_ips'][0]['ip_address']
}
external_gateway_info = {
'network_id': CONF.network.public_network_id,
'external_fixed_ips': [fixed_ip]
}
# Create a router and set gateway to used ip
self.assertRaises(lib_exc.Conflict,
self.admin_routers_client.create_router,
external_gateway_info=external_gateway_info)
subnet_id=subnet02['id'])

@decorators.attr(type=['negative'])
@decorators.idempotent_id('04df80f9-224d-47f5-837a-bf23e33d1c20')
Expand Down Expand Up @@ -142,7 +119,7 @@ class RoutersNegativeIpV6Test(RoutersNegativeTest):
_ip_version = 6


class DvrRoutersNegativeTest(base.BaseRouterTest):
class DvrRoutersNegativeTest(base.BaseNetworkTest):

@classmethod
def skip_checks(cls):
Expand Down

0 comments on commit a93a8e9

Please sign in to comment.