From: Satheesh Rajendran <[email protected]>
Signed-off-by: Satheesh Rajendran <[email protected]> --- libvirt/tests/virsh_pool.py | 233 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 233 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..cb152bc --- /dev/null +++ b/libvirt/tests/virsh_pool.py @@ -0,0 +1,233 @@ +import logging, re, commands, os +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 is marked as autostart=%s" \ + "which is wrong", 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: + cmd = "mkdir -p %s" % (pool_target) + if not os.path.isdir(pool_target): + (status, output) = commands.getstatusoutput(cmd) + if status == 0: + if not virsh.pool_define_as(pool_name, pool_type, pool_target): + raise error.TestFail("Command virsh pool-define-as is" \ + " failed to execute") + else: + raise error.Testfail("Check the target path") + + else: + raise error.TestFail("The pool type %s has not been" \ + "supported yet in the test" % pool_type) + + # Step (2) + if not virsh.pool_undefine(pool_name): + raise error.TestFail("Command virsh pool-undefine" \ + " is failed to execute") + + # Step (3) + if not virsh.pool_define_as(pool_name, pool_type, pool_target): + raise error.TestFail("Command virsh pool-define-as is failed " \ + "to execute") + # Step (4) + if not virsh.pool_start(pool_name): + raise error.TestFail("Command virsh pool-start is failed " \ + "to execute") + # Step (5) + if not check_list_state(pool_name, "active"): + raise error.TestFail("%s pool is marked as state=inactive" \ + "which is wrong" % pool_name) + if not check_list_autostart(pool_name, "no"): + raise error.TestFail("%s pool is marked as autostart=yes" \ + "which is wrong" % pool_name) + + + # Step (6) + if not virsh.pool_autostart(pool_name): + raise error.TestFail("Command virsh autostart is failed" \ + " to execute") + + # Step (7) + if not check_list_state(pool_name, "active"): + raise error.TestFail("%s pool is marked as state=inactive" \ + "which is wrong" % pool_name) + if not check_list_autostart(pool_name, "yes"): + raise error.TestFail("%s pool is marked as autostart=no" \ + "which is wrong" % pool_name) + + + # Step (8) + if virsh.pool_undefine(pool_name): + raise error.TestFail("Command virsh pool-undefine is executed" \ + " fine though the pool is already running") + + # Step (9) + if not virsh.vol_create_as(vol_name, pool_name, \ + "1048576", "1048576", "raw"): + raise error.TestFail("Command virsh vol-create-as is failed" \ + " to execute") + + 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 is failed" \ + "to execute") + + if not check_list_state(pool_name, "inactive"): + raise error.TestFail("%s pool is marked as state=active" \ + "which is wrong" % pool_name) + if not check_list_autostart(pool_name, "yes"): + raise error.TestFail("%s pool is marked as autostart=no" \ + "which is wrong" % pool_name) + + + # Step (11) + if check_vol_list(vol_name, pool_name, pool_target, "False"): + raise error.TestFail("Command virsh vol-list works for" \ + " not active pool") + # Step (12) + if not virsh.pool_start(pool_name): + raise error.TestFail("Command virsh pool-start is failed " \ + "to execute") + + # 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 is failed "\ + "to execute") + # 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 is failed" \ + "to execute") + + # Step (17) + if not virsh.pool_undefine(pool_name): + raise error.TestFail("Command virsh pool-undefine is failed " + "to execute") + + 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) + + cmd = "rm -rf %s" % (pool_target) + (status, output) = commands.getstatusoutput(cmd) + if not status == 0: + raise error.TestFail("Failed to delete the pool target directory" \ + "%s:\n %s" % (pool_target, output) ) -- 1.7.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
