[test-API][PATCH] Add network update test case

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

 



The patch add network update test case to cover network update api.
modified: cases/basic_network.conf
- The test suite covers add/modify/delete ip-dhcp-host in network. For other test
scenario, they can be test via customing the conf file.
new file: repos/network/update.py
- So far the network update test case only checking when flag is live or current.
new file: repos/network/xmls/ip-dhcp-host.xml
- Create the ip-dhcp-host sample xml file for adding/deleting ip-dhcp-host
new file: repos/network/xmls/modify-ip-dhcp-host.xml
- Create the ip-dhcp-host sample xml file for modifying ip-dhcp-host
Known bug:
- Bug 985782 - Some flag values of method are missing in libvirt-python bindings
---
 cases/basic_network.conf                   |   28 ++++++++++
 repos/network/update.py                    |   82 ++++++++++++++++++++++++++++
 repos/network/xmls/ip-dhcp-host.xml        |    1 +
 repos/network/xmls/modify-ip-dhcp-host.xml |    1 +
 4 files changed, 112 insertions(+), 0 deletions(-)
 create mode 100644 repos/network/update.py
 create mode 100644 repos/network/xmls/ip-dhcp-host.xml
 create mode 100644 repos/network/xmls/modify-ip-dhcp-host.xml

diff --git a/cases/basic_network.conf b/cases/basic_network.conf
index 91d7f21..e9abd57 100644
--- a/cases/basic_network.conf
+++ b/cases/basic_network.conf
@@ -32,6 +32,34 @@ network:autostart
     autostart
         enable
 
+network:update
+    networkname
+	$defaultnetname
+    command
+        add-first
+    section
+        ip-dhcp-host
+
+network:update
+    networkname
+	$defaultnetname
+    command
+        modify
+    section
+        ip-dhcp-host
+    xml
+	xmls/modify-ip-dhcp-host.xml
+
+network:update
+    networkname
+	$defaultnetname
+    command
+        delete
+    section
+        ip-dhcp-host
+    xml
+	xmls/modify-ip-dhcp-host.xml
+
 network:destroy
     networkname
         $defaultnetname
diff --git a/repos/network/update.py b/repos/network/update.py
new file mode 100644
index 0000000..0024a5e
--- /dev/null
+++ b/repos/network/update.py
@@ -0,0 +1,82 @@
+#!/usr/bin/evn python
+#Update a network
+
+import libvirt
+from libvirt import libvirtError
+from src import sharedmod
+
+COMMANDDICT = {"none":0, "modify":1, "delete":2, "add-first":4}
+SECTIONDICT = {"none":0, "bridge":1, "domain":2, "ip":3, "ip-dhcp-host":4, \
+               "ip-dhcp-range":5, "forward":6, "forward-interface":7,\
+               "forward-pf":8, "portgroup":9, "dns-host":10, "dns-txt":11,\
+               "dns-srv":12}
+FLAGSDICT = {"current":0, "live":1, "config": 2}
+
+required_params = ('networkname', )
+optional_params = {
+                   'command': 'add-first',
+                   'section': 'ip-dhcp-host',
+                   'parentIndex': 0,
+                   'xml': 'xmls/ip-dhcp-host.xml',
+                   'flag': 'current',
+                  }
+
+def update(params):
+    """Update a network from xml"""
+    global logger
+    logger = params['logger']
+    networkname = params['networkname']
+    conn = sharedmod.libvirtobj['conn']
+
+    command = params['command']
+    logger.info("The specified command is %s" % command)
+    section = params['section']
+    logger.info("The specified section is %s" % section)
+    parentIndex = int(params.get('parentIndex', 0))
+    logger.info("The specified parentIndex is %d" % parentIndex)
+    xmlstr = params.get('xml', 'xmls/ip-dhcp-host.xml').replace('\"','\'')
+    logger.info("The specified updatexml is %s" % xmlstr)
+    flag = params.get('flag', 'current')
+    logger.info("The specified flag is %s" % flag)
+
+    command_val = 0
+    section_val = 0
+    flag_val = 0
+    if COMMANDDICT.has_key(command):
+        command_val = COMMANDDICT.get(command)
+    if SECTIONDICT.has_key(section):
+        section_val = SECTIONDICT.get(section)
+    if FLAGSDICT.has_key(flag):
+        flag_val = FLAGSDICT.get(flag)
+
+    try:
+        network = conn.networkLookupByName(networkname)
+        logger.info("The original network xml is %s" % network.XMLDesc(0))
+        network.update(command_val, section_val, parentIndex, xmlstr, \
+                       flag_val)
+        updated_netxml = network.XMLDesc(0)
+        logger.info("The updated network xml is %s" % updated_netxml)
+        #The check only works when flag isn't set as config
+        if flag_val !=2:
+            if command_val == 0 or command_val == 2:
+                if xmlstr not in updated_netxml:
+                    logger.info("Successfully update network")
+                    return 0
+                else:
+                    logger.error("Failed to update network")
+                    return 1
+
+            elif command_val == 1 or command_val == 4:
+                if xmlstr in updated_netxml:
+                    logger.info("Successfully update network")
+                    return 0
+                else:
+                    logger.error("Failed to update network")
+                    return 1
+
+    except libvirtError, e:
+        logger.error("API error message: %s, error code is %s" \
+                     % (e.message, e.get_error_code()))
+        return 1
+
+    return 0
diff --git a/repos/network/xmls/ip-dhcp-host.xml b/repos/network/xmls/ip-dhcp-host.xml
new file mode 100644
index 0000000..50e7908
--- /dev/null
+++ b/repos/network/xmls/ip-dhcp-host.xml
@@ -0,0 +1 @@
+<host mac="00:16:3e:77:e2:ed" name="foo.example.com" ip="192.168.122.10" />
diff --git a/repos/network/xmls/modify-ip-dhcp-host.xml b/repos/network/xmls/modify-ip-dhcp-host.xml
new file mode 100644
index 0000000..a10e9fa
--- /dev/null
+++ b/repos/network/xmls/modify-ip-dhcp-host.xml
@@ -0,0 +1 @@
+<host mac="00:16:3e:77:e2:ed" name="beijing.redhat.com" ip="192.168.122.101" />
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]