From 1a1a9c9bfe27677069cf24707f1f7b127fdf1684 Mon Sep 17 00:00:00 2001 From: Sandro Bonazzola Date: Mon, 5 Sep 2022 14:00:41 +0200 Subject: [PATCH] pycodestyle fixes: scenarios/openshift/post_action_regex.py Signed-off-by: Sandro Bonazzola --- scenarios/openshift/post_action_regex.py | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/scenarios/openshift/post_action_regex.py b/scenarios/openshift/post_action_regex.py index f7e2ce2e..56993f4c 100755 --- a/scenarios/openshift/post_action_regex.py +++ b/scenarios/openshift/post_action_regex.py @@ -1,14 +1,17 @@ #!/usr/bin/env python3 -import subprocess +import logging import re +import subprocess import sys + from kubernetes import client, config from kubernetes.client.rest import ApiException -import logging -# List all namespaces def list_namespaces(): + """ + List all namespaces + """ namespaces = [] try: config.load_kube_config() @@ -16,17 +19,18 @@ def list_namespaces(): ret = cli.list_namespace(pretty=True) except ApiException as e: logging.error( - "Exception when calling \ - CoreV1Api->list_namespaced_pod: %s\n" - % e + "Exception when calling CoreV1Api->list_namespaced_pod: %s\n", + e ) for namespace in ret.items: namespaces.append(namespace.metadata.name) return namespaces -# Check if all the watch_namespaces are valid def check_namespaces(namespaces): + """ + Check if all the watch_namespaces are valid + """ try: valid_namespaces = list_namespaces() regex_namespaces = set(namespaces) - set(valid_namespaces) @@ -41,7 +45,11 @@ def check_namespaces(namespaces): break invalid_namespaces = regex_namespaces - valid_regex if invalid_namespaces: - raise Exception("There exists no namespaces matching: %s" % (invalid_namespaces)) + raise Exception( + "There exists no namespaces matching: %s" % ( + invalid_namespaces + ) + ) return list(final_namespaces) except Exception as e: logging.error("%s" % (e)) @@ -51,7 +59,11 @@ def check_namespaces(namespaces): def run(cmd): try: output = subprocess.Popen( - cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + cmd, + shell=True, + universal_newlines=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT ) (out, err) = output.communicate() except Exception as e: @@ -63,7 +75,9 @@ regex_namespace = ["openshift-.*"] namespaces = check_namespaces(regex_namespace) pods_running = 0 for namespace in namespaces: - new_pods_running = run("oc get pods -n " + namespace + " | grep -c Running").rstrip() + new_pods_running = run( + "oc get pods -n " + namespace + " | grep -c Running" + ).rstrip() try: pods_running += int(new_pods_running) except Exception: