commit 0deed16ab3a1edea3c8664e311cbacaf8d4f3055
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Apr 5 16:19:55 2013 +0200
SlavePool: test connection to slave machines
This commit adds a new functionality to the SlavePool class. Until now
we have used all configuration files located in the pool directory and
used them in our matching algorithm. This however won't work correctly
if some machines are turned off. In this case the matching algorithm
uses the first configuration that matches even if it contains a machine
that is turned off which will result in a failure state. Even though
there exists a match that is fully available.
This commit adds code to the SlavePool initialization where we test
connectability of each machine being added to the pool and skip machines
that are turned off.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Controller/NetTestController.py | 2 +-
lnst/Controller/SlavePool.py | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 645ed78..ffa2bf8 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -51,7 +51,7 @@ class NetTestController:
self._msg_dispatcher = MessageDispatcher()
sp = SlavePool(config.get_option('environment', 'pool_dirs'),
- check_process_running("libvirtd"))
+ check_process_running("libvirtd"), config)
self._slave_pool = sp
self._recipe = recipe = {}
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py
index 8470190..c98bb24 100644
--- a/lnst/Controller/SlavePool.py
+++ b/lnst/Controller/SlavePool.py
@@ -19,6 +19,7 @@ import re
import copy
from xml.dom import minidom
from lnst.Common.XmlProcessing import XmlDomTreeInit
+from lnst.Common.NetUtils import test_tcp_connection
from lnst.Controller.NetTestParse import SlaveMachineParse
class SlavePool:
@@ -35,7 +36,8 @@ class SlavePool:
_allow_virtual = False
- def __init__(self, pool_dirs, allow_virtual=False):
+ def __init__(self, pool_dirs, allow_virtual=False, config=None):
+ self._config = config
self._allow_virtual = allow_virtual
for pool_dir in pool_dirs:
self.add_dir(pool_dir)
@@ -64,8 +66,20 @@ class SlavePool:
slavemachine = dom.getElementsByTagName("slavemachine")[0]
parser.parse(slavemachine)
+
+ hostname = machine["params"]["hostname"]
+ if "rpcport" in machine:
+ port = machine["params"]["rpcport"]
+ else:
+ port = self._config.get_option('environment', 'rpcport')
+ logging.info("Querying slave machine %s." % machine_id)
+ if not test_tcp_connection(hostname, port):
+ return
+
if 'libvirt_domain' not in machine['params'] \
or self._allow_virtual:
+ logging.info("Adding slave machine %s to slave pool."
+ % machine_id)
self._pool[machine_id] = machine
else:
logging.warning("libvirtd not found- Machine Pool skipping "\