George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | State Manager module: |
| 5 | |
| 6 | - Defines Valid states of the system |
| 7 | |
| 8 | """ |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 9 | import os |
| 10 | import re |
| 11 | import sys |
| 12 | |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 13 | from robot.libraries.BuiltIn import BuiltIn |
| 14 | |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 15 | robot_pgm_dir_path = os.path.dirname(__file__) + os.sep |
| 16 | repo_data_dir_path = re.sub('/lib', '/data', robot_pgm_dir_path) |
| 17 | sys.path.append(repo_data_dir_path) |
| 18 | |
| 19 | import gen_robot_keyword as keyword |
| 20 | import variables as var |
| 21 | |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 22 | BuiltIn().import_resource("state_manager.robot") |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 23 | BuiltIn().import_resource("rest_client.robot") |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 24 | |
| 25 | # We will build eventually the mapping for warm, cold reset as well. |
| 26 | VALID_STATES = { |
| 27 | 'reboot': |
| 28 | { |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 29 | # (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'), |
George Keishing | efc3ff2 | 2017-12-12 11:49:25 -0600 | [diff] [blame] | 35 | ('ALWAYS_POWER_OFF', 'Ready', 'On', 'Running'), |
| 36 | ('ALWAYS_POWER_OFF', 'Ready', 'Off', 'Off'), |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 37 | }, |
| 38 | } |
| 39 | |
| 40 | VALID_BOOT_STATES = { |
| 41 | 'Off': # Valid states when Host is Off. |
| 42 | { |
| 43 | # (BMC , Chassis , Host , BootProgress, OperatingSystemState) |
| 44 | ( |
| 45 | "xyz.openbmc_project.State.BMC.BMCState.Ready", |
| 46 | "xyz.openbmc_project.State.Chassis.PowerState.Off", |
| 47 | "xyz.openbmc_project.State.Host.HostState.Off", |
| 48 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified", |
| 49 | "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive" |
| 50 | ), |
| 51 | }, |
| 52 | 'Reboot': # Valid states when BMC reset to standby. |
| 53 | { |
| 54 | # (BMC , Chassis , Host , BootProgress, OperatingSystemState) |
| 55 | ( |
| 56 | "xyz.openbmc_project.State.BMC.BMCState.Ready", |
| 57 | "xyz.openbmc_project.State.Chassis.PowerState.Off", |
| 58 | "xyz.openbmc_project.State.Host.HostState.Off", |
| 59 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified", |
| 60 | "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive" |
| 61 | ), |
| 62 | }, |
| 63 | 'Running': # Valid states when Host is powering on. |
| 64 | { |
| 65 | # (BMC , Chassis , Host , BootProgress, OperatingSystemState) |
| 66 | ( |
| 67 | "xyz.openbmc_project.State.BMC.BMCState.Ready", |
| 68 | "xyz.openbmc_project.State.Chassis.PowerState.On", |
| 69 | "xyz.openbmc_project.State.Host.HostState.Running", |
| 70 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages.MotherboardInit", |
| 71 | "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive" |
| 72 | ), |
| 73 | }, |
| 74 | 'Booted': # Valid state when Host is booted. |
| 75 | { |
| 76 | # (BMC , Chassis , Host , BootProgress, OperatingSystemState) |
| 77 | ( |
| 78 | "xyz.openbmc_project.State.BMC.BMCState.Ready", |
| 79 | "xyz.openbmc_project.State.Chassis.PowerState.On", |
| 80 | "xyz.openbmc_project.State.Host.HostState.Running", |
| 81 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart", |
| 82 | "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete" |
| 83 | ), |
| 84 | }, |
| 85 | 'ResetReload': # Valid state BMC reset reload when host is booted. |
| 86 | { |
| 87 | # (BMC , Chassis , Host , BootProgress, OperatingSystemState) |
| 88 | ( |
| 89 | "xyz.openbmc_project.State.BMC.BMCState.Ready", |
| 90 | "xyz.openbmc_project.State.Chassis.PowerState.On", |
| 91 | "xyz.openbmc_project.State.Host.HostState.Running", |
| 92 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart", |
| 93 | "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete" |
| 94 | ), |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 95 | }, |
| 96 | } |
| 97 | |
| 98 | |
| 99 | class state_map(): |
| 100 | |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 101 | def get_boot_state(self): |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 102 | r""" |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 103 | Return the system state as a tuple of bmc, chassis, host state, |
| 104 | BootProgress and OperatingSystemState. |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 105 | """ |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 106 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 107 | status, state = keyword.run_key("Read Properties " |
| 108 | + var.SYSTEM_STATE_URI + "enumerate") |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 109 | bmc_state = state[var.SYSTEM_STATE_URI + 'bmc0']['CurrentBMCState'] |
| 110 | chassis_state = \ |
| 111 | state[var.SYSTEM_STATE_URI + 'chassis0']['CurrentPowerState'] |
| 112 | host_state = state[var.SYSTEM_STATE_URI + 'host0']['CurrentHostState'] |
| 113 | boot_state = state[var.SYSTEM_STATE_URI + 'host0']['BootProgress'] |
| 114 | os_state = \ |
| 115 | state[var.SYSTEM_STATE_URI + 'host0']['OperatingSystemState'] |
| 116 | |
| 117 | return (str(bmc_state), |
George Keishing | 4d6f3d6 | 2017-02-06 09:50:41 -0600 | [diff] [blame] | 118 | str(chassis_state), |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 119 | str(host_state), |
| 120 | str(boot_state), |
| 121 | str(os_state)) |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 122 | |
| 123 | def valid_boot_state(self, boot_type, state_set): |
| 124 | r""" |
| 125 | Validate a given set of states is valid. |
| 126 | |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 127 | Description of argument(s): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 128 | boot_type Boot type (e.g. off/running/host booted |
| 129 | etc.) |
| 130 | state_set State set (e.g.bmc,chassis,host, |
| 131 | BootProgress,OperatingSystemState) |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 132 | """ |
George Keishing | 678b65c | 2017-08-31 16:16:39 -0500 | [diff] [blame] | 133 | |
| 134 | if state_set in set(VALID_BOOT_STATES[boot_type]): |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 135 | return True |
| 136 | else: |
| 137 | return False |