Exemplo n.º 1
0
def reset_module_config():
    basic_obj.delete_directory_contents(vars.D1, config_params.ztp_run_path)
    st.log("Resetting all DHCP services as part of module unconfig...")
    connection_objs = [ssh_conn_obj_oob_v4, ssh_conn_obj_inb_v4]
    for connection_obj in connection_objs:
        if connection_obj:
            basic_obj.service_operations(connection_obj,
                                         config_params.dhcp_service_name,
                                         "start", "server")
            con_obj.ssh_disconnect(connection_obj)
    if network_flag == "inband":
        if ssh_conn_obj_inb_v6:
            basic_obj.service_operations(ssh_conn_obj_inb_v6,
                                         config_params.dhcp6_service_name,
                                         "start", "server")
            con_obj.ssh_disconnect(ssh_conn_obj_inb_v6)
        if ssh_conn_obj_oob_v6:
            con_obj.ssh_disconnect(ssh_conn_obj_oob_v6)
    else:
        if ssh_conn_obj_oob_v6:
            basic_obj.service_operations(ssh_conn_obj_oob_v6,
                                         config_params.dhcp6_service_name,
                                         "start", "server")
            con_obj.ssh_disconnect(ssh_conn_obj_oob_v6)
        if ssh_conn_obj_inb_v6:
            con_obj.ssh_disconnect(ssh_conn_obj_inb_v6)
    basic_obj.ifconfig_operation(vars.D1, ztp_params.dhcp6.oob_port, "up")
Exemplo n.º 2
0
def sync_with_server_time(dut_list, ip, username, password):
    """
    To Sync DUT with the CHEF server time.
    Author : Prudvi Mangadu ([email protected])
    :param dut:
    :param ip:
    :param username:
    :param password:
    :return:
    """
    ssh_obj = con_obj.connect_to_device(ip, username, password, 'ssh')
    if ssh_obj:
        prompt = ssh_obj.find_prompt()
        command = "date"
        output = ssh_obj.send_command(command,
                                      expect_string="{}|#|$".format(prompt))
        if not output:
            return False
        st.log(output)
        date = utils_obj.remove_last_line_from_string(output)
        con_obj.ssh_disconnect(ssh_obj)
        st.log("Server Time : {}".format(date))
        for dut in dut_list:
            ntp_obj.config_date(dut, date)
        return True
    else:
        con_obj.ssh_disconnect(ssh_obj)
        st.log(
            "SSH to Server is failed - failed to sync time between DUT and CHEF Server"
        )
        return False
Exemplo n.º 3
0
def chef_module_hooks(request):
    global vars
    vars = st.ensure_min_topology("D1")
    if st.get_ui_type() in ['klish']:
        st.report_unsupported(
            'test_execution_skipped',
            'Skipping Chef test case for ui_type={}'.format(st.get_ui_type()))
    global free_ports
    global node_name
    global exclude_list
    global free_ports_samespeed
    free_ports = st.get_free_ports(vars.D1)
    if not free_ports:
        st.log("No free ports available")
        st.report_env_fail("test_case_not_executeds")
    vlan_members = [free_ports[0], free_ports[1], free_ports[2]]
    st.log("VLAN Members: {}".format(",".join(vlan_members)))
    free_ports_samespeed = get_free_ports_speed_list(vars.D1, vlan_members)
    st.log("Free ports same speed: {}".format(",".join(free_ports_samespeed)))
    exclude_list = vlan_members + [
        free_ports_samespeed[0], free_ports_samespeed[1],
        free_ports_samespeed[2]
    ]
    node_name = 'testsonic{}'.format(random.randrange(1, 5000))
    chef_params.client_path = util_obj.ensure_service_params(
        vars.D1, "chef", "client_path")
    chef_obj.delete_client_pem_files(
        vars.D1, "{}/{}".format(chef_params.client_path, "client.pem"))
    chef_obj.delete_client_pem_files(
        vars.D1, "{}/{}".format(chef_params.client_path, "validation.pem"))
    chef_pre_config_in_parallel()
    yield
    vlan_obj.clear_vlan_configuration(vars.D1)
    portchannel_obj.clear_portchannel_configuration(vars.D1)
    mac_obj.clear_mac(vars.D1)
    basic_obj.service_operations(vars.D1, "chef-client", "stop")
    chef_obj.delete_client_pem_files(
        vars.D1, "{}/{}".format(chef_params.client_path, "client.pem"))
    chef_obj.delete_chef_node(ssh_conn_obj, node_name)
    if ssh_conn_obj:
        con_obj.ssh_disconnect(ssh_conn_obj)
Exemplo n.º 4
0
def chef_package_install(dut,
                         url,
                         ip,
                         username='******',
                         password='******',
                         altpassword='******'):
    """
    Install CHEF package to the DUT with CHEF server url.
    Author : Prudvi Mangadu ([email protected])
    :param dut:
    :param url:
    :param ip:
    :param username:
    :param password:
    :return:
    """
    if basic_obj.verify_package(dut, 'chef'):
        return True
    ssh_obj = con_obj.connect_to_device(ip, username, password, 'ssh')
    if not ssh_obj:
        ssh_obj = con_obj.connect_to_device(ip, username, altpassword, 'ssh')
    if ssh_obj:
        prompt = ssh_obj.find_prompt()
        command = "apt-get install chef -y"
        st.log(
            ssh_obj.send_command(command,
                                 expect_string=r"URL of Chef server:\s*"))
        command = "{}".format(url)
        st.log(
            ssh_obj.send_command(command,
                                 expect_string="{}|#|$".format(prompt)))
        con_obj.ssh_disconnect(ssh_obj)
        return True
    else:
        con_obj.ssh_disconnect(ssh_obj)
        st.log("SSH to DUT is failed - Failed to install the chef package ")
        return False
Exemplo n.º 5
0
def test_ft_ssh_config_reload_docker():
    """
    Author : Prudvi Mangadu ([email protected])
    """
    result = True
    get_docker_ps(vars.D1)
    count = get_and_match_docker_count(vars.D1)
    ssh_d1 = connect_to_device(st.get_mgmt_ip(vars.D1), ssh_data.usr_default,
                               ssh_data.pwd_final)
    if ssh_d1:
        st.log(
            "Executing command - 'sudo config reload -y &' in to the SSH session."
        )
        st.log(execute_command(ssh_d1, 'sudo config reload -y &'))
        st.wait(5, 'After executing "config reload" cmd on SSH session.')
        st.log("Forcefully disconnecting the SSH session..")
        ssh_disconnect(ssh_d1)
    else:
        st.error('Cannot SSH into Device with default credentials')
        st.report_fail("ssh_failed")

    if not poll_wait(verify_docker_status, 180, vars.D1, 'Exited'):
        st.error(
            "Post 'config reload' from SSH, dockers are not auto recovered.")
        result = False

    if result:
        if not poll_wait(get_and_match_docker_count, 180, vars.D1, count):
            st.error("Post 'config reload' from SSH, ALL dockers are not UP.")
            result = False

    if not result:
        st.log("Test Failed: So recovering the device by reboot.")
        st.reboot(vars.D1)
        st.report_fail("test_case_failed")
    st.report_pass("test_case_passed")
Exemplo n.º 6
0
def reset_module_config():
    basic_obj.delete_directory_contents(vars.D1, config_params.ztp_run_path)
    st.log("Resetting all DHCP services as part of module unconfig...")
    if ssh_conn_obj:
        con_obj.ssh_disconnect(ssh_conn_obj)
    connection_objs = [ssh_conn_obj_inb_v6, ssh_conn_obj_oob_v6]
    for connection_obj in connection_objs:
        if connection_obj:
            basic_obj.service_operations(connection_obj, config_params.dhcp6_service_name, "start", "server")
            con_obj.ssh_disconnect(connection_obj)
    if outofband_conn_obj:
        basic_obj.service_operations(outofband_conn_obj, config_params.dhcp_service_name, "start", "server")
        con_obj.ssh_disconnect(outofband_conn_obj)