bmcweb: Fix PartLocationContext for Chassis

I wrongly assumed that an object cannot have both chassis interface
and connector interface which warthog object does. So
PartLocationContext was being derived twice. In this changeset i am
making sure that /containedby association is explored only when chassis
interface is detected after exploring all interfaces including connector

Tested:
```
root@jkeju13-nfd01:~# wget -qO- localhost:80/redfish/v1/Chassis/warthog_1
{
  "@odata.id": "/redfish/v1/Chassis/warthog_1",
  "@odata.type": "#Chassis.v1_17_0.Chassis",
  "Assembly": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/Assembly"
  },
  "ChassisType": "RackMount",
  "Drives": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/Drives"
  },
  "EnvironmentMetrics": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/EnvironmentMetrics"
  },
  "Id": "warthog_1",
  "Links": {
    "ComputerSystems": [
      {
        "@odata.id": "/redfish/v1/Systems/system"
      }
    ],
    "ContainedBy": {
      "@odata.id": "/redfish/v1/Chassis/ioadapter_x8x8_1"
    },
    "ManagedBy": [
      {
        "@odata.id": "/redfish/v1/Managers/bmc"
      }
    ],
    "Storage": [
      {
        "@odata.id": "/redfish/v1/Systems/system/Storage/warthog_storage_1"
      }
    ],
    "Storage@odata.count": 1
  },
  "Location": {
    "PartLocation": {
      "LocationType": "Slot",
      "ServiceLabel": "IO0"
    },
    "PartLocationContext": "PE2"
  },
  "Manufacturer": "Kingston",
  "Model": "Warthog",
  "Name": "warthog_1",
  "PCIeDevices": {
    "@odata.id": "/redfish/v1/Systems/system/PCIeDevices"
  },
  "PartNumber": "KW049419-67901",
  "Power": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/Power"
  },
  "PowerState": "On",
  "PowerSubsystem": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/PowerSubsystem"
  },
  "Sensors": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/Sensors"
  },
  "SerialNumber": "20819562",
  "Status": {
    "Health": "OK",
    "HealthRollup": "OK",
    "State": "Enabled"
  },
  "Thermal": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/Thermal"
  },
  "ThermalSubsystem": {
    "@odata.id": "/redfish/v1/Chassis/warthog_1/ThermalSubsystem"
  }
}
```

Google-Bug-Id: 283353012
Change-Id: I5b41e172cdbb793ba8e2c5d354037485f4c1b1b4
Signed-off-by: Rahul Kapoor <rahulkpr@google.com>
(cherry picked from commit 0051ac5abae4182ee747e67d56455bc7eeb901c2)
diff --git a/recipes-phosphor/interfaces/bmcweb/0004-storage-add-support-for-multiple-storages.patch b/recipes-phosphor/interfaces/bmcweb/0004-storage-add-support-for-multiple-storages.patch
index d96ebd6..f6f6446 100644
--- a/recipes-phosphor/interfaces/bmcweb/0004-storage-add-support-for-multiple-storages.patch
+++ b/recipes-phosphor/interfaces/bmcweb/0004-storage-add-support-for-multiple-storages.patch
@@ -1,4 +1,4 @@
-From 765173ac866aebc555834bdf8733d37d70ea16ce Mon Sep 17 00:00:00 2001
+From 47e243f9359498a775182ae4d668731911af1827 Mon Sep 17 00:00:00 2001
 From: Willy Tu <wltu@google.com>
 Date: Tue, 26 Jul 2022 00:41:55 +0000
 Subject: [PATCH] storage: add support for multiple storages
@@ -140,19 +140,20 @@
 Signed-off-by: Willy Tu <wltu@google.com>
 Signed-off-by: Tom Tung <shes050117@gmail.com>
 Signed-off-by: Willy Tu <wltu@google.com>
