diff --git a/orchagent/muxorch.cpp b/orchagent/muxorch.cpp index cabe0314..94a2e77b 100644 --- a/orchagent/muxorch.cpp +++ b/orchagent/muxorch.cpp @@ -24,6 +24,7 @@ #include "routeorch.h" #include "fdborch.h" #include "qosorch.h" +#include "warm_restart.h" /* Global variables */ extern Directory gDirectory; @@ -416,9 +417,18 @@ MuxCable::MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress state_machine_handlers_.insert(handler_pair(MUX_STATE_INIT_STANDBY, &MuxCable::stateStandby)); state_machine_handlers_.insert(handler_pair(MUX_STATE_ACTIVE_STANDBY, &MuxCable::stateStandby)); - /* Set initial state to "standby" */ - stateStandby(); - state_ = MuxState::MUX_STATE_STANDBY; + if (WarmStart::isWarmStart()) { + /* Warmboot case, Set initial state to "init" + * State will be updated to previous value upon APP DB sync + */ + state_ = MuxState::MUX_STATE_INIT; + } + else + { + /* Set initial state to "standby" */ + stateStandby(); + state_ = MuxState::MUX_STATE_STANDBY; + } } bool MuxCable::stateInitActive() diff --git a/tests/test_mux.py b/tests/test_mux.py index 54340808..8681e05f 100644 --- a/tests/test_mux.py +++ b/tests/test_mux.py @@ -1576,6 +1576,43 @@ def test_soc_ip(self, dvs, dvs_route, setup_vlan, setup_mux_cable, testlog): self.create_and_test_soc(appdb, asicdb, dvs, dvs_route) + def test_warm_boot_mux_state( + self, dvs, dvs_route, setup_vlan, setup_mux_cable, setup_tunnel, + remove_peer_switch, neighbor_cleanup, testlog + ): + """ + test mux initialization during warm boot. + """ + appdb = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + apdb = dvs.get_app_db() + + self.set_mux_state(appdb, "Ethernet0", "active") + self.set_mux_state(appdb, "Ethernet4", "active") + self.set_mux_state(appdb, "Ethernet8", "standby") + + # Execute the warm reboot + dvs.runcmd("config warm_restart enable swss") + dvs.stop_swss() + dvs.start_swss() + + time.sleep(5) + + fvs = apdb.get_entry(self.APP_MUX_CABLE, "Ethernet0") + for key in fvs: + if key == "state": + assert fvs[key] == "active", "Ethernet0 Mux state is not active after warm boot, state: {}".format(fvs[key]) + + fvs = apdb.get_entry(self.APP_MUX_CABLE, "Ethernet4") + for key in fvs: + if key == "state": + assert fvs[key] == "active", "Ethernet4 Mux state is not active after warm boot, state: {}".format(fvs[key]) + + fvs = apdb.get_entry(self.APP_MUX_CABLE, "Ethernet8") + for key in fvs: + if key == "state": + assert fvs[key] == "standby", "Ethernet8 Mux state is not standby after warm boot, state: {}".format(fvs[key]) + + # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down before retrying def test_nonflaky_dummy():