def ofctl_arg_supported(cmd, **kwargs): """Verify if ovs-ofctl binary supports cmd with **kwargs. :param cmd: ovs-ofctl command to use for test. :param **kwargs: arguments to test with the command. :returns: a boolean if the supplied arguments are supported. """ br_name = common_utils.get_rand_device_name(prefix='br-test-') with ovs_lib.OVSBridge(br_name) as test_br: full_args = [ "ovs-ofctl", cmd, test_br.br_name, ovs_lib._build_flow_expr_str(kwargs, cmd.split('-')[0], False) ] try: agent_utils.execute(full_args, run_as_root=True) except RuntimeError as e: LOG.debug( "Exception while checking supported feature via " "command %s. Exception: %s", full_args, e) return False except Exception: LOG.exception( "Unexpected exception while checking supported" " feature via command: %s", full_args) return False else: return True
def mod_flow(self, **kwargs): flow_copy = kwargs.copy() flow_copy.pop('actions') flow_str = ovs_lib._build_flow_expr_str(flow_copy, 'del') dump_flows = self.dump_flows_full_match(flow_str) if dump_flows == '': self.do_action_flows('add', [kwargs]) else: self.do_action_flows('mod', [kwargs])
def mod_flow(self, **kwargs): flow_copy = kwargs.copy() flow_copy.pop("actions") flow_str = ovs_lib._build_flow_expr_str(flow_copy, "del") dump_flows = self.dump_flows_full_match(flow_str) if dump_flows == "": self.do_action_flows("add", [kwargs]) else: self.do_action_flows("mod", [kwargs])
def do_action_flows(self, action, kwargs_list): # We force our own run_ofctl to keep OpenFlow version parameter for kw in kwargs_list: kw.setdefault('cookie', self._cookie) if action is 'mod' or action is 'del': kw['cookie'] = ovs_lib.check_cookie_mask(str(kw['cookie'])) flow_strs = [ovs_lib._build_flow_expr_str(kw, action) for kw in kwargs_list] self.run_ofctl('%s-flows' % action, ['-'], '\n'.join(flow_strs))
def do_action_flows(self, action, kwargs_list): # We force our own run_ofctl to keep OpenFlow version parameter for kw in kwargs_list: kw.setdefault('cookie', self._cookie) if action is 'mod' or action is 'del': kw['cookie'] = ovs_lib.check_cookie_mask(str(kw['cookie'])) flow_strs = [ ovs_lib._build_flow_expr_str(kw, action) for kw in kwargs_list ] self.run_ofctl('%s-flows' % action, ['-'], '\n'.join(flow_strs))
def ofctl_arg_supported(cmd, **kwargs): """Verify if ovs-ofctl binary supports cmd with **kwargs. :param cmd: ovs-ofctl command to use for test. :param **kwargs: arguments to test with the command. :returns: a boolean if the supplied arguments are supported. """ br_name = "br-test-%s" % utils.get_random_string(6) with ovs_lib.OVSBridge(br_name) as test_br: full_args = ["ovs-ofctl", cmd, test_br.br_name, ovs_lib._build_flow_expr_str(kwargs, cmd.split("-")[0])] try: agent_utils.execute(full_args, run_as_root=True) except RuntimeError as e: LOG.debug("Exception while checking supported feature via " "command %s. Exception: %s", full_args, e) return False except Exception: LOG.exception(_LE("Unexpected exception while checking supported" " feature via command: %s"), full_args) return False else: return True