def ztp_func_hooks(request):
    initialize_variables()
    basic_obj.remove_file(vars.D1, config_params.ztp_local_json_path)
    basic_obj.copy_config_db_to_temp(vars.D1, config_params.config_db_path, config_params.config_db_temp)
    basic_obj.change_permissions(vars.D1, config_params.config_db_temp)
    ztp_obj.enable_ztp_if_disabled(vars.D1)
    config_params.func_name = st.get_func_name(request)
    yield
    ztp_obj.ztp_operations(vars.D1, "disable")
    basic_obj.copy_config_db_to_temp(vars.D1, config_params.config_db_temp, config_params.config_db_path)
    config_params.dhcp_config_file = dhcp6_config_file
    config_params.option_type = "option_59"
    ztp_obj.clear_options_from_dhcp_server(ssh_conn_obj, config_params)
Esempio n. 2
0
def ztp_func_hooks(request):
    initialize_config_params()
    initialize_data_variables()
    basic_obj.remove_file(vars.D1, data.ztp_local_json_path)
    basic_obj.copy_config_db_to_temp(vars.D1, data.config_db_path, data.config_db_temp)
    basic_obj.change_permissions(vars.D1, data.config_db_temp)
    ztp_obj.enable_ztp_if_disabled(vars.D1)
    config_params.func_name = st.get_func_name(request)
    yield
    ztp_obj.ztp_operations(vars.D1, "disable")
    basic_obj.copy_config_db_to_temp(vars.D1, data.config_db_temp, data.config_db_path)
    config_params.dhcp_config_file = ztp_params.dhcp.inband_config_file
    if st.get_func_name(request) == "test_ft_ztp_config_section_check_with_option_67_with_inband":
        config_params.option_type = "option_67"
        ztp_obj.clear_options_from_dhcp_server(ssh_conn_obj, config_params)
        config_params.option_type = "option_239"
        ztp_obj.clear_options_from_dhcp_server(ssh_conn_obj, config_params)
Esempio n. 3
0
def test_ft_ztp_validate_cfg_file_with_incorrect_data(ztp_func_hooks):
    vars = st.ensure_min_topology("D1")
    data.ztp_cfg = {
        "admin": True,
        "restart-ztp-interval": 30,
        "reboot-on-success": "abcd"
    }
    ztp_cfg_file = basic_obj.write_to_json_file(data.ztp_cfg)
    st.upload_file_to_dut(vars.D1, ztp_cfg_file, data.dut_ztp_cfg_file)
    ztp_obj.enable_ztp_if_disabled(vars.D1)
    if st.get_ui_type(vars.D1) == "click":
        ztp_obj.ztp_operations(vars.D1, "run")
    else:
        st.reboot(vars.D1, "normal", skip_port_wait=True)
    log_string = "Invalid data type used for reboot-on-success"
    if not basic_obj.poll_for_error_logs(vars.D1, data.ztp_log_path,
                                         log_string):
        st.log("ZTP log {} verification failed for message {}".format(
            data.ztp_log_path, log_string))
        st.report_fail("ztp_log_verification_failed", data.ztp_log_path,
                       log_string)
    st.report_pass("test_case_passed")
Esempio n. 4
0
def ztp_func_hooks(request):
    initialize_config_params()
    initialize_data_variables()
    basic_obj.remove_file(vars.D1, data.ztp_local_json_path)
    if st.get_func_name(
            request) == 'test_ft_ztp_behv_invalid_json_and_config_sections':
        mvrfconfig(vars.D1, cli_type="click")
        reboot_obj.config_save(vars.D1)
    basic_obj.copy_config_db_to_temp(vars.D1, data.config_db_path,
                                     data.config_db_temp)
    basic_obj.change_permissions(vars.D1, data.config_db_temp)
    # st.log("Shutting down the inband interface ...")
    # intf_obj.interface_shutdown(vars.D1, ztp_params.inband_port)
    reboot_obj.config_save(vars.D1)
    ztp_obj.enable_ztp_if_disabled(vars.D1)
    config_params.func_name = st.get_func_name(request)
    yield
    basic_obj.copy_config_db_to_temp(vars.D1, data.config_db_temp,
                                     data.config_db_path)
    ztp_obj.ztp_operations(vars.D1, "disable")
    ztp_cfg = {
        "admin-mode": True,
        "restart-ztp-interval": 30,
        "feat-console-logging": feat_logging_console
    }
    ztp_obj.config_ztp_backdoor_options(vars.D1, ztp_cfg)
    if st.get_func_name(
            request) == 'test_ft_ztp_behv_invalid_json_and_config_sections':
        mvrfconfig(vars.D1, no_form=True, cli_type="click")
    config_params.dhcp_config_file = ztp_params.dhcp.config_file
    config_params.option_type = ""
    if st.get_func_name(request) in functions_67:
        config_params.option_type = "option_67"
    elif st.get_func_name(request) in functions_225:
        config_params.option_type = "option_225"
    elif st.get_func_name(request) in functions_239:
        config_params.option_type = "option_239"
    if config_params.option_type:
        ztp_obj.clear_options_from_dhcp_server(ssh_conn_obj, config_params)
Esempio n. 5
0
 def ztp_disable(self, dut):
     from apis.system.ztp import ztp_operations
     cli_type = st.getenv("SPYTEST_HOOKS_ZTP_UITYPE", "click")
     ztp_operations(dut, "disable", cli_type=cli_type, max_time=1200)
Esempio n. 6
0
def test_ft_ztp_config_section_check_with_option_67(ztp_func_hooks):
    # ################ Author Details ################
    # Name: Chaitanya Vella
    # Email: [email protected]
    # ################################################
    # ############## Test bed details ################
    #  D1 ---- DHCP Server
    #  ft_ztp_config_section_check_with_option_67	: This test function cover over 18 scenarios using option 67
    # #################################################
    vars = st.ensure_min_topology("D1")
    hostname = basic_obj.get_hostname(vars.D1)
    config_params.config_file = "ztp_plugin_conf.json"
    config_params.static_ip = ztp_params.dhcp.static_ip
    config_params.config_path = ztp_params.config_path
    config_params.dhcp_config_file = ztp_params.dhcp.config_file
    config_params.type = "http"
    config_params.dhcp_service_name = data.dhcp_service_name
    config_params.action = 'restart'
    config_params.device = 'server'
    config_params.device_action = "run"
    config_params.reboot_type = "normal"
    config_params.ztp_log_path = data.ztp_log_path
    config_params.file_names = [
        "02-configdb-json", "03-provisioning-script", "04-connectivity-tests",
        "05-test-plugin"
    ]
    config_params.json_content = data.json_content
    config_params.log_msg = "Checking configuration section {} result: SUCCESS"
    config_params.ztp_log_string = "ZTP successfully completed"
    config_params.option_type = "67"
    config_params.result = ""
    config_params.service = "disable"
    config_params.config_db_path = data.config_db_path
    config_params.config_db_temp = data.config_db_temp
    config_params.config_file = "ztp_plugin_conf.json"
    config_params.config_db_file_name = "{}_config_db.json".format(hostname)
    config_params.featureconfig_file_name = "invalid_config.json"
    config_params.json_config_path = "http://{}{}/".format(
        ztp_params.dhcp.static_ip, ztp_params.config_path)
    config_params.provision_script_path = "https://{}{}/{} -k".format(
        ztp_params.dhcp.static_ip, ztp_params.provision_script_path,
        data.option_239_sh_file)
    config_params.ping_script_path = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.provision_script_path,
        data.ping_script_file)
    config_params.config_db_url = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.config_path,
        config_params.config_db_file_name)
    data.feature_config_url = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.config_path,
        config_params.featureconfig_file_name)
    config_params.json_content = {
        "ztp": {
            "02-configdb-json": {
                "dynamic-url": {
                    "source": {
                        "prefix": config_params.json_config_path,
                        "identifier": "hostname",
                        "suffix": "_config_db.json"
                    },
                    "destination": "/etc/sonic/config_db.json"
                }
            },
            "03-provisioning-script": {
                "plugin": {
                    "url": config_params.provision_script_path
                }
            },
            "04-connectivity-tests": {
                "plugin": {
                    "url": config_params.ping_script_path
                }
            },
            "05-test-plugin": {
                "message": "Test-Plugin-Test",
                "message-file": "/home/admin/test-file1",
                "reboot-on-success": True
            },
            "06-snmp": {
                "community-ro": "sonic",
                "snmp-location": "Hyderabad",
                "snmp-syscontact": "admin",
                "ignore-result": "true",
                "restart-agent": True
            },
            "07-configdb-json": {
                "url": {
                    "source": data.feature_config_url,
                    "timeout": 300
                },
                "clear-config": "false",
                "save-config": "true",
                "ignore-result": True
            }
        }
    }
    ztp_obj.config_ztp_backdoor_options(vars.D1,
                                        ztp_cfg={
                                            "admin-mode":
                                            True,
                                            "restart-ztp-interval":
                                            30,
                                            "log-level":
                                            "DEBUG",
                                            "feat-console-logging":
                                            feat_logging_console
                                        })
    source_path = "{}{}".format(data.local_provision_scripts_folder,
                                data.option_239_sh_file)
    destination_path = "{}{}/{}".format(ztp_params.home_path,
                                        ztp_params.provision_script_path,
                                        data.option_239_sh_file)
    basic_obj.copy_file_from_client_to_server(ssh_conn_obj,
                                              src_path=source_path,
                                              dst_path=destination_path,
                                              persist=True)
    options = SpyTestDict()
    options.dhcp_config_file = ztp_params.dhcp.config_file
    options.server_ip = config_params.static_ip
    options.config_path = ztp_params.provision_script_path
    options.provision_script = data.option_239_sh_file
    options.search_pattern = r'\s*option\s+provision-url\s*\S*\s*"\S+";'
    options.option_string = 'option provision-url '
    options.option_url = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.provision_script_path,
        data.option_239_sh_file)
    ztp_obj.write_option_to_dhcp_server(ssh_conn_obj, options)
    shell_scripts = [data.ping_script_file, data.option_239_sh_file]
    for shell_script in shell_scripts:
        source_path = "{}{}".format(data.local_provision_scripts_folder,
                                    shell_script)
        destination_path = "{}{}/{}".format(ztp_params.home_path,
                                            ztp_params.provision_script_path,
                                            shell_script)
        basic_obj.copy_file_from_client_to_server(ssh_conn_obj,
                                                  src_path=source_path,
                                                  dst_path=destination_path,
                                                  persist=True)
    st.log(
        "Preparing invalid config JSON to check the gracefull handling of ZTP ..."
    )
    interface_name = random.choice(st.get_free_ports(vars.D1))
    vlan_list = vlan_obj.get_non_existing_vlan(vars.D1, 1)
    data.config_db_content = {
        "VLAN": {
            "Vlan{}".format(vlan_list[0]): {
                "members": [interface_name],
                "vlanid": vlan_list[0]
            }
        },
        "VLAN_MEMBER": {
            "Vlan{}|{}".format(vlan_list[0], interface_name): {
                "tagging_mode": "tagged"
            }
        }
    }
    file_path = basic_obj.write_to_json_file(data.config_db_content)
    destination_path = "{}{}/{}".format(ztp_params.home_path,
                                        ztp_params.config_path,
                                        config_params.featureconfig_file_name)
    basic_obj.copy_file_from_client_to_server(ssh_conn_obj,
                                              src_path=file_path,
                                              dst_path=destination_path)
    ztp_obj.config_and_verify_dhcp_option(ssh_conn_obj,
                                          vars.D1,
                                          ztp_params,
                                          config_params,
                                          expect_reboot=True,
                                          reboot_on_success=["05-test-plugin"])
    # if ztp_params.cli_type == "click":
    #     st.log("Verifying the ZTP DEBUG logs ..")
    #     ztp_log_string = "DEBUG sonic-ztp"
    #     st.log(st.log(ztp_log_string))
    #     if not basic_obj.poll_for_error_logs(vars.D1, data.ztp_log_path, ztp_log_string):
    #         if not basic_obj.poll_for_error_logs(vars.D1, data.syslog_path, ztp_log_string):
    #             st.log("ZTP log {} verification failed for message {}".format(data.ztp_log_path, ztp_log_string))
    #             st.report_fail("ztp_log_verification_failed", data.ztp_log_path, ztp_log_string)
    ztp_status = ztp_obj.show_ztp_status(vars.D1)
    if "dhcp-opt67" not in ztp_status["source"]:
        st.log(
            "ZTP source verification failed with {} against dhcp-opt67".format(
                ztp_status["source"]))
        st.report_fail("ztp_source_verification_failed", "dhcp-opt67",
                       ztp_status["source"])
    st.log("Verifying the ZTP plugin chronological order ..")
    if not ztp_obj.verify_plugin_chronological_order(vars.D1):
        st.report_fail("ztp_chronoloigical_verification_failed")
    st.log("Verifying ZTP admin disable operation ..")
    if not ztp_obj.verify_dhclient_on_interface(vars.D1, "/sbin/dhclient",
                                                ztp_params.oob_port):
        st.report_fail("ztp_dhclient_error")
    ztp_status = ztp_obj.show_ztp_status(vars.D1)
    ztp_obj.ztp_operations(vars.D1, "disable")
    if not ztp_obj.verify_ztp_attributes(vars.D1, "adminmode", "False"):
        st.log("ZTP status verification failed")
        st.report_fail("ztp_status_verification_failed")
    ztp_status_after_disable = ztp_obj.show_ztp_status(vars.D1)
    if ztp_status["status"] != ztp_status_after_disable["status"]:
        st.log("ZTP status verification failed")
        st.report_fail("ztp_status_verification_failed")
    snmp_params = {"rocommunityv6": "sonic", "rocommunity": "sonic"}
    if not verify_snmp_details_using_docker(vars.D1, **snmp_params):
        st.report_fail("snmp_params_verification_failed")
    snmp_params = {"syslocation": "Hyderabad"}
    if not verify_snmp_details_using_docker(vars.D1, **snmp_params):
        st.report_fail("snmp_params_verification_failed")
    snmp_params = {"syscontact": "admin"}
    if not verify_snmp_details_using_docker(vars.D1, **snmp_params):
        st.report_fail("snmp_params_verification_failed")
    st.report_pass("test_case_passed")
