Files
test/keywords/k8s/patch/kubectl_apply_patch_keywords.py
Gabriel Calixto de Paula cce3287018 add k8s_dashboard_access TC part5
finished the necessary setups for the test case regarding the namespace
and some HTTPS certificates

Change-Id: I59c67de09a0799c733196f66b9e8028b9c4a36a4
Signed-off-by: Gabriel Calixto de Paula <gabrielcalixto9@gmail.com>
2025-03-05 15:23:02 -05:00

56 lines
1.8 KiB
Python

from framework.ssh.ssh_connection import SSHConnection
from keywords.base_keyword import BaseKeyword
from keywords.k8s.k8s_command_wrapper import export_k8s_config
class KubectlApplyPatchKeywords(BaseKeyword):
"""
Class for Kubectl Apply Patch keywords
"""
def __init__(self, ssh_connection: SSHConnection):
"""
Constructor
Args:
ssh_connection(SSHConnection):ssh connection object
"""
self.ssh_connection = ssh_connection
def apply_patch_service(self, svc_name: str, namespace: str, args_port: str):
"""
Apply patch
Args:
svc_name(str): patch service name
namespace (str): namespace for patch
args_port(str): port patch arguments.
e.g:'{"spec":{"type":"NodePort","ports":[{"port":443, "nodePort": 30000}]}}''
"""
args = ""
if namespace:
args += f"-n {namespace} "
if args_port:
args += f"-p '{args_port}' "
self.ssh_connection.send(export_k8s_config(f"kubectl patch service {svc_name} {args}"))
self.validate_success_return_code(self.ssh_connection)
def apply_patch_saccount(self, name: str, namespace: str, args_sa: str):
"""
Apply patch
Args:
name(str): patch service name
namespace (str): namespace for patch
args_sa(str): serviceaccount arguments.
e.g: '{"imagePullSecrets":[{"name":"docker-io"}]}'
"""
args = ""
if namespace:
args += f"-n {namespace} "
if args_sa:
args += f"-p {args_sa} "
self.ssh_connection.send(export_k8s_config(f"kubectl patch serviceaccount {name} {args}"))
self.validate_success_return_code(self.ssh_connection)