Blob Blame History Raw
From 6678c472abbd5f645dbb99ab2946c0e35ded7499 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
Date: Tue, 10 Jul 2018 00:24:00 +0200
Subject: [PATCH] tuned-adm: Fix a traceback when run without action specified
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Running tuned-adm without an action specified using Python 3 results
in a traceback. This is because in this case parse_args does not
exit with a usage message in Python 3 and the 'action' option
is then undefined.

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
---
 tuned-adm.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tuned-adm.py b/tuned-adm.py
index 1b9623d..1df8cc3 100755
--- a/tuned-adm.py
+++ b/tuned-adm.py
@@ -100,7 +100,11 @@ if __name__ == "__main__":
 	debug = options.pop("debug")
 	asynco = options.pop("async")
 	timeout = options.pop("timeout")
-	action_name = options.pop("action")
+	try:
+		action_name = options.pop("action")
+	except KeyError:
+		parser.print_usage(file = sys.stderr)
+		sys.exit(1)
 	log_level = options.pop("loglevel")
 	result = False
 
-- 
2.14.4