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

Fix potential defects #2516

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
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
114 changes: 65 additions & 49 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,17 @@ void getCfgSwitchType(DBConnector *cfgDb, string &switch_type)
{
Table cfgDeviceMetaDataTable(cfgDb, CFG_DEVICE_METADATA_TABLE_NAME);

if (!cfgDeviceMetaDataTable.hget("localhost", "switch_type", switch_type))
try
{
//Switch type is not configured. Consider it default = "switch" (regular switch)
if (!cfgDeviceMetaDataTable.hget("localhost", "switch_type", switch_type))
{
//Switch type is not configured. Consider it default = "switch" (regular switch)
switch_type = "switch";
}
}
catch(const std::system_error& e)
{
SWSS_LOG_ERROR("System error: %s", e.what());
switch_type = "switch";
}

Expand All @@ -196,64 +204,72 @@ bool getSystemPortConfigList(DBConnector *cfgDb, DBConnector *appDb, vector<sai_
return true;
}

string value;
if (!cfgDeviceMetaDataTable.hget("localhost", "switch_id", value))
try
{
//VOQ switch id is not configured.
SWSS_LOG_ERROR("VOQ switch id is not configured");
return false;
}
string value;
if (!cfgDeviceMetaDataTable.hget("localhost", "switch_id", value))
{
//VOQ switch id is not configured.
SWSS_LOG_ERROR("VOQ switch id is not configured");
return false;
}

if (value.size())
gVoqMySwitchId = stoi(value);
if (value.size())
gVoqMySwitchId = stoi(value);

if (gVoqMySwitchId < 0)
{
SWSS_LOG_ERROR("Invalid VOQ switch id %d configured", gVoqMySwitchId);
return false;
}
if (gVoqMySwitchId < 0)
{
SWSS_LOG_ERROR("Invalid VOQ switch id %d configured", gVoqMySwitchId);
return false;
}

if (!cfgDeviceMetaDataTable.hget("localhost", "max_cores", value))
{
//VOQ max cores is not configured.
SWSS_LOG_ERROR("VOQ max cores is not configured");
return false;
}
if (!cfgDeviceMetaDataTable.hget("localhost", "max_cores", value))
{
//VOQ max cores is not configured.
SWSS_LOG_ERROR("VOQ max cores is not configured");
return false;
}

if (value.size())
gVoqMaxCores = stoi(value);
if (value.size())
gVoqMaxCores = stoi(value);

if (gVoqMaxCores == 0)
{
SWSS_LOG_ERROR("Invalid VOQ max cores %d configured", gVoqMaxCores);
return false;
}
if (gVoqMaxCores == 0)
{
SWSS_LOG_ERROR("Invalid VOQ max cores %d configured", gVoqMaxCores);
return false;
}

if (!cfgDeviceMetaDataTable.hget("localhost", "hostname", value))
{
// hostname is not configured.
SWSS_LOG_ERROR("Host name is not configured");
return false;
}
gMyHostName = value;
if (!cfgDeviceMetaDataTable.hget("localhost", "hostname", value))
{
// hostname is not configured.
SWSS_LOG_ERROR("Host name is not configured");
return false;
}
gMyHostName = value;

if (!gMyHostName.size())
{
SWSS_LOG_ERROR("Invalid host name %s configured", gMyHostName.c_str());
return false;
}
if (!gMyHostName.size())
{
SWSS_LOG_ERROR("Invalid host name %s configured", gMyHostName.c_str());
return false;
}

if (!cfgDeviceMetaDataTable.hget("localhost", "asic_name", value))
{
// asic_name is not configured.
SWSS_LOG_ERROR("Asic name is not configured");
return false;
}
gMyAsicName = value;
if (!cfgDeviceMetaDataTable.hget("localhost", "asic_name", value))
{
// asic_name is not configured.
SWSS_LOG_ERROR("Asic name is not configured");
return false;
}
gMyAsicName = value;

if (!gMyAsicName.size())
if (!gMyAsicName.size())
{
SWSS_LOG_ERROR("Invalid asic name %s configured", gMyAsicName.c_str());
return false;
}
}
catch(const std::system_error& e)
{
SWSS_LOG_ERROR("Invalid asic name %s configured", gMyAsicName.c_str());
SWSS_LOG_ERROR("System error: %s", e.what());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Port
}

