-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[orchdaemon]: Fixed sairedis record file rotation (#2481)
**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.
- Loading branch information
1 parent
499b7a7
commit 08711a8
Showing
9 changed files
with
119 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |