2 Library for the robot based system test tool of the OpenDaylight project.
4 This library will parse 'ovs-vstcl list Bridge' and 'ovs-vstcl list Controller'
5 commands and create dictionaries with parsed details which will be used
8 Authors: pgubka@cisco.com
18 def _parse_stdout(stdout):
19 """ Transforms stdout to dict """
20 text = stdout.replace(" ", "")
21 text = text.replace("\r", "")
22 pat = re.compile(r'(?P<key>\w+):(?P<value>.+)')
23 regroups = re.finditer(pat, text)
27 if g.group('key') == '_uuid':
28 cntl_uuid = g.group('value')
29 outdict[cntl_uuid] = {}
30 outdict[cntl_uuid][g.group('key')] = g.group('value')
34 def _postprocess_data(bridges, controllers):
36 - merge bridges and controllers
37 - replace controller 'key' (ip instead uuid)
38 - transformed controller's connected status to bool
40 brs = copy.deepcopy(bridges)
41 cntls = copy.deepcopy(controllers)
43 # replacing string value of is_connected key with boolean
44 for key, cntl in cntls.iteritems():
45 if cntl['is_connected'] == 'false':
46 cntl['is_connected'] = False
47 elif cntl['is_connected'] == 'true':
48 cntl['is_connected'] = True
50 cntl['is_connected'] = None
52 # replacing keys with the same values
53 for key, value in bridges.iteritems():
54 brs[value['name'][1:-1]] = brs[key]
57 for key, value in brs.iteritems():
58 # replace string with references with dict of controllers
59 ctl_refs = value['controller'][1:-1].split(',')
60 value['controller'] = {}
61 for ctl_ref in ctl_refs:
63 value['controller'][ctl_ref] = cntls[ctl_ref]
65 for brkey, bridge in brs.iteritems():
67 for cnkey, cntl in bridge['controller'].iteritems():
68 # port 6654 is set by OvsMAnager.robot to disconnect from controller
69 if '6653' in cntl['target'] or '6633' in cntl['target'] or '6654' in cntl['target']:
70 new_key = cntl['target'].split(":")[1] # getting middle from "tcp:ip:6653"
72 new_key = cntl['target'][1:-1] # getting string without quotes "ptcp:6638"
73 new_cntls[new_key] = cntl
74 bridge['controller'] = new_cntls
79 def parse(bridge_stdout, cntl_stdout):
80 """Produces dictionary with data for future usege
83 :param bridge_stdout: output of 'ovs-vsclt list Bridge' command
85 :param cntl_stdout: output of 'ovs-vsclt list Controller' command
88 :returns processed: processed output dictionary
90 :returns bridges: list bridge command output transformed to dist
92 :returns controllers: list controller command output transformed to dist
96 bridges = _parse_stdout(bridge_stdout)
97 controllers = _parse_stdout(cntl_stdout)
98 processed = _postprocess_data(bridges, controllers)
100 traceback.print_exc()
102 return processed, bridges, controllers