Migrate System constants to enums

Change-Id: I7159f6f4c998d9a7de085b07aedd0313ea1b1e12
This commit is contained in:
Dmitry Tantsur
2021-11-04 14:35:27 +01:00
parent eda4ea115c
commit 519e54b1e9
11 changed files with 482 additions and 405 deletions

View File

@@ -126,9 +126,9 @@ Creating and using a sushy system object
print(sys_inst.power_state)
# Set the next boot device to boot once from PXE in UEFI mode
sys_inst.set_system_boot_source(sushy.BOOT_SOURCE_TARGET_PXE,
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE,
mode=sushy.BOOT_SOURCE_MODE_UEFI)
sys_inst.set_system_boot_source(sushy.BootSource.PXE,
enabled=sushy.BootSourceOverrideEnabled.ONCE,
mode=sushy.BootSourceOverrideMode.UEFI)
# Get the current boot source information
print(sys_inst.boot)

View File

@@ -16,6 +16,8 @@
# Values come from the Redfish System json-schema 1.0.0:
# http://redfish.dmtf.org/schemas/v1/ComputerSystem.v1_0_0.json#/definitions/ComputerSystem # noqa
import enum
from sushy.resources import constants as res_cons
# Reset action constants
@@ -46,144 +48,377 @@ SYSTEM_POWER_STATE_POWERING_OFF = res_cons.POWER_STATE_POWERING_OFF
"""A temporary state between On and Off. The power off action can take
time while the OS is in the shutdown process"""
# Boot source target constants
BOOT_SOURCE_TARGET_NONE = 'none'
"""Boot from the normal boot device"""
class BootSource(enum.Enum):
"""Boot source target constants"""
BOOT_SOURCE_TARGET_PXE = 'pxe'
"""Boot from the Pre-Boot EXecution (PXE) environment"""
NONE = 'None'
"""Boot from the normal boot device."""
BOOT_SOURCE_TARGET_FLOPPY = 'floppy'
"""Boot from the floppy disk drive"""
PXE = 'Pxe'
"""Boot from the Pre-Boot EXecution (PXE) environment."""
BOOT_SOURCE_TARGET_CD = 'cd'
"""Boot from the CD/DVD disc"""
FLOPPY = 'Floppy'
"""Boot from the floppy disk drive."""
BOOT_SOURCE_TARGET_USB = 'usb'
"""Boot from a USB device as specified by the system BIOS"""
CD = 'Cd'
"""Boot from the CD or DVD."""
BOOT_SOURCE_TARGET_HDD = 'hdd'
"""Boot from a hard drive"""
USB = 'Usb'
"""Boot from a system BIOS-specified USB device."""
BOOT_SOURCE_TARGET_BIOS_SETUP = 'bios setup'
"""Boot to the BIOS Setup Utility"""
HDD = 'Hdd'
"""Boot from a hard drive."""
BOOT_SOURCE_TARGET_UTILITIES = 'utilities'
"""Boot the manufacturer's Utilities program(s)"""
BIOS_SETUP = 'BiosSetup'
"""Boot to the BIOS setup utility."""
BOOT_SOURCE_TARGET_DIAGS = 'diags'
"""Boot the manufacturer's Diagnostics program"""
UTILITIES = 'Utilities'
"""Boot to the manufacturer's utilities program or programs."""
BOOT_SOURCE_TARGET_SD_CARD = 'sd card'
"""Boot from an SD Card"""
DIAGS = 'Diags'
"""Boot to the manufacturer's diagnostics program."""
BOOT_SOURCE_TARGET_UEFI_TARGET = 'uefi target'
"""Boot to the UEFI Device specified in the
UefiTargetBootSourceOverride property"""
UEFI_SHELL = 'UefiShell'
"""Boot to the UEFI Shell."""
BOOT_SOURCE_TARGET_UEFI_SHELL = 'uefi shell'
"""Boot to the UEFI Shell"""
UEFI_TARGET = 'UefiTarget'
"""Boot to the UEFI device specified in the UefiTargetBootSourceOverride
property."""
BOOT_SOURCE_TARGET_UEFI_HTTP = 'uefi http'
"""Boot from a UEFI HTTP network location"""
SD_CARD = 'SDCard'
"""Boot from an SD card."""
BOOT_SOURCE_TARGET_USB_CD = 'usb cd'
"""Boot from a USB CD device as specified by the system BIOS.
NOTE(janders): This is NOT a standard value.
On SuperMicro X11 and X12 machines, virtual media is presented as an USB CD
drive as opposed to a CD drive. Both are present in the list of boot
devices, however only selecting UsbCd as the boot source results in a
successful boot from vMedia. If CD is selected, boot fails even if vMedia
is inserted."""
UEFI_HTTP = 'UefiHttp'
"""Boot from a UEFI HTTP network location."""
# Boot source mode constants
REMOTE_DRIVE = 'RemoteDrive'
"""Boot from a remote drive, such as an iSCSI target."""
BOOT_SOURCE_MODE_BIOS = 'bios'
BOOT_SOURCE_MODE_UEFI = 'uefi'
UEFI_BOOT_NEXT = 'UefiBootNext'
"""Boot to the UEFI device that the BootNext property specifies."""
# Boot source enabled constants
USB_CD = 'UsbCd'
"""Boot from a USB CD device as specified by the system BIOS.
**This is NOT a standard value!**
On SuperMicro X11 and X12 machines, virtual media is presented as an USB CD
drive as opposed to a CD drive. Both are present in the list of boot
devices, however only selecting UsbCd as the boot source results in a
successful boot from vMedia. If CD is selected, boot fails even if vMedia
is inserted."""
# Backward compatibility
BOOT_SOURCE_TARGET_NONE = BootSource.NONE
BOOT_SOURCE_TARGET_PXE = BootSource.PXE
BOOT_SOURCE_TARGET_FLOPPY = BootSource.FLOPPY
BOOT_SOURCE_TARGET_CD = BootSource.CD
BOOT_SOURCE_TARGET_USB = BootSource.USB
BOOT_SOURCE_TARGET_HDD = BootSource.HDD
BOOT_SOURCE_TARGET_BIOS_SETUP = BootSource.BIOS_SETUP
BOOT_SOURCE_TARGET_UTILITIES = BootSource.UTILITIES
BOOT_SOURCE_TARGET_DIAGS = BootSource.DIAGS
BOOT_SOURCE_TARGET_UEFI_SHELL = BootSource.UEFI_SHELL
BOOT_SOURCE_TARGET_UEFI_TARGET = BootSource.UEFI_TARGET
BOOT_SOURCE_TARGET_SD_CARD = BootSource.SD_CARD
BOOT_SOURCE_TARGET_UEFI_HTTP = BootSource.UEFI_HTTP
BOOT_SOURCE_TARGET_USB_CD = BootSource.USB_CD
class BootSourceOverrideMode(enum.Enum):
"""Boot source mode constants"""
LEGACY = 'Legacy'
"""The system boots in non-UEFI boot mode to the boot source override
target."""
UEFI = 'UEFI'
"""The system boots in UEFI boot mode to the boot source override
target."""
# Backward compatibility
BOOT_SOURCE_MODE_BIOS = BootSourceOverrideMode.LEGACY
BOOT_SOURCE_MODE_UEFI = BootSourceOverrideMode.UEFI
class BootSourceOverrideEnabled(enum.Enum):
"""Boot source enabled constants"""
DISABLED = 'Disabled'
"""The system boots normally."""
ONCE = 'Once'
"""On its next boot cycle, the system boots one time to the boot source
override target. Then, the BootSourceOverrideEnabled value is reset
to `Disabled`."""
CONTINUOUS = 'Continuous'
"""The system boots to the target specified in the
BootSourceOverrideTarget property until this property is `Disabled`."""
# Backward compatibility
BOOT_SOURCE_ENABLED_DISABLED = BootSourceOverrideEnabled.DISABLED
BOOT_SOURCE_ENABLED_ONCE = BootSourceOverrideEnabled.ONCE
BOOT_SOURCE_ENABLED_CONTINUOUS = BootSourceOverrideEnabled.CONTINUOUS
class SystemType(enum.Enum):
"""System type constants"""
PHYSICAL = 'Physical'
"""A computer system."""
VIRTUAL = 'Virtual'
"""A virtual machine instance running on this system."""
OS = 'OS'
"""An operating system instance."""
PHYSICALLY_PARTITIONED = 'PhysicallyPartitioned'
"""A hardware-based partition of a computer system."""
VIRTUALLY_PARTITIONED = 'VirtuallyPartitioned'
"""A virtual or software-based partition of a computer system."""
COMPOSED = 'Composed'
"""A computer system constructed by binding resource blocks together."""
DPU = 'DPU'
"""A computer system that performs the functions of a data processing
unit, such as a SmartNIC."""
# Backward compatibility
SYSTEM_TYPE_PHYSICAL = SystemType.PHYSICAL
SYSTEM_TYPE_VIRTUAL = SystemType.VIRTUAL
SYSTEM_TYPE_OS = SystemType.OS
SYSTEM_TYPE_PHYSICALLY_PARTITIONED = SystemType.PHYSICALLY_PARTITIONED
SYSTEM_TYPE_VIRTUALLY_PARTITIONED = SystemType.VIRTUALLY_PARTITIONED
SYSTEM_TYPE_COMPOSED = SystemType.COMPOSED
SYSTEM_TYPE_DPU = SystemType.DPU
BOOT_SOURCE_ENABLED_ONCE = 'once'
BOOT_SOURCE_ENABLED_CONTINUOUS = 'continuous'
BOOT_SOURCE_ENABLED_DISABLED = 'disabled'
# Processor related constants
# Values comes from the Redfish Processor json-schema 1.3.0:
# http://redfish.dmtf.org/schemas/v1/Processor.v1_3_0.json
# Processor Architecture constants
class ProcessorArchitecture(enum.Enum):
"""Processor Architecture constants"""
PROCESSOR_ARCH_x86 = 'x86 or x86-64'
PROCESSOR_ARCH_IA_64 = 'Intel Itanium'
PROCESSOR_ARCH_ARM = 'ARM'
PROCESSOR_ARCH_MIPS = 'MIPS'
PROCESSOR_ARCH_OEM = 'OEM-defined'
X86 = 'x86'
"""x86 or x86-64."""
# Processor type constants
IA_64 = 'IA-64'
"""Intel Itanium."""
PROCESSOR_TYPE_ACCELERATOR = 'An Accelerator'
PROCESSOR_TYPE_CPU = 'A Central Processing Unit'
PROCESSOR_TYPE_CORE = 'A Core in a Processor'
PROCESSOR_TYPE_DSP = 'A Digital Signal Processor'
PROCESSOR_TYPE_FPGA = 'A Field Programmable Gate Array'
PROCESSOR_TYPE_GPU = 'A Graphics Processing Unit'
PROCESSOR_TYPE_OEM = 'An OEM-defined Processing Unit'
PROCESSOR_TYPE_THREAD = 'A Thread in a Processor'
ARM = 'ARM'
"""ARM."""
# Processor InstructionSet constants
MIPS = 'MIPS'
"""MIPS."""
PROCESSOR_INSTRUCTIONSET_ARM_A32 = 'ARM 32-bit'
PROCESSOR_INSTRUCTIONSET_ARM_A64 = 'ARM 64-bit'
PROCESSOR_INSTRUCTIONSET_IA_64 = 'Intel IA-64'
PROCESSOR_INSTRUCTIONSET_MIPS32 = 'MIPS 32-bit'
PROCESSOR_INSTRUCTIONSET_MIPS64 = 'MIPS 64-bit'
PROCESSOR_INSTRUCTIONSET_OEM = 'OEM-defined'
PROCESSOR_INSTRUCTIONSET_x86 = 'x86 32-bit'
PROCESSOR_INSTRUCTIONSET_x86_64 = 'x86 64-bit'
POWER = 'Power'
"""Power."""
# System type constants
OEM = 'OEM'
"""OEM-defined."""
SYSTEM_TYPE_PHYSICAL = "Physical"
"""A physical computer system"""
SYSTEM_TYPE_VIRTUAL = "Virtual"
"""A virtual machine instance"""
SYSTEM_TYPE_OS = "OS"
"""An operating system instance"""
SYSTEM_TYPE_PHYSICALLY_PARTITIONED = "PhysicallyPartitioned"
"""A hardware-based partition of a computer system"""
SYSTEM_TYPE_VIRTUALLY_PARTITIONED = "VirtuallyPartitioned"
"""A virtual or software-based partition of a computer system"""
SYSTEM_TYPE_COMPOSED = "Composed"
"""A computer system created by binding resource blocks together"""
# Secure boot constants
# Backward compatibility
PROCESSOR_ARCH_x86 = ProcessorArchitecture.X86
PROCESSOR_ARCH_IA_64 = ProcessorArchitecture.IA_64
PROCESSOR_ARCH_ARM = ProcessorArchitecture.ARM
PROCESSOR_ARCH_MIPS = ProcessorArchitecture.MIPS
PROCESSOR_ARCH_OEM = ProcessorArchitecture.OEM
SECURE_BOOT_ENABLED = "Enabled"
"""UEFI secure boot is enabled."""
SECURE_BOOT_DISABLED = "Disabled"
"""UEFI secure boot is disabled."""
class ProcessorType(enum.Enum):
"""Processor type constants"""
SECURE_BOOT_MODE_SETUP = "SetupMode"
SECURE_BOOT_MODE_USER = "UserMode"
SECURE_BOOT_MODE_AUDIT = "AuditMode"
SECURE_BOOT_MODE_DEPLOYED = "DeployedMode"
CPU = 'CPU'
"""A CPU."""
SECURE_BOOT_RESET_KEYS_TO_DEFAULT = "ResetAllKeysToDefault"
SECURE_BOOT_RESET_KEYS_DELETE_ALL = "DeleteAllKeys"
SECURE_BOOT_RESET_KEYS_DELETE_PK = "DeletePK"
GPU = 'GPU'
"""A GPU."""
SECURE_BOOT_PLATFORM_KEY = "PK"
SECURE_BOOT_KEY_EXCHANGE_KEYS = "KEK"
SECURE_BOOT_ALLOWED_KEYS_DATABASE = "db"
SECURE_BOOT_DENIED_KEYS_DATABASE = "dbx"
SECURE_BOOT_RECOVERY_KEYS_DATABASE = "dbr"
SECURE_BOOT_TIMESTAMP_DATABASE = "dbt"
FPGA = 'FPGA'
"""An FPGA."""
SECURE_BOOT_DEFAULT_PLATFORM_KEY = "PKDefault"
SECURE_BOOT_DEFAULT_KEY_EXCHANGE_KEYS = "KEKDefault"
SECURE_BOOT_DEFAULT_ALLOWED_KEYS_DATABASE = "dbDefault"
SECURE_BOOT_DEFAULT_DENIED_KEYS_DATABASE = "dbxDefault"
SECURE_BOOT_DEFAULT_RECOVERY_KEYS_DATABASE = "dbrDefault"
SECURE_BOOT_DEFAULT_TIMESTAMP_DATABASE = "dbtDefault"
DSP = 'DSP'
"""A DSP."""
ACCELERATOR = 'Accelerator'
"""An accelerator."""
CORE = 'Core'
"""A core in a processor."""
THREAD = 'Thread'
"""A thread in a processor."""
OEM = 'OEM'
"""An OEM-defined processing unit."""
# Backward compatibility
PROCESSOR_TYPE_CPU = ProcessorType.CPU
PROCESSOR_TYPE_GPU = ProcessorType.GPU
PROCESSOR_TYPE_FPGA = ProcessorType.FPGA
PROCESSOR_TYPE_DSP = ProcessorType.DSP
PROCESSOR_TYPE_ACCELERATOR = ProcessorType.ACCELERATOR
PROCESSOR_TYPE_CORE = ProcessorType.CORE
PROCESSOR_TYPE_THREAD = ProcessorType.THREAD
PROCESSOR_TYPE_OEM = ProcessorType.OEM
class InstructionSet(enum.Enum):
"""Processor InstructionSet constants"""
X86 = 'x86'
"""x86 32-bit."""
X86_64 = 'x86-64'
"""x86 64-bit."""
IA_64 = 'IA-64'
"""Intel IA-64."""
ARM_A32 = 'ARM-A32'
"""ARM 32-bit."""
ARM_A64 = 'ARM-A64'
"""ARM 64-bit."""
MIPS32 = 'MIPS32'
"""MIPS 32-bit."""
MIPS64 = 'MIPS64'
"""MIPS 64-bit."""
POWER_ISA = 'PowerISA'
"""PowerISA-64 or PowerISA-32."""
OEM = 'OEM'
"""OEM-defined."""
PROCESSOR_INSTRUCTIONSET_ARM_A32 = InstructionSet.ARM_A32
PROCESSOR_INSTRUCTIONSET_ARM_A64 = InstructionSet.ARM_A64
PROCESSOR_INSTRUCTIONSET_IA_64 = InstructionSet.IA_64
PROCESSOR_INSTRUCTIONSET_MIPS32 = InstructionSet.MIPS32
PROCESSOR_INSTRUCTIONSET_MIPS64 = InstructionSet.MIPS64
PROCESSOR_INSTRUCTIONSET_OEM = InstructionSet.OEM
PROCESSOR_INSTRUCTIONSET_x86 = InstructionSet.X86
PROCESSOR_INSTRUCTIONSET_x86_64 = InstructionSet.X86_64
# Secure boot constants from SecureBoot schema version 1.1.0
# https://redfish.dmtf.org/schemas/v1/SecureBoot.v1_1_0.json
# Some names were altered for clarity
class SecureBootCurrentBoot(enum.Enum):
ENABLED = 'Enabled'
"""UEFI Secure Boot is currently enabled."""
DISABLED = 'Disabled'
"""UEFI Secure Boot is currently disabled."""
# Backward compatibility
SECURE_BOOT_ENABLED = SecureBootCurrentBoot.ENABLED
SECURE_BOOT_DISABLED = SecureBootCurrentBoot.DISABLED
class SecureBootMode(enum.Enum):
SETUP = 'SetupMode'
"""UEFI Secure Boot is currently in Setup Mode."""
USER = 'UserMode'
"""UEFI Secure Boot is currently in User Mode."""
AUDIT = 'AuditMode'
"""UEFI Secure Boot is currently in Audit Mode."""
DEPLOYED = 'DeployedMode'
"""UEFI Secure Boot is currently in Deployed Mode."""
# Backward compatibility
SECURE_BOOT_MODE_SETUP = SecureBootMode.SETUP
SECURE_BOOT_MODE_USER = SecureBootMode.USER
SECURE_BOOT_MODE_AUDIT = SecureBootMode.AUDIT
SECURE_BOOT_MODE_DEPLOYED = SecureBootMode.DEPLOYED
class SecureBootResetKeysType(enum.Enum):
RESET_ALL_KEYS_TO_DEFAULT = 'ResetAllKeysToDefault'
"""Reset the contents of all UEFI Secure Boot key databases, including
the PK key database, to the default values."""
DELETE_ALL_KEYS = 'DeleteAllKeys'
"""Delete the contents of all UEFI Secure Boot key databases, including
the PK key database. This puts the system in Setup Mode."""
DELETE_PK = 'DeletePK'
"""Delete the contents of the PK UEFI Secure Boot database. This puts
the system in Setup Mode."""
# Internal constant based on
# https://redfish.dmtf.org/schemas/v1/SecureBootDatabase.v1_0_1.json
_SECURE_BOOT_DATABASE_RESET_KEYS = frozenset([
SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT,
SecureBootResetKeysType.DELETE_ALL_KEYS,
])
# Backward compatibility
SECURE_BOOT_RESET_KEYS_TO_DEFAULT = \
SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT
SECURE_BOOT_RESET_KEYS_DELETE_ALL = SecureBootResetKeysType.DELETE_ALL_KEYS
SECURE_BOOT_RESET_KEYS_DELETE_PK = SecureBootResetKeysType.DELETE_PK
class SecureBootDatabaseId(enum.Enum):
# This enumeration is hand-written based on the database schema
# https://redfish.dmtf.org/schemas/v1/SecureBootDatabase.v1_0_1.json
# and the UEFI specification.
PLATFORM_KEY = "PK"
KEY_EXCHANGE_KEYS = "KEK"
ALLOWED_KEYS_DATABASE = "db"
DENIED_KEYS_DATABASE = "dbx"
RECOVERY_KEYS_DATABASE = "dbr"
TIMESTAMP_DATABASE = "dbt"
DEFAULT_PLATFORM_KEY = "PKDefault"
DEFAULT_KEY_EXCHANGE_KEYS = "KEKDefault"
DEFAULT_ALLOWED_KEYS_DATABASE = "dbDefault"
DEFAULT_DENIED_KEYS_DATABASE = "dbxDefault"
DEFAULT_RECOVERY_KEYS_DATABASE = "dbrDefault"
DEFAULT_TIMESTAMP_DATABASE = "dbtDefault"
# Backward compatibility
SECURE_BOOT_PLATFORM_KEY = SecureBootDatabaseId.PLATFORM_KEY
SECURE_BOOT_KEY_EXCHANGE_KEYS = SecureBootDatabaseId.KEY_EXCHANGE_KEYS
SECURE_BOOT_ALLOWED_KEYS_DATABASE = SecureBootDatabaseId.ALLOWED_KEYS_DATABASE
SECURE_BOOT_DENIED_KEYS_DATABASE = SecureBootDatabaseId.DENIED_KEYS_DATABASE
SECURE_BOOT_RECOVERY_KEYS_DATABASE = \
SecureBootDatabaseId.RECOVERY_KEYS_DATABASE
SECURE_BOOT_TIMESTAMP_DATABASE = SecureBootDatabaseId.TIMESTAMP_DATABASE
SECURE_BOOT_DEFAULT_PLATFORM_KEY = SecureBootDatabaseId.DEFAULT_PLATFORM_KEY
SECURE_BOOT_DEFAULT_KEY_EXCHANGE_KEYS = \
SecureBootDatabaseId.DEFAULT_KEY_EXCHANGE_KEYS
SECURE_BOOT_DEFAULT_ALLOWED_KEYS_DATABASE = \
SecureBootDatabaseId.DEFAULT_ALLOWED_KEYS_DATABASE
SECURE_BOOT_DEFAULT_DENIED_KEYS_DATABASE = \
SecureBootDatabaseId.DEFAULT_DENIED_KEYS_DATABASE
SECURE_BOOT_DEFAULT_RECOVERY_KEYS_DATABASE = \
SecureBootDatabaseId.DEFAULT_RECOVERY_KEYS_DATABASE
SECURE_BOOT_DEFAULT_TIMESTAMP_DATABASE = \
SecureBootDatabaseId.DEFAULT_TIMESTAMP_DATABASE

View File

@@ -1,152 +0,0 @@
# Copyright 2017 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from sushy.resources.system import constants as sys_cons
from sushy import utils
BOOT_SOURCE_TARGET_MAP = {
'None': sys_cons.BOOT_SOURCE_TARGET_NONE,
'Pxe': sys_cons.BOOT_SOURCE_TARGET_PXE,
'Floppy': sys_cons.BOOT_SOURCE_TARGET_FLOPPY,
'Cd': sys_cons.BOOT_SOURCE_TARGET_CD,
'Usb': sys_cons.BOOT_SOURCE_TARGET_USB,
'Hdd': sys_cons.BOOT_SOURCE_TARGET_HDD,
'BiosSetup': sys_cons.BOOT_SOURCE_TARGET_BIOS_SETUP,
'Utilities': sys_cons.BOOT_SOURCE_TARGET_UTILITIES,
'Diags': sys_cons.BOOT_SOURCE_TARGET_DIAGS,
'SDCard': sys_cons.BOOT_SOURCE_TARGET_SD_CARD,
'UefiTarget': sys_cons.BOOT_SOURCE_TARGET_UEFI_TARGET,
'UefiShell': sys_cons.BOOT_SOURCE_TARGET_UEFI_SHELL,
'UefiHttp': sys_cons.BOOT_SOURCE_TARGET_UEFI_HTTP,
'UsbCd': sys_cons.BOOT_SOURCE_TARGET_USB_CD,
}
BOOT_SOURCE_TARGET_MAP_REV = utils.revert_dictionary(BOOT_SOURCE_TARGET_MAP)
BOOT_SOURCE_MODE_MAP = {
'Legacy': sys_cons.BOOT_SOURCE_MODE_BIOS,
'UEFI': sys_cons.BOOT_SOURCE_MODE_UEFI,
}
BOOT_SOURCE_MODE_MAP_REV = utils.revert_dictionary(BOOT_SOURCE_MODE_MAP)
BOOT_SOURCE_ENABLED_MAP = {
'Once': sys_cons.BOOT_SOURCE_ENABLED_ONCE,
'Continuous': sys_cons.BOOT_SOURCE_ENABLED_CONTINUOUS,
'Disabled': sys_cons.BOOT_SOURCE_ENABLED_DISABLED,
}
BOOT_SOURCE_ENABLED_MAP_REV = utils.revert_dictionary(BOOT_SOURCE_ENABLED_MAP)
PROCESSOR_ARCH_VALUE_MAP = {
'x86': sys_cons.PROCESSOR_ARCH_x86,
'IA-64': sys_cons.PROCESSOR_ARCH_IA_64,
'ARM': sys_cons.PROCESSOR_ARCH_ARM,
'MIPS': sys_cons.PROCESSOR_ARCH_MIPS,
'OEM': sys_cons.PROCESSOR_ARCH_OEM,
}
PROCESSOR_ARCH_VALUE_MAP_REV = (
utils.revert_dictionary(PROCESSOR_ARCH_VALUE_MAP))
PROCESSOR_TYPE_VALUE_MAP = {
'Accelerator': sys_cons.PROCESSOR_TYPE_ACCELERATOR,
'CPU': sys_cons.PROCESSOR_TYPE_CPU,
'Core': sys_cons.PROCESSOR_TYPE_CORE,
'DSP': sys_cons.PROCESSOR_TYPE_DSP,
'FPGA': sys_cons.PROCESSOR_TYPE_FPGA,
'GPU': sys_cons.PROCESSOR_TYPE_GPU,
'OEM': sys_cons.PROCESSOR_TYPE_OEM,
'Thread': sys_cons.PROCESSOR_TYPE_THREAD
}
PROCESSOR_TYPE_VALUE_MAP_REV = (
utils.revert_dictionary(PROCESSOR_TYPE_VALUE_MAP))
PROCESSOR_INSTRUCTIONSET_VALUE_MAP = {
'ARM-A32': sys_cons.PROCESSOR_INSTRUCTIONSET_ARM_A32,
'ARM-A64': sys_cons.PROCESSOR_INSTRUCTIONSET_ARM_A64,
'IA-64': sys_cons.PROCESSOR_INSTRUCTIONSET_IA_64,
'MIPS32': sys_cons.PROCESSOR_INSTRUCTIONSET_MIPS32,
'MIPS64': sys_cons.PROCESSOR_INSTRUCTIONSET_MIPS64,
'OEM': sys_cons.PROCESSOR_INSTRUCTIONSET_OEM,
'x86': sys_cons.PROCESSOR_INSTRUCTIONSET_x86,
'x86-64': sys_cons.PROCESSOR_INSTRUCTIONSET_x86_64
}
PROCESSOR_INSTRUCTIONSET_VALUE_MAP_REV = (
utils.revert_dictionary(PROCESSOR_INSTRUCTIONSET_VALUE_MAP))
SYSTEM_TYPE_VALUE_MAP = {
'Physical': sys_cons.SYSTEM_TYPE_PHYSICAL,
'Virtual': sys_cons.SYSTEM_TYPE_VIRTUAL,
'OS': sys_cons.SYSTEM_TYPE_OS,
'PhysicallyPartitioned': sys_cons.SYSTEM_TYPE_PHYSICALLY_PARTITIONED,
'VirtuallyPartitioned': sys_cons.SYSTEM_TYPE_VIRTUALLY_PARTITIONED,
'Composed': sys_cons.SYSTEM_TYPE_COMPOSED
}
SYSTEM_TYPE_VALUE_MAP_REV = (
utils.revert_dictionary(SYSTEM_TYPE_VALUE_MAP))
SECURE_BOOT_STATE = {
'Enabled': sys_cons.SECURE_BOOT_ENABLED,
'Disabled': sys_cons.SECURE_BOOT_DISABLED,
}
SECURE_BOOT_STATE_REV = utils.revert_dictionary(SECURE_BOOT_STATE)
SECURE_BOOT_MODE = {
'SetupMode': sys_cons.SECURE_BOOT_MODE_SETUP,
'UserMode': sys_cons.SECURE_BOOT_MODE_USER,
'AuditMode': sys_cons.SECURE_BOOT_MODE_AUDIT,
'DeployedMode': sys_cons.SECURE_BOOT_MODE_DEPLOYED,
}
SECURE_BOOT_MODE_REV = utils.revert_dictionary(SECURE_BOOT_MODE)
SECURE_BOOT_RESET_KEYS = {
'ResetAllKeysToDefault': sys_cons.SECURE_BOOT_RESET_KEYS_TO_DEFAULT,
'DeleteAllKeys': sys_cons.SECURE_BOOT_RESET_KEYS_DELETE_ALL,
'DeletePK': sys_cons.SECURE_BOOT_RESET_KEYS_DELETE_PK,
}
SECURE_BOOT_RESET_KEYS_REV = utils.revert_dictionary(SECURE_BOOT_RESET_KEYS)
SECURE_BOOT_DATABASE_TYPE = {
'PK': sys_cons.SECURE_BOOT_PLATFORM_KEY,
'KEK': sys_cons.SECURE_BOOT_KEY_EXCHANGE_KEYS,
'db': sys_cons.SECURE_BOOT_ALLOWED_KEYS_DATABASE,
'dbx': sys_cons.SECURE_BOOT_DENIED_KEYS_DATABASE,
'dbr': sys_cons.SECURE_BOOT_RECOVERY_KEYS_DATABASE,
'dbt': sys_cons.SECURE_BOOT_TIMESTAMP_DATABASE,
'PKDefault': sys_cons.SECURE_BOOT_DEFAULT_PLATFORM_KEY,
'KEKDefault': sys_cons.SECURE_BOOT_DEFAULT_KEY_EXCHANGE_KEYS,
'dbDefault': sys_cons.SECURE_BOOT_DEFAULT_ALLOWED_KEYS_DATABASE,
'dbxDefault': sys_cons.SECURE_BOOT_DEFAULT_DENIED_KEYS_DATABASE,
'dbrDefault': sys_cons.SECURE_BOOT_DEFAULT_RECOVERY_KEYS_DATABASE,
'dbtDefault': sys_cons.SECURE_BOOT_DEFAULT_TIMESTAMP_DATABASE,
}
SECURE_BOOT_DATABASE_TYPE_REV = utils.revert_dictionary(
SECURE_BOOT_DATABASE_TYPE)
SECURE_BOOT_DATABASE_RESET_KEYS = {
'ResetAllKeysToDefault': sys_cons.SECURE_BOOT_RESET_KEYS_TO_DEFAULT,
'DeleteAllKeys': sys_cons.SECURE_BOOT_RESET_KEYS_DELETE_ALL,
}
SECURE_BOOT_DATABASE_RESET_KEYS_REV = utils.revert_dictionary(
SECURE_BOOT_DATABASE_RESET_KEYS)

