From 2b01cb7b7f8fe62037e80b10562e357da96e02dc Mon Sep 17 00:00:00 2001 From: "Mitch Harding (the weird one)" Date: Sat, 7 Dec 2024 10:13:13 -0500 Subject: [PATCH] Linting based on pylint report --- .../tests/check_ncn_uan_ip_dns/__main__.py | 22 ++++++++-------- .../tests/compare_k8s_ncns/__main__.py | 1 + .../__main__.py | 25 ++++++++++--------- .../tools/print_goss_json_results/__main__.py | 4 +-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/csm_testing/tests/check_ncn_uan_ip_dns/__main__.py b/src/csm_testing/tests/check_ncn_uan_ip_dns/__main__.py index aa66d994..a874d56f 100644 --- a/src/csm_testing/tests/check_ncn_uan_ip_dns/__main__.py +++ b/src/csm_testing/tests/check_ncn_uan_ip_dns/__main__.py @@ -127,19 +127,19 @@ def __call__(self, method, route, **kwargs): def token(): # setup kubernetes client config.load_kube_config() - v1 = client.CoreV1Api() + k8s_v1 = client.CoreV1Api() # get kubernetes admin secret - secret = v1.read_namespaced_secret("admin-client-auth", "default").data + secret = k8s_v1.read_namespaced_secret("admin-client-auth", "default").data # decode the base64 secret - token = base64.b64decode(secret['client-secret']).decode('utf-8') + decoded_token = base64.b64decode(secret['client-secret']).decode('utf-8') # create post data to keycloak istio ingress token_data = { 'grant_type': 'client_credentials', 'client_id': 'admin-client', - 'client_secret': token + 'client_secret': decoded_token } # query keycloack @@ -175,16 +175,16 @@ def main(): # pylint: disable=missing-function-docstring continue ip_addresses = smd_entry['IPAddresses'] for ips in ip_addresses: - ip = ips['IPAddress'] - # print (ip) - if ip == '': + ipa = ips['IPAddress'] + # print (ipa) + if ipa == '': continue - if ip not in ip_set: - ip_set.add(ip) + if ipa not in ip_set: + ip_set.add(ipa) continue - log.error('Error: found duplicate IP: %s', ip) + log.error('Error: found duplicate IP: %s', ipa) error_found = True - nslookup_cmd = subprocess.Popen(('nslookup', ip), + nslookup_cmd = subprocess.Popen(('nslookup', ipa), stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, _ = nslookup_cmd.communicate() diff --git a/src/csm_testing/tests/compare_k8s_ncns/__main__.py b/src/csm_testing/tests/compare_k8s_ncns/__main__.py index 68e481ab..e88a6bd0 100644 --- a/src/csm_testing/tests/compare_k8s_ncns/__main__.py +++ b/src/csm_testing/tests/compare_k8s_ncns/__main__.py @@ -210,6 +210,7 @@ def check_k8s_node_info(k8s_node_info: K8sNodeInfo) -> bool: print_err(f"Not all Kubernetes NCNs have the same {field}") print(f"{node_info_values[field]}\n") passed = False + return passed def main() -> None: # pylint: disable=missing-function-docstring diff --git a/src/csm_testing/tests/ips_in_dnsmasq_d_in_correct_order/__main__.py b/src/csm_testing/tests/ips_in_dnsmasq_d_in_correct_order/__main__.py index 5b48b19a..00f8c78d 100644 --- a/src/csm_testing/tests/ips_in_dnsmasq_d_in_correct_order/__main__.py +++ b/src/csm_testing/tests/ips_in_dnsmasq_d_in_correct_order/__main__.py @@ -56,23 +56,23 @@ def main() -> int: # pylint: disable=missing-function-docstring level=L_LVL) logging.info("%s Starting up", now()) - fileDir = "/etc/dnsmasq.d/" - fileNames = ['CAN', 'NMN', 'HMN', 'mtl'] + file_dir = "/etc/dnsmasq.d/" + file_names = ['CAN', 'NMN', 'HMN', 'mtl'] #contents = [] # Iterate over the list of filenames and try to open the file - for fileName in fileNames: + for file_name in file_names: # clear the start and end strings - logging.info("%s Checking %s%s.", now(), fileDir, fileName) + logging.info("%s Checking %s%s.", now(), file_dir, file_name) start = end = '' try: - with open(fileDir + fileName + ".conf", 'r') as f: + with open(file_dir + file_name + ".conf", 'r') as file: #contents = f.read().split('\n') - file_lines = f.readlines() + file_lines = file.readlines() except Exception: - logging.critical("%s Couldn't open %s%s.conf.", now(), fileDir, - fileName) - print("Unable to open file: " + fileName + ".conf") + logging.critical("%s Couldn't open %s%s.conf.", now(), file_dir, + file_name) + print("Unable to open file: " + file_name + ".conf") return 1 # if the contents of the file !NULL - read the file line-by-line @@ -80,7 +80,8 @@ def main() -> int: # pylint: disable=missing-function-docstring # it's a really good bet that the format of that line will not change for line in file_lines: - logging.debug("%s line from %s: %s", now(), fileName, line.strip()) + logging.debug("%s line from %s: %s", now(), file_name, + line.strip()) # If the line continas 'dhcp-range' extract the start and end addresses if 'dhcp-range' in line: start = line.split(',')[1] @@ -105,8 +106,8 @@ def main() -> int: # pylint: disable=missing-function-docstring return 0 logging.error( "%s The file %s%s.conf failed. Start IP (%s) >= End IP (%s).", - now(), fileDir, fileName, start, end) - print("FAIL for file:" + fileDir + fileName + ".conf") + now(), file_dir, file_name, start, end) + print("FAIL for file:" + file_dir + file_name + ".conf") return 3 print("FAIL - no starting IP address found") return 4 diff --git a/src/csm_testing/tools/print_goss_json_results/__main__.py b/src/csm_testing/tools/print_goss_json_results/__main__.py index 2090c616..ca1776cb 100644 --- a/src/csm_testing/tools/print_goss_json_results/__main__.py +++ b/src/csm_testing/tools/print_goss_json_results/__main__.py @@ -581,7 +581,7 @@ def parse_args() -> Dict[str, StringList]: if is_url(source): sources["url"].append(source) continue - elif source == "stdin" or source[:6] == "stdin:": + if source == "stdin" or source[:6] == "stdin:": # Only allow a maximum of one stdin source if sources["stdin"]: stderr_print( @@ -591,7 +591,7 @@ def parse_args() -> Dict[str, StringList]: sys.exit(RC_USAGE) sources["stdin"].append(source) continue - elif is_suite_test_file(source): + if is_suite_test_file(source): source_path = f"{goss_base()}/{source}" sources["goss_file"].append(source_path) else: