Skip to content

Commit 489ce2f

Browse files
Lucas Batesdavem330
authored andcommitted
tc-testing: Restore original behaviour for namespaces in tdc
This patch restores the original behaviour for tdc prior to the introduction of the plugin system, where the network namespace functionality was split from the main script. It introduces the concept of required plugins for testcases, and will automatically load any plugin that isn't already enabled when said plugin is required by even one testcase. Additionally, the -n option for the nsPlugin is deprecated so the default action is to make use of the namespaces. Instead, we introduce -N to not use them, but still create the veth pair. buildebpfPlugin's -B option is also deprecated. If a test cases requires the features of a specific plugin in order to pass, it should instead include a new key/value pair describing plugin interactions: "plugins": { "requires": "buildebpfPlugin" }, A test case can have more than one required plugin: a list can be inserted as the value for 'requires'. Signed-off-by: Lucas Bates <[email protected]> Acked-by: Davide Caratti <[email protected]> Tested-by: Nicolas Dichtel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 27d9280 commit 489ce2f

File tree

8 files changed

+296
-20
lines changed

8 files changed

+296
-20
lines changed

tools/testing/selftests/tc-testing/README

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ REQUIREMENTS
1212
* Minimum Python version of 3.4. Earlier 3.X versions may work but are not
1313
guaranteed.
1414

15-
* The kernel must have network namespace support
15+
* The kernel must have network namespace support if using nsPlugin
1616

1717
* The kernel must have veth support available, as a veth pair is created
18-
prior to running the tests.
18+
prior to running the tests when using nsPlugin.
1919

2020
* The kernel must have the appropriate infrastructure enabled to run all tdc
2121
unit tests. See the config file in this directory for minimum required
@@ -53,8 +53,12 @@ commands being tested must be run as root. The code that enforces
5353
execution by root uid has been moved into a plugin (see PLUGIN
5454
ARCHITECTURE, below).
5555

56-
If nsPlugin is linked, all tests are executed inside a network
57-
namespace to prevent conflicts within the host.
56+
Tests that use a network device should have nsPlugin.py listed as a
57+
requirement for that test. nsPlugin executes all commands within a
58+
network namespace and creates a veth pair which may be used in those test
59+
cases. To disable execution within the namespace, pass the -N option
60+
to tdc when starting a test run; the veth pair will still be created
61+
by the plugin.
5862

5963
Running tdc without any arguments will run all tests. Refer to the section
6064
on command line arguments for more information, or run:
@@ -154,8 +158,8 @@ action:
154158
netns:
155159
options for nsPlugin (run commands in net namespace)
156160

157-
-n, --namespace
158-
Run commands in namespace as specified in tdc_config.py
161+
-N, --no-namespace
162+
Do not run commands in a network namespace.
159163

160164
valgrind:
161165
options for valgrindPlugin (run command under test under Valgrind)
@@ -171,7 +175,8 @@ was in the tdc.py script has been moved into the plugins.
171175

172176
The plugins are in the directory plugin-lib. The are executed from
173177
directory plugins. Put symbolic links from plugins to plugin-lib,
174-
and name them according to the order you want them to run.
178+
and name them according to the order you want them to run. This is not
179+
necessary if a test case being run requires a specific plugin to work.
175180

176181
Example:
177182

@@ -223,7 +228,8 @@ directory:
223228
- rootPlugin.py:
224229
implements the enforcement of running as root
225230
- nsPlugin.py:
226-
sets up a network namespace and runs all commands in that namespace
231+
sets up a network namespace and runs all commands in that namespace,
232+
while also setting up dummy devices to be used in testing.
227233
- valgrindPlugin.py
228234
runs each command in the execute stage under valgrind,
229235
and checks for leaks.

tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ def add_args(self, parser):
3434
'buildebpf',
3535
'options for buildebpfPlugin')
3636
self.argparser_group.add_argument(
37-
'-B', '--buildebpf', action='store_true',
38-
help='build eBPF programs')
37+
'--nobuildebpf', action='store_false', default=True,
38+
dest='buildebpf',
39+
help='Don\'t build eBPF programs')
3940

4041
return self.argparser
4142

tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def pre_suite(self, testcount, testidlist):
1818

1919
if self.args.namespace:
2020
self._ns_create()
21+
else:
22+
self._ports_create()
2123

2224
def post_suite(self, index):
2325
'''run commands after test_runner goes into a test loop'''
@@ -27,15 +29,17 @@ def post_suite(self, index):
2729

2830
if self.args.namespace:
2931
self._ns_destroy()
32+
else:
33+
self._ports_destroy()
3034

3135
def add_args(self, parser):
3236
super().add_args(parser)
3337
self.argparser_group = self.argparser.add_argument_group(
3438
'netns',
3539
'options for nsPlugin(run commands in net namespace)')
3640
self.argparser_group.add_argument(
37-
'-n', '--namespace', action='store_true',
38-
help='Run commands in namespace')
41+
'-N', '--no-namespace', action='store_false', default=True,
42+
dest='namespace', help='Don\'t run commands in namespace')
3943
return self.argparser
4044

4145
def adjust_command(self, stage, command):
@@ -73,20 +77,30 @@ def adjust_command(self, stage, command):
7377
print('adjust_command: return command [{}]'.format(command))
7478
return command
7579

80+
def _ports_create(self):
81+
cmd = 'ip link add $DEV0 type veth peer name $DEV1'
82+
self._exec_cmd('pre', cmd)
83+
cmd = 'ip link set $DEV0 up'
84+
self._exec_cmd('pre', cmd)
85+
if not self.args.namespace:
86+
cmd = 'ip link set $DEV1 up'
87+
self._exec_cmd('pre', cmd)
88+
89+
def _ports_destroy(self):
90+
cmd = 'ip link del $DEV0'
91+
self._exec_cmd('post', cmd)
92+
7693
def _ns_create(self):
7794
'''
7895
Create the network namespace in which the tests will be run and set up
7996
the required network devices for it.
8097
'''
98+
self._ports_create()
8199
if self.args.namespace:
82100
cmd = 'ip netns add {}'.format(self.args.NAMES['NS'])
83101
self._exec_cmd('pre', cmd)
84-
cmd = 'ip link add $DEV0 type veth peer name $DEV1'
85-
self._exec_cmd('pre', cmd)
86102
cmd = 'ip link set $DEV1 netns {}'.format(self.args.NAMES['NS'])
87103
self._exec_cmd('pre', cmd)
88-
cmd = 'ip link set $DEV0 up'
89-
self._exec_cmd('pre', cmd)
90104
cmd = 'ip -n {} link set $DEV1 up'.format(self.args.NAMES['NS'])
91105
self._exec_cmd('pre', cmd)
92106
if self.args.device:

tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
"actions",
5555
"bpf"
5656
],
57+
"plugins": {
58+
"requires": "buildebpfPlugin"
59+
},
5760
"setup": [
5861
[
5962
"$TC action flush action bpf",
@@ -78,6 +81,9 @@
7881
"actions",
7982
"bpf"
8083
],
84+
"plugins": {
85+
"requires": "buildebpfPlugin"
86+
},
8187
"setup": [
8288
[
8389
"$TC action flush action bpf",

0 commit comments

Comments
 (0)