Change obmc_boot_test.py to fail on blank state values.
Blank state values indicate that the states could not be obtained.
obmc_boot_test.py must have these values in order to make appropriate
decisions about what boot test to select.
Change-Id: Iff2187a5c1f76eac6926848be097ae4ca15df7a2
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/obmc_boot_test.py b/lib/obmc_boot_test.py
index 4ee66d1..77eaa7a 100755
--- a/lib/obmc_boot_test.py
+++ b/lib/obmc_boot_test.py
@@ -476,6 +476,22 @@
###############################################################################
+def valid_state():
+
+ r"""
+ Verify that our state dictionary contains no blank values. If we don't get
+ valid state data, we cannot continue to work.
+ """
+
+ if st.compare_states(state, st.invalid_state_match, 'or'):
+ error_message = "The state dictionary contains blank fields which" +\
+ " is illegal.\n" + gp.sprint_var(state)
+ BuiltIn().fail(gp.sprint_error(error_message))
+
+###############################################################################
+
+
+###############################################################################
def select_boot():
r"""
@@ -491,6 +507,7 @@
gp.qprint_timen("Selecting a boot test.")
my_get_state()
+ valid_state()
stack_popped = 0
if len(boot_stack) > 0:
diff --git a/lib/state.py b/lib/state.py
index 83ca5bc..73a35a2 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -128,6 +128,12 @@
'FW Progress, Starting OS|OSStart'),
('host', '^Running$')])
+invalid_state_match = DotDict([('rest', '^$'),
+ ('chassis', '^$'),
+ ('bmc', '^$'),
+ ('boot_progress', '^$'),
+ ('host', '^$')])
+
###############################################################################
def return_default_state():
@@ -214,7 +220,8 @@
###############################################################################
def compare_states(state,
- match_state):
+ match_state,
+ match_type='and'):
r"""
Compare 2 state dictionaries. Return True if they match and False if they
@@ -229,24 +236,33 @@
match_state A dictionary whose key/value pairs are "state field"/
"state value". The state value is interpreted as a
regular expression. Every value in this dictionary is
- considered. If each and every one matches, the 2
- dictionaries are considered to be matching.
+ considered. When match_type is 'and', if each and every
+ comparison matches, the two dictionaries are considered to
+ be matching. If match_type is 'or', if any two of the
+ elements compared match, the two dictionaries are
+ considered to be matching.
+ match_type This may be 'and' or 'or'.
"""
- match = True
+ error_message = gv.svalid_value(match_type, var_name="match_type",
+ valid_values=['and', 'or'])
+ if error_message != "":
+ BuiltIn().fail(gp.sprint_error(error_message))
+
+ default_match = (match_type == 'and')
for key, match_state_value in match_state.items():
# Blank match_state_value means "don't care".
if match_state_value == "":
continue
try:
- if not re.match(match_state_value, str(state[key])):
- match = False
- break
+ match = (re.match(match_state_value, str(state[key])) is not None)
except KeyError:
match = False
- break
- return match
+ if match != default_match:
+ return match
+
+ return default_match
###############################################################################