Skip to content

Commit

Permalink
Update restart_waiter_ut (#742)
Browse files Browse the repository at this point in the history
Update restart_waiter_ut to use "enable"/"disable" as values for fast-reboot entry in state-db.

This PR should come along with the following PRs:
sonic-net/sonic-utilities#2621
sonic-net/sonic-buildimage#13484
sonic-net/sonic-platform-daemons#335
sonic-net/sonic-sairedis#1196

This set of PRs solves the issue sonic-net/sonic-buildimage#13251
  • Loading branch information
arfeigin authored and StormLiangMS committed Apr 11, 2023
1 parent 2b0fb67 commit 91b0b18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 10 additions & 4 deletions common/restart_waiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const std::string STATE_DB_NAME = "STATE_DB";
static const std::string STATE_DB_SEPARATOR = "|";
static const std::string RESTART_KEY = "system";
static const std::string RESTART_ENABLE_FIELD = "enable";
static const std::string FAST_REBOOT_TABLE_NAME = "FAST_REBOOT";
static const std::string FAST_REBOOT_TABLE_NAME = "FAST_RESTART_ENABLE_TABLE";

// waitAdvancedBootDone
bool RestartWaiter::waitAdvancedBootDone(
Expand Down Expand Up @@ -71,7 +71,14 @@ bool RestartWaiter::doWait(DBConnector &stateDb,

bool RestartWaiter::isAdvancedBootInProgress(DBConnector &stateDb)
{
auto ret = stateDb.hget(STATE_WARM_RESTART_ENABLE_TABLE_NAME + STATE_DB_SEPARATOR + RESTART_KEY, RESTART_ENABLE_FIELD);
return isAdvancedBootInProgressHelper(stateDb);
}

bool RestartWaiter::isAdvancedBootInProgressHelper(DBConnector &stateDb,
bool checkFastBoot)
{
std::string table_name = checkFastBoot ? FAST_REBOOT_TABLE_NAME : STATE_WARM_RESTART_ENABLE_TABLE_NAME;
auto ret = stateDb.hget(table_name + STATE_DB_SEPARATOR + RESTART_KEY, RESTART_ENABLE_FIELD);
if (ret) {
std::string value = *ret.get();
boost::to_lower(value);
Expand All @@ -82,8 +89,7 @@ bool RestartWaiter::isAdvancedBootInProgress(DBConnector &stateDb)

bool RestartWaiter::isFastBootInProgress(DBConnector &stateDb)
{
auto ret = stateDb.get(FAST_REBOOT_TABLE_NAME + STATE_DB_SEPARATOR + RESTART_KEY);
return ret.get() != nullptr;
return isAdvancedBootInProgressHelper(stateDb, true);
}

bool RestartWaiter::isWarmBootInProgress(swss::DBConnector &stateDb)
Expand Down
4 changes: 3 additions & 1 deletion common/restart_waiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class RestartWaiter
static bool waitFastBootDone(unsigned int maxWaitSec = 180,
unsigned int dbTimeout = 0,
bool isTcpConn = false);


static bool isAdvancedBootInProgressHelper(swss::DBConnector &stateDb,
bool checkFastBoot = false);
static bool isAdvancedBootInProgress(swss::DBConnector &stateDb);
static bool isFastBootInProgress(swss::DBConnector &stateDb);
static bool isWarmBootInProgress(swss::DBConnector &stateDb);
Expand Down
6 changes: 3 additions & 3 deletions tests/restart_waiter_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace swss;
using namespace std;

static const string FAST_REBOOT_KEY = "FAST_REBOOT|system";
static const string FAST_REBOOT_KEY = "FAST_RESTART_ENABLE_TABLE|system";

static void set_reboot_status(string status, int delay = 0)
{
Expand All @@ -31,12 +31,12 @@ class FastBootHelper
public:
FastBootHelper(): db("STATE_DB", 0)
{
db.set(FAST_REBOOT_KEY, "1");
db.hset(FAST_REBOOT_KEY, "enable", "true");
}

~FastBootHelper()
{
db.del({FAST_REBOOT_KEY});
db.hset(FAST_REBOOT_KEY, "enable", "false");
}
private:
DBConnector db;
Expand Down

0 comments on commit 91b0b18

Please sign in to comment.