From: Satheesh Rajendran <[email protected]>
Signed-off-by: Satheesh Rajendran <[email protected]> --- libvirt/tests/virsh_pool.py | 224 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 224 insertions(+), 0 deletions(-) create mode 100644 libvirt/tests/virsh_pool.py diff --git a/libvirt/tests/virsh_pool.py b/libvirt/tests/virsh_pool.py new file mode 100644 index 0000000..c527aa4 --- /dev/null +++ b/libvirt/tests/virsh_pool.py @@ -0,0 +1,224 @@ +import logging, re, os, shutil +from autotest.client.shared import error +from virttest import virsh + + +def run_virsh_pool(test, params, env): + """ + Test the virsh pool commands + + (1) Define a 'dir' type pool(temp) and check for success + (2) Undefine the pool and check for success + (3) Repeat Step1 + (4) Start the pool(temp) and check for success + (5) Check on pool list whether the start is active and autostart is 'no' + (6) Mark the pool(temp) for autostart and check for the success + (7) Check on pool-list whether autostart is 'yes' + (8) Undefine the pool(temp) and check for the proper error message + (9) Create the volume(tmp) on the pool(temp) anc check for success + (10) Destroy the pool(temp) and check for success + (11) Check volume list on pool(temp) and check for failure + (12) Repeat Step4 + (13) Check volume list on pool(temp) and check for volume(tmp) + (14) Delete the volume(tmp) on pool(temp) + (15) Check volume list on pool(temp) and check for volume(tmp) not present + (16) Destroy the pool(temp) and check for success + (17) Undefine the pool(temp) and check for success + TODO: To support the tests for multiple pool types + """ + + def check_list_state(pool_name, state="active"): + """ + Check pool from the list + """ + + found = False + # Get the list stored in a variable + output = virsh.pool_list(option="--all") + result = re.findall(r"(\w+)\s+(\w+)\s+(\w+)", str(output)) + for item in result: + if pool_name in item[0]: + found = True + if not state == item[1]: + logging.debug("The state: %s of a given pool: %s" + " is not shown in the list", state, pool_name) + return False + if found: + return True + else: + logging.debug("The pool: %s is not found in the list", pool_name) + return False + + + + def check_list_autostart(pool_name, autostart="no"): + """ + Check pool from the list + """ + + found = False + # Get the list stored in a variable + output = virsh.pool_list(option="--all") + result = re.findall(r"(\w+)\s+(\w+)\s+(\w+)", str(output)) + for item in result: + if pool_name in item[0]: + found = True + if not autostart in item[2]: + raise error.TestFail("%s pool shouldn't be marked as " + "autostart=%s", item[0], item[2]) + if found: + return True + else: + logging.debug("The pool: %s is not found in the list", pool_name) + return False + + + def check_vol_list(vol_name, pool_name, pool_target, status= "True"): + """ + Check volume from the list + """ + + found = False + # Get the volume list stored in a variable + if not status: + if not virsh.vol_list(pool_name): + return True + output = virsh.vol_list(pool_name) + result = re.findall(r"(\w+)\s+(%s/%s)" % (pool_target, vol_name), + str(output)) + for item in result: + if vol_name in item[0]: + found = True + if found: + return True + else: + return False + + + # Initialize the variables + pool_name = params.get("pool_name") + pool_type = params.get("pool_type") + pool_target = params.get("pool_target") + vol_name = params.get("vol_name") + + logging.info("\n\tPool Name: %s\n\tPool Type: %s\n\tPool Target: %s\n\t" + "Volume Name:%s", pool_name, pool_type, + pool_target, vol_name) + # Run Testcase + try: + # Step (1) + if 'dir' in pool_type: + try: + os.makedirs(pool_target) + except OSError, detail: + raise error.TestFail("Check the target path") + + if not virsh.pool_define_as(pool_name, pool_type, pool_target): + raise error.TestFail("Command virsh pool-define-as failed") + + else: + raise error.TestFail("The pool type %s has not been" + "supported in the test" % pool_type) + + # Step (2) + if not virsh.pool_undefine(pool_name): + raise error.TestFail("Command virsh pool-undefine failed") + + # Step (3) + if not virsh.pool_define_as(pool_name, pool_type, pool_target): + raise error.TestFail("Command virsh pool-define-as failed") + + # Step (4) + if not virsh.pool_start(pool_name): + raise error.TestFail("Command virsh pool-start failed") + + # Step (5) + if not check_list_state(pool_name, "active"): + raise error.TestFail("State of the pool: %s is marked inactive" + "instead of active" % pool_name) + if not check_list_autostart(pool_name, "no"): + raise error.TestFail("Autostart of the pool: %s marked as yes" + "instead of no" % pool_name) + + + # Step (6) + if not virsh.pool_autostart(pool_name): + raise error.TestFail("Command virsh autostart is failed") + + # Step (7) + if not check_list_state(pool_name, "active"): + raise error.TestFail("State of the pool: %s marked as inactive" + "instead of active" % pool_name) + if not check_list_autostart(pool_name, "yes"): + raise error.TestFail("Autostart of the pool: %s marked as no" + "instead of yes" % pool_name) + + + # Step (8) + if virsh.pool_undefine(pool_name): + raise error.TestFail("Command virsh pool-undefine succeeded" + " with pool still active and running") + + # Step (9) + if not virsh.vol_create_as(vol_name, pool_name, + "1048576", "1048576", "raw"): + raise error.TestFail("Command virsh vol-create-as failed") + + if not check_vol_list(vol_name, pool_name, pool_target): + raise error.TestFail("The volume %s is not found in the " + "output of virsh vol-list" % vol_name) + + # Step (10) + if not virsh.pool_destroy(pool_name): + raise error.TestFail("Command virsh pool-destroy failed") + + if not check_list_state(pool_name, "inactive"): + raise error.TestFail("State of the pool: %s marked as active" + "instead of inactive" % pool_name) + if not check_list_autostart(pool_name, "yes"): + raise error.TestFail("Autostart of the pool: %s marked as no" + "instead of yes" % pool_name) + + + # Step (11) + if check_vol_list(vol_name, pool_name, pool_target, "False"): + raise error.TestFail("Command virsh vol-list succeeded" + " on an inactive pool") + # Step (12) + if not virsh.pool_start(pool_name): + raise error.TestFail("Command virsh pool-start failed") + + # Step (13) + if not check_vol_list(vol_name, pool_name, pool_target): + raise error.TestFail("The volume %s is not found in the " + "output of virsh vol-list" % vol_name) + + # Step (14) + if not virsh.vol_delete(vol_name, pool_name): + raise error.TestFail("Command virsh vol-delete failed") + + # Step (15) + if check_vol_list(vol_name, pool_name, pool_target): + raise error.TestFail("Command virsh vol-list shows deleted volume" + " % for a pool %s" % vol_name, pool_name) + + # Step (16) + if not virsh.pool_destroy(pool_name): + raise error.TestFail("Command virsh pool-destroy failed") + + # Step (17) + if not virsh.pool_undefine(pool_name): + raise error.TestFail("Command virsh pool-undefine failed") + + finally: + if check_list_state(pool_name, "active"): + virsh.pool_destroy(pool_name) + virsh.pool_undefine(pool_name) + elif check_list_state(pool_name, "inactive"): + virsh.pool_undefine(pool_name) + + try: + shutil.rmtree(pool_target) + except OSError, detail: + raise error.TestFail("Failed to delete the pool target directory" + "%s:\n %s" % (pool_target, detail) ) -- 1.7.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
