Check for missing endpoints when adding assocs
An association links 2 D-Bus object paths together, one
which is the path that has the original associations
property, and another endpoint path. It's possible that
that endpoint path doesn't exist on D-Bus when that
associations property is created.
This commit, along with upcoming ones, adds support to not
create the actual association object paths until that
endpoint path shows up on D-Bus. In addition, if that
endpoint path were to get removed from D-Bus in the future,
then the association paths should be removed until that
path is back again.
This particular commit introduces the PendingAssociations map
to track these cases, and adds support in the associationChanged
path to add associations to this map if the endpoint path isn't
on D-Bus instead of just blindly creating the association objects.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1f4bf0e02bf7a350d9e3f18c3591737289a51a39
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index ce3c9eb..e443043 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -167,6 +167,7 @@
TEST_F(TestAssociations, associationChangedEmptyEndpoint)
{
std::vector<Association> associations = {{"inventory", "error", ""}};
+ interface_map_type interfaceMap;
AssociationMaps assocMaps;
assocMaps.owners = createDefaultOwnerAssociation();
@@ -174,7 +175,7 @@
// Empty endpoint will result in deletion of corresponding assocInterface
associationChanged(*server, associations, DEFAULT_SOURCE_PATH,
- DEFAULT_DBUS_SVC, assocMaps);
+ DEFAULT_DBUS_SVC, interfaceMap, assocMaps);
// Both of these should be 0 since we have an invalid endpoint
auto intfEndpoints =
@@ -182,6 +183,8 @@
EXPECT_EQ(intfEndpoints.size(), 0);
intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
+
+ EXPECT_EQ(assocMaps.pending.size(), 0);
}
// Add a new association with endpoint
@@ -194,8 +197,13 @@
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
+ // Make it look like the assoc endpoints are on D-Bus
+ interface_map_type interfaceMap = {
+ {"/new/source/path", {{DEFAULT_DBUS_SVC, {"a"}}}},
+ {"/xyz/openbmc_project/new/endpoint", {{DEFAULT_DBUS_SVC, {"a"}}}}};
+
associationChanged(*server, associations, "/new/source/path",
- DEFAULT_DBUS_SVC, assocMaps);
+ DEFAULT_DBUS_SVC, interfaceMap, assocMaps);
// Two source paths
EXPECT_EQ(assocMaps.owners.size(), 2);
@@ -203,6 +211,9 @@
// Four interfaces
EXPECT_EQ(assocMaps.ifaces.size(), 4);
+ // Nothing pending
+ EXPECT_EQ(assocMaps.pending.size(), 0);
+
// New endpoint so assocMaps.ifaces should be same size
auto intfEndpoints =
std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
@@ -222,12 +233,18 @@
// changed association and interface
AssociationMaps assocMaps;
+ // Make it look like the assoc endpoints are on D-Bus
+ interface_map_type interfaceMap = createDefaultInterfaceMap();
+
associationChanged(*server, associations, DEFAULT_SOURCE_PATH,
- DEFAULT_DBUS_SVC, assocMaps);
+ DEFAULT_DBUS_SVC, interfaceMap, assocMaps);
// New associations so ensure it now contains a single entry
EXPECT_EQ(assocMaps.owners.size(), 1);
+ // Nothing pending
+ EXPECT_EQ(assocMaps.pending.size(), 0);
+
// Verify corresponding assoc paths each have one endpoint in assoc
// interfaces and that those endpoints match
auto singleOwner = assocMaps.owners[DEFAULT_SOURCE_PATH];
@@ -248,12 +265,15 @@
{"inventory", "error",
"/xyz/openbmc_project/inventory/system/chassis"}};
+ // Make it look like the assoc endpoints are on D-Bus
+ interface_map_type interfaceMap = createDefaultInterfaceMap();
+
AssociationMaps assocMaps;
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
associationChanged(*server, associations, DEFAULT_SOURCE_PATH, newOwner,
- assocMaps);
+ interfaceMap, assocMaps);
// New endpoint so assocOwners should be same size
EXPECT_EQ(assocMaps.owners.size(), 1);
@@ -267,6 +287,9 @@
auto a = assocMaps.owners.find(DEFAULT_SOURCE_PATH);
auto o = a->second.find(newOwner);
EXPECT_EQ(o->second.size(), 2);
+
+ // Nothing pending
+ EXPECT_EQ(assocMaps.pending.size(), 0);
}
// Add a new association to existing interface path
@@ -275,12 +298,15 @@
std::vector<Association> associations = {
{"abc", "error", "/xyz/openbmc_project/inventory/system/chassis"}};
+ // Make it look like the assoc endpoints are on D-Bus
+ interface_map_type interfaceMap = createDefaultInterfaceMap();
+
AssociationMaps assocMaps;
assocMaps.owners = createDefaultOwnerAssociation();
assocMaps.ifaces = createDefaultInterfaceAssociation(server);
associationChanged(*server, associations, DEFAULT_SOURCE_PATH,
- DEFAULT_DBUS_SVC, assocMaps);
+ DEFAULT_DBUS_SVC, interfaceMap, assocMaps);
// Should have 3 entries in AssociationInterfaces, one is just missing an
// endpoint
@@ -298,4 +324,6 @@
// Added to an existing owner path so still 1
EXPECT_EQ(assocMaps.owners.size(), 1);
+
+ EXPECT_EQ(assocMaps.pending.size(), 0);
}