Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 1 | #include "src/associations.hpp" |
| 2 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 3 | #include "src/test/util/asio_server_class.hpp" |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 4 | #include "src/test/util/association_objects.hpp" |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 5 | #include "src/test/util/debug_output.hpp" |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 6 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 7 | #include <sdbusplus/asio/connection.hpp> |
| 8 | #include <sdbusplus/asio/object_server.hpp> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 12 | class TestAssociations : public AsioServerClassTest |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 13 | { |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 14 | }; |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 15 | sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server = |
| 16 | nullptr; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 17 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 18 | // Verify call when path is not in associated owners |
| 19 | TEST_F(TestAssociations, SourcePathNotInAssociations) |
| 20 | { |
| 21 | EXPECT_NE(nullptr, server); |
| 22 | std::string sourcePath = "/xyz/openbmc_project/no/association"; |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 23 | AssociationMaps assocMaps; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 24 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 25 | removeAssociation(sourcePath, DEFAULT_DBUS_SVC, *server, assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // Verify call when owner is not in associated owners |
| 29 | TEST_F(TestAssociations, OwnerNotInAssociations) |
| 30 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 31 | AssociationMaps assocMaps; |
| 32 | assocMaps.owners = createDefaultOwnerAssociation(); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 33 | |
| 34 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 35 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // Verify call when path is not in associated interfaces |
| 39 | TEST_F(TestAssociations, PathNotInAssocInterfaces) |
| 40 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 41 | AssociationMaps assocMaps; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 42 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 43 | assocMaps.owners = createDefaultOwnerAssociation(); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 44 | |
| 45 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 46 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 47 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 48 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Verify call when path is in associated interfaces |
| 52 | TEST_F(TestAssociations, PathIsInAssociatedInterfaces) |
| 53 | { |
| 54 | // Build up these objects so that an associated interface will match |
| 55 | // with the associated owner being removed |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 56 | AssociationMaps assocMaps; |
| 57 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 58 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 59 | |
| 60 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 61 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 62 | |
| 63 | // Verify owner association was deleted |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 64 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 65 | |
| 66 | // Verify endpoint was deleted from interface association |
| 67 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 68 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 69 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 70 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 71 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 72 | } |
| 73 | |
| 74 | // Verify call when path is in associated interfaces, with extra endpoints |
| 75 | TEST_F(TestAssociations, PathIsInAssociatedInterfacesExtraEndpoints) |
| 76 | { |
| 77 | // Build up these objects so that an associated interface will match |
| 78 | // with the associated owner being removed |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 79 | AssociationMaps assocMaps; |
| 80 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 81 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 82 | |
| 83 | // Add another endpoint to the assoc interfaces |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 84 | addEndpointToInterfaceAssociation(assocMaps.ifaces); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 85 | |
| 86 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 87 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 88 | |
| 89 | // Verify owner association was deleted |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 90 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 91 | |
| 92 | // Verify all endpoints are deleted since source path was deleted |
| 93 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 94 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 95 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 96 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 97 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 98 | } |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 99 | |
| 100 | // Verify no associations or endpoints removed when the change is identical |
| 101 | TEST_F(TestAssociations, checkAssociationEndpointRemovesNoEpRemove) |
| 102 | { |
| 103 | |
| 104 | AssociationPaths newAssocPaths = { |
| 105 | {DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT}}, |
| 106 | {DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH}}}; |
| 107 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 108 | AssociationMaps assocMaps; |
| 109 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 110 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 111 | |
| 112 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 113 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 114 | |
| 115 | // Verify endpoints were not deleted because they matche with what was |
| 116 | // in the original |
| 117 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 118 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 119 | EXPECT_EQ(intfEndpoints.size(), 1); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 120 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 121 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 122 | } |
| 123 | |
| 124 | // Verify endpoint is removed when assoc path is different |
| 125 | TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveApDiff) |
| 126 | { |
| 127 | AssociationPaths newAssocPaths = {{"/different/path", {DEFAULT_ENDPOINT}}}; |
| 128 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 129 | AssociationMaps assocMaps; |
| 130 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 131 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 132 | |
| 133 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 134 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 135 | |
| 136 | // Verify initial endpoints were deleted because the new path |
| 137 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 138 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 139 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 140 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 141 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 142 | } |
| 143 | |
| 144 | // Verify endpoint is removed when endpoint is different |
| 145 | TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveEpChanged) |
| 146 | { |
| 147 | AssociationPaths newAssocPaths = { |
| 148 | {DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT + "/different"}}, |
| 149 | {DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH + "/different"}}}; |
| 150 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 151 | AssociationMaps assocMaps; |
| 152 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 153 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 154 | |
| 155 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 156 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 157 | |
| 158 | // Verify initial endpoints were deleted because of different endpoints |
| 159 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 160 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 161 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 162 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 163 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 164 | } |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 165 | |
| 166 | // Verify existing endpoint deleted when empty endpoint is provided |
| 167 | TEST_F(TestAssociations, associationChangedEmptyEndpoint) |
| 168 | { |
| 169 | std::vector<Association> associations = {{"inventory", "error", ""}}; |
| 170 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 171 | AssociationMaps assocMaps; |
| 172 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 173 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 174 | |
| 175 | // Empty endpoint will result in deletion of corresponding assocInterface |
| 176 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 177 | DEFAULT_DBUS_SVC, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 178 | |
Andrew Geissler | 0a560a5 | 2019-03-22 10:59:07 -0500 | [diff] [blame] | 179 | // Both of these should be 0 since we have an invalid endpoint |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 180 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 181 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 0a560a5 | 2019-03-22 10:59:07 -0500 | [diff] [blame] | 182 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 183 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 184 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 185 | } |
| 186 | |
| 187 | // Add a new association with endpoint |
| 188 | TEST_F(TestAssociations, associationChangedAddNewAssoc) |
| 189 | { |
| 190 | std::vector<Association> associations = { |
| 191 | {"abc", "def", "/xyz/openbmc_project/new/endpoint"}}; |
| 192 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 193 | AssociationMaps assocMaps; |
| 194 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 195 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 196 | |
| 197 | associationChanged(*server, associations, "/new/source/path", |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 198 | DEFAULT_DBUS_SVC, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 199 | |
| 200 | // Two source paths |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 201 | EXPECT_EQ(assocMaps.owners.size(), 2); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 202 | |
| 203 | // Four interfaces |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 204 | EXPECT_EQ(assocMaps.ifaces.size(), 4); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 205 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 206 | // New endpoint so assocMaps.ifaces should be same size |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 207 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 208 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 209 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 210 | } |
| 211 | |
| 212 | // Add a new association to empty objects |
| 213 | TEST_F(TestAssociations, associationChangedAddNewAssocEmptyObj) |
| 214 | { |
| 215 | std::string sourcePath = "/logging/entry/1"; |
| 216 | std::string owner = "xyz.openbmc_project.Test"; |
| 217 | std::vector<Association> associations = { |
| 218 | {"inventory", "error", |
| 219 | "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 220 | |
| 221 | // Empty objects because this test will ensure assocOwners adds the |
| 222 | // changed association and interface |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 223 | AssociationMaps assocMaps; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 224 | |
| 225 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 226 | DEFAULT_DBUS_SVC, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 227 | |
| 228 | // New associations so ensure it now contains a single entry |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 229 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 230 | |
| 231 | // Verify corresponding assoc paths each have one endpoint in assoc |
| 232 | // interfaces and that those endpoints match |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 233 | auto singleOwner = assocMaps.owners[DEFAULT_SOURCE_PATH]; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 234 | auto singleIntf = singleOwner[DEFAULT_DBUS_SVC]; |
| 235 | for (auto i : singleIntf) |
| 236 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 237 | auto intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[i.first]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 238 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 239 | EXPECT_EQ(intfEndpoints[0], *i.second.begin()); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // Add a new association to same source path but with new owner |
| 244 | TEST_F(TestAssociations, associationChangedAddNewAssocNewOwner) |
| 245 | { |
| 246 | std::string newOwner = "xyz.openbmc_project.Test2"; |
| 247 | std::vector<Association> associations = { |
| 248 | {"inventory", "error", |
| 249 | "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 250 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 251 | AssociationMaps assocMaps; |
| 252 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 253 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 254 | |
| 255 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, newOwner, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 256 | assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 257 | |
| 258 | // New endpoint so assocOwners should be same size |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 259 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 260 | |
| 261 | // Ensure only one endpoint under first path |
| 262 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 263 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 264 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 265 | |
| 266 | // Ensure the 2 new association endpoints are under the new owner |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 267 | auto a = assocMaps.owners.find(DEFAULT_SOURCE_PATH); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 268 | auto o = a->second.find(newOwner); |
| 269 | EXPECT_EQ(o->second.size(), 2); |
| 270 | } |
| 271 | |
| 272 | // Add a new association to existing interface path |
| 273 | TEST_F(TestAssociations, associationChangedAddNewAssocSameInterface) |
| 274 | { |
| 275 | std::vector<Association> associations = { |
| 276 | {"abc", "error", "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 277 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 278 | AssociationMaps assocMaps; |
| 279 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 280 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 281 | |
| 282 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 283 | DEFAULT_DBUS_SVC, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 284 | |
| 285 | // Should have 3 entries in AssociationInterfaces, one is just missing an |
| 286 | // endpoint |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 287 | EXPECT_EQ(assocMaps.ifaces.size(), 3); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 288 | |
| 289 | // Change to existing interface so it will be removed here |
| 290 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 291 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 292 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 293 | |
| 294 | // The new endpoint should exist though in it's place |
| 295 | intfEndpoints = std::get<endpointsPos>( |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 296 | assocMaps.ifaces[DEFAULT_SOURCE_PATH + "/" + "abc"]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 297 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 298 | |
| 299 | // Added to an existing owner path so still 1 |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame^] | 300 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 301 | } |