Signed-off-by: Li Yang <[email protected]>
---
libvirt/tests/virsh_net_dumpxml.py | 64
++++++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
create mode 100644 libvirt/tests/virsh_net_dumpxml.py
diff --git a/libvirt/tests/virsh_net_dumpxml.py
b/libvirt/tests/virsh_net_dumpxml.py
new file mode 100644
index 0000000..bb48574
--- /dev/null
+++ b/libvirt/tests/virsh_net_dumpxml.py
@@ -0,0 +1,64 @@
+from autotest.client.shared import error
+from virttest import virsh
+
+def run_virsh_net_dumpxml(test, params, env):
+ """
+ Test command: virsh net-dumpxml.
+ 1.Get all parameters from config file.
+ 2.If test case's network status is inactive, destroy it.
+ 3.Perform virsh net-dumpxml operation.
+ 4.Recover test environment(network status).
+ 5.Confirm the test result.
+
+ """
+ status_error = params.get("status_error", "no")
+ vm_ref = params.get("net_dumpxml_vm_ref")
+ net_name = params.get("net_dumpxml_network", "default")
+ net_status = params.get("net_dumpxml_network_status", "active")
+ extra = params.get("net_dumpxml_extra", "")
+
+ #run test case
+ if vm_ref == "uuid":
+ vm_ref = virsh.net_uuid(net_name).stdout.strip()
+ elif vm_ref == "name":
+ vm_ref = net_name
+
+ net_status_current = "active"
+ if virsh.net_list("--inactive"):
+ net_status_current = "inactive"
+
+ if not virsh.net_state_dict()[net_name]['persistent']:
+ raise error.TestFail("Network is transient!")
+
+ if net_status == "inactive" and net_status_current == "active":
+ s = virsh.net_destroy(net_name, ignore_status=True).exit_status
+ if s != 0:
+ raise error.TestFail("Network destroied failed!")
+
+ result = virsh.net_dumpxml(vm_ref, extra, ignore_status=True)
+ status = result.exit_status
+ output = result.stdout.strip()
+ err = result.stderr.strip()
+ if extra.find("--") != -1:
+ options = extra.split("--")
+ for option in options:
+ if option.strip() == "":
+ continue
+ if not virsh.has_command_help_match("net-dumpxml",
option.strip()):
+ status_error = "yes"
+ break
+
+ if net_status == "inactive" and net_status_current == "active":
+ s = virsh.net_start(net_name, ignore_status=True).exit_status
+ if s != 0:
+ raise error.TestFail("Network started failed!")
+
+ #check status_error
+ if status_error == "yes":
+ if status == 0 or err == "":
+ raise error.TestFail("Run successfully with wrong command!")
+ elif status_error == "no":
+ if status != 0 or output == "":
+ raise error.TestFail("Run failed with right command")
+ 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