32
32
from neutron_lib import context
33
33
from neutron_lib import exceptions as n_exc
34
34
from neutron_lib .plugins import directory
35
+ from neutron_lib .plugins import utils as p_utils
35
36
from neutron_lib .tests import tools
36
37
from neutron_lib .utils import net as n_net
37
38
from oslo_concurrency import processutils
@@ -1736,7 +1737,8 @@ def test_update_subnet_postcommit_enable_dhcp(self):
1736
1737
self .mech_driver .update_subnet_postcommit (context )
1737
1738
esd .assert_called_once_with (
1738
1739
context .current , context .network .current , mock .ANY )
1739
- umd .assert_called_once_with (mock .ANY , 'id' , subnet = subnet )
1740
+ umd .assert_called_once_with (mock .ANY , context .network .current ,
1741
+ subnet = subnet )
1740
1742
1741
1743
def test_update_subnet_postcommit_disable_dhcp (self ):
1742
1744
self .mech_driver .nb_ovn .get_subnet_dhcp_options .return_value = {
@@ -1752,7 +1754,8 @@ def test_update_subnet_postcommit_disable_dhcp(self):
1752
1754
'update_metadata_port' ) as umd :
1753
1755
self .mech_driver .update_subnet_postcommit (context )
1754
1756
dsd .assert_called_once_with (context .current ['id' ], mock .ANY )
1755
- umd .assert_called_once_with (mock .ANY , 'id' , subnet = subnet )
1757
+ umd .assert_called_once_with (mock .ANY , context .network .current ,
1758
+ subnet = subnet )
1756
1759
1757
1760
def test_update_subnet_postcommit_update_dhcp (self ):
1758
1761
self .mech_driver .nb_ovn .get_subnet_dhcp_options .return_value = {
@@ -1769,7 +1772,8 @@ def test_update_subnet_postcommit_update_dhcp(self):
1769
1772
self .mech_driver .update_subnet_postcommit (context )
1770
1773
usd .assert_called_once_with (
1771
1774
context .current , context .network .current , mock .ANY )
1772
- umd .assert_called_once_with (mock .ANY , 'id' , subnet = subnet )
1775
+ umd .assert_called_once_with (mock .ANY , context .network .current ,
1776
+ subnet = subnet )
1773
1777
1774
1778
def test__get_port_options (self ):
1775
1779
with mock .patch .object (self .mech_driver ._plugin , 'get_subnets' ) as \
@@ -1955,9 +1959,10 @@ def test_update_metadata_port_with_subnet(self):
1955
1959
mock_metaport .return_value = {'fixed_ips' : fixed_ips ,
1956
1960
'id' : 'metadata_id' }
1957
1961
mock_get_subnets .return_value = [{'id' : 'subnet1' }]
1962
+ network = {'id' : 'net_id' }
1958
1963
subnet = {'id' : 'subnet1' , 'enable_dhcp' : True }
1959
1964
self .mech_driver ._ovn_client .update_metadata_port (
1960
- self .context , 'net_id' , subnet = subnet )
1965
+ self .context , network , subnet = subnet )
1961
1966
mock_update_port .assert_not_called ()
1962
1967
1963
1968
# Subnet without DHCP, present in port.
@@ -1967,7 +1972,7 @@ def test_update_metadata_port_with_subnet(self):
1967
1972
mock_get_subnets .return_value = [{'id' : 'subnet1' }]
1968
1973
subnet = {'id' : 'subnet1' , 'enable_dhcp' : False }
1969
1974
self .mech_driver ._ovn_client .update_metadata_port (
1970
- self .context , 'net_id' , subnet = subnet )
1975
+ self .context , network , subnet = subnet )
1971
1976
port = {'id' : 'metadata_id' ,
1972
1977
'port' : {'network_id' : 'net_id' , 'fixed_ips' : []}}
1973
1978
mock_update_port .assert_called_once_with (mock .ANY , 'metadata_id' ,
@@ -1980,7 +1985,7 @@ def test_update_metadata_port_with_subnet(self):
1980
1985
mock_get_subnets .return_value = []
1981
1986
subnet = {'id' : 'subnet1' , 'enable_dhcp' : True }
1982
1987
self .mech_driver ._ovn_client .update_metadata_port (
1983
- self .context , 'net_id' , subnet = subnet )
1988
+ self .context , network , subnet = subnet )
1984
1989
fixed_ips = [{'subnet_id' : 'subnet1' }]
1985
1990
port = {'id' : 'metadata_id' ,
1986
1991
'port' : {'network_id' : 'net_id' , 'fixed_ips' : fixed_ips }}
@@ -1994,7 +1999,7 @@ def test_update_metadata_port_with_subnet(self):
1994
1999
mock_get_subnets .return_value = []
1995
2000
subnet = {'id' : 'subnet1' , 'enable_dhcp' : False }
1996
2001
self .mech_driver ._ovn_client .update_metadata_port (
1997
- self .context , 'net_id' , subnet = subnet )
2002
+ self .context , network , subnet = subnet )
1998
2003
mock_update_port .assert_not_called ()
1999
2004
2000
2005
def test_update_metadata_port_no_subnet (self ):
@@ -2011,10 +2016,11 @@ def test_update_metadata_port_no_subnet(self):
2011
2016
mock_get_subnets .return_value = [{'id' : 'subnet1' },
2012
2017
{'id' : 'subnet2' }]
2013
2018
fixed_ips = [{'subnet_id' : 'subnet1' , 'ip_address' : 'ip_add1' }]
2019
+ network = {'id' : 'net_id' }
2014
2020
mock_metaport .return_value = {'fixed_ips' : fixed_ips ,
2015
2021
'id' : 'metadata_id' }
2016
2022
self .mech_driver ._ovn_client .update_metadata_port (self .context ,
2017
- 'net_id' )
2023
+ network )
2018
2024
port = {'id' : 'metadata_id' ,
2019
2025
'port' : {'network_id' : 'net_id' , 'fixed_ips' : fixed_ips }}
2020
2026
fixed_ips .append ({'subnet_id' : 'subnet2' })
@@ -2025,10 +2031,11 @@ def test_update_metadata_port_no_subnet(self):
2025
2031
# Port with IP in subnet1; subnet1 with DHCP, subnet2 without DHCP.
2026
2032
mock_get_subnets .return_value = [{'id' : 'subnet1' }]
2027
2033
fixed_ips = [{'subnet_id' : 'subnet1' , 'ip_address' : 'ip_add1' }]
2034
+ network = {'id' : 'net_id' }
2028
2035
mock_metaport .return_value = {'fixed_ips' : fixed_ips ,
2029
2036
'id' : 'metadata_id' }
2030
2037
self .mech_driver ._ovn_client .update_metadata_port (self .context ,
2031
- 'net_id' )
2038
+ network )
2032
2039
mock_update_port .assert_not_called ()
2033
2040
2034
2041
# Port with IP in subnet1; subnet1 without DHCP.
@@ -2037,13 +2044,51 @@ def test_update_metadata_port_no_subnet(self):
2037
2044
mock_metaport .return_value = {'fixed_ips' : fixed_ips ,
2038
2045
'id' : 'metadata_id' }
2039
2046
self .mech_driver ._ovn_client .update_metadata_port (self .context ,
2040
- 'net_id' )
2047
+ network )
2041
2048
port = {'id' : 'metadata_id' ,
2042
2049
'port' : {'network_id' : 'net_id' , 'fixed_ips' : []}}
2043
2050
mock_update_port .assert_called_once_with (
2044
2051
mock .ANY , 'metadata_id' , port )
2045
2052
mock_update_port .reset_mock ()
2046
2053
2054
+ def test_update_metadata_port_no_port (self ):
2055
+ ovn_conf .cfg .CONF .set_override ('ovn_metadata_enabled' , True ,
2056
+ group = 'ovn' )
2057
+
2058
+ with mock .patch .object (
2059
+ self .mech_driver ._ovn_client , '_find_metadata_port' ) as \
2060
+ mock_find_metaport , \
2061
+ mock .patch .object (self .mech_driver ._plugin , 'get_subnets' ) as \
2062
+ mock_get_subnets , \
2063
+ mock .patch .object (p_utils , 'create_port' ) as \
2064
+ mock_create_port :
2065
+ # Subnet with DHCP, no port, port created.
2066
+ network = {'id' : 'net_id' , 'project_id' : 'project_id-foo' }
2067
+ subnet = {'id' : 'subnet1' , 'enable_dhcp' : True }
2068
+ fixed_ips = [{'subnet_id' : 'subnet1' , 'ip_address' : 'ip_add1' }]
2069
+ port = {'id' : 'metadata_id' ,
2070
+ 'network_id' : 'net_id' ,
2071
+ 'device_owner' : const .DEVICE_OWNER_DISTRIBUTED ,
2072
+ 'device_id' : 'ovnmeta-%s' % 'net_id' ,
2073
+ 'fixed_ips' : fixed_ips }
2074
+ mock_get_subnets .return_value = [subnet ]
2075
+ mock_find_metaport .return_value = None
2076
+
2077
+ # Subnet with DHCP, no port, port create failure.
2078
+ mock_create_port .return_value = None
2079
+ ret_status = self .mech_driver ._ovn_client .update_metadata_port (
2080
+ self .context , network , subnet = subnet )
2081
+ self .assertFalse (ret_status )
2082
+ mock_create_port .assert_called_once ()
2083
+
2084
+ # Subnet with DHCP, no port, port created successfully.
2085
+ mock_create_port .reset_mock ()
2086
+ mock_create_port .return_value = port
2087
+ ret_status = self .mech_driver ._ovn_client .update_metadata_port (
2088
+ self .context , network , subnet = subnet )
2089
+ self .assertTrue (ret_status )
2090
+ mock_create_port .assert_called_once ()
2091
+
2047
2092
@mock .patch .object (provisioning_blocks , 'is_object_blocked' )
2048
2093
@mock .patch .object (provisioning_blocks , 'provisioning_complete' )
2049
2094
def test_notify_dhcp_updated (self , mock_prov_complete , mock_is_obj_block ):
0 commit comments