Merge "Remove .is_vm_port() from LogicalPort"

This commit is contained in:
Jenkins 2017-08-27 10:06:53 +00:00 committed by Gerrit Code Review
commit 067307d76c
7 changed files with 21 additions and 35 deletions

View File

@ -388,9 +388,6 @@ class DHCPApp(df_base_app.DFlowApp):
LOG.warning("No support for non IPv4 protocol")
return
if not lport.is_vm_port():
return
subnet_id = lport.subnets[0].id
self.subnet_vm_port_map[subnet_id].add(lport.id)

View File

@ -14,7 +14,6 @@ import copy
from jsonmodels import fields
from jsonmodels import models
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants as n_const
from oslo_config import cfg
from oslo_log import log
@ -180,15 +179,6 @@ class LogicalPort(mf.ModelBase, mixins.Name, mixins.Version, mixins.Topic,
def is_remote(self):
return port_locator.is_port_remote(self)
def is_vm_port(self):
"""
Return True if the device owner starts with 'compute:' (or is None)
"""
owner = self.device_owner
if not owner or owner.startswith(n_const.DEVICE_OWNER_COMPUTE_PREFIX):
return True
return False
def __str__(self):
data = {}
for name in dir(self):

View File

@ -88,21 +88,20 @@ def print_command(full_args, run_as_root=False):
)))
def get_vm_port(nb_api, ip=None, mac=None):
def find_logical_port(nb_api, ip=None, mac=None):
ports = nb_api.get_all(l2.LogicalPort)
for port in ports:
if port.is_vm_port():
if ip:
if not isinstance(ip, netaddr.IPAddress):
ip = netaddr.IPAddress(ip)
if port.ip != ip:
continue
if mac:
if not isinstance(mac, netaddr.EUI):
mac = netaddr.EUI(mac)
if port.mac != mac:
continue
return port
if ip:
if not isinstance(ip, netaddr.IPAddress):
ip = netaddr.IPAddress(ip)
if port.ip != ip:
continue
if mac:
if not isinstance(mac, netaddr.EUI):
mac = netaddr.EUI(mac)
if port.mac != mac:
continue
return port
return None

View File

@ -71,7 +71,7 @@ class TestL2FLows(test_base.DFTestBase):
exception=Exception('Metadata id was not found in OpenFlow rules')
)
port = utils.wait_until_is_and_return(
lambda: utils.get_vm_port(self.nb_api, ip, mac),
lambda: utils.find_logical_port(self.nb_api, ip, mac),
exception=Exception('No port assigned to VM')
)
tunnel_key = port.unique_key
@ -130,7 +130,7 @@ class TestL2FLows(test_base.DFTestBase):
exception=Exception('Metadata id was not found in OpenFlow rules')
)
port = utils.wait_until_is_and_return(
lambda: utils.get_vm_port(self.nb_api, ip, mac),
lambda: utils.find_logical_port(self.nb_api, ip, mac),
exception=Exception('No port assigned to VM')
)
port_key = port.unique_key
@ -304,7 +304,7 @@ class TestL2FLows(test_base.DFTestBase):
exception=Exception('Metadata id was not found in OpenFlow rules')
)
port = utils.wait_until_is_and_return(
lambda: utils.get_vm_port(self.nb_api, ip, mac),
lambda: utils.find_logical_port(self.nb_api, ip, mac),
exception=Exception('No port assigned to VM')
)
port_key = port.unique_key
@ -498,7 +498,7 @@ class TestL2FLows(test_base.DFTestBase):
exception=Exception('Metadata id was not found in OpenFlow rules')
)
port = utils.wait_until_is_and_return(
lambda: utils.get_vm_port(self.nb_api, ip, mac),
lambda: utils.find_logical_port(self.nb_api, ip, mac),
exception=Exception('No port assigned to VM')
)
tunnel_key = port.unique_key

View File

@ -127,7 +127,7 @@ class TestOvsdbMonitor(test_base.DFTestBase):
exception=Exception('Could not get wanted offline vm')
)
utils.wait_until_none(
lambda: utils.get_vm_port(self.nb_api, ip=None, mac=mac),
lambda: utils.find_logical_port(self.nb_api, ip=None, mac=mac),
timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT, sleep=1,
exception=Exception('Port was not deleted')
)
@ -169,12 +169,12 @@ class TestOvsdbMonitor(test_base.DFTestBase):
vm1.close()
vm2.close()
utils.wait_until_none(
lambda: utils.get_vm_port(self.nb_api, ip=None, mac=mac1),
lambda: utils.find_logical_port(self.nb_api, ip=None, mac=mac1),
timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT, sleep=1,
exception=Exception('Port was not deleted')
)
utils.wait_until_none(
lambda: utils.get_vm_port(self.nb_api, ip=None, mac=mac2),
lambda: utils.find_logical_port(self.nb_api, ip=None, mac=mac2),
timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT, sleep=1,
exception=Exception('Port was not deleted')
)

View File

@ -238,7 +238,7 @@ class TestOVSFlowsForPortSecurity(test_base.DFTestBase):
mac = addresses[0]['OS-EXT-IPS-MAC:mac_addr']
self.assertIsNotNone(mac)
port = utils.wait_until_is_and_return(
lambda: utils.get_vm_port(self.nb_api, ip, mac),
lambda: utils.find_logical_port(self.nb_api, ip, mac),
exception=Exception('No port assigned to VM')
)

View File

@ -76,7 +76,7 @@ class TestSnatFlows(test_base.DFTestBase):
self.assertIsNotNone(mac)
port = utils.wait_until_is_and_return(
lambda: utils.get_vm_port(self.nb_api, ip, mac),
lambda: utils.find_logical_port(self.nb_api, ip, mac),
exception=Exception('No port assigned to VM')
)
port_key = port.unique_key