RDKEMW-16150: Let's get connected" displayed during Migration testing…#311
Open
gururaajar wants to merge 2 commits into
Open
RDKEMW-16150: Let's get connected" displayed during Migration testing…#311gururaajar wants to merge 2 commits into
gururaajar wants to merge 2 commits into
Conversation
…#296) * RDKEMW-16150: Let's get connected" displayed during Migration testing Reason for Change: Deleting all the connections only in case of BOOT_MIGRATION so that networkmanager connecting to the eth0 connection can be avoided and we can create new "Wired Connection 1" to connect. Test Procedure: Migration Scenario Priority: P1 Risks: Medium Signed-off-by: Gururaaja ESR<Gururaja_ErodeSriranganRamlingham@comcast.com> * RDKEMW-16150: Let's get connected" displayed during Migration testing Reason for Change: Deleting all the connections only in case of BOOT_MIGRATION so that networkmanager connecting to the eth0 connection can be avoided and we can create new "Wired Connection 1" to connect. Test Procedure: Migration Scenario Priority: P1 Risks: Medium Signed-off-by: Gururaaja ESR<Gururaja_ErodeSriranganRamlingham@comcast.com> --------- Signed-off-by: Gururaaja ESR<Gururaja_ErodeSriranganRamlingham@comcast.com>
Reason for Change: Fixed potential causes of plugin crash Test Procedure: Monitor for networkmanager plugin crash Priority: P1 Risks: Medium Signed-off-by: Gururaaja ESR<Gururaja_ErodeSriranganRamlingham@comcast.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the GNOME NetworkManager plugin’s ethernet enable flow to better support migration scenarios by conditionally removing existing wired connection profiles and ensuring a “Wired connection 1” profile is present/activated to avoid unintended autoconnect behavior during BOOT_MIGRATION.
Changes:
- Added
wifiManager::addMinimalEthernetConnection()API and implementation to persist a minimal wired profile vianm_client_add_connection2(). - Updated
NetworkManagerImplementation::SetInterfaceState()to detectBOOT_MIGRATION, disconnect eth0, delete wired profiles, then add/activate the default wired profile when enabling ethernet. - Minor formatting change (blank line) in the proxy implementation.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| plugin/gnome/NetworkManagerGnomeWIFI.h | Adds a new wifiManager method declaration for creating a minimal ethernet connection profile. |
| plugin/gnome/NetworkManagerGnomeWIFI.cpp | Implements the async add-to-disk path for a minimal ethernet connection profile. |
| plugin/gnome/NetworkManagerGnomeProxy.cpp | Adds BOOT_MIGRATION detection + wired profile deletion, then creates/activates the default wired connection on eth enable. |
Comments suppressed due to low confidence (2)
plugin/gnome/NetworkManagerGnomeProxy.cpp:531
- The return value of addMinimalEthernetConnection() is ignored here. If creating the on-disk profile fails, the code still proceeds to enable the interface and later tries to activate "Wired connection 1", which may fail or activate an unexpected existing profile. Please handle the failure (log + return an error, or skip activation and fall back to the existing connection list).
continue;
}
g_ptr_array_add(snapshot, g_object_ref(conn));
}
for(guint i = 0; i < snapshot->len; ++i)
{
NMRemoteConnection *conn = NM_REMOTE_CONNECTION(snapshot->pdata[i]);
plugin/gnome/NetworkManagerGnomeProxy.cpp:520
- New BOOT_MIGRATION behavior (reading /tmp/bootType, disconnecting eth0, snapshotting + deleting wired connections, then adding a minimal profile) isn’t covered by the existing libnm proxy SetInterfaceState_* tests. Please add/extend tests to validate: (1) BOOT_MIGRATION triggers wired-connection deletion, (2) non-migration boots do not delete/add, and (3) failures in delete/add are handled as expected.
rc = Core::ERROR_NONE;
// TODO: if no proimary connection, should we return empty string? RDK V return empty string
}
m_defaultInterface = interface;
return rc;
}
#endif
uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool enabled /* @in */)
{
if(m_nmClient == nullptr)
{
NMLOG_WARNING("NMClient is null");
return Core::ERROR_RPC_CALL_FAILED;
}
if(interface.empty() || (interface != nmUtils::wlanIface() && interface != nmUtils::ethIface()))
{
NMLOG_ERROR("interface: %s; not valied", interface.c_str()!=nullptr? interface.c_str():"empty");
return Core::ERROR_GENERAL;
}
// For ethernet enable: run BOOT_MIGRATION cleanup first, then setInterfaceState
if(enabled && interface == nmUtils::ethIface())
{
// Check boot type and delete all ethernet NM connections if BOOT_MIGRATION
{
const char* bootFile = "/tmp/bootType";
std::ifstream file(bootFile);
if(file.is_open())
{
std::string line, bootTypeValue;
while(std::getline(file, line))
{
const std::string key = "BOOT_TYPE=";
auto pos = line.find(key);
if(pos != std::string::npos)
{
bootTypeValue = line.substr(pos + key.size());
break;
}
}
if(bootTypeValue == "BOOT_MIGRATION")
{
NMLOG_INFO("BOOT_MIGRATION detected, deleting all wired NM connections");
// Bring down the ethernet interface before wiping its connections
// so NM doesn't immediately re-activate them during deletion.
NMDevice *ethDev = nm_client_get_device_by_iface(m_nmClient, interface.c_str());
if(ethDev)
{
GError *discError = nullptr;
if(!nm_device_disconnect(ethDev, nullptr, &discError))
{
NMLOG_WARNING("Failed to disconnect %s before migration cleanup: %s",
interface.c_str(),
discError ? discError->message : "unknown error");
if(discError) g_error_free(discError);
}
}
const GPtrArray *connections = nm_client_get_connections(m_nmClient);
if(connections && connections->len > 0)
{
/* Snapshot the list before iterating: nm_client_get_connections()
* returns an internal array that can be mutated as connections
* are removed, so we must not iterate it while deleting. */
GPtrArray *snapshot = g_ptr_array_new_full(connections->len, g_object_unref);
for(guint i = 0; i < connections->len; ++i)
{
NMRemoteConnection *conn = NM_REMOTE_CONNECTION(connections->pdata[i]);
if(!conn) continue;
NMSettingConnection *sCon = nm_connection_get_setting_connection(NM_CONNECTION(conn));
if(!sCon) continue;
const char *connType = nm_setting_connection_get_connection_type(sCon);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+656
to
+677
| bool wifiManager::addMinimalEthernetConnection(std::string iface) | ||
| { | ||
| if (!createClientNewConnection()) | ||
| return false; | ||
|
|
||
| NMConnection *ethConn = createMinimalEthernetConnection(iface); | ||
| if (ethConn == NULL) | ||
| { | ||
| NMLOG_ERROR("Failed to create minimal ethernet connection"); | ||
| deleteClientConnection(); | ||
| return false; | ||
| } | ||
|
|
||
| GVariant *connSettings = nm_connection_to_dbus(ethConn, NM_CONNECTION_SERIALIZE_ALL); | ||
| g_object_unref(ethConn); | ||
|
|
||
| m_isSuccess = false; | ||
| nm_client_add_connection2(m_client, | ||
| connSettings, | ||
| NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK, | ||
| NULL, TRUE, m_cancellable, | ||
| addMinimalEthernetConnectionCb, this); |
Comment on lines
442
to
+526
| rc = Core::ERROR_NONE; | ||
| // TODO: if no proimary connection, should we return empty string? RDK V return empty string | ||
| } | ||
|
|
||
| m_defaultInterface = interface; | ||
| return rc; | ||
| } | ||
| #endif | ||
|
|
||
| uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool enabled /* @in */) | ||
| { | ||
|
|
||
| if(client == nullptr) | ||
| if(m_nmClient == nullptr) | ||
| { | ||
| NMLOG_WARNING("client connection null:"); | ||
| NMLOG_WARNING("NMClient is null"); | ||
| return Core::ERROR_RPC_CALL_FAILED; | ||
| } | ||
|
|
||
| if(interface.empty() || (interface != nmUtils::wlanIface() && interface != nmUtils::ethIface())) | ||
| { | ||
| NMLOG_ERROR("interface: %s; not valied", interface.c_str()!=nullptr? interface.c_str():"empty"); | ||
| return Core::ERROR_GENERAL; | ||
| } | ||
|
|
||
| if(!wifi->setInterfaceState(interface, enabled)) | ||
| // For ethernet enable: run BOOT_MIGRATION cleanup first, then setInterfaceState | ||
| if(enabled && interface == nmUtils::ethIface()) | ||
| { | ||
| NMLOG_ERROR("interface state change failed"); | ||
| return Core::ERROR_GENERAL; | ||
| } | ||
| // Check boot type and delete all ethernet NM connections if BOOT_MIGRATION | ||
| { | ||
| const char* bootFile = "/tmp/bootType"; | ||
| std::ifstream file(bootFile); | ||
|
|
||
| NMLOG_INFO("interface %s state: %s", interface.c_str(), enabled ? "enabled" : "disabled"); | ||
| // update the interface global cache state | ||
| if(interface == nmUtils::wlanIface() && _instance != NULL) | ||
| _instance->m_wlanEnabled.store(enabled); | ||
| else if(interface == nmUtils::ethIface() && _instance != NULL) | ||
| _instance->m_ethEnabled.store(enabled); | ||
| if(file.is_open()) | ||
| { | ||
| std::string line, bootTypeValue; | ||
| while(std::getline(file, line)) | ||
| { | ||
| const std::string key = "BOOT_TYPE="; | ||
| auto pos = line.find(key); | ||
| if(pos != std::string::npos) | ||
| { | ||
| bootTypeValue = line.substr(pos + key.size()); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if(bootTypeValue == "BOOT_MIGRATION") | ||
| { | ||
| NMLOG_INFO("BOOT_MIGRATION detected, deleting all wired NM connections"); | ||
|
|
||
| // Bring down the ethernet interface before wiping its connections | ||
| // so NM doesn't immediately re-activate them during deletion. | ||
| NMDevice *ethDev = nm_client_get_device_by_iface(m_nmClient, interface.c_str()); | ||
| if(ethDev) | ||
| { | ||
| GError *discError = nullptr; | ||
| if(!nm_device_disconnect(ethDev, nullptr, &discError)) | ||
| { | ||
| NMLOG_WARNING("Failed to disconnect %s before migration cleanup: %s", | ||
| interface.c_str(), | ||
| discError ? discError->message : "unknown error"); | ||
| if(discError) g_error_free(discError); | ||
| } | ||
| } | ||
|
|
||
| const GPtrArray *connections = nm_client_get_connections(m_nmClient); | ||
| if(connections && connections->len > 0) | ||
| { | ||
| /* Snapshot the list before iterating: nm_client_get_connections() | ||
| * returns an internal array that can be mutated as connections | ||
| * are removed, so we must not iterate it while deleting. */ | ||
| GPtrArray *snapshot = g_ptr_array_new_full(connections->len, g_object_unref); | ||
| for(guint i = 0; i < connections->len; ++i) | ||
| { | ||
| NMRemoteConnection *conn = NM_REMOTE_CONNECTION(connections->pdata[i]); | ||
| if(!conn) continue; | ||
| NMSettingConnection *sCon = nm_connection_get_setting_connection(NM_CONNECTION(conn)); | ||
| if(!sCon) continue; | ||
| const char *connType = nm_setting_connection_get_connection_type(sCon); | ||
| if(g_strcmp0(connType, NM_SETTING_WIRED_SETTING_NAME) != 0) | ||
| { | ||
| NMLOG_DEBUG("Skipping non-wired connection type: %s", connType ? connType : "null"); | ||
| continue; | ||
| } | ||
| g_ptr_array_add(snapshot, g_object_ref(conn)); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
… (#296)
Reason for Change: Deleting all the connections only in case of BOOT_MIGRATION so that networkmanager connecting to the eth0 connection can be avoided and we can create new "Wired Connection 1" to connect.
Test Procedure: Migration Scenario
Priority: P1
Risks: Medium
Reason for Change: Deleting all the connections only in case of BOOT_MIGRATION so that networkmanager connecting to the eth0 connection can be avoided and we can create new "Wired Connection 1" to connect.
Test Procedure: Migration Scenario
Priority: P1
Risks: Medium