1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: regen_sched_queues.py 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
4 | # pylint: disable=line-too-long
|
---|
5 |
|
---|
6 | """
|
---|
7 | Interface used by the admin to regenerate scheduling queues.
|
---|
8 | """
|
---|
9 |
|
---|
10 | from __future__ import print_function;
|
---|
11 |
|
---|
12 | __copyright__ = \
|
---|
13 | """
|
---|
14 | Copyright (C) 2012-2024 Oracle and/or its affiliates.
|
---|
15 |
|
---|
16 | This file is part of VirtualBox base platform packages, as
|
---|
17 | available from https://www.virtualbox.org.
|
---|
18 |
|
---|
19 | This program is free software; you can redistribute it and/or
|
---|
20 | modify it under the terms of the GNU General Public License
|
---|
21 | as published by the Free Software Foundation, in version 3 of the
|
---|
22 | License.
|
---|
23 |
|
---|
24 | This program is distributed in the hope that it will be useful, but
|
---|
25 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
27 | General Public License for more details.
|
---|
28 |
|
---|
29 | You should have received a copy of the GNU General Public License
|
---|
30 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
31 |
|
---|
32 | The contents of this file may alternatively be used under the terms
|
---|
33 | of the Common Development and Distribution License Version 1.0
|
---|
34 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
35 | in the VirtualBox distribution, in which case the provisions of the
|
---|
36 | CDDL are applicable instead of those of the GPL.
|
---|
37 |
|
---|
38 | You may elect to license modified versions of this file under the
|
---|
39 | terms and conditions of either the GPL or the CDDL or both.
|
---|
40 |
|
---|
41 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
42 | """
|
---|
43 | __version__ = "$Revision: 106061 $"
|
---|
44 |
|
---|
45 | # Standard python imports
|
---|
46 | import sys;
|
---|
47 | import os;
|
---|
48 | from optparse import OptionParser; # pylint: disable=deprecated-module
|
---|
49 |
|
---|
50 | # Add Test Manager's modules path
|
---|
51 | g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
52 | sys.path.append(g_ksTestManagerDir);
|
---|
53 |
|
---|
54 | # Test Manager imports
|
---|
55 | from testmanager.core.db import TMDatabaseConnection;
|
---|
56 | from testmanager.core.schedulerbase import SchedulerBase;
|
---|
57 | from testmanager.core.schedgroup import SchedGroupLogic;
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 | class RegenSchedQueues(object): # pylint: disable=too-few-public-methods
|
---|
62 | """
|
---|
63 | Regenerates all the scheduling queues.
|
---|
64 | """
|
---|
65 |
|
---|
66 | def __init__(self):
|
---|
67 | """
|
---|
68 | Parse command line.
|
---|
69 | """
|
---|
70 |
|
---|
71 | oParser = OptionParser();
|
---|
72 | oParser.add_option('-q', '--quiet', dest = 'fQuiet', action = 'store_true', default = False,
|
---|
73 | help = 'Quiet execution');
|
---|
74 | oParser.add_option('-u', '--uid', dest = 'uid', action = 'store', type = 'int', default = 1,
|
---|
75 | help = 'User ID to accredit with this job');
|
---|
76 | oParser.add_option('--profile', dest = 'fProfile', action = 'store_true', default = False,
|
---|
77 | help = 'User ID to accredit with this job');
|
---|
78 |
|
---|
79 | (self.oConfig, _) = oParser.parse_args();
|
---|
80 |
|
---|
81 |
|
---|
82 | def doIt(self):
|
---|
83 | """
|
---|
84 | Does the job.
|
---|
85 | """
|
---|
86 | oDb = TMDatabaseConnection();
|
---|
87 |
|
---|
88 | aoGroups = SchedGroupLogic(oDb).getAll();
|
---|
89 | iRc = 0;
|
---|
90 | for oGroup in aoGroups:
|
---|
91 | if not self.oConfig.fQuiet:
|
---|
92 | print('%s (ID %#d):' % (oGroup.sName, oGroup.idSchedGroup,));
|
---|
93 | try:
|
---|
94 | (aoErrors, asMessages) = SchedulerBase.recreateQueue(oDb, self.oConfig.uid, oGroup.idSchedGroup, 2);
|
---|
95 | except Exception as oXcpt:
|
---|
96 | oDb.rollback();
|
---|
97 | print(' !!Hit exception processing "%s": %s' % (oGroup.sName, oXcpt,));
|
---|
98 | else:
|
---|
99 | if not aoErrors:
|
---|
100 | if not self.oConfig.fQuiet:
|
---|
101 | print(' Successfully regenerated.');
|
---|
102 | else:
|
---|
103 | iRc = 1;
|
---|
104 | print(' %d errors:' % (len(aoErrors,)));
|
---|
105 | for oError in aoErrors:
|
---|
106 | if oError[1] is None:
|
---|
107 | print(' !!%s' % (oError[0],));
|
---|
108 | else:
|
---|
109 | print(' !!%s (%s)' % (oError[0], oError[1]));
|
---|
110 | if asMessages and not self.oConfig.fQuiet:
|
---|
111 | print(' %d messages:' % (len(asMessages),));
|
---|
112 | for sMsg in asMessages:
|
---|
113 | print(' ##%s' % (sMsg,));
|
---|
114 | return iRc;
|
---|
115 |
|
---|
116 | @staticmethod
|
---|
117 | def main():
|
---|
118 | """ Main function. """
|
---|
119 | oMain = RegenSchedQueues();
|
---|
120 | if oMain.oConfig.fProfile is not True:
|
---|
121 | iRc = oMain.doIt();
|
---|
122 | else:
|
---|
123 | import cProfile;
|
---|
124 | oProfiler = cProfile.Profile();
|
---|
125 | iRc = oProfiler.runcall(oMain.doIt);
|
---|
126 | oProfiler.print_stats(sort = 'time');
|
---|
127 | oProfiler = None;
|
---|
128 | return iRc;
|
---|
129 |
|
---|
130 | if __name__ == '__main__':
|
---|
131 | sys.exit(RegenSchedQueues().main());
|
---|
132 |
|
---|