commit 0f3920c216a7f6d7dcfd2dc5ed6fc84a8ea7ed8e
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Wed Jun 5 13:24:19 2013 +0200
add generate-recipes.py
This commit adds a python version of the generate-recipes.sh script made
by Radek. I made this because I wanted to add a feature to the recipe
generation which required xml manipulation.
The new script will create a recipe for every combination of two
machines, similarily to how the original script did. After that it will
parse the recipe xml and expand the sourced tags. Then it will do a
final round of variable replacement. The resulting xml is written to the
recipe file.
The added feature is the second round of variable replacement. These
variables are dynamically loaded from the file variables.conf also added
in this patch. This file can define aditional variables in the section
defaults and then in sections named after the combinations of
configuration files (e.g. bond-bond or vlan-bond). This allows us to
define a slightly different behaviour of command sequences for different
configurations. At the moment the only defined variable is 'icmp_result'
which I use to indicate that the IcmpPing test should fail for
configurations of vlan-<non-vlan>.
To use a defined variable in the recipe fragments write this: #var_name#
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
recipes/smoke/generate-recipes.py | 143 +++++++++++++++++++++++++++++++++++++
recipes/smoke/lib/variables.conf | 14 ++++
2 files changed, 157 insertions(+), 0 deletions(-)
---
diff --git a/recipes/smoke/generate-recipes.py b/recipes/smoke/generate-recipes.py
new file mode 100755
index 0000000..e81d265
--- /dev/null
+++ b/recipes/smoke/generate-recipes.py
@@ -0,0 +1,143 @@
+#! /usr/bin/env python
+
+# LNST Smoke Tests
+# Author: Ondrej Lichtner <olichtne(a)redhat.com>
+# License: GNU GPLv2
+# Based on generate-recipes.sh from Radek Pazdera <rpazdera(a)redhat.com>
+
+# This script will generate a set of recipes for assessing the very basic
+# functionality of LNST.
+
+import os
+import shutil
+import re
+import ConfigParser
+import xml.dom.minidom
+
+def print_test_usage():
+ print ""
+
+ print "To run these recipes, you need to have a pool prepared with at"
+ print "least two machines. Both of them must have at least two test"
+ print "interfaces connected to the same network segment."
+
+ print ""
+
+ print " +-----------+ +--------+ +-----------+"
+ print " | |----------| |----------| |"
+ print " | Machine | | Switch | | Machine |"
+ print " | 1 |----------| |----------| 2 |"
+ print " | | +--------+ | |"
+ print " +-----------+ +-----------+"
+
+ print "\nYou can execute the set using the following command:"
+ print " ./lnst-ctl -d recipes/smoke/tests/ run"
+
+def replace_variables(recipe, name1, name2, variables):
+ vars = dict(variables.items("defaults"))
+
+ if variables.has_section("%s-%s" % (name1, name2)):
+ section = variables.items("%s-%s" % (name1, name2))
+ for name, val in section:
+ vars[name] = val
+
+ for name, val in vars.iteritems():
+ 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/"
+ vars_filename = "%svariables.conf" % LIB
+
+ print "[LNST Smoke Tests]"
+ print "Creating '%s' directory for the recipes..." % DIR,
+ shutil.rmtree(DIR, ignore_errors=True)
+ os.mkdir(DIR)
+ os.chdir(DIR)
+ print "[DONE]"
+
+ sequences = ""
+ for seq in os.listdir(LIB):
+ if not re.match("seq-.*", seq):
+ continue
+ print "Found command sequence %s%s" % (LIB, seq)
+ sequences += "\n <command_sequence
source=\"%s%s\"/>" % (LIB, seq)
+
+ conf_files = [LIB+i for i in os.listdir(LIB) if re.match("conf-.*", i)]
+ for conf in conf_files:
+ print "Found configuration %s" % conf
+
+ template_file = open("%s/recipe-temp.xml" % LIB, 'r')
+ template = template_file.read()
+
+ variables = ConfigParser.ConfigParser()
+ variables.read(vars_filename)
+
+ for machine1 in conf_files:
+ for machine2 in conf_files:
+ name1 = re.match(".*conf-(.*)\.xml", machine1).group(1)
+ name2 = re.match(".*conf-(.*)\.xml", machine2).group(1)
+ 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)
+
+ recipe = expand_sources(recipe)
+
+ recipe = replace_variables(recipe, name1, name2, variables)
+
+ recipe_file = open("%s" % recipe_name, 'w')
+ recipe_file.write(recipe)
+ recipe_file.close()
+
+ print "[DONE]"
+
+ print_test_usage()
+
+if __name__ == "__main__":
+ main()
diff --git a/recipes/smoke/lib/variables.conf b/recipes/smoke/lib/variables.conf
new file mode 100644
index 0000000..a0ad9f9
--- /dev/null
+++ b/recipes/smoke/lib/variables.conf
@@ -0,0 +1,14 @@
+[defaults]
+icmp_result = true
+[bond-vlan]
+icmp_result=false
+[team-vlan]
+icmp_result=false
+[eth-vlan]
+icmp_result=false
+[vlan-bond]
+icmp_result=false
+[vlan-team]
+icmp_result=false
+[vlan-eth]
+icmp_result=false
Show replies by date