@ -14,6 +14,7 @@ from neutron_lib import constants
from neutronclient . common import exceptions
from oslo_utils import uuidutils
from neutron . tests . common . agents import l2_extensions
from neutron . tests . fullstack import base
from neutron . tests . fullstack . resources import config
from neutron . tests . fullstack . resources import environment
@ -22,28 +23,28 @@ from neutron.tests.unit import testlib_api
load_tests = testlib_api . module_load_tests
class TestSegmentationId ( base . BaseFullStackTestCase ) :
class BaseSegmentationIdTest ( base . BaseFullStackTestCase ) :
scenarios = [
( ' Open vSwitch Agent ' , { ' l2_agent_type ' : constants . AGENT_TYPE_OVS } ) ,
( ' Linux Bridge Agent ' , {
' l2_agent_type ' : constants . AGENT_TYPE_LINUXBRIDGE } ) ]
network_type = " vlan "
def setUp ( self ) :
host s _description = [
host_descriptions = [
environment . HostDescription (
l2_agent_type = self . l2_agent_type , l3_agent = False ) ]
l2_agent_type = self . l2_agent_type , l3_agent = False
) for _ in range ( self . num_hosts ) ]
env = environment . Environment (
environment . EnvironmentDescription ( ) ,
hosts_description )
environment . EnvironmentDescription (
network_type = self . network_type ) ,
host_descriptions )
super ( TestSegmentationId , self ) . setUp ( env )
self . tenan t_id = uuidutils . generate_uuid ( )
super ( BaseSegmentationIdTest , self ) . setUp ( env )
self . projec t_id = uuidutils . generate_uuid ( )
def _create_network ( self ) :
seg_id = 100
network = self . safe_client . create_network (
self . tenant_id , network_type = " vlan " , segmentation_id = seg_id ,
self . project_id , network_type = self . network_type ,
segmentation_id = seg_id ,
physical_network = config . PHYSICAL_NETWORK_NAME )
self . assertEqual ( seg_id , network [ ' provider:segmentation_id ' ] )
@ -54,7 +55,6 @@ class TestSegmentationId(base.BaseFullStackTestCase):
return network
def _update_segmentation_id ( self , network ) :
# Now change segmentation_id to some other value
new_seg_id = network [ ' provider:segmentation_id ' ] + 1
new_net_args = { ' provider:segmentation_id ' : new_seg_id }
network = self . safe_client . update_network (
@ -65,21 +65,32 @@ class TestSegmentationId(base.BaseFullStackTestCase):
network = self . safe_client . client . show_network (
network [ ' id ' ] ) [ ' network ' ]
self . assertEqual ( new_seg_id , network [ ' provider:segmentation_id ' ] )
return network
class TestSegmentationId ( BaseSegmentationIdTest ) :
scenarios = [
( ' Open vSwitch Agent ' , { ' l2_agent_type ' : constants . AGENT_TYPE_OVS } ) ,
( ' Linux Bridge Agent ' , {
' l2_agent_type ' : constants . AGENT_TYPE_LINUXBRIDGE } ) ]
num_hosts = 1
def test_change_segmentation_id_no_ports_in_network ( self ) :
network = self . _create_network ( )
# Now change segmentation_id to some other value
self . _update_segmentation_id ( network )
def test_change_segmentation_id_with_unbound_ports_in_network ( self ) :
network = self . _create_network ( )
self . safe_client . create_subnet (
self . tenant_id , network [ ' id ' ] , ' 20.0.0.0/24 ' )
self . projec t_id, network [ ' id ' ] , ' 20.0.0.0/24 ' )
# Unbound port
self . safe_client . create_port ( self . tenan t_id, network [ ' id ' ] )
self . safe_client . create_port ( self . projec t_id, network [ ' id ' ] )
# Port failed to bind
self . safe_client . create_port ( self . tenan t_id, network [ ' id ' ] ,
self . safe_client . create_port ( self . projec t_id, network [ ' id ' ] ,
" non-exisiting-host " )
self . _update_segmentation_id ( network )
@ -88,8 +99,8 @@ class TestSegmentationId(base.BaseFullStackTestCase):
network = self . _create_network ( )
self . safe_client . create_subnet (
self . tenan t_id, network [ ' id ' ] , ' 20.0.0.0/24 ' )
self . safe_client . create_port ( self . tenan t_id, network [ ' id ' ] ,
self . projec t_id, network [ ' id ' ] , ' 20.0.0.0/24 ' )
self . safe_client . create_port ( self . projec t_id, network [ ' id ' ] ,
self . environment . hosts [ 0 ] . hostname )
if self . l2_agent_type == constants . AGENT_TYPE_LINUXBRIDGE :
@ -99,3 +110,32 @@ class TestSegmentationId(base.BaseFullStackTestCase):
self . _update_segmentation_id , network )
else :
self . _update_segmentation_id ( network )
class TestSegmentationIdConnectivity ( BaseSegmentationIdTest ) :
scenarios = [
( ' Open vSwitch Agent ' , { ' l2_agent_type ' : constants . AGENT_TYPE_OVS } ) ]
num_hosts = 2
def _ensure_vlan_id_set_in_flows ( self , vlan_id ) :
for host in self . environment . hosts :
l2_extensions . wait_for_mod_vlan_id_applied ( host . br_phys , vlan_id )
def test_connectivity_after_segmentation_id_update ( self ) :
network = self . _create_network ( )
self . safe_client . create_subnet (
self . project_id , network [ ' id ' ] ,
cidr = ' 10.0.0.0/24 ' ,
gateway_ip = ' 10.0.0.1 ' ,
name = ' subnet-test ' ,
enable_dhcp = False )
vms = self . _prepare_vms_in_net ( self . project_id , network , False )
self . _ensure_vlan_id_set_in_flows ( network [ ' provider:segmentation_id ' ] )
vms . ping_all ( )
network = self . _update_segmentation_id ( network )
self . _ensure_vlan_id_set_in_flows ( network [ ' provider:segmentation_id ' ] )
vms . ping_all ( )