Files
neutron-fwaas/neutron_fwaas/privileged/tests/functional/utils.py
Akihiro Motoki 55874d06b1 Change netns tests with oslo.privsep to check netns links
It turns out that pyroute2.netns.setns() changes a network
namespace of a thread instead of that of a process when it is
called in a thread [1].

What we actually would like to check in test_in_namespace test
is whether operations against a network namespace work with
oslo.privsep expectedly. There is no need to check namespace inode.

This commit changes test_in_namespace test to check a list of
network devices in a namespace to check netns operation works
correctly. What the new test does are:
- create a network namespace for testing
- create a veth pair and move one of them to the network namespace
- call oslo.privsep entrypoint function to retrieve a list of
  network devices inside the netns

[1] http://lists.openstack.org/pipermail/openstack-discuss/2019-January/001761.html

Closes-Bug: #1811506
Change-Id: Ie5b238f1df707ea3ce50b5711ff791bac2681a2f
2019-01-24 00:13:56 +09:00

40 lines
1.2 KiB
Python

# Copyright (c) 2017 Thales Services SAS
# All Rights Reserved.
#
# 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.
import pyroute2
from neutron_fwaas import privileged
from neutron_fwaas.privileged import utils
def _get_ifname(link):
attr_dict = dict(link['attrs'])
return attr_dict['IFLA_IFNAME']
def list_interface_names():
iproute = pyroute2.IPRoute()
result = iproute.get_links()
return [_get_ifname(link) for link in result]
@privileged.default.entrypoint
def get_in_namespace_interfaces(namespace):
before = list_interface_names()
with utils.in_namespace(namespace):
inside = list_interface_names()
after = list_interface_names()
return before, inside, after