std::string m_alias;
Type m_type;
Type m_type = UNKNOWN;
int m_index = 0; // PHY_PORT: index
uint32_t m_mtu = DEFAULT_MTU;
uint32_t m_speed = 0; // Mbps
Expand Down
8 changes: 6 additions & 2 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,11 @@ sai_status_t PortsOrch::removePort(sai_object_id_t port_id)
*/
if (getPort(port_id, port))
{
setPortAdminStatus(port, false);
/* Bring port down before removing port */
if (!setPortAdminStatus(port, false))
{
SWSS_LOG_ERROR("Failed to set admin status to DOWN to remove port %" PRIx64, port_id);
}
}
/* else : port is in default state or not yet created */

Expand Down Expand Up @@ -4440,7 +4444,7 @@ void PortsOrch::doTask()
APP_LAG_TABLE_NAME,
APP_LAG_MEMBER_TABLE_NAME,
APP_VLAN_TABLE_NAME,
APP_VLAN_MEMBER_TABLE_NAME,
APP_VLAN_MEMBER_TABLE_NAME
};

for (auto tableName: tableOrder)
Expand Down
52 changes: 31 additions & 21 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,33 @@ void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo

int main(int argc, char **argv)
{
Logger::linkToDbNative("portsyncd");
int opt;

while ((opt = getopt(argc, argv, "v:h")) != -1 )
try
{
switch (opt)
Logger::linkToDbNative("portsyncd");
int opt;

while ((opt = getopt(argc, argv, "v:h")) != -1 )
{
case 'h':
usage();
return 1;
default: /* '?' */
usage();
return EXIT_FAILURE;
switch (opt)
{
case 'h':
usage();
return 1;
default: /* '?' */
usage();
return EXIT_FAILURE;
}
}
}

DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appl_db("APPL_DB", 0);
DBConnector state_db("STATE_DB", 0);
ProducerStateTable p(&appl_db, APP_PORT_TABLE_NAME);
DBConnector cfgDb("CONFIG_DB", 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like there are unexpected diffs due to tab space. Can you fix the spacing diff in this PR and have only the relevant ones?

Copy link
Contributor Author

@Liran-Ar Liran-Ar Nov 15, 2022

Choose a reason for hiding this comment

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

Hi, these indents were done on purpose since the code was inserted under the "try" block, stated on line 49.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @prsunny , the PR merging is blocked due to coverage check failure (only 4 code lines are missing to reach the minimum threshold).
We've tried to expand existing unit tests or create new ones but found out that covering the missing lines via unit tests is very complex because it is called only from main() function.
Therefore, and because I didn't add any new functionality, I would ask for a waiver on the coverage check for this very unique case, Is it possible?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @prsunny , the PR merging is blocked due to coverage check failure (only 4 code lines are missing to reach the minimum threshold). We've tried to expand existing unit tests or create new ones but found out that covering the missing lines via unit tests is very complex because it is called only from main() function. Therefore, and because I didn't add any new functionality, I would ask for a waiver on the coverage check for this very unique case, Is it possible?

@prsunny could you please refer to this question?

DBConnector appl_db("APPL_DB", 0);
DBConnector state_db("STATE_DB", 0);
ProducerStateTable p(&appl_db, APP_PORT_TABLE_NAME);

WarmStart::initialize("portsyncd", "swss");
WarmStart::checkWarmStart("portsyncd", "swss");
const bool warm = WarmStart::isWarmStart();
WarmStart::initialize("portsyncd", "swss");
WarmStart::checkWarmStart("portsyncd", "swss");
const bool warm = WarmStart::isWarmStart();

try
{
NetLink netlink;
Select s;

Expand Down Expand Up @@ -136,6 +136,16 @@ int main(int argc, char **argv)
}
}
}
catch (const swss::RedisError& e)
{
cerr << "Exception \"" << e.what() << "\" was thrown in daemon" << endl;
return EXIT_FAILURE;
}
catch (const std::out_of_range& e)
{
cerr << "Exception \"" << e.what() << "\" was thrown in daemon" << endl;
return EXIT_FAILURE;
}
catch (const std::exception& e)
{
cerr << "Exception \"" << e.what() << "\" was thrown in daemon" << endl;
Expand Down