Merge ~hemanth-n/charm-telegraf:lp1903499 into charm-telegraf:master

Proposed by Hemanth Nakkina
Status: Superseded
Proposed branch: ~hemanth-n/charm-telegraf:lp1903499
Merge into: charm-telegraf:master
Diff against target: 87 lines (+48/-4)
2 files modified
src/files/telegraf_exec_metrics.py (+30/-1)
src/tests/unit/test_telegraf.py (+18/-3)
Reviewer Review Type Date Requested Status
Peter Sabaini (community) Needs Fixing
Benjamin Allot Approve
BootStack Reviewers Pending
Review via email: mp+394920@code.launchpad.net

This proposal has been superseded by a proposal from 2021-01-27.

Commit message

OvsDumpFlowsCmdMetric: Use openflow protocol version to dump the flows

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Benjamin Allot (ballot) wrote :

LGTM.

Ran the tests locally with success and looked at the commands and their output on a compute node.

Not top approving as it requires bootstack reviews.

review: Approve
Revision history for this message
Peter Sabaini (peter-sabaini) wrote :

Hey, thanks for the contribution.

I have only one minor nit inline.

Would it be possible to get some functional test coverage for this too?

Thank you,
peter.

review: Needs Fixing

Unmerged commits

8cb08fd... by Hemanth Nakkina

Fix OvsDumpFlowsCmdMetric to use correct openflow protocol

Currently ovs-ofctl dump the flows without specifying any
openflow protocol which leads to openflow version negotiation
warning messages in ovs-vswitchd daemon.

The fix gets the supported openflow protocol versions and use
the latest one for dump flows command.

