blob: ae64af51e106909159e5544eae9bf68e6ea12587 [file] [log] [blame]
George Keishingdf9ad392017-01-25 13:01:15 -06001#!/usr/bin/env python
2
3r"""
4State Manager module:
5
6 - Defines Valid states of the system
7
8"""
George Keishing678b65c2017-08-31 16:16:39 -05009import os
10import re
11import sys
12
George Keishingdf9ad392017-01-25 13:01:15 -060013from robot.libraries.BuiltIn import BuiltIn
14
George Keishing678b65c2017-08-31 16:16:39 -050015robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
16repo_data_dir_path = re.sub('/lib', '/data', robot_pgm_dir_path)
17sys.path.append(repo_data_dir_path)
18
19import gen_robot_keyword as keyword
20import variables as var
21
George Keishingdf9ad392017-01-25 13:01:15 -060022BuiltIn().import_resource("state_manager.robot")
George Keishing678b65c2017-08-31 16:16:39 -050023BuiltIn().import_resource("rest_client.robot")
George Keishingdf9ad392017-01-25 13:01:15 -060024
Konstantin Aladyshevd78dc932021-03-24 18:17:17 +030025platform_arch_type = BuiltIn().get_variable_value("${PLATFORM_ARCH_TYPE}", default="power")
26
George Keishingdf9ad392017-01-25 13:01:15 -060027# We will build eventually the mapping for warm, cold reset as well.
28VALID_STATES = {
29 'reboot':
30 {
George Keishing678b65c2017-08-31 16:16:39 -050031 # (Power Policy, BMC state, Chassis State, Host State)
32 ('LEAVE_OFF', 'Ready', 'Off', 'Off'),
33 ('ALWAYS_POWER_ON', 'Ready', 'On', 'Running'),
34 ('ALWAYS_POWER_ON', 'Ready', 'On', 'Off'),
35 ('RESTORE_LAST_STATE', 'Ready', 'On', 'Running'),
36 ('RESTORE_LAST_STATE', 'Ready', 'On', 'Off'),
George Keishingefc3ff22017-12-12 11:49:25 -060037 ('ALWAYS_POWER_OFF', 'Ready', 'On', 'Running'),
38 ('ALWAYS_POWER_OFF', 'Ready', 'Off', 'Off'),
George Keishing678b65c2017-08-31 16:16:39 -050039 },
40}
41
42VALID_BOOT_STATES = {
43 'Off': # Valid states when Host is Off.
44 {
45 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
46 (
47 "xyz.openbmc_project.State.BMC.BMCState.Ready",
48 "xyz.openbmc_project.State.Chassis.PowerState.Off",
49 "xyz.openbmc_project.State.Host.HostState.Off",
50 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
51 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
52 ),
53 },
54 'Reboot': # Valid states when BMC reset to standby.
55 {
56 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
57 (
58 "xyz.openbmc_project.State.BMC.BMCState.Ready",
59 "xyz.openbmc_project.State.Chassis.PowerState.Off",
60 "xyz.openbmc_project.State.Host.HostState.Off",
61 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
62 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
63 ),
64 },
65 'Running': # Valid states when Host is powering on.
66 {
67 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
68 (
69 "xyz.openbmc_project.State.BMC.BMCState.Ready",
70 "xyz.openbmc_project.State.Chassis.PowerState.On",
71 "xyz.openbmc_project.State.Host.HostState.Running",
72 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.MotherboardInit",
73 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
74 ),
75 },
76 'Booted': # Valid state when Host is booted.
77 {
78 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
79 (
80 "xyz.openbmc_project.State.BMC.BMCState.Ready",
81 "xyz.openbmc_project.State.Chassis.PowerState.On",
82 "xyz.openbmc_project.State.Host.HostState.Running",
83 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart",
84 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete"
85 ),
86 },
87 'ResetReload': # Valid state BMC reset reload when host is booted.
88 {
89 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
90 (
91 "xyz.openbmc_project.State.BMC.BMCState.Ready",
92 "xyz.openbmc_project.State.Chassis.PowerState.On",
93 "xyz.openbmc_project.State.Host.HostState.Running",
94 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart",
95 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete"
96 ),
George Keishingdf9ad392017-01-25 13:01:15 -060097 },
98}
99
Konstantin Aladyshevd78dc932021-03-24 18:17:17 +0300100if platform_arch_type == "x86":
101 VALID_BOOT_STATES_X86 = {}
102 for state_name, state_set in VALID_BOOT_STATES.items():
103 VALID_BOOT_STATES_X86[state_name] = set()
104 for state_tuple in state_set:
105 state_tuple_new = tuple(
106 x
107 for x in state_tuple
108 if not (
109 x.startswith("xyz.openbmc_project.State.Boot.Progress")
110 or x.startswith("xyz.openbmc_project.State.OperatingSystem")
111 )
112 )
113 VALID_BOOT_STATES_X86[state_name].add(state_tuple_new)
114 VALID_BOOT_STATES = VALID_BOOT_STATES_X86
115
George Keishingdf9ad392017-01-25 13:01:15 -0600116
117class state_map():
118
George Keishing678b65c2017-08-31 16:16:39 -0500119 def get_boot_state(self):
George Keishingdf9ad392017-01-25 13:01:15 -0600120 r"""
George Keishing678b65c2017-08-31 16:16:39 -0500121 Return the system state as a tuple of bmc, chassis, host state,
122 BootProgress and OperatingSystemState.
George Keishingdf9ad392017-01-25 13:01:15 -0600123 """
George Keishing678b65c2017-08-31 16:16:39 -0500124
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -0500125 status, state = keyword.run_key("Read Properties "
126 + var.SYSTEM_STATE_URI + "enumerate")
George Keishing678b65c2017-08-31 16:16:39 -0500127 bmc_state = state[var.SYSTEM_STATE_URI + 'bmc0']['CurrentBMCState']
128 chassis_state = \
129 state[var.SYSTEM_STATE_URI + 'chassis0']['CurrentPowerState']
130 host_state = state[var.SYSTEM_STATE_URI + 'host0']['CurrentHostState']
Konstantin Aladyshevd78dc932021-03-24 18:17:17 +0300131 if platform_arch_type == "x86":
132 return (str(bmc_state),
133 str(chassis_state),
134 str(host_state))
135 else:
136 boot_state = state[var.SYSTEM_STATE_URI + 'host0']['BootProgress']
137 os_state = \
138 state[var.SYSTEM_STATE_URI + 'host0']['OperatingSystemState']
George Keishing678b65c2017-08-31 16:16:39 -0500139
Konstantin Aladyshevd78dc932021-03-24 18:17:17 +0300140 return (str(bmc_state),
141 str(chassis_state),
142 str(host_state),
143 str(boot_state),
144 str(os_state))
George Keishingdf9ad392017-01-25 13:01:15 -0600145
146 def valid_boot_state(self, boot_type, state_set):
147 r"""
148 Validate a given set of states is valid.
149
George Keishing678b65c2017-08-31 16:16:39 -0500150 Description of argument(s):
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -0500151 boot_type Boot type (e.g. off/running/host booted
152 etc.)
153 state_set State set (e.g.bmc,chassis,host,
154 BootProgress,OperatingSystemState)
George Keishingdf9ad392017-01-25 13:01:15 -0600155 """
George Keishing678b65c2017-08-31 16:16:39 -0500156
157 if state_set in set(VALID_BOOT_STATES[boot_type]):
George Keishingdf9ad392017-01-25 13:01:15 -0600158 return True
159 else:
160 return False