From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit extends the message handling on the controller, to recieve
update messages from slave machines.
A new method was added to the Machine objects- interface_update that
will be called when an update message is recieved. At the moment it only
looks up the corresponding interface (by devname) and updates its hw
address. In the future this could be used to update ip addresses, and
devnames them selves (when the kernel indices are stored).
This change also required the addition of a dictionary to the message
dispatcher object that maps machine id to the machine object.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Machine.py | 10 +++++++++-
lnst/Controller/NetTestController.py | 9 ++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 5876347..14e78ed 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -70,6 +70,14 @@ class Machine(object):
self._interfaces.append(iface)
return iface
+ def interface_update(self, if_data):
+ for iface in self._interfaces:
+ try:
+ if iface.get_devname() == if_data["devname"]:
+ iface.set_hwaddr(if_data["hwaddr"])
+ except:
+ pass
+
#
# Factory methods for constructing interfaces on this machine. The
# types of interfaces are explained with the classes below.
@@ -116,7 +124,7 @@ class Machine(object):
logging.info("Connecting to RPC on machine %s (%s)", m_id, hostname)
connection = socket.create_connection((hostname, port))
- self._msg_dispatcher.add_slave(self._id, connection)
+ self._msg_dispatcher.add_slave(self, connection)
hello = self._rpc_call("hello", recipe_name)
if hello != "hello":
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index fee06ed..b8ffd26 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -598,8 +598,11 @@ class MessageDispatcher(ConnectionHandler):
def __init__(self, log_ctl):
super(MessageDispatcher, self).__init__()
self._log_ctl = log_ctl
+ self._machines = dict()
- def add_slave(self, machine_id, connection):
+ def add_slave(self, machine, connection):
+ machine_id = machine.get_id()
+ self._machines[machine_id] = machine
self.add_connection(machine_id, connection)
def send_message(self, machine_id, data):
@@ -641,6 +644,9 @@ class MessageDispatcher(ConnectionHandler):
elif message[1]["type"] == "result":
msg = "Recieved result message from different slave %s" %
message[0]
logging.debug(msg)
+ elif message[1]["type"] == "if_update":
+ machine = self._machines[message[0]]
+ machine.interface_update(message[1])
elif message[1]["type"] == "exception":
msg = "Recieved an exception from slave: %s" % message[0]
raise CommandException(msg)
@@ -655,3 +661,4 @@ class MessageDispatcher(ConnectionHandler):
def disconnect_slave(self, machine_id):
soc = self.get_connection(machine_id)
self.remove_connection(soc)
+ del self._machines[machine_id]
--
1.8.3.1