@ -23,6 +23,7 @@ from tempest.api.network import base_security_groups as sec_base
from tempest . common import custom_matchers
from tempest . common import utils
from tempest . lib . common . utils import data_utils
from tempest . lib . common . utils import test_utils
from tempest . lib import decorators
from tempest . lib import exceptions
@ -52,7 +53,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
def _create_subnet ( self , network , gateway = ' ' ,
cidr = None , mask_bits = None , * * kwargs ) :
subnet = self . create_subnet ( network , gateway , cidr , mask_bits )
self . addCleanup ( self . subnets_client . delete_subnet , subnet [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . subnets_client . delete_subnet , subnet [ ' id ' ] )
return subnet
def _create_network ( self , network_name = None , * * kwargs ) :
@ -60,7 +62,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
self . __class__ . __name__ )
network = self . networks_client . create_network (
name = network_name , * * kwargs ) [ ' network ' ]
self . addCleanup ( self . networks_client . delete_network ,
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . networks_client . delete_network ,
network [ ' id ' ] )
return network
@ -116,13 +119,15 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
mask_bits = address . prefixlen ,
* * allocation_pools )
body = self . ports_client . create_port ( network_id = net_id )
self . addCleanup ( self . ports_client . delete_port , body [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , body [ ' port ' ] [ ' id ' ] )
port = body [ ' port ' ]
ip_address = port [ ' fixed_ips ' ] [ 0 ] [ ' ip_address ' ]
start_ip_address = allocation_pools [ ' allocation_pools ' ] [ 0 ] [ ' start ' ]
end_ip_address = allocation_pools [ ' allocation_pools ' ] [ 0 ] [ ' end ' ]
ip_range = netaddr . IPRange ( start_ip_address , end_ip_address )
self . assertIn ( ip_address , ip_range )
self . ports_client . delete_port ( port [ ' id ' ] )
@decorators.attr ( type = ' smoke ' )
@decorators.idempotent_id ( ' c9a685bd-e83f-499c-939f-9f7863ca259f ' )
@ -168,9 +173,11 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
self . _create_subnet ( network )
# Create two ports
port_1 = self . ports_client . create_port ( network_id = network [ ' id ' ] )
self . addCleanup ( self . ports_client . delete_port , port_1 [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , port_1 [ ' port ' ] [ ' id ' ] )
port_2 = self . ports_client . create_port ( network_id = network [ ' id ' ] )
self . addCleanup ( self . ports_client . delete_port , port_2 [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , port_2 [ ' port ' ] [ ' id ' ] )
# List ports filtered by fixed_ips
port_1_fixed_ip = port_1 [ ' port ' ] [ ' fixed_ips ' ] [ 0 ] [ ' ip_address ' ]
fixed_ips = ' ip_address= ' + port_1_fixed_ip
@ -219,11 +226,13 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
fixed_ips = [ { ' subnet_id ' : subnet [ ' id ' ] , ' ip_address ' : ip_address_1 } ]
port_1 = self . ports_client . create_port ( network_id = network [ ' id ' ] ,
fixed_ips = fixed_ips )
self . addCleanup ( self . ports_client . delete_port , port_1 [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , port_1 [ ' port ' ] [ ' id ' ] )
fixed_ips = [ { ' subnet_id ' : subnet [ ' id ' ] , ' ip_address ' : ip_address_2 } ]
port_2 = self . ports_client . create_port ( network_id = network [ ' id ' ] ,
fixed_ips = fixed_ips )
self . addCleanup ( self . ports_client . delete_port , port_2 [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , port_2 [ ' port ' ] [ ' id ' ] )
# Scenario 1: List port1 (port2 is filtered out)
if ip_address_1 [ : - 1 ] != ip_address_2 [ : - 1 ] :
@ -272,12 +281,14 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
network = self . _create_network ( )
self . _create_subnet ( network )
router = self . create_router ( )
self . addCleanup ( self . routers_client . delete_router , router [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . routers_client . delete_router , router [ ' id ' ] )
port = self . ports_client . create_port ( network_id = network [ ' id ' ] )
# Add router interface to port created above
self . routers_client . add_router_interface ( router [ ' id ' ] ,
port_id = port [ ' port ' ] [ ' id ' ] )
self . addCleanup ( self . routers_client . remove_router_interface ,
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . routers_client . remove_router_interface ,
router [ ' id ' ] , port_id = port [ ' port ' ] [ ' id ' ] )
# List ports filtered by router_id
port_list = self . ports_client . list_ports ( device_id = router [ ' id ' ] )
@ -311,7 +322,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
# Create a port with multiple IP addresses
port = self . create_port ( network ,
fixed_ips = fixed_ips )
self . addCleanup ( self . ports_client . delete_port , port [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , port [ ' id ' ] )
self . assertEqual ( 2 , len ( port [ ' fixed_ips ' ] ) )
check_fixed_ips = [ subnet_1 [ ' id ' ] , subnet_2 [ ' id ' ] ]
for item in port [ ' fixed_ips ' ] :
@ -334,7 +346,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
for name in security_groups_names :
group_create_body = sec_grps_client . create_security_group (
name = name )
self . addCleanup ( self . security_groups_client . delete_security_group ,
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . security_groups_client . delete_security_group ,
group_create_body [ ' security_group ' ] [ ' id ' ] )
security_groups_list . append ( group_create_body [ ' security_group ' ]
[ ' id ' ] )
@ -342,7 +355,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
sec_grp_name = data_utils . rand_name ( ' secgroup ' )
security_group = sec_grps_client . create_security_group (
name = sec_grp_name )
self . addCleanup ( self . security_groups_client . delete_security_group ,
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . security_groups_client . delete_security_group ,
security_group [ ' security_group ' ] [ ' id ' ] )
post_body = {
" name " : data_utils . rand_name ( ' port- ' ) ,
@ -351,7 +365,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
" admin_state_up " : True ,
" fixed_ips " : fixed_ip_1 }
body = self . ports_client . create_port ( * * post_body )
self . addCleanup ( self . ports_client . delete_port , body [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , body [ ' port ' ] [ ' id ' ] )
port = body [ ' port ' ]
# Update the port with security groups
@ -402,7 +417,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
# Create a new port with user defined mac
body = self . ports_client . create_port ( network_id = self . network [ ' id ' ] ,
mac_address = free_mac_address )
self . addCleanup ( self . ports_client . delete_port , body [ ' port ' ] [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , body [ ' port ' ] [ ' id ' ] )
port = body [ ' port ' ]
body = self . ports_client . show_port ( port [ ' id ' ] )
show_port = body [ ' port ' ]
@ -418,7 +434,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest):
network = self . _create_network ( )
self . _create_subnet ( network )
port = self . create_port ( network , security_groups = [ ] )
self . addCleanup ( self . ports_client . delete_port , port [ ' id ' ] )
self . addCleanup ( test_utils . call_and_ignore_notfound_exc ,
self . ports_client . delete_port , port [ ' id ' ] )
self . assertIsNotNone ( port [ ' security_groups ' ] )
self . assertEmpty ( port [ ' security_groups ' ] )