[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [test-API] RFC: Stabilization of libvirt-test-API

On 03/30/2012 05:33 PM, Martin Kletzander wrote:

To answer two of your questions at once, I'll show you an example of
what I had in mind (BTW: one of the current disadvantages is also the
fact that each indentation level _must_ be 4 spaces, otherwise you'll
get an error). Please be aware that this doesn't make almost any sense,
it just shows a couple of things I think could help everyone a lot.

file testcase.cfg:

# Local variables. You can use these variables only in this testcase
# file. This requires 1 more line of code in CofigParser.
my_hyper = "qemu"
module = connections

# Could be named "Defaults" as these variables will be passed to all
# test in this testcase file...
uri = %(my_hyper)s:///system

# This section is not needed if the tests are named Test1.Connect and
# so on, but it is more readable a understandable for some readers
Test_1 = Connect
Test_2 = Disconnect

Module = $(connections)s
Testcase = connect
# if not specified, this could default to Test.<name>.Params
Params = SomethingElse

# ...unless they are overwritten with some others
uri = %(my_hyper)s:///session

Module = $(connections)s
Testcase = disconnect
# No parameters here (none needed)

And then you will have two tests that look something like this (very
rough idea with lots of things I had in my mind, just to show how nice
it could look):

file tests/connections/connect.py:

def get_params(params):
     # clean the parameters, put defaults for undefined ones, etc.
     return params

# this means that if needed, this test will create/update these
# variables in the "shares" (will get to that in a few lines)
provides = ('connection', 'uri')

def run(logger, test_params, shares):
     # no need to test the return code, we can raise an exception that
     # will be caught outside of the test and reported through logger
     params_cleaned = get_params(test_params)

     # "shares" would be object that takes care of the values shared
     # between tests, check for dependencies, etc.
     shares.update('uri', conn)

     logger.debug('using uri: %s' % params_cleaned['uri'])

     # again, no need to check for an exception
     conn = libvirt.open(params_cleaned['uri'])

     # and for example it could return the values that should be
     # provided in "shares"
     return { 'connection' : conn }

file tests/connections/disconnect.py:

def get_params(params):
     # clean the parameters, put defaults for undefined ones, etc.
     return params

# this can be either here or evaluated when the test is trying to get
# the value from the "shares" object
requires = ('connection',)

def run(logger, test_params, shares):
     params_cleaned = get_params(test_params)
     conn = shares.get('connection')
     logger.info('disconnecting from uri: %s' % conn.getURI())

And this would be the two tests with test case that tries to connect and
disconnect. All the errors are caught in the test runner, if some tests
depend on exception that is raised in underlying libvirt, they can catch
it themselves without propagating it up (the whole point of exceptions),

The .ini fomat is often used as data storage, that is perfect for config file.
        The testcase config currently used by test-API is the default
testcase writing format in upstream autotest that supported by qemu.

        Guannan Ren

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]