View File

@@ -21,7 +21,7 @@ import logging
from sushy import exceptions
from sushy.resources import base
from sushy.resources import common
from sushy.resources.system import mappings as sys_maps
from sushy.resources.system import constants as sys_cons
from sushy import utils
# Representation of Summary of Processor information
@@ -59,16 +59,15 @@ class Processor(base.ResourceBase):
socket = base.Field('Socket')
"""The socket or location of the processor"""
processor_type = base.MappedField(
'ProcessorType', sys_maps.PROCESSOR_TYPE_VALUE_MAP)
processor_type = base.MappedField('ProcessorType', sys_cons.ProcessorType)
"""The type of processor"""
processor_architecture = base.MappedField(
'ProcessorArchitecture', sys_maps.PROCESSOR_ARCH_VALUE_MAP)
processor_architecture = base.MappedField('ProcessorArchitecture',
sys_cons.ProcessorArchitecture)
"""The architecture of the processor"""
instruction_set = base.MappedField(
'InstructionSet', sys_maps.PROCESSOR_INSTRUCTIONSET_VALUE_MAP)
instruction_set = base.MappedField('InstructionSet',
sys_cons.InstructionSet)
"""The instruction set of the processor"""
manufacturer = base.Field('Manufacturer')

View File

@@ -18,7 +18,7 @@ import logging
from sushy import exceptions
from sushy.resources import base
from sushy.resources import common
from sushy.resources.system import mappings
from sushy.resources.system import constants
from sushy.resources.system import secure_boot_database
from sushy import utils
@@ -49,7 +49,7 @@ class SecureBoot(base.ResourceBase):
"""Human-readable description of the BIOS resource"""
current_boot = base.MappedField('SecureBootCurrentBoot',
mappings.SECURE_BOOT_STATE)
constants.SecureBootCurrentBoot)
"""The UEFI Secure Boot state during the current boot cycle."""
enabled = base.Field('SecureBootEnable')
@@ -58,7 +58,7 @@ class SecureBoot(base.ResourceBase):
This property can be enabled in UEFI boot mode only.
"""
mode = base.MappedField('SecureBootMode', mappings.SECURE_BOOT_MODE)
mode = base.MappedField('SecureBootMode', constants.SecureBootMode)
"""The current UEFI Secure Boot Mode."""
# TODO(dtantsur): SecureBootDatabases
@@ -114,11 +114,10 @@ class SecureBoot(base.ResourceBase):
if not reset_action.allowed_values:
LOG.warning('Could not figure out the allowed values for the '
'reset keys action for %s', self.identity)
return set(mappings.SECURE_BOOT_RESET_KEYS_REV)
return set(constants.SecureBootResetKeysType)
return set([mappings.SECURE_BOOT_RESET_KEYS[v] for v in
set(mappings.SECURE_BOOT_RESET_KEYS).
intersection(reset_action.allowed_values)])
return {v for v in constants.SecureBootResetKeysType
if v.value in reset_action.allowed_values}
def reset_keys(self, reset_type):
"""Reset secure boot keys.
@@ -132,6 +131,7 @@ class SecureBoot(base.ResourceBase):
parameter='reset_type', value=reset_type,
valid_values=valid_resets)
reset_type = constants.SecureBootResetKeysType(reset_type).value
target_uri = self._get_reset_action_element().target_uri
self._conn.post(target_uri, data={'ResetKeysType': reset_type})

