From d1ccb644205b359d49ff0a2a4c9900ce8151729b Mon Sep 17 00:00:00 2001 From: Andrew McLeod Date: Tue, 21 Apr 2020 12:50:05 +0200 Subject: [PATCH 1/5] handle exceptions in containers when setting sysctl keys --- charmhelpers/core/sysctl.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/charmhelpers/core/sysctl.py b/charmhelpers/core/sysctl.py index f1f4a28f2..141dfa73d 100644 --- a/charmhelpers/core/sysctl.py +++ b/charmhelpers/core/sysctl.py @@ -17,7 +17,7 @@ import yaml -from subprocess import check_call +from subprocess import check_call, CalledProcessError from charmhelpers.core.hookenv import ( log, @@ -25,6 +25,10 @@ ERROR, ) +from charmhelpers.core.host import ( + is_containr, +) + __author__ = 'Jorge Niedbalski R. ' @@ -62,4 +66,10 @@ def create(sysctl_dict, sysctl_file, ignore=False): if ignore: call.append("-e") - check_call(call) + try: + check_call(call) + except CalledProcessError as e: + if is_container(): + print ("Error setting some systcl keys in this container: {}".format(e.output)) + else: + raise e From 5bb25af8abd23fed9ea6e2753b8c3034efb97e6a Mon Sep 17 00:00:00 2001 From: Andrew McLeod Date: Tue, 21 Apr 2020 14:00:46 +0200 Subject: [PATCH 2/5] fix typo --- charmhelpers/core/sysctl.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/charmhelpers/core/sysctl.py b/charmhelpers/core/sysctl.py index 141dfa73d..870ca9a08 100644 --- a/charmhelpers/core/sysctl.py +++ b/charmhelpers/core/sysctl.py @@ -25,9 +25,7 @@ ERROR, ) -from charmhelpers.core.host import ( - is_containr, -) +from charmhelpers.core.host import is_container __author__ = 'Jorge Niedbalski R. ' @@ -70,6 +68,6 @@ def create(sysctl_dict, sysctl_file, ignore=False): check_call(call) except CalledProcessError as e: if is_container(): - print ("Error setting some systcl keys in this container: {}".format(e.output)) + print("Error setting some systcl keys in this container: {}".format(e.output)) else: raise e From 43cecb64d72d7e1a2ebf75c5b59a0176a2ab4fc8 Mon Sep 17 00:00:00 2001 From: Andrew McLeod Date: Tue, 21 Apr 2020 14:17:18 +0200 Subject: [PATCH 3/5] log instead of error --- charmhelpers/core/sysctl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/charmhelpers/core/sysctl.py b/charmhelpers/core/sysctl.py index 870ca9a08..7f3f08ee6 100644 --- a/charmhelpers/core/sysctl.py +++ b/charmhelpers/core/sysctl.py @@ -68,6 +68,7 @@ def create(sysctl_dict, sysctl_file, ignore=False): check_call(call) except CalledProcessError as e: if is_container(): - print("Error setting some systcl keys in this container: {}".format(e.output)) + log("Error setting some systcl keys in this container: {}".format(e.output), + level=ERROR) else: raise e From 48c2330ce1e013502561634c88c9df8e048cde58 Mon Sep 17 00:00:00 2001 From: Andrew McLeod Date: Tue, 21 Apr 2020 14:50:18 +0200 Subject: [PATCH 4/5] fix typo, ERROR to WARNING --- charmhelpers/core/sysctl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charmhelpers/core/sysctl.py b/charmhelpers/core/sysctl.py index 7f3f08ee6..2596033ba 100644 --- a/charmhelpers/core/sysctl.py +++ b/charmhelpers/core/sysctl.py @@ -68,7 +68,7 @@ def create(sysctl_dict, sysctl_file, ignore=False): check_call(call) except CalledProcessError as e: if is_container(): - log("Error setting some systcl keys in this container: {}".format(e.output), - level=ERROR) + log("Error setting some sysctl keys in this container: {}".format(e.output), + level=WARNING) else: raise e From a6fc0b2a72389c5578a16f8cb8aea9ed61c3a0cb Mon Sep 17 00:00:00 2001 From: Andrew McLeod Date: Tue, 21 Apr 2020 14:55:59 +0200 Subject: [PATCH 5/5] import WARNING --- charmhelpers/core/sysctl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/charmhelpers/core/sysctl.py b/charmhelpers/core/sysctl.py index 2596033ba..386428d61 100644 --- a/charmhelpers/core/sysctl.py +++ b/charmhelpers/core/sysctl.py @@ -23,6 +23,7 @@ log, DEBUG, ERROR, + WARNING, ) from charmhelpers.core.host import is_container