aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Jansky <jjansky@redhat.com>2020-02-19 14:03:50 +0100
committerJake Hunsaker <jhunsake@redhat.com>2020-02-19 13:17:20 -0500
commitc90dd7db30df2e8073d62d4d5d65f81f89962252 (patch)
treeedf02f4ae4ccf3ceb4d6d9a1d514d8ef285f2915
parent8bb129f1d64e056e27def5fc60fbc6f71684f1a1 (diff)
downloadsos-c90dd7db30df2e8073d62d4d5d65f81f89962252.tar.gz
[networking] namespace pattern fix
Fixing pattern from using * to .* and also adding $ on end of each namespace. For example: if you have namespaces test1 test11 test2 test3 test333 and will use -k networking.namespace_pattern="test3 test1*" pattern will result as (?:test3$|test1.*$) and only test3, test1 and test11 will be used. Before this fix with same namespaces as above and same input parameter pattern will result as (?:test3|test1*) because of * instead of .* also test2 will be used and because of mising $ also test333 will be used. Input parameter using same syntax as before "ens* eth* test1 test5", * is wildcard in this case. Resolves: #1961 Signed-off-by: Jan Jansky <jjansky@redhat.com> Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/plugins/networking.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/sos/plugins/networking.py b/sos/plugins/networking.py
index f37466f2..56d5b440 100644
--- a/sos/plugins/networking.py
+++ b/sos/plugins/networking.py
@@ -21,11 +21,11 @@ class Networking(Plugin):
option_list = [
("traceroute", "collect a traceroute to %s" % trace_host, "slow",
False),
- ("namespace_regex", "Specific namespaces regex to be " +
- "collected, namespaces regex should be separated by whitespace " +
+ ("namespace_pattern", "Specific namespaces pattern to be " +
+ "collected, namespaces pattern should be separated by whitespace " +
"as for example \"eth* ens2\"", "fast", ""),
("namespaces", "Number of namespaces to collect, 0 for unlimited. " +
- "Incompatible with the namespace_regex plugin option", "slow", 0),
+ "Incompatible with the namespace_pattern plugin option", "slow", 0),
("ethtool_namespaces", "Define if ethtool commands should be " +
"collected for namespaces", "slow", True)
]
@@ -206,22 +206,23 @@ class Networking(Plugin):
if ip_netns['status'] == 0:
out_ns = []
# Regex initialization outside of for loop
- if self.get_option("namespace_regex"):
- regex = '(?:%s)' % '|'.join(
- self.get_option("namespace_regex").split())
+ if self.get_option("namespace_pattern"):
+ pattern = '(?:%s$)' % '$|'.join(
+ self.get_option("namespace_pattern").split()
+ ).replace('*', '.*')
for line in ip_netns['output'].splitlines():
# If there's no namespaces, no need to continue
if line.startswith("Object \"netns\" is unknown") \
or line.isspace() \
or line[:1].isspace():
continue
- # if namespace_regex defined, append only namespaces
- # matching with regex
- if self.get_option("namespace_regex"):
- if bool(match(regex, line)):
+ # if namespace_pattern defined, append only namespaces
+ # matching with pattern
+ if self.get_option("namespace_pattern"):
+ if bool(match(pattern, line)):
out_ns.append(line.partition(' ')[0])
- # if namespaces is defined and namespace_regex is not defined
+ # if namespaces is defined and namespace_pattern is not defined
# remove from out_ns namespaces with higher index than defined
elif self.get_option("namespaces") != 0:
out_ns.append(line.partition(' ')[0])