<s> import json <EOL> from ironic . common import exception <EOL> from ironic . common import raid <EOL> from ironic . drivers import base as drivers_base <EOL> from ironic . tests import base <EOL> from ironic . tests . unit . db import base as db_base <EOL> from ironic . tests . unit . objects import utils as obj_utils <EOL> from ironic . tests . unit import raid_constants <EOL> class ValidateRaidConfigurationTestCase ( base . TestCase ) : <EOL> def setUp ( self ) : <EOL> with open ( drivers_base . RAID_CONFIG_SCHEMA , '<STR_LIT:r>' ) as raid_schema_fobj : <EOL> self . schema = json . load ( raid_schema_fobj ) <EOL> super ( ValidateRaidConfigurationTestCase , self ) . setUp ( ) <EOL> def test_validate_configuration_okay ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_OKAY ) <EOL> raid . validate_configuration ( <EOL> raid_config , raid_config_schema = self . schema ) <EOL> def test_validate_configuration_no_logical_disk ( self ) : <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> { } , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_zero_logical_disks ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_NO_LOGICAL_DISKS ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_no_raid_level ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_NO_RAID_LEVEL ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_raid_level ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_INVALID_RAID_LEVEL ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_no_size_gb ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_NO_SIZE_GB ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_max_size_gb ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_MAX_SIZE_GB ) <EOL> raid . validate_configuration ( raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_size_gb ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_INVALID_SIZE_GB ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_is_root_volume ( self ) : <EOL> raid_config_str = raid_constants . RAID_CONFIG_INVALID_IS_ROOT_VOL <EOL> raid_config = json . loads ( raid_config_str ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_multiple_is_root_volume ( self ) : <EOL> raid_config_str = raid_constants . RAID_CONFIG_MULTIPLE_IS_ROOT_VOL <EOL> raid_config = json . loads ( raid_config_str ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_share_physical_disks ( self ) : <EOL> raid_config_str = raid_constants . RAID_CONFIG_INVALID_SHARE_PHY_DISKS <EOL> raid_config = json . loads ( raid_config_str ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_disk_type ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_INVALID_DISK_TYPE ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_int_type ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_INVALID_INT_TYPE ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_number_of_phy_disks ( self ) : <EOL> raid_config_str = raid_constants . RAID_CONFIG_INVALID_NUM_PHY_DISKS <EOL> raid_config = json . loads ( raid_config_str ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_invalid_physical_disks ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_INVALID_PHY_DISKS ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_additional_property ( self ) : <EOL> raid_config = json . loads ( raid_constants . RAID_CONFIG_ADDITIONAL_PROP ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> raid . validate_configuration , <EOL> raid_config , <EOL> raid_config_schema = self . schema ) <EOL> def test_validate_configuration_custom_schema ( self ) : <EOL> raid_config = json . loads ( raid_constants . CUSTOM_SCHEMA_RAID_CONFIG ) <EOL> schema = json . loads ( raid_constants . CUSTOM_RAID_SCHEMA ) <EOL> raid . validate_configuration ( raid_config , <EOL> raid_config_schema = schema ) <EOL> class RaidPublicMethodsTestCase ( db_base . DbTestCase ) : <EOL> def test_get_logical_disk_properties ( self ) : <EOL> with open ( drivers_base . RAID_CONFIG_SCHEMA , '<STR_LIT:r>' ) as raid_schema_fobj : <EOL> schema = json . load ( raid_schema_fobj ) <EOL> logical_disk_properties = raid . get_logical_disk_properties ( schema ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> def test_get_logical_disk_properties_custom_schema ( self ) : <EOL> raid_schema = json . loads ( raid_constants . CUSTOM_RAID_SCHEMA ) <EOL> logical_disk_properties = raid . get_logical_disk_properties ( <EOL> raid_config_schema = raid_schema ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT>' , logical_disk_properties ) <EOL> self . assertIn ( '<STR_LIT:foo>' , logical_disk_properties ) <EOL> def _test_update_raid_info ( self , current_config , <EOL> capabilities = None ) : <EOL> node = obj_utils . create_test_node ( self . context , <EOL> driver = '<STR_LIT>' ) <EOL> if capabilities : <EOL> properties = node . properties <EOL> properties [ '<STR_LIT>' ] = capabilities <EOL> del properties [ '<STR_LIT>' ] <EOL> node . properties = properties <EOL> target_raid_config = json . loads ( raid_constants . RAID_CONFIG_OKAY ) <EOL> node . target_raid_config = target_raid_config <EOL> node . save ( ) <EOL> raid . update_raid_info ( node , current_config ) <EOL> properties = node . properties <EOL> current = node . raid_config <EOL> target = node . target_raid_config <EOL> self . assertIsNotNone ( current [ '<STR_LIT>' ] ) <EOL> self . assertIsInstance ( current [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , dict ) <EOL> if current_config [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . get ( '<STR_LIT>' ) : <EOL> self . assertEqual ( { '<STR_LIT>' : '<STR_LIT>' } , <EOL> properties [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:100> , properties [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , properties [ '<STR_LIT>' ] ) <EOL> if capabilities : <EOL> self . assertIn ( capabilities , properties [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . assertNotIn ( '<STR_LIT>' , properties ) <EOL> self . assertNotIn ( '<STR_LIT>' , properties ) <EOL> if capabilities : <EOL> self . assertNotIn ( '<STR_LIT>' , properties [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( target_raid_config , target ) <EOL> def test_update_raid_info_okay ( self ) : <EOL> current_config = json . loads ( raid_constants . CURRENT_RAID_CONFIG ) <EOL> self . _test_update_raid_info ( current_config , <EOL> capabilities = '<STR_LIT>' ) <EOL> def test_update_raid_info_okay_no_root_volumes ( self ) : <EOL> current_config = json . loads ( raid_constants . CURRENT_RAID_CONFIG ) <EOL> del current_config [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> del current_config [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> self . _test_update_raid_info ( current_config , <EOL> capabilities = '<STR_LIT>' ) <EOL> def test_update_raid_info_okay_current_capabilities_empty ( self ) : <EOL> current_config = json . loads ( raid_constants . CURRENT_RAID_CONFIG ) <EOL> self . _test_update_raid_info ( current_config , <EOL> capabilities = None ) <EOL> def test_update_raid_info_multiple_root_volumes ( self ) : <EOL> current_config = json . loads ( raid_constants . RAID_CONFIG_MULTIPLE_ROOT ) <EOL> self . assertRaises ( exception . InvalidParameterValue , <EOL> self . _test_update_raid_info , <EOL> current_config ) </s>
