VirtualBox

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

Last change on this file since 80185 was 79087, checked in by vboxsync, 6 years ago

ValKit: New pylint version - cleanup in progress.

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