The change allows 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 | 14 ++++++++------
NetTest/NetTestParse.py | 6 ++++--
nettestctl.py | 2 +-
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/Common/XmlProcessing.py b/Common/XmlProcessing.py
index 5aa7ccd..396a172 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):
@@ -225,6 +226,8 @@ class RecipeParser(XmlParser):
else:
self._recipe = {}
self._template_proc = XmlTemplates()
+ # TODO: not sure what this could break ...
+ # include root for http recipe is not compatible with this
I do not understand. Please clarify.
Thanks
Jiri
self._include_root = os.getcwd()
self._events_enabled = True
self._event_handlers = {}
@@ -281,14 +284,16 @@ 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)
except IOError, err:
msg = "Unable to resolve include: %s" % str(err)
raise XmlProcessingError(msg, node)
@@ -361,6 +366,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 4f54624..94e5502 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -17,20 +17,22 @@ from Common.XmlProcessing import RecipeParser
from Common.XmlProcessing import XmlDomTreeInit
from Common.XmlProcessing import XmlProcessingError
from Common.NetUtils import normalize_hwaddr
+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)
+ xml_dom = dom_init.parse_string(self._rp.to_str())
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)
--
1.7.7.6
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers