Skip to content

Commit

Permalink
API for FRU VPD deletion
Browse files Browse the repository at this point in the history
This commit implements the API to perform FRU VPD deletion.

And implements the following tasks:
 - API to getObjectSubTree for an interface.
 - Added a tag "deletion" for the FRUs that requires some actions to be
 performed for deleting the FRU VPD.

Test:
'''
1. Before performing deletion of FRU
root@p10bmc:~# busctl introspect xyz.openbmc_project.Inventory.Manager /xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot2/pcie_card2
NAME                                                  TYPE      SIGNATURE RESULT/VALUE                             FLAGS
com.ibm.ipzvpd.Location                               interface -         -                                        -
.LocationCode                                         property  s         "U780C.ND0.RCH0011-P0-C2"                emits-change writable
com.ibm.ipzvpd.VINI                                   interface -         -                                        -
.B3                                                   property  ay        6 0 0 0 0 0 0                            emits-change writable
.B4                                                   property  ay        1 0                                      emits-change writable
.B7                                                   property  ay        12 0 0 0 0 0 0 0 0 0 0 0 0               emits-change writable
.CC                                                   property  ay        4 50 67 70 53                            emits-change writable
.CE                                                   property  ay        1 49                                     emits-change writable
.CT                                                   property  ay        4 64 53 16 1                             emits-change writable
.DI                                                   property  ay        0                                        emits-change writable
.DR                                                   property  ay        16 80 67 73 69 32 88 49 54 32 50 67 6... emits-change writable
.FG                                                   property  ay        0                                        emits-change writable
.FN                                                   property  ay        7 48 50 87 70 48 48 48                   emits-change writable
.HE                                                   property  ay        4 48 48 48 49                            emits-change writable
.HW                                                   property  ay        2 0 1                                    emits-change writable
.HX                                                   property  ay        9 1 2 144 144 0 0 0 0 0                  emits-change writable
.PN                                                   property  ay        7 48 50 87 70 48 48 49                   emits-change writable
.PR                                                   property  ay        0                                        emits-change writable
.RT                                                   property  ay        4 86 73 78 73                            emits-change writable
.SN                                                   property  ay        12 89 76 49 49 66 71 48 65 78 48 52 71   emits-change writable
.TS                                                   property  ay        0                                        emits-change writable
.VN                                                   property  ay        0                                        emits-change writable
.VZ                                                   property  ay        2 48 49                                  emits-change writable
com.ibm.ipzvpd.VMSC                                   interface -         -                                        -
.IN                                                   property  ay        205 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... emits-change writable
.RT                                                   property  ay        4 86 77 83 67                            emits-change writable
com.ibm.ipzvpd.VRTN                                   interface -         -                                        -
.I2                                                   property  ay        254 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... emits-change writable
.IN                                                   property  ay        254 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... emits-change writable
.RT                                                   property  ay        4 86 82 84 78                            emits-change writable
.SO                                                   property  ay        2 0 0                                    emits-change writable
com.ibm.ipzvpd.VSRC                                   interface -         -                                        -
.DR                                                   property  ay        16 80 67 73 69 32 88 49 54 32 50 67 6... emits-change writable
.IN                                                   property  ay        100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... emits-change writable
.RT                                                   property  ay        4 86 83 82 67                            emits-change writable
org.freedesktop.DBus.Introspectable                   interface -         -                                        -
.Introspect                                           method    -         s                                        -
org.freedesktop.DBus.Peer                             interface -         -                                        -
.GetMachineId                                         method    -         s                                        -
.Ping                                                 method    -         -                                        -
org.freedesktop.DBus.Properties                       interface -         -                                        -
.Get                                                  method    ss        v                                        -
.GetAll                                               method    s         a{sv}                                    -
.Set                                                  method    ssv       -                                        -
.PropertiesChanged                                    signal    sa{sv}as  -                                        -
xyz.openbmc_project.Association.Definitions           interface -         -                                        -
.Associations                                         property  a(sss)    2 "sensors" "inventory" "/xyz/openbmc... emits-change writable
xyz.openbmc_project.Inventory.Decorator.Asset         interface -         -                                        -
.BuildDate                                            property  s         ""                                       emits-change writable
.Manufacturer                                         property  s         ""                                       emits-change writable
.Model                                                property  s         "2CF5"                                   emits-change writable
.PartNumber                                           property  s         "02WF001"                                emits-change writable
.SerialNumber                                         property  s         "YL11BG0AN04G"                           emits-change writable
.SparePartNumber                                      property  s         "02WF000"                                emits-change writable
.SubModel                                             property  s         ""                                       emits-change writable
xyz.openbmc_project.Inventory.Decorator.I2CDevice     interface -         -                                        -
.Address                                              property  u         80                                       emits-change writable
.Bus                                                  property  u         17                                       emits-change writable
xyz.openbmc_project.Inventory.Decorator.LocationCode  interface -         -                                        -
.LocationCode                                         property  s         "U780C.ND0.RCH0011-P0-C2"                emits-change writable
xyz.openbmc_project.Inventory.Decorator.Slot          interface -         -                                        -
.SlotNumber                                           property  u         2                                        emits-change writable
xyz.openbmc_project.Inventory.Item                    interface -         -                                        -
.Present                                              property  b         true                                     emits-change writable
.PrettyName                                           property  s         "PCIe4 x16 or PCIe5 x8 adapter"          emits-change writable
xyz.openbmc_project.Inventory.Item.FabricAdapter      interface -         -                                        -
xyz.openbmc_project.Inventory.Item.PCIeDevice         interface -         -                                        -
.DeviceType                                           property  s         ""                                       emits-change writable
.Function0ClassCode                                   property  s         ""                                       emits-change writable
.Function0DeviceClass                                 property  s         ""                                       emits-change writable
.Function0DeviceId                                    property  s         ""                                       emits-change writable
.Function0FunctionType                                property  s         ""                                       emits-change writable
.Function0RevisionId                                  property  s         ""                                       emits-change writable
.Function0SubsystemId                                 property  s         ""                                       emits-change writable
.Function0SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function0VendorId                                    property  s         ""                                       emits-change writable
.Function1ClassCode                                   property  s         ""                                       emits-change writable
.Function1DeviceClass                                 property  s         ""                                       emits-change writable
.Function1DeviceId                                    property  s         ""                                       emits-change writable
.Function1FunctionType                                property  s         ""                                       emits-change writable
.Function1RevisionId                                  property  s         ""                                       emits-change writable
.Function1SubsystemId                                 property  s         ""                                       emits-change writable
.Function1SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function1VendorId                                    property  s         ""                                       emits-change writable
.Function2ClassCode                                   property  s         ""                                       emits-change writable
.Function2DeviceClass                                 property  s         ""                                       emits-change writable
.Function2DeviceId                                    property  s         ""                                       emits-change writable
.Function2FunctionType                                property  s         ""                                       emits-change writable
.Function2RevisionId                                  property  s         ""                                       emits-change writable
.Function2SubsystemId                                 property  s         ""                                       emits-change writable
.Function2SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function2VendorId                                    property  s         ""                                       emits-change writable
.Function3ClassCode                                   property  s         ""                                       emits-change writable
.Function3DeviceClass                                 property  s         ""                                       emits-change writable
.Function3DeviceId                                    property  s         ""                                       emits-change writable
.Function3FunctionType                                property  s         ""                                       emits-change writable
.Function3RevisionId                                  property  s         ""                                       emits-change writable
.Function3SubsystemId                                 property  s         ""                                       emits-change writable
.Function3SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function3VendorId                                    property  s         ""                                       emits-change writable
.Function4ClassCode                                   property  s         ""                                       emits-change writable
.Function4DeviceClass                                 property  s         ""                                       emits-change writable
.Function4DeviceId                                    property  s         ""                                       emits-change writable
.Function4FunctionType                                property  s         ""                                       emits-change writable
.Function4RevisionId                                  property  s         ""                                       emits-change writable
.Function4SubsystemId                                 property  s         ""                                       emits-change writable
.Function4SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function4VendorId                                    property  s         ""                                       emits-change writable
.Function5ClassCode                                   property  s         ""                                       emits-change writable
.Function5DeviceClass                                 property  s         ""                                       emits-change writable
.Function5DeviceId                                    property  s         ""                                       emits-change writable
.Function5FunctionType                                property  s         ""                                       emits-change writable
.Function5RevisionId                                  property  s         ""                                       emits-change writable
.Function5SubsystemId                                 property  s         ""                                       emits-change writable
.Function5SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function5VendorId                                    property  s         ""                                       emits-change writable
.Function6ClassCode                                   property  s         ""                                       emits-change writable
.Function6DeviceClass                                 property  s         ""                                       emits-change writable
.Function6DeviceId                                    property  s         ""                                       emits-change writable
.Function6FunctionType                                property  s         ""                                       emits-change writable
.Function6RevisionId                                  property  s         ""                                       emits-change writable
.Function6SubsystemId                                 property  s         ""                                       emits-change writable
.Function6SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function6VendorId                                    property  s         ""                                       emits-change writable
.Function7ClassCode                                   property  s         ""                                       emits-change writable
.Function7DeviceClass                                 property  s         ""                                       emits-change writable
.Function7DeviceId                                    property  s         ""                                       emits-change writable
.Function7FunctionType                                property  s         ""                                       emits-change writable
.Function7RevisionId                                  property  s         ""                                       emits-change writable
.Function7SubsystemId                                 property  s         ""                                       emits-change writable
.Function7SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function7VendorId                                    property  s         ""                                       emits-change writable
.GenerationInUse                                      property  s         "xyz.openbmc_project.Inventory.Item.P... emits-change writable
.GenerationSupported                                  property  s         "xyz.openbmc_project.Inventory.Item.P... emits-change writable
.LanesInUse                                           property  u         4294967295                               emits-change writable
.MaxLanes                                             property  u         0                                        emits-change writable
xyz.openbmc_project.Object.Enable                     interface -         -                                        -
.Enabled                                              property  b         true                                     emits-change writable
xyz.openbmc_project.State.Decorator.OperationalStatus interface -         -                                        -
.Functional                                           property  b         true                                     emits-change writable

2. root@p10bmc:~# busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager deleteFRUVPD o /xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot2/pcie_card2
3. Journal logs:
Dec 04 06:01:24 p10bmc vpd-manager[1037]: FileName: /usr/src/debug/openpower-fru-vpd/1.0+git/include/utility/json_utility.hpp, Line: 280, Func: bool vpd::jsonUtility::processSystemCmdTag(const nlohmann::json_abi_v3_11_3::json&, const std::string&, const std::string&, const std::string&), Command = echo 17-0050 > /sys/bus/i2c/drivers/leds-pca955x/unbind
Dec 04 06:01:24 p10bmc vpd-manager[2633]: sh: line 1: echo: write error: No such device
Dec 04 06:01:24 p10bmc vpd-manager[1037]: FileName: /usr/src/debug/openpower-fru-vpd/1.0+git/include/utility/json_utility.hpp, Line: 429, Func: bool vpd::jsonUtility::procesSetGpioTag(const nlohmann::json_abi_v3_11_3::json&, const std::string&, const std::string&, const std::string&), Setting GPIO: presence-cable-card2 to 0
Dec 04 06:01:24 p10bmc vpd-manager[1037]: FileName: /usr/src/debug/openpower-fru-vpd/1.0+git/include/utility/json_utility.hpp, Line: 280, Func: bool vpd::jsonUtility::processSystemCmdTag(const nlohmann::json_abi_v3_11_3::json&, const std::string&, const std::string&, const std::string&), Command = echo 17-0060 > /sys/bus/i2c/drivers/at24/unbind
Dec 04 06:01:24 p10bmc vpd-manager[2634]: sh: line 1: echo: write error: No such device
Dec 04 06:01:24 p10bmc vpd-manager[1037]: FileName: /usr/src/debug/openpower-fru-vpd/1.0+git/src/worker.cpp, Line: 1642, Func: void vpd::Worker::deleteFruVpd(const std::string&), Successfully completed deletion of FRU VPD for /xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot2/pcie_card2
4. After triggering deleteFRUVPD
root@p10bmc:~# busctl introspect xyz.openbmc_project.Inventory.Manager /xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot2/pcie_card2
NAME                                                  TYPE      SIGNATURE RESULT/VALUE                             FLAGS
com.ibm.ipzvpd.Location                               interface -         -                                        -
.LocationCode                                         property  s         ""                                       emits-change writable
com.ibm.ipzvpd.VINI                                   interface -         -                                        -
.B3                                                   property  ay        0                                        emits-change writable
.B4                                                   property  ay        0                                        emits-change writable
.B7                                                   property  ay        0                                        emits-change writable
.CC                                                   property  ay        0                                        emits-change writable
.CE                                                   property  ay        0                                        emits-change writable
.CT                                                   property  ay        0                                        emits-change writable
.DI                                                   property  ay        0                                        emits-change writable
.DR                                                   property  ay        0                                        emits-change writable
.FG                                                   property  ay        0                                        emits-change writable
.FN                                                   property  ay        0                                        emits-change writable
.HE                                                   property  ay        0                                        emits-change writable
.HW                                                   property  ay        0                                        emits-change writable
.HX                                                   property  ay        0                                        emits-change writable
.PN                                                   property  ay        0                                        emits-change writable
.PR                                                   property  ay        0                                        emits-change writable
.RT                                                   property  ay        0                                        emits-change writable
.SN                                                   property  ay        0                                        emits-change writable
.TS                                                   property  ay        0                                        emits-change writable
.VN                                                   property  ay        0                                        emits-change writable
.VZ                                                   property  ay        0                                        emits-change writable
com.ibm.ipzvpd.VMSC                                   interface -         -                                        -
.IN                                                   property  ay        0                                        emits-change writable
.RT                                                   property  ay        0                                        emits-change writable
com.ibm.ipzvpd.VRTN                                   interface -         -                                        -
.I2                                                   property  ay        0                                        emits-change writable
.IN                                                   property  ay        0                                        emits-change writable
.RT                                                   property  ay        0                                        emits-change writable
.SO                                                   property  ay        0                                        emits-change writable
com.ibm.ipzvpd.VSRC                                   interface -         -                                        -
.DR                                                   property  ay        0                                        emits-change writable
.IN                                                   property  ay        0                                        emits-change writable
.RT                                                   property  ay        0                                        emits-change writable
org.freedesktop.DBus.Introspectable                   interface -         -                                        -
.Introspect                                           method    -         s                                        -
org.freedesktop.DBus.Peer                             interface -         -                                        -
.GetMachineId                                         method    -         s                                        -
.Ping                                                 method    -         -                                        -
org.freedesktop.DBus.Properties                       interface -         -                                        -
.Get                                                  method    ss        v                                        -
.GetAll                                               method    s         a{sv}                                    -
.Set                                                  method    ssv       -                                        -
.PropertiesChanged                                    signal    sa{sv}as  -                                        -
xyz.openbmc_project.Association.Definitions           interface -         -                                        -
.Associations                                         property  a(sss)    2 "sensors" "inventory" "/xyz/openbmc... emits-change writable
xyz.openbmc_project.Inventory.Decorator.Asset         interface -         -                                        -
.BuildDate                                            property  s         ""                                       emits-change writable
.Manufacturer                                         property  s         ""                                       emits-change writable
.Model                                                property  s         ""                                       emits-change writable
.PartNumber                                           property  s         ""                                       emits-change writable
.SerialNumber                                         property  s         ""                                       emits-change writable
.SparePartNumber                                      property  s         ""                                       emits-change writable
.SubModel                                             property  s         ""                                       emits-change writable
xyz.openbmc_project.Inventory.Decorator.I2CDevice     interface -         -                                        -
.Address                                              property  u         80                                       emits-change writable
.Bus                                                  property  u         17                                       emits-change writable
xyz.openbmc_project.Inventory.Decorator.LocationCode  interface -         -                                        -
.LocationCode                                         property  s         "U780C.ND0.RCH0011-P0-C2"                emits-change writable
xyz.openbmc_project.Inventory.Decorator.Slot          interface -         -                                        -
.SlotNumber                                           property  u         2                                        emits-change writable
xyz.openbmc_project.Inventory.Item                    interface -         -                                        -
.Present                                              property  b         false                                    emits-change writable
.PrettyName                                           property  s         ""                                       emits-change writable
xyz.openbmc_project.Inventory.Item.FabricAdapter      interface -         -                                        -
xyz.openbmc_project.Inventory.Item.PCIeDevice         interface -         -                                        -
.DeviceType                                           property  s         ""                                       emits-change writable
.Function0ClassCode                                   property  s         ""                                       emits-change writable
.Function0DeviceClass                                 property  s         ""                                       emits-change writable
.Function0DeviceId                                    property  s         ""                                       emits-change writable
.Function0FunctionType                                property  s         ""                                       emits-change writable
.Function0RevisionId                                  property  s         ""                                       emits-change writable
.Function0SubsystemId                                 property  s         ""                                       emits-change writable
.Function0SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function0VendorId                                    property  s         ""                                       emits-change writable
.Function1ClassCode                                   property  s         ""                                       emits-change writable
.Function1DeviceClass                                 property  s         ""                                       emits-change writable
.Function1DeviceId                                    property  s         ""                                       emits-change writable
.Function1FunctionType                                property  s         ""                                       emits-change writable
.Function1RevisionId                                  property  s         ""                                       emits-change writable
.Function1SubsystemId                                 property  s         ""                                       emits-change writable
.Function1SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function1VendorId                                    property  s         ""                                       emits-change writable
.Function2ClassCode                                   property  s         ""                                       emits-change writable
.Function2DeviceClass                                 property  s         ""                                       emits-change writable
.Function2DeviceId                                    property  s         ""                                       emits-change writable
.Function2FunctionType                                property  s         ""                                       emits-change writable
.Function2RevisionId                                  property  s         ""                                       emits-change writable
.Function2SubsystemId                                 property  s         ""                                       emits-change writable
.Function2SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function2VendorId                                    property  s         ""                                       emits-change writable
.Function3ClassCode                                   property  s         ""                                       emits-change writable
.Function3DeviceClass                                 property  s         ""                                       emits-change writable
.Function3DeviceId                                    property  s         ""                                       emits-change writable
.Function3FunctionType                                property  s         ""                                       emits-change writable
.Function3RevisionId                                  property  s         ""                                       emits-change writable
.Function3SubsystemId                                 property  s         ""                                       emits-change writable
.Function3SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function3VendorId                                    property  s         ""                                       emits-change writable
.Function4ClassCode                                   property  s         ""                                       emits-change writable
.Function4DeviceClass                                 property  s         ""                                       emits-change writable
.Function4DeviceId                                    property  s         ""                                       emits-change writable
.Function4FunctionType                                property  s         ""                                       emits-change writable
.Function4RevisionId                                  property  s         ""                                       emits-change writable
.Function4SubsystemId                                 property  s         ""                                       emits-change writable
.Function4SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function4VendorId                                    property  s         ""                                       emits-change writable
.Function5ClassCode                                   property  s         ""                                       emits-change writable
.Function5DeviceClass                                 property  s         ""                                       emits-change writable
.Function5DeviceId                                    property  s         ""                                       emits-change writable
.Function5FunctionType                                property  s         ""                                       emits-change writable
.Function5RevisionId                                  property  s         ""                                       emits-change writable
.Function5SubsystemId                                 property  s         ""                                       emits-change writable
.Function5SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function5VendorId                                    property  s         ""                                       emits-change writable
.Function6ClassCode                                   property  s         ""                                       emits-change writable
.Function6DeviceClass                                 property  s         ""                                       emits-change writable
.Function6DeviceId                                    property  s         ""                                       emits-change writable
.Function6FunctionType                                property  s         ""                                       emits-change writable
.Function6RevisionId                                  property  s         ""                                       emits-change writable
.Function6SubsystemId                                 property  s         ""                                       emits-change writable
.Function6SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function6VendorId                                    property  s         ""                                       emits-change writable
.Function7ClassCode                                   property  s         ""                                       emits-change writable
.Function7DeviceClass                                 property  s         ""                                       emits-change writable
.Function7DeviceId                                    property  s         ""                                       emits-change writable
.Function7FunctionType                                property  s         ""                                       emits-change writable
.Function7RevisionId                                  property  s         ""                                       emits-change writable
.Function7SubsystemId                                 property  s         ""                                       emits-change writable
.Function7SubsystemVendorId                           property  s         ""                                       emits-change writable
.Function7VendorId                                    property  s         ""                                       emits-change writable
.GenerationInUse                                      property  s         "xyz.openbmc_project.Inventory.Item.P... emits-change writable
.GenerationSupported                                  property  s         "xyz.openbmc_project.Inventory.Item.P... emits-change writable
.LanesInUse                                           property  u         4294967295                               emits-change writable
.MaxLanes                                             property  u         0                                        emits-change writable
xyz.openbmc_project.Object.Enable                     interface -         -                                        -
.Enabled                                              property  b         true                                     emits-change writable
xyz.openbmc_project.State.Decorator.OperationalStatus interface -         -                                        -
.Functional                                           property  b         true                                     emits-change writable

'''

Signed-off-by: RekhaAparna01 <[email protected]>
  • Loading branch information
RekhaAparna01 committed Dec 6, 2024
1 parent 3ae3e9d commit 8b1a32c
Show file tree
Hide file tree
Showing 12 changed files with 1,493 additions and 18 deletions.
216 changes: 216 additions & 0 deletions configuration/ibm/50001000.json

Large diffs are not rendered by default.

216 changes: 216 additions & 0 deletions configuration/ibm/50001000_v2.json

Large diffs are not rendered by default.

216 changes: 216 additions & 0 deletions configuration/ibm/50001001.json

Large diffs are not rendered by default.

242 changes: 229 additions & 13 deletions configuration/ibm/50001001_v2.json

Large diffs are not rendered by default.

210 changes: 210 additions & 0 deletions configuration/ibm/50003000.json

Large diffs are not rendered by default.

214 changes: 214 additions & 0 deletions configuration/ibm/50003000_v2.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions include/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ constexpr auto biosConfigMgrObjPath =
constexpr auto biosConfigMgrService = "xyz.openbmc_project.BIOSConfigManager";
constexpr auto biosConfigMgrInterface =
"xyz.openbmc_project.BIOSConfig.Manager";
constexpr auto objectMapperService = "xyz.openbmc_project.ObjectMapper";
constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
constexpr auto objectMapperInf = "xyz.openbmc_project.ObjectMapper";
constexpr auto systemVpdInvPath =
"/xyz/openbmc_project/inventory/system/chassis/motherboard";
constexpr auto assetTagInf = "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Expand Down
1 change: 1 addition & 0 deletions include/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ using DbusVariantType = std::variant<

using MapperGetObject =
std::vector<std::pair<std::string, std::vector<std::string>>>;
using MapperGetSubTree = std::map<std::string, std::map<std::string, std::vector<std::string>>>;

/* A type for holding the innermost map of property::value.*/
using IPZKwdValueMap = std::unordered_map<std::string, std::string>;
Expand Down
50 changes: 50 additions & 0 deletions include/utility/dbus_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,56 @@ inline types::PropertyMap getPropertyMap(const std::string& i_service,
return l_propertyValueMap;
}

/**
* @brief API to get object subtree from D-bus.
*
* The API returns the map of object, services and interfaces in the
* subtree that implement a certain interface. If no interfaces are provided
* then all the objects, services and interfaces under the subtree will
* be returned.
*
* Note: Depth can be 0 and interfaces can be null.
* It will be caller's responsibility to check for empty vector returned
* and generate appropriate error.
*
* @param[in] i_objectPath - Path to search for an interface.
* @param[in] i_depth - Maximum depth of the tree to search.
* @param[in] i_interfaces - List of interfaces to search.
*
* @return - A map of object and its related services and interfaces, if
* success. If failed, empty map.
*/

inline types::MapperGetSubTree
getObjectSubTree(const std::string& i_objectPath, const int& i_depth,
const std::vector<std::string>& i_interfaces)
{
types::MapperGetSubTree l_subTreeMap;

if (i_objectPath.empty())
{
logging::logMessage("Object path is empty.");
return l_subTreeMap;
}

try
{
auto l_bus = sdbusplus::bus::new_default();
auto l_method = l_bus.new_method_call(
constants::objectMapperService, constants::objectMapperPath,
constants::objectMapperInf, "GetSubTree");
l_method.append(i_objectPath, i_depth, i_interfaces);
auto l_result = l_bus.call(l_method);
l_result.read(l_subTreeMap);
}
catch (const sdbusplus::exception::SdBusError& l_ex)
{
logging::logMessage(l_ex.what());
}

return l_subTreeMap;
}

/**
* @brief An API to read property from Dbus.
*
Expand Down
9 changes: 9 additions & 0 deletions include/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ class Worker
types::ObjectMap& objectInterfaceMap,
const std::string& vpdFilePath);

/**
* @brief An API to delete FRU VPD over DBus.
*
* @param[in] i_dbusObjPath - Dbus object path of the FRU.
*
* @throw std::runtime_error if given input path is empty.
*/
void deleteFruVpd(const std::string& i_dbusObjPath);

/**
* @brief API to get status of VPD collection process.
*
Expand Down
24 changes: 22 additions & 2 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,28 @@ void Manager::collectSingleFruVpd(
void Manager::deleteSingleFruVpd(
const sdbusplus::message::object_path& i_dbusObjPath)
{
// Dummy code to supress unused variable warning. To be removed.
logging::logMessage(std::string(i_dbusObjPath));
try
{
if (std::string(i_dbusObjPath).empty())
{
throw std::runtime_error(
"Given DBus object path is empty. Aborting FRU VPD deletion.");
}

if (m_worker.get() == nullptr)
{
throw std::runtime_error(
"Worker object not found, can't perform FRU VPD deletion for: " +
std::string(i_dbusObjPath));
}

m_worker->deleteFruVpd(std::string(i_dbusObjPath));
}
catch (const std::exception& l_ex)
{
// TODO: Log PEL
logging::logMessage(l_ex.what());
}
}

bool Manager::isValidUnexpandedLocationCode(
Expand Down
110 changes: 107 additions & 3 deletions src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,13 +1282,13 @@ bool Worker::processPostAction(
// Check if post action tag is to be triggered in the flow of collection
// based on some CCIN value?
if (m_parsedJson["frus"][i_vpdFruPath]
.at(0)["postAction"]["collection"]
.at(0)["postAction"][i_flagToProcess]
.contains("ccin"))
{
if (!i_parsedVpd.has_value())
{
throw std::runtime_error(
"Parsed VPD map parameter is mandatory for CCIN match");
logging::logMessage("Empty VPD Map");
return false;
}

// CCIN match is required to process post action for this FRU as it
Expand Down Expand Up @@ -1563,4 +1563,108 @@ void Worker::performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap)
*/
}
}

void Worker::deleteFruVpd(const std::string& i_dbusObjPath)
{
if (i_dbusObjPath.empty())
{
throw std::runtime_error("Given DBus object path is empty.");
}

const std::string& l_fruPath =
jsonUtility::getFruPathFromJson(m_parsedJson, i_dbusObjPath);

try
{
auto l_presentPropValue = dbusUtility::readDbusProperty(
constants::pimServiceName, i_dbusObjPath,
constants::inventoryItemInf, "Present");

if (auto l_value = std::get_if<bool>(&l_presentPropValue))
{
if (!(*l_value))
{
throw std::runtime_error("Given FRU is not present");
}
else
{
if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
"preAction", "deletion"))
{
if (!processPreAction(l_fruPath, "deletion"))
{
throw std::runtime_error("Pre action failed");
}
}

std::vector<std::string> l_interfaceList{
constants::operationalStatusInf};

types::MapperGetSubTree l_subTreeMap =
dbusUtility::getObjectSubTree(i_dbusObjPath, 0,
l_interfaceList);

types::ObjectMap l_objectMap;

// Updates VPD specific interfaces property value under PIM for
// sub FRUs.
for (const auto& [l_objectPath, l_serviceInterfaceMap] :
l_subTreeMap)
{
types::InterfaceMap l_interfaceMap;
vpdSpecificUtility::resetDataUnderPIM(l_objectPath,
l_interfaceMap);
l_objectMap.emplace(l_objectPath,
std::move(l_interfaceMap));
}

types::InterfaceMap l_interfaceMap;
vpdSpecificUtility::resetDataUnderPIM(i_dbusObjPath,
l_interfaceMap);

l_objectMap.emplace(i_dbusObjPath, std::move(l_interfaceMap));

if (!dbusUtility::callPIM(std::move(l_objectMap)))
{
throw std::runtime_error(
"Can't process delete VPD for FRU [" + i_dbusObjPath +
"] as unable to read present property");
}

if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
"postAction", "deletion"))
{
if (!processPostAction(l_fruPath, "deletion"))
{
throw std::runtime_error("Post action failed");
}
}
}
}
else
{
logging::logMessage("DBus read failed");
return;
}

logging::logMessage("Successfully completed deletion of FRU VPD for " +
i_dbusObjPath);
}
catch (const std::exception& l_ex)
{
if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
"postFailAction", "deletion"))
{
if (!jsonUtility::executePostFailAction(m_parsedJson, l_fruPath,
"deletion"))
{
logging::logMessage("Post fail action failed for: " +
i_dbusObjPath);
}
}

logging::logMessage("Failed to delete VPD for FRU : " + i_dbusObjPath +
" error: " + std::string(l_ex.what()));
}
}
} // namespace vpd

0 comments on commit 8b1a32c

Please sign in to comment.