From: Ondrej Lichtner olichtne@redhat.com
This commit removes the old source attributes, since we moved to using XInclude. But since using XInclude for such simple recipe generation is a bit of an overkill the generation script uses simple string replacing.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- recipes/smoke/generate-recipes.py | 61 +++++++++------------------------------ recipes/smoke/lib/recipe-temp.xml | 8 ++--- 2 files changed, 18 insertions(+), 51 deletions(-)
diff --git a/recipes/smoke/generate-recipes.py b/recipes/smoke/generate-recipes.py index c7eedb9..2361aab 100755 --- a/recipes/smoke/generate-recipes.py +++ b/recipes/smoke/generate-recipes.py @@ -45,48 +45,6 @@ def replace_variables(recipe, name1, name2, variables): recipe = recipe.replace("#%s#" % name, val) return recipe
-def handleNode(node): - if node.nodeType == node.ELEMENT_NODE: - if node.hasAttribute("source"): - src_file_name = node.getAttribute("source") - loaded_dom = xml.dom.minidom.parse(src_file_name) - loaded_node = None - try: - loaded_node = loaded_dom.getElementsByTagName(node.nodeName)[0] - except Exception: - msg = ("No '%s' element present in included file '%s'." - % (node.nodeName, src_file_name)) - raise Exception(msg, node) - - old_attrs = node.attributes - - parent = node.parentNode - parent.replaceChild(loaded_node, node) - node = loaded_node - - # copy all of the original attributes to the sourced node - for i in range(old_attrs.length): - attr = old_attrs.item(i) - # do not overwrite sourced attributes - if not node.hasAttribute(attr.name) and attr.name != "source": - node.setAttribute(attr.name, attr.value) - - handleNode(node) - else: - childNodes = list(node.childNodes) - for child in childNodes: - if child.nodeType == node.TEXT_NODE and child.data.isspace(): - node.removeChild(child) - else: - handleNode(child) - -def expand_sources(recipe): - document = xml.dom.minidom.parseString(recipe) - for child in document.childNodes: - handleNode(child) - recipe = document.toprettyxml() - return recipe - def main(): DIR = "tests/" LIB = "../lib/" @@ -104,7 +62,11 @@ def main(): if not re.match("task-.*", seq): continue print "Found a task: %s%s" % (LIB, seq) - sequences += "\n <task source="%s%s"/>" % (LIB, seq) + + task_f = open("%s/%s" % (LIB, seq), 'r') + task = task_f.read() + + sequences += "\n%s" % task
conf_files = [LIB+i for i in os.listdir(LIB) if re.match("conf-.*", i)] for conf in conf_files: @@ -123,11 +85,16 @@ def main(): recipe_name = "recipe-%s-%s.xml" % (name1, name2) print "Generating %s%s..." % (DIR, recipe_name),
- recipe = template.replace("#CONF1#", machine1)\ - .replace("#CONF2#", machine2)\ - .replace("#SEQUENCES#", sequences) + m1_f = open(machine1, 'r') + m1 = m1_f.read() + + m2_f = open(machine2, 'r') + m2 = m2_f.read()
- recipe = expand_sources(recipe) + + recipe = template.replace("#CONF1#", m1)\ + .replace("#CONF2#", m2)\ + .replace("#SEQUENCES#", sequences)
recipe = replace_variables(recipe, name1, name2, variables)
diff --git a/recipes/smoke/lib/recipe-temp.xml b/recipes/smoke/lib/recipe-temp.xml index 954b7ef..ad03a3f 100644 --- a/recipes/smoke/lib/recipe-temp.xml +++ b/recipes/smoke/lib/recipe-temp.xml @@ -1,17 +1,17 @@ -<lnstrecipe> +<lnstrecipe xmlns:xi="http://www.w3.org/2003/XInclude"> <machines> <machine id="1"> <define> <alias name="testip" value="192.168.100.240/24"/> </define> - <interfaces source="#CONF1#"/> + #CONF1# </machine> <machine id="2"> <define> <alias name="testip" value="192.168.100.215/24"/> </define> - <interfaces source="#CONF2#"/> + #CONF2# </machine> </machines> #SEQUENCES# -</lnstrecipe> \ No newline at end of file +</lnstrecipe>
lnst-developers@lists.fedorahosted.org