From 128b73702f0c02c4cc0a2dfb1ef9fb8e30e0bf47 Mon Sep 17 00:00:00 2001 From: Andriy Kokhan Date: Tue, 19 Sep 2023 21:24:09 +0300 Subject: [PATCH] Added LAG basic UTs Signed-off-by: Andriy Kokhan --- .github/workflows/sc-client-server-deb10.yml | 2 +- .github/workflows/sc-client-server-deb11.yml | 2 +- .github/workflows/sc-standalone-deb10.yml | 4 +- .github/workflows/sc-standalone-deb11.yml | 4 +- tests/ut/test_lag_ut.py | 116 +++++++++++++++++++ 5 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 tests/ut/test_lag_ut.py diff --git a/.github/workflows/sc-client-server-deb10.yml b/.github/workflows/sc-client-server-deb10.yml index 0f04fe09..53626639 100644 --- a/.github/workflows/sc-client-server-deb10.yml +++ b/.github/workflows/sc-client-server-deb10.yml @@ -157,7 +157,7 @@ jobs: - name: Run functional test cases run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v -k "test_l2_basic" - name: Run unit tests - run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py + run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py ut/test_lag_ut.py - name: Run unit tests run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v -k \ "test_switch_ut and not sai_map_list_t" diff --git a/.github/workflows/sc-client-server-deb11.yml b/.github/workflows/sc-client-server-deb11.yml index 5246b189..1a332b11 100644 --- a/.github/workflows/sc-client-server-deb11.yml +++ b/.github/workflows/sc-client-server-deb11.yml @@ -156,7 +156,7 @@ jobs: - name: Run functional test cases run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v -k "test_l2_basic" - name: Run unit tests - run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py + run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py ut/test_lag_ut.py - name: Run unit tests run: ./exec.sh --no-tty -i client pytest --testbed=saivs_client_server -v -k \ "test_switch_ut and not sai_map_list_t" diff --git a/.github/workflows/sc-standalone-deb10.yml b/.github/workflows/sc-standalone-deb10.yml index 93e86819..57688b62 100644 --- a/.github/workflows/sc-standalone-deb10.yml +++ b/.github/workflows/sc-standalone-deb10.yml @@ -72,7 +72,7 @@ jobs: - name: Run sairedis tests run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v -k "test_sairec" - name: Run unit tests - run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py + run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py ut/test_lag_ut.py - name: Run unit tests run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v -k "test_switch_ut and not sai_map_list_t" - name: Run data-driven tests @@ -95,7 +95,7 @@ jobs: - name: Run thift data-driven tests run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v test_l2_basic_dd.py - name: Run thrift unit tests - run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ut/test_vrf_ut.py ut/test_bridge_ut.py ut/test_acl_ut.py ut/test_fdb_ut.py + run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ut/test_vrf_ut.py ut/test_bridge_ut.py ut/test_acl_ut.py ut/test_fdb_ut.py ut/test_lag_ut.py - name: Run thrift unit tests run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k \ "(test_switch_ut and not sai_map_list_t and not sai_system_port_config_list_t) or (test_port_ut and not sai_map_list_t)" diff --git a/.github/workflows/sc-standalone-deb11.yml b/.github/workflows/sc-standalone-deb11.yml index 6e0b38fa..f237ae68 100644 --- a/.github/workflows/sc-standalone-deb11.yml +++ b/.github/workflows/sc-standalone-deb11.yml @@ -72,7 +72,7 @@ jobs: - name: Run sairedis tests run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v -k "test_sairec" - name: Run unit tests - run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py + run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v ut/test_acl_ut.py ut/test_bridge_ut.py ut/test_vrf_ut.py ut/test_port_ut.py ut/test_fdb_ut.py ut/test_lag_ut.py - name: Run unit tests run: ./exec.sh --no-tty pytest --testbed=saivs_standalone -v -k "test_switch_ut and not sai_map_list_t" - name: Run data-driven tests @@ -95,7 +95,7 @@ jobs: - name: Run thift data-driven tests run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v test_l2_basic_dd.py - name: Run thrift unit tests - run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ut/test_vrf_ut.py ut/test_bridge_ut.py ut/test_acl_ut.py ut/test_fdb_ut.py + run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v ut/test_vrf_ut.py ut/test_bridge_ut.py ut/test_acl_ut.py ut/test_fdb_ut.py ut/test_lag_ut.py - name: Run thrift unit tests run: ./exec.sh --no-tty -s thrift pytest --testbed=saivs_thrift_standalone -v -k \ "(test_switch_ut and not sai_map_list_t and not sai_system_port_config_list_t) or (test_port_ut and not sai_map_list_t)" diff --git a/tests/ut/test_lag_ut.py b/tests/ut/test_lag_ut.py new file mode 100644 index 00000000..84cb4737 --- /dev/null +++ b/tests/ut/test_lag_ut.py @@ -0,0 +1,116 @@ +import pytest +from saichallenger.common.sai import Sai +from saichallenger.common.sai_data import SaiObjType + +lag_attrs = Sai.get_obj_attrs("SAI_OBJECT_TYPE_LAG") +lag_mbr_attrs = Sai.get_obj_attrs("SAI_OBJECT_TYPE_LAG_MEMBER") + +@pytest.fixture(scope="module", autouse=True) +def skip_all(testbed_instance): + testbed = testbed_instance + if testbed is not None and len(testbed.npu) != 1: + pytest.skip("invalid for \"{}\" testbed".format(testbed.name)) + + +class TestLag: + oid = None + lag_mbr_num = 2 + lag_mbr_oids = [] + + @pytest.mark.dependency() + def test_create(self, npu): + TestLag.oid = npu.create(SaiObjType.LAG) + + @pytest.mark.parametrize( + "attr,attr_type", + lag_attrs + ) + @pytest.mark.dependency(depends=['TestLag::test_create']) + def test_get_attr(self, npu, attr, attr_type): + if attr == "SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID": + pytest.skip("Valid for SAI_SWITCH_TYPE_VOQ only") + status, data = npu.get_by_type(TestLag.oid, attr, attr_type, False) + npu.assert_status_success(status) + if attr == "SAI_LAG_ATTR_PORT_LIST": + assert len(data.to_list()) == 0 + elif attr == "SAI_LAG_ATTR_PORT_VLAN_ID": + assert data.value() == npu.default_vlan_id + elif attr in ["SAI_LAG_ATTR_DROP_UNTAGGED", "SAI_LAG_ATTR_DROP_TAGGED"]: + assert data.value() == "false" + + @pytest.mark.dependency(depends=['TestLag::test_create']) + def test_create_members(self, npu): + # Remove bridge ports + for idx in range(TestLag.lag_mbr_num): + npu.remove_vlan_member(npu.default_vlan_oid, npu.dot1q_bp_oids[idx]) + npu.remove(npu.dot1q_bp_oids[idx]) + + # Create LAG members + for idx in range(TestLag.lag_mbr_num): + oid = npu.create(SaiObjType.LAG_MEMBER, + [ + "SAI_LAG_MEMBER_ATTR_LAG_ID", TestLag.oid, + "SAI_LAG_MEMBER_ATTR_PORT_ID", npu.port_oids[idx] + ]) + TestLag.lag_mbr_oids.append(oid) + + @pytest.mark.parametrize( + "attr,attr_type", + lag_mbr_attrs + ) + @pytest.mark.dependency(depends=['TestLag::test_create_members']) + def test_get_member_attr(self, npu, attr, attr_type): + status, data = npu.get_by_type(TestLag.lag_mbr_oids[0], attr, attr_type, False) + npu.assert_status_success(status) + if attr == "SAI_LAG_MEMBER_ATTR_LAG_ID": + assert data.value() == TestLag.oid + elif attr == "SAI_LAG_MEMBER_ATTR_PORT_ID": + assert data.value() == npu.port_oids[0] + elif attr in ["SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE", "SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE"]: + assert data.value() == "false" + + + @pytest.mark.dependency(depends=['TestLag::test_create_members']) + def test_check_members(self, npu): + status, data = npu.get(TestLag.oid, ["SAI_LAG_ATTR_PORT_LIST"], False) + npu.assert_status_success(status) + mbr_oids = data.oids() + assert len(mbr_oids) == TestLag.lag_mbr_num + for oid in mbr_oids: + assert oid in TestLag.lag_mbr_oids + + @pytest.mark.dependency(depends=['TestLag::test_create_members']) + def test_remove_members(self, npu): + # Remove LAG members + for oid in TestLag.lag_mbr_oids: + npu.remove(oid) + + # Create bridge port for ports removed from LAG + for idx in range(TestLag.lag_mbr_num): + bp_oid = npu.create(SaiObjType.BRIDGE_PORT, + [ + "SAI_BRIDGE_PORT_ATTR_TYPE", "SAI_BRIDGE_PORT_TYPE_PORT", + "SAI_BRIDGE_PORT_ATTR_PORT_ID", npu.port_oids[idx], + #"SAI_BRIDGE_PORT_ATTR_BRIDGE_ID", npu.dot1q_br_oid, + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE", "true" + ]) + npu.dot1q_bp_oids[idx] = bp_oid + + # Add ports to default VLAN + for oid in npu.dot1q_bp_oids[0:TestLag.lag_mbr_num]: + npu.create_vlan_member(npu.default_vlan_oid, oid, "SAI_VLAN_TAGGING_MODE_UNTAGGED") + + # Set PVID + for oid in npu.port_oids[0:TestLag.lag_mbr_num]: + npu.set(oid, ["SAI_PORT_ATTR_PORT_VLAN_ID", npu.default_vlan_id]) + + @pytest.mark.dependency(depends=['TestLag::test_remove_members']) + def test_check_no_members(self, npu): + status, data = npu.get(TestLag.oid, ["SAI_LAG_ATTR_PORT_LIST"], False) + npu.assert_status_success(status) + assert len(data.oids()) == 0 + + @pytest.mark.dependency(depends=['TestLag::test_create']) + def test_remove(self, npu): + npu.remove(TestLag.oid) +