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
17 def _parse_stdout(stdout):
18 """ Transforms stdout to dict """
19 text = stdout.replace(" ", "")
20 text = text.replace("\r", "")
21 pat = re.compile(r"(?P<key>\w+):(?P<value>.+)")
22 regroups = re.finditer(pat, text)
26 if g.group("key") == "_uuid":
27 cntl_uuid = g.group("value")
28 outdict[cntl_uuid] = {}
29 outdict[cntl_uuid][g.group("key")] = g.group("value")
33 def _postprocess_data(bridges, controllers):
35 - merge bridges and controllers
36 - replace controller 'key' (ip instead uuid)
37 - transformed controller's connected status to bool
39 brs = copy.deepcopy(bridges)
40 cntls = copy.deepcopy(controllers)
42 # replacing string value of is_connected key with boolean
43 for key, cntl in cntls.items():
44 if cntl["is_connected"] == "false":
45 cntl["is_connected"] = False
46 elif cntl["is_connected"] == "true":
47 cntl["is_connected"] = True
49 cntl["is_connected"] = None
51 # replacing keys with the same values
52 for key, value in bridges.items():
53 brs[value["name"][1:-1]] = brs[key]
56 for key, value in brs.items():
57 # replace string with references with dict of controllers
58 ctl_refs = value["controller"][1:-1].split(",")
59 value["controller"] = {}
60 for ctl_ref in ctl_refs:
62 value["controller"][ctl_ref] = cntls[ctl_ref]
64 for brkey, bridge in brs.items():
66 for cnkey, cntl in bridge["controller"].items():
67 # port 6654 is set by OvsMAnager.robot to disconnect from controller
69 "6653" in cntl["target"]
70 or "6633" in cntl["target"]
71 or "6654" in cntl["target"]
73 new_key = cntl["target"].split(":")[
75 ] # getting middle from "tcp:ip:6653"
77 new_key = cntl["target"][
79 ] # getting string without quotes "ptcp:6638"
80 new_cntls[new_key] = cntl
81 bridge["controller"] = new_cntls
86 def parse(bridge_stdout, cntl_stdout):
87 """Produces dictionary with data for future usege
90 :param bridge_stdout: output of 'ovs-vsclt list Bridge' command
92 :param cntl_stdout: output of 'ovs-vsclt list Controller' command
95 :returns processed: processed output dictionary
97 :returns bridges: list bridge command output transformed to dist
99 :returns controllers: list controller command output transformed to dist
103 bridges = _parse_stdout(bridge_stdout)
104 controllers = _parse_stdout(cntl_stdout)
105 processed = _postprocess_data(bridges, controllers)
107 traceback.print_exc()
109 return processed, bridges, controllers