1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: check_for_deleted_builds.py 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
4 | # pylint: disable=line-too-long
|
---|
5 |
|
---|
6 | """
|
---|
7 | Admin job for checking detecting deleted builds.
|
---|
8 |
|
---|
9 | This is necessary when the tinderbox <-> test manager interface was
|
---|
10 | busted and the build info in is out of sync. The result is generally
|
---|
11 | a lot of skipped tests because of missing builds, typically during
|
---|
12 | bisecting problems.
|
---|
13 | """
|
---|
14 |
|
---|
15 | from __future__ import print_function;
|
---|
16 |
|
---|
17 | __copyright__ = \
|
---|
18 | """
|
---|
19 | Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
20 |
|
---|
21 | This file is part of VirtualBox base platform packages, as
|
---|
22 | available from https://www.virtualbox.org.
|
---|
23 |
|
---|
24 | This program is free software; you can redistribute it and/or
|
---|
25 | modify it under the terms of the GNU General Public License
|
---|
26 | as published by the Free Software Foundation, in version 3 of the
|
---|
27 | License.
|
---|
28 |
|
---|
29 | This program is distributed in the hope that it will be useful, but
|
---|
30 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
32 | General Public License for more details.
|
---|
33 |
|
---|
34 | You should have received a copy of the GNU General Public License
|
---|
35 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
36 |
|
---|
37 | The contents of this file may alternatively be used under the terms
|
---|
38 | of the Common Development and Distribution License Version 1.0
|
---|
39 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
40 | in the VirtualBox distribution, in which case the provisions of the
|
---|
41 | CDDL are applicable instead of those of the GPL.
|
---|
42 |
|
---|
43 | You may elect to license modified versions of this file under the
|
---|
44 | terms and conditions of either the GPL or the CDDL or both.
|
---|
45 |
|
---|
46 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
47 | """
|
---|
48 | __version__ = "$Revision: 98103 $"
|
---|
49 |
|
---|
50 | # Standard python imports
|
---|
51 | import sys;
|
---|
52 | import os;
|
---|
53 | from optparse import OptionParser; # pylint: disable=deprecated-module
|
---|
54 |
|
---|
55 | # Add Test Manager's modules path
|
---|
56 | g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
57 | sys.path.append(g_ksTestManagerDir);
|
---|
58 |
|
---|
59 | # Test Manager imports
|
---|
60 | from testmanager.core.db import TMDatabaseConnection;
|
---|
61 | from testmanager.core.build import BuildLogic;
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | class BuildChecker(object): # pylint: disable=too-few-public-methods
|
---|
66 | """
|
---|
67 | Add build info into Test Manager database.
|
---|
68 | """
|
---|
69 |
|
---|
70 | def __init__(self):
|
---|
71 | """
|
---|
72 | Parse command line.
|
---|
73 | """
|
---|
74 |
|
---|
75 | oParser = OptionParser();
|
---|
76 | oParser.add_option('-q', '--quiet', dest = 'fQuiet', action = 'store_true', default = False,
|
---|
77 | help = 'Quiet execution');
|
---|
78 | oParser.add_option('--dry-run', dest = 'fRealRun', action = 'store_false', default = False,
|
---|
79 | help = 'Dry run');
|
---|
80 | oParser.add_option('--real-run', dest = 'fRealRun', action = 'store_true', default = False,
|
---|
81 | help = 'Real run');
|
---|
82 |
|
---|
83 | (self.oConfig, _) = oParser.parse_args();
|
---|
84 | if not self.oConfig.fQuiet:
|
---|
85 | if not self.oConfig.fRealRun:
|
---|
86 | print('Dry run.');
|
---|
87 | else:
|
---|
88 | print('Real run! Will commit findings!');
|
---|
89 |
|
---|
90 |
|
---|
91 | def checkBuilds(self):
|
---|
92 | """
|
---|
93 | Add build data record into database.
|
---|
94 | """
|
---|
95 | oDb = TMDatabaseConnection();
|
---|
96 | oBuildLogic = BuildLogic(oDb);
|
---|
97 |
|
---|
98 | tsNow = oDb.getCurrentTimestamp();
|
---|
99 | cMaxRows = 1024;
|
---|
100 | iStart = 0;
|
---|
101 | while True:
|
---|
102 | aoBuilds = oBuildLogic.fetchForListing(iStart, cMaxRows, tsNow);
|
---|
103 | if not self.oConfig.fQuiet and aoBuilds:
|
---|
104 | print('Processing builds #%s thru #%s' % (aoBuilds[0].idBuild, aoBuilds[-1].idBuild));
|
---|
105 |
|
---|
106 | for oBuild in aoBuilds:
|
---|
107 | if oBuild.fBinariesDeleted is False:
|
---|
108 | rc = oBuild.areFilesStillThere();
|
---|
109 | if rc is False:
|
---|
110 | if not self.oConfig.fQuiet:
|
---|
111 | print('missing files for build #%s / r%s / %s / %s / %s / %s / %s'
|
---|
112 | % (oBuild.idBuild, oBuild.iRevision, oBuild.sVersion, oBuild.oCat.sType,
|
---|
113 | oBuild.oCat.sBranch, oBuild.oCat.sProduct, oBuild.oCat.asOsArches,));
|
---|
114 | print(' %s' % (oBuild.sBinaries,));
|
---|
115 | if self.oConfig.fRealRun is True:
|
---|
116 | oBuild.fBinariesDeleted = True;
|
---|
117 | oBuildLogic.editEntry(oBuild, fCommit = True);
|
---|
118 | elif rc is True and not self.oConfig.fQuiet:
|
---|
119 | print('build #%s still have its files' % (oBuild.idBuild,));
|
---|
120 | elif rc is None and not self.oConfig.fQuiet:
|
---|
121 | print('Unable to determine state of build #%s' % (oBuild.idBuild,));
|
---|
122 |
|
---|
123 | # advance
|
---|
124 | if len(aoBuilds) < cMaxRows:
|
---|
125 | break;
|
---|
126 | iStart += len(aoBuilds);
|
---|
127 |
|
---|
128 | oDb.close();
|
---|
129 | return 0;
|
---|
130 |
|
---|
131 | if __name__ == '__main__':
|
---|
132 | sys.exit(BuildChecker().checkBuilds());
|
---|
133 |
|
---|