|
| 1 | +from pprint import pprint |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture(scope='module', autouse=True) |
| 7 | +def skip_all(testbed_instance): |
| 8 | + testbed = testbed_instance |
| 9 | + if testbed is not None and len(testbed.npu) != 1: |
| 10 | + pytest.skip('invalid for {} testbed'.format(testbed.name)) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.npu |
| 14 | +class TestSaiHostif: |
| 15 | + # object with parent SAI_OBJECT_TYPE_PORT SAI_OBJECT_TYPE_LAG SAI_OBJECT_TYPE_VLAN SAI_OBJECT_TYPE_SYSTEM_PORT |
| 16 | + |
| 17 | + def test_hostif_create(self, npu): |
| 18 | + commands = [ |
| 19 | + { |
| 20 | + 'name': 'port_1', |
| 21 | + 'op': 'create', |
| 22 | + 'type': 'SAI_OBJECT_TYPE_PORT', |
| 23 | + 'attributes': [ |
| 24 | + 'SAI_PORT_ATTR_HW_LANE_LIST', |
| 25 | + '2:10,11', |
| 26 | + 'SAI_PORT_ATTR_SPEED', |
| 27 | + '10', |
| 28 | + ], |
| 29 | + }, |
| 30 | + { |
| 31 | + 'name': 'hostif_1', |
| 32 | + 'op': 'create', |
| 33 | + 'type': 'SAI_OBJECT_TYPE_HOSTIF', |
| 34 | + 'attributes': [ |
| 35 | + 'SAI_HOSTIF_ATTR_TYPE', |
| 36 | + 'SAI_HOSTIF_TYPE_NETDEV', |
| 37 | + 'SAI_HOSTIF_ATTR_OBJ_ID', |
| 38 | + '$port_1', |
| 39 | + 'SAI_HOSTIF_ATTR_NAME', |
| 40 | + 'inbound', |
| 41 | + 'SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME', |
| 42 | + 'inbound', |
| 43 | + ], |
| 44 | + }, |
| 45 | + ] |
| 46 | + |
| 47 | + results = [*npu.process_commands(commands)] |
| 48 | + print('======= SAI commands RETURN values create =======') |
| 49 | + pprint(results) |
| 50 | + |
| 51 | + @pytest.mark.dependency(name='test_sai_hostif_attr_oper_status_set') |
| 52 | + def test_sai_hostif_attr_oper_status_set(self, npu): |
| 53 | + commands = [ |
| 54 | + { |
| 55 | + 'name': 'hostif_1', |
| 56 | + 'op': 'set', |
| 57 | + 'attributes': ['SAI_HOSTIF_ATTR_OPER_STATUS', 'false'], |
| 58 | + } |
| 59 | + ] |
| 60 | + results = [*npu.process_commands(commands)] |
| 61 | + print('======= SAI commands RETURN values set =======') |
| 62 | + pprint(results) |
| 63 | + |
| 64 | + @pytest.mark.dependency(depends=['test_sai_hostif_attr_oper_status_set']) |
| 65 | + def test_sai_hostif_attr_oper_status_get(self, npu): |
| 66 | + commands = [ |
| 67 | + { |
| 68 | + 'name': 'hostif_1', |
| 69 | + 'op': 'get', |
| 70 | + 'attributes': ['SAI_HOSTIF_ATTR_OPER_STATUS'], |
| 71 | + } |
| 72 | + ] |
| 73 | + results = [*npu.process_commands(commands)] |
| 74 | + print('======= SAI commands RETURN values get =======') |
| 75 | + for command in results: |
| 76 | + for attribute in command: |
| 77 | + pprint(attribute.raw()) |
| 78 | + r_value = results[0][0].value() |
| 79 | + print(r_value) |
| 80 | + assert r_value == 'false', 'Get error, expected false but got %s' % r_value |
| 81 | + |
| 82 | + @pytest.mark.dependency(name='test_sai_hostif_attr_queue_set') |
| 83 | + def test_sai_hostif_attr_queue_set(self, npu): |
| 84 | + commands = [ |
| 85 | + { |
| 86 | + 'name': 'hostif_1', |
| 87 | + 'op': 'set', |
| 88 | + 'attributes': ['SAI_HOSTIF_ATTR_QUEUE', '0'], |
| 89 | + } |
| 90 | + ] |
| 91 | + results = [*npu.process_commands(commands)] |
| 92 | + print('======= SAI commands RETURN values set =======') |
| 93 | + pprint(results) |
| 94 | + |
| 95 | + @pytest.mark.dependency(depends=['test_sai_hostif_attr_queue_set']) |
| 96 | + def test_sai_hostif_attr_queue_get(self, npu): |
| 97 | + commands = [ |
| 98 | + {'name': 'hostif_1', 'op': 'get', 'attributes': ['SAI_HOSTIF_ATTR_QUEUE']} |
| 99 | + ] |
| 100 | + results = [*npu.process_commands(commands)] |
| 101 | + print('======= SAI commands RETURN values get =======') |
| 102 | + for command in results: |
| 103 | + for attribute in command: |
| 104 | + pprint(attribute.raw()) |
| 105 | + r_value = results[0][0].value() |
| 106 | + print(r_value) |
| 107 | + assert r_value == '0', 'Get error, expected 0 but got %s' % r_value |
| 108 | + |
| 109 | + @pytest.mark.dependency(name='test_sai_hostif_attr_vlan_tag_set') |
| 110 | + def test_sai_hostif_attr_vlan_tag_set(self, npu): |
| 111 | + commands = [ |
| 112 | + { |
| 113 | + 'name': 'hostif_1', |
| 114 | + 'op': 'set', |
| 115 | + 'attributes': ['SAI_HOSTIF_ATTR_VLAN_TAG', 'SAI_HOSTIF_VLAN_TAG_STRIP'], |
| 116 | + } |
| 117 | + ] |
| 118 | + results = [*npu.process_commands(commands)] |
| 119 | + print('======= SAI commands RETURN values set =======') |
| 120 | + pprint(results) |
| 121 | + |
| 122 | + @pytest.mark.dependency(depends=['test_sai_hostif_attr_vlan_tag_set']) |
| 123 | + def test_sai_hostif_attr_vlan_tag_get(self, npu): |
| 124 | + commands = [ |
| 125 | + { |
| 126 | + 'name': 'hostif_1', |
| 127 | + 'op': 'get', |
| 128 | + 'attributes': ['SAI_HOSTIF_ATTR_VLAN_TAG'], |
| 129 | + } |
| 130 | + ] |
| 131 | + results = [*npu.process_commands(commands)] |
| 132 | + print('======= SAI commands RETURN values get =======') |
| 133 | + for command in results: |
| 134 | + for attribute in command: |
| 135 | + pprint(attribute.raw()) |
| 136 | + r_value = results[0][0].value() |
| 137 | + print(r_value) |
| 138 | + assert r_value == 'SAI_HOSTIF_VLAN_TAG_STRIP', ( |
| 139 | + 'Get error, expected SAI_HOSTIF_VLAN_TAG_STRIP but got %s' % r_value |
| 140 | + ) |
| 141 | + |
| 142 | + def test_hostif_remove(self, npu): |
| 143 | + commands = [ |
| 144 | + {'name': 'hostif_1', 'op': 'remove'}, |
| 145 | + {'name': 'port_1', 'op': 'remove'}, |
| 146 | + ] |
| 147 | + |
| 148 | + results = [*npu.process_commands(commands)] |
| 149 | + print('======= SAI commands RETURN values remove =======') |
| 150 | + pprint(results) |
0 commit comments