Esempio n. 7
0
def test_ft_ztp_restart_no_config(ztp_func_hooks):
    # ################ Author Details ################
    # Name: Chaitanya Vella
    # Email: [email protected]
    # ################################################
    # ############## Test bed details ################
    #  D1 ---- DHCP Server
    #  ft_ztp_restart_no_config	: Verify that SONiC ZTP is successful even though we have not pushed config db json
    #  with and without ""restart-ztp-no-config": false" attribute in ztp.json
    #  YET TO BE DONE #
    # #################################################
    vars = st.ensure_min_topology("D1")
    hostname = basic_obj.get_hostname(vars.D1)
    config_params.config_file = "ztp_restart_no_config.json"
    config_params.static_ip = ztp_params.dhcp.static_ip
    config_params.config_path = ztp_params.config_path
    config_params.dhcp_config_file = ztp_params.dhcp.config_file
    config_params.type = "http"
    config_params.dhcp_service_name = data.dhcp_service_name
    config_params.action = 'restart'
    config_params.device = 'server'
    config_params.device_action = "reboot"
    config_params.reboot_type = "normal"
    config_params.ztp_log_path = data.ztp_log_path
    config_params.file_names = [
        "03-provisioning-script", "04-connectivity-tests"
    ]
    config_params.json_content = data.json_content
    config_params.log_msg = "Checking configuration section {} result: SUCCESS"
    config_params.ztp_log_string = "ZTP successfully completed"
    config_params.option_type = "67"
    config_params.config_db_path = data.config_db_path
    config_params.config_db_temp = data.config_db_temp
    config_params.config_db_file_name = "{}_config_db.json".format(hostname)
    config_params.json_config_path = "http://{}{}/".format(
        ztp_params.dhcp.static_ip, ztp_params.config_path)
    config_params.provision_script_path = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.provision_script_path,
        data.option_239_sh_file)
    config_params.ping_script_path = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.provision_script_path,
        data.ping_script_file)
    config_params.config_db_url = "http://{}{}/{}".format(
        ztp_params.dhcp.static_ip, ztp_params.config_path,
        config_params.config_db_file_name)
    config_params.json_content = {
        "ztp": {
            "03-provisioning-script": {
                "plugin": {
                    "url": config_params.provision_script_path
                }
            },
            "04-connectivity-tests": {
                "plugin": {
                    "url": config_params.ping_script_path
                }
            },
            "restart-ztp-no-config": False
        }
    }
    ztp_obj.ztp_operations(vars.D1, "disable")
    if not ztp_obj.verify_ztp_attributes(vars.D1, "adminmode", "False"):
        st.log("ZTP status verification failed")
        st.report_fail("ztp_status_verification_failed")
    st.reboot(vars.D1)
    if not ztp_obj.verify_ztp_attributes(vars.D1, "adminmode", "False"):
        st.log("ZTP status verification failed")
        st.report_fail("ztp_status_verification_failed")
    ztp_obj.enable_ztp_if_disabled(vars.D1)
    if ztp_obj.verify_ztp_attributes(vars.D1, "adminmode", "False"):
        st.log("ZTP status verification failed")
        st.report_fail("ztp_status_verification_failed")
    shell_scripts = [data.ping_script_file, data.option_239_sh_file]
    for shell_script in shell_scripts:
        source_path = "{}{}".format(data.local_provision_scripts_folder,
                                    shell_script)
        destination_path = "{}{}/{}".format(ztp_params.home_path,
                                            ztp_params.provision_script_path,
                                            shell_script)
        basic_obj.copy_file_from_client_to_server(ssh_conn_obj,
                                                  src_path=source_path,
                                                  dst_path=destination_path,
                                                  persist=True)
    ztp_obj.config_and_verify_dhcp_option(ssh_conn_obj, vars.D1, ztp_params,
                                          config_params)