Browse code

Introduce iniget_sections function

This function returns list of sections from specified INI file.
It is needed for I7938f26015d953efdf720774b5ad2cee4068ac90.
'iniget_sections' is needed for automatic node enrollment to
Ironic from INI syntax file.

Change-Id: I52a69ad3bc8fc528e7f20e6b03a98f327acaaa74
Implements: blueprint ironic-ml2-integration

vsaienko authored on 2015/12/11 18:03:52
Showing 2 changed files
... ...
@@ -261,6 +261,18 @@ function iniuncomment {
261 261
     $xtrace
262 262
 }
263 263
 
264
+# Get list of sections from an INI file
265
+# iniget_sections config-file
266
+function iniget_sections {
267
+    local xtrace
268
+    xtrace=$(set +o | grep xtrace)
269
+    set +o xtrace
270
+    local file=$1
271
+
272
+    echo $(sed -ne "s/^\[\(.*\)\]/\1/p" "$file")
273
+    $xtrace
274
+}
275
+
264 276
 # Restore xtrace
265 277
 $INC_CONF_TRACE
266 278
 
... ...
@@ -80,6 +80,11 @@ if [ -n "$TEST_SUDO" ]; then
80 80
     sudo chown -R root:root ${INI_TMP_ETC_DIR}
81 81
 fi
82 82
 
83
+# test iniget_sections
84
+VAL=$(iniget_sections "${TEST_INI}")
85
+assert_equal "$VAL" "default aaa bbb ccc ddd eee del_separate_options \
86
+del_same_option del_missing_option del_missing_option_multi del_no_options"
87
+
83 88
 # Test with missing arguments
84 89
 BEFORE=$(cat ${TEST_INI})
85 90