mbligh | 313b926 | 2009-09-03 20:49:54 +0000 | [diff] [blame] | 1 | import logging |
mbligh | f957fe2 | 2009-05-12 20:51:56 +0000 | [diff] [blame] | 2 | from autotest_lib.client.common_lib import enum, global_config |
showard | df06256 | 2008-07-03 19:56:37 +0000 | [diff] [blame] | 3 | |
mbligh | 3f033d5 | 2009-04-01 18:36:08 +0000 | [diff] [blame] | 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 | |
mbligh | b024fb1 | 2008-07-11 21:24:21 +0000 | [diff] [blame] | 13 | Protection = enum.Enum('No protection', # Repair can do anything to |
| 14 | # this host. |
mbligh | 25c0b8c | 2009-01-24 01:44:17 +0000 | [diff] [blame] | 15 | 'Repair software only', # repair should try to fix any |
| 16 | # software problem |
mbligh | b024fb1 | 2008-07-11 21:24:21 +0000 | [diff] [blame] | 17 | 'Repair filesystem only', # Repair should only try to |
| 18 | # recover the file system. |
showard | c9ae178 | 2009-01-30 01:42:37 +0000 | [diff] [blame] | 19 | 'Do not repair', # Repair should not touch this |
mbligh | b024fb1 | 2008-07-11 21:24:21 +0000 | [diff] [blame] | 20 | # host. |
showard | c9ae178 | 2009-01-30 01:42:37 +0000 | [diff] [blame] | 21 | 'Do not verify', # Don't even try to verify |
| 22 | # this host |
showard | df06256 | 2008-07-03 19:56:37 +0000 | [diff] [blame] | 23 | ) |
| 24 | |
lmr | 6d08b3c | 2009-11-18 19:26:38 +0000 | [diff] [blame] | 25 | running_client = global_config.global_config.check_stand_alone_client_run() |
| 26 | |
mbligh | 313b926 | 2009-09-03 20:49:54 +0000 | [diff] [blame] | 27 | try: |
| 28 | _bad_value = object() |
lmr | 6d08b3c | 2009-11-18 19:26:38 +0000 | [diff] [blame] | 29 | default_protection = global_config.global_config.get_config_value( |
| 30 | 'HOSTS', 'default_protection', default=_bad_value) |
| 31 | if default_protection == _bad_value: |
lmr | da8fb97 | 2009-12-01 22:49:08 +0000 | [diff] [blame] | 32 | if not running_client: |
lmr | 6d08b3c | 2009-11-18 19:26:38 +0000 | [diff] [blame] | 33 | raise global_config.ConfigError( |
| 34 | 'No HOSTS.default_protection defined in global_config.ini') |
| 35 | else: |
| 36 | default = Protection.get_value(default_protection) |
| 37 | |
lmr | da8fb97 | 2009-12-01 22:49:08 +0000 | [diff] [blame] | 38 | # It is OK to have an empty global configuration object (stand alone client) |
| 39 | # so we trap this exception. |
mbligh | 313b926 | 2009-09-03 20:49:54 +0000 | [diff] [blame] | 40 | except global_config.ConfigError: |
lmr | da8fb97 | 2009-12-01 22:49:08 +0000 | [diff] [blame] | 41 | pass |
showard | df06256 | 2008-07-03 19:56:37 +0000 | [diff] [blame] | 42 | |
| 43 | choices = Protection.choices() |