Changeset 79157 in vbox
- Timestamp:
- Jun 15, 2019 4:21:55 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79156 r79157 923 923 self.cNumSessions = cNumSessions; 924 924 925 class GstFsObj(object): 926 """ A file system object we created in the guest for test purposes. """ 927 def __init__(self, oParent, sPath): 928 self.oParent = oParent # type: GstFsDir 929 self.sPath = sPath # type: str 930 self.sName = sPath # type: str 931 if oParent: 932 assert sPath.startswith(oParent.sPath); 933 self.sName = sPath[len(oParent.sPath) + 1:]; 934 # Add to parent. 935 oParent.aoChildren.append(self); 936 oParent.dChildrenUpper[self.sName.upper()] = self; 937 938 class GstFsFile(GstFsObj): 939 """ A file object in the guest. """ 940 def __init__(self, oParent, sPath, abContent): 941 GstFsObj.__init__(self, oParent, sPath); 942 self.abContent = abContent # type: bytearray 943 self.cbContent = len(abContent); 944 self.off = 0; 945 946 def read(self, cbToRead): 947 assert self.off <= self.cbContent; 948 cbLeft = self.cbContent - self.off; 949 if cbLeft < cbToRead: 950 cbToRead = cbLeft; 951 abRet = self.abContent[self.off:(self.off + cbToRead)]; 952 assert len(abRet) == cbToRead; 953 self.off += cbToRead; 954 return abRet; 955 956 class GstFsDir(GstFsObj): 957 """ A file object in the guest. """ 958 def __init__(self, oParent, sPath): 959 GstFsObj.__init__(self, oParent, sPath); 960 self.aoChildren = [] # type: list(GsFsObj) 961 self.dChildrenUpper = {} # type: dict(str,GsFsObj) 962 963 def contains(self, sName): 964 """ Checks if the directory contains the given name. """ 965 return sName.upper() in self.dChildrenUpper 925 926 class TestFileSet(object): 927 """ 928 Set of files and directories for use in a test. 929 """ 930 931 class GstFsObj(object): 932 """ A file system object we created in the guest for test purposes. """ 933 def __init__(self, oParent, sPath): 934 self.oParent = oParent # type: GstDir 935 self.sPath = sPath # type: str 936 self.sName = sPath # type: str 937 if oParent: 938 assert sPath.startswith(oParent.sPath); 939 self.sName = sPath[len(oParent.sPath) + 1:]; 940 # Add to parent. 941 oParent.aoChildren.append(self); 942 oParent.dChildrenUpper[self.sName.upper()] = self; 943 944 class GstFile(GstFsObj): 945 """ A file object in the guest. """ 946 def __init__(self, oParent, sPath, abContent): 947 TestFileSet.GstFsObj.__init__(self, oParent, sPath); 948 self.abContent = abContent # type: bytearray 949 self.cbContent = len(abContent); 950 self.off = 0; 951 952 def read(self, cbToRead): 953 assert self.off <= self.cbContent; 954 cbLeft = self.cbContent - self.off; 955 if cbLeft < cbToRead: 956 cbToRead = cbLeft; 957 abRet = self.abContent[self.off:(self.off + cbToRead)]; 958 assert len(abRet) == cbToRead; 959 self.off += cbToRead; 960 return abRet; 961 962 class GstDir(GstFsObj): 963 """ A file object in the guest. """ 964 def __init__(self, oParent, sPath): 965 TestFileSet.GstFsObj.__init__(self, oParent, sPath); 966 self.aoChildren = [] # type: list(GsFsObj) 967 self.dChildrenUpper = {} # type: dict(str,GsFsObj) 968 969 def contains(self, sName): 970 """ Checks if the directory contains the given name. """ 971 return sName.upper() in self.dChildrenUpper 972 973 974 ksReservedWinOS2 = '/\\"*:<>?|\t\v\n\r\f\a\b'; 975 ksReservedUnix = '/'; 976 ksReservedTrailingWinOS2 = ' .'; # The space is tar's fault. Must be first. 977 ksReservedTrailingUnix = ' '; 978 979 def __init__(self, oTestVm, sBasePath, sSubDir, # pylint: disable=too-many-arguments 980 oRngFileSizes = xrange(0, 16384), 981 oRngManyFiles = xrange(128, 512), 982 oRngTreeFiles = xrange(128, 384), 983 oRngTreeDepth = xrange(92, 256), 984 oRngTreeDirs = xrange(2, 16), 985 cchMaxPath = 230, 986 cchMaxName = 230): 987 ## @name Parameters 988 ## @{ 989 self.oTestVm = oTestVm; 990 self.sBasePath = sBasePath; 991 self.sSubDir = sSubDir; 992 self.oRngFileSizes = oRngFileSizes; 993 self.oRngManyFiles = oRngManyFiles; 994 self.oRngTreeFiles = oRngTreeFiles; 995 self.oRngTreeDepth = oRngTreeDepth; 996 self.oRngTreeDirs = oRngTreeDirs; 997 self.cchMaxPath = cchMaxPath; 998 self.cchMaxName = cchMaxName 999 ## @} 1000 1001 ## @name Charset stuff 1002 ## @todo allow more chars for unix hosts + guests. 1003 ## @{ 1004 ## The filename charset. 1005 self.sFileCharset = string.printable; 1006 ## The filename charset common to host and guest. 1007 self.sFileCharsetCommon = string.printable; 1008 ## Set of characters that should not trail a guest filename. 1009 self.sReservedTrailing = self.ksReservedTrailingWinOS2; 1010 ## Set of characters that should not trail a host or guest filename. 1011 self.sReservedTrailingCommon = self.ksReservedTrailingWinOS2; 1012 if oTestVm.isWindows() or oTestVm.isOS2(): 1013 for ch in self.ksReservedWinOS2: 1014 self.sFileCharset = self.sFileCharset.replace(ch, ''); 1015 else: 1016 self.sReservedTrailing = self.ksReservedTrailingUnix; 1017 for ch in self.ksReservedUnix: 1018 self.sFileCharset = self.sFileCharset.replace(ch, ''); 1019 self.sFileCharset += ' ...'; 1020 1021 for ch in self.ksReservedWinOS2: 1022 self.sFileCharsetCommon = self.sFileCharset.replace(ch, ''); 1023 self.sFileCharsetCommon += ' ...'; 1024 ## @} 1025 1026 ## The root directory. 1027 self.oRoot = None # type: GstDir; 1028 ## An empty directory (under root). 1029 self.oEmptyDir = None # type: GstDir; 1030 1031 ## A directory with a lot of files in it. 1032 self.oManyDir = None # type: GstDir; 1033 1034 ## A directory with a mixed tree structure under it. 1035 self.oTreeDir = None # type: GstDir; 1036 ## Number of files in oTreeDir. 1037 self.cTreeFiles = 0; 1038 ## Number of directories under oTreeDir. 1039 self.cTreeDirs = 0; 1040 1041 ## All directories in creation order. 1042 self.aoDirs = [] # type: list(GstDir); 1043 ## All files in creation order. 1044 self.aoFiles = [] # type: list(GstFile); 1045 ## Path to object lookup. 1046 self.dPaths = {} # type: dict(str, GstFsObj); 1047 1048 # 1049 # Do the creating. 1050 # 1051 self.uSeed = utils.timestampMilli(); 1052 self.oRandom = random.Random(); 1053 self.oRandom.seed(self.uSeed); 1054 reporter.log('prepareGuestForTesting: random seed %s' % (self.uSeed,)); 1055 1056 self.__createTestStuff(); 1057 1058 def __createTestDir(self, oParent, sDir): 1059 """ 1060 Creates a test directory. 1061 """ 1062 oDir = TestFileSet.GstDir(oParent, sDir); 1063 self.aoDirs.append(oDir); 1064 self.dPaths[sDir] = oDir; 1065 return oDir; 1066 1067 def __createTestFile(self, oParent, sFile): 1068 """ 1069 Creates a test file with random size up to cbMaxContent and random content. 1070 """ 1071 cbFile = self.oRandom.choice(self.oRngFileSizes); 1072 abContent = bytearray(self.oRandom.getrandbits(8) for _ in xrange(cbFile)); 1073 1074 oFile = TestFileSet.GstFile(oParent, sFile, abContent); 1075 self.aoFiles.append(oFile); 1076 self.dPaths[sFile] = oFile; 1077 return oFile; 1078 1079 def __createFilename(self, oParent, sCharset, sReservedTrailing): 1080 """ 1081 Creates a filename contains random characters from sCharset and together 1082 with oParent.sPath doesn't exceed 230 chars in length. 1083 """ 1084 cchMaxName = self.cchMaxPath - len(oParent.sPath) - 1; 1085 if cchMaxName > self.cchMaxName: 1086 cchMaxName = self.cchMaxName; 1087 if cchMaxName <= 1: 1088 cchMaxName = 2; 1089 1090 while True: 1091 cchName = self.oRandom.randrange(1, cchMaxName); 1092 sName = ''.join(self.oRandom.choice(sCharset) for _ in xrange(cchName)); 1093 if oParent is None or not oParent.contains(sName): 1094 if sName[-1] not in sReservedTrailing: 1095 if sName not in ('.', '..',): 1096 return sName; 1097 return ''; # never reached, but makes pylint happy. 1098 1099 def __createTestStuff(self): 1100 """ 1101 Create a random file set that we can work on in the tests. 1102 Returns True/False. 1103 """ 1104 1105 # Create the root test dir. 1106 sRoot = self.oTestVm.pathJoinEx(self.sBasePath, self.sSubDir); 1107 self.oRoot = self.__createTestDir(None, sRoot); 1108 self.oEmptyDir = self.__createTestDir(self.oRoot, self.oTestVm.pathJoinEx(sRoot, 'empty')); 1109 1110 # Create a directory with about files in it using the guest specific charset: 1111 oDir = self.__createTestDir(self.oRoot, self.oTestVm.pathJoinEx(sRoot, 'many')); 1112 self.oManyDir = oDir; 1113 cManyFiles = self.oRandom.choice(self.oRngManyFiles); 1114 for _ in xrange(cManyFiles): 1115 sName = self.__createFilename(oDir, self.sFileCharset, self.sReservedTrailing); 1116 self.__createTestFile(oDir, self.oTestVm.pathJoinEx(oDir.sPath, sName)); 1117 1118 # Generate a tree of files and dirs. Portable character set. 1119 oDir = self.__createTestDir(self.oRoot, self.oTestVm.pathJoinEx(sRoot, 'tree')); 1120 uMaxDepth = self.oRandom.choice(self.oRngTreeDepth); 1121 cMaxFiles = self.oRandom.choice(self.oRngTreeFiles); 1122 cMaxDirs = self.oRandom.choice(self.oRngTreeDirs); 1123 self.oTreeDir = oDir; 1124 self.cTreeFiles = 0; 1125 self.cTreeDirs = 0; 1126 uDepth = 0; 1127 while self.cTreeFiles < cMaxFiles and self.cTreeDirs < cMaxDirs: 1128 iAction = self.oRandom.randrange(0, 2+1); 1129 # 0: Add a file: 1130 if iAction == 0 and self.cTreeFiles < cMaxFiles and len(oDir.sPath) < 230 - 2: 1131 sName = self.__createFilename(oDir, self.sFileCharsetCommon, self.sReservedTrailingCommon); 1132 self.__createTestFile(oDir, self.oTestVm.pathJoinEx(oDir.sPath, sName)); 1133 self.cTreeFiles += 1; 1134 # 1: Add a subdirector and descend into it (trailing space is okay here): 1135 elif iAction == 1 and self.cTreeDirs < cMaxDirs and uDepth < uMaxDepth and len(oDir.sPath) < 220: 1136 sName = self.__createFilename(oDir, self.sFileCharsetCommon, self.sReservedTrailingCommon[1:]); 1137 oDir = self.__createTestDir(oDir, self.oTestVm.pathJoinEx(oDir.sPath, sName)); 1138 self.cTreeDirs += 1; 1139 uDepth += 1; 1140 # 2: Ascend to parent dir: 1141 elif iAction == 2 and uDepth > 0: 1142 oDir = oDir.oParent; 1143 uDepth -= 1; 1144 1145 return True; 1146 1147 def createTarball(self, sTarFileHst): 1148 """ 1149 Creates a tarball on the host. 1150 Returns success indicator. 1151 """ 1152 reporter.log('Creating tarball "%s" with test files for the guest...' % (sTarFileHst,)); 1153 1154 chOtherSlash = '\\' if self.oTestVm.isWindows() or self.oTestVm.isOS2() else '/'; 1155 cchSkip = len(self.sBasePath) + 1; 1156 1157 # Open the tarball: 1158 try: 1159 oTarFile = tarfile.open(sTarFileHst, 'w:gz'); 1160 except: 1161 return reporter.errorXcpt('Failed to open new tar file: %s' % (sTarFileHst,)); 1162 1163 # Directories: 1164 for oDir in self.aoDirs: 1165 oTarInfo = tarfile.TarInfo(oDir.sPath[cchSkip:].replace(chOtherSlash, '/') + '/'); 1166 oTarInfo.mode = 0o777; 1167 oTarInfo.type = tarfile.DIRTYPE; 1168 try: 1169 oTarFile.addfile(oTarInfo); 1170 except: 1171 return reporter.errorXcpt('Failed adding directory tarfile: %s' % (oDir.sPath,)); 1172 1173 # Files: 1174 for oFile in self.aoFiles: 1175 oTarInfo = tarfile.TarInfo(oFile.sPath[cchSkip:].replace(chOtherSlash, '/')); 1176 oTarInfo.size = len(oFile.abContent); 1177 oFile.off = 0; 1178 try: 1179 oTarFile.addfile(oTarInfo, oFile); 1180 except: 1181 return reporter.errorXcpt('Failed adding directory tarfile: %s' % (oFile.sPath,)); 1182 1183 # Complete the tarball. 1184 try: 1185 oTarFile.close(); 1186 except: 1187 return reporter.errorXcpt('Error closing new tar file: %s' % (sTarFileHst,)); 1188 return True; 1189 1190 def __uploadFallback(self, oTxsSession, sTarFileGst, oTstDrv): 1191 """ 1192 Fallback upload method. 1193 """ 1194 1195 ## Directories: 1196 #for oDir in self.aoDirs: 1197 # if oTxsSession.syncMkDirPath(oDir.sPath, 0o777) is not True: 1198 # return reporter.error('Failed to create directory "%s"!' % (oDir.sPath,)); 1199 # 1200 ## Files: 1201 #for oFile in self.aoFiles: 1202 # if oTxsSession.syncUploadString(oFile.abContent, oFile.sPath) is not True: 1203 # return reporter.error('Failed to create file "%s" with %s content bytes!' % (oFile.sPath, oFile.cbContent)); 1204 1205 sVtsTarExe = 'vts_tar' + self.oTestVm.getGuestExeSuff(); 1206 sVtsTarHst = os.path.join(oTstDrv.sVBoxValidationKit, self.oTestVm.getGuestOs(), 1207 self.oTestVm.getGuestArch(), sVtsTarExe); 1208 sVtsTarGst = self.oTestVm.pathJoinEx(self.sBasePath, sVtsTarExe); 1209 1210 if oTxsSession.syncUploadFile(sVtsTarHst, sVtsTarGst) is not True: 1211 return reporter.error('Failed to upload "%s" to the guest as "%s"!' % (sVtsTarHst, sVtsTarGst,)); 1212 1213 fRc = oTxsSession.syncExec(sVtsTarGst, [sVtsTarGst, '-xzf', sTarFileGst, '-C', self.sBasePath,], fWithTestPipe = False); 1214 if fRc is not True: 1215 return reporter.error('vts_tar failed!'); 1216 return True; 1217 1218 def upload(self, oTxsSession, oTstDrv): 1219 """ 1220 Uploads the files into the guest via the given TXS session. 1221 1222 Returns True / False. 1223 """ 1224 1225 # 1226 # Create a tarball. 1227 # 1228 sTarFileHst = os.path.join(oTstDrv.sScratchPath, 'tdAddGuestCtrl-1-Stuff.tar.gz'); 1229 sTarFileGst = self.oTestVm.pathJoinEx(self.sBasePath, 'tdAddGuestCtrl-1-Stuff.tar.gz'); 1230 if self.createTarball(sTarFileHst) is not True: 1231 return False; 1232 1233 # 1234 # Upload it. 1235 # 1236 reporter.log('Uploading tarball "%s" to the guest as "%s"...' % (sTarFileHst, sTarFileGst)); 1237 if oTxsSession.syncUploadFile(sTarFileHst, sTarFileGst) is not True: 1238 return reporter.error('Failed upload tarball "%s" as "%s"!' % (sTarFileHst, sTarFileGst,)); 1239 1240 # 1241 # Try unpack it. 1242 # 1243 reporter.log('Unpacking "%s" into "%s"...' % (sTarFileGst, self.sBasePath)); 1244 if oTxsSession.syncUnpackFile(sTarFileGst, self.sBasePath, fIgnoreErrors = True) is not True: 1245 reporter.log('Failed to expand tarball "%s" into "%s", falling back on individual directory and file creation...' 1246 % (sTarFileGst, self.sBasePath,)); 1247 if self.__uploadFallback(oTxsSession, sTarFileGst, oTstDrv) is not True: 1248 return False; 1249 reporter.log('Successfully placed test files and directories in the VM.'); 1250 return True; 966 1251 967 1252 … … 986 1271 self.asTests = self.asTestsDef; 987 1272 self.asRsrcs = ['5.3/guestctrl/50mb_rnd.dat', ]; 988 989 # Directories and files placed in the guest temp area by prepareGuestForTesting. 990 self.oTestRoot = None # type: GstFsDir; ##< The root directory. 991 self.oTestEmptyDir = None # type: GstFsDir; ##< Empty directory. 992 self.oTestManyDir = None # type: GstFsDir; ##< A directory with a few files in it (around 100) 993 self.oTestTreeDir = None # type: GstFsDir; ##< A directory with a mixed tree structure under it. 994 self.cTestTreeFiles = 0; ##< Number of files in oTestTreeDir. 995 self.cTestTreeDirs = 0; ##< Number of directories under oTestTreeDir. 996 997 self.aoTestDirs = [] # type: list(GstFsDir); 998 self.aoTestFiles = [] # type: list(GstFsFile); 999 self.dTestPaths = {} # type: dict(str, GstFsFile); 1273 self.oTestFiles = None # type: TestFileSet 1000 1274 1001 1275 def parseOption(self, asArgs, iArg): # pylint: disable=too-many-branches,too-many-statements … … 1142 1416 # 1143 1417 1144 ## @todo separate this out into a separate class. This one is way to big and this may be handy for to reuse.1145 1146 def __createTestDir(self, oParent, sDir):1147 """1148 Creates a test directory.1149 """1150 oDir = GstFsDir(oParent, sDir);1151 self.aoTestDirs.append(oDir);1152 self.dTestPaths[sDir] = oDir;1153 return oDir;1154 1155 def __createTestFile(self, oParent, sFile, oRandom, cbMaxContent):1156 """1157 Creates a test file with random size up to cbMaxContent and random content.1158 """1159 cbFile = oRandom.randrange(0, cbMaxContent);1160 abContent = bytearray(oRandom.getrandbits(8) for _ in xrange(cbFile));1161 1162 oFile = GstFsFile(oParent, sFile, abContent);1163 self.aoTestFiles.append(oFile);1164 self.dTestPaths[sFile] = oFile;1165 return oFile;1166 1167 @staticmethod1168 def __createFilename(oParent, oRandom, sCharset, sReservedTrailing):1169 """1170 Creates a filename contains random characters from sCharset and together1171 with oParent.sPath doesn't exceed 230 chars in length.1172 """1173 while True:1174 cchName = oRandom.randrange(1, 230 - len(oParent.sPath));1175 sName = ''.join(oRandom.choice(sCharset) for _ in xrange(cchName));1176 if oParent is None or not oParent.contains(sName):1177 if sName[-1] not in sReservedTrailing:1178 if sName not in ('.', '..',):1179 return sName;1180 1181 def __createTestStuff(self, oTestVm):1182 """1183 Create a random file set that we can work on in the tests.1184 Returns True/False.1185 """1186 1187 # Zap anything left over from a previous run.1188 for oFile in self.aoTestDirs:1189 oFile.oParent = None;1190 for oFile in self.aoTestFiles:1191 oFile.oParent = None;1192 oFile.abContent = None;1193 self.oTestRoot = None;1194 self.oTestEmptyDir = None;1195 self.oTestManyDir = None;1196 self.oTestTreeDir = None;1197 self.cTestTreeFiles = 0;1198 self.cTestTreeDirs = 0;1199 self.aoTestDirs = [];1200 self.aoTestFiles = [];1201 self.dTestPaths = {};1202 1203 # See random.1204 uSeed = utils.timestampMilli();1205 reporter.log('prepareGuestForTesting: random seed %s' % (uSeed,));1206 oRandom = random.Random();1207 oRandom.seed(uSeed);1208 1209 # filename characters:1210 ksReservedWinOS2 = '/\\"*:<>?|\t\v\n\r\f\a\b';1211 ksReservedUnix = '/';1212 ksReservedTrailingWinOS2 = ' .'; # The space is tar's fault. Must be first.1213 ksReservedTrailingUnix = ' ';1214 sFileCharset = string.printable;1215 sFileCharsetCommon = string.printable;1216 sReservedTrailingCommon = ksReservedTrailingWinOS2;1217 1218 if oTestVm.isWindows() or oTestVm.isOS2():1219 sReservedTrailing = ksReservedTrailingWinOS2;1220 for ch in ksReservedWinOS2:1221 sFileCharset = sFileCharset.replace(ch, '');1222 else:1223 sReservedTrailing = ksReservedTrailingUnix;1224 for ch in ksReservedUnix:1225 sFileCharset = sFileCharset.replace(ch, '');1226 sFileCharset += ' ...';1227 1228 for ch in ksReservedWinOS2:1229 sFileCharsetCommon = sFileCharset.replace(ch, '');1230 sFileCharsetCommon += ' ...';1231 1232 # Create the root test dir.1233 sRoot = oTestVm.pathJoinEx(self.getGuestTempDir(oTestVm), 'addgst-1');1234 self.oTestRoot = self.__createTestDir(None, sRoot);1235 self.oTestEmptyDir = self.__createTestDir(self.oTestRoot, oTestVm.pathJoinEx(sRoot, 'empty'));1236 1237 # Create a directory with about files in it using the guest specific charset:1238 oDir = self.__createTestDir(self.oTestRoot, oTestVm.pathJoinEx(sRoot, 'many'));1239 self.oTestManyDir = oDir;1240 cManyFiles = oRandom.randrange(92, 128);1241 for _ in xrange(cManyFiles):1242 sName = self.__createFilename(oDir, oRandom, sFileCharset, sReservedTrailing);1243 self.__createTestFile(oDir, oTestVm.pathJoinEx(oDir.sPath, sName), oRandom, 16384);1244 1245 # Generate a tree of files and dirs. 2-16 levels deep. Portable character set.1246 cMaxFiles = oRandom.randrange(128, 384);1247 cMaxDirs = oRandom.randrange(92, 256);1248 uMaxDepth = oRandom.randrange(2, 16);1249 oDir = self.__createTestDir(self.oTestRoot, oTestVm.pathJoinEx(sRoot, 'tree'));1250 self.oTestTreeDir = oDir;1251 self.cTestTreeFiles = 0;1252 self.cTestTreeDirs = 0;1253 uDepth = 0;1254 while self.cTestTreeFiles < cMaxFiles and self.cTestTreeDirs < cMaxDirs:1255 iAction = oRandom.randrange(0, 2+1);1256 # 0: Add a file:1257 if iAction == 0 and self.cTestTreeFiles < cMaxFiles and len(oDir.sPath) < 230 - 2:1258 sName = self.__createFilename(oDir, oRandom, sFileCharsetCommon, sReservedTrailingCommon[1:]); # trailing space ok1259 self.__createTestFile(oDir, oTestVm.pathJoinEx(oDir.sPath, sName), oRandom, 16384);1260 self.cTestTreeFiles += 1;1261 # 1: Add a subdirector and descend into it:1262 elif iAction == 1 and self.cTestTreeDirs < cMaxDirs and uDepth < uMaxDepth and len(oDir.sPath) < 220:1263 sName = self.__createFilename(oDir, oRandom, sFileCharsetCommon, sReservedTrailingCommon);1264 oDir = self.__createTestDir(oDir, oTestVm.pathJoinEx(oDir.sPath, sName));1265 self.cTestTreeDirs += 1;1266 uDepth += 1;1267 # 2: Ascend to parent dir:1268 elif iAction == 2 and uDepth > 0:1269 oDir = oDir.oParent;1270 uDepth -= 1;1271 1272 return True;1273 1274 1275 def __uploadTestStuffsFallback(self, oTxsSession, oTestVm, sTarFileGst, sTempDirGst):1276 """1277 Fallback upload method.1278 """1279 1280 ## Directories:1281 #for oDir in self.aoTestDirs:1282 # if oTxsSession.syncMkDirPath(oDir.sPath, 0o777) is not True:1283 # return reporter.error('Failed to create directory "%s"!' % (oDir.sPath,));1284 #1285 ## Files:1286 #for oFile in self.aoTestFiles:1287 # if oTxsSession.syncUploadString(oFile.abContent, oFile.sPath) is not True:1288 # return reporter.error('Failed to create file "%s" with %s content bytes!' % (oFile.sPath, oFile.cbContent));1289 1290 sVtsTarExe = 'vts_tar' + oTestVm.getGuestExeSuff();1291 sVtsTarHst = os.path.join(self.oTstDrv.sVBoxValidationKit, oTestVm.getGuestOs(), oTestVm.getGuestArch(), sVtsTarExe);1292 sVtsTarGst = oTestVm.pathJoinEx(sTempDirGst, sVtsTarExe);1293 1294 if oTxsSession.syncUploadFile(sVtsTarHst, sVtsTarGst) is not True:1295 return reporter.error('Failed to upload "%s" to the guest as "%s"!' % (sVtsTarHst, sVtsTarGst,));1296 1297 fRc = oTxsSession.syncExec(sVtsTarGst, [sVtsTarGst, '-xzf', sTarFileGst, '-C', sTempDirGst,], fWithTestPipe = False);1298 if fRc is not True:1299 return reporter.error('vts_tar failed!');1300 return True;1301 1302 def __uploadTestStuff(self, oTxsSession, oTestVm):1303 """1304 Primary upload method.1305 """1306 1307 #1308 # Create a tarball.1309 #1310 sTempDirGst = self.getGuestTempDir(oTestVm);1311 sTarFileHst = os.path.join(self.oTstDrv.sScratchPath, 'tdAddGuestCtrl-1-Stuff.tar.gz');1312 sTarFileGst = oTestVm.pathJoinEx(sTempDirGst, 'tdAddGuestCtrl-1-Stuff.tar.gz');1313 chOtherSlash = '\\' if oTestVm.isWindows() or oTestVm.isOS2() else '/';1314 cchSkip = len(sTempDirGst) + 1;1315 1316 reporter.log('Creating tarball "%s" with test files for the guest...' % (sTarFileHst,));1317 1318 # Open the tarball:1319 try:1320 oTarFile = tarfile.open(sTarFileHst, 'w:gz');1321 except:1322 return reporter.errorXcpt('Failed to open new tar file: %s' % (sTarFileHst,));1323 1324 # Directories:1325 for oDir in self.aoTestDirs:1326 oTarInfo = tarfile.TarInfo(oDir.sPath[cchSkip:].replace(chOtherSlash, '/') + '/');1327 oTarInfo.mode = 0o777;1328 oTarInfo.type = tarfile.DIRTYPE;1329 try:1330 oTarFile.addfile(oTarInfo);1331 except:1332 return reporter.errorXcpt('Failed adding directory tarfile: %s' % (oDir.sPath,));1333 1334 # Files:1335 for oFile in self.aoTestFiles:1336 oTarInfo = tarfile.TarInfo(oFile.sPath[cchSkip:].replace(chOtherSlash, '/'));1337 oTarInfo.size = len(oFile.abContent);1338 oFile.off = 0;1339 try:1340 oTarFile.addfile(oTarInfo, oFile);1341 except:1342 return reporter.errorXcpt('Failed adding directory tarfile: %s' % (oFile.sPath,));1343 1344 # Complete the tarball.1345 try:1346 oTarFile.close();1347 except:1348 return reporter.errorXcpt('Error closing new tar file: %s' % (sTarFileHst,));1349 1350 #1351 # Upload it.1352 #1353 reporter.log('Uploading tarball "%s" to the guest as "%s"...' % (sTarFileHst, sTarFileGst));1354 if oTxsSession.syncUploadFile(sTarFileHst, sTarFileGst) is not True:1355 return reporter.error('Failed upload tarball "%s" as "%s"!' % (sTarFileHst, sTarFileGst,));1356 1357 #1358 # Try unpack it.1359 #1360 reporter.log('Unpacking "%s" into "%s"...' % (sTarFileGst, sTempDirGst));1361 if oTxsSession.syncUnpackFile(sTarFileGst, sTempDirGst, fIgnoreErrors = True) is not True:1362 reporter.log('Failed to expand tarball "%s" into "%s", falling back on individual directory and file creation...'1363 % (sTarFileGst, sTempDirGst,));1364 if self.__uploadTestStuffsFallback(oTxsSession, oTestVm, sTarFileGst, sTempDirGst) is not True:1365 return False;1366 reporter.log('Successfully placed test files and directories in the VM.');1367 return True;1368 1369 1418 def prepareGuestForTesting(self, oSession, oTxsSession, oTestVm): 1370 1419 """ … … 1384 1433 1385 1434 # Generate and upload some random files and dirs to the guest: 1386 if self.__createTestStuff(oTestVm) is not True: 1387 return False; 1388 return self.__uploadTestStuff(oTxsSession, oTestVm); 1435 self.oTestFiles = TestFileSet(oTestVm, self.getGuestTempDir(oTestVm), 'addgst-1'); 1436 return self.oTestFiles.upload(oTxsSession, self.oTstDrv); 1389 1437 1390 1438
Note:
See TracChangeset
for help on using the changeset viewer.