Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: client/site_tests/hardware_Components/hardware_Components.py

Issue 6736025: autotest/factory: improve message feedback on UI (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/site_tests/factory_WriteGBB/factory_WriteGBB.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 glob 5 import glob
6 import logging 6 import logging
7 import os 7 import os
8 import pprint 8 import pprint
9 import re 9 import re
10 from autotest_lib.client.bin import factory, test, utils 10 from autotest_lib.client.bin import factory, test, utils
11 from autotest_lib.client.common_lib import error 11 from autotest_lib.client.common_lib import error
12 from autotest_lib.client.cros import gooftools 12 from autotest_lib.client.cros import gooftools
13 13
14 14
15 class hardware_Components(test.test): 15 class hardware_Components(test.test):
16 version = 3 16 version = 3
17 17
18 def run_once(self, approved_dbs='approved_components', do_probe=True): 18 def run_once(self, approved_dbs='approved_components', do_probe=True):
19 # In probe mode, we have to find out the matching HWID, write that into
20 # shared data LAST_PROBED_HWID_NAME, and then let factory_WriteGBB to
21 # update system. factory_Finalize will verify if that's set correctly.
22 #
23 # In verify mode, we simply check if current system matches a hardware
24 # configuration in the databases.
19 25
20 last_probed_hwid = None 26 last_probed_hwid = None
21 if not do_probe: 27 if not do_probe:
22 # verify, or trust previous probed. 28 # Verify, or trust previous probed HWID.
23 try: 29 try:
24 last_probed_hwid = factory.get_shared_data('last_probed_hwid') 30 last_probed_hwid = factory.get_shared_data(
31 factory.LAST_PROBED_HWID_NAME)
25 except Exception, e: 32 except Exception, e:
26 # hardware_Components may run without factory environment 33 # hardware_Components may run without factory environment
27 factory.log('Failed getting shared data, ignored: %s' % repr(e)) 34 factory.log('Failed getting shared data, ignored: %s' % repr(e))
28 35
29 # If a hwid was probed, trust it. Otherwise, find best match. 36 # If a hwid was probed, trust it. Otherwise, find best match.
30 if last_probed_hwid: 37 if last_probed_hwid:
31 approved_dbs = last_probed_hwid 38 approved_dbs = last_probed_hwid
32 else: 39 else:
33 # Currently the files are expected to be inside same folder with 40 # Currently the files are expected to be inside same folder with
34 # hardware_Components test. 41 # hardware_Components test.
35 approved_dbs = os.path.join(self.bindir, approved_dbs) 42 approved_dbs = os.path.join(self.bindir, approved_dbs)
36 sample_approved_dbs = os.path.join(self.bindir, 43 sample_approved_dbs = os.path.join(self.bindir,
37 'approved_components.default') 44 'approved_components.default')
38 if (not glob.glob(approved_dbs)) and glob.glob(sample_approved_dbs): 45 if (not glob.glob(approved_dbs)) and glob.glob(sample_approved_dbs):
39 # Fallback to the default (sample) version 46 # Fallback to the default (sample) version
40 approved_dbs = sample_approved_dbs 47 approved_dbs = sample_approved_dbs
41 factory.log('Using default (sample) approved component list: %s' 48 factory.log('Using default (sample) approved component list: %s'
42 % sample_approved_dbs) 49 % sample_approved_dbs)
43 50
44 # approved_dbs supports shell-like filename expansion. 51 # approved_dbs supports shell-like filename expansion.
45 existing_dbs = glob.glob(approved_dbs) 52 existing_dbs = glob.glob(approved_dbs)
46 if not existing_dbs: 53 if not existing_dbs:
47 raise error.TestError('Unable to find approved db: %s' % 54 raise error.TestError('Unable to find approved db: %s' %
48 approved_dbs) 55 approved_dbs)
49 56
50 if do_probe: 57 if do_probe:
51 probed_hwids = gooftools.run( 58 command = 'gooftool --probe --db_path "%s" --verbose' % approved_dbs
52 'gooftool --probe --db_path "%s" --verbose' % approved_dbs)
53 pattern = 'Probed: ' 59 pattern = 'Probed: '
54 factory.log('probe result: ' + probed_hwids) 60 # The output format is "Probed: PATH"
55 probed_hwids = [hwid.lstrip(pattern) 61 else:
56 for hwid in probed_hwids.splitlines() 62 command = ('gooftool --verify_hwid --db_path "%s" --verbose' %
57 if hwid.startswith(pattern)] 63 approved_dbs)
58 if len(probed_hwids) < 1: 64 pattern = 'Verified: '
59 raise error.TestFail('No HWID matched.') 65 # The output format is "Verified: PATH (HWID)", not a pure path.
60 if len(probed_hwids) > 1: 66
61 raise error.TestError('Multiple HWIDs match current system: ' + 67 (stdout, stderr, result) = gooftools.run(command, ignore_status=True)
62 ','.join(probed_hwids)) 68
63 factory.log('Set last_probed_hwid = %s' % probed_hwids[0]) 69 # Decode successfully matched results
70 hwids = [hwid.lstrip(pattern)
71 for hwid in stdout.splitlines()
72 if hwid.startswith(pattern)]
73
74 # Decode unmatched results
75 if stderr.find('Unmatched ') < 0:
76 unmatched = ''
77 else:
78 start = stderr.find('Unmatched ')
79 end = stderr.rfind('Current System:')
80 if end >= 0:
81 unmatched = stderr[start:end]
82 else:
83 unmatched = stderr[start:]
84 unmatched = '\n'.join([line for line in unmatched.splitlines()
85 # 'gft_hwcome'/'probe' are debug message.
86 if not (line.startswith('gft_hwcomp:') or
87 line.startswith('probe:') or
88 (not line))])
89 # Report the results
90 if len(hwids) < 1:
91 raise error.TestFail('\n'.join(('No HWID matched.', unmatched)))
92 if len(hwids) > 1:
93 raise error.TestError('Multiple HWIDs match current system: ' +
94 ','.join(hwids))
95 if result != 0:
96 raise error.TestFail('HWID matched (%s) with unknown error: %s'
97 % hwids[0], result)
98
99 # Set the factory state sharead data for factory_WriteGBB
100 if do_probe:
101 factory.log('Set factory state shared data %s = %s' %
102 (factory.LAST_PROBED_HWID_NAME, hwids[0]))
64 try: 103 try:
65 factory.set_shared_data('last_probed_hwid', probed_hwids[0]) 104 factory.set_shared_data(factory.LAST_PROBED_HWID_NAME,
105 hwids[0])
66 except Exception, e: 106 except Exception, e:
67 # hardware_Components may run without factory environment 107 # hardware_Components may run without factory environment
68 factory.log('Failed setting shared data, ignored: %s' % 108 factory.log('Failed setting shared data, ignored: %s' %
69 repr(e)) 109 repr(e))
70 else: 110 factory.log('Exact Matched: HWID=%s' % hwids[0])
71 verified_hwids = gooftools.run(
72 'gooftool --verify_hwid --db_path "%s" --verbose' %
73 approved_dbs)
74 pattern = 'Verified: '
75 # The 'verified hwid' is in format "PATH (HWID)", so we can only use
76 # it for logging instead of using it directly like in probing.
77 verified_hwids = [hwid.lstrip(pattern)
78 for hwid in verified_hwids.splitlines()
79 if hwid.startswith(pattern)]
80 if len(probed_hwids) < 1:
81 raise error.TestFail('No HWID matched.')
82 if len(verified_hwids) > 1:
83 raise error.TestError('Multiple HWIDs match current system: ' +
84 ','.join(verified_hwids))
85 factory.log('Verified: HWID=%s' % verified_hwids[0])
OLDNEW
« no previous file with comments | « client/site_tests/factory_WriteGBB/factory_WriteGBB.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698