-
Notifications
You must be signed in to change notification settings - Fork 692
Connect to teamd before adding the lag to STATE_DB #3984
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
Merged
prsunny
merged 16 commits into
sonic-net:master
from
saiarcot895:fix-teamdsyncd-race-condition
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f9abf24
Connect to teamd before adding the lag to STATE_DB
saiarcot895 3dc6420
Merge branch 'master' into fix-teamdsyncd-race-condition
saiarcot895 f9cae00
Bug and style fixes
saiarcot895 8c48f08
Merge branch 'fix-teamdsyncd-race-condition' of github.com:saiarcot89…
saiarcot895 17ad529
Merge branch 'master' into fix-teamdsyncd-race-condition
saiarcot895 fc730f9
Merge branch 'master' into fix-teamdsyncd-race-condition
prsunny 425500a
Merge branch 'master' into fix-teamdsyncd-race-condition
saiarcot895 a880c61
Merge branch 'master' into fix-teamdsyncd-race-condition
saiarcot895 295afa2
Merge commit 'f39134cbb25b6cf27358437a88de6c55c6dc16a1' into fix-team…
saiarcot895 7e84155
Add some mock tests for teamsyncd
saiarcot895 1304a59
Merge branch 'fix-teamdsyncd-race-condition' of github.com:saiarcot89…
saiarcot895 0abb535
Add more tests
saiarcot895 d6b1810
Merge branch 'master' into fix-teamdsyncd-race-condition
judyjoseph 2e3f35c
Merge branch 'master' into fix-teamdsyncd-race-condition
judyjoseph 1edff3c
Fix Trixie build error
saiarcot895 ca35fd3
Merge branch 'master' into fix-teamdsyncd-race-condition
judyjoseph 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,185 @@ | ||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
| #include <dlfcn.h> | ||
| #include <stdexcept> | ||
| #include <team.h> | ||
| #include <teamdctl.h> | ||
| #include "teamsync.h" | ||
|
|
||
| static unsigned int (*callback_sleep)(unsigned int seconds) = NULL; | ||
| static int (*callback_team_init)(struct team_handle *th, uint32_t ifindex) = NULL; | ||
| static int (*callback_team_change_handler)(struct team_handle *th, struct team_change_handler *handler, void *priv) = NULL; | ||
| static int (*callback_teamdctl_connect)(struct teamdctl *tdc, const char *team_name, const char *addr, const char *cli_type) = NULL; | ||
| static int (*callback_teamdctl_config_get_raw_direct)(struct teamdctl *tdc, char **response) = NULL; | ||
| static void (*callback_teamdctl_disconnect)(struct teamdctl *tdc) = NULL; | ||
|
|
||
| static unsigned int cb_sleep(unsigned int seconds) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| unsigned int sleep(unsigned int seconds) | ||
| { | ||
| if (callback_sleep) | ||
| { | ||
| return callback_sleep(seconds); | ||
| } | ||
| unsigned int (*realfunc)(unsigned int) = | ||
| (unsigned int (*)(unsigned int))(dlsym (RTLD_NEXT, "sleep")); | ||
| return realfunc(seconds); | ||
| } | ||
|
|
||
|
|
||
| static int cb_team_init(struct team_handle *th, uint32_t ifindex) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int team_init(struct team_handle *th, uint32_t ifindex) | ||
| { | ||
| if (callback_team_init) | ||
| { | ||
| return callback_team_init(th, ifindex); | ||
| } | ||
| int (*realfunc)(struct team_handle *, uint32_t) = | ||
| (int (*)(struct team_handle *, uint32_t))(dlsym (RTLD_NEXT, "team_init")); | ||
| return realfunc(th, ifindex); | ||
| } | ||
|
|
||
| static int cb_team_change_handler(struct team_handle *th, struct team_change_handler *handler, void *priv) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int team_change_handler(struct team_handle *th, struct team_change_handler *handler, void *priv) | ||
| { | ||
| if (callback_team_change_handler) | ||
| { | ||
| return callback_team_change_handler(th, handler, priv); | ||
| } | ||
| int (*realfunc)(struct team_handle *, struct team_change_handler*, void*) = | ||
| (int (*)(struct team_handle *, struct team_change_handler*, void*))(dlsym (RTLD_NEXT, "team_change_handler")); | ||
| return realfunc(th, handler, priv); | ||
| } | ||
|
|
||
| static int cb_teamdctl_connect(struct teamdctl *tdc, const char *team_name, const char *addr, const char *cli_type) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int teamdctl_connect(struct teamdctl *tdc, const char *team_name, const char *addr, const char *cli_type) | ||
| { | ||
| if (callback_teamdctl_connect) | ||
| { | ||
| return callback_teamdctl_connect(tdc, team_name, addr, cli_type); | ||
| } | ||
| int (*realfunc)(struct teamdctl *, const char *, const char *, const char *) = | ||
| (int (*)(struct teamdctl *, const char *, const char *, const char *))(dlsym (RTLD_NEXT, "teamdctl_connect")); | ||
| return realfunc(tdc, team_name, addr, cli_type); | ||
| } | ||
|
|
||
| static int cb_teamdctl_config_get_raw_direct_force_error(struct teamdctl *tdc, char **response) | ||
| { | ||
| // Forced error | ||
| return 1; | ||
| } | ||
|
|
||
| static int cb_teamdctl_config_get_raw_direct_success(struct teamdctl *tdc, char **response) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int teamdctl_config_get_raw_direct(struct teamdctl *tdc, char **response) | ||
| { | ||
| if (callback_teamdctl_config_get_raw_direct) | ||
| { | ||
| return callback_teamdctl_config_get_raw_direct(tdc, response); | ||
| } | ||
| int (*realfunc)(struct teamdctl *, char **) = | ||
| (int (*)(struct teamdctl *, char **))(dlsym (RTLD_NEXT, "teamdctl_config_get_raw_direct")); | ||
| return realfunc(tdc, response); | ||
| } | ||
|
|
||
| static void cb_teamdctl_disconnect(struct teamdctl *tdc) | ||
| { | ||
| } | ||
|
|
||
| void teamdctl_disconnect(struct teamdctl *tdc) | ||
| { | ||
| if (callback_teamdctl_disconnect) | ||
| { | ||
| callback_teamdctl_disconnect(tdc); | ||
| return; | ||
| } | ||
| int (*realfunc)(struct teamdctl *) = | ||
| (int (*)(struct teamdctl *))(dlsym (RTLD_NEXT, "teamdctl_disconnect")); | ||
| realfunc(tdc); | ||
| } | ||
|
|
||
| namespace teamportsync_test | ||
| { | ||
| struct TeamPortSyncTest : public ::testing::Test | ||
| { | ||
| virtual void SetUp() override | ||
| { | ||
| callback_sleep = cb_sleep; | ||
| callback_team_init = NULL; | ||
| callback_team_change_handler = NULL; | ||
| callback_teamdctl_connect = NULL; | ||
| callback_teamdctl_config_get_raw_direct = cb_teamdctl_config_get_raw_direct_force_error; | ||
| callback_teamdctl_disconnect = cb_teamdctl_disconnect; | ||
| } | ||
|
|
||
| virtual void TearDown() override | ||
| { | ||
| callback_sleep = NULL; | ||
| callback_team_init = NULL; | ||
| callback_team_change_handler = NULL; | ||
| callback_teamdctl_connect = NULL; | ||
| callback_teamdctl_config_get_raw_direct = NULL; | ||
| callback_teamdctl_disconnect = NULL; | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(TeamPortSyncTest, TestInvalidIfIndex) | ||
| { | ||
| try { | ||
| swss::TeamSync::TeamPortSync("testLag", 0, NULL); | ||
| FAIL(); | ||
| } catch (std::runtime_error &exception) { | ||
| EXPECT_THAT(exception.what(), testing::HasSubstr("Unable to initialize team socket")); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(TeamPortSyncTest, NoLagPresent) | ||
| { | ||
| try { | ||
| swss::TeamSync::TeamPortSync("testLag", 4, NULL); | ||
| FAIL(); | ||
| } catch (std::runtime_error &exception) { | ||
| EXPECT_THAT(exception.what(), testing::HasSubstr("Unable to initialize team socket")); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(TeamPortSyncTest, TeamdctlNoConfig) | ||
| { | ||
| callback_team_init = cb_team_init; | ||
| callback_team_change_handler = cb_team_change_handler; | ||
| callback_teamdctl_connect = cb_teamdctl_connect; | ||
| try { | ||
| swss::TeamSync::TeamPortSync("testLag", 4, NULL); | ||
| FAIL(); | ||
| } catch (std::runtime_error &exception) { | ||
| EXPECT_THAT(exception.what(), testing::HasSubstr("Unable to get config from teamd")); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(TeamPortSyncTest, AllSuccess) | ||
| { | ||
| callback_team_init = cb_team_init; | ||
| callback_team_change_handler = cb_team_change_handler; | ||
| callback_teamdctl_connect = cb_teamdctl_connect; | ||
| callback_teamdctl_config_get_raw_direct = cb_teamdctl_config_get_raw_direct_success; | ||
| swss::TeamSync::TeamPortSync("testLag", 4, NULL); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.