Merge "Migrate System Storage constants to enums"

This commit is contained in:
Zuul
2021-11-24 07:38:30 +00:00
committed by Gerrit Code Review
6 changed files with 150 additions and 156 deletions

View File

@@ -10,108 +10,158 @@
# License for the specific language governing permissions and limitations
# under the License.
# Volume Initialization Types
VOLUME_INIT_TYPE_FAST = 'fast'
"""The volume is prepared for use quickly, typically by erasing just the
beginning and end of the space so that partitioning can be performed."""
# From http://redfish.dmtf.org/schemas/swordfish/v1/Volume.json
VOLUME_INIT_TYPE_SLOW = 'slow'
"""The volume is prepared for use slowly, typically by completely erasing
the volume."""
import enum
# VolumeType Types
VOLUME_TYPE_RAW_DEVICE = 'rawdevice'
"""The volume is a raw physical device without any RAID or other
virtualization applied."""
VOLUME_TYPE_NON_REDUNDANT = 'nonredundant'
"""The volume is a non-redundant storage device."""
# FIXME(dtantsur): this is deprecated in favour of InitializeMethod
class VolumeInitializeType(enum.Enum):
FAST = 'Fast'
"""The volume is prepared for use quickly, typically by erasing just the
beginning and end of the space so that partitioning can be performed."""
VOLUME_TYPE_MIRRORED = 'mirrored'
"""The volume is a mirrored device."""
SLOW = 'Slow'
"""The volume is prepared for use slowly, typically by completely
erasing the volume."""
VOLUME_TYPE_STRIPED_WITH_PARITY = 'stripedwithparity'
"""The volume is a device which uses parity to retain redundant information."""
VOLUME_TYPE_SPANNED_MIRRORS = 'spannedmirrors'
"""The volume is a spanned set of mirrored devices."""
# Backward compatibility
VOLUME_INIT_TYPE_FAST = VolumeInitializeType.FAST
VOLUME_INIT_TYPE_SLOW = VolumeInitializeType.SLOW
VOLUME_TYPE_SPANNED_STRIPES_WITH_PARITY = 'spannedstripeswithparity'
"""The volume is a spanned set of devices which uses parity to retain
redundant information."""
# RAIDType Types
RAID_TYPE_RAID0 = 'RAID0'
"""A placement policy where consecutive logical blocks of data are uniformly
distributed across a set of independent storage devices without offering any
form of redundancy."""
class VolumeType(enum.Enum):
RAW_DEVICE = 'RawDevice'
"""The volume is a raw physical device without any RAID or other
virtualization applied."""
RAID_TYPE_RAID1 = 'RAID1'
"""A placement policy where each logical block of data is stored on more than
one independent storage device."""
NON_REDUNDANT = 'NonRedundant'
"""The volume is a non-redundant storage device."""
RAID_TYPE_RAID3 = 'RAID3'
"""A placement policy using parity-based protection where logical bytes of
data are uniformly distributed across a set of independent storage devices and
where the parity is stored on a dedicated independent storage device."""
MIRRORED = 'Mirrored'
"""The volume is a mirrored device."""
RAID_TYPE_RAID4 = 'RAID4'
"""A placement policy using parity-based protection where logical blocks of
data are uniformly distributed across a set of independent storage devices and
where the parity is stored on a dedicated independent storage device."""
STRIPED_WITH_PARITY = 'StripedWithParity'
"""The volume is a device which uses parity to retain redundant
information."""
RAID_TYPE_RAID5 = 'RAID5'
"""A placement policy using parity-based protection for storing stripes of 'n'
logical blocks of data and one logical block of parity across a set of 'n+1'
independent storage devices where the parity and data blocks are interleaved
across the storage devices."""
SPANNED_MIRRORS = 'SpannedMirrors'
"""The volume is a spanned set of mirrored devices."""
RAID_TYPE_RAID6 = 'RAID6'
"""A placement policy using parity-based protection for storing stripes of 'n'
logical blocks of data and two logical blocks of independent parity across a
set of 'n+2' independent storage devices where the parity and data blocks are
interleaved across the storage devices."""
SPANNED_STRIPES_WITH_PARITY = 'SpannedStripesWithParity'
"""The volume is a spanned set of devices which uses parity to retain
redundant information."""
RAID_TYPE_RAID10 = 'RAID10'
"""A placement policy that creates a striped device (RAID 0) over a set of
mirrored devices (RAID 1)."""
RAID_TYPE_RAID01 = 'RAID01'
"""A data placement policy that creates a mirrored device (RAID 1) over a set
of striped devices (RAID 0)."""
# Backward compatibility
VOLUME_TYPE_RAW_DEVICE = VolumeType.RAW_DEVICE
VOLUME_TYPE_NON_REDUNDANT = VolumeType.NON_REDUNDANT
VOLUME_TYPE_MIRRORED = VolumeType.MIRRORED
VOLUME_TYPE_STRIPED_WITH_PARITY = VolumeType.STRIPED_WITH_PARITY
VOLUME_TYPE_SPANNED_MIRRORS = VolumeType.SPANNED_MIRRORS
VOLUME_TYPE_SPANNED_STRIPES_WITH_PARITY = \
VolumeType.SPANNED_STRIPES_WITH_PARITY
RAID_TYPE_RAID6TP = 'RAID6TP'
"""A placement policy that uses parity-based protection for storing stripes of
'n' logical blocks of data and three logical blocks of independent parity
across a set of 'n+3' independent storage devices where the parity and data
blocks are interleaved across the storage devices."""
RAID_TYPE_RAID1E = 'RAID1E'
"""A placement policy that uses a form of mirroring implemented over a set of
independent storage devices where logical blocks are duplicated on a pair of
independent storage devices so that data is uniformly distributed across the
storage devices."""
class RAIDType(enum.Enum):
RAID0 = 'RAID0'
"""A placement policy where consecutive logical blocks of data are
uniformly distributed across a set of independent storage devices
without offering any form of redundancy."""
RAID_TYPE_RAID50 = 'RAID50'
"""A placement policy that uses a RAID 0 stripe set over two or more RAID 5
sets of independent storage devices."""
RAID1 = 'RAID1'
"""A placement policy where each logical block of data is stored on more
than one independent storage device."""
RAID_TYPE_RAID60 = 'RAID60'
"""A placement policy that uses a RAID 0 stripe set over two or more RAID 6
sets of independent storage devices."""
RAID3 = 'RAID3'
"""A placement policy using parity-based protection where logical bytes
of data are uniformly distributed across a set of independent storage
devices and where the parity is stored on a dedicated independent
storage device."""
RAID_TYPE_RAID00 = 'RAID00'
"""A placement policy that creates a RAID 0 stripe set over two or more RAID 0
sets."""
RAID4 = 'RAID4'
"""A placement policy using parity-based protection where logical blocks
of data are uniformly distributed across a set of independent storage
devices and where the parity is stored on a dedicated independent
storage device."""
RAID_TYPE_RAID10E = 'RAID10E'
"""A placement policy that uses a RAID 0 stripe set over two or more RAID 10
sets."""
RAID5 = 'RAID5'
"""A placement policy using parity-based protection for storing stripes
of 'n' logical blocks of data and one logical block of parity across
a set of 'n+1' independent storage devices where the parity and data
blocks are interleaved across the storage devices."""
RAID_TYPE_RAID1Triple = 'RAID1Triple'
"""A placement policy where each logical block of data is mirrored three times
across a set of three independent storage devices."""
RAID6 = 'RAID6'
"""A placement policy using parity-based protection for storing stripes
of 'n' logical blocks of data and two logical blocks of independent
parity across a set of 'n+2' independent storage devices where the
parity and data blocks are interleaved across the storage devices."""
RAID_TYPE_RAID10Triple = 'RAID10Triple'
"""A placement policy that uses a striped device (RAID 0) over a set of triple
mirrored devices (RAID 1Triple)."""
RAID10 = 'RAID10'
"""A placement policy that creates a striped device (RAID 0) over a set
of mirrored devices (RAID 1)."""
RAID01 = 'RAID01'
"""A data placement policy that creates a mirrored device (RAID 1) over
a set of striped devices (RAID 0)."""
RAID6TP = 'RAID6TP'
"""A placement policy that uses parity-based protection for storing
stripes of 'n' logical blocks of data and three logical blocks of
independent parity across a set of 'n+3' independent storage devices
where the parity and data blocks are interleaved across the storage
devices."""
RAID1E = 'RAID1E'
"""A placement policy that uses a form of mirroring implemented over a
set of independent storage devices where logical blocks are
duplicated on a pair of independent storage devices so that data is
uniformly distributed across the storage devices."""
RAID50 = 'RAID50'
"""A placement policy that uses a RAID 0 stripe set over two or more
RAID 5 sets of independent storage devices."""
RAID60 = 'RAID60'
"""A placement policy that uses a RAID 0 stripe set over two or more
RAID 6 sets of independent storage devices."""
RAID00 = 'RAID00'
"""A placement policy that creates a RAID 0 stripe set over two or more
RAID 0 sets."""
RAID10E = 'RAID10E'
"""A placement policy that uses a RAID 0 stripe set over two or more
RAID 10 sets."""
RAID1_TRIPLE = 'RAID1Triple'
"""A placement policy where each logical block of data is mirrored three
times across a set of three independent storage devices."""
RAID10_TRIPLE = 'RAID10Triple'
"""A placement policy that uses a striped device (RAID 0) over a set of
triple mirrored devices (RAID 1Triple)."""
NONE = 'None'
"""A placement policy with no redundancy at the device level."""
# Backward compatibility
RAID_TYPE_RAID0 = RAIDType.RAID0
RAID_TYPE_RAID1 = RAIDType.RAID1
RAID_TYPE_RAID3 = RAIDType.RAID3
RAID_TYPE_RAID4 = RAIDType.RAID4
RAID_TYPE_RAID5 = RAIDType.RAID5
RAID_TYPE_RAID6 = RAIDType.RAID6
RAID_TYPE_RAID10 = RAIDType.RAID10
RAID_TYPE_RAID01 = RAIDType.RAID01
RAID_TYPE_RAID6TP = RAIDType.RAID6TP
RAID_TYPE_RAID1E = RAIDType.RAID1E
RAID_TYPE_RAID50 = RAIDType.RAID50
RAID_TYPE_RAID60 = RAIDType.RAID60
RAID_TYPE_RAID00 = RAIDType.RAID00
RAID_TYPE_RAID10E = RAIDType.RAID10E
RAID_TYPE_RAID1Triple = RAIDType.RAID1_TRIPLE
RAID_TYPE_RAID10Triple = RAIDType.RAID10_TRIPLE
RAID_TYPE_NONE = RAIDType.NONE

View File

@@ -1,52 +0,0 @@
# 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.storage import constants as store_cons
from sushy import utils
VOLUME_INIT_TYPE_MAP = {
'Fast': store_cons.VOLUME_INIT_TYPE_FAST,
'Slow': store_cons.VOLUME_INIT_TYPE_SLOW
}
VOLUME_INIT_TYPE_MAP_REV = (
utils.revert_dictionary(VOLUME_INIT_TYPE_MAP)
)
VOLUME_TYPE_TYPE_MAP = {
'RawDevice': store_cons.VOLUME_TYPE_RAW_DEVICE,
'NonRedundant': store_cons.VOLUME_TYPE_NON_REDUNDANT,
'Mirrored': store_cons.VOLUME_TYPE_MIRRORED,
'StripedWithParity': store_cons.VOLUME_TYPE_STRIPED_WITH_PARITY,
'SpannedMirrors': store_cons.VOLUME_TYPE_SPANNED_MIRRORS,
'SpannedStripesWithParity':
store_cons.VOLUME_TYPE_SPANNED_STRIPES_WITH_PARITY
}
RAID_TYPE_TYPE_MAP = {
'RAID0': store_cons.RAID_TYPE_RAID0,
'RAID1': store_cons.RAID_TYPE_RAID1,
'RAID3': store_cons.RAID_TYPE_RAID3,
'RAID4': store_cons.RAID_TYPE_RAID4,
'RAID5': store_cons.RAID_TYPE_RAID5,
'RAID6': store_cons.RAID_TYPE_RAID6,
'RAID10': store_cons.RAID_TYPE_RAID10,
'RAID01': store_cons.RAID_TYPE_RAID01,
'RAID6TP': store_cons.RAID_TYPE_RAID6TP,
'RAID1E': store_cons.RAID_TYPE_RAID1E,
'RAID50': store_cons.RAID_TYPE_RAID50,
'RAID60': store_cons.RAID_TYPE_RAID60,
'RAID00': store_cons.RAID_TYPE_RAID00,
'RAID10E': store_cons.RAID_TYPE_RAID10E,
'RAID1Triple': store_cons.RAID_TYPE_RAID1Triple,
'RAID10Triple': store_cons.RAID_TYPE_RAID10Triple,
}

View File

@@ -18,8 +18,8 @@ import logging
from sushy.resources import base
from sushy.resources import common
from sushy.resources import constants as res_cons
from sushy.resources.system.storage import constants
from sushy.resources.system.storage import drive
from sushy.resources.system.storage import mappings
from sushy.resources.system.storage import volume
from sushy import utils
@@ -53,8 +53,7 @@ class StorageControllersListField(base.ListField):
res_cons.Protocol)
"""The protocols which the controller can use tocommunicate with devices"""
raid_types = base.MappedListField('SupportedRAIDTypes',
mappings.RAID_TYPE_TYPE_MAP)
raid_types = base.MappedListField('SupportedRAIDTypes', constants.RAIDType)
"""The set of RAID types supported by the storage controller."""

View File

@@ -20,7 +20,6 @@ from sushy.resources import base
from sushy.resources import common
from sushy.resources import constants as res_cons
from sushy.resources.system.storage import constants as store_cons
from sushy.resources.system.storage import mappings as store_maps
from sushy.taskmonitor import TaskMonitor
from sushy import utils
@@ -45,11 +44,10 @@ class Volume(base.ResourceBase):
capacity_bytes = base.Field('CapacityBytes', adapter=utils.int_or_none)
"""The size in bytes of this Volume."""
volume_type = base.MappedField('VolumeType',
store_maps.VOLUME_TYPE_TYPE_MAP)
volume_type = base.MappedField('VolumeType', store_cons.VolumeType)
"""The type of this volume."""
raid_type = base.MappedField('RAIDType', store_maps.RAID_TYPE_TYPE_MAP)
raid_type = base.MappedField('RAIDType', store_cons.RAIDType)
"""The RAID type of this volume."""
encrypted = base.Field('Encrypted', adapter=bool)
@@ -85,20 +83,19 @@ class Volume(base.ResourceBase):
LOG.warning('Could not figure out the allowed values for the '
'initialize volume action for Volume %s',
self.identity)
return set(store_maps.VOLUME_INIT_TYPE_MAP_REV)
return set(store_cons.VolumeInitializeType)
return set([store_maps.VOLUME_INIT_TYPE_MAP[v] for v in
set(store_maps.VOLUME_INIT_TYPE_MAP).
intersection(action.allowed_values)])
return {v for v in store_cons.VolumeInitializeType
if v.value in action.allowed_values}
def _initialize(self, value=store_cons.VOLUME_INIT_TYPE_FAST,
def _initialize(self, value=store_cons.VolumeInitializeType.FAST,
apply_time=None, timeout=500):
valid_values = self.get_allowed_initialize_volume_values()
value = store_cons.VolumeInitializeType(value)
if value not in valid_values:
raise exceptions.InvalidParameterValueError(
parameter='value', value=value, valid_values=valid_values)
value = store_maps.VOLUME_INIT_TYPE_MAP_REV[value]
payload = {'InitializeType': value}
payload = {'InitializeType': value.value}
blocking = False
if apply_time:
payload[_OAT_PROP] = res_cons.ApplyTime(apply_time).value
@@ -110,7 +107,7 @@ class Volume(base.ResourceBase):
timeout=timeout)
return r, target_uri
def initialize(self, value=store_cons.VOLUME_INIT_TYPE_FAST,
def initialize(self, value=store_cons.VolumeInitializeType.FAST,
apply_time=None, timeout=500):
"""Initialize the volume.

View File

@@ -133,7 +133,7 @@ class StorageTestCase(base.TestCase):
controller.controller_protocols)
self.assertEqual([sushy.Protocol.SAS, sushy.Protocol.SATA],
controller.device_protocols)
self.assertEqual([sushy.RAID_TYPE_RAID0, sushy.RAID_TYPE_RAID1],
self.assertEqual([sushy.RAIDType.RAID0, sushy.RAIDType.RAID1],
controller.raid_types)
def test_drives_after_refresh(self):

View File

@@ -43,7 +43,7 @@ class VolumeTestCase(base.TestCase):
self.assertEqual('1', self.stor_volume.identity)
self.assertEqual('Virtual Disk 1', self.stor_volume.name)
self.assertEqual(899527000000, self.stor_volume.capacity_bytes)
self.assertEqual(sushy.VOLUME_TYPE_MIRRORED,
self.assertEqual(sushy.VolumeType.MIRRORED,
self.stor_volume.volume_type)
self.assertFalse(self.stor_volume.encrypted)
identifiers = self.stor_volume.identifiers
@@ -60,7 +60,7 @@ class VolumeTestCase(base.TestCase):
target_uri = '/redfish/v1/Systems/3/Storage/RAIDIntegrated/' \
'Volumes/1/Actions/Volume.Initialize'
self.stor_volume.initialize(
store_cons.VOLUME_INIT_TYPE_FAST,
store_cons.VolumeInitializeType.FAST,
apply_time=res_cons.ApplyTime.IMMEDIATE)
self.stor_volume._conn.post.assert_called_once_with(
target_uri, data={'InitializeType': 'Fast',
@@ -71,10 +71,10 @@ class VolumeTestCase(base.TestCase):
target_uri = '/redfish/v1/Systems/3/Storage/RAIDIntegrated/' \
'Volumes/1/Actions/Volume.Initialize'
self.stor_volume.initialize(
store_cons.VOLUME_INIT_TYPE_FAST,
store_cons.VolumeInitializeType.SLOW,
apply_time=res_cons.ApplyTime.ON_RESET)
self.stor_volume._conn.post.assert_called_once_with(
target_uri, data={'InitializeType': 'Fast',
target_uri, data={'InitializeType': 'Slow',
'@Redfish.OperationApplyTime': 'OnReset'},
blocking=False, timeout=500)
@@ -236,8 +236,8 @@ class VolumeCollectionTestCase(base.TestCase):
self.assertEqual('4', new_vol.identity)
self.assertEqual('My Volume 4', new_vol.name)
self.assertEqual(107374182400, new_vol.capacity_bytes)
self.assertEqual(sushy.VOLUME_TYPE_MIRRORED, new_vol.volume_type)
self.assertEqual(sushy.RAID_TYPE_RAID1, new_vol.raid_type)
self.assertEqual(sushy.VolumeType.MIRRORED, new_vol.volume_type)
self.assertEqual(sushy.RAIDType.RAID1, new_vol.raid_type)
def test_create_on_reset(self):
payload = {