xref: /aosp_15_r20/external/autotest/utils/reverify_repair_failed.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1*9c5db199SXin Li#!/usr/bin/python3
2*9c5db199SXin Li
3*9c5db199SXin Li"""
4*9c5db199SXin LiSend all Repair Failed hosts that the user running this script has access to
5*9c5db199SXin Liback into Verifying.  (Only hosts ACL accessable to the user)
6*9c5db199SXin Li
7*9c5db199SXin LiSuggested use: Run this as an occasional cron job to re-check if Repair Failed
8*9c5db199SXin Lihosts have overcome whatever issue caused the failure and are useful again.
9*9c5db199SXin Li"""
10*9c5db199SXin Li
11*9c5db199SXin Lifrom __future__ import absolute_import
12*9c5db199SXin Lifrom __future__ import division
13*9c5db199SXin Lifrom __future__ import print_function
14*9c5db199SXin Li
15*9c5db199SXin Liimport optparse, os, sys
16*9c5db199SXin Li
17*9c5db199SXin Liimport common
18*9c5db199SXin Lifrom autotest_lib.server import frontend
19*9c5db199SXin Li
20*9c5db199SXin Li
21*9c5db199SXin Lidef main():
22*9c5db199SXin Li    parser = optparse.OptionParser(usage='%prog [options]\n\n' +
23*9c5db199SXin Li                                   __doc__.strip())
24*9c5db199SXin Li    parser.add_option('-w', dest='server', default='autotest',
25*9c5db199SXin Li                      help='Hostname of the autotest frontend RPC server.')
26*9c5db199SXin Li    parser.add_option('-b', dest='label', default=None, type=str,
27*9c5db199SXin Li                      help='A label to restrict the set of hosts reverified.')
28*9c5db199SXin Li    options, unused_args = parser.parse_args(sys.argv)
29*9c5db199SXin Li
30*9c5db199SXin Li    afe_client = frontend.AFE(debug=False, server=options.server)
31*9c5db199SXin Li    hostnames = afe_client.reverify_hosts(status='Repair Failed',
32*9c5db199SXin Li                                          label=options.label)
33*9c5db199SXin Li    # The old RPC interface didn't return anything.
34*9c5db199SXin Li    # A more recent one returns a list of hostnames to make this message useful.
35*9c5db199SXin Li    if hostnames:
36*9c5db199SXin Li        print('The following Repair Failed hosts on', options.server, end=' ')
37*9c5db199SXin Li        print('will be reverified:')
38*9c5db199SXin Li        print(' '.join(hostnames))
39*9c5db199SXin Li    else:
40*9c5db199SXin Li        print('Repair Failed hosts on', options.server, 'will be reverified.')
41*9c5db199SXin Li
42*9c5db199SXin Li
43*9c5db199SXin Liif __name__ == '__main__':
44*9c5db199SXin Li    main()
45