+
 ---
  redfish-core/lib/chassis.hpp |  51 ++++++++++-
  redfish-core/lib/storage.hpp | 170 ++++++++++++++++++++++++++++++-----
  2 files changed, 199 insertions(+), 22 deletions(-)
 
 diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
-index 0bc77c9f..da1bbf47 100644
+index 709be8f5..730e1664 100644
 --- a/redfish-core/lib/chassis.hpp
 +++ b/redfish-core/lib/chassis.hpp
 @@ -36,6 +36,54 @@
  namespace redfish
  {
-
+ 
 +/**
 + * @brief Retrieves resources over dbus to link to the chassis
 + *
@@ -219,10 +220,10 @@
                  getChassisState(asyncResp);
 +                getStorageLink(asyncResp, path);
                  });
-
-             for (const auto& interface : interfaces2)
+ 
+             bool hasChassisInterface = false;
 diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
-index 89ace599..eaa0bc76 100644
+index 776bbb3f..7fd9276d 100644
 --- a/redfish-core/lib/storage.hpp
 +++ b/redfish-core/lib/storage.hpp
 @@ -59,12 +59,36 @@ inline void requestRoutesStorageCollection(App& app)
@@ -267,9 +268,9 @@
 +            interface);
          });
  }
-
+ 
 @@ -115,28 +139,134 @@ inline void getDrives(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-
+ 
  inline void requestRoutesStorage(App& app)
  {
 -    BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/1/")
@@ -297,7 +298,7 @@
 +                                       systemName);
 +            return;
 +        }
-
+ 
 -        auto health = std::make_shared<HealthPopulate>(asyncResp);
 -        health->populate();
 +        constexpr std::array<std::string_view, 1> interfaces = {
@@ -328,7 +329,7 @@
 +                    asyncResp->res, "#Storage.v1_13_0.Storage", storageId);
 +                return;
 +            }
-
+ 
 -        getDrives(asyncResp, health);
 -        asyncResp->res.jsonValue["Controllers"]["@odata.id"] =
 -            "/redfish/v1/Systems/system/Storage/1/Controllers";
@@ -415,8 +416,8 @@
 +            });
          });
  }
-
-@@ -631,7 +761,6 @@ inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ 
+@@ -633,7 +763,6 @@ inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                         const boost::system::error_code& ec,
                         const dbus::utility::MapperGetSubTreeResponse& subtree)
  {
@@ -424,7 +425,7 @@
      if (ec)
      {
          BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
-@@ -679,7 +808,6 @@ inline void
+@@ -681,7 +810,6 @@ inline void
                        const std::string& driveName,
                        const std::vector<std::string>& resp)
  {
@@ -432,6 +433,3 @@
      for (const std::string& drivePath : resp)
      {
          sdbusplus::message::object_path path(drivePath);
---
-2.40.0.634.g4ca3ef3211-goog
-
diff --git a/recipes-phosphor/interfaces/bmcweb/0009-Chassis-Add-PartLocationContext-in-chassis.patch b/recipes-phosphor/interfaces/bmcweb/0009-Chassis-Add-PartLocationContext-in-chassis.patch
index 8f23b77..d667b18 100644
--- a/recipes-phosphor/interfaces/bmcweb/0009-Chassis-Add-PartLocationContext-in-chassis.patch
+++ b/recipes-phosphor/interfaces/bmcweb/0009-Chassis-Add-PartLocationContext-in-chassis.patch
@@ -1,4 +1,4 @@
-From 31cb299f58cec3aeac296ec604ebf03b63eb8ac9 Mon Sep 17 00:00:00 2001
+From 23eef76aabb165e3b7133b20d327260e4e8376b0 Mon Sep 17 00:00:00 2001
 From: Rahul Kapoor <rahulkpr@google.com>
 Date: Mon, 8 May 2023 21:54:36 +0000
 Subject: [PATCH] Chassis: Add PartLocationContext in chassis
@@ -50,14 +50,22 @@
 Signed-off-by: Rahul Kapoor <rahulkpr@google.com>
 
 ---
- redfish-core/lib/chassis.hpp | 18 ++++++++++++++----
- 1 file changed, 14 insertions(+), 4 deletions(-)
+ redfish-core/lib/chassis.hpp | 26 ++++++++++++++++++++++----
+ 1 file changed, 22 insertions(+), 4 deletions(-)
 
 diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
-index 3a270d57..2be6f938 100644
+index 3a270d57..36a950e7 100644
 --- a/redfish-core/lib/chassis.hpp
 +++ b/redfish-core/lib/chassis.hpp
-@@ -429,9 +429,9 @@ inline void
+@@ -420,6 +420,7 @@ inline void
+                 getChassisState(asyncResp);
+                 });
+ 
++            bool hasChassisInterface = false;
+             for (const auto& interface : interfaces2)
+             {
+                 if (interface == "xyz.openbmc_project.Common.UUID")
+@@ -429,9 +430,9 @@ inline void
                  else if (interface ==
                           "xyz.openbmc_project.Inventory.Decorator.LocationCode")
                  {
@@ -70,13 +78,11 @@
                  }
                  else if (location_util::isConnector(interface))
                  {
-@@ -444,11 +444,21 @@ inline void
+@@ -444,13 +445,30 @@ inline void
                              << interface;
                          continue;
                      }
 -
-+                    location_util::getPartLocationContext(
-+                        asyncResp, "/Location"_json_pointer, path + "/chassis");
                      asyncResp->res.jsonValue["Location"]["PartLocation"]
                                              ["LocationType"] =
                          *locationType;
@@ -86,10 +92,21 @@
 +                         interface ==
 +                             "xyz.openbmc_project.Inventory.Item.Board")
 +                {
-+                    location_util::getPartLocationContext(
-+                        asyncResp, "/Location"_json_pointer,
-+                        path + "/contained_by");
++                    hasChassisInterface = true;
 +                }
              }
  
++            if (hasChassisInterface)
++            {
++                location_util::getPartLocationContext(asyncResp,
++                                                      "/Location"_json_pointer,
++                                                      path + "/contained_by");
++            }
++            else
++            {
++                location_util::getPartLocationContext(
++                    asyncResp, "/Location"_json_pointer, path + "/chassis");
++            }
              return;
+         }
+ 
diff --git a/recipes-phosphor/interfaces/bmcweb/0012-chassis-Set-Chassis.Reset-to-support-only-RackMount-.patch b/recipes-phosphor/interfaces/bmcweb/0012-chassis-Set-Chassis.Reset-to-support-only-RackMount-.patch
index 1cf0050..849d8a0 100644
--- a/recipes-phosphor/interfaces/bmcweb/0012-chassis-Set-Chassis.Reset-to-support-only-RackMount-.patch
+++ b/recipes-phosphor/interfaces/bmcweb/0012-chassis-Set-Chassis.Reset-to-support-only-RackMount-.patch
@@ -1,4 +1,4 @@
-From 68727acab031fb8ce8fe62b311941a3376f96b7f Mon Sep 17 00:00:00 2001
+From bf308df4f966ec2edb8e795861232d487e4357ae Mon Sep 17 00:00:00 2001
 From: Willy Tu <wltu@google.com>
 Date: Thu, 29 Jul 2021 11:31:54 -0700
 Subject: [PATCH] chassis: Set Chassis.Reset to support only RackMount
@@ -93,11 +93,11 @@
 Signed-off-by: Willy Tu <wltu@google.com>
 
 ---
- redfish-core/lib/chassis.hpp | 307 +++++++++++++++++++++++++++++++----
- 1 file changed, 279 insertions(+), 28 deletions(-)
+ redfish-core/lib/chassis.hpp | 300 +++++++++++++++++++++++++++++++----
+ 1 file changed, 272 insertions(+), 28 deletions(-)
 
 diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
-index 8b64faa0..35c8ea54 100644
+index 730e1664..921f4738 100644
 --- a/redfish-core/lib/chassis.hpp
 +++ b/redfish-core/lib/chassis.hpp
 @@ -31,6 +31,7 @@
@@ -205,7 +205,7 @@
 +            return;
 +        }
 +        callback(ec, val);
-+        },
++    },
 +        connectionName, path, "org.freedesktop.DBus.Properties", "Get",
 +        "xyz.openbmc_project.Inventory.Item.Chassis", "Type");
 +}
@@ -229,7 +229,7 @@
 +
 +        asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
 +            property;
-+        });
++    });
 +}
 +
  inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -250,19 +250,10 @@
              asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] =
                  crow::utility::urlFromPieces("redfish", "v1", "Systems",
                                               "system", "PCIeDevices");
-@@ -548,6 +661,7 @@ inline void
-                 getStorageLink(asyncResp, path);
-                 });
- 
-+            bool addedChassisResetAction = false;
-             for (const auto& interface : interfaces2)
-             {
-                 if (interface == "xyz.openbmc_project.Common.UUID")
-@@ -586,9 +700,31 @@ inline void
-                     location_util::getPartLocationContext(
-                         asyncResp, "/Location"_json_pointer,
-                         path + "/contained_by");
-+
+@@ -583,6 +696,19 @@ inline void
+                              "xyz.openbmc_project.Inventory.Item.Board")
+                 {
+                     hasChassisInterface = true;
 +                    getChassisType(
 +                        connectionName, path,
 +                        [asyncResp,
@@ -275,22 +266,21 @@
 +                        }
 +                        addChassisReset(asyncResp, chassisId,
 +                                        getChassisTypeProperty(property));
-+                        });
-+                    addedChassisResetAction = true;
++                    });
                  }
              }
  
-+            // Item.Chassis interface is not available
-+            // Enable Reset Action by default.
-+            if (!addedChassisResetAction)
-+            {
+@@ -596,6 +722,9 @@ inline void
+             {
+                 location_util::getPartLocationContext(
+                     asyncResp, "/Location"_json_pointer, path + "/chassis");
++                // Item.Chassis interface is not available
++                // Enable Reset Action by default.
 +                addChassisReset(asyncResp, chassisId, std::nullopt);
-+            }
-+
+             }
              return;
          }
- 
-@@ -792,29 +928,93 @@ inline void
+@@ -800,29 +929,93 @@ inline void
          });
  }
  
@@ -345,7 +335,7 @@
 +        }
 +        messages::resourceNotFound(asyncResp->res, "#Chassis.v1_14_0.Chassis",
 +                                   chassisId);
-+        },
++    },
 +        "xyz.openbmc_project.ObjectMapper",
 +        "/xyz/openbmc_project/object_mapper",
 +        "xyz.openbmc_project.ObjectMapper", "GetSubTree",
@@ -395,7 +385,7 @@
                                                "ResetType");
  
          return;
-@@ -822,6 +1022,25 @@ inline void handleChassisResetActionInfoPost(
+@@ -830,6 +1023,25 @@ inline void handleChassisResetActionInfoPost(
      doChassisPowerCycle(asyncResp);
  }
  
@@ -421,7 +411,7 @@
  /**
   * ChassisResetAction class supports the POST method for the Reset
   * action.
-@@ -837,20 +1056,15 @@ inline void requestRoutesChassisResetAction(App& app)
+@@ -845,20 +1057,15 @@ inline void requestRoutesChassisResetAction(App& app)
              std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
  }
  
@@ -445,7 +435,7 @@
      asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
      nlohmann::json::array_t parameters;
      nlohmann::json::object_t parameter;
-@@ -859,12 +1073,49 @@ inline void handleChassisResetActionInfoGet(
+@@ -867,12 +1074,49 @@ inline void handleChassisResetActionInfoGet(
      parameter["DataType"] = "String";
      nlohmann::json::array_t allowed;
      allowed.push_back("PowerCycle");