Skip to content

Commit

Permalink
Add DELETE Method for debug actions (#334)
Browse files Browse the repository at this point in the history
* Add DELETE Method for debug actions

* Pylint fixes
  • Loading branch information
juztas authored Oct 10, 2023
1 parent bd0406e commit 9217aff
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/python/SiteFE/REST/Modules/DebugCalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def __urlParams(self):
'getalldebughostname': {'allowedMethods': ['GET']},
'getalldebughostnameactive': {'allowedMethods': ['GET']},
'submitdebug': {'allowedMethods': ['PUT', 'POST']},
'updatedebug': {'allowedMethods': ['PUT', 'POST']}}
'updatedebug': {'allowedMethods': ['PUT', 'POST']},
'deletedebug': {'allowedMethods': ['DELETE']}}
self.urlParams.update(urlParams)

def __defineRoutes(self):
Expand All @@ -164,6 +165,7 @@ def __defineRoutes(self):
self.routeMap.connect("getalldebughostnameactive", "/json/frontend/getalldebughostnameactive/:debugvar", action="getalldebughostnameactive")
self.routeMap.connect("submitdebug", "/json/frontend/submitdebug/:debugvar", action="submitdebug")
self.routeMap.connect("updatedebug", "/json/frontend/updatedebug/:debugvar", action="updatedebug")
self.routeMap.connect("deletedebug", "/json/frontend/deletedebug/:debugvar", action="deletedebug")

def getdebug(self, environ, **kwargs):
"""Get Debug action for specific ID."""
Expand Down Expand Up @@ -221,3 +223,9 @@ def updatedebug(self, environ, **kwargs):
updOut = self.dbI.update('debugrequests', [out])
self.responseHeaders(environ, **kwargs)
return {'Status': updOut[0], 'ID': updOut[2]}

def deletedebug(self, environ, **kwargs):
"""Delete debug action information."""
updOut = self.dbI.delete('debugrequests', [['id', kwargs['debugvar']]])
self.responseHeaders(environ, **kwargs)
return {'Status': updOut[0], 'ID': updOut[2]}
2 changes: 1 addition & 1 deletion src/python/SiteFE/REST/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def checkIfMethodAllowed(self, environ, actionName):
print(f'Warning. Undefined behavior. Allowed Methods not defined for {actionName}')
return
if environ['REQUEST_METHOD'].upper() not in self.urlParams[actionName].get('allowedMethods', []):
raise MethodNotSupported("Method not supported")
raise MethodNotSupported(f"Method {environ['REQUEST_METHOD'].upper()} not supported.")
return

def responseHeaders(self, environ, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions test/test-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

hostname: https://sense-caltech-fe.sdn-lb.ultralight.org
sitename: T2_US_Caltech_Test
hostname: https://sense-caltech-dev.sdn-lb.ultralight.org
sitename: T3_US_Caltech_Dev
cert: /etc/grid-security/hostcert.pem
key: /etc/grid-security/hostkey.pem
18 changes: 15 additions & 3 deletions test/test-fe-debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ def debugActions(cls, dataIn, dataUpd):
# GET
urlg = f"/{cls.PARAMS['sitename']}/sitefe/json/frontend/getdebug/{outs[0]['ID']}"
outg = makeRequest(cls, urlg, {'verb': 'GET', 'data': {}})
cls.assertEqual(outg[1], 200, msg=f'{str(outs)}')
cls.assertEqual(outg[2], 'OK', msg=f'{str(outs)}')
cls.assertEqual(outg[1], 200, msg=f'{str(outg)}')
cls.assertEqual(outg[2], 'OK', msg=f'{str(outg)}')


def deleteDebug(cls, out):
"""Test Delete Debug entries"""
# DELETE
for item in out:
urlg = f"/{cls.PARAMS['sitename']}/sitefe/json/frontend/deletedebug/{item['id']}"
outg = makeRequest(cls, urlg, {'verb': 'DELETE', 'data': {}})
cls.assertEqual(outg[1], 200, msg=f'{str(outg)}')
cls.assertEqual(outg[2], 'OK', msg=f'{str(outg)}')


class TestUtils(unittest.TestCase):
Expand Down Expand Up @@ -64,10 +74,12 @@ def test_debug_prometheus_push(self):
dataupd = {'state': 'active', 'output': json.dumps(outsuc)}
debugActions(self, data, dataupd)

url = f"/{self.PARAMS['sitename']}/sitefe/json/frontend/getalldebughostnameactive/dummyhostname"
url = f"/{self.PARAMS['sitename']}/sitefe/json/frontend/getdebug/ALL"
out = makeRequest(self, url, {'verb': 'GET', 'data': {}})
self.assertEqual(out[1], 200, msg=f'{str(out)}')
self.assertEqual(out[2], 'OK', msg=f'{str(out)}')
# Delete
deleteDebug(self, out[0])


if __name__ == '__main__':
Expand Down
5 changes: 5 additions & 0 deletions test/test-fe.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def debugActions(cls, dataIn, dataUpd):
outu = makeRequest(cls, urlu, {'verb': 'PUT', 'data': dataUpd})
cls.assertEqual(outu[1], 200)
cls.assertEqual(outu[2], 'OK')
# DELETE
urld = f"/{cls.PARAMS['sitename']}/sitefe/json/frontend/deletedebug/{outs[0]['ID']}"
outd = makeRequest(cls, urld, {'verb': 'DELETE', 'data': {}})
cls.assertEqual(outd[1], 200)
cls.assertEqual(outd[2], 'OK')


class TestUtils(unittest.TestCase):
Expand Down

0 comments on commit 9217aff

Please sign in to comment.