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

[orchdaemon]: Fixed sairedis record file rotation #2481

Merged
merged 5 commits into from
Oct 6, 2022
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
1 change: 0 additions & 1 deletion orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
bool gSairedisRecord = true;
bool gSwssRecord = true;
bool gLogRotate = false;
bool gSaiRedisLogRotate = false;
bool gSyncMode = false;
sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC;
string gAsicInstance;
Expand Down
34 changes: 23 additions & 11 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BfdOrch *gBfdOrch;
QosOrch *gQosOrch;

bool gIsNatSupported = false;
bool gSaiRedisLogRotate = false;

#define DEFAULT_MAX_BULK_SIZE 1000
size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE;
Expand Down Expand Up @@ -529,24 +530,24 @@ void OrchDaemon::flush()
SWSS_LOG_ERROR("Failed to flush redis pipeline %d", status);
exit(EXIT_FAILURE);
}
}

// check if logroate is requested
if (gSaiRedisLogRotate)
{
SWSS_LOG_NOTICE("performing log rotate");

gSaiRedisLogRotate = false;

attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE;
attr.value.booldata = true;

sai_switch_api->set_switch_attribute(gSwitchId, &attr);
/* Release the file handle so the log can be rotated */
void OrchDaemon::logRotate() {
SWSS_LOG_ENTER();
sai_attribute_t attr;
attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE;
attr.value.booldata = true;
sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
if (status != SAI_STATUS_SUCCESS) {
SWSS_LOG_ERROR("Failed to release the file handle on sairedis log %d", status);
}
}

void OrchDaemon::start()
{
SWSS_LOG_ENTER();
gSaiRedisLogRotate = false;

for (Orch *o : m_orchList)
{
Expand Down Expand Up @@ -590,6 +591,17 @@ void OrchDaemon::start()
continue;
}

// check if logroate is requested
if (gSaiRedisLogRotate)
{
SWSS_LOG_NOTICE("performing log rotate");

gSaiRedisLogRotate = false;

logRotate();
continue;
}

auto *c = (Executor *)s;
c->execute();

Expand Down
3 changes: 3 additions & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#include "natorch.h"
#include "muxorch.h"
#include "bfdorch.h"
#include <sairedis.h>

using namespace swss;
extern bool gSaiRedisLogRotate;

class OrchDaemon
{
Expand All @@ -49,6 +51,7 @@ class OrchDaemon
bool warmRestoreValidation();

bool warmRestartCheck();
void logRotate();
private:
DBConnector *m_applDb;
DBConnector *m_configDb;
Expand Down
6 changes: 4 additions & 2 deletions tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FLEX_CTR_DIR = $(top_srcdir)/orchagent/flex_counter
DEBUG_CTR_DIR = $(top_srcdir)/orchagent/debug_counter

INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib
INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib -I$(top_srcdir)/orchagent

CFLAGS_SAI = -I /usr/include/sai

Expand Down Expand Up @@ -33,6 +33,8 @@ tests_SOURCES = aclorch_ut.cpp \
mock_hiredis.cpp \
mock_redisreply.cpp \
bulker_ut.cpp \
mock_sai_switch.cpp \
orchdaemon_ut.cpp \
$(top_srcdir)/lib/gearboxutils.cpp \
$(top_srcdir)/orchagent/orchdaemon.cpp \
$(top_srcdir)/orchagent/orch.cpp \
Expand Down Expand Up @@ -76,4 +78,4 @@ tests_SOURCES += $(DEBUG_CTR_DIR)/debug_counter.cpp $(DEBUG_CTR_DIR)/drop_counte
tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) -I$(top_srcdir)/orchagent
tests_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis -lpthread \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lgmock -lgmock_main
1 change: 0 additions & 1 deletion tests/mock_tests/mock_orchagent_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
bool gSairedisRecord = true;
bool gSwssRecord = true;
bool gLogRotate = false;
bool gSaiRedisLogRotate = false;
ofstream gRecordOfs;
string gRecordFile;

Expand Down
1 change: 0 additions & 1 deletion tests/mock_tests/mock_orchagent_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extern int gBatchSize;
extern bool gSwssRecord;
extern bool gSairedisRecord;
extern bool gLogRotate;
extern bool gSaiRedisLogRotate;
extern ofstream gRecordOfs;
extern string gRecordFile;

Expand Down
14 changes: 14 additions & 0 deletions tests/mock_tests/mock_sai_switch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "mock_sai_switch.h"

MockSaiSwitch *mock_sai_switch;

sai_status_t mock_get_switch_attribute(_In_ sai_object_id_t switch_id, _In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list)
{
return mock_sai_switch->get_switch_attribute(switch_id, attr_count, attr_list);
}

sai_status_t mock_set_switch_attribute(_In_ sai_object_id_t switch_id, _In_ const sai_attribute_t *attr)
{
return mock_sai_switch->set_switch_attribute(switch_id, attr);
}
24 changes: 24 additions & 0 deletions tests/mock_tests/mock_sai_switch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <gmock/gmock.h>

extern "C"
{
#include "sai.h"
}

// Mock Class mapping methods to switch object SAI APIs.
class MockSaiSwitch
{
public:
MOCK_METHOD3(get_switch_attribute, sai_status_t(_In_ sai_object_id_t switch_id, _In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list));
MOCK_METHOD2(set_switch_attribute, sai_status_t(_In_ sai_object_id_t switch_id, _In_ const sai_attribute_t *attr));
};

extern MockSaiSwitch *mock_sai_switch;

sai_status_t mock_get_switch_attribute(_In_ sai_object_id_t switch_id, _In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list);

sai_status_t mock_set_switch_attribute(_In_ sai_object_id_t switch_id, _In_ const sai_attribute_t *attr);
51 changes: 51 additions & 0 deletions tests/mock_tests/orchdaemon_ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "orchdaemon.h"
#include "dbconnector.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "mock_sai_switch.h"

extern sai_switch_api_t* sai_switch_api;
sai_switch_api_t test_sai_switch;

namespace orchdaemon_test
{

using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;

DBConnector appl_db("APPL_DB", 0);
DBConnector state_db("STATE_DB", 0);
DBConnector config_db("CONFIG_DB", 0);

class OrchDaemonTest : public ::testing::Test
{
public:
StrictMock<MockSaiSwitch> mock_sai_switch_;

OrchDaemon* orchd;

OrchDaemonTest()
{
mock_sai_switch = &mock_sai_switch_;
sai_switch_api = &test_sai_switch;
sai_switch_api->get_switch_attribute = &mock_get_switch_attribute;
sai_switch_api->set_switch_attribute = &mock_set_switch_attribute;

orchd = new OrchDaemon(&appl_db, &config_db, &state_db);

};

~OrchDaemonTest()
{

};
};

TEST_F(OrchDaemonTest, logRotate)
{
EXPECT_CALL(mock_sai_switch_, set_switch_attribute( _, _)).WillOnce(Return(SAI_STATUS_SUCCESS));

orchd->logRotate();
}
}