forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[IntfMgrd] Retry adding ipv6 prefix to iface if it fails because of disabled_ipv6 flag set to 1 #9
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b79d490
brief changes added
vivekrnv 846331e
Change completed and UT's added
vivekrnv 5a36dfd
missing ut file added
vivekrnv 37402bf
Minor fix
vivekrnv dd729a6
Minor fix
vivekrnv 0e56a7a
Removed global ipv6 check and refactored
vivekrnv ac357d1
Removed recursive approach
vivekrnv 99dcddf
makefile updated
vivekrnv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "gtest/gtest.h" | ||
#include <iostream> | ||
#include <fstream> | ||
#include <unistd.h> | ||
#include <sys/stat.h> | ||
#include "../mock_table.h" | ||
#include "warm_restart.h" | ||
#define private public | ||
#include "intfmgr.h" | ||
#undef private | ||
|
||
/* Override this pointer for custom behavior */ | ||
int (*callback)(const std::string &cmd, std::string &stdout) = nullptr; | ||
std::vector<std::string> mockCallArgs; | ||
|
||
namespace swss { | ||
int exec(const std::string &cmd, std::string &stdout) | ||
{ | ||
mockCallArgs.push_back(cmd); | ||
return callback(cmd, stdout); | ||
} | ||
} | ||
|
||
bool Ethernet0IPv6Set = false; | ||
|
||
int cb(const std::string &cmd, std::string &stdout){ | ||
if (cmd == "sysctl -w net.ipv6.conf.\"Ethernet0\".disable_ipv6=0") Ethernet0IPv6Set = true; | ||
else if (cmd.find("/sbin/ip -6 address \"add\"") == 0) { | ||
return Ethernet0IPv6Set ? 0 : 2; | ||
} | ||
else { | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
|
||
// Test Fixture | ||
namespace add_ipv6_prefix_ut | ||
{ | ||
struct IntfMgrTest : 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::vector<std::string> cfg_intf_tables; | ||
|
||
virtual 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); | ||
|
||
swss::WarmStart::initialize("intfmgrd", "swss"); | ||
|
||
std::vector<std::string> tables = { | ||
CFG_INTF_TABLE_NAME, | ||
CFG_LAG_INTF_TABLE_NAME, | ||
CFG_VLAN_INTF_TABLE_NAME, | ||
CFG_LOOPBACK_INTERFACE_TABLE_NAME, | ||
CFG_VLAN_SUB_INTF_TABLE_NAME, | ||
CFG_VOQ_INBAND_INTERFACE_TABLE_NAME, | ||
}; | ||
cfg_intf_tables = tables; | ||
mockCallArgs.clear(); | ||
callback = cb; | ||
} | ||
}; | ||
|
||
TEST_F(IntfMgrTest, testSettingIpv6Flag){ | ||
Ethernet0IPv6Set = false; | ||
swss::IntfMgr intfmgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_intf_tables); | ||
/* Set portStateTable */ | ||
std::vector<swss::FieldValueTuple> values; | ||
values.emplace_back("state", "ok"); | ||
intfmgr.m_statePortTable.set("Ethernet0", values, "SET", ""); | ||
/* Set m_stateIntfTable */ | ||
values.clear(); | ||
values.emplace_back("vrf", ""); | ||
intfmgr.m_stateIntfTable.set("Ethernet0", values, "SET", ""); | ||
/* Set Ipv6 prefix */ | ||
const std::vector<std::string>& keys = {"Ethernet0", "2001::8/64"}; | ||
const std::vector<swss::FieldValueTuple> data; | ||
intfmgr.doIntfAddrTask(keys, data, "SET"); | ||
int ip_cmd_called = 0; | ||
for (auto cmd : mockCallArgs){ | ||
if (cmd.find("/sbin/ip -6 address \"add\"") == 0){ | ||
ip_cmd_called++; | ||
} | ||
} | ||
ASSERT_EQ(ip_cmd_called, 2); | ||
} | ||
|
||
TEST_F(IntfMgrTest, testNoSettingIpv6Flag){ | ||
Ethernet0IPv6Set = true; // Assuming it is already set by SDK | ||
swss::IntfMgr intfmgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_intf_tables); | ||
/* Set portStateTable */ | ||
std::vector<swss::FieldValueTuple> values; | ||
values.emplace_back("state", "ok"); | ||
intfmgr.m_statePortTable.set("Ethernet0", values, "SET", ""); | ||
/* Set m_stateIntfTable */ | ||
values.clear(); | ||
values.emplace_back("vrf", ""); | ||
intfmgr.m_stateIntfTable.set("Ethernet0", values, "SET", ""); | ||
/* Set Ipv6 prefix */ | ||
const std::vector<std::string>& keys = {"Ethernet0", "2001::8/64"}; | ||
const std::vector<swss::FieldValueTuple> data; | ||
intfmgr.doIntfAddrTask(keys, data, "SET"); | ||
int ip_cmd_called = 0; | ||
for (auto cmd : mockCallArgs){ | ||
if (cmd.find("/sbin/ip -6 address \"add\"") == 0){ | ||
ip_cmd_called++; | ||
} | ||
} | ||
ASSERT_EQ(ip_cmd_called, 1); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If my understanding is correct, this mock works due to how dynamic linker resolves symbols. Since swss::exec is defined inside tests binary it is getting used instead of swss::exec from libswsscommon.so. That means every test, not just add_ipv6_prefix_ut tests will use this version of swss::exec, however, they won't have an API to provide mock implementation. Is my undestanding correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests_intfmgrd will be compiled into a different binary so the other orchgent tests are not affected.