Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpTestSystem: Add state names for readability #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

debmc
Copy link
Collaborator

@debmc debmc commented Dec 12, 2018

For consumers of the debug files add the state names
to aide in debug log analysis.

Signed-off-by: Deb McLemore [email protected]

@@ -328,10 +328,12 @@ def goto_state(self, state):
raise unittest.SkipTest("OpTestSystem running QEMU/Mambo so skipping OpSystemState.OS test")
if (self.state == OpSystemState.UNKNOWN):
log.debug("OpTestSystem CHECKING CURRENT STATE and TRANSITIONING for TARGET STATE: %s" % (state))
log.debug(" *** UNKNOWN=0 OFF=1 IPLing=2 PETITBOOT=3 PETITBOOT_SHELL=4 BOOTING=5 OS=6 POWERING_OFF=7 UNKNOWN_BAD=8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead have a little helper that turns state numbers into strings and do
log.debug("OpTestSystem CHECKING CURRENT STATE and TRANSITIONING for TARGET STATE: {} ({})".format(state, state_name(state))?

Copy link
Collaborator Author

@debmc debmc Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little helper

I thought about that as well, but in some places it just says "CURRENT DETECTED STATE=xx" and for the consumer that is not familiar doesn't know the entire table so it is not quite as meaningful, so I thought the entire state machine would help level set the terminology.

@ghost
Copy link

ghost commented Dec 13, 2018 via email

@debmc
Copy link
Collaborator Author

debmc commented Dec 17, 2018

We should be able to do that by using the object-as-an-enum trick and having a str method in it.

I think I have a combo solution, alternative suggestions welcomed !

@debmc debmc force-pushed the statenames branch 3 times, most recently from 9f82e1b to b5d5201 Compare February 26, 2019 16:57
@debmc debmc force-pushed the statenames branch 2 times, most recently from cd98861 to 6252e4f Compare March 22, 2019 17:59
@debmc debmc force-pushed the statenames branch 2 times, most recently from 73bddc3 to dc465ed Compare July 28, 2019 00:10
@debmc debmc closed this Jul 31, 2019
@debmc debmc reopened this Jul 31, 2019
For consumers of the debug files add the state names
to aide in debug log analysis.

Signed-off-by: Deb McLemore <[email protected]>
@oohal
Copy link
Contributor

oohal commented Nov 28, 2019

comedy option:

diff --git a/common/OpTestSystem.py b/common/OpTestSystem.py
index 712057704edf..ddb8f8c67de5 100644
--- a/common/OpTestSystem.py
+++ b/common/OpTestSystem.py
@@ -55,22 +55,28 @@ import logging
 import OpTestLogger
 log = OpTestLogger.optest_logger_glob.get_logger(__name__)
 
-
 class OpSystemState():
-    '''
-    This class is used as an enum as to what state op-test *thinks* the host is in.
-    These states are used to drive a state machine in OpTestSystem.
-    '''
-    UNKNOWN = 0
-    OFF = 1
-    IPLing = 2
-    PETITBOOT = 3
-    PETITBOOT_SHELL = 4
-    BOOTING = 5
-    OS = 6
-    POWERING_OFF = 7
-    UNKNOWN_BAD = 8  # special case, use set_state to place system in hold for later goto
-
+    # dumb wrapper that'll print out the state name when printed / casted
+    # to a string. Otherwise it acts like an int.
+    class OpSysState(int):
+        state_names = ["UNKNOWN", "OFF", "IPL", "PETITBOOT", "PETITBOOT_SHELL",
+                       "BOOTING", "OS", "POWERING_OFF", "UNKNOWN_BAD"]
+        def __str__(self):
+            return self.state_names[self]
+        def __format__(self, fmt):
+            if fmt == "s":
+                return str(self)
+            return int(self).__format__(fmt)
+
+    UNKNOWN         = OpSysState(0)
+    OFF             = OpSysState(1)
+    IPLing          = OpSysState(2)
+    PETITBOOT       = OpSysState(3)
+    PETITBOOT_SHELL = OpSysState(4)
+    BOOTING         = OpSysState(5)
+    OS              = OpSysState(6)
+    POWERING_OFF    = OpSysState(7)
+    UNKNOWN_BAD     = OpSysState(8)  # special case, use set_state to place system in hold for later goto
 
 class OpTestSystem(object):
 

Whenever we print the state we'd get the string name, but in most situations it's treated as an integer would be. We might be better off using the enum class rather though.

@PraveenPenguin PraveenPenguin force-pushed the master branch 2 times, most recently from 4d0cb14 to b976629 Compare October 6, 2023 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants