test/keywords/k8s/pods/kubectl_delete_pods_keywords.py
croy 82d417b9e6 New StarlingX Automation Framework
Fresh start for the StarlingX automation framework.

Change-Id: Ie265e0791024f45f71faad6315c2b91b022934d1
2024-11-29 16:01:57 -05:00

53 lines
1.4 KiB
Python

from framework.logging.automation_logger import get_logger
from keywords.base_keyword import BaseKeyword
from keywords.k8s.k8s_command_wrapper import export_k8s_config
class KubectlDeletePodsKeywords(BaseKeyword):
"""
Keywords for delete pods
"""
def __init__(self, ssh_connection):
"""
Constructor
Args:
ssh_connection:
"""
self.ssh_connection = ssh_connection
def delete_pod(self, pod_name: str) -> str:
"""
Deletes the pod
Args:
pod_name (): the pod
Returns: the output
"""
output = self.ssh_connection.send(export_k8s_config(f"kubectl delete pod {pod_name}"))
self.validate_success_return_code(self.ssh_connection)
return output
def cleanup_pod(self, pod_name: str, namespace: str = None) -> int:
"""
For use in cleanup as it doesn't automatically fail the test
Deletes the pod
Args:
pod_name (): the pod
namespace (): the namespace
Returns: the output
"""
arg_namespace = ""
if namespace:
arg_namespace = f"-n {namespace}"
self.ssh_connection.send(export_k8s_config(f"kubectl {arg_namespace} delete pod {pod_name}"))
rc = self.ssh_connection.get_return_code()
if rc != 0:
get_logger().log_error(f"Pod {pod_name} failed to delete")
return rc