xref: /aosp_15_r20/external/autotest/server/control_segments/verify (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1from autotest_lib.server import utils
2from autotest_lib.server.cros import provision
3
4try:
5    from autotest_lib.utils.frozen_chromite.lib import metrics
6except ImportError:
7    metrics = utils.metrics_mock
8
9
10DURATION_METRIC = 'chromeos/autotest/autoserv/verify_duration'
11
12
13# A string of the form 'label1,label2:value,label3'.
14job_labels = locals().get('job_labels') or ','.join(args)
15labels_list = [l.strip() for l in job_labels.split(',') if l]
16
17
18def verify(machine):
19    print('Initializing host %s' % machine)
20    job.record('START', None, 'verify')
21    target = hosts.create_target_machine(machine,
22                                         try_lab_servo=True,
23                                         try_servo_recovery=True)
24    hostname = utils.get_hostname_from_machine(machine)
25    try:
26        with metrics.SecondsTimer(DURATION_METRIC,
27                                  fields={'dut_host_name': hostname}):
28            target.verify()
29            provision.Verify.run_task_actions(job, target, labels_list)
30    except Exception:
31        logging.exception('Verify failed due to Exception.')
32        job.record('END FAIL', None, 'verify')
33        # See the provision control segment for the explanation of why we're
34        # doing this.
35        raise Exception('')
36    else:
37        hostname = utils.get_hostname_from_machine(machine)
38        job.record('END GOOD', None, 'verify',
39                   '%s verified successfully' % hostname)
40
41
42job.parallel_simple(verify, machines)
43
44# vim: set syntax=python :
45