Return empty paths if no SubTreePathsById is found
`getAssociatedSubTreePaths()` returns the empty paths if there are no
associated subtrees, and bmcweb uses it to differentiate from the error.
However, `getAssociatedSubTreePathsById()` (which is introduced by [1])
returns NotFound error for the case. It would be more appropriate to
match its behavior with `getAssociatedSubTreePaths()`.
Tested:
- unit-test is succeeded for good and bad cases
[1] https://gerrit.openbmc.org/c/openbmc/phosphor-objmgr/+/70699
Change-Id: I84680b1b39ba8ade94ea6fdb7dae280505e5c050
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/src/handler.cpp b/src/handler.cpp
index 2c4b5d7..4f431d5 100644
--- a/src/handler.cpp
+++ b/src/handler.cpp
@@ -390,11 +390,6 @@
}
}
}
- if (output.empty())
- {
- throw sdbusplus::xyz::openbmc_project::Common::Error::
- ResourceNotFound();
- }
return output;
}
diff --git a/src/test/handler.cpp b/src/test/handler.cpp
index 7f418e5..46d998c 100644
--- a/src/test/handler.cpp
+++ b/src/test/handler.cpp
@@ -449,18 +449,16 @@
std::vector<std::string> endpointvalidInterfaces = {"test_interface_1",
"test_interface_2"};
// invalid id
- EXPECT_THROW(
- getAssociatedSubTreeById(interfaceMap, associationMap, "childx", path,
- subtreeInterfaces, "descendent",
- endpointvalidInterfaces),
- sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
+ ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap, "childx",
+ path, subtreeInterfaces, "descendent",
+ endpointvalidInterfaces)
+ .empty());
// invalid subtreeInterfaces
- EXPECT_THROW(
- getAssociatedSubTreeById(interfaceMap, associationMap, "child", path,
- badsubtreeInterfaces, "descendent",
- endpointvalidInterfaces),
- sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
+ ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap, "child",
+ path, badsubtreeInterfaces,
+ "descendent", endpointvalidInterfaces)
+ .empty());
// invalid endpointinterface
ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap, "child",
@@ -468,11 +466,10 @@
endpointinvalidInterfaces)
.empty());
// valid id, but doesn't have specified interface
- EXPECT_THROW(
- getAssociatedSubTreeById(interfaceMap, associationMap, "grandchild",
- path, subtreeInterfaces, "descendent",
- endpointvalidInterfaces),
- sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
+ ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap,
+ "grandchild", path, subtreeInterfaces,
+ "descendent", endpointvalidInterfaces)
+ .empty());
// invalid association
ASSERT_TRUE(getAssociatedSubTreeById(interfaceMap, associationMap, "child",
@@ -524,18 +521,16 @@
std::vector<std::string> endpointvalidInterfaces = {"test_interface_1",
"test_interface_2"};
// invalid id
- EXPECT_THROW(
- getAssociatedSubTreePathsById(interfaceMap, associationMap, "childx",
- path, subtreeInterfaces, "descendent",
- endpointvalidInterfaces),
- sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
+ ASSERT_TRUE(getAssociatedSubTreePathsById(
+ interfaceMap, associationMap, "childx", path,
+ subtreeInterfaces, "descendent", endpointvalidInterfaces)
+ .empty());
// invalid subtreeInterfaces
- EXPECT_THROW(
- getAssociatedSubTreePathsById(interfaceMap, associationMap, "child",
- path, badsubtreeInterfaces, "descendent",
- endpointvalidInterfaces),
- sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
+ ASSERT_TRUE(getAssociatedSubTreePathsById(
+ interfaceMap, associationMap, "child", path,
+ badsubtreeInterfaces, "descendent", endpointvalidInterfaces)
+ .empty());
// invalid endpointinterface
ASSERT_TRUE(getAssociatedSubTreePathsById(
@@ -543,11 +538,10 @@
subtreeInterfaces, "descendent", endpointinvalidInterfaces)
.empty());
// valid id, but doesn't have specified interface
- EXPECT_THROW(
- getAssociatedSubTreePathsById(interfaceMap, associationMap,
- "grandchild", path, subtreeInterfaces,
- "descendent", endpointvalidInterfaces),
- sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound);
+ ASSERT_TRUE(getAssociatedSubTreePathsById(
+ interfaceMap, associationMap, "grandchild", path,
+ subtreeInterfaces, "descendent", endpointvalidInterfaces)
+ .empty());
// invalid association
ASSERT_TRUE(getAssociatedSubTreePathsById(interfaceMap, associationMap,