From: guyanhua <[email protected]>
This patch adds three test cases for "virsh hostname" command.
Use three cases:(1) virsh hostname
(2) virsh hostname with an unexpected option
(3) virsh hostname with libvirtd service stop
Signed-off-by: Gu Yanhua <[email protected]>
---
client/tests/libvirt/tests/virsh_hostname.py | 50 ++++++++++++++++++++++++++
client/virt/subtests.cfg.sample | 17 +++++++++
2 files changed, 67 insertions(+), 0 deletions(-)
create mode 100644 client/tests/libvirt/tests/virsh_hostname.py
diff --git a/client/tests/libvirt/tests/virsh_hostname.py
b/client/tests/libvirt/tests/virsh_hostname.py
new file mode 100644
index 0000000..d22a725
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_hostname.py
@@ -0,0 +1,50 @@
+import logging
+from autotest_lib.client.common_lib import utils, error
+from autotest_lib.client.virt import libvirt_vm
+
+def run_virsh_hostname(test, params, env):
+ """
+ Test the command virsh hostname
+
+ (1) Call virsh hostname
+ (2) Call virsh hostname with an unexpected option
+ (3) Call virsh hostname with libvirtd service stop
+ """
+ def virsh_hostname(option):
+ cmd = "virsh hostname %s" % option
+ cmd_result = utils.run(cmd, ignore_status=True)
+ logging.debug("Output: %s", cmd_result.stdout.strip())
+ logging.debug("Error: %s", cmd_result.stderr.strip())
+ logging.debug("Status: %d", cmd_result.exit_status)
+ return cmd_result.exit_status, cmd_result.stdout.strip()
+
+ hostname_result = utils.run("hostname", ignore_status=True)
+ hostname = hostname_result.stdout.strip()
+
+ # Prepare libvirtd service
+ check_libvirtd = params.has_key("libvirtd")
+ if check_libvirtd:
+ libvirtd = params.get("libvirtd")
+ if libvirtd == "off":
+ libvirt_vm.libvirtd_stop()
+
+ # Run test case
+ option = params.get("options")
+ status, hostname_test = virsh_hostname(option)
+
+ # Recover libvirtd service start
+ if libvirtd == "off":
+ libvirt_vm.libvirtd_start()
+
+ # Check status_error
+ status_error = params.get("status_error")
+ if status_error == "yes":
+ if status == 0:
+ raise error.TestFail("Command 'virsh hostname %s' succeeded "
+ "(incorrect command)" % option)
+ elif status_error == "no":
+ if cmp(hostname, hostname_test) != 0:
+ raise error.TestFail("Virsh cmd gives wrong hostname.")
+ if status != 0:
+ raise error.TestFail("Command 'virsh hostname %s' failed "
+ "(correct command)" % option)
diff --git a/client/virt/subtests.cfg.sample b/client/virt/subtests.cfg.sample
index ba8cd7c..cca9d43 100644
--- a/client/virt/subtests.cfg.sample
+++ b/client/virt/subtests.cfg.sample
@@ -178,6 +178,23 @@ variants:
status_error = "yes"
libvirtd = "off"
+ - virsh_hostname: install setup image_copy unattended_install.cdrom
+ type = virsh_hostname
+ vms = ''
+ variants:
+ - no_option:
+ options = ""
+ status_error = "no"
+ libvirtd = "on"
+ - unexpect_option:
+ options = " xyz"
+ status_error = "yes"
+ libvirtd = "on"
+ - with_libvirtd_stop:
+ options = ""
+ status_error = "yes"
+ libvirtd = "off"
+
- module_probe:
type = module_probe
--
1.7.7.6
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest