neutron/neutron/tests/functional/privileged/agent/linux/test_ip_lib.py

47 lines
1.8 KiB
Python

# Copyright 2018 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import uuidutils
from neutron.agent.linux import ip_lib
from neutron.privileged.agent.linux import ip_lib as priv_ip_lib
from neutron.tests.functional import base
class GetDevicesTestCase(base.BaseLoggingTestCase):
def _remove_ns(self, namespace):
priv_ip_lib.remove_netns(namespace)
def test_get_devices(self):
namespace = 'ns_test-' + uuidutils.generate_uuid()
priv_ip_lib.create_netns(namespace)
self.addCleanup(self._remove_ns, namespace)
interfaces = ['int_01', 'int_02', 'int_03', 'int_04', 'int_05']
interfaces_to_check = (interfaces + ip_lib.FB_TUNNEL_DEVICE_NAMES +
[ip_lib.LOOPBACK_DEVNAME])
for interface in interfaces:
priv_ip_lib.create_interface(interface, namespace, 'dummy')
device_names = priv_ip_lib.get_devices(namespace)
for name in device_names:
self.assertIn(name, interfaces_to_check)
for interface in interfaces:
priv_ip_lib.delete_interface(interface, namespace)
device_names = priv_ip_lib.get_devices(namespace)
for name in device_names:
self.assertNotIn(name, interfaces)