From: Kamalesh Babulal Date: Thu, 24 Feb 2022 15:37:23 +0000 (+0530) Subject: cgroup.py: replace UnicodeDecodeError with RunError X-Git-Tag: v3.1.0~308^2~2^2~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83d2891234f887557eca24b82855d01eb7af269f;p=thirdparty%2Flibcgroup.git cgroup.py: replace UnicodeDecodeError with RunError init_cgrules(), tries creating a directory '/etc/cgconfig.d' and relies on stderr from RunError to check if the directory already exists and fails on other exceptions. The exception logic can be simplified by, passing `-p` to mkdir and fail on any RunError exceptions. This patch replaces except UnicodeDecodeError RunError to catch any exceptions raised when running the command `mkdir -p /etc/cgconfig.d`. Suggested-by: Tom Hromatka Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/ftests/cgroup.py b/ftests/cgroup.py index cbc44dd3..30fdf588 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -601,6 +601,7 @@ class Cgroup(object): cmd.append('sudo') cmd.append('mkdir') + cmd.append('-p') cmd.append('/etc/cgconfig.d') try: @@ -608,9 +609,8 @@ class Cgroup(object): config.container.run(cmd, shell_bool=True) else: Run.run(cmd, shell_bool=True) - except UnicodeDecodeError as ude: - # A unicode error is thrown when the directory already exists - pass + except RunError as re: + raise re cmd2 = list()