From f1ea4d6f466f862277ecc3bd57fbeda2f2444717 Mon Sep 17 00:00:00 2001 From: Dinesh Kumar Sellappan <40899231+selldinesh@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:49:41 -0700 Subject: [PATCH] Phase4 new set of sai cases (#24) --- tests/api/test_buffer_profile.py | 51 +++++++++ tests/api/test_hostif.py | 150 +++++++++++++++++++++++++++ tests/api/test_hostif_table_entry.py | 89 ++++++++++++++++ tests/api/test_lag_member.py | 90 ++++++++++++++++ tests/api/test_my_mac.py | 36 +++++++ tests/api/test_next_hop_group.py | 24 ++++- tests/api/test_port.py | 35 +++++++ tests/api/test_virtual_router.py | 72 ++++++++++++- tests/api/test_vlan.py | 42 +++++++- 9 files changed, 583 insertions(+), 6 deletions(-) create mode 100644 tests/api/test_buffer_profile.py create mode 100644 tests/api/test_hostif.py create mode 100644 tests/api/test_hostif_table_entry.py create mode 100644 tests/api/test_lag_member.py create mode 100644 tests/api/test_my_mac.py create mode 100644 tests/api/test_port.py diff --git a/tests/api/test_buffer_profile.py b/tests/api/test_buffer_profile.py new file mode 100644 index 00000000..b938c8c1 --- /dev/null +++ b/tests/api/test_buffer_profile.py @@ -0,0 +1,51 @@ +from pprint import pprint + +import pytest + + +@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)) + + +@pytest.mark.npu +class TestSaiBufferProfile: + # object with parent SAI_OBJECT_TYPE_BUFFER_POOL + + def test_buffer_profile_create(self, npu): + commands = [ + { + 'name': 'buffer_pool_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_BUFFER_POOL', + 'attributes': [ + 'SAI_BUFFER_POOL_ATTR_TYPE', + 'SAI_BUFFER_POOL_TYPE_INGRESS', + 'SAI_BUFFER_POOL_ATTR_SIZE', + '10', + ], + }, + { + 'name': 'buffer_profile_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_BUFFER_PROFILE', + 'attributes': [ + 'SAI_BUFFER_PROFILE_ATTR_POOL_ID', + '$buffer_pool_1', + 'SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE', + '10', + 'SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE', + 'SAI_BUFFER_PROFILE_THRESHOLD_MODE_STATIC', + 'SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH', + '1', + 'SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH', + '10', + ], + }, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) diff --git a/tests/api/test_hostif.py b/tests/api/test_hostif.py new file mode 100644 index 00000000..2382e367 --- /dev/null +++ b/tests/api/test_hostif.py @@ -0,0 +1,150 @@ +from pprint import pprint + +import pytest + + +@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)) + + +@pytest.mark.npu +class TestSaiHostif: + # object with parent SAI_OBJECT_TYPE_PORT SAI_OBJECT_TYPE_LAG SAI_OBJECT_TYPE_VLAN SAI_OBJECT_TYPE_SYSTEM_PORT + + def test_hostif_create(self, npu): + commands = [ + { + 'name': 'port_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_PORT', + 'attributes': [ + 'SAI_PORT_ATTR_HW_LANE_LIST', + '2:10,11', + 'SAI_PORT_ATTR_SPEED', + '10', + ], + }, + { + 'name': 'hostif_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_HOSTIF', + 'attributes': [ + 'SAI_HOSTIF_ATTR_TYPE', + 'SAI_HOSTIF_TYPE_NETDEV', + 'SAI_HOSTIF_ATTR_OBJ_ID', + '$port_1', + 'SAI_HOSTIF_ATTR_NAME', + 'inbound', + 'SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME', + 'inbound', + ], + }, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + @pytest.mark.dependency(name='test_sai_hostif_attr_oper_status_set') + def test_sai_hostif_attr_oper_status_set(self, npu): + commands = [ + { + 'name': 'hostif_1', + 'op': 'set', + 'attributes': ['SAI_HOSTIF_ATTR_OPER_STATUS', 'false'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_hostif_attr_oper_status_set']) + def test_sai_hostif_attr_oper_status_get(self, npu): + commands = [ + { + 'name': 'hostif_1', + 'op': 'get', + 'attributes': ['SAI_HOSTIF_ATTR_OPER_STATUS'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'false', 'Get error, expected false but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_hostif_attr_queue_set') + def test_sai_hostif_attr_queue_set(self, npu): + commands = [ + { + 'name': 'hostif_1', + 'op': 'set', + 'attributes': ['SAI_HOSTIF_ATTR_QUEUE', '0'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_hostif_attr_queue_set']) + def test_sai_hostif_attr_queue_get(self, npu): + commands = [ + {'name': 'hostif_1', 'op': 'get', 'attributes': ['SAI_HOSTIF_ATTR_QUEUE']} + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == '0', 'Get error, expected 0 but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_hostif_attr_vlan_tag_set') + def test_sai_hostif_attr_vlan_tag_set(self, npu): + commands = [ + { + 'name': 'hostif_1', + 'op': 'set', + 'attributes': ['SAI_HOSTIF_ATTR_VLAN_TAG', 'SAI_HOSTIF_VLAN_TAG_STRIP'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_hostif_attr_vlan_tag_set']) + def test_sai_hostif_attr_vlan_tag_get(self, npu): + commands = [ + { + 'name': 'hostif_1', + 'op': 'get', + 'attributes': ['SAI_HOSTIF_ATTR_VLAN_TAG'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'SAI_HOSTIF_VLAN_TAG_STRIP', ( + 'Get error, expected SAI_HOSTIF_VLAN_TAG_STRIP but got %s' % r_value + ) + + def test_hostif_remove(self, npu): + commands = [ + {'name': 'hostif_1', 'op': 'remove'}, + {'name': 'port_1', 'op': 'remove'}, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_hostif_table_entry.py b/tests/api/test_hostif_table_entry.py new file mode 100644 index 00000000..011fcc11 --- /dev/null +++ b/tests/api/test_hostif_table_entry.py @@ -0,0 +1,89 @@ +from pprint import pprint + +import pytest + + +@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)) + + +@pytest.mark.npu +class TestSaiHostifTableEntry: + # object with parent SAI_OBJECT_TYPE_PORT SAI_OBJECT_TYPE_LAG SAI_OBJECT_TYPE_ROUTER_INTERFACE SAI_OBJECT_TYPE_HOSTIF_TRAP SAI_OBJECT_TYPE_HOSTIF_USER_DEFINED_TRAP SAI_OBJECT_TYPE_HOSTIF + + def test_hostif_table_entry_create(self, npu): + commands = [ + { + 'name': 'port_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_PORT', + 'attributes': [ + 'SAI_PORT_ATTR_HW_LANE_LIST', + '2:10,11', + 'SAI_PORT_ATTR_SPEED', + '10', + ], + }, + { + 'name': 'hostif_trap_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_HOSTIF_TRAP', + 'attributes': [ + 'SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE', + 'SAI_HOSTIF_TRAP_TYPE_STP', + 'SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION', + 'SAI_PACKET_ACTION_DROP', + ], + }, + { + 'name': 'hostif_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_HOSTIF', + 'attributes': [ + 'SAI_HOSTIF_ATTR_TYPE', + 'SAI_HOSTIF_TYPE_NETDEV', + 'SAI_HOSTIF_ATTR_OBJ_ID', + '$port_1', + 'SAI_HOSTIF_ATTR_NAME', + 'inbound', + 'SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME', + 'inbound', + ], + }, + { + 'name': 'hostif_table_entry_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_HOSTIF_TABLE_ENTRY', + 'attributes': [ + 'SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE', + 'SAI_HOSTIF_TABLE_ENTRY_TYPE_PORT', + 'SAI_HOSTIF_TABLE_ENTRY_ATTR_OBJ_ID', + '$port_1', + 'SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID', + '$hostif_trap_1', + 'SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE', + 'SAI_HOSTIF_TABLE_ENTRY_CHANNEL_TYPE_CB', + 'SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF', + '$hostif_1', + ], + }, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_hostif_table_entry_remove(self, npu): + commands = [ + {'name': 'hostif_table_entry_1', 'op': 'remove'}, + {'name': 'hostif_1', 'op': 'remove'}, + {'name': 'hostif_trap_1', 'op': 'remove'}, + {'name': 'port_1', 'op': 'remove'}, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_lag_member.py b/tests/api/test_lag_member.py new file mode 100644 index 00000000..7311a0bc --- /dev/null +++ b/tests/api/test_lag_member.py @@ -0,0 +1,90 @@ +from pprint import pprint + +import pytest + + +@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)) + + +@pytest.mark.npu +class TestSaiLagMember: + # object with parent SAI_OBJECT_TYPE_LAG SAI_OBJECT_TYPE_PORT SAI_OBJECT_TYPE_SYSTEM_PORT + + def test_lag_member_create(self, npu): + commands = [ + { + 'name': 'lag_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_LAG', + 'attributes': [], + }, + { + 'name': 'port_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_PORT', + 'attributes': [ + 'SAI_PORT_ATTR_HW_LANE_LIST', + '2:10,11', + 'SAI_PORT_ATTR_SPEED', + '10', + ], + }, + { + 'name': 'lag_member_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_LAG_MEMBER', + 'attributes': [ + 'SAI_LAG_MEMBER_ATTR_LAG_ID', + '$lag_1', + 'SAI_LAG_MEMBER_ATTR_PORT_ID', + '$port_1', + ], + }, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + @pytest.mark.dependency(name='test_sai_lag_member_attr_egress_disable_set') + def test_sai_lag_member_attr_egress_disable_set(self, npu): + commands = [ + { + 'name': 'lag_member_1', + 'op': 'set', + 'attributes': ['SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE', 'false'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + + @pytest.mark.dependency(name='test_sai_lag_member_attr_ingress_disable_set') + def test_sai_lag_member_attr_ingress_disable_set(self, npu): + commands = [ + { + 'name': 'lag_member_1', + 'op': 'set', + 'attributes': ['SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE', 'false'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + + def test_lag_member_remove(self, npu): + commands = [ + {'name': 'lag_member_1', 'op': 'remove'}, + {'name': 'port_1', 'op': 'remove'}, + {'name': 'lag_1', 'op': 'remove'}, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_my_mac.py b/tests/api/test_my_mac.py new file mode 100644 index 00000000..a626f71d --- /dev/null +++ b/tests/api/test_my_mac.py @@ -0,0 +1,36 @@ +from pprint import pprint + +import pytest + + +@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)) + + +@pytest.mark.npu +class TestSaiMyMac: + # object with no attributes + + def test_my_mac_create(self, npu): + commands = [ + { + 'name': 'my_mac_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_MY_MAC', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_my_mac_remove(self, npu): + commands = [{'name': 'my_mac_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_next_hop_group.py b/tests/api/test_next_hop_group.py index d20c3c58..66dcbc4a 100644 --- a/tests/api/test_next_hop_group.py +++ b/tests/api/test_next_hop_group.py @@ -1,6 +1,16 @@ from pprint import pprint +import pytest + +@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)) + + +@pytest.mark.npu class TestSaiNextHopGroup: # object with no parents @@ -21,13 +31,23 @@ def test_next_hop_group_create(self, npu): print('======= SAI commands RETURN values create =======') pprint(results) - def test_next_hop_group_remove(self, npu): + + @pytest.mark.dependency(name='test_sai_next_hop_group_attr_set_switchover_set') + def test_sai_next_hop_group_attr_set_switchover_set(self, npu): commands = [ { 'name': 'next_hop_group_1', - 'op': 'remove', + 'op': 'set', + 'attributes': ['SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER', 'false'], } ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + + def test_next_hop_group_remove(self, npu): + commands = [{'name': 'next_hop_group_1', 'op': 'remove'}] results = [*npu.process_commands(commands)] print('======= SAI commands RETURN values remove =======') diff --git a/tests/api/test_port.py b/tests/api/test_port.py new file mode 100644 index 00000000..628f46ed --- /dev/null +++ b/tests/api/test_port.py @@ -0,0 +1,35 @@ +from pprint import pprint + +import pytest + + +@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)) + + +@pytest.mark.npu +class TestSaiPort: + # object with no parents + + def test_port_create(self, npu): + commands = [ + { + 'name': 'port_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_PORT', + 'attributes': [ + 'SAI_PORT_ATTR_HW_LANE_LIST', + '2:10,11', + 'SAI_PORT_ATTR_SPEED', + '10', + ], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + diff --git a/tests/api/test_virtual_router.py b/tests/api/test_virtual_router.py index 285e9cee..ba86c93c 100644 --- a/tests/api/test_virtual_router.py +++ b/tests/api/test_virtual_router.py @@ -1,6 +1,16 @@ from pprint import pprint +import pytest + +@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)) + + +@pytest.mark.npu class TestSaiVirtualRouter: # object with no attributes @@ -18,13 +28,71 @@ def test_virtual_router_create(self, npu): print('======= SAI commands RETURN values create =======') pprint(results) - def test_virtual_router_remove(self, npu): + @pytest.mark.dependency(name='test_sai_virtual_router_attr_admin_v4_state_set') + def test_sai_virtual_router_attr_admin_v4_state_set(self, npu): + commands = [ + { + 'name': 'virtual_router_1', + 'op': 'set', + 'attributes': ['SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', 'true'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_virtual_router_attr_admin_v4_state_set']) + def test_sai_virtual_router_attr_admin_v4_state_get(self, npu): commands = [ { 'name': 'virtual_router_1', - 'op': 'remove', + 'op': 'get', + 'attributes': ['SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE'], } ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'true', 'Get error, expected true but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_virtual_router_attr_admin_v6_state_set') + def test_sai_virtual_router_attr_admin_v6_state_set(self, npu): + commands = [ + { + 'name': 'virtual_router_1', + 'op': 'set', + 'attributes': ['SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', 'true'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_virtual_router_attr_admin_v6_state_set']) + def test_sai_virtual_router_attr_admin_v6_state_get(self, npu): + commands = [ + { + 'name': 'virtual_router_1', + 'op': 'get', + 'attributes': ['SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'true', 'Get error, expected true but got %s' % r_value + + + def test_virtual_router_remove(self, npu): + commands = [{'name': 'virtual_router_1', 'op': 'remove'}] results = [*npu.process_commands(commands)] print('======= SAI commands RETURN values remove =======') diff --git a/tests/api/test_vlan.py b/tests/api/test_vlan.py index 8dac7c9e..72308e29 100644 --- a/tests/api/test_vlan.py +++ b/tests/api/test_vlan.py @@ -1,6 +1,16 @@ from pprint import pprint +import pytest + +@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)) + + +@pytest.mark.npu class TestSaiVlan: # object with no parents @@ -18,13 +28,41 @@ def test_vlan_create(self, npu): print('======= SAI commands RETURN values create =======') pprint(results) - def test_vlan_remove(self, npu): + + @pytest.mark.dependency(name='test_sai_vlan_attr_max_learned_addresses_set') + def test_sai_vlan_attr_max_learned_addresses_set(self, npu): commands = [ { 'name': 'vlan_1', - 'op': 'remove', + 'op': 'set', + 'attributes': ['SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES', '0'], } ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_vlan_attr_max_learned_addresses_set']) + def test_sai_vlan_attr_max_learned_addresses_get(self, npu): + commands = [ + { + 'name': 'vlan_1', + 'op': 'get', + 'attributes': ['SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == '0', 'Get error, expected 0 but got %s' % r_value + + + def test_vlan_remove(self, npu): + commands = [{'name': 'vlan_1', 'op': 'remove'}] results = [*npu.process_commands(commands)] print('======= SAI commands RETURN values remove =======')