Signed-off-by: Li Yang <[email protected]>
---
libvirt/tests/cfg/virsh_net_dumpxml.cfg | 34 ++++++++++++++++
libvirt/tests/virsh_net_dumpxml.py | 67
+++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 0 deletions(-)
create mode 100644 libvirt/tests/cfg/virsh_net_dumpxml.cfg
create mode 100644 libvirt/tests/virsh_net_dumpxml.py
diff --git a/libvirt/tests/cfg/virsh_net_dumpxml.cfg
b/libvirt/tests/cfg/virsh_net_dumpxml.cfg
new file mode 100644
index 0000000..76c4a06
--- /dev/null
+++ b/libvirt/tests/cfg/virsh_net_dumpxml.cfg
@@ -0,0 +1,34 @@
+- virsh_net_dumpxml:
+ type = virsh_net_dumpxml
+ vms = ""
+ main_vm = ""
+ kill_vm = "no"
+ kill_unresponsive_vms = "no"
+ encode_video_files = "no"
+ skip_image_processing = "yes"
+ take_regular_screendumps = "no"
+ net_dumpxml_network = "default"
+ net_dumpxml_net_ref = "name"
+ net_dumpxml_extra = ""
+ net_dumpxml_network_status = "active"
+ variants:
+ - normal_test:
+ status_error = "no"
+ variants:
+ - name_option:
+ - uuid_option:
+ net_dumpxml_net_ref = "uuid"
+ - inactive_option:
+ net_dumpxml_network_status = "inactive"
+ net_dumpxml_extra = "--inactive"
+ - error_test:
+ status_error = "yes"
+ variants:
+ - no_option:
+ net_dumpxml_net_ref = ""
+ - no_exist_option:
+ net_dumpxml_net_ref = "xyz"
+ - extra_option:
+ net_dumpxml_extra = "xyz"
+ - extra_args_option:
+ net_dumpxml_extra = "--xyz"
diff --git a/libvirt/tests/virsh_net_dumpxml.py
b/libvirt/tests/virsh_net_dumpxml.py
new file mode 100644
index 0000000..9067eac
--- /dev/null
+++ b/libvirt/tests/virsh_net_dumpxml.py
@@ -0,0 +1,67 @@
+from autotest.client.shared import error
+from virttest import virsh
+
+def run_virsh_net_dumpxml(test, params, env):
+ """
+ Test command: virsh net-dumpxml.
+
+ This command can output the network information as an XML dump to
stdout.
+ 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")
+ net_ref = params.get("net_dumpxml_net_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 net_ref == "uuid":
+ net_ref = virsh.net_uuid(net_name).stdout.strip()
+ elif net_ref == "name":
+ net_ref = net_name
+
+ net_status_current = "active"
+ if not virsh.net_state_dict()[net_name]['active']:
+ 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(net_ref, extra, ignore_status=True)
+ status = result.exit_status
+ output = result.stdout.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
+
+ # Recover network
+ 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:
+ raise error.TestFail("Run successfully with wrong command!")
+ elif status_error == "no":
+ if status != 0:
+ raise error.TestFail("Run failed with right command")
+ if output == "":
+ raise error.TestFail("The command has no detail outputed!")
+ 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