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.xm... 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@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 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)
Fri, Sep 21, 2012 at 12:07:03PM CEST, jtluka@redhat.com wrote:
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:
- url supplied to controller on command line
# nettestctl.py -c http://somedomain.com/jtluka/rhel63-tests/bond-tests/bond-mode5-scenario1.xm... run
- relative local file path supplied to controller
# nettestctl.py -c ./rhel63-tests/bond-tests/bond-mode5-scenario1.xml run
- relative local directory path supplied to controller
# nettestctl.py -c ./rhel63-tests/bond-tests/ run
Signed-off-by: Jan Tluka jtluka@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@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
Fri, Sep 21, 2012 at 12:46:22PM CEST, jpirko@redhat.com wrote:
Fri, Sep 21, 2012 at 12:07:03PM CEST, jtluka@redhat.com wrote:
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:
- url supplied to controller on command line
# nettestctl.py -c http://somedomain.com/jtluka/rhel63-tests/bond-tests/bond-mode5-scenario1.xm... run
- relative local file path supplied to controller
# nettestctl.py -c ./rhel63-tests/bond-tests/bond-mode5-scenario1.xml run
- relative local directory path supplied to controller
# nettestctl.py -c ./rhel63-tests/bond-tests/ run
Signed-off-by: Jan Tluka jtluka@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.
I think that this is related to sourcing local files only. So if you happen to combine local root with http bits I can't imagine what would be the result.
From my point of view, if you start with http://something then the
controller should use http as root. If you start with some local file, then os.getcwd() makes sense, since this will be the root for later referencing.
To be honest, I'd set it here to None. But, I'm just not sure if there's anything I missed that could break things. Maybe Radek could review this patch and share his 2 cents.
-Jan
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@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
lnst-developers@lists.fedorahosted.org