Message ID | 20240105114702.443465-3-amorenoz@redhat.com |
---|---|
State | Changes Requested |
Delegated to: | Simon Horman |
Headers | show |
Series | python: Miscelaneous flow parsing fixes. | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/intel-ovs-compilation | fail | test: fail |
On Fri, Jan 05, 2024 at 12:46:54PM +0100, Adrian Moreno wrote: > Parsing of info and matches was being tested as generic k-v parsing. > Also verify we don't find any unexpected field. > > Signed-off-by: Adrian Moreno <amorenoz@redhat.com> > --- > python/ovs/tests/test_ofp.py | 73 +++++++++++++++++++++++++++--------- > 1 file changed, 55 insertions(+), 18 deletions(-) > > diff --git a/python/ovs/tests/test_ofp.py b/python/ovs/tests/test_ofp.py > index 27bcf0c47..5d2736ab4 100644 > --- a/python/ovs/tests/test_ofp.py > +++ b/python/ovs/tests/test_ofp.py > @@ -6,6 +6,30 @@ from ovs.flow.kv import KeyValue, ParseError > from ovs.flow.decoders import EthMask, IPMask, decode_mask > > > +def do_test_section(input_string, section, expected): > + flow = OFPFlow(input_string) > + kv_list = flow.section(section).data > + > + for i in range(len(expected)): > + assert expected[i].key == kv_list[i].key > + assert expected[i].value == kv_list[i].value > + > + # Assert positions relative to action string are OK. > + pos = flow.section(section).pos > + string = flow.section(section).string > + > + kpos = kv_list[i].meta.kpos > + kstr = kv_list[i].meta.kstring > + vpos = kv_list[i].meta.vpos > + vstr = kv_list[i].meta.vstring > + assert string[kpos : kpos + len(kstr)] == kstr > + if vpos != -1: > + assert string[vpos : vpos + len(vstr)] == vstr > + > + # Assert string meta is correct. > + assert input_string[pos : pos + len(string)] == string Hi Adrian, I'm probably missing something obvious. But I wonder if there a possibility that kv_list contains more elements than expected, and if so, is that something we should check for? > + > + > @pytest.mark.parametrize( > "input_string,expected", > [ ...
On 1/5/24 16:16, Simon Horman wrote: > On Fri, Jan 05, 2024 at 12:46:54PM +0100, Adrian Moreno wrote: >> Parsing of info and matches was being tested as generic k-v parsing. >> Also verify we don't find any unexpected field. >> >> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> >> --- >> python/ovs/tests/test_ofp.py | 73 +++++++++++++++++++++++++++--------- >> 1 file changed, 55 insertions(+), 18 deletions(-) >> >> diff --git a/python/ovs/tests/test_ofp.py b/python/ovs/tests/test_ofp.py >> index 27bcf0c47..5d2736ab4 100644 >> --- a/python/ovs/tests/test_ofp.py >> +++ b/python/ovs/tests/test_ofp.py >> @@ -6,6 +6,30 @@ from ovs.flow.kv import KeyValue, ParseError >> from ovs.flow.decoders import EthMask, IPMask, decode_mask >> >> >> +def do_test_section(input_string, section, expected): >> + flow = OFPFlow(input_string) >> + kv_list = flow.section(section).data >> + >> + for i in range(len(expected)): >> + assert expected[i].key == kv_list[i].key >> + assert expected[i].value == kv_list[i].value >> + >> + # Assert positions relative to action string are OK. >> + pos = flow.section(section).pos >> + string = flow.section(section).string >> + >> + kpos = kv_list[i].meta.kpos >> + kstr = kv_list[i].meta.kstring >> + vpos = kv_list[i].meta.vpos >> + vstr = kv_list[i].meta.vstring >> + assert string[kpos : kpos + len(kstr)] == kstr >> + if vpos != -1: >> + assert string[vpos : vpos + len(vstr)] == vstr >> + >> + # Assert string meta is correct. >> + assert input_string[pos : pos + len(string)] == string > > Hi Adrian, > > I'm probably missing something obvious. > But I wonder if there a possibility that kv_list contains more elements > than expected, and if so, is that something we should check for? > That's a good point. We could also assert on the length of kv_list. I'll send another version. >> + >> + >> @pytest.mark.parametrize( >> "input_string,expected", >> [ > > ... >
diff --git a/python/ovs/tests/test_ofp.py b/python/ovs/tests/test_ofp.py index 27bcf0c47..5d2736ab4 100644 --- a/python/ovs/tests/test_ofp.py +++ b/python/ovs/tests/test_ofp.py @@ -6,6 +6,30 @@ from ovs.flow.kv import KeyValue, ParseError from ovs.flow.decoders import EthMask, IPMask, decode_mask +def do_test_section(input_string, section, expected): + flow = OFPFlow(input_string) + kv_list = flow.section(section).data + + for i in range(len(expected)): + assert expected[i].key == kv_list[i].key + assert expected[i].value == kv_list[i].value + + # Assert positions relative to action string are OK. + pos = flow.section(section).pos + string = flow.section(section).string + + kpos = kv_list[i].meta.kpos + kstr = kv_list[i].meta.kstring + vpos = kv_list[i].meta.vpos + vstr = kv_list[i].meta.vstring + assert string[kpos : kpos + len(kstr)] == kstr + if vpos != -1: + assert string[vpos : vpos + len(vstr)] == vstr + + # Assert string meta is correct. + assert input_string[pos : pos + len(string)] == string + + @pytest.mark.parametrize( "input_string,expected", [ @@ -570,27 +594,40 @@ from ovs.flow.decoders import EthMask, IPMask, decode_mask def test_act(input_string, expected): if isinstance(expected, type): with pytest.raises(expected): - ofp = OFPFlow(input_string) + OFPFlow(input_string) return - ofp = OFPFlow(input_string) - actions = ofp.actions_kv + do_test_section(input_string, "actions", expected) - for i in range(len(expected)): - assert expected[i].key == actions[i].key - assert expected[i].value == actions[i].value - # Assert positions relative to action string are OK. - apos = ofp.section("actions").pos - astring = ofp.section("actions").string +@pytest.mark.parametrize( + "input_string,expected", + [ + ( + "cookie=0x35f946ead8d8f9e4, duration=97746.271s, table=0, n_packets=12, n_bytes=254, priority=4,in_port=1", # noqa: E501 + ( + [ + KeyValue("cookie", 0x35f946ead8d8f9e4), + KeyValue("duration", 97746.271), + KeyValue("table", 0), + KeyValue("n_packets", 12), + KeyValue("n_bytes", 254), + ], + [ + KeyValue("priority", 4), + KeyValue("in_port", 1) + ], + ), + ), + ], +) +def test_key(input_string, expected): + if isinstance(expected, type): + with pytest.raises(expected): + OFPFlow(input_string) + return - kpos = actions[i].meta.kpos - kstr = actions[i].meta.kstring - vpos = actions[i].meta.vpos - vstr = actions[i].meta.vstring - assert astring[kpos : kpos + len(kstr)] == kstr - if vpos != -1: - assert astring[vpos : vpos + len(vstr)] == vstr + input_string += " actions=drop" - # Assert astring meta is correct. - assert input_string[apos : apos + len(astring)] == astring + do_test_section(input_string, "info", expected[0]) + do_test_section(input_string, "match", expected[1])
Parsing of info and matches was being tested as generic k-v parsing. Also verify we don't find any unexpected field. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> --- python/ovs/tests/test_ofp.py | 73 +++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 18 deletions(-)