|
| 1 | +from swsscommon import swsscommon |
| 2 | +import time |
| 3 | + |
| 4 | + |
| 5 | +def create_entry(tbl, key, pairs): |
| 6 | + fvs = swsscommon.FieldValuePairs(pairs) |
| 7 | + tbl.set(key, fvs) |
| 8 | + time.sleep(1) |
| 9 | + |
| 10 | + |
| 11 | +def get_exist_entry(dvs, table): |
| 12 | + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) |
| 13 | + tbl = swsscommon.Table(db, table) |
| 14 | + entries = list(tbl.getKeys()) |
| 15 | + return entries[0] |
| 16 | + |
| 17 | + |
| 18 | +def create_entry_pst(db, table, separator, key, pairs): |
| 19 | + tbl = swsscommon.ProducerStateTable(db, table) |
| 20 | + create_entry(tbl, key, pairs) |
| 21 | + |
| 22 | + |
| 23 | +def check_object(db, table, key, expected_attributes): |
| 24 | + tbl = swsscommon.Table(db, table) |
| 25 | + keys = tbl.getKeys() |
| 26 | + assert key in keys, "The desired key is not presented" |
| 27 | + |
| 28 | + status, fvs = tbl.get(key) |
| 29 | + assert status, "Got an error when get a key" |
| 30 | + |
| 31 | + assert len(fvs) >= len(expected_attributes), "Incorrect attributes" |
| 32 | + |
| 33 | + attr_keys = {entry[0] for entry in fvs} |
| 34 | + |
| 35 | + for name, value in fvs: |
| 36 | + if name in expected_attributes: |
| 37 | + assert expected_attributes[name] == value, "Wrong value %s for the attribute %s = %s" % \ |
| 38 | + (value, name, expected_attributes[name]) |
| 39 | + |
| 40 | + |
| 41 | +def vxlan_switch_test(dvs, oid, port, mac): |
| 42 | + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) |
| 43 | + create_entry_pst( |
| 44 | + app_db, |
| 45 | + "SWITCH_TABLE", ':', "switch", |
| 46 | + [ |
| 47 | + ("vxlan_port", port), |
| 48 | + ("vxlan_router_mac", mac) |
| 49 | + ], |
| 50 | + ) |
| 51 | + time.sleep(2) |
| 52 | + |
| 53 | + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) |
| 54 | + check_object(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH", oid, |
| 55 | + { |
| 56 | + 'SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT': port, |
| 57 | + 'SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC': mac, |
| 58 | + } |
| 59 | + ) |
| 60 | + |
| 61 | + |
| 62 | +class TestSwitch(object): |
| 63 | + |
| 64 | + ''' |
| 65 | + Test- Check switch attributes |
| 66 | + ''' |
| 67 | + def test_switch_attribute(self, dvs, testlog): |
| 68 | + switch_oid = get_exist_entry(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH") |
| 69 | + |
| 70 | + vxlan_switch_test(dvs, switch_oid, "12345", "00:01:02:03:04:05") |
| 71 | + |
| 72 | + vxlan_switch_test(dvs, switch_oid, "56789", "00:0A:0B:0C:0D:0E") |
| 73 | + |
0 commit comments