Skip to content
Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ tests/mock_tests/tests_fpmsyncd
tests/mock_tests/tests_intfmgrd
tests/mock_tests/tests_teammgrd
tests/mock_tests/tests_portsyncd
tests/mock_tests/tests_teamsyncd


# Test Files #
Expand Down
28 changes: 3 additions & 25 deletions teamsyncd/teamsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ void TeamSync::applyState()

m_lagTable.apply_temp_view();
m_lagMemberTable.apply_temp_view();

for(auto &it: m_stateLagTablePreserved)
{
const auto &lagName = it.first;
const auto &fvVector = it.second;
m_stateLagTable.set(lagName, fvVector);
}

m_stateLagTablePreserved.clear();
}

void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
Expand Down Expand Up @@ -172,14 +163,8 @@ void TeamSync::addLag(const string &lagName, int ifindex, bool admin_state,

FieldValueTuple s("state", "ok");
fvVector.push_back(s);
if (m_warmstart)
{
m_stateLagTablePreserved[lagName] = fvVector;
}
else
{
m_stateLagTable.set(lagName, fvVector);
}

m_stateLagTable.set(lagName, fvVector);

if (lag_update)
{
Expand Down Expand Up @@ -211,14 +196,7 @@ void TeamSync::removeLag(const string &lagName)
if (m_teamSelectables.find(lagName) == m_teamSelectables.end())
return;

if (m_warmstart)
{
m_stateLagTablePreserved.erase(lagName);
}
else
{
m_stateLagTable.del(lagName);
}
m_stateLagTable.del(lagName);

m_selectablesToRemove.insert(lagName);
}
Expand Down
1 change: 0 additions & 1 deletion teamsyncd/teamsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class TeamSync : public NetMsg
Table m_stateLagTable;

bool m_warmstart;
std::unordered_map<std::string, std::vector<FieldValueTuple>> m_stateLagTablePreserved;
steady_clock::time_point m_start_time;
uint32_t m_pending_timeout;

Expand Down
23 changes: 21 additions & 2 deletions tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ CXXFLAGS = -g -O0

CFLAGS_SAI = -I /usr/include/sai

TESTS = tests tests_intfmgrd tests_teammgrd tests_portsyncd tests_fpmsyncd tests_response_publisher
TESTS = tests tests_intfmgrd tests_teammgrd tests_portsyncd tests_fpmsyncd tests_response_publisher tests_teamsyncd

noinst_PROGRAMS = tests tests_intfmgrd tests_teammgrd tests_portsyncd tests_fpmsyncd tests_response_publisher
noinst_PROGRAMS = tests tests_intfmgrd tests_teammgrd tests_portsyncd tests_fpmsyncd tests_response_publisher tests_teamsyncd

LDADD_SAI = -lsaimeta -lsaimetadata -lsaivs -lsairedis

Expand Down Expand Up @@ -220,6 +220,25 @@ tests_portsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GT
tests_portsyncd_LDADD = $(LDADD_GTEST) -lnl-genl-3 -lhiredis -lhiredis \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lnl-3 -lnl-route-3 -lpthread

## teamsyncd unit tests

tests_teamsyncd_SOURCES = teamsyncd/teamsyncd_ut.cpp \
teamsyncd/mock_libteam.cpp \
$(top_srcdir)/lib/recorder.cpp \
$(top_srcdir)/teamsyncd/teamsync.cpp \
mock_dbconnector.cpp \
common/mock_shell_command.cpp \
mock_table.cpp \
mock_hiredis.cpp \
mock_redisreply.cpp

tests_teamsyncd_INCLUDES = -I $(top_srcdir)/teamsyncd -I $(top_srcdir)/cfgmgr -I $(top_srcdir)/lib
tests_teamsyncd_CXXFLAGS = -Wl,-wrap,if_nameindex -Wl,-wrap,if_freenameindex
tests_teamsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST)
tests_teamsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(tests_teamsyncd_INCLUDES)
tests_teamsyncd_LDADD = $(LDADD_GTEST) -lnl-genl-3 -lhiredis -lhiredis \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lnl-3 -lnl-route-3 -lpthread -lteam

## intfmgrd unit tests

tests_intfmgrd_SOURCES = intfmgrd/intfmgr_ut.cpp \
Expand Down
35 changes: 35 additions & 0 deletions tests/mock_tests/teamsyncd/mock_libteam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern "C"
{

#include <cstddef>
#include <team.h>

team_handle* team_alloc()
{
return reinterpret_cast<team_handle*>(1);
}

int team_init(team_handle*, uint32_t)
{
return 0;
}

void team_free(team_handle*)
{
}

int team_change_handler_register(team_handle*, const team_change_handler*, void*)
{
return 0;
}

void team_change_handler_unregister(team_handle*, const team_change_handler*, void*)
{
}

team_port* team_get_next_port(team_handle*, team_port*)
{
return nullptr;
}

}
47 changes: 47 additions & 0 deletions tests/mock_tests/teamsyncd/teamsyncd_ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "gtest/gtest.h"
#define protected public
#define private public
#include "teamsync.h"
#undef protected
#undef private
#include "mock_table.h"

namespace teamsyncd_ut
{
struct TeamSyncdTest : public ::testing::Test
{
std::shared_ptr<swss::DBConnector> m_config_db;
std::shared_ptr<swss::DBConnector> m_app_db;
std::shared_ptr<swss::DBConnector> m_state_db;

std::shared_ptr<swss::Table> m_stateWarmRestartTable;

void SetUp() override
{
testing_db::reset();
m_config_db = std::make_shared<swss::DBConnector>("CONFIG_DB", 0);
m_app_db = std::make_shared<swss::DBConnector>("APPL_DB", 0);
m_state_db = std::make_shared<swss::DBConnector>("STATE_DB", 0);
}
};

TEST_F(TeamSyncdTest, testAddingLagOnWarmBootSetsStateDbFlag)
{
swss::TeamSync sync(m_config_db.get(), m_state_db.get(), nullptr);
swss::Table stateLagTable(m_state_db.get(), STATE_LAG_TABLE_NAME);

sync.m_warmstart = true;

const bool admin_state = true;
const bool oper_state = true;
const int if_index = 1;
const unsigned int mtu = 1500;
const char* lag_name = "PortChannel1";
sync.addLag(lag_name, if_index, admin_state, oper_state, mtu);

std::string okValue;
const bool found = stateLagTable.hget(lag_name, "state", okValue);
ASSERT_TRUE(found);
ASSERT_EQ(okValue, "ok");
}
}
Loading