Files
test/keywords/k8s/pods/kubectl_apply_pods_keywords.py
vshivara 756f667163 Adding the tests for Pod Security Admission.
JIRA: CGTS-74433

Change-Id: I2177683f45e46a9b4da45a7dfb1276a10d99afdd
Signed-off-by: vshivara <vanamala.shivaramakrishna@windriver.com>
2025-03-27 09:31:31 -04:00

50 lines
1.3 KiB
Python

from keywords.base_keyword import BaseKeyword
from keywords.k8s.k8s_command_wrapper import export_k8s_config
from starlingx.framework.ssh.ssh_connection import SSHConnection
class KubectlApplyPodsKeywords(BaseKeyword):
"""
Class for Kubectl apply pod keywords
"""
def __init__(self, ssh_connection: SSHConnection):
"""
Constructor
Args:
ssh_connection (SSHConnection): ssh connection
"""
self.ssh_connection = ssh_connection
def apply_from_yaml(self, yaml_file: str) -> None:
"""
Applies a pod yaml config
Args:
yaml_file (str): the yaml file
Returns: None
"""
self.ssh_connection.send(export_k8s_config(f"kubectl apply -f {yaml_file}"))
self.validate_success_return_code(self.ssh_connection)
def fail_apply_from_yaml(self, yaml_file: str) -> None:
"""
Checks if applying a pod yaml config fails
Args:
yaml_file (str): the yaml file
Returns:
None: This function does not return a value.
"""
self.ssh_connection.send(export_k8s_config(f"kubectl apply -f {yaml_file}"))
rc = self.ssh_connection.get_return_code()
if 1 != rc:
raise Exception(f"Expected deployment of {yaml_file} to fail, instead it passed, investigate")