diff mbox series

[net-next,3/6] selftests: tc-testing: use netns delete from pyroute2

Message ID 20231117171208.2066136-4-pctammela@mojatatu.com (mailing list archive)
State Accepted
Commit 3d5026fc5adbc796a0547fcef19d997786e0bb31
Delegated to: Netdev Maintainers
Headers show
Series selftests: tc-testing: more updates to tdc | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 2 maintainers not CCed: linux-kselftest@vger.kernel.org horms@kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Pedro Tammela Nov. 17, 2023, 5:12 p.m. UTC
When pyroute2 is available, use the native netns delete routine instead
of calling iproute2 to do it. As forks are expensive with some kernel
configs, minimize its usage to avoid kselftests timeouts.

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
---
 .../testing/selftests/tc-testing/plugin-lib/nsPlugin.py  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Simon Horman Nov. 20, 2023, 5:35 p.m. UTC | #1
On Fri, Nov 17, 2023 at 02:12:05PM -0300, Pedro Tammela wrote:
> When pyroute2 is available, use the native netns delete routine instead
> of calling iproute2 to do it. As forks are expensive with some kernel
> configs, minimize its usage to avoid kselftests timeouts.
> 
> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>

I have a suggestion for a follow up below, but this change looks good to me.

Reviewed-by: Simon Horman <horms@kernel.org>

> ---
>  .../testing/selftests/tc-testing/plugin-lib/nsPlugin.py  | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py b/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
> index 2b8cbfdf1083..920dcbedc395 100644
> --- a/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
> +++ b/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
> @@ -64,7 +64,10 @@ class SubPlugin(TdcPlugin):
>          if self.args.verbose:
>              print('{}.post_case'.format(self.sub_class))
>  
> -        self._ns_destroy()
> +        if netlink == True:
> +            self._nl_ns_destroy()
> +        else:
> +            self._ns_destroy()

As an aside, I think it would to rename _ns_* to
_iproute2_ns_* or similar, to make the distinction with _nl_ns_* clearer.

>  
>      def post_suite(self, index):
>          if self.args.verbose:
> @@ -174,6 +177,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.40.1
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py b/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
index 2b8cbfdf1083..920dcbedc395 100644
--- a/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
+++ b/tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
@@ -64,7 +64,10 @@  class SubPlugin(TdcPlugin):
         if self.args.verbose:
             print('{}.post_case'.format(self.sub_class))
 
-        self._ns_destroy()
+        if netlink == True:
+            self._nl_ns_destroy()
+        else:
+            self._ns_destroy()
 
     def post_suite(self, index):
         if self.args.verbose:
@@ -174,6 +177,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']))