Commit 2495e32c authored by Tomas Hlavacek's avatar Tomas Hlavacek

Refactor graph generation and cover error path

Remove constants out of code and add error message to output when there
are no data produced by the show bgp ipv4/6 <prefix> command parser (or
BIRD equivalent - show route <prefix> all) and therefore no graph
can be generated. The error occures in situation when wrong prefix is
on input or the prefix has no paths in the routing table.
parent bdfac8fa
......@@ -29,6 +29,9 @@ import defaults
import ulgmodel
import ulggraph
STRING_BGP_GRAPH='BGP graph'
STRING_BGP_GRAPH_ERROR='Error: Can not produce image out of the received output.'
IPV46_SUBNET_REGEXP = '^[0-9a-fA-F:\.]+(/[0-9]{1,2}){0,1}$'
RTNAME_REGEXP = '^[a-zA-Z0-9]+$'
STRING_SYMBOL_ROUTING_TABLE = 'routing table'
......@@ -357,7 +360,10 @@ class BirdGraphShowRouteAll(ulgmodel.TextCommand):
def decorateResult(self,session,decorator_helper=None):
if(session.isFinished()):
return (decorator_helper.img(decorator_helper.getSpecialContentURL(session.getSessionId()),"BGP graph"),1)
if(session.getData() != None) and (session.getData() != []):
return (decorator_helper.img(decorator_helper.getSpecialContentURL(session.getSessionId()),STRING_BGP_GRAPH),1)
else:
return (STRING_BGP_GRAPH_ERROR, 1)
else:
return ('',0)
......
......@@ -31,6 +31,8 @@ import ulgmodel
import ulggraph
# module globals
STRING_BGP_GRAPH='BGP graph'
STRING_BGP_GRAPH_ERROR='Error: Can not produce image out of the received output.'
STRING_EXPECT_SSH_NEWKEY='Are you sure you want to continue connecting'
STRING_EXPECT_PASSWORD='(P|p)assword:'
STRING_EXPECT_SHELL_PROMPT_REGEXP = '\n[a-zA-Z0-9\._-]+>'
......@@ -600,7 +602,10 @@ class CiscoCommandGraphShowBgpIPv46Uni(ulgmodel.TextCommand):
def decorateResult(self,session,decorator_helper=None):
if(session.isFinished()):
return (decorator_helper.img(decorator_helper.getSpecialContentURL(session.getSessionId()),"BGP graph"),1)
if(session.getData() != None) and (session.getData() != []):
return (decorator_helper.img(decorator_helper.getSpecialContentURL(session.getSessionId()),STRING_BGP_GRAPH),1)
else:
return (STRING_BGP_GRAPH_ERROR, 1)
else:
return ('',0)
......@@ -609,6 +614,7 @@ class CiscoCommandGraphShowBgpIPv46Uni(ulgmodel.TextCommand):
def getSpecialContent(self,session,**params):
paths = session.getData()
ulgmodel.debug("CISCO GRAPH: "+str(paths))
print "Content-type: image/png\n"
ulggraph.bgp_graph_gen(reduce_bgp_paths(paths),start=session.getRouter().getName(),
end=session.getParameters()[0])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment