yaml: add back support for empty LED groups
The old script had support for empty LED groups. I tried removing the
empty "bmc_booted" LED group, but that caused systemd to never "finish"
booting (systemctl is-system-running returned "starting" because it was
blocked waiting for the "bmc_booted" LED service to start).
This adds back support for empty LED groups.
Tested:
Confirmed that with an empty "bmc_booted" LED group, the firmware will
build successfully and systemd doesn't get blocked waiting for the
"bmc_booted" LED service.
Change-Id: I11d7c50696cd50d989a4eaef28f8e5c43473ce6e
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/scripts/parse_led.py b/scripts/parse_led.py
index 5724e6d..ee6bab8 100755
--- a/scripts/parse_led.py
+++ b/scripts/parse_led.py
@@ -90,7 +90,7 @@
led_dict = ifile[group]
group_priority = 0
- has_group_priority = "Priority" in led_dict
+ has_group_priority = led_dict and "Priority" in led_dict
if has_group_priority:
group_priority = led_dict["Priority"]
@@ -108,6 +108,10 @@
+ "{\n"
)
+ # Some LED groups could be empty
+ if not led_dict:
+ led_dict = {}
+
for led_name, list_dict in list(led_dict.items()):
generate_file_single_led(
ifile,
diff --git a/test/config/test-empty-group.yaml b/test/config/test-empty-group.yaml
new file mode 100644
index 0000000..472d484
--- /dev/null
+++ b/test/config/test-empty-group.yaml
@@ -0,0 +1,6 @@
+emptygroup:
+
+nonemptygroup:
+ led2:
+ Action: "Off"
+ Priority: "Off"
diff --git a/test/meson.build b/test/meson.build
index 4aa6632..b7f0b47 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -20,6 +20,7 @@
endif
test_yamls = [
+ 'test-empty-group',
'test-group-priority',
'test-led-priority'
]
@@ -51,6 +52,7 @@
'utest-group-priority.cpp',
'utest-led-yaml-group-priority.cpp',
'utest-led-yaml-led-priority.cpp',
+ 'utest-led-yaml-empty-group.cpp',
'utest-config-validator.cpp'
]
if get_option('persistent-led-asserted').allowed()
diff --git a/test/utest-led-yaml-empty-group.cpp b/test/utest-led-yaml-empty-group.cpp
new file mode 100644
index 0000000..7055053
--- /dev/null
+++ b/test/utest-led-yaml-empty-group.cpp
@@ -0,0 +1,39 @@
+#include "config-validator.hpp"
+#include "group.hpp"
+#include "ledlayout.hpp"
+#include "test-empty-group.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::led;
+
+// systemLedMap is generated code
+// static const GroupMap systemLedMap = {};
+
+const std::string basePath = "/xyz/openbmc_project/led/groups/";
+
+TEST(YamlEmptyGroupTest, assertEmptyGroupExists)
+{
+ /* Empty led groups are supported since some boards may
+ * not have the required leds to fill the expected groups.
+ * Other software in openbmc (e.g bmcweb, led-manager itself)
+ * expects certain groups and unintended error messages can result
+ * if they are not present.
+ */
+
+ const std::string emptyGroupPath = basePath + "emptygroup";
+ const std::string nonEmptyGroupPath = basePath + "nonemptygroup";
+
+ EXPECT_EQ(systemLedMap.contains(emptyGroupPath), true);
+ EXPECT_EQ(systemLedMap.contains(nonEmptyGroupPath), true);
+
+ const Layout::GroupLayout& emptyGroup = systemLedMap.at(emptyGroupPath);
+ const Layout::GroupLayout& nonEmptyGroup =
+ systemLedMap.at(nonEmptyGroupPath);
+
+ EXPECT_EQ(emptyGroup.actionSet.size(), 0);
+ EXPECT_EQ(nonEmptyGroup.actionSet.size(), 1);
+
+ // this should not throw
+ phosphor::led::validateConfigV1(systemLedMap);
+}