Skip to content
Open
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
8 changes: 8 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,14 @@ void Meta::meta_generic_validation_post_remove(
return;
}

// Make sure the object exists before trying to get its attributes
if (!m_saiObjectCollection.objectExists(meta_key))
{
SWSS_LOG_ERROR("FATAL: object %s doesn't exist",
sai_serialize_object_meta_key(meta_key).c_str());
return;
}

// get all attributes that was set

for (auto&it: m_saiObjectCollection.getObject(meta_key)->getAttributes())
Expand Down
12 changes: 8 additions & 4 deletions meta/SaiObjectCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ void SaiObjectCollection::createObject(

if (objectExists(metaKey))
{
SWSS_LOG_THROW("FATAL: object %s already exists",
SWSS_LOG_ERROR("FATAL: object %s already exists",
sai_serialize_object_meta_key(metaKey).c_str());
return;
}

m_objects[metaKey] = obj;
Expand All @@ -44,8 +45,9 @@ void SaiObjectCollection::removeObject(

if (!objectExists(metaKey))
{
SWSS_LOG_THROW("FATAL: object %s doesn't exist",
SWSS_LOG_ERROR("FATAL: object %s doesn't exist",
sai_serialize_object_meta_key(metaKey).c_str());
return;
}

m_objects.erase(metaKey);
Expand All @@ -60,8 +62,9 @@ void SaiObjectCollection::setObjectAttr(

if (!objectExists(metaKey))
{
SWSS_LOG_THROW("FATAL: object %s doesn't exist",
SWSS_LOG_ERROR("FATAL: object %s doesn't exist",
sai_serialize_object_meta_key(metaKey).c_str());
return;
}

m_objects[metaKey]->setAttr(&md, attr);
Expand Down Expand Up @@ -115,8 +118,9 @@ std::shared_ptr<SaiObject> SaiObjectCollection::getObject(

if (!objectExists(metaKey))
{
SWSS_LOG_THROW("FATAL: object %s doesn't exist",
SWSS_LOG_ERROR("FATAL: object %s doesn't exist",
sai_serialize_object_meta_key(metaKey).c_str());
return nullptr;
}

return m_objects.at(metaKey);
Expand Down
8 changes: 4 additions & 4 deletions unittest/meta/TestSaiObjectCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(SaiObjectCollection, createObject)

oc.createObject(mk);

EXPECT_THROW(oc.createObject(mk), std::runtime_error);
EXPECT_NO_THROW(oc.createObject(mk));
}

TEST(SaiObjectCollection, removeObject)
Expand All @@ -23,7 +23,7 @@ TEST(SaiObjectCollection, removeObject)

SaiObjectCollection oc;

EXPECT_THROW(oc.removeObject(mk), std::runtime_error);
EXPECT_NO_THROW(oc.removeObject(mk));
}

TEST(SaiObjectCollection, setObjectAttr)
Expand All @@ -36,7 +36,7 @@ TEST(SaiObjectCollection, setObjectAttr)
SAI_OBJECT_TYPE_SWITCH,
SAI_SWITCH_ATTR_INIT_SWITCH);

EXPECT_THROW(oc.setObjectAttr(mk, *meta, nullptr), std::runtime_error);
EXPECT_NO_THROW(oc.setObjectAttr(mk, *meta, nullptr));
}

TEST(SaiObjectCollection, getObjectAttr)
Expand All @@ -54,5 +54,5 @@ TEST(SaiObjectCollection, getObject)

SaiObjectCollection oc;

EXPECT_THROW(oc.getObject(mk), std::runtime_error);
EXPECT_NO_THROW(oc.getObject(mk));
}
Loading