From 8a7ad0af4aba2dab2cb825c64cdb136f3e08a4ff Mon Sep 17 00:00:00 2001 From: Paige Patton Date: Thu, 24 Oct 2024 15:48:31 -0400 Subject: [PATCH] adding proxy set up Signed-off-by: Paige Patton --- .github/workflows/build.yaml | 2 +- src/krkn_lib/elastic/krkn_elastic.py | 4 +- src/krkn_lib/k8s/krkn_kubernetes.py | 57 +++++++++---- src/krkn_lib/models/elastic/models.py | 12 +-- src/krkn_lib/models/telemetry/models.py | 5 +- .../telemetry/ocp/krkn_telemetry_openshift.py | 1 + src/krkn_lib/tests/base_test.py | 10 ++- src/krkn_lib/tests/test_krkn_elastic.py | 6 +- src/krkn_lib/tests/test_krkn_kubernetes.py | 82 ++++++++++++++----- .../test_krkn_kubernetes_pods_monitor_pool.py | 4 + .../tests/test_krkn_telemetry_models.py | 2 +- src/krkn_lib/tests/test_utils.py | 2 +- src/krkn_lib/tests/test_version.py | 3 +- src/krkn_lib/utils/functions.py | 4 +- src/testdata/fedtools-deployment.j2 | 2 +- 15 files changed, 136 insertions(+), 60 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7e7b2d10..29542513 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Create multi-node KinD cluster - uses: redhat-chaos/actions/kind@main + uses: paigerube14/actions/kind@update_kind - name: get nodes run: | diff --git a/src/krkn_lib/elastic/krkn_elastic.py b/src/krkn_lib/elastic/krkn_elastic.py index a5771103..a3c939f1 100644 --- a/src/krkn_lib/elastic/krkn_elastic.py +++ b/src/krkn_lib/elastic/krkn_elastic.py @@ -2,17 +2,17 @@ import datetime import logging +import math import time -import math import urllib3 from elasticsearch import Elasticsearch, NotFoundError from elasticsearch_dsl import Search from krkn_lib.models.elastic.models import ( ElasticAlert, - ElasticMetric, ElasticChaosRunTelemetry, + ElasticMetric, ) from krkn_lib.models.telemetry import ChaosRunTelemetry from krkn_lib.utils.safe_logger import SafeLogger diff --git a/src/krkn_lib/k8s/krkn_kubernetes.py b/src/krkn_lib/k8s/krkn_kubernetes.py index d7f3a6ae..075d58f3 100644 --- a/src/krkn_lib/k8s/krkn_kubernetes.py +++ b/src/krkn_lib/k8s/krkn_kubernetes.py @@ -12,6 +12,7 @@ from functools import partial from queue import Queue from typing import Any, Dict, List, Optional +from urllib.parse import urlparse import arcaflow_lib_kubernetes import kubernetes @@ -37,7 +38,7 @@ Volume, VolumeMount, ) -from krkn_lib.models.telemetry import NodeInfo, Taint, ClusterEvent +from krkn_lib.models.telemetry import ClusterEvent, NodeInfo, Taint from krkn_lib.utils import filter_dictionary, get_random_string from krkn_lib.utils.safe_logger import SafeLogger @@ -144,20 +145,41 @@ def __initialize_clients(self, kubeconfig_path: str = None): conf.use_context("krkn-context") try: - config.load_kube_config(kubeconfig_path) + # config.load_kube_config(kubeconfig_path) + + client_config = client.Configuration() + http_proxy = os.getenv("http_proxy", None) + if http_proxy and "@" in http_proxy: + proxy_auth = urlparse(http_proxy) + auth_string = proxy_auth.username + ":" + proxy_auth.password + client_config.username = proxy_auth.username + client_config.password = proxy_auth.password + config.load_kube_config( + kubeconfig_path, + client_configuration=client_config, + ) + + proxy_url = http_proxy + if proxy_url: + client_config.proxy = proxy_url + if proxy_auth: + client_config.proxy_headers = urllib3.util.make_headers( + proxy_basic_auth=auth_string + ) + + client.Configuration.set_default(client_config) + self.api_client = client.ApiClient() - self.k8s_client = config.new_client_from_config( - config_file=kubeconfig_path - ) - self.cli = client.CoreV1Api(self.k8s_client) + + self.cli = client.CoreV1Api(self.api_client) self.version_client = client.VersionApi(self.api_client) self.apps_api = client.AppsV1Api(self.api_client) - self.batch_cli = client.BatchV1Api(self.k8s_client) + self.batch_cli = client.BatchV1Api(self.api_client) self.net_cli = client.NetworkingV1Api(self.api_client) self.custom_object_client = client.CustomObjectsApi( - self.k8s_client + self.api_client ) - self.dyn_client = DynamicClient(self.k8s_client) + self.dyn_client = DynamicClient(self.api_client) self.watch_resource = watch.Watch() except OSError: @@ -1127,11 +1149,12 @@ def exec_command_on_node( pod_body = yaml.safe_load( pod_template.render(nodename=node_name, podname=exec_pod_name) ) + logging.info( f"Creating pod to exec command {command} on node {node_name}" ) try: - self.create_pod(pod_body, exec_pod_namespace, 300) + self.create_pod(pod_body, exec_pod_namespace, 500) except Exception as e: logging.error( f"failed to create pod {exec_pod_name} on node {node_name}," @@ -1498,10 +1521,12 @@ def apply_yaml(self, path, namespace="default") -> list[str]: the resource (optional default `default`) :return: the list of names of created objects """ - - return utils.create_from_yaml( - self.api_client, yaml_file=path, namespace=namespace - ) + try: + return utils.create_from_yaml( + self.api_client, yaml_file=path, namespace=namespace + ) + except Exception as e: + logging.error("Error trying to apply_yaml" + str(e)) def get_pod_info(self, name: str, namespace: str = "default") -> Pod: """ @@ -1712,9 +1737,7 @@ def find_kraken_node(self) -> str: raise e return node_name - def watch_node_status( - self, node: str, status: str, timeout: int - ): + def watch_node_status(self, node: str, status: str, timeout: int): """ Watch for a specific node status diff --git a/src/krkn_lib/models/elastic/models.py b/src/krkn_lib/models/elastic/models.py index cdc20c5a..49ac882e 100644 --- a/src/krkn_lib/models/elastic/models.py +++ b/src/krkn_lib/models/elastic/models.py @@ -1,15 +1,16 @@ +import datetime + from elasticsearch_dsl import ( - Keyword, - Text, Date, Document, Float, - Long, - Nested, InnerDoc, Integer, + Keyword, + Long, + Nested, + Text, ) -import datetime from krkn_lib.models.telemetry import ChaosRunTelemetry @@ -195,4 +196,3 @@ def __init__( self.cloud_type = chaos_run_telemetry.cloud_type self.cluster_version = chaos_run_telemetry.cluster_version self.run_uuid = chaos_run_telemetry.run_uuid - diff --git a/src/krkn_lib/models/telemetry/models.py b/src/krkn_lib/models/telemetry/models.py index d124312e..105d41ef 100644 --- a/src/krkn_lib/models/telemetry/models.py +++ b/src/krkn_lib/models/telemetry/models.py @@ -1,9 +1,12 @@ from __future__ import annotations + import base64 import json -import yaml from dataclasses import dataclass from datetime import datetime, timezone + +import yaml + from krkn_lib.models.k8s import PodsStatus relevant_event_reasons: frozenset[str] = frozenset( diff --git a/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py b/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py index c5fab51e..1b25b5a7 100644 --- a/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py +++ b/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py @@ -4,6 +4,7 @@ import os import threading from queue import Queue + from krkn_lib.models.telemetry import ChaosRunTelemetry from krkn_lib.ocp import KrknOpenshift from krkn_lib.telemetry.k8s import KrknTelemetryKubernetes diff --git a/src/krkn_lib/tests/base_test.py b/src/krkn_lib/tests/base_test.py index 7b739a00..e3e8ea99 100644 --- a/src/krkn_lib/tests/base_test.py +++ b/src/krkn_lib/tests/base_test.py @@ -50,7 +50,7 @@ def setUpClass(cls): cls.lib_telemetry_ocp = KrknTelemetryOpenshift( SafeLogger(), cls.lib_ocp ) - host = cls.lib_k8s.api_client.configuration.host + host = cls.lib_k8s.get_host() logging.disable(logging.CRITICAL) # PROFILER # """init each test""" @@ -103,6 +103,7 @@ def deploy_namespace(self, name: str, labels: List[Dict[str, str]]): template = self.template_to_namespace(name, labels) self.apply_template(template) + def deploy_fedtools( self, namespace: str = "default", @@ -266,7 +267,12 @@ def apply_template(self, template: str): with tempfile.NamedTemporaryFile(mode="w") as file: file.write(template) file.flush() - self.lib_k8s.apply_yaml(file.name, "") + retries = 3 + while retries > 0: + template_applied = self.lib_k8s.apply_yaml(file.name, namespace="") + if template_applied is not None: + return + retries -= 1 def get_random_string(self, length: int) -> str: letters = string.ascii_lowercase diff --git a/src/krkn_lib/tests/test_krkn_elastic.py b/src/krkn_lib/tests/test_krkn_elastic.py index d9dd93c9..ca76e3ba 100644 --- a/src/krkn_lib/tests/test_krkn_elastic.py +++ b/src/krkn_lib/tests/test_krkn_elastic.py @@ -1,13 +1,9 @@ import datetime import time - import uuid from krkn_lib.elastic.krkn_elastic import KrknElastic -from krkn_lib.models.elastic.models import ( - ElasticAlert, - ElasticMetric, -) +from krkn_lib.models.elastic.models import ElasticAlert, ElasticMetric from krkn_lib.models.telemetry import ChaosRunTelemetry from krkn_lib.tests import BaseTest from krkn_lib.utils import SafeLogger diff --git a/src/krkn_lib/tests/test_krkn_kubernetes.py b/src/krkn_lib/tests/test_krkn_kubernetes.py index 4a151dae..e9df475c 100644 --- a/src/krkn_lib/tests/test_krkn_kubernetes.py +++ b/src/krkn_lib/tests/test_krkn_kubernetes.py @@ -21,14 +21,18 @@ class KrknKubernetesTests(BaseTest): def test_exec_command(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-ec-" + self.get_random_string(10) alpine_name = "alpine-" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fedtools(namespace=namespace) count = 0 - MAX_RETRIES = 5 + MAX_RETRIES = 20 while not self.lib_k8s.is_pod_running("fedtools", namespace): if count > MAX_RETRIES: + print( + "fedtools pod info " + + str(self.lib_k8s.get_pod_info("fedtools", namespace)) + ) self.assertFalse(True, "container failed to become ready") count += 1 time.sleep(3) @@ -69,11 +73,13 @@ def test_exec_command(self): try: self.lib_k8s.exec_cmd_in_pod(["ls", "-al"], alpine_name, namespace) + self.lib_k8s.delete_namespace(namespace) except Exception: + self.lib_k8s.delete_namespace(namespace) self.fail() def test_pod_shell(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-ps-" + self.get_random_string(10) alpine_name = "alpine-" + self.get_random_string(10) self.deploy_namespace(namespace, []) @@ -104,13 +110,14 @@ def test_pod_shell(self): continue shell = self.lib_k8s.get_pod_shell("fedtools", namespace) self.assertEqual(shell, "bash") + self.lib_k8s.delete_namespace(namespace) - def test_exec_command_on_node(self): + def test_command_on_node(self): try: response = self.lib_k8s.exec_command_on_node( "kind-control-plane", ["timedatectl", "status"], - f"test-pod-{time.time()}", + f"test-pod-{self.get_random_string(6)}", ) self.assertTrue( "NTP service: active" or "Network time on: yes" in response @@ -200,7 +207,7 @@ def test_get_namespace_status(self): self.lib_k8s.get_namespace_status("not-exists") def test_delete_namespace(self): - name = "test-ns-" + self.get_random_string(10) + name = "test-d-ns-" + self.get_random_string(6) self.deploy_namespace(name, [{"name": "name", "label": name}]) result = self.lib_k8s.get_namespace_status(name) self.assertTrue(result == "Active") @@ -276,7 +283,7 @@ def test_list_killable_nodes(self): self.delete_fake_kraken() def test_list_pods(self): - namespace = "test-" + self.get_random_string(10) + namespace = "test-lp" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fake_kraken(namespace=namespace) pods = self.lib_k8s.list_pods(namespace=namespace) @@ -286,7 +293,7 @@ def test_list_pods(self): self.delete_fake_kraken(namespace=namespace) def test_get_all_pods(self): - namespace = "test-" + self.get_random_string(10) + namespace = "test-ap" + self.get_random_string(10) random_label = self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fake_kraken(random_label=random_label, namespace=namespace) @@ -302,32 +309,36 @@ def test_get_all_pods(self): self.assertTrue(len(results) == 1) self.assertEqual(results[0][0], "kraken-deployment") self.assertEqual(results[0][1], namespace) - self.lib_k8s.delete_namespace(namespace) + self.delete_fake_kraken(namespace=namespace) + self.lib_k8s.delete_namespace(namespace) def test_delete_pod(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-dp-" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fedtools(namespace=namespace) self.wait_pod("fedtools", namespace=namespace) self.lib_k8s.delete_pod("fedtools", namespace=namespace) with self.assertRaises(ApiException): self.lib_k8s.read_pod("fedtools", namespace=namespace) + self.lib_k8s.delete_namespace(namespace) def test_create_pod(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-cp-" + self.get_random_string(10) self.deploy_namespace(namespace, []) template_str = self.template_to_pod("fedtools", namespace=namespace) body = yaml.safe_load(template_str) self.lib_k8s.create_pod(body, namespace) try: self.wait_pod("fedtools", namespace=namespace) + self.lib_k8s.delete_namespace(namespace) except Exception: logging.error("failed to create pod") self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_read_pod(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-rp" + self.get_random_string(10) name = "test-name-" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fedtools(namespace=namespace, name=name) @@ -342,9 +353,10 @@ def test_read_pod(self): ) ) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_get_pod_log(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-pl-" + self.get_random_string(10) name = "test-name-" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fedtools(namespace=namespace, name=name) @@ -358,9 +370,10 @@ def test_get_pod_log(self): "failed to get logs due to an exception: %s" % str(e) ) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_get_containers_in_pod(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-cip-" + self.get_random_string(10) name = "test-name-" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_fedtools(namespace=namespace, name=name) @@ -376,9 +389,10 @@ def test_get_containers_in_pod(self): ) ) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_net_policy(self): - namespace = "test-" + self.get_random_string(10) + namespace = "test-np" + self.get_random_string(10) name = "test" self.deploy_namespace(namespace, []) self.create_networkpolicy(name, namespace) @@ -390,7 +404,7 @@ def test_net_policy(self): self.lib_k8s.delete_namespace(namespace) def test_delete_deployment(self): - namespace = "test-" + self.get_random_string(10) + namespace = "test-dd" + self.get_random_string(10) name = "test" self.deploy_namespace(namespace, []) self.deploy_deployment(name, namespace) @@ -402,7 +416,7 @@ def test_delete_deployment(self): self.lib_k8s.delete_namespace(namespace) def test_delete_statefulsets(self): - namespace = "test-" + self.get_random_string(10) + namespace = "test-ss" + self.get_random_string(10) name = "test" self.deploy_namespace(namespace, []) self.deploy_statefulset(name, namespace) @@ -475,6 +489,7 @@ def test_delete_job(self): "job deleted after %d seconds" % (counter * sleep) ) break + self.lib_k8s.delete_namespace(namespace) def test_create_job(self): namespace = "test-ns-" + self.get_random_string(10) @@ -492,9 +507,10 @@ def test_create_job(self): ) ) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_get_job_status(self): - namespace = "test-ns-" + self.get_random_string(10) + namespace = "test-js-" + self.get_random_string(10) name = "test-name-" + self.get_random_string(10) self.deploy_namespace(namespace, []) self.deploy_job(name, namespace) @@ -516,6 +532,7 @@ def test_get_job_status(self): except ApiException: continue self.assertTrue(status.metadata.name == name) + self.lib_k8s.delete_namespace(namespace) def test_monitor_nodes(self): try: @@ -550,6 +567,8 @@ def test_monitor_namespace(self): self.assertTrue(len(status[1]) == 1) self.assertTrue(status[1][0] == "kraken-deployment") self.delete_fake_kraken(namespace=bad_namespace) + self.lib_k8s.delete_namespace(good_namespace) + self.lib_k8s.delete_namespace(bad_namespace) def test_monitor_component(self): good_namespace = "test-ns-" + self.get_random_string(10) @@ -577,6 +596,8 @@ def test_monitor_component(self): self.assertTrue(len(status[1]) == 1) self.assertTrue(status[1][0] == "kraken-deployment") self.delete_fake_kraken(namespace=bad_namespace) + self.lib_k8s.delete_namespace(good_namespace) + self.lib_k8s.delete_namespace(bad_namespace) def test_apply_yaml(self): try: @@ -610,6 +631,7 @@ def test_get_pod_info(self): except Exception as e: logging.error("test raised exception {0}".format(str(e))) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_check_if_namespace_exists(self): try: @@ -624,6 +646,7 @@ def test_check_if_namespace_exists(self): except Exception as e: logging.error("test raised exception {0}".format(str(e))) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_check_if_pod_exists(self): try: @@ -641,6 +664,7 @@ def test_check_if_pod_exists(self): except Exception as e: logging.error("test raised exception {0}".format(str(e))) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_check_if_pvc_exists(self): try: @@ -664,6 +688,7 @@ def test_check_if_pvc_exists(self): except Exception as e: logging.error("test raised exception {0}".format(str(e))) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_get_pvc_info(self): try: @@ -688,6 +713,7 @@ def test_get_pvc_info(self): except Exception as e: logging.error("test raised exception {0}".format(str(e))) self.assertTrue(False) + self.lib_k8s.delete_namespace(namespace) def test_find_kraken_node(self): namespace = "test-ns-" + self.get_random_string(10) @@ -700,6 +726,7 @@ def test_find_kraken_node(self): result = self.lib_k8s.find_kraken_node() self.assertEqual(nodes[random_node_index], result) self.delete_fake_kraken(namespace) + self.lib_k8s.delete_namespace(namespace) def test_get_node_resource_version(self): try: @@ -819,7 +846,7 @@ def test_exists_path_in_pod(self): self.deploy_namespace(namespace, []) self.deploy_fedtools(namespace=namespace) count = 0 - MAX_RETRIES = 5 + MAX_RETRIES = 10 while not self.lib_k8s.is_pod_running("fedtools", namespace): if count > MAX_RETRIES: self.assertFalse(True, "container failed to become ready") @@ -838,6 +865,7 @@ def test_exists_path_in_pod(self): "fedtools", "fedtools", namespace, "/does_not_exist" ) ) + self.lib_k8s.delete_namespace(namespace) def test_is_pod_running(self): namespace = "test-" + self.get_random_string(10) @@ -853,6 +881,7 @@ def test_is_pod_running(self): continue result = self.lib_k8s.is_pod_running("do_not_exist", "do_not_exist") self.assertFalse(result) + self.lib_k8s.delete_namespace(namespace) def test_collect_and_parse_cluster_events(self): namespace_with_evt = "test-" + self.get_random_string(10) @@ -871,6 +900,7 @@ def test_collect_and_parse_cluster_events(self): namespace=namespace_with_evt, ) self.assertGreater(len(events), 0) + self.lib_k8s.delete_namespace(namespace_with_evt) def test_is_kubernetes(self): self.assertTrue(self.lib_k8s.is_kubernetes()) @@ -897,6 +927,7 @@ def test_is_terminating(self): self.assertFalse( self.lib_k8s.is_pod_terminating(not_terminated, namespace) ) + self.lib_k8s.delete_namespace(namespace) def test_monitor_pods_by_label_no_pods_affected(self): # test no pods affected @@ -933,6 +964,7 @@ def test_monitor_pods_by_label_no_pods_affected(self): self.assertIsNone(result.error) self.assertEqual(len(result.recovered), 0) self.assertEqual(len(result.unrecovered), 0) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_name_and_namespace_pattern_different_names_respawn( self, @@ -980,6 +1012,7 @@ def test_pods_by_name_and_namespace_pattern_different_names_respawn( self.assertTrue(result.recovered[0].pod_rescheduling_time > 0) self.assertTrue(result.recovered[0].total_recovery_time >= pod_delay) self.assertEqual(len(result.unrecovered), 0) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_namespace_pattern_and_label_same_name_respawn( self, @@ -1024,6 +1057,7 @@ def test_pods_by_namespace_pattern_and_label_same_name_respawn( self.assertTrue(result.recovered[0].pod_rescheduling_time > 0) self.assertTrue(result.recovered[0].total_recovery_time >= pod_delay) self.assertEqual(len(result.unrecovered), 0) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_label_respawn_timeout(self): # test pod will not recover before the timeout @@ -1062,6 +1096,7 @@ def test_pods_by_label_respawn_timeout(self): self.assertEqual(len(result.recovered), 0) self.background_delete_pod(delayed_respawn, namespace) self.background_delete_pod(delayed_2, namespace) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_label_never_respawn(self): # test pod will never recover @@ -1086,6 +1121,7 @@ def test_pods_by_label_never_respawn(self): result = pods_thread.join() self.assertIsNotNone(result.error) self.background_delete_pod(delayed_2, namespace) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_label_multiple_respawn(self): # test pod will never recover @@ -1132,6 +1168,7 @@ def test_pods_by_label_multiple_respawn(self): self.assertTrue( delayed_respawn_2 in [p.pod_name for p in result.recovered] ) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_label_multiple_respawn_one_too_late(self): # test pod will never recover @@ -1179,6 +1216,7 @@ def test_pods_by_label_multiple_respawn_one_too_late(self): self.assertTrue( delayed_respawn_2 in [p.pod_name for p in result.unrecovered] ) + self.lib_k8s.delete_namespace(namespace) def test_pods_by_label_multiple_respawn_one_fails(self): # test pod will never recover @@ -1216,6 +1254,7 @@ def test_pods_by_label_multiple_respawn_one_fails(self): self.assertIsNotNone(result.error) self.assertEqual(len(result.unrecovered), 0) self.assertEqual(len(result.recovered), 0) + self.lib_k8s.delete_namespace(namespace) def test_replace_service_selector(self): namespace = "test-" + self.get_random_string(10) @@ -1266,6 +1305,7 @@ def test_replace_service_selector(self): self.assertEqual( sanitized_service["spec"]["selector"]["good"], "selector" ) + self.lib_k8s.delete_namespace(namespace) def test_deploy_undeploy_service_hijacking(self): # test deploy @@ -1307,6 +1347,7 @@ def test_deploy_undeploy_service_hijacking(self): self.lib_k8s.cli.read_namespaced_config_map( service_infos.config_map_name, service_infos.namespace ) + self.lib_k8s.delete_namespace(namespace) def test_service_exists(self): namespace = "test-" + self.get_random_string(10) @@ -1317,6 +1358,7 @@ def test_service_exists(self): self.assertFalse( self.lib_k8s.service_exists("doesnotexist", "doesnotexist") ) + self.lib_k8s.delete_namespace(namespace) def test_deploy_syn_flood(self): namespace = "test-" + self.get_random_string(10) @@ -1365,6 +1407,7 @@ def test_deploy_syn_flood(self): places=None, delta=2, ) + self.lib_k8s.delete_namespace(namespace) def test_select_services_by_label(self): namespace = "test-" + self.get_random_string(10) @@ -1383,6 +1426,7 @@ def test_select_services_by_label(self): service = self.lib_k8s.select_service_by_label(namespace, "not=found") self.assertEqual(len(service), 0) + self.lib_k8s.delete_namespace(namespace) def test_list_namespaces_by_regex(self): namespace_1 = ( diff --git a/src/krkn_lib/tests/test_krkn_kubernetes_pods_monitor_pool.py b/src/krkn_lib/tests/test_krkn_kubernetes_pods_monitor_pool.py index f0727f9c..df6bfc43 100644 --- a/src/krkn_lib/tests/test_krkn_kubernetes_pods_monitor_pool.py +++ b/src/krkn_lib/tests/test_krkn_kubernetes_pods_monitor_pool.py @@ -88,6 +88,9 @@ def test_pods_monitor_pool(self): self.assertIsNone(status.error) self.assertEqual(len(status.recovered), 2) self.assertEqual(len(status.unrecovered), 1) + self.lib_k8s.delete_namespace(namespace_1) + self.lib_k8s.delete_namespace(namespace_2) + self.lib_k8s.delete_namespace(namespace_3) def test_cancel(self): namespace_1 = "test-pool-ns-0-" + self.get_random_string(10) @@ -118,3 +121,4 @@ def test_cancel(self): self.background_delete_pod(delayed_2, namespace_1) # give the time to wrap up the threads and return self.assertLess(end_time, 1) + self.lib_k8s.delete_namespace(namespace_1) diff --git a/src/krkn_lib/tests/test_krkn_telemetry_models.py b/src/krkn_lib/tests/test_krkn_telemetry_models.py index 59a981ff..a21b3501 100644 --- a/src/krkn_lib/tests/test_krkn_telemetry_models.py +++ b/src/krkn_lib/tests/test_krkn_telemetry_models.py @@ -3,8 +3,8 @@ from krkn_lib.models.telemetry import ( ChaosRunTelemetry, - ScenarioTelemetry, ClusterEvent, + ScenarioTelemetry, ) diff --git a/src/krkn_lib/tests/test_utils.py b/src/krkn_lib/tests/test_utils.py index 1eee61bc..c5ffc102 100644 --- a/src/krkn_lib/tests/test_utils.py +++ b/src/krkn_lib/tests/test_utils.py @@ -14,10 +14,10 @@ filter_dictionary, filter_log_line, find_executable_in_path, + get_junit_test_case, get_random_string, get_yaml_item_value, is_host_reachable, - get_junit_test_case, ) diff --git a/src/krkn_lib/tests/test_version.py b/src/krkn_lib/tests/test_version.py index 3c8a2fcf..c85ec7cd 100644 --- a/src/krkn_lib/tests/test_version.py +++ b/src/krkn_lib/tests/test_version.py @@ -1,6 +1,5 @@ -from krkn_lib.version import __version__ - from krkn_lib.tests import BaseTest +from krkn_lib.version import __version__ class VersionTest(BaseTest): diff --git a/src/krkn_lib/utils/functions.py b/src/krkn_lib/utils/functions.py index fd5519fc..0d7c015a 100644 --- a/src/krkn_lib/utils/functions.py +++ b/src/krkn_lib/utils/functions.py @@ -3,9 +3,10 @@ import os import random import re +import socket import string import sys -import socket +import xml.etree.cElementTree as ET from queue import Queue from typing import Optional @@ -13,7 +14,6 @@ from base64io import Base64IO from dateutil import parser from dateutil.parser import ParserError -import xml.etree.cElementTree as ET def decode_base64_file(source_filename: str, destination_filename: str): diff --git a/src/testdata/fedtools-deployment.j2 b/src/testdata/fedtools-deployment.j2 index b9869127..79eb89ed 100644 --- a/src/testdata/fedtools-deployment.j2 +++ b/src/testdata/fedtools-deployment.j2 @@ -9,7 +9,7 @@ metadata: {% endif %} spec: containers: - - image: docker.io/fedora/tools + - image: quay.io/krkn-chaos/krkn-lib:fedtools command: - /bin/sh - "-c"