View File

@@ -15,7 +15,7 @@ import logging
from sushy import exceptions
from sushy.resources import base
from sushy.resources import common
from sushy.resources.system import mappings
from sushy.resources.system import constants
LOG = logging.getLogger(__name__)
@@ -37,7 +37,7 @@ class SecureBootDatabase(base.ResourceBase):
# TODO(dtantsur): certificates
database_id = base.MappedField('DatabaseId',
mappings.SECURE_BOOT_DATABASE_TYPE)
constants.SecureBootDatabaseId)
"""Standard UEFI database type."""
description = base.Field('Description')
@@ -70,11 +70,10 @@ class SecureBootDatabase(base.ResourceBase):
if not reset_action.allowed_values:
LOG.warning('Could not figure out the allowed values for the '
'reset keys action for %s', self.identity)
return set(mappings.SECURE_BOOT_DATABASE_RESET_KEYS_REV)
return constants._SECURE_BOOT_DATABASE_RESET_KEYS
return set([mappings.SECURE_BOOT_DATABASE_RESET_KEYS[v] for v in
set(mappings.SECURE_BOOT_DATABASE_RESET_KEYS).
intersection(reset_action.allowed_values)])
return {v for v in constants._SECURE_BOOT_DATABASE_RESET_KEYS
if v.value in reset_action.allowed_values}
def reset_keys(self, reset_type):
"""Reset secure boot keys.
@@ -88,6 +87,7 @@ class SecureBootDatabase(base.ResourceBase):
parameter='reset_type', value=reset_type,
valid_values=valid_resets)
reset_type = constants.SecureBootResetKeysType(reset_type).value
target_uri = self._get_reset_action_element().target_uri
self._conn.post(target_uri, data={'ResetKeysType': reset_type})

View File

@@ -29,7 +29,6 @@ from sushy.resources import settings
from sushy.resources.system import bios
from sushy.resources.system import constants as sys_cons
from sushy.resources.system import ethernet_interface
from sushy.resources.system import mappings as sys_maps
from sushy.resources.system import processor
from sushy.resources.system import secure_boot
from sushy.resources.system import simple_storage as sys_simple_storage
@@ -50,13 +49,12 @@ class BootField(base.CompositeField):
adapter=list)
enabled = base.MappedField('BootSourceOverrideEnabled',
sys_maps.BOOT_SOURCE_ENABLED_MAP)
sys_cons.BootSourceOverrideEnabled)
mode = base.MappedField('BootSourceOverrideMode',
sys_maps.BOOT_SOURCE_MODE_MAP)
sys_cons.BootSourceOverrideMode)
target = base.MappedField('BootSourceOverrideTarget',
sys_maps.BOOT_SOURCE_TARGET_MAP)
target = base.MappedField('BootSourceOverrideTarget', sys_cons.BootSource)
class MemorySummaryField(base.CompositeField):
@@ -118,8 +116,7 @@ class System(base.ResourceBase):
status = common.StatusField('Status')
"""The system status"""
system_type = base.MappedField('SystemType',
sys_maps.SYSTEM_TYPE_VALUE_MAP)
system_type = base.MappedField('SystemType', sys_cons.SystemType)
"""The system type"""
uuid = base.Field('UUID')
@@ -204,11 +201,10 @@ class System(base.ResourceBase):
LOG.warning('Could not figure out the allowed values for '
'configuring the boot source for System %s',
self.identity)
return set(sys_maps.BOOT_SOURCE_TARGET_MAP_REV)
return set(sys_cons.BootSource)
return set([sys_maps.BOOT_SOURCE_TARGET_MAP[v] for v in
set(sys_maps.BOOT_SOURCE_TARGET_MAP).
intersection(self.boot.allowed_values)])
return {v for v in sys_cons.BootSource
if v.value in self.boot.allowed_values}
def set_system_boot_options(self, target=None, enabled=None, mode=None):
"""Set boot source and/or boot frequency and/or boot mode.
@@ -216,13 +212,12 @@ class System(base.ResourceBase):
Set the boot source and/or boot frequency and/or boot mode to use
on next reboot of the System.
:param target: The target boot source, optional.
:param enabled: The frequency, whether to set it for the next
reboot only (BOOT_SOURCE_ENABLED_ONCE) or persistent to all
future reboots (BOOT_SOURCE_ENABLED_CONTINUOUS) or disabled
(BOOT_SOURCE_ENABLED_DISABLED), optional.
:param mode: The boot mode (UEFI: BOOT_SOURCE_MODE_UEFI or
BIOS: BOOT_SOURCE_MODE_BIOS), optional.
:param target: The target boot source,
a :py:class:`sushy.BootSource` value. Optional.
:param enabled: How long the override be enabled,
a :py:class:`sushy.BootSourceOverrideEnabled` value. Optional.
:param mode: The boot mode,
a :py:class:`sushy.BootSourceOverrideMode` value. Optional.
:raises: InvalidParameterValueError, if any information passed is
invalid.
"""
@@ -235,7 +230,7 @@ class System(base.ResourceBase):
parameter='target', value=target,
valid_values=valid_targets)
fishy_target = sys_maps.BOOT_SOURCE_TARGET_MAP_REV[target]
target = sys_cons.BootSource(target)
# NOTE(janders) on SuperMicro X11 and X12 machines, virtual media
# is presented as an "USB CD" drive as opposed to a CD drive. Both
# are present in the list of boot devices, however only selecting
@@ -245,37 +240,33 @@ class System(base.ResourceBase):
# about to attempt boot from CD and overrides the boot device to
# UsbCd instead which makes boot from vMedia work as expected.
if (self.manufacturer and self.manufacturer.lower() == 'supermicro'
and fishy_target == sys_maps.BOOT_SOURCE_TARGET_MAP_REV[
sys_cons.BOOT_SOURCE_TARGET_CD]
and sys_maps.BOOT_SOURCE_TARGET_MAP_REV[
sys_cons.BOOT_SOURCE_TARGET_USB_CD]
and target == sys_cons.BootSource.CD
and sys_cons.BootSource.USB_CD.value
in self.boot.allowed_values):
fishy_target = sys_maps.BOOT_SOURCE_TARGET_MAP_REV[
sys_cons.BOOT_SOURCE_TARGET_USB_CD]
LOG.debug('Boot from vMedia was requested on a SuperMicro'
'machine. Overriding boot device from %s to %s.',
sys_cons.BOOT_SOURCE_TARGET_CD,
fishy_target)
target, sys_cons.BootSource.USB_CD)
target = sys_cons.BootSource.USB_CD
data['Boot']['BootSourceOverrideTarget'] = fishy_target
data['Boot']['BootSourceOverrideTarget'] = target.value
if enabled is not None:
if enabled not in sys_maps.BOOT_SOURCE_ENABLED_MAP_REV:
try:
fishy_freq = sys_cons.BootSourceOverrideEnabled(enabled).value
except ValueError:
raise exceptions.InvalidParameterValueError(
parameter='enabled', value=enabled,
valid_values=list(sys_maps.BOOT_SOURCE_ENABLED_MAP_REV))
fishy_freq = sys_maps.BOOT_SOURCE_ENABLED_MAP_REV[enabled]
valid_values=list(sys_cons.BootSourceOverrideEnabled))
data['Boot']['BootSourceOverrideEnabled'] = fishy_freq
if mode is not None:
if mode not in sys_maps.BOOT_SOURCE_MODE_MAP_REV:
try:
fishy_mode = sys_cons.BootSourceOverrideMode(mode).value
except ValueError:
raise exceptions.InvalidParameterValueError(
parameter='mode', value=mode,
valid_values=list(sys_maps.BOOT_SOURCE_MODE_MAP_REV))
fishy_mode = sys_maps.BOOT_SOURCE_MODE_MAP_REV[mode]
valid_values=list(sys_cons.BootSourceOverrideMode))
data['Boot']['BootSourceOverrideMode'] = fishy_mode
@@ -285,7 +276,7 @@ class System(base.ResourceBase):
# TODO(etingof): we should remove this method, eventually
def set_system_boot_source(
self, target, enabled=sys_cons.BOOT_SOURCE_ENABLED_ONCE,
self, target, enabled=sys_cons.BootSourceOverrideEnabled.ONCE,
mode=None):
"""Set boot source and/or boot frequency and/or boot mode.
@@ -294,14 +285,13 @@ class System(base.ResourceBase):
This method is obsoleted by `set_system_boot_options`.
:param target: The target boot source.
:param target: The target boot source,
a :py:class:`sushy.BootSource` value.
:param enabled: The frequency, whether to set it for the next
reboot only (BOOT_SOURCE_ENABLED_ONCE) or persistent to all
future reboots (BOOT_SOURCE_ENABLED_CONTINUOUS) or disabled
(BOOT_SOURCE_ENABLED_DISABLED).
Default is `BOOT_SOURCE_ENABLED_ONCE`.
:param mode: The boot mode (UEFI: BOOT_SOURCE_MODE_UEFI or
BIOS: BOOT_SOURCE_MODE_BIOS), optional.
a :py:class:`sushy.BootSourceOverrideEnabled` value.
Default is `ONCE`.
:param mode: The boot mode,
a :py:class:`sushy.BootSourceOverrideMode` value.
:raises: InvalidParameterValueError, if any information passed is
invalid.
"""

View File

@@ -43,13 +43,12 @@ class ProcessorTestCase(base.TestCase):
self.assertEqual('CPU1', self.sys_processor.identity)
self.assertEqual('CPU 1', self.sys_processor.socket)
self.assertEqual(
sushy.PROCESSOR_TYPE_CPU,
sushy.ProcessorType.CPU,
self.sys_processor.processor_type)
self.assertEqual(sushy.PROCESSOR_ARCH_x86,
self.assertEqual(sushy.ProcessorArchitecture.X86,
self.sys_processor.processor_architecture)
self.assertEqual(
sushy.PROCESSOR_INSTRUCTIONSET_x86_64,
self.sys_processor.instruction_set)
self.assertEqual(sushy.InstructionSet.X86_64,
self.sys_processor.instruction_set)
self.assertEqual('Intel(R) Corporation',
self.sys_processor.manufacturer)
self.assertEqual('Multi-Core Intel(R) Xeon(R) processor 7xxx Series',
@@ -167,10 +166,10 @@ class ProcessorCollectionTestCase(base.TestCase):
# | WHEN |
actual_summary = self.sys_processor_col.summary
# | THEN |
self.assertEqual((16, sushy.PROCESSOR_ARCH_x86),
self.assertEqual((16, sushy.ProcessorArchitecture.X86),
actual_summary)
self.assertEqual(16, actual_summary.count)
self.assertEqual(sushy.PROCESSOR_ARCH_x86,
self.assertEqual(sushy.ProcessorArchitecture.X86,
actual_summary.architecture)
# reset mock
@@ -186,7 +185,7 @@ class ProcessorCollectionTestCase(base.TestCase):
# | GIVEN |
self._setUp_processor_summary()
# | WHEN & THEN |
self.assertEqual((16, sushy.PROCESSOR_ARCH_x86),
self.assertEqual((16, sushy.ProcessorArchitecture.X86),
self.sys_processor_col.summary)
self.conn.get.return_value.json.side_effect = None
@@ -200,5 +199,5 @@ class ProcessorCollectionTestCase(base.TestCase):
# | GIVEN |
self._setUp_processor_summary()
# | WHEN & THEN |
self.assertEqual((16, sushy.PROCESSOR_ARCH_x86),
self.assertEqual((16, sushy.ProcessorArchitecture.X86),
self.sys_processor_col.summary)

View File

@@ -40,26 +40,28 @@ class SecureBootTestCase(base.TestCase):
self.assertEqual('UEFI Secure Boot', self.secure_boot.name)
self.assertIsNone(self.secure_boot.description)
self.assertIs(False, self.secure_boot.enabled)
self.assertEqual(constants.SECURE_BOOT_DISABLED,
self.assertEqual(constants.SecureBootCurrentBoot.DISABLED,
self.secure_boot.current_boot)
self.assertEqual(constants.SECURE_BOOT_MODE_DEPLOYED,
self.assertEqual(constants.SecureBootMode.DEPLOYED,
self.secure_boot.mode)
@mock.patch.object(secure_boot.LOG, 'warning', autospec=True)
def test_get_allowed_reset_keys_values(self, mock_log):
self.assertEqual({constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT,
constants.SECURE_BOOT_RESET_KEYS_DELETE_ALL,
constants.SECURE_BOOT_RESET_KEYS_DELETE_PK},
self.secure_boot.get_allowed_reset_keys_values())
self.assertEqual({
constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT,
constants.SecureBootResetKeysType.DELETE_ALL_KEYS,
constants.SecureBootResetKeysType.DELETE_PK
}, self.secure_boot.get_allowed_reset_keys_values())
self.assertFalse(mock_log.called)
@mock.patch.object(secure_boot.LOG, 'warning', autospec=True)
def test_get_allowed_reset_keys_values_no_values(self, mock_log):
self.secure_boot._actions.reset_keys.allowed_values = None
self.assertEqual({constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT,
constants.SECURE_BOOT_RESET_KEYS_DELETE_ALL,
constants.SECURE_BOOT_RESET_KEYS_DELETE_PK},
self.secure_boot.get_allowed_reset_keys_values())
self.assertEqual({
constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT,
constants.SecureBootResetKeysType.DELETE_ALL_KEYS,
constants.SecureBootResetKeysType.DELETE_PK
}, self.secure_boot.get_allowed_reset_keys_values())
self.assertTrue(mock_log.called)
@mock.patch.object(secure_boot.LOG, 'warning', autospec=True)
@@ -68,8 +70,9 @@ class SecureBootTestCase(base.TestCase):
'ResetAllKeysToDefault',
'IamNotRedfishCompatible',
]
self.assertEqual({constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT},
self.secure_boot.get_allowed_reset_keys_values())
self.assertEqual(
{constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT},
self.secure_boot.get_allowed_reset_keys_values())
self.assertFalse(mock_log.called)
def test_set_enabled(self):
@@ -84,7 +87,7 @@ class SecureBootTestCase(base.TestCase):
def test_reset_keys(self):
self.secure_boot.reset_keys(
constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT)
constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT)
self.conn.post.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/SecureBoot'
'/Actions/SecureBoot.ResetKeys',

View File

@@ -44,17 +44,19 @@ class SecureBootDatabaseTestCase(base.TestCase):
@mock.patch.object(secure_boot_database.LOG, 'warning', autospec=True)
def test_get_allowed_reset_keys_values(self, mock_log):
self.assertEqual({constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT,
constants.SECURE_BOOT_RESET_KEYS_DELETE_ALL},
self.secure_boot.get_allowed_reset_keys_values())
self.assertEqual({
constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT,
constants.SecureBootResetKeysType.DELETE_ALL_KEYS
}, self.secure_boot.get_allowed_reset_keys_values())
self.assertFalse(mock_log.called)
@mock.patch.object(secure_boot_database.LOG, 'warning', autospec=True)
def test_get_allowed_reset_keys_values_no_values(self, mock_log):
self.secure_boot._actions.reset_keys.allowed_values = None
self.assertEqual({constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT,
constants.SECURE_BOOT_RESET_KEYS_DELETE_ALL},
self.secure_boot.get_allowed_reset_keys_values())
self.assertEqual({
constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT,
constants.SecureBootResetKeysType.DELETE_ALL_KEYS
}, self.secure_boot.get_allowed_reset_keys_values())
self.assertTrue(mock_log.called)
@mock.patch.object(secure_boot_database.LOG, 'warning', autospec=True)
@@ -63,13 +65,14 @@ class SecureBootDatabaseTestCase(base.TestCase):
'ResetAllKeysToDefault',
'IamNotRedfishCompatible',
]
self.assertEqual({constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT},
self.secure_boot.get_allowed_reset_keys_values())
self.assertEqual(
{constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT},
self.secure_boot.get_allowed_reset_keys_values())
self.assertFalse(mock_log.called)
def test_reset_keys(self):
self.secure_boot.reset_keys(
constants.SECURE_BOOT_RESET_KEYS_TO_DEFAULT)
constants.SecureBootResetKeysType.RESET_ALL_KEYS_TO_DEFAULT)
self.conn.post.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/SecureBoot/SecureBootDatabases/db'
'/Actions/SecureBootDatabase.ResetKeys',

View File

@@ -25,7 +25,6 @@ from sushy.resources import constants as res_cons
from sushy.resources.manager import manager
from sushy.resources.oem import fake
from sushy.resources.system import bios
from sushy.resources.system import mappings as sys_map
from sushy.resources.system import processor
from sushy.resources.system import secure_boot
from sushy.resources.system import simple_storage
@@ -62,8 +61,7 @@ class SystemTestCase(base.TestCase):
self.assertEqual('224071-J23', self.sys_inst.part_number)
self.assertEqual('437XR1138R2', self.sys_inst.serial_number)
self.assertEqual('8675309', self.sys_inst.sku)
self.assertEqual(sushy.SYSTEM_TYPE_PHYSICAL,
self.sys_inst.system_type)
self.assertEqual(sushy.SystemType.PHYSICAL, self.sys_inst.system_type)
self.assertEqual('38947555-7742-3448-3784-823347823834',
self.sys_inst.uuid)
self.assertEqual(res_cons.State.ENABLED, self.sys_inst.status.state)
@@ -236,16 +234,16 @@ class SystemTestCase(base.TestCase):
def test_get_allowed_system_boot_source_values(self):
values = self.sys_inst.get_allowed_system_boot_source_values()
expected = set([sushy.BOOT_SOURCE_TARGET_NONE,
sushy.BOOT_SOURCE_TARGET_PXE,
sushy.BOOT_SOURCE_TARGET_CD,
sushy.BOOT_SOURCE_TARGET_USB,
sushy.BOOT_SOURCE_TARGET_HDD,
sushy.BOOT_SOURCE_TARGET_BIOS_SETUP,
sushy.BOOT_SOURCE_TARGET_UTILITIES,
sushy.BOOT_SOURCE_TARGET_DIAGS,
sushy.BOOT_SOURCE_TARGET_SD_CARD,
sushy.BOOT_SOURCE_TARGET_UEFI_TARGET])
expected = set([sushy.BootSource.NONE,
sushy.BootSource.PXE,
sushy.BootSource.CD,
sushy.BootSource.USB,
sushy.BootSource.HDD,
sushy.BootSource.BIOS_SETUP,
sushy.BootSource.UTILITIES,
sushy.BootSource.DIAGS,
sushy.BootSource.SD_CARD,
sushy.BootSource.UEFI_TARGET])
self.assertEqual(expected, values)
self.assertIsInstance(values, set)
@@ -255,29 +253,31 @@ class SystemTestCase(base.TestCase):
self.sys_inst.boot.allowed_values = None
values = self.sys_inst.get_allowed_system_boot_source_values()
# Assert it returns all values if it can't get the specific ones
expected = set([sushy.BOOT_SOURCE_TARGET_NONE,
sushy.BOOT_SOURCE_TARGET_PXE,
sushy.BOOT_SOURCE_TARGET_CD,
sushy.BOOT_SOURCE_TARGET_USB,
sushy.BOOT_SOURCE_TARGET_USB_CD,
sushy.BOOT_SOURCE_TARGET_HDD,
sushy.BOOT_SOURCE_TARGET_BIOS_SETUP,
sushy.BOOT_SOURCE_TARGET_UTILITIES,
sushy.BOOT_SOURCE_TARGET_DIAGS,
sushy.BOOT_SOURCE_TARGET_SD_CARD,
sushy.BOOT_SOURCE_TARGET_FLOPPY,
sushy.BOOT_SOURCE_TARGET_UEFI_TARGET,
sushy.BOOT_SOURCE_TARGET_UEFI_SHELL,
sushy.BOOT_SOURCE_TARGET_UEFI_HTTP])
expected = set([sushy.BootSource.NONE,
sushy.BootSource.PXE,
sushy.BootSource.CD,
sushy.BootSource.USB,
sushy.BootSource.HDD,
sushy.BootSource.BIOS_SETUP,
sushy.BootSource.UTILITIES,
sushy.BootSource.DIAGS,
sushy.BootSource.SD_CARD,
sushy.BootSource.FLOPPY,
sushy.BootSource.UEFI_TARGET,
sushy.BootSource.UEFI_SHELL,
sushy.BootSource.UEFI_HTTP,
sushy.BootSource.REMOTE_DRIVE,
sushy.BootSource.UEFI_BOOT_NEXT,
sushy.BootSource.USB_CD])
self.assertEqual(expected, values)
self.assertIsInstance(values, set)
self.assertEqual(1, mock_log.call_count)
def test_set_system_boot_options(self):
self.sys_inst.set_system_boot_options(
sushy.BOOT_SOURCE_TARGET_PXE,
enabled=sushy.BOOT_SOURCE_ENABLED_CONTINUOUS,
mode=sushy.BOOT_SOURCE_MODE_UEFI)
sushy.BootSource.PXE,
enabled=sushy.BootSourceOverrideEnabled.CONTINUOUS,
mode=sushy.BootSourceOverrideMode.UEFI)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
@@ -286,8 +286,8 @@ class SystemTestCase(base.TestCase):
def test_set_system_boot_options_no_mode_specified(self):
self.sys_inst.set_system_boot_options(
sushy.BOOT_SOURCE_TARGET_HDD,
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
sushy.BootSource.HDD,
enabled=sushy.BootSourceOverrideEnabled.ONCE)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'Boot': {'BootSourceOverrideEnabled': 'Once',
@@ -295,8 +295,8 @@ class SystemTestCase(base.TestCase):
def test_set_system_boot_options_no_target_specified(self):
self.sys_inst.set_system_boot_options(
enabled=sushy.BOOT_SOURCE_ENABLED_CONTINUOUS,
mode=sushy.BOOT_SOURCE_MODE_UEFI)
enabled=sushy.BootSourceOverrideEnabled.CONTINUOUS,
mode=sushy.BootSourceOverrideMode.UEFI)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
@@ -304,8 +304,8 @@ class SystemTestCase(base.TestCase):
def test_set_system_boot_options_no_freq_specified(self):
self.sys_inst.set_system_boot_options(
target=sushy.BOOT_SOURCE_TARGET_PXE,
mode=sushy.BOOT_SOURCE_MODE_UEFI)
target=sushy.BootSource.PXE,
mode=sushy.BootSourceOverrideMode.UEFI)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'Boot': {'BootSourceOverrideTarget': 'Pxe',
@@ -325,10 +325,10 @@ class SystemTestCase(base.TestCase):
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'"enabled" value.*{0}'.format(
list(sys_map.BOOT_SOURCE_ENABLED_MAP_REV))):
list(sushy.BootSourceOverrideEnabled))):
self.sys_inst.set_system_boot_options(
sushy.BOOT_SOURCE_TARGET_HDD,
sushy.BootSource.HDD,
enabled='invalid-enabled')
def test_set_system_boot_options_supermicro_usb_cd_boot(self):
@@ -338,8 +338,8 @@ class SystemTestCase(base.TestCase):
self.sys_inst.manufacturer = "supermicro"
self.sys_inst.set_system_boot_options(
target=sushy.BOOT_SOURCE_TARGET_CD,
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
target=sushy.BootSource.CD,
enabled=sushy.BootSourceOverrideEnabled.ONCE)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
@@ -350,8 +350,8 @@ class SystemTestCase(base.TestCase):
self.sys_inst.manufacturer = "supermicro"
self.sys_inst.set_system_boot_options(
target=sushy.BOOT_SOURCE_TARGET_CD,
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
target=sushy.BootSource.CD,
enabled=sushy.BootSourceOverrideEnabled.ONCE)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
@@ -360,9 +360,9 @@ class SystemTestCase(base.TestCase):
def test_set_system_boot_source(self):
self.sys_inst.set_system_boot_source(
sushy.BOOT_SOURCE_TARGET_PXE,
enabled=sushy.BOOT_SOURCE_ENABLED_CONTINUOUS,
mode=sushy.BOOT_SOURCE_MODE_UEFI)
sushy.BootSource.PXE,
enabled=sushy.BootSourceOverrideEnabled.CONTINUOUS,
mode=sushy.BootSourceOverrideMode.UEFI)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'Boot': {'BootSourceOverrideEnabled': 'Continuous',
@@ -371,8 +371,8 @@ class SystemTestCase(base.TestCase):
def test_set_system_boot_source_no_mode_specified(self):
self.sys_inst.set_system_boot_source(
sushy.BOOT_SOURCE_TARGET_HDD,
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
sushy.BootSource.HDD,
enabled=sushy.BootSourceOverrideEnabled.ONCE)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'Boot': {'BootSourceOverrideEnabled': 'Once',
@@ -387,10 +387,10 @@ class SystemTestCase(base.TestCase):
with self.assertRaisesRegex(
exceptions.InvalidParameterValueError,
'"enabled" value.*{0}'.format(
list(sys_map.BOOT_SOURCE_ENABLED_MAP_REV))):
list(sushy.BootSourceOverrideEnabled))):
self.sys_inst.set_system_boot_source(
sushy.BOOT_SOURCE_TARGET_HDD,
sushy.BootSource.HDD,
enabled='invalid-enabled')
def test_set_indicator_led(self):
@@ -515,10 +515,10 @@ class SystemTestCase(base.TestCase):
# | WHEN |
actual_processor_summary = self.sys_inst.processors.summary
# | THEN |
self.assertEqual((16, sushy.PROCESSOR_ARCH_x86),
self.assertEqual((16, sushy.ProcessorArchitecture.X86),
actual_processor_summary)
self.assertEqual(16, actual_processor_summary.count)
self.assertEqual(sushy.PROCESSOR_ARCH_x86,
self.assertEqual(sushy.ProcessorArchitecture.X86,
actual_processor_summary.architecture)
# reset mock