commit 28b5f16bb69dbc0a4915360b343a2415eeaa26a9 Author: Radek Pazdera rpazdera@redhat.com Date: Thu Aug 30 15:02:42 2012 +0200
NetTest: Adding MachinePool module
This commit introduces MachinePool into NetTestController.
MachinePool will be responsible for managing local machine configs at controller. NetTestController will search for available configs on startup and then be able to use the machines for testing. Template matching of test setups against the pool should be done in the future.
Signed-off-by: Radek Pazdera rpazdera@redhat.com
NetTest/MachinePool.py | 61 ++++++++++++++++++++++++++++++++++++++++++ NetTest/NetTestController.py | 3 ++ 2 files changed, 64 insertions(+), 0 deletions(-) --- diff --git a/NetTest/MachinePool.py b/NetTest/MachinePool.py new file mode 100644 index 0000000..2712f09 --- /dev/null +++ b/NetTest/MachinePool.py @@ -0,0 +1,61 @@ +""" +This module contains implementaion of MachinePool class that +can be used to maintain a cluster of test machines. + +Copyright 2012 Red Hat, Inc. +Licensed under the GNU General Public License, version 2 as +published by the Free Software Foundation; see COPYING for details. +""" + +__author__ = """ +rpazdera@redhat.com (Radek Pazdera) +""" + +import logging +import os +import re +from Common.XmlProcessing import XmlDomTreeInit +from NetTestParse import MachineConfigParse + +class MachinePool: + """ This class is responsible for managing test machines + that are available at controler and can be used for + testing via template matching + """ + + _machines = {} + + def __init__(self, pool_dirs): + for pool_dir in pool_dirs: + self.add_dir(pool_dir) + + def add_dir(self, pool_dir): + dentries = os.listdir(pool_dir) + + for dirent in dentries: + self.add_file("%s/%s" % (pool_dir, dirent)) + + def add_file(self, filepath): + if os.path.isfile(filepath) and re.search(".xml$", filepath, re.I): + dom_init = XmlDomTreeInit() + dom = dom_init.parse_file(filepath) + + dirname, basename = os.path.split(filepath) + + parser = MachineConfigParse() + parser.set_include_root(dirname) + parser.disable_events() + + machine = {"info": {}, "netdevices": {}} + machine_id = re.sub(".xml$", "", basename, flags=re.I) + parser.set_machine(machine_id, machine) + + machineconfig = dom.getElementsByTagName("machineconfig")[0] + parser.parse(machineconfig) + self._machines[machine_id] = machine + + def get_machines(self): + return self._machines + + def match_setup(self, templates): + pass diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py index 41707c5..b028e35 100644 --- a/NetTest/NetTestController.py +++ b/NetTest/NetTestController.py @@ -26,6 +26,7 @@ from NetTest.NetTestCommand import NetTestCommand, str_command from Common.LoggingServer import LoggingServer from Common.VirtUtils import VirtNetCtl, VirtDomainCtl, BridgeCtl from Common.Utils import wait_for +from NetTest.MachinePool import MachinePool
MAC_POOL_RANGE = {"start": "52:54:01:00:00:01", "end": "52:54:01:FF:FF:FF"}
@@ -43,6 +44,8 @@ class NetTestController: self._res_serializer = res_serializer self._remote_capture_files = {}
+ self._machine_pool = MachinePool([]) + self._recipe = {} definitions = {"recipe": self._recipe}
lnst-developers@lists.fedorahosted.org