blob: 0b16d1d20aedde08e76e4cfa4689e7fa537390bf [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
25# We will build eventually the mapping for warm, cold reset as well.
26VALID_STATES = {
27 'reboot':
28 {
George Keishing678b65c2017-08-31 16:16:39 -050029 # (Power Policy, BMC state, Chassis State, Host State)
30 ('LEAVE_OFF', 'Ready', 'Off', 'Off'),
31 ('ALWAYS_POWER_ON', 'Ready', 'On', 'Running'),
32 ('ALWAYS_POWER_ON', 'Ready', 'On', 'Off'),
33 ('RESTORE_LAST_STATE', 'Ready', 'On', 'Running'),
34 ('RESTORE_LAST_STATE', 'Ready', 'On', 'Off'),
35 ('RESTORE_LAST_STATE', 'Ready', 'Off', 'Off'),
36 },
37}
38
39VALID_BOOT_STATES = {
40 'Off': # Valid states when Host is Off.
41 {
42 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
43 (
44 "xyz.openbmc_project.State.BMC.BMCState.Ready",
45 "xyz.openbmc_project.State.Chassis.PowerState.Off",
46 "xyz.openbmc_project.State.Host.HostState.Off",
47 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
48 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
49 ),
50 },
51 'Reboot': # Valid states when BMC reset to standby.
52 {
53 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
54 (
55 "xyz.openbmc_project.State.BMC.BMCState.Ready",
56 "xyz.openbmc_project.State.Chassis.PowerState.Off",
57 "xyz.openbmc_project.State.Host.HostState.Off",
58 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
59 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
60 ),
61 },
62 'Running': # Valid states when Host is powering on.
63 {
64 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
65 (
66 "xyz.openbmc_project.State.BMC.BMCState.Ready",
67 "xyz.openbmc_project.State.Chassis.PowerState.On",
68 "xyz.openbmc_project.State.Host.HostState.Running",
69 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.MotherboardInit",
70 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
71 ),
72 },
73 'Booted': # Valid state when Host is booted.
74 {
75 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
76 (
77 "xyz.openbmc_project.State.BMC.BMCState.Ready",
78 "xyz.openbmc_project.State.Chassis.PowerState.On",
79 "xyz.openbmc_project.State.Host.HostState.Running",
80 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart",
81 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete"
82 ),
83 },
84 'ResetReload': # Valid state BMC reset reload when host is booted.
85 {
86 # (BMC , Chassis , Host , BootProgress, OperatingSystemState)
87 (
88 "xyz.openbmc_project.State.BMC.BMCState.Ready",
89 "xyz.openbmc_project.State.Chassis.PowerState.On",
90 "xyz.openbmc_project.State.Host.HostState.Running",
91 "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart",
92 "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete"
93 ),
George Keishingdf9ad392017-01-25 13:01:15 -060094 },
95}
96
97
98class state_map():
99
George Keishing678b65c2017-08-31 16:16:39 -0500100 def get_boot_state(self):
George Keishingdf9ad392017-01-25 13:01:15 -0600101 r"""
George Keishing678b65c2017-08-31 16:16:39 -0500102 Return the system state as a tuple of bmc, chassis, host state,
103 BootProgress and OperatingSystemState.
George Keishingdf9ad392017-01-25 13:01:15 -0600104 """
George Keishing678b65c2017-08-31 16:16:39 -0500105
106 status, state = keyword.run_key("Read Properties " +
107 var.SYSTEM_STATE_URI + "enumerate")
108 bmc_state = state[var.SYSTEM_STATE_URI + 'bmc0']['CurrentBMCState']
109 chassis_state = \
110 state[var.SYSTEM_STATE_URI + 'chassis0']['CurrentPowerState']
111 host_state = state[var.SYSTEM_STATE_URI + 'host0']['CurrentHostState']
112 boot_state = state[var.SYSTEM_STATE_URI + 'host0']['BootProgress']
113 os_state = \
114 state[var.SYSTEM_STATE_URI + 'host0']['OperatingSystemState']
115
116 return (str(bmc_state),
George Keishing4d6f3d62017-02-06 09:50:41 -0600117 str(chassis_state),
George Keishing678b65c2017-08-31 16:16:39 -0500118 str(host_state),
119 str(boot_state),
120 str(os_state))
George Keishingdf9ad392017-01-25 13:01:15 -0600121
122 def valid_boot_state(self, boot_type, state_set):
123 r"""
124 Validate a given set of states is valid.
125
George Keishing678b65c2017-08-31 16:16:39 -0500126 Description of argument(s):
127 boot_type Boot type (e.g. off/running/host booted etc.)
128 state_set State set
129 (e.g.bmc,chassis,host,BootProgress,OperatingSystemState)
George Keishingdf9ad392017-01-25 13:01:15 -0600130 """
George Keishing678b65c2017-08-31 16:16:39 -0500131
132 if state_set in set(VALID_BOOT_STATES[boot_type]):
George Keishingdf9ad392017-01-25 13:01:15 -0600133 return True
134 else:
135 return False