On 02/22/2013 04:27 PM, liyang wrote:
Signed-off-by: Li Yang <[email protected]>
---
libvirt/tests/virsh_net_destroy.py | 93
++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 0 deletions(-)
create mode 100644 libvirt/tests/virsh_net_destroy.py
diff --git a/libvirt/tests/virsh_net_destroy.py
b/libvirt/tests/virsh_net_destroy.py
new file mode 100644
index 0000000..543a45b
--- /dev/null
+++ b/libvirt/tests/virsh_net_destroy.py
@@ -0,0 +1,93 @@
+import re, logging
+from autotest.client.shared import error
+from virttest import libvirt_vm, virsh, remote
+
+def run_virsh_net_destroy(test, params, env):
+ """
+ Test command: virsh net-destroy.
+
+ The command can forcefully stop a given network.
+ 1.Prepare test environment, make sure the network exists.
+ 2.If network status is inactive, start it.
+ 3.If the libvirtd == "off", stop the libvirtd service.
+ 4.Perform virsh net-destroy operation.
+ 5.Check if the network has been destroied.
+ 6.Recover test environment(network status, libvirtd).
+ 7.Confirm the test result.
+ """
+
+ libvirtd = params.get("libvirtd", "on")
+ vm_ref = params.get("net_destroy_vm_ref")
+ extra = params.get("net_destroy_extra", "")
+ network_name = params.get("net_destroy_network", "default")
+ vm_ref = params.get("net_destroy_vm_ref")
+ remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM")
+ local_ip = params.get("local_ip", "LOCAL.EXAMPLE.COM")
+ remote_pwd = params.get("remote_pwd", "")
+ status_error = params.get("status_error", "no")
+
+ # Confirm the network exists.
+ output_all = virsh.net_list("--all").stdout.strip()
+ if not re.search(network_name, output_all):
+ raise error.TestFail("Make sure the network exists!!")
+
+ #run test case
+ if vm_ref == "uuid":
+ vm_ref = virsh.net_uuid(network_name).stdout.strip()
+ elif vm_ref == "name":
+ vm_ref = network_name
+
+ # Get status of network.
+ network_status = "active"
+ output_inactive = virsh.net_list("--inactive").stdout.strip()
+ if re.search(network_name, output_inactive):
+ network_status = "inactive"
+ virsh.net_start(network_name)
+
+ if libvirtd == "off":
+ libvirt_vm.libvirtd_stop()
+
+ if vm_ref != "remote":
+ status = virsh.net_destroy(vm_ref, extra,
+ ignore_status=True).exit_status
+ else:
+ try:
+ status = 0
+ if remote_ip.count("EXAMPLE.COM") or
local_ip.count("EXAMPLE.COM"):
+ logging.info("remote_ip and/or local_ip parameters not"
+ " changed from default values.")
+ status = 1
+ if status == 0:
+ uri = libvirt_vm.complete_uri(local_ip)
+ session = remote.remote_login("ssh", remote_ip, "22",
"root",
+ remote_pwd, "#")
+ session.cmd_output('LANG=C')
+ command = "virsh -c %s net-destroy %s" % (uri,
network_name)
As I said before, the virsh.$commands() should support remote URI then
you just need to
pass a remote URI to virsh.$commands() to do a remote testing, if so,
you will also avoid
mixing virsh.$commands() and virsh commands usage.
+ status, output = session.cmd_status_output(command,
+
internal_timeout=5)
+ session.close()
+ except error.CmdError:
+ status = 1
+
+ # Confirm the network has been destroied.
+ output = virsh.net_list("--inactive").stdout.strip()
+ if not re.search(network_name, output):
+ status = 1
+
+ # recover libvirtd service start
+ if libvirtd == "off":
+ libvirt_vm.libvirtd_start()
+
+ # recover network status
+ if network_status == "active":
+ output = virsh.net_list("--inactive").stdout.strip()
+ if not re.search(network_name, output):
+ virsh.net_start(network_name)
+
+ # 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