VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testboxscript/testboxscript.py@ 60906

Last change on this file since 60906 was 56295, checked in by vboxsync, 9 years ago

ValidationKit: Updated (C) year.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: testboxscript.py 56295 2015-06-09 14:29:55Z vboxsync $
4
5"""
6TestBox Script Wrapper.
7
8This script aimes at respawning the Test Box Script when it terminates
9abnormally or due to an UPGRADE request.
10"""
11
12__copyright__ = \
13"""
14Copyright (C) 2012-2015 Oracle Corporation
15
16This file is part of VirtualBox Open Source Edition (OSE), as
17available from http://www.virtualbox.org. This file is free software;
18you can redistribute it and/or modify it under the terms of the GNU
19General Public License (GPL) as published by the Free Software
20Foundation, in version 2 as it comes in the "COPYING" file of the
21VirtualBox OSE distribution. VirtualBox OSE is distributed in the
22hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
23
24The contents of this file may alternatively be used under the terms
25of the Common Development and Distribution License Version 1.0
26(CDDL) only, as it comes in the "COPYING.CDDL" file of the
27VirtualBox OSE distribution, in which case the provisions of the
28CDDL are applicable instead of those of the GPL.
29
30You may elect to license modified versions of this file under the
31terms and conditions of either the GPL or the CDDL or both.
32"""
33__version__ = "$Revision: 56295 $"
34
35import subprocess
36import sys
37import os
38import time
39
40
41## @name Test Box script exit statuses (see also RTEXITCODE)
42# @remarks These will _never_ change
43# @{
44TBS_EXITCODE_FAILURE = 1 # RTEXITCODE_FAILURE
45TBS_EXITCODE_SYNTAX = 2 # RTEXITCODE_SYNTAX
46TBS_EXITCODE_NEED_UPGRADE = 9
47## @}
48
49
50class TestBoxScriptWrapper(object): # pylint: disable=R0903
51 """
52 Wrapper class
53 """
54
55 TESTBOX_SCRIPT_FILENAME = 'testboxscript_real.py'
56
57 def __init__(self):
58 """
59 Init
60 """
61 self.task = None
62
63 def __del__(self):
64 """
65 Cleanup
66 """
67 if self.task is not None:
68 print 'Wait for child task...'
69 self.task.terminate()
70 self.task.wait()
71 print 'done. Exiting'
72 self.task = None;
73
74 def run(self):
75 """
76 Start spawning the real TestBox script.
77 """
78
79 # Figure out where we live first.
80 try:
81 __file__
82 except:
83 __file__ = sys.argv[0];
84 sTestBoxScriptDir = os.path.dirname(os.path.abspath(__file__));
85
86 # Construct the argument list for the real script (same dir).
87 sRealScript = os.path.join(sTestBoxScriptDir, TestBoxScriptWrapper.TESTBOX_SCRIPT_FILENAME);
88 asArgs = sys.argv[1:];
89 asArgs.insert(0, sRealScript);
90 if sys.executable is not None and len(sys.executable) > 0:
91 asArgs.insert(0, sys.executable);
92
93 # Look for --pidfile <name> and write a pid file.
94 sPidFile = None;
95 for i in range(len(asArgs)):
96 if asArgs[i] == '--pidfile' and i + 1 < len(asArgs):
97 sPidFile = asArgs[i + 1];
98 break;
99 if asArgs[i] == '--':
100 break;
101 if sPidFile is not None and len(sPidFile) > 0:
102 oPidFile = open(sPidFile, 'w');
103 oPidFile.write(str(os.getpid()));
104 oPidFile.close();
105
106 # Execute the testbox script almost forever in a relaxed loop.
107 rcExit = TBS_EXITCODE_FAILURE;
108 while True:
109 self.task = subprocess.Popen(asArgs, shell=False);
110 rcExit = self.task.wait();
111 self.task = None;
112 if rcExit == TBS_EXITCODE_SYNTAX:
113 break;
114
115 # Relax.
116 time.sleep(1);
117 return rcExit;
118
119if __name__ == '__main__':
120 sys.exit(TestBoxScriptWrapper().run());
121
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette