def post_reboot(self, dut, is_upgrade=False): if is_upgrade: basic.ensure_hwsku_config(dut) if st.getenv("SPYTEST_NTP_CONFIG_INIT", "0") != "0": ntp.ensure_ntp_config(dut) if st.getenv("SPYTEST_GENERATE_CERTIFICATE", "0") != "0": basic.ensure_certificate(dut)
def set_port_defaults(self, dut, breakout, speed): rv1, rv2 = True, True if breakout: cli_type = st.getenv("SPYTEST_HOOKS_BREAKOUT_UITYPE", "klish") rv1 = port.breakout(dut, breakout, cli_type=cli_type) if speed: cli_type = st.getenv("SPYTEST_HOOKS_SPEED_UITYPE", "") rv2 = port.set_speed(dut, speed, cli_type=cli_type) return bool(rv1 and rv2)
def db_cli_init(dut): db_map_read(dut) db_cli = st.getenv("SPYTEST_REDIS_DB_CLI_TYPE", "1") if db_cli in ["1", "2"]: db_map_read(dut) if db_cli in ["0", "1", "2"]: return db_cli output = st.show(dut, 'ls /usr/local/bin/sonic-db-cli', skip_tmpl=True) return "0" if re.search(r'No such file or directory', output) else "2"
def tg_links_status(check_type): if st.getenv("SPYTEST_TOPOLOGY_STATUS_FAST", "1") == "1": # avoid checking TGEN status for faster execution if check_type in ["module", "function"]: return dict() try: return tg_links_status_using_native_calls() except Exception: return tg_links_status_using_hltapi()
def apis_instrument(scope, data): if st.getenv("SPYTEST_API_INSTRUMENT_SUPPORT", "0") == "0": return if scope in ["session-init-start", "session-init-end"]: _session_init(scope) elif scope in ["session-clean-start", "session-clean-end"]: pass elif scope in ["init-config-start", "init-config-end"]: _show_runcfg(scope, data) elif scope in ["apply-base-config-dut", "apply-base-config-dut-start", "apply-base-config-dut-end"]: _show_runcfg(scope, data) elif scope in ["module-init-start", "module-init-end"]: pass elif scope in ["module-clean-start", "module-clean-end"]: pass elif scope in ["function-init-start", "function-init-end"]: pass elif scope in ["function-clean-start", "function-clean-end"]: pass elif scope in ["post-module-prolog", "post-class-prolog"]: _show_runcfg(scope, data) else: st.warn("Unknown scope {}".format(scope))
def show_version(self, dut): cli_type = st.getenv("SPYTEST_HOOKS_VERSION_UITYPE", "click") return basic.show_version(dut, cli_type=cli_type)
def get_interface_status(self, dut, port_csv): cli_type = st.getenv("SPYTEST_HOOKS_PORT_STATUS_UITYPE", "click") return port.get_interface_status(dut, port_csv, cli_type=cli_type)
def noshutdown(self, dut, portlist): cli_type = st.getenv("SPYTEST_HOOKS_PORT_ADMIN_STATE_UITYPE", "click") port.noshutdown(dut, portlist, cli_type=cli_type)
def get_physical_ifname_map(self, dut): cli_type = st.getenv("SPYTEST_IFNAME_MAP_UITYPE", "click") return interface.get_physical_ifname_map(dut, cli_type)
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)
def simulate_link_fail(): if st.getenv("SPYTEST_TOPOLOGY_SIMULATE_FAIL", "0") == "0": return False from random import randint return bool(randint(0, 100) > 90)
def links_status(hooks, threads, check_type): header = [ 'DUT', 'DId', 'Local', "LStatus (A/O)", "Partner", 'PDId', "Remote", "RStatus (A/O)" ] funcs = [[tg_links_status, check_type], [duts_links_status, hooks, threads]] show_alias = bool(st.getenv("SPYTEST_TOPOLOGY_SHOW_ALIAS", "0") != "0") if show_alias: header.insert(3, "LAlias") header.insert(8, "RAlias") # st.fail during ctrl+c or prompt not found scenarios, is causing issues. # To avoid that below code block should be in try-except only. try: [[v1, [v2, seen_exp]], [e1, e2]] = putils.exec_all2(threads, "trace", funcs, True) if v1 is None or v2 is None or e1 is not None or e2 is not None or seen_exp: print(v1, v2, e1, e2, seen_exp) return [True, header, [], True, show_alias] except Exception: print("Observed exception during the thread call return handling") return [True, header, [], True, show_alias] v1_default = "?2?" if v1 else "NA" (results, exclude, (dids, palias)) = ([], [], fill_dev_ids()) for dut in st.get_dut_names(): for local, partner, remote in st.get_tg_links(dut, native=use_native): res = [] res.append(dut) res.append(dids.get(dut, "?")) res.append(local) if show_alias: res.append(palias.get(local, local)) res.append(v2.get("{}--{}".format(dut, local), "?1?")) res.append(partner) res.append(dids.get(partner, "?")) res.append(remote) if show_alias: res.append(palias.get(remote, remote)) res.append(v1.get("{}--{}".format(partner, remote), v1_default)) results.append(res) for local, partner, remote in st.get_dut_links(dut, native=use_native): name = "{}--{}".format(dut, local) if name in exclude: continue res = [] res.append(dut) res.append(dids.get(dut, "?")) res.append(local) if show_alias: res.append(palias.get(local, local)) res.append(v2.get("{}--{}".format(dut, local), "?3?")) res.append(partner) res.append(dids.get(partner, "?")) res.append(remote) if show_alias: res.append(palias.get(remote, remote)) res.append(v2.get("{}--{}".format(partner, remote), "?4?")) exclude.append("{}--{}".format(partner, remote)) results.append(res) return [True, header, results, False, show_alias]