Commit 4da325cc authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'selftests-tc-testing-more-updates-to-tdc'

Pedro Tammela says:

====================
selftests: tc-testing: more updates to tdc

Address the issues making tdc timeout on downstream CIs like lkp and
tuxsuite.
====================

Link: https://lore.kernel.org/r/20231117171208.2066136-1-pctammela@mojatatu.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents b1711d43 4968afa0
Loading
Loading
Loading
Loading
+49 −49
Original line number Diff line number Diff line
@@ -17,71 +17,60 @@ except ImportError:
    netlink = False
    print("!!! Consider installing pyroute2 !!!")

def prepare_suite(obj, test):
    original = obj.args.NAMES
class SubPlugin(TdcPlugin):
    def __init__(self):
        self.sub_class = 'ns/SubPlugin'
        super().__init__()

    def pre_suite(self, testcount, testlist):
        from itertools import cycle

        super().pre_suite(testcount, testlist)

    def prepare_test(self, test):
        if 'skip' in test and test['skip'] == 'yes':
            return

        if 'nsPlugin' not in test['plugins']:
            return

    shadow = {}
    shadow['IP'] = original['IP']
    shadow['TC'] = original['TC']
    shadow['NS'] = '{}-{}'.format(original['NS'], test['random'])
    shadow['DEV0'] = '{}id{}'.format(original['DEV0'], test['id'])
    shadow['DEV1'] = '{}id{}'.format(original['DEV1'], test['id'])
    shadow['DUMMY'] = '{}id{}'.format(original['DUMMY'], test['id'])
    shadow['DEV2'] = original['DEV2']
    obj.args.NAMES = shadow

        if netlink == True:
        obj._nl_ns_create()
            self._nl_ns_create()
        else:
        obj._ns_create()
            self._ns_create()

        # Make sure the netns is visible in the fs
        ticks = 20
        while True:
        obj._proc_check()
            if ticks == 0:
                raise TimeoutError
            self._proc_check()
            try:
            ns = obj.args.NAMES['NS']
                ns = self.args.NAMES['NS']
                f = open('/run/netns/{}'.format(ns))
                f.close()
                break
            except:
                time.sleep(0.1)
                ticks -= 1
                continue

    obj.args.NAMES = original

class SubPlugin(TdcPlugin):
    def __init__(self):
        self.sub_class = 'ns/SubPlugin'
        super().__init__()

    def pre_suite(self, testcount, testlist):
        from itertools import cycle

        super().pre_suite(testcount, testlist)

        print("Setting up namespaces and devices...")

        with Pool(self.args.mp) as p:
            it = zip(cycle([self]), testlist)
            p.starmap(prepare_suite, it)

    def pre_case(self, caseinfo, test_skip):
    def pre_case(self, test, test_skip):
        if self.args.verbose:
            print('{}.pre_case'.format(self.sub_class))

        if test_skip:
            return

        self.prepare_test(test)

    def post_case(self):
        if self.args.verbose:
            print('{}.post_case'.format(self.sub_class))

        if netlink == True:
            self._nl_ns_destroy()
        else:
            self._ns_destroy()

    def post_suite(self, index):
@@ -89,8 +78,7 @@ class SubPlugin(TdcPlugin):
            print('{}.post_suite'.format(self.sub_class))

        # Make sure we don't leak resources
        for f in os.listdir('/run/netns/'):
            cmd = self._replace_keywords("$IP netns del {}".format(f))
        cmd = "$IP -a netns del"

        if self.args.verbose > 3:
            print('_exec_cmd:  command "{}"'.format(cmd))
@@ -143,7 +131,10 @@ class SubPlugin(TdcPlugin):
        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')
            ticks = 20
            while True:
                if ticks == 0:
                    raise TimeoutError
                try:
                    dev1_idx = ip.link_lookup(ifname=dev1)[0]
                    dummy_idx = ip.link_lookup(ifname=dummy)[0]
@@ -152,17 +143,22 @@ class SubPlugin(TdcPlugin):
                    break
                except:
                    time.sleep(0.1)
                    ticks -= 1
                    continue
        netns.popns()

        with IPRoute() as ip:
            ticks = 20
            while True:
                if ticks == 0:
                    raise TimeoutError
                try:
                    dev0_idx = ip.link_lookup(ifname=dev0)[0]
                    ip.link('set', index=dev0_idx, state='up')
                    break
                except:
                    time.sleep(0.1)
                    ticks -= 1
                    continue

    def _ns_create_cmds(self):
@@ -192,6 +188,10 @@ class SubPlugin(TdcPlugin):
        '''
        self._exec_cmd_batched('pre', self._ns_create_cmds())

    def _nl_ns_destroy(self):
        ns = self.args.NAMES['NS']
        netns.remove(ns)

    def _ns_destroy_cmd(self):
        return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS']))

+2 −1
Original line number Diff line number Diff line
@@ -616,7 +616,7 @@ def test_runner_mp(pm, args, alltests):
    batches.insert(0, serial)

    print("Executing {} tests in parallel and {} in serial".format(len(parallel), len(serial)))
    print("Using {} batches".format(len(batches)))
    print("Using {} batches and {} workers".format(len(batches), args.mp))

    # We can't pickle these objects so workaround them
    global mp_pm
@@ -1017,6 +1017,7 @@ def main():
    parser = pm.call_add_args(parser)
    (args, remaining) = parser.parse_known_args()
    args.NAMES = NAMES
    args.mp = min(args.mp, 4)
    pm.set_args(args)
    check_default_settings(args, remaining, pm)
    if args.verbose > 2: