From 1d635add9ead358d000991bdbfd52fb06305c073 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 16 Jun 2014 16:44:05 -0400 Subject: [PATCH] Fix traces when trailing slashes are omitted from node resource collections When a url that could have been a valid resource collection with a trailing slash hits the daemon without a trailing slash, it would fail. Correct by recognizing this scenario and properly handling it. --- TODO | 18 ------------------ confluent_server/confluent/core.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 3f2b6667..ffbe0437 100644 --- a/TODO +++ b/TODO @@ -50,22 +50,4 @@ Traceback (most recent call last): AttributeError: 'str' object has no attribute 'iterkeys' [root@odin ~]# confetty / -> cd /nodes/n3 --Jun 11 14:51:49 Traceback (most recent call last): - File "/usr/lib/python2.6/site-packages/confluent/httpapi.py", line 238, in resourcehandler - for rsp in resourcehandler_backend(env, start_response): - File "/usr/lib/python2.6/site-packages/confluent/httpapi.py", line 358, in resourcehandler_backend - extension): - File "/usr/lib/python2.6/site-packages/confluent/httpapi.py", line 406, in _assemble_html - for rsp in responses: - File "/usr/lib/python2.6/site-packages/confluent/core.py", line 168, in stripnode - for i in iterablersp: - File "/usr/lib/python2.6/site-packages/confluent/plugins/hardwaremanagement/ipmi.py", line 196, in next - retdata = self.currdata.next() - File "/usr/lib/python2.6/site-packages/confluent/plugins/hardwaremanagement/ipmi.py", line 288, in health - response = self.ipmicmd.get_health() - File "/usr/lib/python2.6/site-packages/pyghmi/ipmi/command.py", line 301, in get_health - for reading in self.get_sensor_data(): - File "/usr/lib/python2.6/site-packages/pyghmi/ipmi/command.py", line 322, in get_sensor_data - raise Exception(rsp['error']) -Exception: Payload already active on another session -try to get 'health' without trailing / diff --git a/confluent_server/confluent/core.py b/confluent_server/confluent/core.py index 2d91ce94..b053478d 100644 --- a/confluent_server/confluent/core.py +++ b/confluent_server/confluent/core.py @@ -321,6 +321,13 @@ def handle_path(path, operation, configmanager, inputdata=None): return iterate_collections(configmanager.list_nodes()) if len(pathcomponents) == 2: iscollection = True + else: + try: + routespec = nested_lookup(noderesources, pathcomponents[2:]) + except KeyError: + raise exc.NotFoundException("Invalid element requested") + if isinstance(routespec, dict): + iscollection = True if iscollection: if operation == "delete": return delete_node_collection(pathcomponents, configmanager) @@ -330,10 +337,7 @@ def handle_path(path, operation, configmanager, inputdata=None): raise Exception("TODO here") del pathcomponents[0:2] passvalue = None - try: - plugroute = nested_lookup(noderesources, pathcomponents).routeinfo - except KeyError: - raise exc.NotFoundException("Invalid element requested") + plugroute = routespec.routeinfo inputdata = msg.get_input_message( pathcomponents, operation, inputdata, (node,)) if 'handler' in plugroute: # fixed handler definition