summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/common/check.py
diff options
context:
space:
mode:
authorthuva4 <tharma.thuva@gmail.com>2018-02-26 09:48:45 +0530
committerthuva4 <tharma.thuva@gmail.com>2018-03-01 12:29:16 +0530
commit4aa95918da586d3c1f9bf19a19c5cd55541c38d0 (patch)
treef822c1c3c658b9b76ecc8cf89bbfe53e8d850c7f /testapi/opnfv_testapi/common/check.py
parent7ac324f4b4bb2d190bf0888d12054663e095cc77 (diff)
Prevent to delete the pods
Do not allow to delete pods which are associated with test-results JIRA: RELENG-350 Change-Id: I8cb306d719acebff257048f08bcb981d81c64513 Signed-off-by: thuva4 <tharma.thuva@gmail.com>
Diffstat (limited to 'testapi/opnfv_testapi/common/check.py')
-rw-r--r--testapi/opnfv_testapi/common/check.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 7f866dd..77b48f5 100644
--- a/testapi/opnfv_testapi/common/check.py
+++ b/testapi/opnfv_testapi/common/check.py
@@ -35,7 +35,7 @@ def is_authorized(method):
if type(query) is not dict:
query_data = query()
else:
- if self.json_args is None:
+ if self.json_args is None or 'name' not in self.json_args:
query_data = query
else:
query_data = self.json_args
@@ -47,13 +47,22 @@ def is_authorized(method):
return wrapper
-def is_allowed(method):
+def is_reource_tied(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
- if self.table == 'projects':
- query_data = {}
- query_data['project_name'] = kwargs.get('query')['name']
- data = yield dbapi.db_find_one('testcases', query_data)
+ query_data = {}
+ tied_map_tables = {
+ 'projects': ('testcases', 'project_name'),
+ 'pods': ('results', 'pod_name'),
+ 'testcases': ('results', 'case_name')
+ }
+ if self.table in tied_map_tables:
+ if method.__name__ == '_update':
+ if 'name' not in self.json_args:
+ ret = yield gen.coroutine(method)(self, *args, **kwargs)
+ raise gen.Return(ret)
+ query_data[tied_map_tables[self.table][1]] = kwargs.get('query')['name']
+ data = yield dbapi.db_find_one(tied_map_tables[self.table][0], query_data)
if data:
raises.Unauthorized(message.tied_with_resource())
ret = yield gen.coroutine(method)(self, *args, **kwargs)