1import logging 2from autotest_lib.client.common_lib import autotest_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 = autotest_enum.AutotestEnum( 14 'No protection', # Repair can do anything to 15 # this host. 16 'Repair software only', # repair should try to fix any 17 # software problem 18 'Repair filesystem only', # Repair should only try to 19 # recover the file system. 20 'Do not repair', # Repair should not touch this 21 # host. 22 'Do not verify', # Don't even try to verify 23 # this host 24 ) 25 26running_client = global_config.global_config.check_stand_alone_client_run() 27 28try: 29 _bad_value = object() 30 default_protection = global_config.global_config.get_config_value( 31 'HOSTS', 'default_protection', default=_bad_value) 32 if default_protection == _bad_value: 33 if not running_client: 34 raise global_config.ConfigError( 35 'No HOSTS.default_protection defined in global_config.ini') 36 else: 37 default = Protection.get_value(default_protection) 38 39# It is OK to have an empty global configuration object (stand alone client) 40# so we trap this exception. 41except global_config.ConfigError: 42 pass 43 44choices = Protection.choices() 45