|
4 | 4 | import time
|
5 | 5 | import json
|
6 | 6 |
|
| 7 | +# start processes in SWSS |
| 8 | +def start_swss(dvs): |
| 9 | + dvs.runcmd(['sh', '-c', 'supervisorctl start orchagent; supervisorctl start portsyncd; supervisorctl start intfsyncd; \ |
| 10 | + supervisorctl start neighsyncd; supervisorctl start intfmgrd; supervisorctl start vlanmgrd; \ |
| 11 | + supervisorctl start buffermgrd; supervisorctl start arp_update']) |
| 12 | + |
| 13 | +# stop processes in SWSS |
| 14 | +def stop_swss(dvs): |
| 15 | + dvs.runcmd(['sh', '-c', 'supervisorctl stop orchagent; supervisorctl stop portsyncd; supervisorctl stop intfsyncd; \ |
| 16 | + supervisorctl stop neighsyncd; supervisorctl stop intfmgrd; supervisorctl stop vlanmgrd; \ |
| 17 | + supervisorctl stop buffermgrd; supervisorctl stop arp_update']) |
| 18 | + |
| 19 | + |
7 | 20 | # Get restart count of all processes supporting warm restart
|
8 | 21 | def swss_get_RestartCount(state_db):
|
9 | 22 | restart_count = {}
|
@@ -683,3 +696,84 @@ def test_swss_neighbor_syncup(dvs):
|
683 | 696 | check_sairedis_for_neighbor_entry(dvs, 4, 4, 4)
|
684 | 697 | # check restart Count
|
685 | 698 | swss_app_check_RestartCount_single(state_db, restart_count, "neighsyncd")
|
| 699 | + |
| 700 | +def test_swss_port_state_syncup(dvs): |
| 701 | + |
| 702 | + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) |
| 703 | + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) |
| 704 | + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) |
| 705 | + |
| 706 | + # enable warm restart |
| 707 | + # TODO: use cfg command to config it |
| 708 | + create_entry_tbl( |
| 709 | + conf_db, |
| 710 | + swsscommon.CFG_WARM_RESTART_TABLE_NAME, "swss", |
| 711 | + [ |
| 712 | + ("enable", "true"), |
| 713 | + ] |
| 714 | + ) |
| 715 | + |
| 716 | + tbl = swsscommon.Table(appl_db, swsscommon.APP_PORT_TABLE_NAME) |
| 717 | + |
| 718 | + restart_count = swss_get_RestartCount(state_db) |
| 719 | + |
| 720 | + # update port admin state |
| 721 | + dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") |
| 722 | + dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") |
| 723 | + dvs.runcmd("ifconfig Ethernet8 10.0.0.4/31 up") |
| 724 | + |
| 725 | + dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") |
| 726 | + dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") |
| 727 | + dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") |
| 728 | + |
| 729 | + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 |
| 730 | + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 |
| 731 | + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 |
| 732 | + |
| 733 | + dvs.servers[2].runcmd("ip link set up dev eth0") == 0 |
| 734 | + |
| 735 | + time.sleep(3) |
| 736 | + |
| 737 | + for i in [0, 1, 2]: |
| 738 | + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) |
| 739 | + assert status == True |
| 740 | + oper_status = "unknown" |
| 741 | + for v in fvs: |
| 742 | + if v[0] == "oper_status": |
| 743 | + oper_status = v[1] |
| 744 | + break |
| 745 | + if i == 2: |
| 746 | + assert oper_status == "up" |
| 747 | + else: |
| 748 | + assert oper_status == "down" |
| 749 | + |
| 750 | + stop_swss(dvs) |
| 751 | + time.sleep(3) |
| 752 | + |
| 753 | + # flap the port oper status for Ethernet0, Ethernet4 and Ethernet8 |
| 754 | + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 |
| 755 | + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 |
| 756 | + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 |
| 757 | + |
| 758 | + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 |
| 759 | + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 |
| 760 | + |
| 761 | + time.sleep(5) |
| 762 | + start_swss(dvs) |
| 763 | + time.sleep(10) |
| 764 | + |
| 765 | + swss_check_RestartCount(state_db, restart_count) |
| 766 | + |
| 767 | + for i in [0, 1, 2]: |
| 768 | + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) |
| 769 | + assert status == True |
| 770 | + oper_status = "unknown" |
| 771 | + for v in fvs: |
| 772 | + if v[0] == "oper_status": |
| 773 | + oper_status = v[1] |
| 774 | + break |
| 775 | + if i == 2: |
| 776 | + assert oper_status == "down" |
| 777 | + else: |
| 778 | + assert oper_status == "up" |
| 779 | + |
0 commit comments