Skip to content

Commit

Permalink
[orchdaemon]: Fixed sairedis record file rotation
Browse files Browse the repository at this point in the history
What I did
Fix sonic-net/sonic-buildimage#8162

Moved sairedis record file rotation logic out of flush() to fix issue.

Why I did it
Sairedis record file was not releasing the file handle on rotation. This is because the file handle release was inside the flush() which was only being called if a select timeout was triggered. Moved the logic to its own function which is called in the start() loop.

How I verified it
Ran a script to fill log and verified that rotation was happening correctly.

Signed-off-by: Bryan Crossland bryan.crossland@target.com
  • Loading branch information
bacrossland committed Oct 4, 2022
1 parent 569c8b1 commit caa0fb9
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
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
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);
52 changes: 52 additions & 0 deletions tests/mock_tests/orchdaemon_ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#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);
DBConnector counters_db("COUNTERS_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, &counters_db);

};

~OrchDaemonTest()
{

};
};

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

orchd->logRotate();
}
}

0 comments on commit caa0fb9

Please sign in to comment.