Skip to content

Commit 20116a1

Browse files
author
Shuotian Cheng
authored
orchagent: Fixing resolveFieldRefValue() bug multiple fields with same name (sonic-net#125)
1 parent bde9154 commit 20116a1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

orchagent/orch.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ bool Orch::execute(string tableName)
123123
bool Orch::parseReference(type_map &type_maps, string &ref_in, string &type_name, string &object_name)
124124
{
125125
SWSS_LOG_ENTER();
126+
126127
SWSS_LOG_DEBUG("input:%s", ref_in.c_str());
127128
if (ref_in.size() < 3)
128129
{
@@ -168,15 +169,16 @@ ref_resolve_status Orch::resolveFieldRefValue(
168169
sai_object_id_t &sai_object)
169170
{
170171
SWSS_LOG_ENTER();
171-
size_t count = 0;
172+
173+
bool hit = false;
172174
for (auto i = kfvFieldsValues(tuple).begin(); i != kfvFieldsValues(tuple).end(); i++)
173175
{
174176
if (fvField(*i) == field_name)
175177
{
176178
SWSS_LOG_DEBUG("field:%s, value:%s", fvField(*i).c_str(), fvValue(*i).c_str());
177-
if (count > 1)
179+
if (hit)
178180
{
179-
SWSS_LOG_ERROR("Singleton field with name:%s must have only 1 instance, actual count:%d\n", field_name.c_str(), count);
181+
SWSS_LOG_ERROR("Multiple same fields %s", field_name.c_str());
180182
return ref_resolve_status::multiple_instances;
181183
}
182184
string ref_type_name, object_name;
@@ -185,12 +187,11 @@ ref_resolve_status Orch::resolveFieldRefValue(
185187
return ref_resolve_status::not_resolved;
186188
}
187189
sai_object = (*(type_maps[ref_type_name]))[object_name];
188-
count++;
190+
hit = true;
189191
}
190192
}
191-
if (0 == count)
193+
if (!hit)
192194
{
193-
SWSS_LOG_NOTICE("field with name:%s not found\n", field_name.c_str());
194195
return ref_resolve_status::field_not_found;
195196
}
196197
return ref_resolve_status::success;

0 commit comments

Comments
 (0)