mirror of
https://github.com/openvswitch/ovs
synced 2025-10-15 14:17:18 +00:00
python: tests: Add info and key tests for OFPFlows.
Parsing of info and matches was being tested as generic k-v parsing. Also verify we don't find any unexpected field. Also, verify the length of the kv_list meets the expectations. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Simon Horman <horms@ovn.org>
This commit is contained in:
committed by
Simon Horman
parent
6bbbb76642
commit
9ef49ca85b
@@ -6,6 +6,32 @@ from ovs.flow.kv import KeyValue, ParseError
|
|||||||
from ovs.flow.decoders import EthMask, IPMask, decode_mask
|
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
|
||||||
|
|
||||||
|
assert len(expected) == len(kv_list)
|
||||||
|
|
||||||
|
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(
|
@pytest.mark.parametrize(
|
||||||
"input_string,expected",
|
"input_string,expected",
|
||||||
[
|
[
|
||||||
@@ -570,27 +596,40 @@ from ovs.flow.decoders import EthMask, IPMask, decode_mask
|
|||||||
def test_act(input_string, expected):
|
def test_act(input_string, expected):
|
||||||
if isinstance(expected, type):
|
if isinstance(expected, type):
|
||||||
with pytest.raises(expected):
|
with pytest.raises(expected):
|
||||||
ofp = OFPFlow(input_string)
|
OFPFlow(input_string)
|
||||||
return
|
return
|
||||||
|
|
||||||
ofp = OFPFlow(input_string)
|
do_test_section(input_string, "actions", expected)
|
||||||
actions = ofp.actions_kv
|
|
||||||
|
|
||||||
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.
|
@pytest.mark.parametrize(
|
||||||
apos = ofp.section("actions").pos
|
"input_string,expected",
|
||||||
astring = ofp.section("actions").string
|
[
|
||||||
|
(
|
||||||
|
"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
|
input_string += " actions=drop"
|
||||||
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
|
|
||||||
|
|
||||||
# Assert astring meta is correct.
|
do_test_section(input_string, "info", expected[0])
|
||||||
assert input_string[apos : apos + len(astring)] == astring
|
do_test_section(input_string, "match", expected[1])
|
||||||
|
Reference in New Issue
Block a user