From: Wayne Sun <gsun@xxxxxxxxxx> * modify all cases under repos/ of try/except/finally format * delete utils/Python/virt.cfg which in wrong place Signed-off-by: Guannan Ren <gren@xxxxxxxxxx> --- repos/domain/attach_disk.py | 29 ++++---- repos/domain/attach_interface.py | 29 ++++---- repos/domain/autostart.py | 29 ++++---- repos/domain/blkstats.py | 9 +- repos/domain/create.py | 13 ++-- repos/domain/define.py | 19 +++-- repos/domain/destroy.py | 13 ++-- repos/domain/detach_disk.py | 29 ++++---- repos/domain/detach_interface.py | 31 ++++---- repos/domain/domain_uuid.py | 25 +++--- repos/domain/reboot.py | 13 ++-- repos/domain/save.py | 25 +++--- repos/domain/undefine.py | 19 +++-- repos/interface/create.py | 29 ++++---- repos/interface/define.py | 25 +++--- repos/interface/destroy.py | 29 ++++---- repos/interface/undefine.py | 25 +++--- repos/network/autostart.py | 39 +++++----- repos/network/create.py | 31 ++++---- repos/network/define.py | 29 ++++---- repos/network/destroy.py | 31 ++++---- repos/network/network_name.py | 25 +++--- repos/network/network_uuid.py | 25 +++--- repos/network/undefine.py | 29 ++++---- repos/nodedevice/detach.py | 33 ++++---- repos/nodedevice/reattach.py | 33 ++++---- repos/nodedevice/reset.py | 21 +++--- repos/npiv/create_virtual_hba.py | 35 +++++---- repos/snapshot/delete.py | 23 +++--- repos/snapshot/internal_create.py | 15 ++-- repos/snapshot/revert.py | 15 ++-- repos/storage/activate_pool.py | 23 +++--- repos/storage/build_dir_pool.py | 27 ++++--- repos/storage/build_disk_pool.py | 27 ++++--- repos/storage/build_logical_pool.py | 29 ++++---- repos/storage/build_netfs_pool.py | 27 ++++--- repos/storage/create_dir_pool.py | 25 +++--- repos/storage/create_dir_volume.py | 13 ++-- repos/storage/create_fs_pool.py | 35 +++++---- repos/storage/create_iscsi_pool.py | 25 +++--- repos/storage/create_logical_volume.py | 31 ++++---- repos/storage/create_netfs_pool.py | 35 +++++---- repos/storage/create_netfs_volume.py | 13 ++-- repos/storage/define_dir_pool.py | 37 +++++----- repos/storage/define_disk_pool.py | 31 ++++---- repos/storage/define_iscsi_pool.py | 29 ++++---- repos/storage/define_logical_pool.py | 29 ++++---- repos/storage/define_mpath_pool.py | 31 ++++---- repos/storage/define_netfs_pool.py | 29 ++++---- repos/storage/define_scsi_pool.py | 31 ++++---- repos/storage/delete_dir_volume.py | 27 ++++--- repos/storage/delete_logical_pool.py | 29 ++++---- repos/storage/delete_logical_volume.py | 31 ++++---- repos/storage/delete_netfs_volume.py | 27 ++++--- repos/storage/pool_name.py | 23 +++--- repos/storage/pool_uuid.py | 23 +++--- repos/storage/undefine_pool.py | 29 ++++---- utils/Python/virt.cfg | 129 -------------------------------- 58 files changed, 774 insertions(+), 846 deletions(-) delete mode 100644 utils/Python/virt.cfg diff --git a/repos/domain/attach_disk.py b/repos/domain/attach_disk.py index b8fd8ef..3a1175e 100644 --- a/repos/domain/attach_disk.py +++ b/repos/domain/attach_disk.py @@ -120,21 +120,22 @@ def attach_disk(params): # Attach disk to domain try: - domobj.attach_device(guestname, diskxml) - disk_num2 = util.dev_num(guestname, "disk") - logger.debug("update disk number to %s" %disk_num2) - if check_attach_disk(disk_num1, disk_num2): - logger.info("current disk number: %s\n" %disk_num2) - test_result = True - else: - logger.error("fail to attach a disk to guest: %s\n" %disk_num2) + try: + domobj.attach_device(guestname, diskxml) + disk_num2 = util.dev_num(guestname, "disk") + logger.debug("update disk number to %s" %disk_num2) + if check_attach_disk(disk_num1, disk_num2): + logger.info("current disk number: %s\n" %disk_num2) + test_result = True + else: + logger.error("fail to attach a disk to guest: %s\n" %disk_num2) + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % + (e.response()['message'], e.response()['code'])) + logger.error("attach %s disk to guest %s" % (imagename, guestname)) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % - (e.response()['message'], e.response()['code'])) - logger.error("attach %s disk to guest %s" % (imagename, guestname)) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/attach_interface.py b/repos/domain/attach_interface.py index 351e57e..9d475a3 100644 --- a/repos/domain/attach_interface.py +++ b/repos/domain/attach_interface.py @@ -89,21 +89,22 @@ def attach_interface(params): # Attach interface to domain try: - domobj.attach_device(guestname, interfacexml) - iface_num2 = util.dev_num(guestname, "interface") - logger.debug("update interface number to %s" %iface_num2) - if check_attach_interface(iface_num1, iface_num2): - logger.info("current interface number: %s" %iface_num2) - test_result = True - else: - logger.error("fail to attach a interface to guest: %s" %iface_num2) + try: + domobj.attach_device(guestname, interfacexml) + iface_num2 = util.dev_num(guestname, "interface") + logger.debug("update interface number to %s" %iface_num2) + if check_attach_interface(iface_num1, iface_num2): + logger.info("current interface number: %s" %iface_num2) + test_result = True + else: + logger.error("fail to attach a interface to guest: %s" %iface_num2) + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % + (e.response()['message'], e.response()['code'])) + logger.error("attach a interface to guest %s" % guestname) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % - (e.response()['message'], e.response()['code'])) - logger.error("attach a interface to guest %s" % guestname) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/autostart.py b/repos/domain/autostart.py index 2a1f0c8..f0fc97c 100644 --- a/repos/domain/autostart.py +++ b/repos/domain/autostart.py @@ -94,21 +94,22 @@ def autostart(params): # Set autostart for domain domobj = domainAPI.DomainAPI(virconn) try: - domobj.set_auto_start(guestname, flag) - if check_guest_autostart(guestname, uri.split(":")[0], flag, logger): - logger.info("current %s autostart: %s" % - (guestname, domobj.get_auto_start(guestname))) - logger.info("executing autostart operation is successful") - test_result = True - else: - logger.error("Error: fail to check autostart domain") + try: + domobj.set_auto_start(guestname, flag) + if check_guest_autostart(guestname, uri.split(":")[0], flag, logger): + logger.info("current %s autostart: %s" % + (guestname, domobj.get_auto_start(guestname))) + logger.info("executing autostart operation is successful") + test_result = True + else: + logger.error("Error: fail to check autostart domain") + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % + (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to autostart %s domain" %guestname) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % - (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to autostart %s domain" %guestname) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/blkstats.py b/repos/domain/blkstats.py index 4c35ca3..05dbb83 100644 --- a/repos/domain/blkstats.py +++ b/repos/domain/blkstats.py @@ -72,10 +72,11 @@ def block_stats(params): domobj.start(guestname) time.sleep(90) try: - (blkstats, path) = domobj.get_block_stats(guestname) - except exception.LibvirtAPI, e: - logger.error("libvirt error: error code - %s; error message - %s" %(e.code, e.message)) - return 1; + try: + (blkstats, path) = domobj.get_block_stats(guestname) + except exception.LibvirtAPI, e: + logger.error("libvirt error: error code - %s; error message - %s" %(e.code, e.message)) + return 1; finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/create.py b/repos/domain/create.py index 2bb759d..343aba2 100644 --- a/repos/domain/create.py +++ b/repos/domain/create.py @@ -98,12 +98,13 @@ def create(params): # Create domain from xml try: - domobj.create(domxml) - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % - (e.response()['message'], e.response()['code'])) - logger.error("fail to create domain %s" % guestname) - return 1 + try: + domobj.create(domxml) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % + (e.response()['message'], e.response()['code'])) + logger.error("fail to create domain %s" % guestname) + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/define.py b/repos/domain/define.py index 8ad7843..d965f63 100644 --- a/repos/domain/define.py +++ b/repos/domain/define.py @@ -115,16 +115,17 @@ def define(params): # Define domain from xml try: - dom_obj.define(dom_xml) - if check_define_domain(guestname, guesttype, logger): - logger.info("define a domain form xml is successful") - test_result = True - else: - logger.error("fail to check define domain") + try: + dom_obj.define(dom_xml) + if check_define_domain(guestname, guesttype, logger): + logger.info("define a domain form xml is successful") + test_result = True + else: + logger.error("fail to check define domain") + test_result = False + except: + logger.error("fail to define a domain from xml") test_result = False - except: - logger.error("fail to define a domain from xml") - test_result = False finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/destroy.py b/repos/domain/destroy.py index f06a1f6..f98b602 100644 --- a/repos/domain/destroy.py +++ b/repos/domain/destroy.py @@ -88,12 +88,13 @@ def destroy(params): # Destroy domain try: - dom_obj.destroy(guestname) - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - logger.error("fail to destroy domain") - return 1 + try: + dom_obj.destroy(guestname) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("fail to destroy domain") + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/detach_disk.py b/repos/domain/detach_disk.py index 3972c3f..21c6598 100644 --- a/repos/domain/detach_disk.py +++ b/repos/domain/detach_disk.py @@ -99,21 +99,22 @@ def detach_disk(params): time.sleep(90) try: - domobj.detach_device(guestname, diskxml) - disk_num2 = util.dev_num(guestname, "disk") - logger.debug("update disk number to %s" %disk_num2) - if check_detach_disk(disk_num1, disk_num2): - logger.info("current disk number: %s\n" %disk_num2) - test_result = True - else: - logger.error("fail to detach a disk to guest: %s\n" %disk_num2) + try: + domobj.detach_device(guestname, diskxml) + disk_num2 = util.dev_num(guestname, "disk") + logger.debug("update disk number to %s" %disk_num2) + if check_detach_disk(disk_num1, disk_num2): + logger.info("current disk number: %s\n" %disk_num2) + test_result = True + else: + logger.error("fail to detach a disk to guest: %s\n" %disk_num2) + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("detach %s disk from guest %s" % (imagename, guestname)) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - logger.error("detach %s disk from guest %s" % (imagename, guestname)) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/detach_interface.py b/repos/domain/detach_interface.py index 5eee836..6639336 100644 --- a/repos/domain/detach_interface.py +++ b/repos/domain/detach_interface.py @@ -101,22 +101,23 @@ def detach_interface(params): time.sleep(90) try: - domobj.detach_device(guestname, ifacexml) - iface_num2 = util.dev_num(guestname, "interface") - logger.debug("update interface number to %s" % iface_num2) - if check_detach_interface(iface_num1, iface_num2): - logger.info("current interface number: %s" % iface_num2) - test_result = True - else: - logger.error("fail to detach a interface to guest: %s" % - iface_num2) + try: + domobj.detach_device(guestname, ifacexml) + iface_num2 = util.dev_num(guestname, "interface") + logger.debug("update interface number to %s" % iface_num2) + if check_detach_interface(iface_num1, iface_num2): + logger.info("current interface number: %s" % iface_num2) + test_result = True + else: + logger.error("fail to detach a interface to guest: %s" % + iface_num2) + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("detach the interface from guest %s" % guestname) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - logger.error("detach the interface from guest %s" % guestname) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/domain_uuid.py b/repos/domain/domain_uuid.py index 05bd7e1..8b02a15 100644 --- a/repos/domain/domain_uuid.py +++ b/repos/domain/domain_uuid.py @@ -85,19 +85,20 @@ def domuuid(params): return 1 try: - logger.info("get the UUID string of %s" % guestname) - UUIDString = domobj.get_uuid_string(guestname) - if check_domain_uuid(guestname, UUIDString, logger): - logger.info("UUIDString from API is the same as the one from virsh") - logger.info("UUID String is %s" % UUIDString) - return 0 - else: - logger.error("UUIDString from API is not the same as the one from virsh") + try: + logger.info("get the UUID string of %s" % guestname) + UUIDString = domobj.get_uuid_string(guestname) + if check_domain_uuid(guestname, UUIDString, logger): + logger.info("UUIDString from API is the same as the one from virsh") + logger.info("UUID String is %s" % UUIDString) + return 0 + else: + logger.error("UUIDString from API is not the same as the one from virsh") + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/reboot.py b/repos/domain/reboot.py index aabeb88..03172c4 100644 --- a/repos/domain/reboot.py +++ b/repos/domain/reboot.py @@ -81,12 +81,13 @@ def reboot(params): # Reboot domain try: - dom_obj.reboot(domain_name) - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % - (e.response()['message'], e.response()['code'])) - logger.error("fail to reboot domain") - return 1 + try: + dom_obj.reboot(domain_name) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % + (e.response()['message'], e.response()['code'])) + logger.error("fail to reboot domain") + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/save.py b/repos/domain/save.py index 33d8d41..d9782e3 100644 --- a/repos/domain/save.py +++ b/repos/domain/save.py @@ -124,20 +124,21 @@ def save(params): logger.info("closed hypervisor connection") return 1 try: - domobj.save(guestname, filepath) - if check_guest_save(guestname, domobj, util, logger): - logger.info("save %s domain successful" %guestname) - test_result = True - else: - logger.error("Error: fail to check save domain") + try: + domobj.save(guestname, filepath) + if check_guest_save(guestname, domobj, util, logger): + logger.info("save %s domain successful" %guestname) + test_result = True + else: + logger.error("Error: fail to check save domain") + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to save %s domain" %guestname) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to save %s domain" %guestname) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/domain/undefine.py b/repos/domain/undefine.py index 02ca5bd..13412fa 100644 --- a/repos/domain/undefine.py +++ b/repos/domain/undefine.py @@ -70,16 +70,17 @@ def undefine(params): dom_obj = domainAPI.DomainAPI(virconn) try: - dom_obj.undefine(guestname) - if check_undefine_domain(guestname): - logger.info("undefine the domain is successful") - test_result = True - else: - logger.error("fail to check domain undefine") + try: + dom_obj.undefine(guestname) + if check_undefine_domain(guestname): + logger.info("undefine the domain is successful") + test_result = True + else: + logger.error("fail to check domain undefine") + test_result = False + except: + logger.error("fail to undefine the domain") test_result = False - except: - logger.error("fail to undefine the domain") - test_result = False finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/interface/create.py b/repos/interface/create.py index 6aabfe7..41e5dcc 100644 --- a/repos/interface/create.py +++ b/repos/interface/create.py @@ -110,22 +110,23 @@ def create(params): try: - ifaceobj.create(ifacename) - logger.info("create host interface %s" % ifacename) - display_current_interface(ifaceobj) - if check_create_interface(ifacename, util): - logger.info("create host interface %s is successful" % ifacename) - test_result = True - else: - logger.error("fail to check create interface") + try: + ifaceobj.create(ifacename) + logger.info("create host interface %s" % ifacename) + display_current_interface(ifaceobj) + if check_create_interface(ifacename, util): + logger.info("create host interface %s is successful" % ifacename) + test_result = True + else: + logger.error("fail to check create interface") + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("fail to create interface %s" %ifacename) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("fail to create interface %s" %ifacename) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/interface/define.py b/repos/interface/define.py index 4d996ab..054bd54 100644 --- a/repos/interface/define.py +++ b/repos/interface/define.py @@ -103,20 +103,21 @@ def define(params): logger.debug("interface xml:\n%s" %iface_xml) try: - ifaceobj.define(iface_xml) - if check_define_interface(ifacename): - logger.info("define a interface form xml is successful") - test_result = True - else: - logger.error("fail to check define interface") + try: + ifaceobj.define(iface_xml) + if check_define_interface(ifacename): + logger.info("define a interface form xml is successful") + test_result = True + else: + logger.error("fail to check define interface") + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("fail to define a interface from xml") test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("fail to define a interface from xml") - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/interface/destroy.py b/repos/interface/destroy.py index 2467aa6..771fa74 100644 --- a/repos/interface/destroy.py +++ b/repos/interface/destroy.py @@ -111,22 +111,23 @@ def destroy(params): #logger.debug("interface xml:\n%s" %iface_xml) try: - ifaceobj.destroy(ifacename) - logger.info("destroy host interface %s" % ifacename) - display_current_interface(ifaceobj) - if check_destroy_interface(hostip): - logger.info("destroy host interface %s is successful" % ifacename) - test_result = True - else: - logger.error("fail to check destroy interface") + try: + ifaceobj.destroy(ifacename) + logger.info("destroy host interface %s" % ifacename) + display_current_interface(ifaceobj) + if check_destroy_interface(hostip): + logger.info("destroy host interface %s is successful" % ifacename) + test_result = True + else: + logger.error("fail to check destroy interface") + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("fail to destroy interface %s" %ifacename) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("fail to destroy interface %s" %ifacename) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/interface/undefine.py b/repos/interface/undefine.py index 61f90bf..7d49942 100644 --- a/repos/interface/undefine.py +++ b/repos/interface/undefine.py @@ -98,20 +98,21 @@ def undefine(params): ifaceobj = interfaceAPI.InterfaceAPI(virconn) try: - ifaceobj.undefine(ifacename) - if check_undefine_interface(ifacename): - logger.info("undefine a interface form xml is successful") - test_result = True - else: - logger.error("fail to check undefine interface") + try: + ifaceobj.undefine(ifacename) + if check_undefine_interface(ifacename): + logger.info("undefine a interface form xml is successful") + test_result = True + else: + logger.error("fail to check undefine interface") + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("fail to undefine a interface from xml") test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("fail to undefine a interface from xml") - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/autostart.py b/repos/network/autostart.py index 0c4bd5a..ba4b4f1 100644 --- a/repos/network/autostart.py +++ b/repos/network/autostart.py @@ -113,26 +113,27 @@ def autostart(params): logger.debug("the output of 'virsh net-list --all' is %s" % text) try: - netobj.setnetAutostart(networkname, flag) - if check_network_autostart(networkname, - "qemu", - flag, - logger): - logger.info("current virtual network %s autostart: %s" % \ - (networkname, netobj.get_autostart(networkname))) - logger.info("executing autostart operation is successful") - test_result = True - else: - logger.error("Error: fail to check autostart status of \ - virtual network %s" % networkname) + try: + netobj.setnetAutostart(networkname, flag) + if check_network_autostart(networkname, + "qemu", + flag, + logger): + logger.info("current virtual network %s autostart: %s" % \ + (networkname, netobj.get_autostart(networkname))) + logger.info("executing autostart operation is successful") + test_result = True + else: + logger.error("Error: fail to check autostart status of \ + virtual network %s" % networkname) + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to autostart virtual network %s " % \ + networkname) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to autostart virtual network %s " % \ - networkname) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/create.py b/repos/network/create.py index 4caa7f7..a667441 100644 --- a/repos/network/create.py +++ b/repos/network/create.py @@ -89,22 +89,23 @@ def create(params): logger.info("original network active number: %s" % net_num1) try: - netobj.create(netxml) - net_num2 = netobj.get_number() - if not check_network_status(networkname, netobj, logger) and \ - net_num2 > net_num1: - logger.info("current network active number: %s\n" % net_num2) - test_result = True - else: - logger.error("the %s network is inactive" % networkname) - logger.error("fail to create network from :\n%s" % netxml) + try: + netobj.create(netxml) + net_num2 = netobj.get_number() + if not check_network_status(networkname, netobj, logger) and \ + net_num2 > net_num1: + logger.info("current network active number: %s\n" % net_num2) + test_result = True + else: + logger.error("the %s network is inactive" % networkname) + logger.error("fail to create network from :\n%s" % netxml) + test_result = False + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("create a network from xml: \n%s" % netxml) test_result = False - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("create a network from xml: \n%s" % netxml) - test_result = False - return 1 + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/define.py b/repos/network/define.py index b96c599..dda8d06 100644 --- a/repos/network/define.py +++ b/repos/network/define.py @@ -97,22 +97,23 @@ def define(params): logger.info("original network define number: %s" % net_num1) try: - netobj.define(netxml) - net_num2 = netobj.get_define_number() - if check_network_define(networkname, logger) and net_num2 > net_num1: - logger.info("current network define number: %s" % net_num2) - logger.info("define %s network is successful" % networkname) - test_result = True - else: - logger.error("%s network is undefined" % networkname) + try: + netobj.define(netxml) + net_num2 = netobj.get_define_number() + if check_network_define(networkname, logger) and net_num2 > net_num1: + logger.info("current network define number: %s" % net_num2) + logger.info("define %s network is successful" % networkname) + test_result = True + else: + logger.error("%s network is undefined" % networkname) + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("define a network from xml: \n%s" % netxml) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("define a network from xml: \n%s" % netxml) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/destroy.py b/repos/network/destroy.py index 5b31bf0..51663ac 100644 --- a/repos/network/destroy.py +++ b/repos/network/destroy.py @@ -86,23 +86,24 @@ def destroy(params): logger.info("original network active number: %s" % net_num1) try: - netobj.destroy(networkname) - net_num2 = netobj.get_number() - if not check_network_status(networkname, netobj, logger) and \ - net_num1 > net_num2: - logger.info("current network active number: %s\n" % net_num2) - logger.info("destroy %s network successful" % networkname) - test_result = True - else: - logger.error("the %s network is still running" % networkname) + try: + netobj.destroy(networkname) + net_num2 = netobj.get_number() + if not check_network_status(networkname, netobj, logger) and \ + net_num1 > net_num2: + logger.info("current network active number: %s\n" % net_num2) + logger.info("destroy %s network successful" % networkname) + test_result = True + else: + logger.error("the %s network is still running" % networkname) + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("fail to destroy %s network" % networkname) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("fail to destroy %s network" % networkname) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/network_name.py b/repos/network/network_name.py index d4e9c04..5b78dec 100644 --- a/repos/network/network_name.py +++ b/repos/network/network_name.py @@ -86,19 +86,20 @@ def netname(params): return 1 try: - UUIDString = netobj.get_uuid_string(networkname) - logger.info("the UUID string of network %s is %s" % (networkname, UUIDString)) - - if check_network_uuid(networkname, UUIDString, logger): - logger.info(VIRSH_NETNAME + " test succeeded.") - return 0 - else: - logger.error(VIRSH_NETNAME + " test failed.") + try: + UUIDString = netobj.get_uuid_string(networkname) + logger.info("the UUID string of network %s is %s" % (networkname, UUIDString)) + + if check_network_uuid(networkname, UUIDString, logger): + logger.info(VIRSH_NETNAME + " test succeeded.") + return 0 + else: + logger.error(VIRSH_NETNAME + " test failed.") + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/network_uuid.py b/repos/network/network_uuid.py index 266d893..be30fd2 100644 --- a/repos/network/network_uuid.py +++ b/repos/network/network_uuid.py @@ -86,19 +86,20 @@ def netuuid(params): return 1 try: - UUIDString = netobj.get_uuid_string(networkname) - logger.info("the UUID string of network %s is %s" % (networkname, UUIDString)) - - if check_network_uuid(networkname, UUIDString, logger): - logger.info(VIRSH_NETUUID + " test succeeded.") - return 0 - else: - logger.error(VIRSH_NETUUID + " test failed.") + try: + UUIDString = netobj.get_uuid_string(networkname) + logger.info("the UUID string of network %s is %s" % (networkname, UUIDString)) + + if check_network_uuid(networkname, UUIDString, logger): + logger.info(VIRSH_NETUUID + " test succeeded.") + return 0 + else: + logger.error(VIRSH_NETUUID + " test failed.") + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/network/undefine.py b/repos/network/undefine.py index ea14282..d7e903e 100644 --- a/repos/network/undefine.py +++ b/repos/network/undefine.py @@ -85,22 +85,23 @@ def undefine(params): logger.info("original network define number: %s" % net_num1) try: - netobj.undefine(networkname) - net_num2 = netobj.get_define_number() - if check_network_undefine(networkname) and net_num2 < net_num1: - logger.info("current network define number: %s" % net_num2) - logger.info("undefine %s network is successful" % networkname) - test_result = True - else: - logger.error("the network %s is still define" % networkname) + try: + netobj.undefine(networkname) + net_num2 = netobj.get_define_number() + if check_network_undefine(networkname) and net_num2 < net_num1: + logger.info("current network define number: %s" % net_num2) + logger.info("undefine %s network is successful" % networkname) + test_result = True + else: + logger.error("the network %s is still define" % networkname) + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("fail to undefine a network") test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("fail to undefine a network") - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/nodedevice/detach.py b/repos/nodedevice/detach.py index 7304b7a..ac9aa89 100644 --- a/repos/nodedevice/detach.py +++ b/repos/nodedevice/detach.py @@ -119,24 +119,25 @@ def dettach(dicts): nodeobj = nodedevAPI.NodedevAPI(virconn) try: - logger.info("dettach the node device") - nodeobj.dettach(device_name) - current_driver = check_node_dettach(pciaddress) - logger.info("current device driver: %s" % current_driver) - if current_driver != original_driver and current_driver == pciback: - logger.info("the node %s device dettach is successful" \ - % device_name) - test_result = True - else: - logger.info("the node %s device dettach is failed" % device_name) + try: + logger.info("dettach the node device") + nodeobj.dettach(device_name) + current_driver = check_node_dettach(pciaddress) + logger.info("current device driver: %s" % current_driver) + if current_driver != original_driver and current_driver == pciback: + logger.info("the node %s device dettach is successful" \ + % device_name) + test_result = True + else: + logger.info("the node %s device dettach is failed" % device_name) + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to dettach %s node device" % device_name) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to dettach %s node device" % device_name) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/nodedevice/reattach.py b/repos/nodedevice/reattach.py index 4943fc2..8eafb1d 100644 --- a/repos/nodedevice/reattach.py +++ b/repos/nodedevice/reattach.py @@ -118,24 +118,25 @@ def reattach(dicts): nodeobj = nodedevAPI.NodedevAPI(virconn) try: - nodeobj.reattach(device_name) - logger.info("reattach the node device") - current_driver = check_node_reattach(pciaddress) - logger.info("current device driver: %s" % current_driver) - if original_driver == pciback and current_driver != pciback: - logger.info("the node %s device reattach is successful" \ - % device_name) - test_result = True - else: - logger.info("the node %s device reattach is failed" % device_name) + try: + nodeobj.reattach(device_name) + logger.info("reattach the node device") + current_driver = check_node_reattach(pciaddress) + logger.info("current device driver: %s" % current_driver) + if original_driver == pciback and current_driver != pciback: + logger.info("the node %s device reattach is successful" \ + % device_name) + test_result = True + else: + logger.info("the node %s device reattach is failed" % device_name) + test_result = False + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to reattach %s node device" % device_name) test_result = False return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to reattach %s node device" % device_name) - test_result = False - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/nodedevice/reset.py b/repos/nodedevice/reset.py index 7b85d70..40ba95b 100644 --- a/repos/nodedevice/reset.py +++ b/repos/nodedevice/reset.py @@ -87,16 +87,17 @@ def reset(dicts): nodeobj = nodedevAPI.NodedevAPI(virconn) try: - nodeobj.reset(device_name) - logger.info("reset the node device") - logger.info("the node %s device reset is successful" % device_name) - test_result = True - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to reset %s node device" % device_name) - test_result = False - return 1 + try: + nodeobj.reset(device_name) + logger.info("reset the node device") + logger.info("the node %s device reset is successful" % device_name) + test_result = True + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to reset %s node device" % device_name) + test_result = False + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/npiv/create_virtual_hba.py b/repos/npiv/create_virtual_hba.py index 3bc6b5b..e86b85a 100644 --- a/repos/npiv/create_virtual_hba.py +++ b/repos/npiv/create_virtual_hba.py @@ -117,24 +117,25 @@ def create_virtual_hba(params): logger.debug("node device xml:\n%s" % nodedev_xml) try: - logger.info("creating a virtual HBA ...") - nodedev_obj = nodedev.create(nodedev_xml) - dev_name = nodedev.get_name(nodedev_obj) - - if check_nodedev_create(wwpn, dev_name) and \ - check_nodedev_parent(nodedev, params['parent'], dev_name): - logger.info("the virtual HBA '%s' was created successfully" \ - % dev_name) - return 0 - else: - logger.error("fail to create the virtual HBA '%s'" \ - % dev_name) + try: + logger.info("creating a virtual HBA ...") + nodedev_obj = nodedev.create(nodedev_xml) + dev_name = nodedev.get_name(nodedev_obj) + + if check_nodedev_create(wwpn, dev_name) and \ + check_nodedev_parent(nodedev, params['parent'], dev_name): + logger.info("the virtual HBA '%s' was created successfully" \ + % dev_name) + return 0 + else: + logger.error("fail to create the virtual HBA '%s'" \ + % dev_name) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + logger.error("Error: fail to create %s virtual hba" % dev_name) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - logger.error("Error: fail to create %s virtual hba" % dev_name) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/snapshot/delete.py b/repos/snapshot/delete.py index 88540c8..8a7eef6 100644 --- a/repos/snapshot/delete.py +++ b/repos/snapshot/delete.py @@ -105,18 +105,19 @@ def delete(params): return 1 try: - logger.info("delete a snapshot for %s" % guestname) - snap_obj.delete(guestname, snapshotname) - if not delete_check(guestname, snapshotname, "noexist", logger): - logger.error("after deleting, the corresponding \ - xmlfile still exists in %s" % SNAPSHOT_DIR) + try: + logger.info("delete a snapshot for %s" % guestname) + snap_obj.delete(guestname, snapshotname) + if not delete_check(guestname, snapshotname, "noexist", logger): + logger.error("after deleting, the corresponding \ + xmlfile still exists in %s" % SNAPSHOT_DIR) + return 1 + else: + logger.info("delete snapshot %s succeeded" % snapshotname) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - else: - logger.info("delete snapshot %s succeeded" % snapshotname) - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ -(e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/snapshot/internal_create.py b/repos/snapshot/internal_create.py index a28eff6..123e38a 100644 --- a/repos/snapshot/internal_create.py +++ b/repos/snapshot/internal_create.py @@ -111,13 +111,14 @@ def internal_create(params): logger.debug("%s snapshot xml:\n%s" % (guestname, snapshot_xml)) try: - logger.info("create a snapshot for %s" % guestname) - snap_obj.create(guestname, snapshot_xml) - logger.info("creating snapshot succeeded") - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ -(e.response()['message'], e.response()['code'])) - return 1 + try: + logger.info("create a snapshot for %s" % guestname) + snap_obj.create(guestname, snapshot_xml) + logger.info("creating snapshot succeeded") + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/snapshot/revert.py b/repos/snapshot/revert.py index 4c86bb4..f70e5dc 100644 --- a/repos/snapshot/revert.py +++ b/repos/snapshot/revert.py @@ -81,13 +81,14 @@ def revert(params): return 1 try: - logger.info("revert a snapshot for %s" % guestname) - snap_obj.revertToSnapshot(guestname, snapshotname) - logger.info("revert snapshot succeeded") - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ -(e.response()['message'], e.response()['code'])) - return 1 + try: + logger.info("revert a snapshot for %s" % guestname) + snap_obj.revertToSnapshot(guestname, snapshotname) + logger.info("revert snapshot succeeded") + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/activate_pool.py b/repos/storage/activate_pool.py index 9dab7ee..2b27be6 100644 --- a/repos/storage/activate_pool.py +++ b/repos/storage/activate_pool.py @@ -101,18 +101,19 @@ def activate_pool(params): logger.info("closed hypervisor connection") return 1 try: - stgobj.active_pool(poolname) - time.sleep(5) - if check_pool_active(stgobj, poolname, logger): - logger.info("activating %s storage pool is SUCCESSFUL!!!" % poolname) - return 0 - else: - logger.info("activating %s storage pool is UNSUCCESSFUL!!!" % poolname) + try: + stgobj.active_pool(poolname) + time.sleep(5) + if check_pool_active(stgobj, poolname, logger): + logger.info("activating %s storage pool is SUCCESSFUL!!!" % poolname) + return 0 + else: + logger.info("activating %s storage pool is UNSUCCESSFUL!!!" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/build_dir_pool.py b/repos/storage/build_dir_pool.py index d447a5b..5765b36 100644 --- a/repos/storage/build_dir_pool.py +++ b/repos/storage/build_dir_pool.py @@ -115,20 +115,21 @@ def build_dir_pool(params): display_pool_info(stgobj) try: - logger.info("build %s storage pool" % poolname) - stgobj.build_pool(poolname) - display_pool_info(stgobj) - - if check_build_pool(path_value): - logger.info("build %s storage pool is successful" % poolname) - return 0 - else: - logger.error("fail to build %s storage pool" % poolname) + try: + logger.info("build %s storage pool" % poolname) + stgobj.build_pool(poolname) + display_pool_info(stgobj) + + if check_build_pool(path_value): + logger.info("build %s storage pool is successful" % poolname) + return 0 + else: + logger.error("fail to build %s storage pool" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/build_disk_pool.py b/repos/storage/build_disk_pool.py index c5311cb..be36ea8 100644 --- a/repos/storage/build_disk_pool.py +++ b/repos/storage/build_disk_pool.py @@ -141,20 +141,21 @@ def build_disk_pool(params): (source_device, device_type)) try: - logger.info("begin to build the storage pool") - stgobj.build_pool(poolname) - time.sleep(5) - if not check_pool_built(source_device, device_type): - logger.info("building %s storage pool is SUCCESSFUL!!!" % poolname) - return 0 - else: - logger.info("building %s storage pool is UNSUCCESSFUL!!!" % \ - poolname) + try: + logger.info("begin to build the storage pool") + stgobj.build_pool(poolname) + time.sleep(5) + if not check_pool_built(source_device, device_type): + logger.info("building %s storage pool is SUCCESSFUL!!!" % poolname) + return 0 + else: + logger.info("building %s storage pool is UNSUCCESSFUL!!!" % \ + poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/build_logical_pool.py b/repos/storage/build_logical_pool.py index cc9ccae..f761fd1 100644 --- a/repos/storage/build_logical_pool.py +++ b/repos/storage/build_logical_pool.py @@ -120,21 +120,22 @@ def build_logical_pool(params): display_physical_volume() try: - logger.info("build %s storage pool" % poolname) - stgobj.build_pool(poolname) - display_pool_info(stgobj) - display_physical_volume() - - if check_build_pool(poolname): - logger.info("build %s storage pool is successful" % poolname) - return 0 - else: - logger.error("fail to build %s storage pool" % poolname) + try: + logger.info("build %s storage pool" % poolname) + stgobj.build_pool(poolname) + display_pool_info(stgobj) + display_physical_volume() + + if check_build_pool(poolname): + logger.info("build %s storage pool is successful" % poolname) + return 0 + else: + logger.error("fail to build %s storage pool" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/build_netfs_pool.py b/repos/storage/build_netfs_pool.py index 4d0b191..d0012ff 100644 --- a/repos/storage/build_netfs_pool.py +++ b/repos/storage/build_netfs_pool.py @@ -114,20 +114,21 @@ def build_netfs_pool(params): display_pool_info(stgobj) try: - logger.info("build %s storage pool" % poolname) - stgobj.build_pool(poolname) - display_pool_info(stgobj) - - if check_build_pool(path_value): - logger.info("build %s storage pool is successful" % poolname) - return 0 - else: - logger.error("fail to build %s storage pool" % poolname) + try: + logger.info("build %s storage pool" % poolname) + stgobj.build_pool(poolname) + display_pool_info(stgobj) + + if check_build_pool(path_value): + logger.info("build %s storage pool is successful" % poolname) + return 0 + else: + logger.error("fail to build %s storage pool" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_dir_pool.py b/repos/storage/create_dir_pool.py index 9f7e36c..d497fdb 100644 --- a/repos/storage/create_dir_pool.py +++ b/repos/storage/create_dir_pool.py @@ -109,19 +109,20 @@ def create_dir_pool(params): logger.debug("storage pool xml:\n%s" % poolxml) try: - logger.info("Creating %s storage pool" % poolname) - stgobj.create_pool(poolxml) - display_pool_info(stgobj, logger) - if check_pool_create(stgobj, poolname, logger): - logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) - return 0 - else: - logger.info("aa creating %s storage pool is UNSUCCESSFUL!!!" % poolname) + try: + logger.info("Creating %s storage pool" % poolname) + stgobj.create_pool(poolxml) + display_pool_info(stgobj, logger) + if check_pool_create(stgobj, poolname, logger): + logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) + return 0 + else: + logger.info("aa creating %s storage pool is UNSUCCESSFUL!!!" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_dir_volume.py b/repos/storage/create_dir_volume.py index e5e5cd7..6022e7b 100644 --- a/repos/storage/create_dir_volume.py +++ b/repos/storage/create_dir_volume.py @@ -174,12 +174,13 @@ def create_dir_volume(params): logger.debug("volume xml:\n%s" % volumexml) try: - logger.info("create %s volume" % volname) - stgobj.create_volume(poolname, volumexml) - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 + try: + logger.info("create %s volume" % volname) + stgobj.create_volume(poolname, volumexml) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_fs_pool.py b/repos/storage/create_fs_pool.py index 4338cad..887b91d 100644 --- a/repos/storage/create_fs_pool.py +++ b/repos/storage/create_fs_pool.py @@ -136,26 +136,27 @@ def create_fs_pool(params): logger.debug("storage pool xml:\n%s" % poolxml) try: - logger.info("Creating %s storage pool" % poolname) - stgobj.create_pool(poolxml) - display_pool_info(stgobj, logger) - if check_pool_create_libvirt(stgobj, poolname, logger): - logger.info("creating %s storage pool is in libvirt" % poolname) - if check_pool_create_OS(stgobj, poolname, logger): - logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) - return 0 + try: + logger.info("Creating %s storage pool" % poolname) + stgobj.create_pool(poolxml) + display_pool_info(stgobj, logger) + if check_pool_create_libvirt(stgobj, poolname, logger): + logger.info("creating %s storage pool is in libvirt" % poolname) + if check_pool_create_OS(stgobj, poolname, logger): + logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) + return 0 + else: + logger.info("creating %s storage pool is UNSUCCESSFUL!!!" % \ + poolname) + return 1 else: - logger.info("creating %s storage pool is UNSUCCESSFUL!!!" % \ - poolname) + logger.info("creating %s storage pool is \ + UNSUCCESSFUL in libvirt!!!" % poolname) return 1 - else: - logger.info("creating %s storage pool is \ - UNSUCCESSFUL in libvirt!!!" % poolname) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_iscsi_pool.py b/repos/storage/create_iscsi_pool.py index 11e345a..d642ddd 100644 --- a/repos/storage/create_iscsi_pool.py +++ b/repos/storage/create_iscsi_pool.py @@ -116,19 +116,20 @@ def create_iscsi_pool(params): logger.debug("storage pool xml:\n%s" % poolxml) try: - logger.info("Creating %s storage pool" % poolname) - stgobj.create_pool(poolxml) - display_pool_info(stgobj,logger) - if check_pool_create(stgobj, poolname,logger): - logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) - return 0 - else: - logger.info("creating %s storage pool is UNSUCCESSFUL!!!" % poolname) + try: + logger.info("Creating %s storage pool" % poolname) + stgobj.create_pool(poolxml) + display_pool_info(stgobj,logger) + if check_pool_create(stgobj, poolname,logger): + logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) + return 0 + else: + logger.info("creating %s storage pool is UNSUCCESSFUL!!!" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_logical_volume.py b/repos/storage/create_logical_volume.py index 43fdc42..e41bede 100644 --- a/repos/storage/create_logical_volume.py +++ b/repos/storage/create_logical_volume.py @@ -163,22 +163,23 @@ def create_logical_volume(params): display_physical_volume() try: - logger.info("create %s storage volume" % volname) - stgobj.create_volume(poolname, volxml) - display_physical_volume() - vol_num2 = get_storage_volume_number(stgobj, poolname) - display_volume_info(stgobj, poolname) - if check_volume_create(stgobj, poolname, volname, caps_kbyte) \ - and vol_num2 > vol_num1: - logger.info("create %s storage volume is successful" % volname) - return 0 - else: - logger.error("fail to crearte %s storage volume" % volname) + try: + logger.info("create %s storage volume" % volname) + stgobj.create_volume(poolname, volxml) + display_physical_volume() + vol_num2 = get_storage_volume_number(stgobj, poolname) + display_volume_info(stgobj, poolname) + if check_volume_create(stgobj, poolname, volname, caps_kbyte) \ + and vol_num2 > vol_num1: + logger.info("create %s storage volume is successful" % volname) + return 0 + else: + logger.error("fail to crearte %s storage volume" % volname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_netfs_pool.py b/repos/storage/create_netfs_pool.py index abe50f1..8ea781b 100644 --- a/repos/storage/create_netfs_pool.py +++ b/repos/storage/create_netfs_pool.py @@ -139,27 +139,28 @@ def create_netfs_pool(params): logger.debug("storage pool xml:\n%s" % poolxml) try: - logger.info("Creating %s storage pool" % poolname) - stgobj.create_pool(poolxml) - display_pool_info(stgobj, logger) - if check_pool_create_libvirt(stgobj, poolname, logger): - logger.info("creating %s storage pool is \ - successful in libvirt" % poolname) - if check_pool_create_OS(stgobj, poolname, logger): - logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) - return 0 + try: + logger.info("Creating %s storage pool" % poolname) + stgobj.create_pool(poolxml) + display_pool_info(stgobj, logger) + if check_pool_create_libvirt(stgobj, poolname, logger): + logger.info("creating %s storage pool is \ + successful in libvirt" % poolname) + if check_pool_create_OS(stgobj, poolname, logger): + logger.info("creating %s storage pool is SUCCESSFUL!!!" % poolname) + return 0 + else: + logger.info("creating %s storage pool is \ + UNSUCCESSFUL!!!" % poolname) + return 1 else: logger.info("creating %s storage pool is \ - UNSUCCESSFUL!!!" % poolname) + UNSUCCESSFUL in libvirt!!!" % poolname) return 1 - else: - logger.info("creating %s storage pool is \ - UNSUCCESSFUL in libvirt!!!" % poolname) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/create_netfs_volume.py b/repos/storage/create_netfs_volume.py index a62fd4d..65d1215 100644 --- a/repos/storage/create_netfs_volume.py +++ b/repos/storage/create_netfs_volume.py @@ -172,12 +172,13 @@ def create_netfs_volume(params): logger.debug("volume xml:\n%s" % volumexml) try: - logger.info("create %s volume" % volname) - stgobj.create_volume(poolname, volumexml) - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 + try: + logger.info("create %s volume" % volname) + stgobj.create_volume(poolname, volumexml) + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) + return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/define_dir_pool.py b/repos/storage/define_dir_pool.py index 757666f..03b15b7 100644 --- a/repos/storage/define_dir_pool.py +++ b/repos/storage/define_dir_pool.py @@ -35,7 +35,7 @@ from exception import LibvirtAPI VIRSH_POOLLIST = "virsh --quiet pool-list --all|awk '{print $1}'|grep \"^%s$\"" POOL_STAT = "virsh --quiet pool-list --all|grep \"^%s\\b\" |grep \"inactive\"" -POOL_DESTROY = "virsh pool-destroy %s" +POOL_DESTROY = "virsh pool-destroy %s" POOL_UNDEFINE = "virsh pool-undefine %s" def usage(params): @@ -110,21 +110,22 @@ def define_dir_pool(params): display_pool_info(stgobj, logger) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj, logger) - if check_pool_define(poolname, logger) and pool_num2 > pool_num1: - logger.info("define %s storage pool is successful" % poolname) - return 0 - else: - logger.error("%s storage pool is undefined" % poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj, logger) + if check_pool_define(poolname, logger) and pool_num2 > pool_num1: + logger.info("define %s storage pool is successful" % poolname) + return 0 + else: + logger.error("%s storage pool is undefined" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") @@ -133,7 +134,7 @@ def define_dir_pool(params): def define_dir_pool_clean(params): logger = params['logger'] - poolname = params['poolname'] + poolname = params['poolname'] (status, output) = commands.getstatusoutput(VIRSH_POOLLIST % poolname) if status: pass @@ -146,7 +147,7 @@ def define_dir_pool_clean(params): logger.error("failed to destroy storage pool %s" % poolname) logger.error("%s" % output) else: - (status, output) = commands.getstatusoutput(POOL_UNDEFINE % poolname) + (status, output) = commands.getstatusoutput(POOL_UNDEFINE % poolname) if status: logger.error("failed to undefine storage pool %s" % poolname) logger.error("%s" % output) @@ -156,5 +157,5 @@ def define_dir_pool_clean(params): logger.error("failed to undefine storage pool %s" % poolname) logger.error("%s" % output) - + diff --git a/repos/storage/define_disk_pool.py b/repos/storage/define_disk_pool.py index 85b6e7b..4b47814 100644 --- a/repos/storage/define_disk_pool.py +++ b/repos/storage/define_disk_pool.py @@ -125,22 +125,23 @@ def define_disk_pool(params): display_pool_info(stgobj) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj) - if check_pool_define(poolname) and pool_num2 > pool_num1: - logger.info("It is successful to define %s storage pool" % poolname) - return 0 - else: - logger.error("%s storage pool was not defined successfully" % \ - poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj) + if check_pool_define(poolname) and pool_num2 > pool_num1: + logger.info("It is successful to define %s storage pool" % poolname) + return 0 + else: + logger.error("%s storage pool was not defined successfully" % \ + poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/define_iscsi_pool.py b/repos/storage/define_iscsi_pool.py index 2066d19..5711159 100644 --- a/repos/storage/define_iscsi_pool.py +++ b/repos/storage/define_iscsi_pool.py @@ -123,21 +123,22 @@ def define_iscsi_pool(params): display_pool_info(stgobj, logger) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj, logger) - if check_pool_define(stgobj, poolname, logger) and pool_num2 > pool_num1: - logger.info("define %s storage pool is successful" % poolname) - return 0 - else: - logger.error("%s storage pool is undefined" % poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj, logger) + if check_pool_define(stgobj, poolname, logger) and pool_num2 > pool_num1: + logger.info("define %s storage pool is successful" % poolname) + return 0 + else: + logger.error("%s storage pool is undefined" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/define_logical_pool.py b/repos/storage/define_logical_pool.py index d97021d..71dbdeb 100644 --- a/repos/storage/define_logical_pool.py +++ b/repos/storage/define_logical_pool.py @@ -101,21 +101,22 @@ def define_logical_pool(params): display_pool_info(stgobj, logger) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj, logger) - if check_pool_define(poolname, logger) and pool_num2 > pool_num1: - logger.info("define %s storage pool is successful" % poolname) - return 0 - else: - logger.error("%s storage pool is undefined" % poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj, logger) + if check_pool_define(poolname, logger) and pool_num2 > pool_num1: + logger.info("define %s storage pool is successful" % poolname) + return 0 + else: + logger.error("%s storage pool is undefined" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/define_mpath_pool.py b/repos/storage/define_mpath_pool.py index 1a1f8fe..89db5ef 100644 --- a/repos/storage/define_mpath_pool.py +++ b/repos/storage/define_mpath_pool.py @@ -119,22 +119,23 @@ def define_mpath_pool(params): display_pool_info(stgobj) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj) - if check_pool_define(poolname) and pool_num2 > pool_num1: - logger.info("It is successful to define %s storage pool" % poolname) - return 0 - else: - logger.error("%s storage pool was not defined successfully" % \ - poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj) + if check_pool_define(poolname) and pool_num2 > pool_num1: + logger.info("It is successful to define %s storage pool" % poolname) + return 0 + else: + logger.error("%s storage pool was not defined successfully" % \ + poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/define_netfs_pool.py b/repos/storage/define_netfs_pool.py index 17988b7..68d7c86 100644 --- a/repos/storage/define_netfs_pool.py +++ b/repos/storage/define_netfs_pool.py @@ -102,21 +102,22 @@ def define_netfs_pool(params): display_pool_info(stgobj, logger) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj, logger) - if check_pool_define(poolname, logger) and pool_num2 > pool_num1: - logger.info("define %s storage pool is successful" % poolname) - return 0 - else: - logger.error("%s storage pool is undefined" % poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj, logger) + if check_pool_define(poolname, logger) and pool_num2 > pool_num1: + logger.info("define %s storage pool is successful" % poolname) + return 0 + else: + logger.error("%s storage pool is undefined" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/define_scsi_pool.py b/repos/storage/define_scsi_pool.py index b49f412..a5193e2 100644 --- a/repos/storage/define_scsi_pool.py +++ b/repos/storage/define_scsi_pool.py @@ -123,22 +123,23 @@ def define_scsi_pool(params): display_pool_info(stgobj) try: - logger.info("define %s storage pool" % poolname) - stgobj.define_pool(poolxml) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj) - if check_pool_define(poolname) and pool_num2 > pool_num1: - logger.info("It is successful to define %s storage pool" % poolname) - return 0 - else: - logger.error("%s storage pool was not defined successfully" % \ - poolname) + try: + logger.info("define %s storage pool" % poolname) + stgobj.define_pool(poolxml) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj) + if check_pool_define(poolname) and pool_num2 > pool_num1: + logger.info("It is successful to define %s storage pool" % poolname) + return 0 + else: + logger.error("%s storage pool was not defined successfully" % \ + poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/delete_dir_volume.py b/repos/storage/delete_dir_volume.py index 87cedc5..7e6c714 100644 --- a/repos/storage/delete_dir_volume.py +++ b/repos/storage/delete_dir_volume.py @@ -118,20 +118,21 @@ def delete_dir_volume(params): display_volume_info(stgobj, poolname) try: - logger.info("delete %s storage volume" % volname) - stgobj.delete_volume(poolname, volname) - vol_num2 = get_storage_volume_number(stgobj, poolname) - display_volume_info(stgobj, poolname) - if check_volume_delete(volkey) and vol_num1 > vol_num2: - logger.info("delete %s storage volume is successful" % volname) - return 0 - else: - logger.error("%s storage volume is undeleted" % volname) + try: + logger.info("delete %s storage volume" % volname) + stgobj.delete_volume(poolname, volname) + vol_num2 = get_storage_volume_number(stgobj, poolname) + display_volume_info(stgobj, poolname) + if check_volume_delete(volkey) and vol_num1 > vol_num2: + logger.info("delete %s storage volume is successful" % volname) + return 0 + else: + logger.error("%s storage volume is undeleted" % volname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/delete_logical_pool.py b/repos/storage/delete_logical_pool.py index 11f2130..c880aa3 100644 --- a/repos/storage/delete_logical_pool.py +++ b/repos/storage/delete_logical_pool.py @@ -115,21 +115,22 @@ def delete_logical_pool(params): display_physical_volume() try: - logger.info("delete %s storage pool" % poolname) - stgobj.delete_pool(poolname) - display_pool_info(stgobj) - display_physical_volume() - - if check_delete_pool(poolname): - logger.info("delete %s storage pool is successful" % poolname) - return 0 - else: - logger.error("fail to delete %s storage pool" % poolname) + try: + logger.info("delete %s storage pool" % poolname) + stgobj.delete_pool(poolname) + display_pool_info(stgobj) + display_physical_volume() + + if check_delete_pool(poolname): + logger.info("delete %s storage pool is successful" % poolname) + return 0 + else: + logger.error("fail to delete %s storage pool" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/delete_logical_volume.py b/repos/storage/delete_logical_volume.py index 528d4e6..3dc7036 100644 --- a/repos/storage/delete_logical_volume.py +++ b/repos/storage/delete_logical_volume.py @@ -136,22 +136,23 @@ def delete_logical_volume(params): display_volume_info(stgobj, poolname) display_physical_volume() try: - logger.info("delete %s storage volume" % volname) - stgobj.delete_volume(poolname, volname) - vol_num2 = get_storage_volume_number(stgobj, poolname) - display_volume_info(stgobj, poolname) - display_physical_volume() - - if vol_num1 > vol_num2 and check_volume_delete(poolname, volkey): - logger.info("delete %s storage volume is successful" % volname) - return 0 - else: - logger.error("fail to delete %s storage volume" % volname) + try: + logger.info("delete %s storage volume" % volname) + stgobj.delete_volume(poolname, volname) + vol_num2 = get_storage_volume_number(stgobj, poolname) + display_volume_info(stgobj, poolname) + display_physical_volume() + + if vol_num1 > vol_num2 and check_volume_delete(poolname, volkey): + logger.info("delete %s storage volume is successful" % volname) + return 0 + else: + logger.error("fail to delete %s storage volume" % volname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/delete_netfs_volume.py b/repos/storage/delete_netfs_volume.py index 69a5616..e719087 100644 --- a/repos/storage/delete_netfs_volume.py +++ b/repos/storage/delete_netfs_volume.py @@ -118,20 +118,21 @@ def delete_netfs_volume(params): display_volume_info(stgobj, poolname) try: - logger.info("delete %s storage volume" % volname) - stgobj.delete_volume(poolname, volname) - vol_num2 = get_storage_volume_number(stgobj, poolname) - display_volume_info(stgobj, poolname) - if check_volume_delete(volkey) and vol_num1 > vol_num2: - logger.info("delete %s storage volume is successful" % volname) - return 0 - else: - logger.error("%s storage volume is undeleted" % volname) + try: + logger.info("delete %s storage volume" % volname) + stgobj.delete_volume(poolname, volname) + vol_num2 = get_storage_volume_number(stgobj, poolname) + display_volume_info(stgobj, poolname) + if check_volume_delete(volkey) and vol_num1 > vol_num2: + logger.info("delete %s storage volume is successful" % volname) + return 0 + else: + logger.error("%s storage volume is undeleted" % volname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/pool_name.py b/repos/storage/pool_name.py index a91ea5a..15329c4 100644 --- a/repos/storage/pool_name.py +++ b/repos/storage/pool_name.py @@ -87,18 +87,19 @@ def pool_name(params): return 1 try: - UUIDString = stgobj.get_pool_uuidstring(poolname) - logger.info("the UUID string of pool %s is %s" % (poolname, UUIDString)) - if check_pool_uuid(poolname, UUIDString, logger): - logger.info(VIRSH_POOLNAME + " test succeeded.") - return 0 - else: - logger.error(VIRSH_POOLNAME + " test failed.") + try: + UUIDString = stgobj.get_pool_uuidstring(poolname) + logger.info("the UUID string of pool %s is %s" % (poolname, UUIDString)) + if check_pool_uuid(poolname, UUIDString, logger): + logger.info(VIRSH_POOLNAME + " test succeeded.") + return 0 + else: + logger.error(VIRSH_POOLNAME + " test failed.") + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/pool_uuid.py b/repos/storage/pool_uuid.py index 8bba936..ba92466 100644 --- a/repos/storage/pool_uuid.py +++ b/repos/storage/pool_uuid.py @@ -87,18 +87,19 @@ def pool_uuid(params): return 1 try: - UUIDString = stgobj.get_pool_uuidstring(poolname) - logger.info("the UUID string of pool %s is %s" % (poolname, UUIDString)) - if check_pool_uuid(poolname, UUIDString, logger): - logger.info(VIRSH_POOLUUID + " test succeeded.") - return 0 - else: - logger.error(VIRSH_POOLUUID + " test failed.") + try: + UUIDString = stgobj.get_pool_uuidstring(poolname) + logger.info("the UUID string of pool %s is %s" % (poolname, UUIDString)) + if check_pool_uuid(poolname, UUIDString, logger): + logger.info(VIRSH_POOLUUID + " test succeeded.") + return 0 + else: + logger.error(VIRSH_POOLUUID + " test failed.") + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" % \ + (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" % \ - (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") diff --git a/repos/storage/undefine_pool.py b/repos/storage/undefine_pool.py index 8cf9e46..8246926 100644 --- a/repos/storage/undefine_pool.py +++ b/repos/storage/undefine_pool.py @@ -108,21 +108,22 @@ def undefine_pool(params): display_pool_info(stgobj) try: - logger.info("undefine %s storage pool" % poolname) - stgobj.undefine_pool(poolname) - pool_num2 = stgobj.get_number_of_defpools() - logger.info("current storage pool define number: %s" % pool_num2) - display_pool_info(stgobj) - if check_pool_undefine(poolname) and pool_num2 < pool_num1: - logger.info("undefine %s storage pool is successful" % poolname) - return 0 - else: - logger.error("%s storage pool is undefined" % poolname) + try: + logger.info("undefine %s storage pool" % poolname) + stgobj.undefine_pool(poolname) + pool_num2 = stgobj.get_number_of_defpools() + logger.info("current storage pool define number: %s" % pool_num2) + display_pool_info(stgobj) + if check_pool_undefine(poolname) and pool_num2 < pool_num1: + logger.info("undefine %s storage pool is successful" % poolname) + return 0 + else: + logger.error("%s storage pool is undefined" % poolname) + return 1 + except LibvirtAPI, e: + logger.error("API error message: %s, error code is %s" \ + % (e.response()['message'], e.response()['code'])) return 1 - except LibvirtAPI, e: - logger.error("API error message: %s, error code is %s" \ - % (e.response()['message'], e.response()['code'])) - return 1 finally: conn.close() logger.info("closed hypervisor connection") -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list