def run(self): indev_name = self.get_opt("input_netdev_name") dport = self.get_opt("dport") proto = self.get_opt("proto") ipv6 = self.get_opt("ipv6") self._is_ipv6 = False if ipv6 and bool_it(ipv6): self._is_ipv6 = True params = "" if indev_name: params += " -i %s" % indev_name if proto: params += " -p %s" % proto if dport: params += " --dport %s" % dport ''' Remove all same already existing rules ''' while True: if self._get_pkt_count(indev_name, dport, proto) == None: break self._iptables_exec("-D INPUT%s" % params) self._iptables_exec("-I INPUT%s" % params) self.wait_on_interrupt() count = self._get_pkt_count(indev_name, dport, proto) self._iptables_exec("-D INPUT%s" % params) return self.set_pass(res_data={"pkt_count": count})
def create(self): config = self._dev_config dev_name = config["name"] params = [] slaves = get_slaves(config) if len(slaves) == 1: ul_id = slaves[0] ul_name = self._if_manager.get_mapped_device(ul_id).get_name() params.append(" dev %s" % ul_name) for k in ("ttl", "tos", "key", "ikey", "okey", "local_ip", "remote_ip"): v = get_option(config, k) if v is not None: flag = {"local_ip": "local", "remote_ip": "remote"}.get(k, k) params.append(" %s %s" % (flag, v)) for k in ("seq", "iseq", "oseq", "csum", "icsum", "ocsum"): v = get_option(config, k) if v is not None and bool_it(v): params.append(" " + k) exec_cmd("ip tunnel add name %s mode gre%s" % (dev_name, "".join(params)))
def _prepare_tasks(self): self._tasks = [] for task_data in self._recipe["tasks"]: task = {} task["quit_on_fail"] = False if "quit_on_fail" in task_data: task["quit_on_fail"] = bool_it(task_data["quit_on_fail"]) if "module_dir" in task_data: task["module_dir"] = task_data["module_dir"] if "tools_dir" in task_data: task["tools_dir"] = task_data["tools_dir"] if "python" in task_data: root = Path(None, self._recipe_path).get_root() path = Path(root, task_data["python"]) task["python"] = path if not path.exists(): msg = "Task file '%s' not found." % path raise RecipeError(msg, task_data) self._tasks.append(task) continue task["commands"] = task_data["commands"] task["skeleton"] = [] for cmd_data in task["commands"]: cmd = {"type": cmd_data["type"]} if "host" in cmd_data: cmd["host"] = cmd_data["host"] if cmd["host"] not in self._machines: msg = "Invalid host id '%s'." % cmd["host"] raise RecipeError(msg, cmd_data) if cmd["type"] in ["test", "exec"]: if "bg_id" in cmd_data: cmd["bg_id"] = cmd_data["bg_id"] elif cmd["type"] in ["wait", "intr", "kill"]: cmd["proc_id"] = cmd_data["bg_id"] task["skeleton"].append(cmd) if self._check_task(task): raise RecipeError("Incorrect command sequence.", task_data) self._tasks.append(task)
def run(self): fail_str = self.get_opt("fail") if not fail_str: fail = False else: fail = bool_it(fail_str) res_data = self.get_single_opts() if "fail" in res_data: del(res_data["fail"]) if fail: return self.set_fail(res_data) return self.set_pass(res_data)
def load_presets_from_config(lnst_config): for preset_name in PRESETS: preset = lnst_config.get_option("colours", preset_name) if preset == None: continue fg, bg, bf = preset extended_re = "^extended\([0-9]+\)$" if fg == "default": fg = None elif not re.match(extended_re, fg) and fg not in COLOURS.keys(): raise Exception("Colour '%s' not supported" % fg) if bg == "default": bg = None elif not re.match(extended_re, bg) and bg not in COLOURS.keys(): raise Exception("Colour '%s' not supported" % bg) PRESETS[preset_name] = [fg, bg, bool_it(bf)]
def run(self): logging.info('Started LinkNeg...') iface = self.get_mopt('iface') state = bool_it(self.get_mopt('state')) timeout = self.get_opt('timeout', default=10) ip = IPDB() self.oper_state = ip.interfaces[iface]['operstate'] wd = ip.watchdog(ifname=iface) cuid = ip.register_callback(self._cb) wd.wait(timeout=timeout) ip.unregister_callback(cuid) ip.release() admin_state = 'UP' if state else 'DOWN' oper_state = self.oper_state res_data = {'admin_state': admin_state, 'oper_state': oper_state} if admin_state == oper_state: self.set_pass(res_data) else: self.set_fail(res_data)
mtu = ctl.get_alias("mtu") netperf_duration = int(ctl.get_alias("netperf_duration")) nperf_reserve = int(ctl.get_alias("nperf_reserve")) nperf_confidence = ctl.get_alias("nperf_confidence") nperf_max_runs = int(ctl.get_alias("nperf_max_runs")) nperf_cpupin = ctl.get_alias("nperf_cpupin") nperf_cpu_util = ctl.get_alias("nperf_cpu_util") nperf_mode = ctl.get_alias("nperf_mode") nperf_num_parallel = int(ctl.get_alias("nperf_num_parallel")) nperf_debug = ctl.get_alias("nperf_debug") nperf_max_dev = ctl.get_alias("nperf_max_dev") nperf_msg_size = ctl.get_alias("nperf_msg_size") pr_user_comment = ctl.get_alias("perfrepo_comment") offloads_alias = ctl.get_alias("offloads") nperf_protocols = ctl.get_alias("nperf_protocols") official_result = bool_it(ctl.get_alias("official_result")) adaptive_coalescing_off = bool_it(ctl.get_alias("adaptive_coalescing_off")) sctp_default_msg_size = "16K" if offloads_alias is not None: offloads, offload_settings = parse_offloads(offloads_alias) else: offloads = ["gro", "gso", "tso", "tx"] offload_settings = [ [("gro", "on"), ("gso", "on"), ("tso", "on"), ("tx", "on")], [("gro", "off"), ("gso", "on"), ("tso", "on"), ("tx", "on")], [("gro", "on"), ("gso", "off"), ("tso", "off"), ("tx", "on")], [("gro", "on"), ("gso", "on"), ("tso", "off"), ("tx", "off")]] pr_comment = generate_perfrepo_comment([m1, m2], pr_user_comment)
h2.sync_resources(modules=["IcmpPing", "Custom"]) dpdk_version = h1.run("testpmd -v --help 2>&1").get_result()["res_data"]["stdout"] tmp = re.search(r"^.*RTE Version: '(.*)'$", dpdk_version, flags=re.MULTILINE) if tmp: dpdk_version = tmp.group(1) else: dpdk_version = "unknown" ovs_rpm_version = h2.run("rpm -qf `which ovs-vswitchd` || true").get_result()["res_data"]["stdout"] # ------ # TESTS # ------ official_result = bool_it(ctl.get_alias("official_result")) pr_user_comment = ctl.get_alias("perfrepo_comment") host1_dpdk_cores = ctl.get_alias("host1_dpdk_cores") host2_dpdk_lcores = ctl.get_alias("host2_dpdk_lcores") host2_dpdk_cores = ctl.get_alias("host2_dpdk_cores") guest_testpmd_cores = ctl.get_alias("guest_testpmd_cores") guest_dpdk_cores = ctl.get_alias("guest_dpdk_cores") nr_hugepages = int(ctl.get_alias("nr_hugepages")) guest_nr_hugepages = int(ctl.get_alias("guest_nr_hugepages")) socket_mem = int(ctl.get_alias("socket_mem")) guest_mem_amount = ctl.get_alias("guest_mem_amount") guest_virtname = ctl.get_alias("guest_virtname") guest_hostname = ctl.get_alias("guest_hostname") guest_username = ctl.get_alias("guest_username") guest_password = ctl.get_alias("guest_password") guest_cpus = ctl.get_alias("guest_cpus")
def _should_enable_dbus(self): dbus_disabled = get_option(self._dev_config, "dbus_disabled") if not dbus_disabled or bool_it(dbus_disabled): return True return False
def _prepare_command(self, cmd_data): cmd = {"type": cmd_data["type"]} if "host" in cmd_data: cmd["host"] = cmd_data["host"] if cmd["host"] not in self._machines: msg = "Invalid host id '%s'." % cmd["host"] raise RecipeError(msg, cmd_data) if "netns" in cmd_data: cmd["netns"] = cmd_data["netns"] if "expect" in cmd_data: expect = cmd_data["expect"] if expect not in ["pass", "fail"]: msg = "Illegal expect attribute value." raise RecipeError(msg, cmd_data) cmd["expect"] = expect == "pass" if cmd["type"] == "test": cmd["module"] = cmd_data["module"] cmd_opts = {} if "options" in cmd_data: for opt in cmd_data["options"]: name = opt["name"] val = opt["value"] if name not in cmd_opts: cmd_opts[name] = [] cmd_opts[name].append({"value": val}) cmd["options"] = cmd_opts elif cmd["type"] == "exec": cmd["command"] = cmd_data["command"] if "from" in cmd_data: cmd["from"] = cmd_data["from"] if "save_output" in cmd_data: cmd["save_output"] = cmd_data["save_output"] elif cmd["type"] in ["wait", "intr", "kill"]: # 'proc_id' is used to store bg_id for wait/kill/intr # 'bg_id' is used for test/exec # this is used to distinguish between the two in NetTestSlave code cmd["proc_id"] = cmd_data["bg_id"] elif cmd["type"] == "config": cmd["persistent"] = False if "persistent" in cmd_data: cmd["persistent"] = bool_it(cmd_data["persistent"]) cmd["options"] = [] for opt in cmd_data["options"]: name = opt["name"] value = opt["value"] cmd["options"].append({"name": name, "value": value}) elif cmd["type"] == "ctl_wait": cmd["seconds"] = int(cmd_data["seconds"]) else: msg = "Unknown command type '%s'" % cmd["type"] raise RecipeError(msg, cmd_data) if cmd["type"] in ["test", "exec"]: if "bg_id" in cmd_data: cmd["bg_id"] = cmd_data["bg_id"] if "timeout" in cmd_data: try: cmd["timeout"] = int(cmd_data["timeout"]) except ValueError: msg = "Timeout value must be an integer." raise RecipeError(msg, cmd_data) return cmd
def optionBool(self, option, cfg_path): return bool_it(option)
def _prepare_command(self, cmd_data): cmd = {"type": cmd_data["type"]} if "host" in cmd_data: cmd["host"] = cmd_data["host"] if cmd["host"] not in self._machines: msg = "Invalid host id '%s'." % cmd["host"] raise RecipeError(msg, cmd_data) if "expect" in cmd_data: expect = cmd_data["expect"] if expect not in ["pass", "fail"]: msg = "Illegal expect attribute value." raise RecipeError(msg, cmd_data) cmd["expect"] = expect == "pass" if cmd["type"] == "test": cmd["module"] = cmd_data["module"] cmd_opts = {} if "options" in cmd_data: for opt in cmd_data["options"]: name = opt["name"] val = opt["value"] if name not in cmd_opts: cmd_opts[name] = [] cmd_opts[name].append({"value": val}) cmd["options"] = cmd_opts elif cmd["type"] == "exec": cmd["command"] = cmd_data["command"] if "from" in cmd_data: cmd["from"] = cmd_data["from"] elif cmd["type"] in ["wait", "intr", "kill"]: # XXX The internal name (proc_id) is different, because # bg_id is already used by LNST in a different context cmd["proc_id"] = cmd_data["bg_id"] elif cmd["type"] == "config": cmd["persistent"] = False if "persistent" in cmd_data: cmd["persistent"] = bool_it(cmd_data["persistent"]) cmd["options"] = [] for opt in cmd_data["options"]: name = opt["name"] value = opt["value"] cmd["options"].append({"name": name, "value": value}) elif cmd["type"] == "ctl_wait": cmd["seconds"] = int(cmd_data["seconds"]) else: msg = "Unknown command type '%s'" % cmd["type"] raise RecipeError(msg, cmd_data) if cmd["type"] in ["test", "exec"]: if "bg_id" in cmd_data: cmd["bg_id"] = cmd_data["bg_id"] if "timeout" in cmd_data: try: cmd["timeout"] = int(cmd_data["timeout"]) except ValueError: msg = "Timeout value must be an integer." raise RecipeError(msg, cmd_data) return cmd
ipv = ctl.get_alias("ipv") netperf_duration = int(ctl.get_alias("netperf_duration")) nperf_reserve = int(ctl.get_alias("nperf_reserve")) nperf_confidence = ctl.get_alias("nperf_confidence") nperf_max_runs = int(ctl.get_alias("nperf_max_runs")) netdev_cpupin = ctl.get_alias("netdev_cpupin") nperf_cpu_util = ctl.get_alias("nperf_cpu_util") nperf_mode = ctl.get_alias("nperf_mode") nperf_num_parallel = int(ctl.get_alias("nperf_num_parallel")) nperf_debug = ctl.get_alias("nperf_debug") nperf_max_dev = ctl.get_alias("nperf_max_dev") nperf_msg_size = ctl.get_alias("nperf_msg_size") pr_user_comment = ctl.get_alias("perfrepo_comment") offloads_alias = ctl.get_alias("offloads") nperf_protocols = ctl.get_alias("nperf_protocols") official_result = bool_it(ctl.get_alias("official_result")) sctp_default_msg_size = "16K" if offloads_alias is not None: offloads, offload_settings = parse_offloads(offloads_alias) else: offloads = ["gro", "gso", "tso", "rx", "tx"] offload_settings = [[("gro", "on"), ("gso", "on"), ("tso", "on"), ("tx", "on"), ("rx", "on")], [("gro", "off"), ("gso", "on"), ("tso", "on"), ("tx", "on"), ("rx", "on")], [("gro", "on"), ("gso", "off"), ("tso", "off"), ("tx", "on"), ("rx", "on")], [("gro", "on"), ("gso", "on"), ("tso", "off"), ("tx", "off"), ("rx", "on")],
mtu = ctl.get_alias("mtu") netperf_duration = int(ctl.get_alias("netperf_duration")) nperf_reserve = int(ctl.get_alias("nperf_reserve")) nperf_confidence = ctl.get_alias("nperf_confidence") nperf_max_runs = int(ctl.get_alias("nperf_max_runs")) nperf_cpupin = ctl.get_alias("nperf_cpupin") nperf_cpu_util = ctl.get_alias("nperf_cpu_util") nperf_mode = ctl.get_alias("nperf_mode") nperf_num_parallel = int(ctl.get_alias("nperf_num_parallel")) nperf_debug = ctl.get_alias("nperf_debug") nperf_max_dev = ctl.get_alias("nperf_max_dev") nperf_msg_size = ctl.get_alias("nperf_msg_size") pr_user_comment = ctl.get_alias("perfrepo_comment") offloads_alias = ctl.get_alias("offloads") nperf_protocols = ctl.get_alias("nperf_protocols") official_result = bool_it(ctl.get_alias("official_result")) adaptive_coalescing_off = bool_it(ctl.get_alias("adaptive_coalescing_off")) sctp_default_msg_size = "16K" if offloads_alias is not None: offloads, offload_settings = parse_offloads(offloads_alias) else: offloads = ["gro", "gso", "tso", "tx"] offload_settings = [[("gro", "on"), ("gso", "on"), ("tso", "on"), ("tx", "on")], [("gro", "off"), ("gso", "on"), ("tso", "on"), ("tx", "on")], [("gro", "on"), ("gso", "off"), ("tso", "off"), ("tx", "on")], [("gro", "on"), ("gso", "on"), ("tso", "off"),
def __init__(self, ifmanager, *args, **kwargs): super(TeamDevice, self).__init__(ifmanager, args, kwargs) self._config = kwargs.get("config", None) self._dbus = not bool_it(kwargs.get("disable_dbus", False))