commit ee497ab18ba0e2c2b8ff74773688ab9c5cdb1652
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Mon Sep 24 15:52:16 2012 +0200
Recipes and sourced bits can now be represented by HTTP urls
The change allows a user to specify both local file and http urls as
recipe and sourced recipe bits (using 'source' attribute). Relative
paths are automagically resolved. See usage below in tested scenarios.
Tested for following use cases:
1. url supplied to controller on command line
# nettestctl.py -c
http://somedomain.com/jtluka/rhel63-tests/bond-tests/bond-mode5-scenario1...
# run
2. relative local file path supplied to controller
# nettestctl.py -c ./rhel63-tests/bond-tests/bond-mode5-scenario1.xml
# run
3. relative local directory path supplied to controller
# nettestctl.py -c ./rhel63-tests/bond-tests/ run
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Common/XmlProcessing.py | 13 +++++++------
NetTest/NetTestParse.py | 7 +++++--
nettestctl.py | 2 +-
3 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/Common/XmlProcessing.py b/Common/XmlProcessing.py
index 5aa7ccd..2ae5f4c 100644
--- a/Common/XmlProcessing.py
+++ b/Common/XmlProcessing.py
@@ -15,6 +15,7 @@ import logging
from xml.dom.minidom import parseString
from xml import sax
from Common.XmlTemplates import XmlTemplates, XmlTemplateError
+from Common.RecipePath import RecipePath
class XmlProcessingError(Exception):
@@ -281,14 +282,17 @@ class RecipeParser(XmlParser):
old_include_root = None
if self._has_attribute(node, "source"):
source = self._get_attribute(node, "source")
- file_path = self._get_referenced_xml_path(source)
+
+ source_rp = RecipePath(self._include_root, source)
old_include_root = self._include_root
- self._include_root = os.path.dirname(file_path)
+ self._include_root = source_rp.get_root()
+ xmlstr = source_rp.to_str()
dom_init = XmlDomTreeInit()
try:
- dom = dom_init.parse_file(file_path)
+ dom = dom_init.parse_string(xmlstr,
+ filename=source_rp.abs_path())
except IOError, err:
msg = "Unable to resolve include: %s" % str(err)
raise XmlProcessingError(msg, node)
@@ -361,6 +365,3 @@ class RecipeParser(XmlParser):
self._template_proc.define_alias(name, value)
except XmlTemplateError, err:
raise XmlProcessingError(str(err), node)
-
- def _get_referenced_xml_path(self, filename):
- return os.path.normpath(os.path.join(self._include_root,
os.path.expanduser(filename)))
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 76068dd..bdf1721 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -18,20 +18,23 @@ from Common.XmlProcessing import XmlDomTreeInit
from Common.XmlProcessing import XmlProcessingError
from Common.NetUtils import normalize_hwaddr
from Common.Utils import bool_it
+from Common.RecipePath import RecipePath
class NetTestParse(RecipeParser):
def __init__(self, recipe_filepath):
super(NetTestParse, self).__init__()
self._filepath = recipe_filepath
- self._include_root = os.path.dirname(recipe_filepath)
+ self._rp = RecipePath(None, self._filepath)
+ self._include_root = self._rp.get_root()
self._recipe = {}
self._template_proc.set_definitions({"recipe": self._recipe})
def parse_recipe(self):
dom_init = XmlDomTreeInit()
- xml_dom = dom_init.parse_file(self._filepath)
+ rp = self._rp
+ xml_dom = dom_init.parse_string(rp.to_str(), rp.abs_path())
self._parse(xml_dom)
def _parse(self, xml_dom):
diff --git a/nettestctl.py b/nettestctl.py
index bc79398..f9973e4 100755
--- a/nettestctl.py
+++ b/nettestctl.py
@@ -47,7 +47,7 @@ def usage():
def process_recipe(action, file_path, remoteexec, cleanup,
res_serializer, packet_capture, config):
- nettestctl = NetTestController(os.path.realpath(file_path),
+ nettestctl = NetTestController(file_path,
remoteexec=remoteexec, cleanup=cleanup,
res_serializer=res_serializer,
config=config)