[netcf-devel] [PATCH 5/5] tests: check define/undefine cycle

David Lutterkort lutter at redhat.com
Thu Jul 9 22:58:15 UTC 2009


Make sure that defining and immediately undefining an interface actually
does remove the interface. This does not work because of a bug in Augeas
(https://fedorahosted.org/augeas/ticket/78)

The bug shouldn't affect us though, since we should reload Augeas on every
call through the public API to make sure we pick up changes to the
filesystem that happened in between calls.

  * tests/test-initscripts.c (testDefineUndefine): new test
  * tests/interface/bridge42.xml: interface for test
---
 tests/interface/bridge42.xml |    7 +++++++
 tests/test-initscripts.c     |   29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 tests/interface/bridge42.xml

diff --git a/tests/interface/bridge42.xml b/tests/interface/bridge42.xml
new file mode 100644
index 0000000..0035762
--- /dev/null
+++ b/tests/interface/bridge42.xml
@@ -0,0 +1,7 @@
+<interface type="bridge" name="br42">
+  <start mode="onboot"/>
+  <mtu size="1500"/>
+  <bridge stp="off">
+    <interface type="ethernet" name="eth42"/>
+  </bridge>
+</interface>
diff --git a/tests/test-initscripts.c b/tests/test-initscripts.c
index 39241c8..3a45231 100644
--- a/tests/test-initscripts.c
+++ b/tests/test-initscripts.c
@@ -66,6 +66,10 @@ static char *read_test_file(CuTest *tc, const char *relpath) {
     return txt;
 }
 
+static void assert_ncf_no_error(CuTest *tc) {
+    CuAssertIntEquals(tc, NETCF_NOERROR, ncf_error(ncf, NULL, NULL));
+}
+
 static xmlDocPtr parse_xml(const char *xml_str) {
     xmlParserCtxtPtr pctxt;
     xmlDocPtr xml = NULL;
@@ -259,6 +263,30 @@ static void testLookupByMAC(CuTest *tc) {
     CuAssertIntEquals(tc, 1, ncf->ref);
 }
 
+static void testDefineUndefine(CuTest *tc) {
+    char *bridge_xml = NULL;
+    struct netcf_if *nif = NULL;
+    int r;
+
+    bridge_xml = read_test_file(tc, "interface/bridge42.xml");
+    CuAssertPtrNotNull(tc, bridge_xml);
+
+    nif = ncf_define(ncf, bridge_xml);
+    CuAssertPtrNotNull(tc, nif);
+    assert_ncf_no_error(tc);
+
+    r = ncf_if_undefine(nif);
+    CuAssertIntEquals(tc, 0, r);
+    assert_ncf_no_error(tc);
+
+    ncf_close(ncf);
+    r = ncf_init(&ncf, root);
+    CuAssertIntEquals(tc, 0, r);
+
+    nif = ncf_lookup_by_name(ncf, "br42");
+    CuAssertPtrEquals(tc, NULL, nif);
+}
+
 static void assert_transforms(CuTest *tc, const char *base) {
     char *aug_fname = NULL, *ncf_fname = NULL;
     char *aug_xml_exp = NULL, *ncf_xml_exp = NULL;
@@ -319,6 +347,7 @@ int main(void) {
     SUITE_ADD_TEST(suite, testListInterfaces);
     SUITE_ADD_TEST(suite, testLookupByName);
     SUITE_ADD_TEST(suite, testLookupByMAC);
+    SUITE_ADD_TEST(suite, testDefineUndefine);
     SUITE_ADD_TEST(suite, testTransforms);
 
     CuSuiteRun(suite);
-- 
1.6.0.6



More information about the netcf-devel mailing list