Signed-off-by: Li Yang <[email protected]>
---
libvirt/tests/virsh_net_uuid.py | 44 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
 create mode 100644 libvirt/tests/virsh_net_uuid.py

diff --git a/libvirt/tests/virsh_net_uuid.py b/libvirt/tests/virsh_net_uuid.py
new file mode 100644
index 0000000..0509846
--- /dev/null
+++ b/libvirt/tests/virsh_net_uuid.py
@@ -0,0 +1,44 @@
+import os, logging
+from autotest.client.shared import error
+from virttest import virsh, libvirt_xml
+
+def run_virsh_net_uuid(test, params, env):
+    """
+    Test command: virsh net-uuid.
+
+    The command can convert a network name to network UUID.
+    1.Get all parameters from config file.
+    2.Get uuid by network name from network xml.
+    3.Perform virsh net-uuid operation.
+    4.Confirm the test result.`
+    """
+    net_ref = params.get("net_uuid_net_ref")
+    net_name = params.get("net_uuid_network", "default")
+    extra = params.get("net_uuid_extra", "")
+    status_error = params.get("status_error", "no")
+    net_uuid = libvirt_xml.NetworkXML.get_uuid_by_name(net_name)
+
+    if net_ref == "name":
+        net_ref = net_name
+
+    result = virsh.net_uuid(net_ref, extra, ignore_status=True)
+    status = result.exit_status
+    output = result.stdout.strip()
+    err = result.stderr.strip()
+
+    #check status_error
+    if status_error == "yes":
+        if status == 0 or err == "":
+            raise error.TestFail("Run successfully with wrong command!")
+        else:
+            logging.info("It's an expected error")
+    elif status_error == "no":
+        if status != 0 or output == "":
+            raise error.TestFail("Run failed with right command!")
+        elif output != net_uuid.strip():
+            raise error.TestFail("net-uuid cannot match!")
+        else:
+            logging.info("Normal test passed")
+    else:
+        raise error.TestFail("The status_error must be 'yes' or 'no'!")
+
--
1.7.1

--
Regards,
--------------------------------------------------
Li Yang
TEL:+86+25-86630566-8526
EMail:[email protected]
--------------------------------------------------



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

Reply via email to