2018-02-14 14:09:23 -05:00
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
from string import Template
|
|
|
|
import subprocess
|
|
|
|
import time
|
2023-09-19 10:54:03 -03:00
|
|
|
from multiprocessing import Pool
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
from functools import cached_property
|
2018-02-14 14:09:23 -05:00
|
|
|
from TdcPlugin import TdcPlugin
|
|
|
|
|
|
|
|
from tdc_config import *
|
|
|
|
|
2023-11-14 13:04:40 -03:00
|
|
|
try:
|
|
|
|
from pyroute2 import netns
|
|
|
|
from pyroute2 import IPRoute
|
|
|
|
netlink = True
|
|
|
|
except ImportError:
|
|
|
|
netlink = False
|
|
|
|
print("!!! Consider installing pyroute2 !!!")
|
|
|
|
|
2018-02-14 14:09:23 -05:00
|
|
|
class SubPlugin(TdcPlugin):
|
|
|
|
def __init__(self):
|
|
|
|
self.sub_class = 'ns/SubPlugin'
|
|
|
|
super().__init__()
|
|
|
|
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
def pre_suite(self, testcount, testlist):
|
|
|
|
super().pre_suite(testcount, testlist)
|
2018-02-14 14:09:23 -05:00
|
|
|
|
2023-11-17 14:12:04 -03:00
|
|
|
def prepare_test(self, test):
|
|
|
|
if 'skip' in test and test['skip'] == 'yes':
|
|
|
|
return
|
2018-02-14 14:09:23 -05:00
|
|
|
|
2023-11-17 14:12:04 -03:00
|
|
|
if 'nsPlugin' not in test['plugins']:
|
|
|
|
return
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-17 14:12:04 -03:00
|
|
|
if netlink == True:
|
|
|
|
self._nl_ns_create()
|
|
|
|
else:
|
2023-11-24 12:42:46 -03:00
|
|
|
self._ipr2_ns_create()
|
2023-11-17 14:12:04 -03:00
|
|
|
|
|
|
|
# Make sure the netns is visible in the fs
|
2023-11-17 14:12:07 -03:00
|
|
|
ticks = 20
|
2023-11-17 14:12:04 -03:00
|
|
|
while True:
|
2023-11-17 14:12:07 -03:00
|
|
|
if ticks == 0:
|
|
|
|
raise TimeoutError
|
2023-11-17 14:12:04 -03:00
|
|
|
self._proc_check()
|
|
|
|
try:
|
|
|
|
ns = self.args.NAMES['NS']
|
|
|
|
f = open('/run/netns/{}'.format(ns))
|
|
|
|
f.close()
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
time.sleep(0.1)
|
2023-11-17 14:12:07 -03:00
|
|
|
ticks -= 1
|
2023-11-17 14:12:04 -03:00
|
|
|
continue
|
|
|
|
|
|
|
|
def pre_case(self, test, test_skip):
|
2018-02-14 14:09:23 -05:00
|
|
|
if self.args.verbose:
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
print('{}.pre_case'.format(self.sub_class))
|
|
|
|
|
|
|
|
if test_skip:
|
|
|
|
return
|
|
|
|
|
2023-11-17 14:12:04 -03:00
|
|
|
self.prepare_test(test)
|
|
|
|
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
def post_case(self):
|
|
|
|
if self.args.verbose:
|
|
|
|
print('{}.post_case'.format(self.sub_class))
|
2018-02-14 14:09:23 -05:00
|
|
|
|
2023-11-17 14:12:05 -03:00
|
|
|
if netlink == True:
|
|
|
|
self._nl_ns_destroy()
|
|
|
|
else:
|
2023-11-24 12:42:46 -03:00
|
|
|
self._ipr2_ns_destroy()
|
2018-02-14 14:09:23 -05:00
|
|
|
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
def post_suite(self, index):
|
|
|
|
if self.args.verbose:
|
|
|
|
print('{}.post_suite'.format(self.sub_class))
|
|
|
|
|
|
|
|
# Make sure we don't leak resources
|
2023-11-24 12:42:47 -03:00
|
|
|
cmd = self._replace_keywords("$IP -a netns del")
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-17 14:12:06 -03:00
|
|
|
if self.args.verbose > 3:
|
|
|
|
print('_exec_cmd: command "{}"'.format(cmd))
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-17 14:12:06 -03:00
|
|
|
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2018-02-14 14:09:23 -05:00
|
|
|
def adjust_command(self, stage, command):
|
|
|
|
super().adjust_command(stage, command)
|
|
|
|
cmdform = 'list'
|
|
|
|
cmdlist = list()
|
|
|
|
|
|
|
|
if self.args.verbose:
|
|
|
|
print('{}.adjust_command'.format(self.sub_class))
|
|
|
|
|
|
|
|
if not isinstance(command, list):
|
|
|
|
cmdform = 'str'
|
|
|
|
cmdlist = command.split()
|
|
|
|
else:
|
|
|
|
cmdlist = command
|
|
|
|
if stage == 'setup' or stage == 'execute' or stage == 'verify' or stage == 'teardown':
|
|
|
|
if self.args.verbose:
|
|
|
|
print('adjust_command: stage is {}; inserting netns stuff in command [{}] list [{}]'.format(stage, command, cmdlist))
|
|
|
|
cmdlist.insert(0, self.args.NAMES['NS'])
|
|
|
|
cmdlist.insert(0, 'exec')
|
|
|
|
cmdlist.insert(0, 'netns')
|
2019-08-30 18:51:47 +02:00
|
|
|
cmdlist.insert(0, self.args.NAMES['IP'])
|
2018-02-14 14:09:23 -05:00
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if cmdform == 'str':
|
|
|
|
command = ' '.join(cmdlist)
|
|
|
|
else:
|
|
|
|
command = cmdlist
|
|
|
|
|
|
|
|
if self.args.verbose:
|
|
|
|
print('adjust_command: return command [{}]'.format(command))
|
|
|
|
return command
|
|
|
|
|
2023-11-14 13:04:40 -03:00
|
|
|
def _nl_ns_create(self):
|
|
|
|
ns = self.args.NAMES["NS"];
|
|
|
|
dev0 = self.args.NAMES["DEV0"];
|
|
|
|
dev1 = self.args.NAMES["DEV1"];
|
|
|
|
dummy = self.args.NAMES["DUMMY"];
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-14 13:04:40 -03:00
|
|
|
if self.args.verbose:
|
|
|
|
print('{}._nl_ns_create'.format(self.sub_class))
|
|
|
|
|
|
|
|
netns.create(ns)
|
|
|
|
netns.pushns(newns=ns)
|
|
|
|
with IPRoute() as ip:
|
|
|
|
ip.link('add', ifname=dev1, kind='veth', peer={'ifname': dev0, 'net_ns_fd':'/proc/1/ns/net'})
|
|
|
|
ip.link('add', ifname=dummy, kind='dummy')
|
2023-11-17 14:12:07 -03:00
|
|
|
ticks = 20
|
2023-11-14 13:04:40 -03:00
|
|
|
while True:
|
2023-11-17 14:12:07 -03:00
|
|
|
if ticks == 0:
|
|
|
|
raise TimeoutError
|
2023-11-14 13:04:40 -03:00
|
|
|
try:
|
|
|
|
dev1_idx = ip.link_lookup(ifname=dev1)[0]
|
|
|
|
dummy_idx = ip.link_lookup(ifname=dummy)[0]
|
|
|
|
ip.link('set', index=dev1_idx, state='up')
|
|
|
|
ip.link('set', index=dummy_idx, state='up')
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
time.sleep(0.1)
|
2023-11-17 14:12:07 -03:00
|
|
|
ticks -= 1
|
2023-11-14 13:04:40 -03:00
|
|
|
continue
|
|
|
|
netns.popns()
|
|
|
|
|
|
|
|
with IPRoute() as ip:
|
2023-11-17 14:12:07 -03:00
|
|
|
ticks = 20
|
2023-11-14 13:04:40 -03:00
|
|
|
while True:
|
2023-11-17 14:12:07 -03:00
|
|
|
if ticks == 0:
|
|
|
|
raise TimeoutError
|
2023-11-14 13:04:40 -03:00
|
|
|
try:
|
|
|
|
dev0_idx = ip.link_lookup(ifname=dev0)[0]
|
|
|
|
ip.link('set', index=dev0_idx, state='up')
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
time.sleep(0.1)
|
2023-11-17 14:12:07 -03:00
|
|
|
ticks -= 1
|
2023-11-14 13:04:40 -03:00
|
|
|
continue
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-24 12:42:46 -03:00
|
|
|
def _ipr2_ns_create_cmds(self):
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
cmds = []
|
|
|
|
|
2023-11-14 13:04:39 -03:00
|
|
|
ns = self.args.NAMES['NS']
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-14 13:04:39 -03:00
|
|
|
cmds.append(self._replace_keywords('netns add {}'.format(ns)))
|
2023-11-14 13:04:40 -03:00
|
|
|
cmds.append(self._replace_keywords('link add $DEV1 type veth peer name $DEV0'))
|
2023-11-14 13:04:39 -03:00
|
|
|
cmds.append(self._replace_keywords('link set $DEV1 netns {}'.format(ns)))
|
2023-11-14 13:04:40 -03:00
|
|
|
cmds.append(self._replace_keywords('link add $DUMMY type dummy'.format(ns)))
|
2023-11-14 13:04:39 -03:00
|
|
|
cmds.append(self._replace_keywords('link set $DUMMY netns {}'.format(ns)))
|
|
|
|
cmds.append(self._replace_keywords('netns exec {} $IP link set $DEV1 up'.format(ns)))
|
|
|
|
cmds.append(self._replace_keywords('netns exec {} $IP link set $DUMMY up'.format(ns)))
|
2023-11-14 13:04:40 -03:00
|
|
|
cmds.append(self._replace_keywords('link set $DEV0 up'.format(ns)))
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-14 13:04:39 -03:00
|
|
|
if self.args.device:
|
|
|
|
cmds.append(self._replace_keywords('link set $DEV2 netns {}'.format(ns)))
|
|
|
|
cmds.append(self._replace_keywords('netns exec {} $IP link set $DEV2 up'.format(ns)))
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
|
|
|
return cmds
|
2019-06-24 21:00:27 -04:00
|
|
|
|
2023-11-24 12:42:46 -03:00
|
|
|
def _ipr2_ns_create(self):
|
2018-02-14 14:09:23 -05:00
|
|
|
'''
|
|
|
|
Create the network namespace in which the tests will be run and set up
|
|
|
|
the required network devices for it.
|
|
|
|
'''
|
2023-11-24 12:42:46 -03:00
|
|
|
self._exec_cmd_batched('pre', self._ipr2_ns_create_cmds())
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
2023-11-17 14:12:05 -03:00
|
|
|
def _nl_ns_destroy(self):
|
|
|
|
ns = self.args.NAMES['NS']
|
|
|
|
netns.remove(ns)
|
|
|
|
|
2023-11-24 12:42:46 -03:00
|
|
|
def _ipr2_ns_destroy_cmd(self):
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS']))
|
2018-02-14 14:09:23 -05:00
|
|
|
|
2023-11-24 12:42:46 -03:00
|
|
|
def _ipr2_ns_destroy(self):
|
2018-02-14 14:09:23 -05:00
|
|
|
'''
|
|
|
|
Destroy the network namespace for testing (and any associated network
|
|
|
|
devices as well)
|
|
|
|
'''
|
2023-11-24 12:42:46 -03:00
|
|
|
self._exec_cmd('post', self._ipr2_ns_destroy_cmd())
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def _proc(self):
|
|
|
|
ip = self._replace_keywords("$IP -b -")
|
|
|
|
proc = subprocess.Popen(ip,
|
|
|
|
shell=True,
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
env=ENVIR)
|
|
|
|
|
|
|
|
return proc
|
|
|
|
|
|
|
|
def _proc_check(self):
|
|
|
|
proc = self._proc
|
|
|
|
|
|
|
|
proc.poll()
|
|
|
|
|
|
|
|
if proc.returncode is not None and proc.returncode != 0:
|
|
|
|
raise RuntimeError("iproute2 exited with an error code")
|
2018-02-14 14:09:23 -05:00
|
|
|
|
|
|
|
def _exec_cmd(self, stage, command):
|
|
|
|
'''
|
|
|
|
Perform any required modifications on an executable command, then run
|
|
|
|
it in a subprocess and return the results.
|
|
|
|
'''
|
|
|
|
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
if self.args.verbose > 3:
|
2018-02-14 14:09:23 -05:00
|
|
|
print('_exec_cmd: command "{}"'.format(command))
|
|
|
|
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
proc = self._proc
|
|
|
|
|
|
|
|
proc.stdin.write((command + '\n').encode())
|
|
|
|
proc.stdin.flush()
|
|
|
|
|
|
|
|
if self.args.verbose > 3:
|
|
|
|
print('_exec_cmd proc: {}'.format(proc))
|
|
|
|
|
|
|
|
self._proc_check()
|
2018-02-14 14:09:23 -05:00
|
|
|
|
selftests/tc-testing: localize test resources
As of today, the current tdc architecture creates one netns and uses it
to run all tests. This assumption was embedded into the nsPlugin which
carried over as how the tests were written.
The tdc tests are by definition self contained and can,
theoretically, run in parallel. Even though in the kernel they will
serialize over the rtnl lock, we should expect a significant speedup of the
total wall time for the entire test suite, which is hitting close to
1100 tests at this point.
A first step to achieve this goal is to remove sharing of global resources like
veth/dummy interfaces and the netns. In this patch we 'localize' these
resources on a per test basis. Each test gets it's own netns, VETH/dummy interfaces.
The resources are spawned in the pre_suite phase, where tdc will prepare
all netns and interfaces for all tests. This is done in order to avoid
concurrency issues with netns / interfaces spawning and commands using
them. As tdc progresses, the resources are deleted after each test finishes
executing.
Tests that don't use the nsPlugin still run under the root namespace,
but are now required to manage any external resources like interfaces.
These cannot be parallelized as their definition doesn't allow it.
On the other hand, when using the nsPlugin, tests don't need to create
dummy/veth interfaces as these are handled already.
Tested-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-19 10:54:01 -03:00
|
|
|
def _exec_cmd_batched(self, stage, commands):
|
|
|
|
for cmd in commands:
|
|
|
|
self._exec_cmd(stage, cmd)
|
2018-02-14 14:09:23 -05:00
|
|
|
|
|
|
|
def _replace_keywords(self, cmd):
|
|
|
|
"""
|
|
|
|
For a given executable command, substitute any known
|
|
|
|
variables contained within NAMES with the correct values
|
|
|
|
"""
|
|
|
|
tcmd = Template(cmd)
|
|
|
|
subcmd = tcmd.safe_substitute(self.args.NAMES)
|
|
|
|
return subcmd
|