Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unittest for common/ssh_client package #364

Merged
merged 10 commits into from
Aug 6, 2024
13 changes: 8 additions & 5 deletions common/ssh_client/kubernetes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ def __init__(self, context=None, node=None):
def exec_cmd(self, cmd):
exec_command = ['/bin/sh', '-c', cmd]
self.stdio.verbose("KubernetesClient exec_cmd: {0}".format(cmd))
resp = stream(self.client.connect_get_namespaced_pod_exec, self.pod_name, self.namespace, command=exec_command, stderr=True, stdin=False, stdout=True, tty=False, container=self.container_name)
self.stdio.verbose("KubernetesClient exec_cmd.resp: {0}".format(resp))
if "init system (PID 1). Can't operate." in resp:
return "KubernetesClient can't get the resp by {0}".format(cmd)
return resp
try:
resp = stream(self.client.connect_get_namespaced_pod_exec, self.pod_name, self.namespace, command=exec_command, stderr=True, stdin=False, stdout=True, tty=False, container=self.container_name)
self.stdio.verbose("KubernetesClient exec_cmd.resp: {0}".format(resp))
if "init system (PID 1). Can't operate." in resp:
return "KubernetesClient can't get the resp by {0}".format(cmd)
return resp
except Exception as e:
return f"KubernetesClient can't get the resp by {cmd}: {str(e)}"

def download(self, remote_path, local_path):
return self.__download_file_from_pod(self.namespace, self.pod_name, self.container_name, remote_path, local_path)
Expand Down
Empty file added test/__init__.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件删除

Empty file.
464 changes: 464 additions & 0 deletions test/common/ssh_client/test_docker_client.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions test/common/ssh_client/test_kubernetes_cilent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://127.0.0.1:8443
name: dev-cluster
users:
- user:
client-certificate-data: DATA+OMITTED
client-key-data: DATA+OMITTED
name: dev-user
contexts:
- context:
cluster: dev-cluster
user: dev-user
name: dev-context
current-context: dev-context
452 changes: 452 additions & 0 deletions test/common/ssh_client/test_kubernetes_client.py

Large diffs are not rendered by default.

Loading
Loading