1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: regen_sched_queues.py 76553 2019-01-01 01:45:53Z vboxsync $
|
---|
4 | # pylint: disable=C0301
|
---|
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-2019 Oracle Corporation
|
---|
15 |
|
---|
16 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
17 | available from http://www.virtualbox.org. This file is free software;
|
---|
18 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
19 | General Public License (GPL) as published by the Free Software
|
---|
20 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
21 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
22 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
23 |
|
---|
24 | The contents of this file may alternatively be used under the terms
|
---|
25 | of the Common Development and Distribution License Version 1.0
|
---|
26 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
27 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
28 | CDDL are applicable instead of those of the GPL.
|
---|
29 |
|
---|
30 | You may elect to license modified versions of this file under the
|
---|
31 | terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | """
|
---|
33 | __version__ = "$Revision: 76553 $"
|
---|
34 |
|
---|
35 | # Standard python imports
|
---|
36 | import sys;
|
---|
37 | import os;
|
---|
38 | from optparse import OptionParser; # pylint: disable=deprecated-module
|
---|
39 |
|
---|
40 | # Add Test Manager's modules path
|
---|
41 | g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
42 | sys.path.append(g_ksTestManagerDir);
|
---|
43 |
|
---|
44 | # Test Manager imports
|
---|
45 | from testmanager.core.db import TMDatabaseConnection;
|
---|
46 | from testmanager.core.schedulerbase import SchedulerBase;
|
---|
47 | from testmanager.core.schedgroup import SchedGroupLogic;
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 | class RegenSchedQueues(object): # pylint: disable=R0903
|
---|
52 | """
|
---|
53 | Regenerates all the scheduling queues.
|
---|
54 | """
|
---|
55 |
|
---|
56 | def __init__(self):
|
---|
57 | """
|
---|
58 | Parse command line.
|
---|
59 | """
|
---|
60 |
|
---|
61 | oParser = OptionParser();
|
---|
62 | oParser.add_option('-q', '--quiet', dest = 'fQuiet', action = 'store_true', default = False,
|
---|
63 | help = 'Quiet execution');
|
---|
64 | oParser.add_option('-u', '--uid', dest = 'uid', action = 'store', type = 'int', default = 1,
|
---|
65 | help = 'User ID to accredit with this job');
|
---|
66 | oParser.add_option('--profile', dest = 'fProfile', action = 'store_true', default = False,
|
---|
67 | help = 'User ID to accredit with this job');
|
---|
68 |
|
---|
69 | (self.oConfig, _) = oParser.parse_args();
|
---|
70 |
|
---|
71 |
|
---|
72 | def doIt(self):
|
---|
73 | """
|
---|
74 | Does the job.
|
---|
75 | """
|
---|
76 | oDb = TMDatabaseConnection();
|
---|
77 |
|
---|
78 | aoGroups = SchedGroupLogic(oDb).getAll();
|
---|
79 | iRc = 0;
|
---|
80 | for oGroup in aoGroups:
|
---|
81 | if not self.oConfig.fQuiet:
|
---|
82 | print('%s (ID %#d):' % (oGroup.sName, oGroup.idSchedGroup,));
|
---|
83 | try:
|
---|
84 | (aoErrors, asMessages) = SchedulerBase.recreateQueue(oDb, self.oConfig.uid, oGroup.idSchedGroup, 2);
|
---|
85 | except Exception as oXcpt:
|
---|
86 | oDb.rollback();
|
---|
87 | print(' !!Hit exception processing "%s": %s' % (oGroup.sName, oXcpt,));
|
---|
88 | else:
|
---|
89 | if not aoErrors:
|
---|
90 | if not self.oConfig.fQuiet:
|
---|
91 | print(' Successfully regenerated.');
|
---|
92 | else:
|
---|
93 | iRc = 1;
|
---|
94 | print(' %d errors:' % (len(aoErrors,)));
|
---|
95 | for oError in aoErrors:
|
---|
96 | if oError[1] is None:
|
---|
97 | print(' !!%s' % (oError[0],));
|
---|
98 | else:
|
---|
99 | print(' !!%s (%s)' % (oError[0], oError[1]));
|
---|
100 | if asMessages and not self.oConfig.fQuiet:
|
---|
101 | print(' %d messages:' % (len(asMessages),));
|
---|
102 | for sMsg in asMessages:
|
---|
103 | print(' ##%s' % (sMsg,));
|
---|
104 | return iRc;
|
---|
105 |
|
---|
106 | @staticmethod
|
---|
107 | def main():
|
---|
108 | """ Main function. """
|
---|
109 | oMain = RegenSchedQueues();
|
---|
110 | if oMain.oConfig.fProfile is not True:
|
---|
111 | iRc = oMain.doIt();
|
---|
112 | else:
|
---|
113 | import cProfile;
|
---|
114 | oProfiler = cProfile.Profile();
|
---|
115 | iRc = oProfiler.runcall(oMain.doIt);
|
---|
116 | oProfiler.print_stats(sort = 'time');
|
---|
117 | oProfiler = None;
|
---|
118 | return iRc;
|
---|
119 |
|
---|
120 | if __name__ == '__main__':
|
---|
121 | sys.exit(RegenSchedQueues().main());
|
---|
122 |
|
---|