Debian Codegraph @

neutron_fwaas/tests/functional/privileged/test_utils.py

raw symbols SCIP
1 # Copyright (c) 2017 Thales Services SAS
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from neutron.agent.linux import ip_lib
17 from neutron.common import utils as neutron_utils
18 from neutron.tests.common import net_helpers
19 from neutron.tests.functional import base
20
21 from neutron_fwaas.privileged.tests.functional import utils
22
23
24 class InNamespaceTest(base.BaseSudoTestCase):
25
26 def setUp(self):
27 super().setUp()
28 self.namespace = self.useFixture(net_helpers.NamespaceFixture()).name
29
30 ip = ip_lib.IPWrapper()
31 root_dev_name = neutron_utils.get_rand_device_name()
32 netns_dev_name = neutron_utils.get_rand_device_name()
33 self.root_dev, self.netns_dev = ip.add_veth(
34 root_dev_name, netns_dev_name, namespace2=self.namespace)
35 self.addCleanup(self.root_dev.link.delete)
36
37 def test_in_namespace(self):
38 before, observed, after = utils.get_in_namespace_interfaces(
39 self.namespace)
40 expected = ['lo', self.netns_dev.name]
41 self.assertCountEqual(expected, observed)
42 # Other tests can create/delete devices, so we just checks
43 # self.root_dev_name is included in the root namespace result.
44 self.assertIn(self.root_dev.name, before)
45 self.assertIn(self.root_dev.name, after)
46
47 def test_in_no_namespace(self):
48 before, observed, after = utils.get_in_namespace_interfaces(None)
49 # Other tests can create/delete devices, so we just checks
50 # self.root_dev_name is included in the root namespace result.
51 self.assertIn(self.root_dev.name, observed)
52 self.assertIn(self.root_dev.name, before)
53 self.assertIn(self.root_dev.name, after)