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 | """ |
| 9 | from robot.libraries.BuiltIn import BuiltIn |
| 10 | |
| 11 | BuiltIn().import_resource("state_manager.robot") |
| 12 | |
| 13 | # We will build eventually the mapping for warm, cold reset as well. |
| 14 | VALID_STATES = { |
| 15 | 'reboot': |
| 16 | { |
George Keishing | 4d6f3d6 | 2017-02-06 09:50:41 -0600 | [diff] [blame] | 17 | # (Power Policy, BMC state, Chassis State, Host State) |
| 18 | ('LEAVE_OFF','Ready','Off','Off'), |
| 19 | ('ALWAYS_POWER_ON','Ready','On','Running'), |
| 20 | ('ALWAYS_POWER_ON','Ready','On','Off'), |
| 21 | ('RESTORE_LAST_STATE','Ready','On','Running'), |
| 22 | ('RESTORE_LAST_STATE','Ready','On','Off'), |
| 23 | ('RESTORE_LAST_STATE','Ready','Off','Off'), |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 24 | }, |
| 25 | } |
| 26 | |
| 27 | |
| 28 | class state_map(): |
| 29 | |
| 30 | def get_system_state(self): |
| 31 | r""" |
George Keishing | 4d6f3d6 | 2017-02-06 09:50:41 -0600 | [diff] [blame] | 32 | Return the system state as a tuple of power policy, bmc, chassis and |
| 33 | host states. |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 34 | """ |
George Keishing | 4d6f3d6 | 2017-02-06 09:50:41 -0600 | [diff] [blame] | 35 | power_policy = BuiltIn().run_keyword('Get System Power Policy') |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 36 | bmc_state = BuiltIn().run_keyword('Get BMC State') |
| 37 | chassis_state = BuiltIn().run_keyword('Get Chassis Power State') |
| 38 | host_state = BuiltIn().run_keyword('Get Host State') |
George Keishing | 4d6f3d6 | 2017-02-06 09:50:41 -0600 | [diff] [blame] | 39 | return (str(power_policy), |
| 40 | str(bmc_state), |
| 41 | str(chassis_state), |
| 42 | str(host_state)) |
George Keishing | df9ad39 | 2017-01-25 13:01:15 -0600 | [diff] [blame] | 43 | |
| 44 | def valid_boot_state(self, boot_type, state_set): |
| 45 | r""" |
| 46 | Validate a given set of states is valid. |
| 47 | |
| 48 | Description of arguments: |
| 49 | boot_type Reset type (reboot/warm/cold) |
| 50 | state_set State set (bmc,chassis,host) |
| 51 | """ |
| 52 | if state_set in set(VALID_STATES[boot_type]): |
| 53 | return True |
| 54 | else: |
| 55 | return False |