| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging, os, utils | 5 import logging, os, utils |
| 6 | 6 |
| 7 # Host attributes are specified a strings with the format: | 7 # Host attributes are specified a strings with the format: |
| 8 # <key>{,<value>}? | 8 # <key>{,<value>}? |
| 9 # | 9 # |
| 10 # A machine may have a list of strings for attributes like: | 10 # A machine may have a list of strings for attributes like: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 # host_attributes.unknown_attribute => raise KeyError | 28 # host_attributes.unknown_attribute => raise KeyError |
| 29 # | 29 # |
| 30 # Machine attributes can be specified in two ways. | 30 # Machine attributes can be specified in two ways. |
| 31 # | 31 # |
| 32 # If you create private_host_attributes_config.py and | 32 # If you create private_host_attributes_config.py and |
| 33 # private_host_attributes there, we will use it when possible instead of | 33 # private_host_attributes there, we will use it when possible instead of |
| 34 # using the server front-end. | 34 # using the server front-end. |
| 35 # | 35 # |
| 36 # Example configuration: | 36 # Example configuration: |
| 37 # private_host_attributes = { | 37 # private_host_attributes = { |
| 38 # "myserver": ["has_80211n,True", | 38 # "mydevice": ["has_80211n,True", |
| 39 # "has_resume_bug,False"] | 39 # "has_resume_bug,False"] |
| 40 # } | 40 # } |
| 41 # | 41 # |
| 42 # We also consult the AFE database for its labels which are all treated | 42 # We also consult the AFE database for its labels which are all treated |
| 43 # as host attribute strings defined above. Illegal strings are ignored. | 43 # as host attribute strings defined above. Illegal strings are ignored. |
| 44 # | 44 # |
| 45 | 45 |
| 46 private_host_attributes = utils.import_site_symbol( | 46 private_host_attributes = utils.import_site_symbol( |
| 47 __file__, | 47 __file__, |
| 48 'autotest_lib.server.private_host_attributes_config', | 48 'autotest_lib.server.private_host_attributes_config', |
| 49 'private_host_attributes', dummy={}) | 49 'private_host_attributes', dummy={}) |
| 50 | 50 |
| 51 try: | 51 try: |
| 52 settings = 'autotest_lib.frontend.settings' | 52 settings = 'autotest_lib.frontend.settings' |
| 53 os.environ['DJANGO_SETTINGS_MODULE'] = settings | 53 os.environ['DJANGO_SETTINGS_MODULE'] = settings |
| 54 from autotest_lib.frontend.afe import models | 54 from autotest_lib.frontend.afe import models |
| 55 has_models = True | 55 has_models = True |
| 56 except ImportError, e: | 56 except ImportError, e: |
| 57 has_models = False | 57 has_models = False |
| 58 | 58 |
| 59 | 59 |
| 60 _DEFAULT_ATTRIBUTES = [ | 60 _DEFAULT_ATTRIBUTES = [ |
| 61 'has_3g,False', |
| 61 'has_80211n,True', | 62 'has_80211n,True', |
| 62 'has_bluetooth,True', | 63 'has_bluetooth,True', |
| 63 'has_chromeos_firmware,False', | 64 'has_chromeos_firmware,False', |
| 64 'has_resume_bug,False', | 65 'has_resume_bug,False', |
| 65 'has_ssd,True', | 66 'has_ssd,True', |
| 66 'has_3g,False', | 67 'has_working_kcrash,False' |
| 67 ] | 68 ] |
| 68 | 69 |
| 69 | 70 |
| 70 class HostAttributes(object): | 71 class HostAttributes(object): |
| 71 | 72 |
| 72 | 73 |
| 73 def __init__(self, host): | 74 def __init__(self, host): |
| 74 """ | 75 """ |
| 75 Create an instance of HostAttribute for the given hostname. | 76 Create an instance of HostAttribute for the given hostname. |
| 76 We look up the host in both the hardcoded configuration and | 77 We look up the host in both the hardcoded configuration and |
| (...skipping 19 matching lines...) Expand all Loading... |
| 96 if value == 'True': | 97 if value == 'True': |
| 97 value = True | 98 value = True |
| 98 elif value == 'False': | 99 elif value == 'False': |
| 99 value = False | 100 value = False |
| 100 elif splitnames[1] == 'string' and len(splitnames) > 2: | 101 elif splitnames[1] == 'string' and len(splitnames) > 2: |
| 101 value = ','.join(splitnames[2:]) | 102 value = ','.join(splitnames[2:]) |
| 102 else: | 103 else: |
| 103 logging.info('Non-attribute string "%s" is ignored' % attribute) | 104 logging.info('Non-attribute string "%s" is ignored' % attribute) |
| 104 continue | 105 continue |
| 105 setattr(self, splitnames[0], value) | 106 setattr(self, splitnames[0], value) |
| OLD | NEW |