Skip to content

Commit

Permalink
tc-testing: Restore original behaviour for namespaces in tdc
Browse files Browse the repository at this point in the history
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 <lucasb@mojatatu.com>
Acked-by: Davide Caratti <dcaratti@redhat.com>
Tested-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Lucas Bates authored and David S. Miller committed Jun 25, 2019
1 parent 27d9280 commit 489ce2f
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 20 deletions.
22 changes: 14 additions & 8 deletions tools/testing/selftests/tc-testing/README
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ REQUIREMENTS
* Minimum Python version of 3.4. Earlier 3.X versions may work but are not
guaranteed.

* The kernel must have network namespace support
* The kernel must have network namespace support if using nsPlugin

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

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

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

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

-n, --namespace
Run commands in namespace as specified in tdc_config.py
-N, --no-namespace
Do not run commands in a network namespace.

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

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

Example:

Expand Down Expand Up @@ -223,7 +228,8 @@ directory:
- rootPlugin.py:
implements the enforcement of running as root
- nsPlugin.py:
sets up a network namespace and runs all commands in that namespace
sets up a network namespace and runs all commands in that namespace,
while also setting up dummy devices to be used in testing.
- valgrindPlugin.py
runs each command in the execute stage under valgrind,
and checks for leaks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def add_args(self, parser):
'buildebpf',
'options for buildebpfPlugin')
self.argparser_group.add_argument(
'-B', '--buildebpf', action='store_true',
help='build eBPF programs')
'--nobuildebpf', action='store_false', default=True,
dest='buildebpf',
help='Don\'t build eBPF programs')

return self.argparser

Expand Down
26 changes: 20 additions & 6 deletions tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def pre_suite(self, testcount, testidlist):

if self.args.namespace:
self._ns_create()
else:
self._ports_create()

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

if self.args.namespace:
self._ns_destroy()
else:
self._ports_destroy()

def add_args(self, parser):
super().add_args(parser)
self.argparser_group = self.argparser.add_argument_group(
'netns',
'options for nsPlugin(run commands in net namespace)')
self.argparser_group.add_argument(
'-n', '--namespace', action='store_true',
help='Run commands in namespace')
'-N', '--no-namespace', action='store_false', default=True,
dest='namespace', help='Don\'t run commands in namespace')
return self.argparser

def adjust_command(self, stage, command):
Expand Down Expand Up @@ -73,20 +77,30 @@ def adjust_command(self, stage, command):
print('adjust_command: return command [{}]'.format(command))
return command

def _ports_create(self):
cmd = 'ip link add $DEV0 type veth peer name $DEV1'
self._exec_cmd('pre', cmd)
cmd = 'ip link set $DEV0 up'
self._exec_cmd('pre', cmd)
if not self.args.namespace:
cmd = 'ip link set $DEV1 up'
self._exec_cmd('pre', cmd)

def _ports_destroy(self):
cmd = 'ip link del $DEV0'
self._exec_cmd('post', cmd)

def _ns_create(self):
'''
Create the network namespace in which the tests will be run and set up
the required network devices for it.
'''
self._ports_create()
if self.args.namespace:
cmd = 'ip netns add {}'.format(self.args.NAMES['NS'])
self._exec_cmd('pre', cmd)
cmd = 'ip link add $DEV0 type veth peer name $DEV1'
self._exec_cmd('pre', cmd)
cmd = 'ip link set $DEV1 netns {}'.format(self.args.NAMES['NS'])
self._exec_cmd('pre', cmd)
cmd = 'ip link set $DEV0 up'
self._exec_cmd('pre', cmd)
cmd = 'ip -n {} link set $DEV1 up'.format(self.args.NAMES['NS'])
self._exec_cmd('pre', cmd)
if self.args.device:
Expand Down
6 changes: 6 additions & 0 deletions tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"actions",
"bpf"
],
"plugins": {
"requires": "buildebpfPlugin"
},
"setup": [
[
"$TC action flush action bpf",
Expand All @@ -78,6 +81,9 @@
"actions",
"bpf"
],
"plugins": {
"requires": "buildebpfPlugin"
},
"setup": [
[
"$TC action flush action bpf",
Expand Down
Loading

0 comments on commit 489ce2f

Please sign in to comment.