[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/2] Tests : Make nwfilter testcases robust against optional locking flags.



Commit dc33e6e4a5a5d42 introduces iptables/ebtables to adding locking
flags if/when these are available. However, the nwfilter testcases
list outputs without taking into account whether locking flags have been passed.

This shows up false testcase failures such as :
 2) ebiptablesTearOldRules                                            ...
Offset 1035
Expect [t nat -D PREROUTING -i vnet0 -j libvirt-I-vnet0
ebtables -t nat -D POSTROUTING -o vnet0 -j libvirt-O-vnet0
ebtables -t nat -L libvirt-I-vnet0
ebtables -t nat -L libvirt-O-vnet0
...snip...]
Actual [-concurrent -t nat -D PREROUTING -i vnet0 -j libvirt-I-vnet0
ebtables --concurrent -t nat -D POSTROUTING -o vnet0 -j libvirt-O-vnet0
ebtables --concurrent -t nat -L libvirt-I-vnet0
ebtables --concurrent -t nat -L libvirt-O-vnet0
...snip...]

This scrubs all reference to locking flags from test results buffer,
so that achieved output matches the expected results.

Signed-off-by: Prerna Saxena <prerna linux vnet ibm com>
---
 tests/nwfilterebiptablestest.c   |  7 +++++
 tests/nwfilterxml2firewalltest.c |  3 ++
 tests/testutils.c                | 62 ++++++++++++++++++++++++++++++++++++++++
 tests/testutils.h                |  6 ++++
 4 files changed, 78 insertions(+)

diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c
index f62e046..8bf7d53 100644
--- a/tests/nwfilterebiptablestest.c
+++ b/tests/nwfilterebiptablestest.c
@@ -112,6 +112,7 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
@@ -183,6 +184,7 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
@@ -232,6 +234,7 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
@@ -266,6 +269,7 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
@@ -338,6 +342,7 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
@@ -428,6 +433,7 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
@@ -501,6 +507,7 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque ATTRIBUTE_UNUSED)
         goto cleanup;
 
     actual = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actual, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actual);
 
     if (STRNEQ_NULLABLE(expected, actual)) {
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index 01527f4..b8c895c 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -402,6 +402,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
         goto cleanup;
 
     actualargv = virBufferContentAndReset(&buf);
+    virtTestClearLockingArgs(actualargv, VIR_TEST_IPTABLES);
+    virtTestClearLockingArgs(actualargv, VIR_TEST_IP6TABLES);
+    virtTestClearLockingArgs(actualargv, VIR_TEST_EBTABLES);
     virtTestClearCommandPath(actualargv);
     virCommandSetDryRun(NULL, NULL, NULL);
 
diff --git a/tests/testutils.c b/tests/testutils.c
index 9a79f98..fbb41b6 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -930,6 +930,68 @@ void virtTestClearCommandPath(char *cmdset)
     cmdset[offset] = '\0';
 }
 
+/*
+ * Scrub all reference to arguments that allow iptables to be locked.
+ * This is a newer iptables change that is unavailable with older distros.
+ * For seamless comparison of test results between 'expected' &'actual' values,
+ * it makes sense to *not* compare :
+ * EXPECTED : /path/to/ebtables -ARG1 -ARG2 -ARG3
+ * vs
+ * ACTUAL : /path/to/iptables --LOCKFLAG -ARG1 -ARG2 -ARG3
+ */
+void virtTestClearLockingArgs(char *cmdset, virTestNwFilter filter)
+{
+    const char *iptables_str = "iptables -w";
+    const char *ip6tables_str = "ip6tables -w";
+    const char *ebtables_str = "ebtables --concurrent";
+
+    char *lineStart = cmdset;
+    char *lineEnd = strchr(cmdset, '\n');
+    char *filter_str = NULL, *next;
+    size_t filterArgLen, movelen;
+    char *movedest, *movestart;
+
+    switch (filter) {
+        case VIR_TEST_IPTABLES:
+            if (VIR_STRDUP(filter_str, iptables_str) < 0)
+                goto error;
+            break;
+        case VIR_TEST_IP6TABLES:
+            if (VIR_STRDUP(filter_str, ip6tables_str) < 0)
+                goto error;
+            break;
+        case VIR_TEST_EBTABLES:
+            if (VIR_STRDUP(filter_str, ebtables_str) < 0)
+                goto error;
+            break;
+        default:
+            goto error;
+    }
+
+    /*
+     * Replace all references of filter_str with just the base command
+     * Eg, 'iptables -w' is replaced with 'iptables'
+     */
+    next = strchr(filter_str, ' ');
+    filterArgLen = strlen(next+1);
+
+    while (lineStart) {
+        next = strstr(lineStart, filter_str);
+        if (next) {
+            movedest = strchr(next, ' ');
+            movestart = movedest + filterArgLen + 1;
+            movelen = strlen(movestart);
+            memmove(movedest, movestart, movelen + 1);
+          }
+
+        lineEnd = strchr(lineStart, '\n');
+        lineStart = lineEnd ? lineEnd + 1 : NULL;
+    }
+
+    VIR_FREE(filter_str);
+ error:
+    return;
+}
 
 virCapsPtr virTestGenericCapsInit(void)
 {
diff --git a/tests/testutils.h b/tests/testutils.h
index d78818d..6a0a00f 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -40,6 +40,11 @@
 # endif
 
 extern char *progname;
+typedef enum {
+    VIR_TEST_IPTABLES,
+    VIR_TEST_IP6TABLES,
+    VIR_TEST_EBTABLES
+} virTestNwFilter;
 
 /* Makefile.am provides these two definitions */
 # if !defined(abs_srcdir) || !defined(abs_builddir)
@@ -60,6 +65,7 @@ int virtTestClearLineRegex(const char *pattern,
                            char *string);
 
 void virtTestClearCommandPath(char *cmdset);
+void virtTestClearLockingArgs(char *cmdset, virTestNwFilter filter);
 
 int virtTestDifference(FILE *stream,
                        const char *expect,
-- 
1.9.3

-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]