X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=api%2Fresources%2Fv2%2Fprojects.py;h=2ff61d0fe0b3865dfaad1871697e5e81366efeb0;hb=326ca99184b896d75266737466516846df29b447;hp=7d51cf0409a6a6d98bca5706f5fb39c4d8ac1e4b;hpb=6bc4d2c813460cba201c390cc2380fb99bdc2c9d;p=yardstick.git diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py index 7d51cf040..2ff61d0fe 100644 --- a/api/resources/v2/projects.py +++ b/api/resources/v2/projects.py @@ -1,13 +1,26 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## import uuid +import logging from datetime import datetime from api import ApiResource from api.database.v2.handlers import V2ProjectHandler +from api.database.v2.handlers import V2TaskHandler from yardstick.common.utils import result_handler from yardstick.common.utils import change_obj_to_dict from yardstick.common import constants as consts +LOG = logging.getLogger(__name__) +LOG.setLevel(logging.DEBUG) + class V2Projects(ApiResource): @@ -63,3 +76,30 @@ class V2Project(ApiResource): project_info['tasks'] = tasks.split(',') if tasks else [] return result_handler(consts.API_SUCCESS, {'project': project_info}) + + def delete(self, project_id): + try: + uuid.UUID(project_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid project id') + + project_handler = V2ProjectHandler() + try: + project = project_handler.get_by_uuid(project_id) + except ValueError: + return result_handler(consts.API_ERROR, 'no such project id') + + if project.tasks: + LOG.info('delete related task') + task_handler = V2TaskHandler() + for task_id in project.tasks.split(','): + LOG.debug('delete task: %s', task_id) + try: + task_handler.delete_by_uuid(task_id) + except ValueError: + LOG.exception('no such task id: %s', task_id) + + LOG.info('delete project in database') + project_handler.delete_by_uuid(project_id) + + return result_handler(consts.API_SUCCESS, {'project': project_id})