def run_kubectl_command(request, kubeconfig, kubectl_args): env_vars = os.environ.copy() env_vars.update({'KUBECONFIG': kubeconfig}) kubectl_command = "kubectl {}".format(kubectl_args) kubectl_run = run_make_shell(kubectl_command, env=env_vars, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if kubectl_run.returncode != 0: logging.error("kubectl stdout: {}\n stderr: {}".format( kubectl_run.stdout.read(), kubectl_run.stderr.read())) request.kubectl_result = kubectl_run return kubectl_run
def get_kubernetes_pv(kubeconfig): pv_list_process = run_make_shell( 'kubectl get pv --export -o yaml', env={'KUBECONFIG': kubeconfig}, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) kubectl_output = pv_list_process.stdout.read() if pv_list_process.returncode == 0: pv_list = yaml.load(kubectl_output) return pv_list['items'] else: logging.error("kubectl stdout: {}\n stderr: {}".format( kubectl_output, pv_list_process.stderr.read()))
def storage_pod_test_result(kubeconfig): count = 5 while count: test_pv_process = run_make_shell( 'kubectl get pods test-pv -o yaml', env={'KUBECONFIG': kubeconfig}, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) kubectl_output = test_pv_process.stdout.read() test_pv_info = yaml.load(kubectl_output) if test_pv_info is None: logging.error("kubectl stdout: {}\n stderr: {}".format( kubectl_output, test_pv_process.stderr.read())) if test_pv_info['status']['phase'] in ['Succeeded', 'Failed']: break count -= 1 time.sleep(1) assert test_pv_info['status']['phase'] == 'Succeeded'
def lauch_test_storage_pod(kubeconfig): pod_yaml_path = os.path.join(os.path.dirname(__file__), 'files/storage_pod_test.yml') run_make_shell('kubectl apply -f {}'.format(pod_yaml_path), env={'KUBECONFIG': kubeconfig})
def clean_pvc(kubeconfig): kube_clean_pv = run_make_shell( 'kubectl delete pod test-pv; kubectl delete pvc testclaim', env={'KUBECONFIG': kubeconfig}) kube_clean_pv.wait() assert kube_clean_pv.returncode == 0
def make_shells_step(): make_process = run_make_shell() assert make_process.returncode == 0
def clean_pvc(kubeconfig): run_make_shell('kubectl delete pod test-pv; kubectl delete pvc testclaim', env={'KUBECONFIG': kubeconfig})