[PATCH 1/4] lnst-pool-wizard: add _parse_host method
by Jiri Prochazka
this methods parses host in touple hostname,port. Created to avoid
code duplication when support for hostlist in interactive mode
will be released.
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Controller/Wizard.py | 46 ++++++++++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/lnst/Controller/Wizard.py b/lnst/Controller/Wizard.py
index 562efe1..a917949 100644
--- a/lnst/Controller/Wizard.py
+++ b/lnst/Controller/Wizard.py
@@ -96,24 +96,9 @@ class Wizard:
for host in hostlist:
print("Processing host '%s'" % host)
- # Check if port was entered along with hostname
- if host.find(":") != -1:
- hostname = host.split(":")[0]
- if hostname == "":
- msg = "'%s' does not contain valid hostname\n" % host
- sys.stderr.write(msg)
- sys.stderr.write("Skipping host '%s'\n" % host)
- continue
- try:
- port = int(host.split(":")[1])
- except:
- port = DefaultRPCPort
- msg = "Invalid port entered, "\
- "using '%s' instead\n" % port
- sys.stderr.write(msg)
- else:
- hostname = host
- port = DefaultRPCPort
+ hostname, port = self._parse_host(host)
+ if hostname == -1:
+ continue
if not self._check_hostname(hostname):
sys.stderr.write("Hostname '%s' is not translatable into a "
@@ -353,6 +338,31 @@ class Wizard:
if data["type"] == "result":
return data["result"]
+ def _parse_host(self, host):
+ """ Parses hostname:port string
+ @param host String where hostname and optionally port is stored
+ @return touple with string hostname and int port
+ """
+ if host.find(":") != -1:
+ hostname = host.split(":")[0]
+ if hostname == "":
+ msg = "'%s' does not contain valid hostname\n" % host
+ sys.stderr.write(msg)
+ sys.stderr.write("Skipping host '%s'\n" % host)
+ return -1, -1
+ try:
+ port = int(host.split(":")[1])
+ except:
+ port = DefaultRPCPort
+ msg = "Invalid port entered, "\
+ "using '%s' instead\n" % port
+ sys.stderr.write(msg)
+ else:
+ hostname = host
+ port = DefaultRPCPort
+
+ return hostname, port
+
def _query_continuation(self):
""" Queries user for adding next machine
@return True if user wants to add another machine, False otherwise
--
2.4.3
7 years, 8 months
[patch lnst] lnst-slave: allow to configure RPC port in config file
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
Similar to default RPC port on controller side, allow user to configure
RPC port on the slave.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst-slave | 8 ++++----
lnst/Common/Config.py | 5 +++++
lnst/Slave/NetTestSlave.py | 4 +++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/lnst-slave b/lnst-slave
index a91df1b..93856c2 100755
--- a/lnst-slave
+++ b/lnst-slave
@@ -88,10 +88,10 @@ def main():
colours=coloured_output)
logging.info("Started")
- if port:
- nettestslave = NetTestSlave(log_ctl, port=port)
- else:
- nettestslave = NetTestSlave(log_ctl)
+ if port != None:
+ lnst_config.set_option("environment", "rpcport", port)
+
+ nettestslave = NetTestSlave(log_ctl)
if daemon:
daemon = Daemon(pidfile)
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index ddaa508..97a82e4 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -112,6 +112,11 @@ class Config():
"additive" : False,
"action" : self.optionBool,
"name" : "use_nm"}
+ self._options['environment']['rpcport'] = {\
+ "value" : DefaultRPCPort,
+ "additive" : False,
+ "action" : self.optionPort,
+ "name" : "rpcport"}
self._options['cache'] = dict()
self._options['cache']['dir'] = {\
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index dc58e1c..d65db5a 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -849,10 +849,12 @@ class ServerHandler(ConnectionHandler):
self._netns_con_mapping = {}
class NetTestSlave:
- def __init__(self, log_ctl, port = DefaultRPCPort):
+ def __init__(self, log_ctl):
die_when_parent_die()
self._cmd_context = NetTestCommandContext()
+ port = lnst_config.get_option("environment", "rpcport")
+ logging.info("Using RPC port %d." % port)
self._server_handler = ServerHandler(("", port))
self._if_manager = InterfaceManager(self._server_handler)
--
2.4.3
7 years, 8 months
[patch lnst] Machine: fill-up command["netns"] in all cases in set_mtu method
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
Just fill-up command["netns"] even in case it is None. The rest of the
code counts on the key being there.
Fixes: 3ab35292 ("Machine: introduce helper method _rpc_call_x")
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Machine.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 12f8757..7281203 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -654,8 +654,7 @@ class Interface(object):
{"name": "/sys/class/net/%s/mtu" % self._devname,
"value": str(mtu)}
]}
- if self._netns != None:
- command["netns"] = self._netns
+ command["netns"] = self._netns
self._machine.run_command(command)
self._mtu = mtu
--
2.4.3
7 years, 8 months
[patch lnst] lnst-slave: allow to configure RPC port in config file
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
Similar to default RPC port on controller side, allow user to configure
RPC port on the slave.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst-slave | 8 ++++----
lnst/Common/Config.py | 5 +++++
lnst/Slave/NetTestSlave.py | 4 +++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/lnst-slave b/lnst-slave
index a91df1b..93856c2 100755
--- a/lnst-slave
+++ b/lnst-slave
@@ -88,10 +88,10 @@ def main():
colours=coloured_output)
logging.info("Started")
- if port:
- nettestslave = NetTestSlave(log_ctl, port=port)
- else:
- nettestslave = NetTestSlave(log_ctl)
+ if port != None:
+ lnst_config.set_option("environment", "rpcport", port)
+
+ nettestslave = NetTestSlave(log_ctl)
if daemon:
daemon = Daemon(pidfile)
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index ddaa508..97a82e4 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -112,6 +112,11 @@ class Config():
"additive" : False,
"action" : self.optionBool,
"name" : "use_nm"}
+ self._options['environment']['rpcport'] = {\
+ "value" : DefaultRPCPort,
+ "additive" : False,
+ "action" : self.optionPort,
+ "name" : "rpcport"}
self._options['cache'] = dict()
self._options['cache']['dir'] = {\
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index dc58e1c..d65db5a 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -849,10 +849,12 @@ class ServerHandler(ConnectionHandler):
self._netns_con_mapping = {}
class NetTestSlave:
- def __init__(self, log_ctl, port = DefaultRPCPort):
+ def __init__(self, log_ctl):
die_when_parent_die()
self._cmd_context = NetTestCommandContext()
+ port = lnst_config.get_option("environment", "rpcport")
+ logging.info("Using RPC port %d." % port)
self._server_handler = ServerHandler(("", port))
self._if_manager = InterfaceManager(self._server_handler)
--
2.4.3
7 years, 8 months
[patch lnst 1/3] Machine: introduce helper method _rpc_call_x
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
On lot of places, there is if-else construction due to netns and
non-netns rpc call. Wrap this up by _rpc_call_x method and make the code
more simple.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Machine.py | 164 +++++++++++++--------------------------------
1 file changed, 45 insertions(+), 119 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index ce78866..8cfe5bf 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -191,6 +191,11 @@ class Machine(object):
return result
+ def _rpc_call_x(self, netns, method_name, *args):
+ if not netns:
+ return self._rpc_call(method_name, *args)
+ return self._rpc_call_to_netns(netns, method_name, *args)
+
def configure(self, recipe_name):
""" Prepare the machine
@@ -289,16 +294,12 @@ class Machine(object):
if bg_cmd["netns"] != None:
command["netns"] = bg_cmd["netns"]
+ netns = command["netns"]
if command["type"] == "wait":
logging.debug("Get remaining time of bg process with bg_id == %s"
% command["proc_id"])
- if command["netns"] != None:
- remaining_time = self._rpc_call_to_netns(command["netns"],
- "get_remaining_time",
- command["proc_id"])
- else:
- remaining_time = self._rpc_call("get_remaining_time",
- command["proc_id"])
+ remaining_time = self._rpc_call_x(netns, "get_remaining_time",
+ command["proc_id"])
logging.debug("Setting timeout to %d", remaining_time)
if remaining_time > 0:
signal.alarm(remaining_time)
@@ -316,25 +317,14 @@ class Machine(object):
signal.alarm(DEFAULT_TIMEOUT)
try:
- if 'netns' in command and command['netns'] != None:
- netns = command["netns"]
- cmd_res = self._rpc_call_to_netns(netns, "run_command", command)
- else:
- cmd_res = self._rpc_call("run_command", command)
+ cmd_res = self._rpc_call_x(netns, "run_command", command)
except MachineError as exc:
- if command["netns"] is not None:
- netns = command["netns"]
- if "proc_id" in command:
- cmd_res = self._rpc_call_to_netns(netns, "kill_command",
- command["proc_id"])
- else:
- cmd_res = self._rpc_call_to_netns(netns, "kill_command",
- None)
+ if "proc_id" in command:
+ cmd_res = self._rpc_call_x(netns, "kill_command",
+ command["proc_id"])
else:
- if "proc_id" in command:
- cmd_res = self._rpc_call("kill_command", command["proc_id"])
- else:
- cmd_res = self._rpc_call("kill_command", None)
+ cmd_res = self._rpc_call_x(netns, "kill_command",
+ None)
if "killed" in cmd_res and cmd_res["killed"]:
cmd_res["passed"] = False
@@ -400,10 +390,7 @@ class Machine(object):
tmp = {}
for netns in namespaces:
- if netns == None:
- tmp.update(self._rpc_call("start_packet_capture", ""))
- else:
- tmp.update(self._rpc_call_to_netns(netns, "start_packet_capture", ""))
+ tmp.update(self._rpc_call_x(netns, "start_packet_capture", ""))
return tmp
def stop_packet_capture(self):
@@ -412,17 +399,10 @@ class Machine(object):
namespaces.add(iface.get_netns())
for netns in namespaces:
- if netns == None:
- self._rpc_call("stop_packet_capture")
- else:
- self._rpc_call_to_netns(netns, "stop_packet_capture")
+ self._rpc_call_x(netns, "stop_packet_capture")
def copy_file_to_machine(self, local_path, remote_path=None, netns=None):
- if netns:
- remote_path = self._rpc_call_to_netns(netns, "start_copy_to",
- remote_path)
- else:
- remote_path = self._rpc_call("start_copy_to", remote_path)
+ remote_path = self._rpc_call_x(netns, "start_copy_to", remote_path)
f = open(local_path, "rb")
@@ -431,16 +411,9 @@ class Machine(object):
if len(data) == 0:
break
- if netns:
- self._rpc_call_to_netns(netns, "copy_part_to", remote_path,
- Binary(data))
- else:
- self._rpc_call("copy_part_to", remote_path, Binary(data))
+ self._rpc_call_x(netns, "copy_part_to", remote_path, Binary(data))
- if netns:
- self._rpc_call_to_netns(netns, "finish_copy_to", remote_path)
- else:
- self._rpc_call("finish_copy_to", remote_path)
+ self._rpc_call_x(netns, "finish_copy_to", remote_path)
return remote_path
@@ -689,12 +662,8 @@ class Interface(object):
return self._mtu
def update_from_slave(self):
- if self._netns != None:
- if_data = self._machine._rpc_call_to_netns(self._netns,
- "get_if_data",
- self._id)
- else:
- if_data = self._machine._rpc_call("get_if_data", self._id)
+ if_data = self._machine._rpc_call_x(self._netns, "get_if_data",
+ self._id)
if if_data is not None:
self.update(if_data)
@@ -734,32 +703,16 @@ class Interface(object):
return config
def up(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_device_up", self._id)
- else:
- self._machine._rpc_call("set_device_up", self._id)
+ self._machine._rpc_call_x(self._netns, "set_device_up", self._id)
def down(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_device_down", self._id)
- else:
- self._machine._rpc_call("set_device_down", self._id)
+ self._machine._rpc_call_x(self._netns, "set_device_down", self._id)
def set_link_up(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_link_up", self._id)
- else:
- self._machine._rpc_call("set_link_up", self._id)
+ self._machine._rpc_call_x(self._netns, "set_link_up", self._id)
def set_link_down(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_link_down", self._id)
- else:
- self._machine._rpc_call("set_link_down", self._id)
+ self._machine._rpc_call_x(self._netns, "set_link_down", self._id)
def initialize(self):
phys_devs = self._machine._rpc_call("map_if_by_hwaddr",
@@ -795,24 +748,20 @@ class Interface(object):
if self._netns != None:
self._machine._rpc_call("set_if_netns", self.get_id(), self._netns)
- self._machine._rpc_call_to_netns(self._netns, "configure_interface",
- self.get_id(), self.get_config())
- else:
- self._machine._rpc_call("configure_interface", self.get_id(),
- self.get_config())
+ self._machine._rpc_call_x(self._netns, "configure_interface",
+ self.get_id(), self.get_config())
+
self.update_from_slave()
def deconfigure(self):
if not self._configured:
return
+ self._machine._rpc_call_x(self._netns, "deconfigure_interface",
+ self.get_id())
if self._netns != None:
self._machine._rpc_call_to_netns(self._netns,
- "deconfigure_interface", self.get_id())
- self._machine._rpc_call_to_netns(self._netns,
"return_if_netns", self.get_id())
- else:
- self._machine._rpc_call("deconfigure_interface", self.get_id())
self._configured = False
class StaticInterface(Interface):
@@ -849,16 +798,10 @@ class LoopbackInterface(Interface):
self._hwaddr = '00:00:00:00:00:00'
self._driver = 'loopback'
- if self._netns:
- phys_devs = self._machine._rpc_call_to_netns(self._netns,
- "map_if_by_params", self._id,
- { 'hwaddr': self._hwaddr,
- 'driver': self._driver })
- else:
- phys_devs = self._machine._rpc_call("map_if_by_params",
- self._id,
- { 'hwaddr': self._hwaddr,
- 'driver': self._driver })
+ phys_devs = self._machine._rpc_call_x(self._netns,
+ "map_if_by_params", self._id,
+ { 'hwaddr': self._hwaddr,
+ 'driver': self._driver })
if len(phys_devs) == 1:
self.set_devname(phys_devs[0]["name"])
@@ -880,12 +823,8 @@ class LoopbackInterface(Interface):
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
- if self._netns != None:
- self._machine._rpc_call_to_netns(self._netns, "configure_interface",
- self.get_id(), self.get_config())
- else:
- self._machine._rpc_call("configure_interface", self.get_id(),
- self.get_config())
+ self._machine._rpc_call_x(self._netns, "configure_interface",
+ self.get_id(), self.get_config())
self._configured = True
self.update_from_slave()
@@ -893,14 +832,9 @@ class LoopbackInterface(Interface):
if not self._configured:
return
- if self._netns != None:
- self._machine._rpc_call_to_netns(self._netns,
- "deconfigure_interface", self.get_id())
- self._machine._rpc_call_to_netns(self._netns,
- "unmap_if", self.get_id())
- else:
- self._machine._rpc_call("deconfigure_interface", self.get_id())
- self._machine._rpc_call("unmap_if", self.get_id())
+ self._machine._rpc_call_x(self._netns, "deconfigure_interface",
+ self.get_id())
+ self._machine._rpc_call_x(self._netns, "unmap_if", self.get_id())
self._configured = False
class VirtualInterface(Interface):
@@ -1024,12 +958,9 @@ class SoftInterface(Interface):
peer_if._configured = True
return
- if self._netns != None:
- dev_name = self._machine._rpc_call_to_netns(self._netns,
- "create_soft_interface", self._id, self.get_config())
- else:
- dev_name = self._machine._rpc_call("create_soft_interface",
- self._id, self.get_config())
+ dev_name = self._machine._rpc_call_x(self._netns,
+ "create_soft_interface",
+ self._id, self.get_config())
self.set_devname(dev_name)
self.update_from_slave()
@@ -1048,14 +979,9 @@ class SoftInterface(Interface):
peer_if._configured = False
return
- if self._netns != None:
- self._machine._rpc_call_to_netns(self._netns,
- "deconfigure_interface", self.get_id())
- self._machine._rpc_call_to_netns(self._netns,
- "unmap_if", self.get_id())
- else:
- self._machine._rpc_call("deconfigure_interface", self.get_id())
- self._machine._rpc_call("unmap_if", self.get_id())
+ self._machine._rpc_call_x(self._netns, "deconfigure_interface",
+ self.get_id())
+ self._machine._rpc_call_x(self._netns, "unmap_if", self.get_id())
self._configured = False
class UnusedInterface(Interface):
--
2.4.3
7 years, 9 months
[patch lnst] Machine: introduce helper method _rpc_call_x
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
On lot of places, there is if-else construction due to netns and
non-netns rpc call. Wrap this up by _rpc_call_x method and make the code
more simple.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Machine.py | 164 +++++++++++++--------------------------------
1 file changed, 45 insertions(+), 119 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index ce78866..8cfe5bf 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -191,6 +191,11 @@ class Machine(object):
return result
+ def _rpc_call_x(self, netns, method_name, *args):
+ if not netns:
+ return self._rpc_call(method_name, *args)
+ return self._rpc_call_to_netns(netns, method_name, *args)
+
def configure(self, recipe_name):
""" Prepare the machine
@@ -289,16 +294,12 @@ class Machine(object):
if bg_cmd["netns"] != None:
command["netns"] = bg_cmd["netns"]
+ netns = command["netns"]
if command["type"] == "wait":
logging.debug("Get remaining time of bg process with bg_id == %s"
% command["proc_id"])
- if command["netns"] != None:
- remaining_time = self._rpc_call_to_netns(command["netns"],
- "get_remaining_time",
- command["proc_id"])
- else:
- remaining_time = self._rpc_call("get_remaining_time",
- command["proc_id"])
+ remaining_time = self._rpc_call_x(netns, "get_remaining_time",
+ command["proc_id"])
logging.debug("Setting timeout to %d", remaining_time)
if remaining_time > 0:
signal.alarm(remaining_time)
@@ -316,25 +317,14 @@ class Machine(object):
signal.alarm(DEFAULT_TIMEOUT)
try:
- if 'netns' in command and command['netns'] != None:
- netns = command["netns"]
- cmd_res = self._rpc_call_to_netns(netns, "run_command", command)
- else:
- cmd_res = self._rpc_call("run_command", command)
+ cmd_res = self._rpc_call_x(netns, "run_command", command)
except MachineError as exc:
- if command["netns"] is not None:
- netns = command["netns"]
- if "proc_id" in command:
- cmd_res = self._rpc_call_to_netns(netns, "kill_command",
- command["proc_id"])
- else:
- cmd_res = self._rpc_call_to_netns(netns, "kill_command",
- None)
+ if "proc_id" in command:
+ cmd_res = self._rpc_call_x(netns, "kill_command",
+ command["proc_id"])
else:
- if "proc_id" in command:
- cmd_res = self._rpc_call("kill_command", command["proc_id"])
- else:
- cmd_res = self._rpc_call("kill_command", None)
+ cmd_res = self._rpc_call_x(netns, "kill_command",
+ None)
if "killed" in cmd_res and cmd_res["killed"]:
cmd_res["passed"] = False
@@ -400,10 +390,7 @@ class Machine(object):
tmp = {}
for netns in namespaces:
- if netns == None:
- tmp.update(self._rpc_call("start_packet_capture", ""))
- else:
- tmp.update(self._rpc_call_to_netns(netns, "start_packet_capture", ""))
+ tmp.update(self._rpc_call_x(netns, "start_packet_capture", ""))
return tmp
def stop_packet_capture(self):
@@ -412,17 +399,10 @@ class Machine(object):
namespaces.add(iface.get_netns())
for netns in namespaces:
- if netns == None:
- self._rpc_call("stop_packet_capture")
- else:
- self._rpc_call_to_netns(netns, "stop_packet_capture")
+ self._rpc_call_x(netns, "stop_packet_capture")
def copy_file_to_machine(self, local_path, remote_path=None, netns=None):
- if netns:
- remote_path = self._rpc_call_to_netns(netns, "start_copy_to",
- remote_path)
- else:
- remote_path = self._rpc_call("start_copy_to", remote_path)
+ remote_path = self._rpc_call_x(netns, "start_copy_to", remote_path)
f = open(local_path, "rb")
@@ -431,16 +411,9 @@ class Machine(object):
if len(data) == 0:
break
- if netns:
- self._rpc_call_to_netns(netns, "copy_part_to", remote_path,
- Binary(data))
- else:
- self._rpc_call("copy_part_to", remote_path, Binary(data))
+ self._rpc_call_x(netns, "copy_part_to", remote_path, Binary(data))
- if netns:
- self._rpc_call_to_netns(netns, "finish_copy_to", remote_path)
- else:
- self._rpc_call("finish_copy_to", remote_path)
+ self._rpc_call_x(netns, "finish_copy_to", remote_path)
return remote_path
@@ -689,12 +662,8 @@ class Interface(object):
return self._mtu
def update_from_slave(self):
- if self._netns != None:
- if_data = self._machine._rpc_call_to_netns(self._netns,
- "get_if_data",
- self._id)
- else:
- if_data = self._machine._rpc_call("get_if_data", self._id)
+ if_data = self._machine._rpc_call_x(self._netns, "get_if_data",
+ self._id)
if if_data is not None:
self.update(if_data)
@@ -734,32 +703,16 @@ class Interface(object):
return config
def up(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_device_up", self._id)
- else:
- self._machine._rpc_call("set_device_up", self._id)
+ self._machine._rpc_call_x(self._netns, "set_device_up", self._id)
def down(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_device_down", self._id)
- else:
- self._machine._rpc_call("set_device_down", self._id)
+ self._machine._rpc_call_x(self._netns, "set_device_down", self._id)
def set_link_up(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_link_up", self._id)
- else:
- self._machine._rpc_call("set_link_up", self._id)
+ self._machine._rpc_call_x(self._netns, "set_link_up", self._id)
def set_link_down(self):
- netns = self._netns
- if netns != None:
- self._machine._rpc_call_to_netns(netns, "set_link_down", self._id)
- else:
- self._machine._rpc_call("set_link_down", self._id)
+ self._machine._rpc_call_x(self._netns, "set_link_down", self._id)
def initialize(self):
phys_devs = self._machine._rpc_call("map_if_by_hwaddr",
@@ -795,24 +748,20 @@ class Interface(object):
if self._netns != None:
self._machine._rpc_call("set_if_netns", self.get_id(), self._netns)
- self._machine._rpc_call_to_netns(self._netns, "configure_interface",
- self.get_id(), self.get_config())
- else:
- self._machine._rpc_call("configure_interface", self.get_id(),
- self.get_config())
+ self._machine._rpc_call_x(self._netns, "configure_interface",
+ self.get_id(), self.get_config())
+
self.update_from_slave()
def deconfigure(self):
if not self._configured:
return
+ self._machine._rpc_call_x(self._netns, "deconfigure_interface",
+ self.get_id())
if self._netns != None:
self._machine._rpc_call_to_netns(self._netns,
- "deconfigure_interface", self.get_id())
- self._machine._rpc_call_to_netns(self._netns,
"return_if_netns", self.get_id())
- else:
- self._machine._rpc_call("deconfigure_interface", self.get_id())
self._configured = False
class StaticInterface(Interface):
@@ -849,16 +798,10 @@ class LoopbackInterface(Interface):
self._hwaddr = '00:00:00:00:00:00'
self._driver = 'loopback'
- if self._netns:
- phys_devs = self._machine._rpc_call_to_netns(self._netns,
- "map_if_by_params", self._id,
- { 'hwaddr': self._hwaddr,
- 'driver': self._driver })
- else:
- phys_devs = self._machine._rpc_call("map_if_by_params",
- self._id,
- { 'hwaddr': self._hwaddr,
- 'driver': self._driver })
+ phys_devs = self._machine._rpc_call_x(self._netns,
+ "map_if_by_params", self._id,
+ { 'hwaddr': self._hwaddr,
+ 'driver': self._driver })
if len(phys_devs) == 1:
self.set_devname(phys_devs[0]["name"])
@@ -880,12 +823,8 @@ class LoopbackInterface(Interface):
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
- if self._netns != None:
- self._machine._rpc_call_to_netns(self._netns, "configure_interface",
- self.get_id(), self.get_config())
- else:
- self._machine._rpc_call("configure_interface", self.get_id(),
- self.get_config())
+ self._machine._rpc_call_x(self._netns, "configure_interface",
+ self.get_id(), self.get_config())
self._configured = True
self.update_from_slave()
@@ -893,14 +832,9 @@ class LoopbackInterface(Interface):
if not self._configured:
return
- if self._netns != None:
- self._machine._rpc_call_to_netns(self._netns,
- "deconfigure_interface", self.get_id())
- self._machine._rpc_call_to_netns(self._netns,
- "unmap_if", self.get_id())
- else:
- self._machine._rpc_call("deconfigure_interface", self.get_id())
- self._machine._rpc_call("unmap_if", self.get_id())
+ self._machine._rpc_call_x(self._netns, "deconfigure_interface",
+ self.get_id())
+ self._machine._rpc_call_x(self._netns, "unmap_if", self.get_id())
self._configured = False
class VirtualInterface(Interface):
@@ -1024,12 +958,9 @@ class SoftInterface(Interface):
peer_if._configured = True
return
- if self._netns != None:
- dev_name = self._machine._rpc_call_to_netns(self._netns,
- "create_soft_interface", self._id, self.get_config())
- else:
- dev_name = self._machine._rpc_call("create_soft_interface",
- self._id, self.get_config())
+ dev_name = self._machine._rpc_call_x(self._netns,
+ "create_soft_interface",
+ self._id, self.get_config())
self.set_devname(dev_name)
self.update_from_slave()
@@ -1048,14 +979,9 @@ class SoftInterface(Interface):
peer_if._configured = False
return
- if self._netns != None:
- self._machine._rpc_call_to_netns(self._netns,
- "deconfigure_interface", self.get_id())
- self._machine._rpc_call_to_netns(self._netns,
- "unmap_if", self.get_id())
- else:
- self._machine._rpc_call("deconfigure_interface", self.get_id())
- self._machine._rpc_call("unmap_if", self.get_id())
+ self._machine._rpc_call_x(self._netns, "deconfigure_interface",
+ self.get_id())
+ self._machine._rpc_call_x(self._netns, "unmap_if", self.get_id())
self._configured = False
class UnusedInterface(Interface):
--
2.4.3
7 years, 9 months
[patch lnst 1/2] Task: get interface id after new iface is created
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
When user passes None and the if_id is generated by Machine class, get
the created id and use it further.
Fixes: c1ef94696 ("Task: Allow to create software devices from running task")
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Task.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 8670150..2f16e84 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -365,6 +365,7 @@ class HostAPI(object):
def _add_iface(self, if_type, if_id, netns, ip, options, slaves):
interface = self._m.new_soft_interface(if_id, if_type)
+ if_id = interface.get_id()
iface = InterfaceAPI(interface, self)
self._ifaces[if_id] = iface
--
2.4.3
7 years, 9 months
[patch lnst v2 1/5] Task: fix naming of ifaces
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
if_id is for interface id, iface is for InterfaceAPI objects, interface
is for Interface object
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Task.py | 54 ++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 673048d..242d046 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -171,11 +171,11 @@ class HostAPI(object):
self._id = host_id
self._m = host
- self._interfaces = {}
- for i in self._m.get_interfaces():
- if i.get_id() is None:
+ self._ifaces = {}
+ for interface in self._m.get_interfaces():
+ if interface.get_id() is None:
continue
- self._interfaces[i.get_id()] = InterfaceAPI(i, self)
+ self._ifaces[interface.get_id()] = InterfaceAPI(interface, self)
self._bg_id_seq = 0
@@ -274,72 +274,72 @@ class HostAPI(object):
return ProcessAPI(self._ctl, self._id, cmd_res, bg_id, cmd["netns"])
def get_interfaces(self):
- return self._interfaces
+ return self._ifaces
- def get_interface(self, interface_id):
- return self._interfaces[interface_id]
+ def get_interface(self, if_id):
+ return self._ifaces[if_id]
@deprecated
- def get_devname(self, interface_id):
+ def get_devname(self, if_id):
"""
Returns devname of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
:return: Device name (e.g., eth0).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_devname()
@deprecated
- def get_hwaddr(self, interface_id):
+ def get_hwaddr(self, if_id):
"""
Returns hwaddr of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
:return: HW address (e.g., 00:11:22:33:44:55:FF).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_hwaddr()
@deprecated
- def get_ip(self, interface_id, addr_number=0):
+ def get_ip(self, if_id, addr_number=0):
"""
Returns an IP address of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
- :param interface_id: which address
- :type interface_id: int
+ :param addr_number: which address
+ :type addr_number: int
:return: IP address (e.g., 192.168.1.10).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_ip_addr(addr_number)
@deprecated
- def get_prefix(self, interface_id, addr_number=0):
+ def get_prefix(self, if_id, addr_number=0):
"""
Returns an IP address prefix (netmask)
of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
- :param interface_id: which address
- :type interface_id: int
+ :param addr_number: which address
+ :type addr_number: int
:return: netmask (e.g., 24).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_ip_prefix(addr_number)
def sync_resources(self, modules=[], tools=[]):
--
2.4.3
7 years, 9 months
[patch lnst 1/3] Task: fix naming of ifaces
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
if_id is for interface id, iface is for InterfaceAPI objects, interface
is for Interface object
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Task.py | 54 ++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 673048d..242d046 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -171,11 +171,11 @@ class HostAPI(object):
self._id = host_id
self._m = host
- self._interfaces = {}
- for i in self._m.get_interfaces():
- if i.get_id() is None:
+ self._ifaces = {}
+ for interface in self._m.get_interfaces():
+ if interface.get_id() is None:
continue
- self._interfaces[i.get_id()] = InterfaceAPI(i, self)
+ self._ifaces[interface.get_id()] = InterfaceAPI(interface, self)
self._bg_id_seq = 0
@@ -274,72 +274,72 @@ class HostAPI(object):
return ProcessAPI(self._ctl, self._id, cmd_res, bg_id, cmd["netns"])
def get_interfaces(self):
- return self._interfaces
+ return self._ifaces
- def get_interface(self, interface_id):
- return self._interfaces[interface_id]
+ def get_interface(self, if_id):
+ return self._ifaces[if_id]
@deprecated
- def get_devname(self, interface_id):
+ def get_devname(self, if_id):
"""
Returns devname of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
:return: Device name (e.g., eth0).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_devname()
@deprecated
- def get_hwaddr(self, interface_id):
+ def get_hwaddr(self, if_id):
"""
Returns hwaddr of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
:return: HW address (e.g., 00:11:22:33:44:55:FF).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_hwaddr()
@deprecated
- def get_ip(self, interface_id, addr_number=0):
+ def get_ip(self, if_id, addr_number=0):
"""
Returns an IP address of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
- :param interface_id: which address
- :type interface_id: int
+ :param addr_number: which address
+ :type addr_number: int
:return: IP address (e.g., 192.168.1.10).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_ip_addr(addr_number)
@deprecated
- def get_prefix(self, interface_id, addr_number=0):
+ def get_prefix(self, if_id, addr_number=0):
"""
Returns an IP address prefix (netmask)
of the interface.
- :param interface_id: which interface
- :type interface_id: string
+ :param if_id: which interface
+ :type if_id: string
- :param interface_id: which address
- :type interface_id: int
+ :param addr_number: which address
+ :type addr_number: int
:return: netmask (e.g., 24).
:rtype: str
"""
- iface = self._interfaces[interface_id]
+ iface = self._ifaces[if_id]
return iface.get_ip_prefix(addr_number)
def sync_resources(self, modules=[], tools=[]):
--
2.4.3
7 years, 9 months
[patch lnst] Task: add get_host method to Interface API
by Jiri Pirko
From: Jiri Pirko <jiri(a)mellanox.com>
python task might need to get host object by interface object.
I actually have usecase for this. So just add the method.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Task.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 7f9dc8e..673048d 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -175,7 +175,7 @@ class HostAPI(object):
for i in self._m.get_interfaces():
if i.get_id() is None:
continue
- self._interfaces[i.get_id()] = InterfaceAPI(i)
+ self._interfaces[i.get_id()] = InterfaceAPI(i, self)
self._bg_id_seq = 0
@@ -364,8 +364,9 @@ class HostAPI(object):
self._m.sync_resources(sync_table)
class InterfaceAPI(object):
- def __init__(self, interface):
+ def __init__(self, interface, host):
self._if = interface
+ self._host = host
def get_id(self):
return self._if.get_id()
@@ -418,6 +419,9 @@ class InterfaceAPI(object):
def set_link_down(self):
return self._if.set_link_down()
+ def get_host(self):
+ return self._host
+
class ModuleAPI(object):
""" An API class representing a module. """
--
2.4.3
7 years, 9 months