Closes: #1903499

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/files/telegraf_exec_metrics.py b/src/files/telegraf_exec_metrics.py
2index 7f9bfc3..fe31c81 100755
3--- a/src/files/telegraf_exec_metrics.py
4+++ b/src/files/telegraf_exec_metrics.py
5@@ -360,8 +360,37 @@ class OvsDumpFlowsCmdMetric(CmdMetric):
6
7 # query OVS for the list of bridges
8 bridges = self.get_cmd_output(["sudo", ovs_vsctl, "list-br"]).split()
9+
10 for bridge in bridges:
11- cmd = ["sudo", ovs_ofctl, "dump-flows", bridge]
12+ # find openflow protocol supported
13+ bridge_details_cmd = [
14+ "sudo",
15+ ovs_vsctl,
16+ "-f",
17+ "json",
18+ "find",
19+ "bridge",
20+ "name=" + bridge,
21+ ]
22+ bridge_details = self.get_cmd_output(bridge_details_cmd, is_json=True)
23+ protocol_index = bridge_details["headings"].index("protocols")
24+ # Ex: br_int_details['data'][0][protocol_index] is in format
25+ # ['set', ['OpenFlow13', 'OpenFlow15']]]
26+ supported_protocols = bridge_details["data"][0][protocol_index][1]
27+
28+ if supported_protocols:
29+ # pick the latest openflow protocol version
30+ cmd = [
31+ "sudo",
32+ ovs_ofctl,
33+ "dump-flows",
34+ "-O",
35+ supported_protocols[-1],
36+ bridge,
37+ ]
38+ else:
39+ cmd = ["sudo", ovs_ofctl, "dump-flows", bridge]
40+
41 output = self.get_cmd_output(cmd)
42 flows[bridge] = output
43
44diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py
45index afc3625..d13dedb 100644
46--- a/src/tests/unit/test_telegraf.py
47+++ b/src/tests/unit/test_telegraf.py
48@@ -457,8 +457,12 @@ def test_ovs_dump_flows_cmd_metric(monkeypatch):
49 def mock_check_output(*args, **kwargs):
50 """Mock the subprocess calls to the OVS tools."""
51 cmd = args[0][1]
52- if cmd == "ovs-vsctl":
53- return b"br-ex\n"
54+ if cmd == "ovs-vsctl" and args[0][2] == "list-br":
55+ return b"br-ex\nbr-data\n"
56+ elif cmd == "ovs-vsctl" and args[0][6] == "name=br-ex":
57+ return b'{"data":[[["uuid","8267c260-81d5-4a06-848f-711b82d9bf4b"],["set",[]],["set",[]],"000062c26782064a","system","<unknown>",["map",[]],["set",[]],["set",[]],["map",[]],["set",[]],false,["set",[]],"br-ex",["set",[]],["map",[]],["uuid","c1b763d1-a706-46af-98a8-4b4bd0125249"],["set",[]],false,["map",[]],["set",[]],["map",[]],false]],"headings":["_uuid","auto_attach","controller","datapath_id","datapath_type","datapath_version","external_ids","fail_mode","flood_vlans","flow_tables","ipfix","mcast_snooping_enable","mirrors","name","netflow","other_config","ports","protocols","rstp_enable","rstp_status","sflow","status","stp_enable"]}' # noqa E501
58+ elif cmd == "ovs-vsctl" and args[0][6] == "name=br-data":
59+ return b'{"data":[[["uuid","8267c260-81d5-4a06-848f-711b82d9bf4c"],["set",[]],["set",[]],"000062c26782064b","system","<unknown>",["map",[]],["set",[]],["set",[]],["map",[]],["set",[]],false,["set",[]],"br-data",["set",[]],["map",[]],["uuid","c1b763d1-a706-46af-98a8-4b4bd0125250"],["set",["OpenFlow13", "OpenFlow15"]],false,["map",[]],["set",[]],["map",[]],false]],"headings":["_uuid","auto_attach","controller","datapath_id","datapath_type","datapath_version","external_ids","fail_mode","flood_vlans","flow_tables","ipfix","mcast_snooping_enable","mirrors","name","netflow","other_config","ports","protocols","rstp_enable","rstp_status","sflow","status","stp_enable"]}' # noqa E501
60 elif (
61 cmd == "ovs-ofctl" and args[0][3] == "br-ex"
62 ): # sudo ovs-ofctl dump-flows br-ex
63@@ -467,6 +471,14 @@ def test_ovs_dump_flows_cmd_metric(monkeypatch):
64 b' cookie=0x3711311ec90146a9, duration=247966.151s, table=0, n_packets=0, n_bytes=0, priority=2,in_port="phy-br-ex" actions=drop\n' # noqa E501
65 b" cookie=0x3711311ec90146a9, duration=247966.175s, table=0, n_packets=2192, n_bytes=156148, priority=0 actions=NORMAL\n" # noqa E501
66 )
67+ elif (
68+ cmd == "ovs-ofctl" and args[0][5] == "br-data"
69+ ): # sudo ovs-ofctl dump-flows br-data
70+ return (
71+ b"NXST_FLOW reply (xid=0x4):\n"
72+ b' cookie=0x3711311ec90146a0, duration=247966.151s, table=0, n_packets=0, n_bytes=0, priority=2,in_port="phy-br-data" actions=drop\n' # noqa E501
73+ b" cookie=0x3711311ec90146a0, duration=247966.175s, table=0, n_packets=2192, n_bytes=156148, priority=0 actions=NORMAL\n" # noqa E501
74+ )
75 else:
76 raise Exception("unexpected argument: {}".format(args))
77
78@@ -479,7 +491,10 @@ def test_ovs_dump_flows_cmd_metric(monkeypatch):
79
80 raw_output = metric.get_input_content()
81 parsed_output = metric.parse(raw_output)
82- expected_output = [{"bridge": "br-ex", "count": 2}]
83+ expected_output = [
84+ {"bridge": "br-ex", "count": 2},
85+ {"bridge": "br-data", "count": 2},
86+ ]
87 assert parsed_output == expected_output
88
89

Subscribers

People subscribed via source and target branches

to all changes: