Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended VRF UTs #153

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 62 additions & 34 deletions tests/ut/test_vrf_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,65 @@ def skip_all(testbed_instance):
pytest.skip("invalid for \"{}\" testbed".format(testbed.name))


@pytest.mark.parametrize(
"attr,attr_type",
switch_attrs
)
def test_default_vrf_get_attr(npu, dataplane, attr, attr_type):
status, data = npu.get_by_type(npu.default_vrf_oid, attr, attr_type, False)
npu.assert_status_success(status)


@pytest.fixture(scope="module")
def vrf_state():
state = {
"vrf_oid" : "oid:0x0",
}
return state

@pytest.mark.dependency()
def test_vrf_create(npu, vrf_state):
vrf_state["vrf_oid"] = npu.create(SaiObjType.VIRTUAL_ROUTER, [])
assert vrf_state["vrf_oid"] != "oid:0x0"

@pytest.mark.parametrize(
"attr,attr_type",
switch_attrs
)
@pytest.mark.dependency(depends=['test_vrf_create'])
def test_vrf_get_attr(npu, dataplane, vrf_state, attr, attr_type):
status, data = npu.get_by_type(vrf_state["vrf_oid"], attr, attr_type, False)
npu.assert_status_success(status)

@pytest.mark.dependency(depends=['test_vrf_create'])
def test_vrf_remove(npu, vrf_state):
assert vrf_state["vrf_oid"] != "oid:0x0"
npu.remove(vrf_state["vrf_oid"])
class TestDefaultVrf:
state = dict()

@pytest.mark.parametrize(
"attr,attr_type",
switch_attrs
)
def test_get_attr(self, npu, dataplane, attr, attr_type):
status, data = npu.get_by_type(npu.default_vrf_oid, attr, attr_type, False)
npu.assert_status_success(status)
self.state[attr] = data.value()

@pytest.mark.parametrize(
"attr,attr_value",
[
("SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE", "false"),
("SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE", "true"),
("SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE", None),
("SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE", "false"),
("SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE", "true"),
("SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE", None),
("SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION", "SAI_PACKET_ACTION_DROP"),
("SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION", "SAI_PACKET_ACTION_TRAP"),
("SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION", None),
("SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION", "SAI_PACKET_ACTION_DROP"),
("SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION", "SAI_PACKET_ACTION_TRAP"),
("SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION", None),
("SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION", "SAI_PACKET_ACTION_DROP"),
("SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION", "SAI_PACKET_ACTION_TRAP"),
("SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION", None),
],
)
def test_set_attr(self, npu, dataplane, attr, attr_value):
if attr_value is None:
attr_value = self.state.get(attr)
if attr_value is None:
pytest.skip("no default value")
npu.set(npu.default_vrf_oid, [attr, attr_value])
assert npu.get(npu.default_vrf_oid, [attr]).value() == attr_value


class TestNonDefaultVrf:
state = dict()

@pytest.mark.dependency()
def test_create(self, npu):
self.state["vrf_oid"] = npu.create(SaiObjType.VIRTUAL_ROUTER, [])
assert self.state["vrf_oid"] != "oid:0x0"

@pytest.mark.parametrize(
"attr,attr_type",
switch_attrs
)
@pytest.mark.dependency(depends=['TestNonDefaultVrf::test_create'])
def test_get_attr(self, npu, dataplane, attr, attr_type):
status, data = npu.get_by_type(self.state["vrf_oid"], attr, attr_type, False)
npu.assert_status_success(status)

@pytest.mark.dependency(depends=['TestNonDefaultVrf::test_create'])
def test_remove(self, npu):
assert self.state["vrf_oid"] != "oid:0x0"
npu.remove(self.state["vrf_oid"])