示例#1
0
def check_exec(host, command, label, namespace):
    # Just in case something is not ready yet, we make sure we can find
    # candidates before trying further
    def _wait_for_pods():
        assert len(kube_utils.get_pods(host, label, namespace)) > 0

    utils.retry(_wait_for_pods,
                times=10,
                wait=3,
                name="wait for pod labeled '{}'".format(label))

    candidates = kube_utils.get_pods(host, label, namespace)

    assert len(candidates) == 1, (
        "Expected only one Pod with label {l}, found {f}").format(
            l=label, f=len(candidates))

    pod = candidates[0]

    with host.sudo():
        host.check_output(
            'kubectl --kubeconfig=/etc/kubernetes/admin.conf '
            'exec --namespace %s %s %s',
            namespace,
            pod['metadata']['name'],
            command,
        )
示例#2
0
def check_pod_state(host, label, state):
    pods = kube_utils.get_pods(
        host, label, namespace="kube-system", status_phase="Running",
    )

    assert len(pods) > 0, "No {} pod with label '{}' found".format(
        state.lower(), label
    )
示例#3
0
    def _check_pods_count():
        pods = kube_utils.get_pods(
            host,
            label,
            namespace="kube-system",
            status_phase="Running",
        )

        assert len(pods) >= min_pods_count
示例#4
0
 def _check_pods_count():
     pods = kube_utils.get_pods(
         k8s_client,
         ssh_config,
         label,
         node,
         namespace=namespace,
         state="Running",
     )
     assert len(pods) == pods_count
示例#5
0
def check_pod_state(request, host, k8s_client, label, state):
    ssh_config = request.config.getoption('--ssh-config')
    pods = kube_utils.get_pods(
        k8s_client, ssh_config, label,
        namespace="kube-system", state="Running",
    )

    assert pods, "No {} pod with label '{}' found".format(
        state.lower(), label
    )
示例#6
0
    def _wait_for_status():
        pods = kube_utils.get_pods(
            k8s_client, ssh_config, label,
            namespace=namespace
        )
        assert pods

        for pod in pods:
            # If really not ready, status may not have been pushed yet.
            if pod.status.conditions is None:
                assert expected_status == 'NotReady'
                continue

            for condition in pod.status.conditions:
                if condition.type == 'Ready':
                    break
            assert kube_utils.MAP_STATUS[condition.status] == expected_status

        return pods
示例#7
0
def check_exec(request, host, k8s_client, command, label, namespace):
    ssh_config = request.config.getoption('--ssh-config')

    # Just in case something is not ready yet, we make sure we can find
    # candidates before trying further
    def _wait_for_pods():
        pods = kube_utils.get_pods(
            k8s_client, ssh_config, label, namespace=namespace
        )
        assert len(pods) > 0

    utils.retry(
        _wait_for_pods,
        times=10,
        wait=3,
        name="wait for pod labeled '{}'".format(label)
    )

    candidates = kube_utils.get_pods(
        k8s_client, ssh_config, label, namespace=namespace
    )

    assert len(candidates) == 1, (
        "Expected only one Pod with label {l}, found {f}"
    ).format(l=label, f=len(candidates))

    pod = candidates[0]

    with host.sudo():
        host.check_output(
            'kubectl --kubeconfig=/etc/kubernetes/admin.conf '
            'exec --namespace %s %s %s',
            namespace,
            pod.metadata.name,
            command,
        )
示例#8
0
 def _wait_for_pods():
     assert len(kube_utils.get_pods(host, label, namespace)) > 0
示例#9
0
 def _wait_for_pods():
     pods = kube_utils.get_pods(
         k8s_client, ssh_config, label, namespace=namespace
     )
     assert len(pods) > 0