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
30 changes: 30 additions & 0 deletions .github/workflows/test_ssh_client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test Ssh Client

on:
push:
branches: "dev*"
pull_request:
branches: "dev*"

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for proper version detection

- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements3.txt

- name: Run tests
run: python -m unittest discover -s test/common/ssh_client -p 'test_*.py'
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
Loading
Loading