Skip to content
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

If available, read port settings from Config DB first #723

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void usage()
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm);
void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm);
bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm);
void handleVlanIntfFile(string file);
void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map);
void checkPortInitDone(DBConnector *appl_db);
Expand Down Expand Up @@ -92,11 +92,14 @@ int main(int argc, char **argv)
netlink.dumpRequest(RTM_GETLINK);
cout << "Listen to link messages..." << endl;

if (!port_config_file.empty())
if (!handlePortConfigFromConfigDB(p, cfgDb, warm))
{
handlePortConfigFile(p, port_config_file, warm);
} else {
handlePortConfigFromConfigDB(p, cfgDb, warm);
// if port config is missing in ConfigDB
// attempt to use port_config.ini
if (!port_config_file.empty())
{
handlePortConfigFile(p, port_config_file, warm);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we "throw" if port_config_file.empty() is true in this else branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to keep the old logic as it was before

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, if not in this PR, we probably need add some logic here later in case both places do not have the port config.

}

s.addSelectable(&netlink);
Expand Down Expand Up @@ -175,14 +178,21 @@ static void notifyPortConfigDone(ProducerStateTable &p)
p.set("PortConfigDone", attrs);
}

void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
{
cout << "Get port configuration from ConfigDB..." << endl;

Table table(&cfgDb, CFG_PORT_TABLE_NAME);
std::vector<FieldValueTuple> ovalues;
std::vector<string> keys;
table.getKeys(keys);

if (keys.empty())
{
cout << "No port configuration in ConfigDB" << endl;
return false;
}

for ( auto &k : keys )
{
table.get(k, ovalues);
Expand All @@ -202,6 +212,8 @@ void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo
{
notifyPortConfigDone(p);
}

return true;
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm)
Expand Down