def clear_resources(cls, resources=None): """Deletes resources, that were created in test suites. This method tries to remove resources from resource list, if it is not found, assume it was deleted in test itself. It is expected, that all resources were added as LIFO due to restriction of deletion resources, that are in the chain. :param resources: dict with keys 'type','id','client' and 'deleted' """ if resources is None: resources = cls.method_resources for res in resources: if "deleted" not in res: res["deleted"] = False if "client" not in res: res["client"] = cls.get_cleanup_client() if not(res["deleted"]): res_id = res['id'] client = res["client"] with handle_cleanup_exceptions(): # TODO(vponomaryov): add support for other resources if res["type"] is "share_type": client.delete_share_type(res_id) client.wait_for_share_type_deletion(res_id) elif res["type"] is "share_network": client.delete_share_network(res_id) client.wait_for_share_network_deletion(res_id) elif res["type"] is "share": client.delete_share(res_id) client.wait_for_share_deletion(res_id) else: LOG.warn("Provided unsupported resource type for " "cleanup '%s'. Skipping." % res["type"]) res["deleted"] = True
def delete_share(cls, shares_to_delete, share_group_id=None, wait=False, client=None, microversion=None): client = client or cls.get_admin_client() client.delete_share(shares_to_delete, share_group_id=share_group_id, wait=wait, microversion=microversion)
def clear_resources(cls, resources=None): """Deletes resources, that were created in test suites. This method tries to remove resources from resource list, if it is not found, assume it was deleted in test itself. It is expected, that all resources were added as LIFO due to restriction of deletion resources, that are in the chain. :param resources: dict with keys 'type','id','client' and 'deleted' """ if resources is None: resources = cls.method_resources for res in resources: if "deleted" not in res: res["deleted"] = False if "client" not in res: res["client"] = cls.get_cleanup_client() if not (res["deleted"]): res_id = res["id"] client = res["client"] with handle_cleanup_exceptions(): # TODO(vponomaryov): add support for other resources if res["type"] is "share_type": client.delete_share_type( res_id, microversion=res["microversion"]) client.wait_for_share_type_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "share_network": client.delete_share_network( res_id, microversion=res["microversion"]) client.wait_for_share_network_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "share": client.delete_share(res_id, microversion=res["microversion"]) client.wait_for_share_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "snapshot": client.delete_snapshot( res_id, microversion=res["microversion"]) client.wait_for_snapshot_deletion( res_id, microversion=res["microversion"]) else: LOG.warning( "Provided unsupported resource type for " "cleanup '%s'. Skipping.", res["type"]) res["deleted"] = True
def clear_resources(cls, resources=None): """Deletes resources, that were created in test suites. This method tries to remove resources from resource list, if it is not found, assume it was deleted in test itself. It is expected, that all resources were added as LIFO due to restriction of deletion resources, that are in the chain. :param resources: dict with keys 'type','id','client', 'deletion_params' and 'deleted'. Optional 'deletion_params' contains additional data needed to delete some type of resources. Ex: params = { 'type': 'share_network_subnet', 'id': 'share-network-subnet-id', 'client': None, 'deletion_params': { 'share_network': 'share-network-id', }, 'deleted': False, } """ if resources is None: resources = cls.method_resources for res in resources: if "deleted" not in res: res["deleted"] = False if "client" not in res: res["client"] = cls.get_cleanup_client() if not (res["deleted"]): res_id = res["id"] client = res["client"] deletion_params = res.get("deletion_params") with handle_cleanup_exceptions(): # TODO(vponomaryov): add support for other resources if res["type"] is "share_type": client.delete_share_type( res_id, microversion=res["microversion"]) client.wait_for_share_type_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "share_network": client.delete_share_network( res_id, microversion=res["microversion"]) client.wait_for_share_network_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "share_network_subnet": client.delete_share_network_subnet( share_network_subnet=res_id, share_network=deletion_params["share_network"], microversion=res["microversion"]) client.wait_for_share_network_subnet_deletion( share_network_subnet=res_id, share_network=deletion_params["share_network"], microversion=res["microversion"]) elif res["type"] is "share": client.delete_share(res_id, microversion=res["microversion"]) client.wait_for_share_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "snapshot": client.delete_snapshot( res_id, microversion=res["microversion"]) client.wait_for_snapshot_deletion( res_id, microversion=res["microversion"]) elif res["type"] is "share_replica": client.delete_share_replica( res_id, microversion=res["microversion"]) client.wait_for_share_replica_deletion( res_id, microversion=res["microversion"]) else: LOG.warning( "Provided unsupported resource type for " "cleanup '%s'. Skipping.", res["type"]) res["deleted"] = True