diff --git a/src/python/WMCore/Services/ReqMgr/ReqMgr.py b/src/python/WMCore/Services/ReqMgr/ReqMgr.py index 4902799e77..acccc06e87 100644 --- a/src/python/WMCore/Services/ReqMgr/ReqMgr.py +++ b/src/python/WMCore/Services/ReqMgr/ReqMgr.py @@ -81,78 +81,67 @@ def getRequestByNames(self, names): query = self._createQuery({'name': names}) callname = 'request?%s' % query - #return self._getResult(callname, verb = "GET") - return self["requests"].get(callname) + return self._getResult(callname, verb = "GET")['result'] def getRequestByStatus(self, statusList, detail = False): """ _getRequestByStatus_ - returns tuples with following format - ({'result': [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], + returns list of requests + [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], 'BlockWhitelist': [], 'CMSSWVersion': 'CMSSW_4_4_2_patch2', .... '_id': 'test_RequestString-OVERRIDE-ME_141125_142331_4966', - 'inputMode': 'couchDB'}}]}, - 200, - 'OK', - False) + 'inputMode': 'couchDB'}}] """ query = self._createQuery({'status': statusList}) callname = 'request?%s' % query - #return self._getResult(callname, verb = "GET") - return self["requests"].get(callname) - + return self._getResult(callname, verb = "GET")['result'] def insertRequests(self, requestDict): """ _insertRequests_ - returns tuples with following format - ({'result': [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], + returns list with following format + [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], 'BlockWhitelist': [], 'CMSSWVersion': 'CMSSW_4_4_2_patch2', .... '_id': 'test_RequestString-OVERRIDE-ME_141125_142331_4966', - 'inputMode': 'couchDB'}}]}, - 200, - 'OK', - False) + 'inputMode': 'couchDB'}}] + need proper error handling if status is not 200 from orignal reporting. """ - return self["requests"].post('request', requestDict) + return self["requests"].post('request', requestDict)[0]['result'] def updateRequestStatus(self, request, status): """ _updateRequestStatus_ - returns tuples with following format - ({'result': [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], + returns list with following format + [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], 'BlockWhitelist': [], 'CMSSWVersion': 'CMSSW_4_4_2_patch2', .... '_id': 'test_RequestString-OVERRIDE-ME_141125_142331_4966', - 'inputMode': 'couchDB'}}]}, - 200, - 'OK', - False) + 'inputMode': 'couchDB'}}] + need proper error handling if status is not 200 from orignal reporting. """ status = {"RequestStatus": status} - return self["requests"].put('request/%s' % request, status) + return self["requests"].put('request/%s' % request, status)[0]['result'] def updateRequestProperty(self, request, propDict): """ _updateRequestProperty_ - returns tuples with following format - ({'result': [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], + returns list with following format + [{'test_RequestString-OVERRIDE-ME_141125_142331_4966': {'BlockBlacklist': [], 'BlockWhitelist': [], 'CMSSWVersion': 'CMSSW_4_4_2_patch2', .... '_id': 'test_RequestString-OVERRIDE-ME_141125_142331_4966', - 'inputMode': 'couchDB'}}]}, - 200, - 'OK', - False) + 'inputMode': 'couchDB'}}] + need proper error handling if status is not 200 from orignal reporting. + ({'result': data}, status_code, response, cache_flag) """ - return self["requests"].put('request/%s' % request, propDict) + return self["requests"].put('request/%s' % request, propDict)[0]['result'] diff --git a/src/python/WMCore/Services/Service.py b/src/python/WMCore/Services/Service.py index 8cbfcd29a0..152ebcb5ff 100644 --- a/src/python/WMCore/Services/Service.py +++ b/src/python/WMCore/Services/Service.py @@ -136,7 +136,7 @@ def __init__(self, cfg_dict = {}): # either passed as param to __init__, determine via scheme or default if type(self.get('requests')) == types.TypeType: requests = self['requests'] - elif (self['accept_type'] == "application/json" and self['content_type'] == "application/json"): + elif (self.get('accept_type') == "application/json" and self.get('content_type') == "application/json"): requests = JSONRequests else: requests = Requests @@ -292,7 +292,10 @@ def getData(self, cachefile, url, inputdata = {}, incoming_headers = {}, cachefile.seek (0, 0) # return to beginning of file else: f = open(cachefile, 'w') - f.write(str(data)) + if isinstance(data, dict) or isinstance(data, list): + f.write(json.dumps(data)) + else: + f.write(str(data)) f.close() diff --git a/test/python/WMCore_t/Services_t/ReqMgr_t/ReqMgr_t.py b/test/python/WMCore_t/Services_t/ReqMgr_t/ReqMgr_t.py index 16975e8323..7945ebe2f9 100644 --- a/test/python/WMCore_t/Services_t/ReqMgr_t/ReqMgr_t.py +++ b/test/python/WMCore_t/Services_t/ReqMgr_t/ReqMgr_t.py @@ -98,28 +98,22 @@ def testRequestSimpleCycle(self): response = self.reqSvc.insertRequests(self.rerecoCreateArgs) from pprint import pprint pprint(response) - self.assertEqual(response[1], 200) - requestName = response[0]['result'][0]['RequestName'] + self.assertEqual(len(response), 1) + requestName = response[0]['RequestName'] ## test get method # get by name response = self.reqSvc.getRequestByNames(requestName) - pprint(response) - self.assertEqual(response[1], 200, "get by name") - self.assertEqual(self.resultLength(response), 1) + self.assertEqual(len(response), 1) # get by status response = self.reqSvc.getRequestByStatus('new') - pprint(response) - self.assertEqual(response[1], 200, "get by status") - self.assertEqual(self.resultLength(response), 1) + self.assertEqual(len(response), 1) self.reqSvc.updateRequestStatus(requestName, 'assignment-approved') - pprint(response) response = self.reqSvc.getRequestByStatus('assignment-approved') - self.assertEqual(response[1], 200, "get by status") - self.assertEqual(self.resultLength(response), 1) + self.assertEqual(len(response), 1) if __name__ == '__main__': unittest.main()