From: Ondrej Lichtner <olichtne(a)redhat.com>
Currently logging doesn't work correctly if the connection between a
slave and the controller isn't properly set up. This can be for example
caused by a firewall. In these cases it can be confusing to users
because there is no indication of it other than missing logs.
This patch changes that. It adds a new function test_tcp_connection() to
the NetUtils module. Slaves use it to check if they are able to connect to
the logging server and inform the controller of the results. The
controller can then log an error message in case of a failure.
I tried making the error message more visible so that it's harder to
overlook.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
Common/NetUtils.py | 9 +++++++++
NetTest/NetTestController.py | 6 +++++-
NetTest/NetTestSlave.py | 6 ++++--
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/Common/NetUtils.py b/Common/NetUtils.py
index d7db077..fb39a41 100644
--- a/Common/NetUtils.py
+++ b/Common/NetUtils.py
@@ -37,6 +37,15 @@ def scan_netdevs():
scan.append({"name": d, "hwaddr": addr})
return scan
+def test_tcp_connection(host, port):
+ try:
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect((host, port))
+ s.shutdown(socket.SHUT_RDWR)
+ return True
+ except:
+ return False
+
def verify_ip_address(addr):
if len(addr.split('.')) != 4:
return False
diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py
index 95326e3..526a3e7 100644
--- a/NetTest/NetTestController.py
+++ b/NetTest/NetTestController.py
@@ -261,7 +261,11 @@ class NetTestController:
logging.info("Setting logging server on machine %s", hostname)
rpc = self._get_machinerpc(machine_id)
ip_addr = get_corespond_local_ip(hostname)
- rpc.set_logging(ip_addr, self._config.get_option('log', 'port'))
+ if not rpc.set_logging(ip_addr, self._config.get_option('log',
'port')):
+
logging.error("==================================================")
+ logging.error("Machine %s is unable to connect to the logging "\
+ "server! Check your firewall settings." % hostname)
+
logging.error("==================================================")
def _deconfigure_slaves(self):
if 'machines' not in self._recipe:
diff --git a/NetTest/NetTestSlave.py b/NetTest/NetTestSlave.py
index 7c391f8..a375f12 100644
--- a/NetTest/NetTestSlave.py
+++ b/NetTest/NetTestSlave.py
@@ -22,7 +22,7 @@ from NetConfig.NetConfig import NetConfig
from NetConfig.NetConfigDevice import NetConfigDeviceAllCleanup
from NetTest.NetTestCommand import NetTestCommandContext, NetTestCommand,
CommandException
from Common.Utils import die_when_parent_die
-from Common.NetUtils import scan_netdevs
+from Common.NetUtils import scan_netdevs, test_tcp_connection
DefaultRPCPort = 9999
@@ -45,8 +45,10 @@ class NetTestSlaveXMLRPC:
@param logger_address: Address of running logger.
"""
+ connectable = test_tcp_connection(logger_address, port)
+
Logs.append_network_hadler(logger_address, port)
- return True
+ return connectable
def get_devices_by_hwaddr(self, hwaddr):
name_scan = scan_netdevs()
--
1.7.11.4
Show replies by date