]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgroup.py: replace UnicodeDecodeError with RunError
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 24 Feb 2022 15:37:23 +0000 (21:07 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 24 Feb 2022 16:31:45 +0000 (09:31 -0700)
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 <tom.hromatka@oracle.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests/cgroup.py

index cbc44dd3768f7b304f5b6157655b26597fb83d89..30fdf5887f937ec0de06d39a06d48c06f913a230 100644 (file)
@@ -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()