[libvirt] [test-API PATCH 3/3] repo: Add test for console input and output operations
Guannan Ren
gren at redhat.com
Wed Apr 4 06:54:00 UTC 2012
On 04/03/2012 09:20 PM, Peter Krempa wrote:
> This test checks if the console input and output work as desired. The
> test takes as an argument a string, that is sent to the console and
> another string that is expected to be read from the console. When those
> two compare successfuly the test succeeds.
> ---
> repos/domain/console_io.py | 76 ++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 76 insertions(+), 0 deletions(-)
> create mode 100644 repos/domain/console_io.py
>
> diff --git a/repos/domain/console_io.py b/repos/domain/console_io.py
> new file mode 100644
> index 0000000..6af206a
> --- /dev/null
> +++ b/repos/domain/console_io.py
> @@ -0,0 +1,76 @@
> +#!/usr/bin/env python
> +""" A test case to test console mutual exclusivity
> + mandatory arguments: guestname
> + device
> + data
> + expect
> +"""
> +import libvirt
> +from libvirt import libvirtError
> +
> +from utils.Python import utils
> +from utils.Python.testError import TestError
It'd better to raise 'TestError' exception from framework
because of
unexpected environment error, or something common for all of
tests.
> +
> +def usage(params):
> + """Verify parameter dictionary"""
> + logger = params['logger']
> + keys = ['guestname', 'device', 'data', 'expect']
> + for key in keys:
> + if key not in params:
> + logger.error("%s is required" %key)
> + return 1
> +
> +def console_io(params):
> + """Attach to console"""
call usage() here to check for mandatory options and values.
> + logger = params['logger']
> + guest = params['guestname']
> + device = params['device']
> + data = params['data']
> + expect = params['expect']
> +
> + util = utils.Utils()
> + uri = params['uri']
> + reply = ""
> +
> + ret = 1
> +
> + try:
> + logger.info("Connecting to hypervisor: " + uri)
> + conn = libvirt.open(uri)
> + dom = conn.lookupByName(guest)
> +
> + logger.info("Creating stream object")
> + stream = conn.newStream(0)
> +
> + logger.info("Forcibly open console on domain")
> + dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE);
the semicolon and the following are optional.
> +
> + logger.info("Sending data: '" + data + "'")
> + stream.send(data)
> +
> + while len(reply)< len(expect):
> + recv = stream.recv(10);
> + reply += recv
> + logger.info("Recieved data: '" + recv + "'")
> +
> + if expect != reply:
> + raise TestError("Recieved data don't match expected string")
> +
> + except libvirtError, e:
> + logger.error("Libvirt call failed")
> + raise e;
> +
> + except TestError, e:
> + logger.error("Test failed: " + str(e));
logger.error is enough I think.
> +
> + else:
> + logger.info("All tests succeeded")
> + ret = 0
> +
> + finally:
> + logger.info("Closing hypervisor connection")
> + conn.close()
> +
> + logger.info("Done")
> +
> + return ret
we need a console_io_clean(params) function for use by clean flag
in testcase config
BTW, I tried the testcase, but don't know how to offer the
options to let it run successful
It always hang up, could you give a detailed comments.
Guannan Ren
More information about the libvir-list
mailing list