Changeset 86540 in vbox
- Timestamp:
- Oct 12, 2020 11:07:32 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 140855
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py
r86062 r86540 35 35 import sys; 36 36 import re; 37 import ssl;38 39 # Python 3 hacks:40 if sys.version_info[0] < 3:41 import urllib2 as urllib; # pylint: disable=import-error,no-name-in-module42 from urllib2 import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module43 from urllib2 import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module44 else:45 import urllib; # pylint: disable=import-error,no-name-in-module46 from urllib.request import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module47 from urllib.request import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module48 49 37 50 38 # Only the main script needs to modify the path. … … 60 48 from testdriver import vboxcon; 61 49 from testdriver import vboxwrappers; 62 from common import utils;63 64 # Python 3 hacks:65 if sys.version_info[0] >= 3:66 long = int # pylint: disable=redefined-builtin,invalid-name67 xrange = range; # pylint: disable=redefined-builtin,invalid-name68 50 69 51 … … 115 97 116 98 117 def downloadFile(sUrlFile, sDstFile, sLocalPrefix, fnLog, fnError = None, fNoProxies=True):118 """119 Downloads the given file if an URL is given, otherwise assume it's120 something on the build share and copy it from there.121 122 Raises no exceptions, returns log + success indicator instead.123 124 Note! This method may use proxies configured on the system and the125 http_proxy, ftp_proxy, no_proxy environment variables.126 127 """128 if fnError is None:129 fnError = fnLog;130 131 if sUrlFile.startswith('http://') \132 or sUrlFile.startswith('https://') \133 or sUrlFile.startswith('ftp://'):134 # Download the file.135 fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile));136 try:137 # Disable SSL certificate verification for our servers138 ssl_ctx = ssl.create_default_context();139 ssl_ctx.check_hostname = False;140 ssl_ctx.verify_mode = ssl.CERT_NONE;141 142 ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.143 if not fNoProxies:144 oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx));145 else:146 oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx), urllib_ProxyHandler(proxies = dict()));147 oSrc = oOpener.open(sUrlFile);148 oDst = utils.openNoInherit(sDstFile, 'wb');149 oDst.write(oSrc.read());150 oDst.close();151 oSrc.close();152 except Exception as oXcpt:153 fnError('Error downloading "%s" to "%s": %s' % (sUrlFile, sDstFile, oXcpt));154 return False;155 else:156 # Assumes file from the build share.157 sSrcPath = os.path.join(sLocalPrefix, sUrlFile);158 fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile));159 try:160 utils.copyFileSimple(sSrcPath, sDstFile);161 except Exception as oXcpt:162 fnError('Error copying "%s" to "%s": %s' % (sSrcPath, sDstFile, oXcpt));163 return False;164 165 return True;166 167 168 99 class tdAutostartOs(object): 169 100 """ … … 171 102 """ 172 103 173 def __init__(self, oT estDriver, fpApiVer, sGuestAdditionsIso):174 self.oT estDriver = oTestDriver;104 def __init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso): 105 self.oTstDrv = oTstDrv; 175 106 self.fpApiVer = fpApiVer; 176 107 self.sGuestAdditionsIso = sGuestAdditionsIso; … … 236 167 break; 237 168 238 self.oT estDriver.sleep(10);169 self.oTstDrv.sleep(10); 239 170 cAttempt += 1; 240 171 return fRc; … … 481 412 else: 482 413 if oCurProgress is not None: 483 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr, 484 self.oTestDriver, "uploadFile"); 414 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "uploadFile"); 485 415 oWrapperProgress.wait(); 486 416 if not oWrapperProgress.isSuccess(): … … 494 424 def downloadFile(self, oGuestSession, sSrc, sDst, fIgnoreErrors = False): 495 425 """ 496 Upload the string into guest.426 Get a file (sSrc) from the guest storing it on the host (sDst). 497 427 """ 498 428 fRc = True; … … 510 440 else: 511 441 if oCurProgress is not None: 512 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oT estDriver.oVBoxMgr,513 self.oT estDriver, "downloadFile");442 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, 443 self.oTstDrv, "downloadFile"); 514 444 oWrapperProgress.wait(); 515 445 if not oWrapperProgress.isSuccess(): … … 536 466 fRc = True; 537 467 for sGstFile in asFiles: 538 sTmpFile = os.path.join(self.oTestDriver.sScratchPath, 'tmp-' + os.path.basename(sGstFile)); 468 ## @todo r=bird: You need to use the guest specific path functions here. 469 ## Best would be to add basenameEx to common/pathutils.py. See how joinEx 470 ## is used by BaseTestVm::pathJoin and such. 471 sTmpFile = os.path.join(self.oTstDrv.sScratchPath, 'tmp-' + os.path.basename(sGstFile)); 539 472 reporter.log2('Downloading file "%s" to "%s" ...' % (sGstFile, sTmpFile)); 540 473 # First try to remove (unlink) an existing temporary file, as we don't truncate the file. … … 559 492 """ 560 493 561 def __init__(self, oT estDriver, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):562 tdAutostartOs.__init__(self, oT estDriver, fpApiVer, sGuestAdditionsIso);494 def __init__(self, oTstDrv, asTestBuildDirs, fpApiVer, sGuestAdditionsIso): 495 tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso); 563 496 self.sTestBuild = self._findFile('^VirtualBox-.*\\.run$', asTestBuildDirs); 564 497 if not self.sTestBuild: 565 498 raise base.GenError("VirtualBox install package not found"); 566 499 567 def waitV MisReady(self, oSession, fWaitTrayControl):500 def waitVmIsReady(self, oSession, fWaitTrayControl): 568 501 """ 569 502 Waits the VM is ready after start or reboot. … … 572 505 _ = fWaitTrayControl; 573 506 # Give the VM a time to reboot 574 self.oT estDriver.sleep(30);507 self.oTstDrv.sleep(30); 575 508 576 509 # Waiting the VM is ready. … … 585 518 while cAttempt < 30: 586 519 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 587 'vbox', 'password', 10 * 1000, False);520 'vbox', 'password', 10 * 1000, False); 588 521 if fRc: 589 522 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process', … … 596 529 self.closeSession(oGuestSession, False); 597 530 598 self.oT estDriver.sleep(10);531 self.oTstDrv.sleep(10); 599 532 cAttempt += 1; 600 533 … … 615 548 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 616 549 if fRc: 617 (fRc, oGuestSession) = self.waitV MisReady(oSession, False);550 (fRc, oGuestSession) = self.waitVmIsReady(oSession, False); 618 551 619 552 if not fRc: … … 655 588 fRc = False; 656 589 # Install Kernel headers, which are required for actually installing the Linux Additions. 657 if oVM.OSTypeId.startswith('Debian') \658 or oVM.OSTypeId.startswith('Ubuntu'):590 if oVM.OSTypeId.startswith('Debian') \ 591 or oVM.OSTypeId.startswith('Ubuntu'): 659 592 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers', 660 593 5 * 60 *1000, '/usr/bin/apt-get', … … 673 606 674 607 elif oVM.OSTypeId.startswith('OL') \ 675 oroVM.OSTypeId.startswith('Oracle') \676 oroVM.OSTypeId.startswith('RHEL') \677 oroVM.OSTypeId.startswith('Redhat') \678 oroVM.OSTypeId.startswith('Cent'):608 or oVM.OSTypeId.startswith('Oracle') \ 609 or oVM.OSTypeId.startswith('RHEL') \ 610 or oVM.OSTypeId.startswith('Redhat') \ 611 or oVM.OSTypeId.startswith('Cent'): 679 612 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers', 680 613 5 * 60 *1000, '/usr/bin/yum', … … 711 644 fRc = self.closeSession(oGuestSession); 712 645 if fRc: 713 (fRc, oGuestSession) = self.waitV MisReady(oSession, False);646 (fRc, oGuestSession) = self.waitVmIsReady(oSession, False); 714 647 715 648 # Download log files. … … 764 697 return fRc; 765 698 766 def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow', 767 asUserAllow = (), asUserDeny = ()): 699 def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow', asUserAllow = (), asUserDeny = ()): 768 700 """ 769 701 Configures the autostart feature in the guest. … … 886 818 """ 887 819 888 self.oT estDriver.sleep(30);820 self.oTstDrv.sleep(30); 889 821 890 822 _ = oSession; … … 912 844 """ 913 845 914 def __init__(self, oT estDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso):846 def __init__(self, oTstDrv, sTestBuildDir, fpApiVer, sGuestAdditionsIso): 915 847 _ = sTestBuildDir; 916 tdAutostartOs.__init__(self, oT estDriver, fpApiVer, sGuestAdditionsIso);848 tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso); 917 849 raise base.GenError('Testing the autostart functionality for Darwin is not implemented'); 918 850 … … 923 855 """ 924 856 925 def __init__(self, oT estDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso):857 def __init__(self, oTstDrv, sTestBuildDir, fpApiVer, sGuestAdditionsIso): 926 858 _ = sTestBuildDir; 927 tdAutostartOs.__init__(self, oT estDriver, fpApiVer, sGuestAdditionsIso);859 tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso); 928 860 raise base.GenError('Testing the autostart functionality for Solaris is not implemented'); 929 861 … … 934 866 """ 935 867 936 def __init__(self, oT estDriver, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):937 tdAutostartOs.__init__(self, oT estDriver, fpApiVer, sGuestAdditionsIso);868 def __init__(self, oTstDrv, asTestBuildDirs, fpApiVer, sGuestAdditionsIso): 869 tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso); 938 870 self.sTestBuild = self._findFile('^VirtualBox-.*\\.(exe|msi)$', asTestBuildDirs); 939 871 if not self.sTestBuild: … … 941 873 return; 942 874 943 def waitV MisReady(self, oSession, fWaitTrayControl, fWaitFacility = True):875 def waitVmIsReady(self, oSession, fWaitTrayControl, fWaitFacility = True): 944 876 """ 945 877 Waits the VM is ready after start or reboot. 946 878 """ 947 879 # Give the VM a time to reboot 948 self.oT estDriver.sleep(30);880 self.oTstDrv.sleep(30); 949 881 950 882 # Waiting the VM is ready. … … 957 889 oGuestSession = None; 958 890 while cAttempt < 10: 959 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 960 'vbox', 'password', 10 * 1000, False); 891 fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 'vbox', 'password', 10 * 1000, False); 961 892 if fRc: 962 893 (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process', … … 968 899 self.closeSession(oGuestSession, False); 969 900 970 self.oT estDriver.sleep(10);901 self.oTstDrv.sleep(10); 971 902 cAttempt += 1; 972 903 … … 987 918 fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack. 988 919 if fRc: 989 (fRc, oGuestSession) = self.waitV MisReady(oSession, True);920 (fRc, oGuestSession) = self.waitVmIsReady(oSession, True); 990 921 if not fRc: 991 922 reporter.error('VM is not ready after reboot'); … … 1035 966 else: 1036 967 if oCurProgress is not None: 1037 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oT estDriver.oVBoxMgr,1038 self.oT estDriver, "installAdditions");968 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, 969 self.oTstDrv, "installAdditions"); 1039 970 oWrapperProgress.wait(cMsTimeout = 10 * 60 * 1000); 1040 971 if not oWrapperProgress.isSuccess(): … … 1050 981 ## 1051 982 # 1052 #self.oT estDriver.sleep(60 * 2);983 #self.oTstDrv.sleep(60 * 2); 1053 984 # 1054 985 #if oVM.OSTypeId not in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003'): … … 1083 1014 # fRc = self.closeSession(oGuestSession, True); 1084 1015 # if fRc: 1085 # (fRc, oGuestSession) = self.waitV MisReady(oSession, False, False);1016 # (fRc, oGuestSession) = self.waitVmIsReady(oSession, False, False); 1086 1017 #--------------------------------------- 1087 1018 … … 1162 1093 return fRc; 1163 1094 1164 def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow', 1165 asUserAllow = (), asUserDeny = ()): 1095 def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow', asUserAllow = (), asUserDeny = ()): 1166 1096 """ 1167 1097 Configures the autostart feature in the guest. 1168 1098 """ 1169 1099 reporter.testStart('Configure autostart'); 1100 1170 1101 # Create autostart database directory writeable for everyone 1171 1102 (fRc, _, _, _) = \ … … 1177 1108 'C:\\ProgramData\\autostart.cfg', '/f'], 1178 1109 False, True); 1179 if not fRc:1180 reporter.error('Setting the autostart environment variable failed');1181 1182 1110 if fRc: 1183 1111 sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny); … … 1185 1113 if not fRc: 1186 1114 reporter.error('Upload the autostart.cfg failed'); 1115 else: 1116 reporter.error('Setting the autostart environment variable failed'); 1117 1187 1118 reporter.testDone(); 1188 1119 return fRc; … … 1242 1173 """ 1243 1174 1244 self.oT estDriver.sleep(30);1175 self.oTstDrv.sleep(30); 1245 1176 1246 1177 _ = oGuestSession; … … 1256 1187 1257 1188 (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM', 1258 60 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',1259 ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',1260 'list', 'runningvms'], True, True);1189 60 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1190 [ 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe', 1191 'list', 'runningvms' ], True, True); 1261 1192 if not fRc: 1262 1193 reporter.error('Checking the VM %s is running for user %s failed' % (sVmName, sUser)); … … 1329 1260 1330 1261 WScript.Echo "Logon As A Service Right granted to user '"& strUserName &"'" 1331 """ % sUser;1262 """ % (sUser,); 1332 1263 fRc = self.uploadString(oGuestSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs'); 1333 1264 if not fRc: … … 1365 1296 self.asTestVMs = self.asTestVMsDef; 1366 1297 self.asSkipVMs = []; 1367 self.asTestBuildDirs = None; #'D:/AlexD/TestBox/TestAdditionalFiles'; 1298 ## @todo r=bird: The --test-build-dirs option as primary way to get the installation files to test 1299 ## is not an acceptable test practice as we don't know wtf you're testing. See defect for more. 1300 self.asTestBuildDirs = None; #'D:/AlexD/TestBox/TestAdditionalFiles'; 1368 1301 self.sGuestAdditionsIso = None; #'D:/AlexD/TestBox/TestAdditionalFiles/VBoxGuestAdditions_6.1.2.iso'; 1369 1302 … … 1527 1460 if oGuestOsHlp is not None: 1528 1461 #wait the VM is ready after starting 1529 (fRc, oGuestSession) = oGuestOsHlp.waitV MisReady(oSession, True);1462 (fRc, oGuestSession) = oGuestOsHlp.waitVmIsReady(oSession, True); 1530 1463 #install fresh guest additions 1531 1464 if fRc:
Note:
See TracChangeset
for help on using the changeset viewer.