Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update restart_waiter_ut #742

Merged
merged 6 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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