host_protections.py revision 313b9266da8da08299d3786e1023f14023c82906
1import logging 2from autotest_lib.client.common_lib import enum, global_config 3 4# Changing this file has consequences that need to be understood. 5# Adding a protection level to the enum requires you to append your change to 6# the end of the enum or a database migration needs to be added to migrate 7# older protections to match the layout of the new enum. 8# Removing a protection level from the enum requires a database migration to 9# update the integer values in the DB and migrate hosts that use the removed 10# protection to a default protection level. 11# IF THIS IS NOT DONE HOSTS' PROTECTION LEVELS WILL BE CHANGED RANDOMLY. 12 13Protection = enum.Enum('No protection', # Repair can do anything to 14 # this host. 15 'Repair software only', # repair should try to fix any 16 # software problem 17 'Repair filesystem only', # Repair should only try to 18 # recover the file system. 19 'Do not repair', # Repair should not touch this 20 # host. 21 'Do not verify', # Don't even try to verify 22 # this host 23 ) 24 25try: 26 _bad_value = object() 27 default = Protection.get_value( 28 global_config.global_config.get_config_value( 29 'HOSTS', 'default_protection', default=_bad_value)) 30 if default == _bad_value: 31 raise global_config.ConfigError( 32 'No HOSTS.default_protection defined in global_config.ini') 33except global_config.ConfigError: 34 # can happen if no global_config.ini exists at all, but this can actually 35 # happen in reasonable cases (e.g. on a standalone clinet) where it's 36 # safe to ignore 37 logging.debug('No global_config.ini exists so host_protection.default ' 38 'will not be defined') 39 40choices = Protection.choices() 41