On 2013-2-25 16:49, Alex Jia wrote:
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.
This test case means that,there's two host,local host and remote
host.The local host has a guest
to test, and the remote host perhaps has a guest or not, it doesn't
matter. The test runs on the
local host, when you use the virsh.$commands() with remote URI, if
there's no guest in the remote
host, the test will fail..So first I log into the remote host, then on
the remote host I can use
virsh command freely with "-c uri" to test the guest which on the local
host..
I think it's convenient to test....
BTW, Chris has made a new class named "VirshConnectBack" for this kind
of test. I tested it and
it runs smoothly, but it has not been pushed to next...:-( ..I'm waiting
for it..I will modify the
test in version 2.
+ 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
--
Regards,
--------------------------------------------------
Li Yang
No. 6 Wenzhu Road, Nanjing, 210012, China
TEL:+86+25-86630566-8526
FUJITSU INTERNAL:7998-8526
FAX:+86+25-83317685
EMail:[email protected]
--------------------------------------------------
This communication is for use by the intended recipient(s) only and may contain
information that is privileged, confidential and exempt from disclosure under
applicable law. If you are not an intended recipient of this communication, you
are hereby notified that any dissemination, distribution or copying hereof is
strictly prohibited. If you have received this communication in error, please
notify me by reply e-mail, permanently delete this communication from your
system, and destroy any hard copies you may have printed
_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel