|
| 1 | +from swsscommon import swsscommon |
| 2 | + |
| 3 | +from dash_api.appliance_pb2 import * |
| 4 | +from dash_api.vnet_pb2 import * |
| 5 | +from dash_api.eni_pb2 import * |
| 6 | +from dash_api.route_pb2 import * |
| 7 | +from dash_api.route_rule_pb2 import * |
| 8 | +from dash_api.vnet_mapping_pb2 import * |
| 9 | +from dash_api.route_type_pb2 import * |
| 10 | +from dash_api.types_pb2 import * |
| 11 | + |
| 12 | +import typing |
| 13 | +import time |
| 14 | +import binascii |
| 15 | +import uuid |
| 16 | +import ipaddress |
| 17 | +import sys |
| 18 | +import socket |
| 19 | +import logging |
| 20 | +import pytest |
| 21 | + |
| 22 | +logging.basicConfig(level=logging.INFO) |
| 23 | +zmq_logger = logging.getLogger(__name__) |
| 24 | + |
| 25 | +DVS_ENV = ["HWSKU=DPU-2P"] |
| 26 | +NUM_PORTS = 2 |
| 27 | + |
| 28 | +class Table(object): |
| 29 | + def __init__(self, database, table_name: str): |
| 30 | + self.table_name = table_name |
| 31 | + self.table = swsscommon.Table(database.db_connection, self.table_name) |
| 32 | + |
| 33 | + def __getitem__(self, key: str): |
| 34 | + exists, result = self.table.get(str(key)) |
| 35 | + if not exists: |
| 36 | + return None |
| 37 | + else: |
| 38 | + return dict(result) |
| 39 | + |
| 40 | + def get_keys(self): |
| 41 | + return self.table.getKeys() |
| 42 | + |
| 43 | + def get_newly_created_oid(self, old_oids): |
| 44 | + new_oids = self.asic_db.wait_for_n_keys(table, len(old_oids) + 1) |
| 45 | + oid = [ids for ids in new_oids if ids not in old_oids] |
| 46 | + return oid[0] |
| 47 | + |
| 48 | +class DashZmq(object): |
| 49 | + def __init__(self, dvs): |
| 50 | + self.dvs = dvs |
| 51 | + self.asic_direction_lookup_table = Table( |
| 52 | + self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_DIRECTION_LOOKUP_ENTRY") |
| 53 | + self.asic_vip_table = Table( |
| 54 | + self.dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_VIP_ENTRY") |
| 55 | + |
| 56 | +class TestZmqDash(object): |
| 57 | + @pytest.fixture(scope="class") |
| 58 | + def enable_orchagent_zmq(self, dvs): |
| 59 | + # change orchagent to use ZMQ |
| 60 | + dvs.runcmd("cp /usr/bin/orchagent.sh /usr/bin/orchagent.sh_zmq_ut_backup") |
| 61 | + dvs.runcmd("sed -i.bak 's/\/usr\/bin\/orchagent /\/usr\/bin\/orchagent -q tcp:\/\/127.0.0.1:8100 /g' /usr/bin/orchagent.sh") |
| 62 | + dvs.stop_swss() |
| 63 | + dvs.start_swss() |
| 64 | + |
| 65 | + process_statue = dvs.runcmd("ps -ef") |
| 66 | + zmq_logger.debug("Process status: {}".format(process_statue)) |
| 67 | + |
| 68 | + yield |
| 69 | + |
| 70 | + # revert change |
| 71 | + dvs.runcmd("cp /usr/bin/orchagent.sh_zmq_ut_backup /usr/bin/orchagent.sh") |
| 72 | + dvs.stop_swss() |
| 73 | + dvs.start_swss() |
| 74 | + |
| 75 | + @pytest.mark.usefixtures("enable_orchagent_zmq") |
| 76 | + def test_appliance(self, dvs): |
| 77 | + # upload test script to test container and create applicance with it |
| 78 | + dvs.copy_file("/", "create_appliance.py") |
| 79 | + dvs.runcmd(['sh', '-c', "python3 create_appliance.py {}".format(1234)]) |
| 80 | + time.sleep(3) |
| 81 | + |
| 82 | + asic_direction_lookup_table = Table( |
| 83 | + dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_DIRECTION_LOOKUP_ENTRY") |
| 84 | + direction_entries = asic_direction_lookup_table.get_keys() |
| 85 | + zmq_logger.info("Keys from asic_direction_lookup_table: {}".format(direction_entries)) |
| 86 | + |
| 87 | + assert direction_entries |
| 88 | + fvs = asic_direction_lookup_table[direction_entries[0]] |
| 89 | + zmq_logger.info("Data from asic_direction_lookup_table: {}={}".format(direction_entries[0], fvs)) |
| 90 | + for fv in fvs.items(): |
| 91 | + if fv[0] == "SAI_DIRECTION_LOOKUP_ENTRY_ATTR_ACTION": |
| 92 | + assert fv[1] == "SAI_DIRECTION_LOOKUP_ENTRY_ACTION_SET_OUTBOUND_DIRECTION" |
| 93 | + |
| 94 | + asic_vip_table = Table( |
| 95 | + dvs.get_asic_db(), "ASIC_STATE:SAI_OBJECT_TYPE_VIP_ENTRY") |
| 96 | + vip_entries = asic_vip_table.get_keys() |
| 97 | + zmq_logger.info("Keys from asic_vip_table: {}".format(direction_entries)) |
| 98 | + |
| 99 | + assert vip_entries |
| 100 | + fvs = asic_vip_table[vip_entries[0]] |
| 101 | + zmq_logger.info("Data from asic_vip_table: {}={}".format(vip_entries[0], fvs)) |
| 102 | + for fv in fvs.items(): |
| 103 | + if fv[0] == "SAI_VIP_ENTRY_ATTR_ACTION": |
| 104 | + assert fv[1] == "SAI_VIP_ENTRY_ACTION_ACCEPT" |
0 commit comments