QA: Ignore tags using regular expression
authorMichael Hanselmann <hansmi@google.com>
Wed, 6 Jun 2012 10:54:32 +0000 (12:54 +0200)
committerMichael Hanselmann <hansmi@google.com>
Thu, 7 Jun 2012 13:51:00 +0000 (15:51 +0200)
In some QA environments external scripts may add tags. With this patch a
regular expression can be used to ignore them during QA runs.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

qa/qa-sample.json
qa/qa_rapi.py

index 4034814..82f9c6c 100644 (file)
@@ -27,6 +27,9 @@
   "# Script to check instance status": null,
   "instance-check": null,
 
+  "# Regular expression to ignore existing tags": null,
+  "ignore-tags-re": null,
+
   "nodes": [
     {
       "# Master node": null,
index e265764..b53b8cf 100644 (file)
@@ -25,6 +25,8 @@
 
 import tempfile
 import random
+import re
+import itertools
 
 from ganeti import utils
 from ganeti import constants
@@ -416,6 +418,18 @@ def TestNode(node):
     ])
 
 
+def _FilterTags(seq):
+  """Removes unwanted tags from a sequence.
+
+  """
+  ignore_re = qa_config.get("ignore-tags-re", None)
+
+  if ignore_re:
+    return itertools.ifilterfalse(re.compile(ignore_re).match, seq)
+  else:
+    return seq
+
+
 def TestTags(kind, name, tags):
   """Tests .../tags resources.
 
@@ -432,7 +446,7 @@ def TestTags(kind, name, tags):
     raise errors.ProgrammerError("Unknown tag kind")
 
   def _VerifyTags(data):
-    AssertEqual(sorted(tags), sorted(data))
+    AssertEqual(sorted(tags), sorted(_FilterTags(data)))
 
   queryargs = "&".join("tag=%s" % i for i in tags)