def test_launch_pod_via_kubectl(copy_test_apps, delete_test_pod, controller):
    """
    Test custom pod apply and delete
    Args:
        copy_test_apps (str): module fixture
        delete_test_pod: fixture
        controller: test param

    Setups:
        - Copy test files from test server to tis system (module)
        - Delete test pod if already exists on system

    Test Steps:
        - ssh to given controller
        - kubectl apply custom pod yaml and verify custom pod is added to
            both controllers (if applicable)
        - kubectl delete custom pod and verify it is removed from both
            controllers (if applicable)

    """
    host = controller_precheck(controller)

    with host_helper.ssh_to_host(hostname=host) as con_ssh:
        app_path = os.path.join(copy_test_apps, POD_YAML)
        LOG.tc_step('kubectl apply {}, and check {} pod is created and '
                    'running'.format(POD_YAML, POD_NAME))
        kube_helper.apply_pod(file_path=app_path,
                              pod_name=POD_NAME,
                              check_both_controllers=True,
                              con_ssh=con_ssh)

        LOG.tc_step("Delete {} pod and check it's removed from both "
                    "controllers if applicable".format(POD_NAME))
        kube_helper.delete_resources(resource_names=POD_NAME, con_ssh=con_ssh)
 def delete_app():
     LOG.fixture_step("Delete {} pod if exists after test "
                      "run".format(app_name))
     kube_helper.delete_resources(resource_names=app_name,
                                  resource_types=('deployment', 'service'),
                                  namespace='default',
                                  post_check=False)
     kube_helper.wait_for_resources_gone(resource_names=pod_name,
                                         namespace='default')
Esempio n. 3
0
def get_hugepage_pod_file():
    """
    Fixture used to return the hugepage deployment file

        - Get the compute-0 if exist, else standby controller
        - Check 2M hugepages configured, elsif check 1G is configured
            else lock,configure 2G of 1G hugepages and unlock host
        - Call modify_yaml function to modify the yaml
          file with the values
        - Modified file scps to host to deploy hugepages pod
        - Deletes the hugepages pod from the host after the test

    """
    if system_helper.is_aio_duplex():
        hostname = system_helper.get_standby_controller_name()
    else:
        hostname = system_helper.get_hypervisors()[0]
    LOG.fixture_step("Checking hugepage values on {}".format(hostname))
    proc_id = 0
    out = host_helper.get_host_memories(hostname,
                                        ('app_hp_avail_2M', 'app_hp_avail_1G'),
                                        proc_id)
    if out[proc_id][0] > 0:
        hugepage_val = "{}Mi".format(out[proc_id][0])
        hugepage_str = "hugepages-2Mi"
    elif out[proc_id][1] > 0:
        hugepage_val = "{}Gi".format(out[proc_id][1])
        hugepage_str = "hugepages-1Gi"
    else:
        hugepage_val = "{}Gi".format(2)
        cmd = "{} -1G {}".format(proc_id, 2)
        hugepage_str = "hugepages-1Gi"
        HostsToRecover.add(hostname)
        host_helper.lock_host(hostname)
        LOG.fixture_step("Configuring hugepage values {} on {}".format(
            hugepage_val, hostname))
        cli.system('host-memory-modify {} {}'.format(hostname, cmd),
                   ssh_client=None,
                   auth_info=Tenant.get('admin_platform'))
        host_helper.unlock_host(hostname)
    LOG.fixture_step("{} {} pod will be configured on {} proc id {}".format(
        hugepage_str, hugepage_val, hostname, proc_id))
    file_dir, file_name = modify_yaml("utils/test_files/",
                                      "hugepages_pod.yaml", hugepage_str,
                                      hugepage_val)
    source_path = "{}/{}".format(file_dir, file_name)
    home_dir = HostLinuxUser.get_home()
    common.scp_from_localhost_to_active_controller(source_path,
                                                   dest_path=home_dir)
    yield file_name
    LOG.fixture_step("Delete hugepages pod")
    kube_helper.delete_resources(resource_names="hugepages-pod")
Esempio n. 4
0
 def teardown():
     LOG.fixture_step("Delete the service {}".format(service_name))
     kube_helper.exec_kube_cmd(sub_cmd="delete service  ",
                               args=service_name)
     LOG.fixture_step("Delete the deployment {}".format(deployment_name))
     kube_helper.exec_kube_cmd(sub_cmd="delete deployment  ",
                               args=deployment_name)
     LOG.fixture_step("Delete the client pods {} & {}".format(
         client_pod1_name, client_pod2_name))
     kube_helper.delete_resources(labels="client=pod-to-pod")
     if len(computes) > 1:
         LOG.fixture_step("Remove the labels on the nodes if not simplex")
         kube_helper.exec_kube_cmd(sub_cmd="label nodes {}".format(
             computes[0]),
                                   args="test-")
         kube_helper.exec_kube_cmd(sub_cmd="label nodes {}".format(
             computes[1]),
                                   args="test-")
Esempio n. 5
0
def test_create_check_delete_pod():
    """
    Launch a POD via kubectl, wait until it is active, then delete it.
    """
    # Create pod
    test_pod_yaml_path = os.path.join(os.getcwd(),
                                      "testcases/sanity/sanity_platform",
                                      POD_YAML)
    stx_path = STX_HOME + POD_YAML
    current_controller = ControllerClient.get_active_controller()
    if not current_controller.file_exists(test_pod_yaml_path):
        common.scp_from_localhost_to_active_controller(
            source_path=test_pod_yaml_path,
            dest_path=stx_path,
            timeout=60,
            is_dir=False)
    sub_cmd_str = "create -f"
    code, output_create = kube_helper.exec_kube_cmd(sub_cmd=sub_cmd_str,
                                                    args=stx_path,
                                                    con_ssh=current_controller)
    assert code == 0, "Controller kubectl create has exited with an error"
    assert output_create == "pod/testpod created", "Creation of testpod has failed"
    timer = DELAY
    while timer != 0:
        command_check = kube_helper.get_pods(field="STATUS",
                                             all_namespaces=True,
                                             pod_names=POD_NAME)
        if command_check == "Running":
            assert command_check == "Running"
            timer = 0
        else:
            timer -= 5
    # Delete pod
    code, output_delete = kube_helper.delete_resources(
        resource_names=POD_NAME,
        resource_types="pod",
        con_ssh=current_controller,
        check_both_controllers=True)
    assert code == 0, "Controller kubectl delete has exited with an error"
    assert output_delete is None, "Pod was not successfully deleted"
def delete_test_pod():
    LOG.info("Delete {} pod if exists".format(POD_NAME))
    kube_helper.delete_resources(resource_names=POD_NAME, fail_ok=True)