Merge "ip_lib: ignore gre and lo devices in get_devices by default"
This commit is contained in:
commit
008bc01ddf
@ -251,8 +251,7 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
|
|||||||
return
|
return
|
||||||
|
|
||||||
ns_ip = ip_lib.IPWrapper(namespace=self.snat_namespace.name)
|
ns_ip = ip_lib.IPWrapper(namespace=self.snat_namespace.name)
|
||||||
for d in ns_ip.get_devices(exclude_loopback=True,
|
for d in ns_ip.get_devices():
|
||||||
exclude_gre_devices=True):
|
|
||||||
if (d.name.startswith(router.EXTERNAL_DEV_PREFIX) and
|
if (d.name.startswith(router.EXTERNAL_DEV_PREFIX) and
|
||||||
d.name != interface_name):
|
d.name != interface_name):
|
||||||
LOG.debug('Deleting stale external router device: %s', d.name)
|
LOG.debug('Deleting stale external router device: %s', d.name)
|
||||||
|
@ -215,8 +215,7 @@ class FipNamespace(namespaces.Namespace):
|
|||||||
@namespaces.check_ns_existence
|
@namespaces.check_ns_existence
|
||||||
def _delete(self):
|
def _delete(self):
|
||||||
ip_wrapper = ip_lib.IPWrapper(namespace=self.name)
|
ip_wrapper = ip_lib.IPWrapper(namespace=self.name)
|
||||||
for d in ip_wrapper.get_devices(exclude_loopback=True,
|
for d in ip_wrapper.get_devices():
|
||||||
exclude_gre_devices=True):
|
|
||||||
if d.name.startswith(FIP_2_ROUTER_DEV_PREFIX):
|
if d.name.startswith(FIP_2_ROUTER_DEV_PREFIX):
|
||||||
# internal link between IRs and FIP NS
|
# internal link between IRs and FIP NS
|
||||||
ip_wrapper.del_veth(d.name)
|
ip_wrapper.del_veth(d.name)
|
||||||
|
@ -41,8 +41,7 @@ class SnatNamespace(namespaces.Namespace):
|
|||||||
@namespaces.check_ns_existence
|
@namespaces.check_ns_existence
|
||||||
def delete(self):
|
def delete(self):
|
||||||
ns_ip = ip_lib.IPWrapper(namespace=self.name)
|
ns_ip = ip_lib.IPWrapper(namespace=self.name)
|
||||||
for d in ns_ip.get_devices(exclude_loopback=True,
|
for d in ns_ip.get_devices():
|
||||||
exclude_gre_devices=True):
|
|
||||||
if d.name.startswith(constants.SNAT_INT_DEV_PREFIX):
|
if d.name.startswith(constants.SNAT_INT_DEV_PREFIX):
|
||||||
LOG.debug('Unplugging DVR device %s', d.name)
|
LOG.debug('Unplugging DVR device %s', d.name)
|
||||||
self.driver.unplug(d.name, namespace=self.name,
|
self.driver.unplug(d.name, namespace=self.name,
|
||||||
|
@ -123,8 +123,7 @@ class RouterNamespace(Namespace):
|
|||||||
@check_ns_existence
|
@check_ns_existence
|
||||||
def delete(self):
|
def delete(self):
|
||||||
ns_ip = ip_lib.IPWrapper(namespace=self.name)
|
ns_ip = ip_lib.IPWrapper(namespace=self.name)
|
||||||
for d in ns_ip.get_devices(exclude_loopback=True,
|
for d in ns_ip.get_devices():
|
||||||
exclude_gre_devices=True):
|
|
||||||
if d.name.startswith(INTERNAL_DEV_PREFIX):
|
if d.name.startswith(INTERNAL_DEV_PREFIX):
|
||||||
# device is on default bridge
|
# device is on default bridge
|
||||||
self.driver.unplug(d.name, namespace=self.name,
|
self.driver.unplug(d.name, namespace=self.name,
|
||||||
|
@ -468,8 +468,7 @@ class RouterInfo(object):
|
|||||||
|
|
||||||
def _get_existing_devices(self):
|
def _get_existing_devices(self):
|
||||||
ip_wrapper = ip_lib.IPWrapper(namespace=self.ns_name)
|
ip_wrapper = ip_lib.IPWrapper(namespace=self.ns_name)
|
||||||
ip_devs = ip_wrapper.get_devices(exclude_loopback=True,
|
ip_devs = ip_wrapper.get_devices()
|
||||||
exclude_gre_devices=True)
|
|
||||||
return [ip_dev.name for ip_dev in ip_devs]
|
return [ip_dev.name for ip_dev in ip_devs]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1337,8 +1337,7 @@ class DeviceManager(object):
|
|||||||
ns_ip = ip_lib.IPWrapper(namespace=network.namespace)
|
ns_ip = ip_lib.IPWrapper(namespace=network.namespace)
|
||||||
if not ns_ip.netns.exists(network.namespace):
|
if not ns_ip.netns.exists(network.namespace):
|
||||||
return
|
return
|
||||||
for d in ns_ip.get_devices(exclude_loopback=True,
|
for d in ns_ip.get_devices():
|
||||||
exclude_gre_devices=True):
|
|
||||||
# delete all devices except current active DHCP port device
|
# delete all devices except current active DHCP port device
|
||||||
if d.name != skip_dev_name:
|
if d.name != skip_dev_name:
|
||||||
LOG.debug("Found stale device %s, deleting", d.name)
|
LOG.debug("Found stale device %s, deleting", d.name)
|
||||||
|
@ -122,7 +122,7 @@ class IPWrapper(SubProcessBase):
|
|||||||
def device(self, name):
|
def device(self, name):
|
||||||
return IPDevice(name, namespace=self.namespace)
|
return IPDevice(name, namespace=self.namespace)
|
||||||
|
|
||||||
def get_devices(self, exclude_loopback=False, exclude_gre_devices=False):
|
def get_devices(self, exclude_loopback=True, exclude_gre_devices=True):
|
||||||
retval = []
|
retval = []
|
||||||
if self.namespace:
|
if self.namespace:
|
||||||
# we call out manually because in order to avoid screen scraping
|
# we call out manually because in order to avoid screen scraping
|
||||||
@ -215,8 +215,7 @@ class IPWrapper(SubProcessBase):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
def namespace_is_empty(self):
|
def namespace_is_empty(self):
|
||||||
return not self.get_devices(exclude_loopback=True,
|
return not self.get_devices()
|
||||||
exclude_gre_devices=True)
|
|
||||||
|
|
||||||
def garbage_collect_namespace(self):
|
def garbage_collect_namespace(self):
|
||||||
"""Conditionally destroy the namespace if it is empty."""
|
"""Conditionally destroy the namespace if it is empty."""
|
||||||
|
@ -248,8 +248,7 @@ def destroy_namespace(conf, namespace, force=False):
|
|||||||
# the error and continue with the cleanup
|
# the error and continue with the cleanup
|
||||||
LOG.error(_LE('Not all processes were killed in %s'),
|
LOG.error(_LE('Not all processes were killed in %s'),
|
||||||
namespace)
|
namespace)
|
||||||
for device in ip.get_devices(exclude_loopback=True,
|
for device in ip.get_devices():
|
||||||
exclude_gre_devices=True):
|
|
||||||
unplug_device(conf, device)
|
unplug_device(conf, device)
|
||||||
|
|
||||||
ip.garbage_collect_namespace()
|
ip.garbage_collect_namespace()
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import functools
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
@ -77,19 +75,16 @@ class TestDhcp(functional_base.BaseSudoTestCase):
|
|||||||
"10:22:33:44:55:69",
|
"10:22:33:44:55:69",
|
||||||
namespace="qdhcp-foo_id")
|
namespace="qdhcp-foo_id")
|
||||||
ipw = ip_lib.IPWrapper(namespace="qdhcp-foo_id")
|
ipw = ip_lib.IPWrapper(namespace="qdhcp-foo_id")
|
||||||
get_devices = functools.partial(
|
devices = ipw.get_devices()
|
||||||
ipw.get_devices,
|
|
||||||
exclude_loopback=True, exclude_gre_devices=True)
|
|
||||||
devices = get_devices()
|
|
||||||
self.addCleanup(ipw.netns.delete, 'qdhcp-foo_id')
|
self.addCleanup(ipw.netns.delete, 'qdhcp-foo_id')
|
||||||
self.assertEqual(sorted(["tapfoo_id2", "tapfoo_id3"]),
|
self.assertEqual(sorted(["tapfoo_id2", "tapfoo_id3"]),
|
||||||
sorted(map(str, devices)))
|
sorted(map(str, devices)))
|
||||||
# setting up dhcp for the network
|
# setting up dhcp for the network
|
||||||
dev_mgr.setup(tests_base.AttributeDict(network))
|
dev_mgr.setup(tests_base.AttributeDict(network))
|
||||||
common_utils.wait_until_true(
|
common_utils.wait_until_true(
|
||||||
lambda: 1 == len(get_devices()),
|
lambda: 1 == len(ipw.get_devices()),
|
||||||
timeout=5,
|
timeout=5,
|
||||||
sleep=0.1,
|
sleep=0.1,
|
||||||
exception=RuntimeError("only one non-loopback device must remain"))
|
exception=RuntimeError("only one non-loopback device must remain"))
|
||||||
devices = get_devices()
|
devices = ipw.get_devices()
|
||||||
self.assertEqual("tapfoo_port_id", devices[0].name)
|
self.assertEqual("tapfoo_port_id", devices[0].name)
|
||||||
|
@ -275,7 +275,7 @@ class TestIpWrapper(base.BaseTestCase):
|
|||||||
def test_get_devices(self, mocked_listdir, mocked_islink):
|
def test_get_devices(self, mocked_listdir, mocked_islink):
|
||||||
retval = ip_lib.IPWrapper().get_devices()
|
retval = ip_lib.IPWrapper().get_devices()
|
||||||
mocked_islink.assert_called_once_with('/sys/class/net/lo')
|
mocked_islink.assert_called_once_with('/sys/class/net/lo')
|
||||||
self.assertEqual(retval, [ip_lib.IPDevice('lo')])
|
self.assertEqual([], retval)
|
||||||
|
|
||||||
@mock.patch('neutron.agent.common.utils.execute')
|
@mock.patch('neutron.agent.common.utils.execute')
|
||||||
def test_get_devices_namespaces(self, mocked_execute):
|
def test_get_devices_namespaces(self, mocked_execute):
|
||||||
@ -288,7 +288,7 @@ class TestIpWrapper(base.BaseTestCase):
|
|||||||
'-maxdepth', '1', '-type', 'l', '-printf', '%f '],
|
'-maxdepth', '1', '-type', 'l', '-printf', '%f '],
|
||||||
run_as_root=True, log_fail_as_error=True)
|
run_as_root=True, log_fail_as_error=True)
|
||||||
self.assertTrue(fake_str.split.called)
|
self.assertTrue(fake_str.split.called)
|
||||||
self.assertEqual(retval, [ip_lib.IPDevice('lo', namespace='foo')])
|
self.assertEqual([], retval)
|
||||||
|
|
||||||
@mock.patch('neutron.agent.common.utils.execute')
|
@mock.patch('neutron.agent.common.utils.execute')
|
||||||
def test_get_devices_namespaces_ns_not_exists(self, mocked_execute):
|
def test_get_devices_namespaces_ns_not_exists(self, mocked_execute):
|
||||||
|
@ -335,9 +335,7 @@ class TestNetnsCleanup(base.BaseTestCase):
|
|||||||
if force:
|
if force:
|
||||||
expected.extend([
|
expected.extend([
|
||||||
mock.call().netns.exists(ns),
|
mock.call().netns.exists(ns),
|
||||||
mock.call().get_devices(
|
mock.call().get_devices()])
|
||||||
exclude_loopback=True,
|
|
||||||
exclude_gre_devices=True)])
|
|
||||||
self.assertTrue(kill_dhcp.called)
|
self.assertTrue(kill_dhcp.called)
|
||||||
unplug.assert_has_calls(
|
unplug.assert_has_calls(
|
||||||
[mock.call(conf, d) for d in
|
[mock.call(conf, d) for d in
|
||||||
|
Loading…
Reference in New Issue
Block a user