Signed-off-by: Yu Mingfei<[email protected]>
---
 client/tests/libvirt/tests/virsh_net_create.py |   73 ++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/libvirt/tests/virsh_net_create.py

diff --git a/client/tests/libvirt/tests/virsh_net_create.py 
b/client/tests/libvirt/tests/virsh_net_create.py
new file mode 100644
index 0000000..e00ae72
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_net_create.py
@@ -0,0 +1,73 @@
+import re, logging, tempfile
+from autotest.client.shared import utils, error
+from autotest.client.virt import libvirt_vm, libvirt_xml
+
+
+def run_virsh_net_create(test, params, env):
+    """
+    Test command: virsh net-create.
+
+    1) Create a new network's config file from a source file.
+    2) Check current network environment for new network.
+    3) Stop libvirtd if test need.
+    4) Run test.
+    5) Recover libvirtd and network if test need.
+    6) Check result.
+    """
+    #Create network's xml file
+    source_file = params.get("source_file", 
"/etc/libvirt/qemu/networks/default.xml")
+    net_name = params.get("net_name", "default")
+    net_uuid = params.get("net_uuid", "")
+
+    new_net_xml = tempfile.mktemp(dir="/tmp")
+
+    network_xml = libvirt_xml.NetworkXML(source_file)
+    network_xml.general_metadata_config(net_name, net_uuid)
+    #TODO:other configuration
+    network_xml.write(new_net_xml)
+
+    #Prepare network environment
+    list_output = libvirt_vm.virsh_net_list("", print_info=True).stdout.strip()
+    if re.search(net_name, list_output):
+        libvirt_vm.virsh_net_destroy(net_name, print_info=True)
+
+    #Prepare libvirtd status
+    libvirtd = params.get("libvirtd", "on")
+    if libvirtd == "off":
+        libvirt_vm.service_libvirtd_control("stop")
+
+    #Run test case
+    options_ref = params.get("options_ref", "default")
+    extra = params.get("extra", "")
+    if options_ref == "exist_file":
+        options_ref = new_net_xml + extra
+
+    result = libvirt_vm.virsh_net_create(options_ref, extra, 
ignore_status=True, print_info=True)
+    status = result.exit_status
+    output = result.stdout.strip()
+
+    #Recover libvirtd service start
+    if libvirtd == "off":
+        libvirt_vm.service_libvirtd_control("start")
+
+    #Recover network
+    list_output = libvirt_vm.virsh_net_list("", print_info=True).stdout.strip()
+    if re.search(net_name, list_output) and net_name != "default":
+        libvirt_vm.virsh_net_destroy(net_name, print_info=True)
+
+    list_output = libvirt_vm.virsh_net_list("", print_info=True).stdout.strip()
+    if not re.search("default", list_output):
+        libvirt_vm.virsh_net_create(source_file, print_info=True)
+
+    #Check Result
+    status_error = params.get("status_error", "no")
+    addition_status_error = params.get("addition_status_error", "no")
+    status_error = (status_error == "no") and (addition_status_error == "no")
+    if not status_error:
+        if status == 0:
+            raise error.TestFail("Run successful with wrong command!")
+    else:
+        if status != 0:
+            raise error.TestFail("Run failed with right command.")
+        if not re.search(net_name, output):
+            raise error.TestFail("Run successful but result is not expected.")
-- 1.7.1

--
Best Regards
Yu Mingfei

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to