xref: /aosp_15_r20/external/autotest/client/common_lib/host_protections.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1*9c5db199SXin Liimport logging
2*9c5db199SXin Lifrom autotest_lib.client.common_lib import autotest_enum, global_config
3*9c5db199SXin Li
4*9c5db199SXin Li# Changing this file has consequences that need to be understood.
5*9c5db199SXin Li# Adding a protection level to the enum requires you to append your change to
6*9c5db199SXin Li# the end of the enum or a database migration needs to be added to migrate
7*9c5db199SXin Li# older protections to match the layout of the new enum.
8*9c5db199SXin Li# Removing a protection level from the enum requires a database migration to
9*9c5db199SXin Li# update the integer values in the DB and migrate hosts that use the removed
10*9c5db199SXin Li# protection to a default protection level.
11*9c5db199SXin Li# IF THIS IS NOT DONE HOSTS' PROTECTION LEVELS WILL BE CHANGED RANDOMLY.
12*9c5db199SXin Li
13*9c5db199SXin LiProtection = autotest_enum.AutotestEnum(
14*9c5db199SXin Li                       'No protection',          # Repair can do anything to
15*9c5db199SXin Li                                                 # this host.
16*9c5db199SXin Li                       'Repair software only',   # repair should try to fix any
17*9c5db199SXin Li                                                 # software problem
18*9c5db199SXin Li                       'Repair filesystem only', # Repair should only try to
19*9c5db199SXin Li                                                 # recover the file system.
20*9c5db199SXin Li                       'Do not repair',          # Repair should not touch this
21*9c5db199SXin Li                                                 # host.
22*9c5db199SXin Li                       'Do not verify',          # Don't even try to verify
23*9c5db199SXin Li                                                 # this host
24*9c5db199SXin Li                       )
25*9c5db199SXin Li
26*9c5db199SXin Lirunning_client = global_config.global_config.check_stand_alone_client_run()
27*9c5db199SXin Li
28*9c5db199SXin Litry:
29*9c5db199SXin Li    _bad_value = object()
30*9c5db199SXin Li    default_protection = global_config.global_config.get_config_value(
31*9c5db199SXin Li                            'HOSTS', 'default_protection', default=_bad_value)
32*9c5db199SXin Li    if default_protection == _bad_value:
33*9c5db199SXin Li        if not running_client:
34*9c5db199SXin Li            raise global_config.ConfigError(
35*9c5db199SXin Li                'No HOSTS.default_protection defined in global_config.ini')
36*9c5db199SXin Li    else:
37*9c5db199SXin Li        default = Protection.get_value(default_protection)
38*9c5db199SXin Li
39*9c5db199SXin Li# It is OK to have an empty global configuration object (stand alone client)
40*9c5db199SXin Li# so we trap this exception.
41*9c5db199SXin Liexcept global_config.ConfigError:
42*9c5db199SXin Li    pass
43*9c5db199SXin Li
44*9c5db199SXin Lichoices = Protection.choices()
45