On 04/01/2013 06:12 PM, liyang wrote:
Signed-off-by: Li Yang <[email protected]>
---
libvirt/tests/virsh_cpu_compare.py | 72 ++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 libvirt/tests/virsh_cpu_compare.py

diff --git a/libvirt/tests/virsh_cpu_compare.py b/libvirt/tests/virsh_cpu_compare.py
new file mode 100644
index 0000000..5d96133
--- /dev/null
+++ b/libvirt/tests/virsh_cpu_compare.py
@@ -0,0 +1,72 @@
+import commands, codecs, os
+from autotest.client.shared import error
+from virttest import virsh
+from xml.dom.minidom import parseString
+
+
+def run_virsh_cpu_compare(test, params, env):
+    """
+    Test command: virsh cpu-compare.
+
+    Compare host CPU with a CPU described by an XML file.
+    1.Get all parameters from configuration.
+    2.Prepare temp file saves  CPU infomation.
+    3.Perform virsh net-compare operation.

s/net-compare/cpu-compare/.

+    4.Confirm the result.
+
+    """
+
+    def get_cpu_xml(mode, tmp_file):
+        """
+        Get CPU infomation and put it into a file.
+
+        @param: mode: Test mode, decides file's detail.
+        @param: tmp_file: File saves CPU infomation.
+        """
+        file = codecs.open(tmp_file, 'wb', encoding='utf-8')
+        domxml = virsh.capabilities()

'virsh capabilities' output just include host CPU XML element, you should also cover guest CPU definition, please refer to http://libvirt.org/formatdomain.html#elementsCPU

+        dom = parseString(domxml)
+        cpu_node = dom.getElementsByTagName('cpu')[0]
+        if mode == "modify":
+            vendor = cpu_node.getElementsByTagName('vendor')[0]
+            for node in vendor.childNodes:
+                if node.nodeType == node.TEXT_NODE:
+                    vendor.removeChild(node)
+                    break
+            text_node = dom.createTextNode('test_vendor')
+            vendor.appendChild(text_node)
+            cpu_node.writexml(file)
+        elif mode == "clear":
+            # Clear up file detail
+            file.truncate(0)
+        else:
+            cpu_node.writexml(file)
+        file.close()
+        dom.unlink()
+
+
+    # Get all parameters.
+    ref = params.get("cpu_compare_ref")
+    mode = params.get("cpu_compare_mode", "")
+    status_error = params.get("status_error", "no")
+    extra = params.get("cpu_compare_extra", "")
+    file_name = params.get("cpu_compare_file_name", "cpu.xml")
+    tmp_file = os.path.join(test.tmpdir, file_name)
+
+    # Prepare temp file.
+    get_cpu_xml(mode, tmp_file)
+
+    if ref == "file":
+        ref = tmp_file
+    ref = "%s %s" % (ref, extra)
+
+    # Perform virsh cpu-compare operation.
+ status = virsh.cpu_compare(ref, ignore_status=True, debug=True).exit_status
+
+    # Check status_error
+    if status_error == "yes":
+        if status == 0:
+            raise error.TestFail("Run successfully with wrong command!")
+    elif status_error == "no":
+        if status != 0:
+            raise error.TestFail("Run failed with right command")
--
1.7.1


_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to