VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/teleportation/tdTeleportLocal1.py@ 69111

Last change on this file since 69111 was 69111, checked in by vboxsync, 7 years ago

(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: 42.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdTeleportLocal1.py 69111 2017-10-17 14:26:02Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Local teleportation testdriver.
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2017 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 69111 $"
31
32
33# Standard Python imports.
34import os;
35import sys;
36
37# Only the main script needs to modify the path.
38try: __file__
39except: __file__ = sys.argv[0];
40g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
41sys.path.append(g_ksValidationKitDir);
42
43# Validation Kit imports.
44from testdriver import reporter;
45from testdriver import base;
46from testdriver import vbox;
47
48
49class tdTeleportLocal1(vbox.TestDriver):
50 """
51 Local Teleportation Test #1.
52 """
53
54 def __init__(self):
55 vbox.TestDriver.__init__(self);
56 self.asRsrcs = None;
57
58 self.asTestsDef = ['test1', 'test2'];
59 self.asTests = ['test1', 'test2'];
60 self.asSkipTests = [];
61 self.asTestVMsDef = ['tst-rhel5', 'tst-win2k3ent', 'tst-sol10'];
62 self.asTestVMs = self.asTestVMsDef;
63 self.asSkipVMs = [];
64 self.asVirtModesDef = ['hwvirt', 'hwvirt-np', 'raw',]
65 self.asVirtModes = self.asVirtModesDef
66 self.acCpusDef = [1, 2,]
67 self.acCpus = self.acCpusDef;
68
69 #
70 # Overridden methods.
71 #
72 def showUsage(self):
73 rc = vbox.TestDriver.showUsage(self);
74 reporter.log('');
75 reporter.log('tdTeleportLocal1 Options:');
76 reporter.log(' --virt-modes <m1[:m2[:]]');
77 reporter.log(' Default: %s' % (':'.join(self.asVirtModesDef)));
78 reporter.log(' --cpu-counts <c1[:c2[:]]');
79 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.acCpusDef)));
80 reporter.log(' --test-vms <vm1[:vm2[:...]]>');
81 reporter.log(' Test the specified VMs in the given order. Use this to change');
82 reporter.log(' the execution order or limit the choice of VMs');
83 reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));
84 reporter.log(' --skip-vms <vm1[:vm2[:...]]>');
85 reporter.log(' Skip the specified VMs when testing.');
86 reporter.log(' --tests <test1[:test2[:...]]>');
87 reporter.log(' Run the specified tests.');
88 reporter.log(' Default: %s (all)' % (':'.join(self.asTestsDef)));
89 reporter.log(' --skip-tests <test1[:test2[:...]]>');
90 reporter.log(' Skip the specified VMs when testing.');
91 reporter.log(' --quick');
92 reporter.log(' Shorthand for: --virt-modes hwvirt --cpu-counts 1');
93 reporter.log(' --test-vms tst-rhel5:tst-win2k3ent:tst-sol10');
94 return rc;
95
96 def parseOption(self, asArgs, iArg):
97 if asArgs[iArg] == '--virt-modes':
98 iArg += 1;
99 if iArg >= len(asArgs): raise base.InvalidOption('The "--virt-modes" takes a colon separated list of modes');
100 self.asVirtModes = asArgs[iArg].split(':');
101 for s in self.asVirtModes:
102 if s not in self.asVirtModesDef:
103 raise base.InvalidOption('The "--virt-modes" value "%s" is not valid; valid values are: %s' \
104 % (s, ' '.join(self.asVirtModesDef)));
105 elif asArgs[iArg] == '--cpu-counts':
106 iArg += 1;
107 if iArg >= len(asArgs): raise base.InvalidOption('The "--cpu-counts" takes a colon separated list of cpu counts');
108 self.acCpus = [];
109 for s in asArgs[iArg].split(':'):
110 try: c = int(s);
111 except: raise base.InvalidOption('The "--cpu-counts" value "%s" is not an integer' % (s,));
112 if c <= 0: raise base.InvalidOption('The "--cpu-counts" value "%s" is zero or negative' % (s,));
113 self.acCpus.append(c);
114 elif asArgs[iArg] == '--test-vms':
115 iArg += 1;
116 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');
117 if asArgs[iArg]:
118 self.asTestVMs = asArgs[iArg].split(':');
119 for s in self.asTestVMs:
120 if s not in self.asTestVMsDef:
121 raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \
122 % (s, ' '.join(self.asTestVMsDef)));
123 else:
124 self.asTestVMs = [];
125 elif asArgs[iArg] == '--skip-vms':
126 iArg += 1;
127 if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');
128 self.asSkipVMs = asArgs[iArg].split(':');
129 for s in self.asSkipVMs:
130 if s not in self.asTestVMsDef:
131 reporter.log('warning: The "--skip-vms" value "%s" does not specify any of our test VMs.' % (s));
132 elif asArgs[iArg] == '--tests':
133 iArg += 1;
134 if iArg >= len(asArgs): raise base.InvalidOption('The "--tests" takes colon separated list');
135 self.asTests = asArgs[iArg].split(':');
136 for s in self.asTests:
137 if s not in self.asTestsDef:
138 reporter.log('warning: The "--tests" value "%s" does not specify any of our tests.' % (s));
139 elif asArgs[iArg] == '--skip-tests':
140 iArg += 1;
141 if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-tests" takes colon separated list');
142 self.asSkipVMs = asArgs[iArg].split(':');
143 for s in self.asSkipTests:
144 if s not in self.asTestsDef:
145 reporter.log('warning: The "--skip-tests" value "%s" does not specify any of our tests.' % (s));
146 elif asArgs[iArg] == '--quick':
147 self.asVirtModes = ['hwvirt',];
148 self.acCpus = [1,];
149 #self.asTestVMs = ['tst-rhel5', 'tst-win2k3ent', 'tst-sol10',];
150 self.asTestVMs = ['tst-rhel5', ];
151 else:
152 return vbox.TestDriver.parseOption(self, asArgs, iArg);
153 return iArg + 1;
154
155 def completeOptions(self):
156 # Remove skipped VMs from the test VM list.
157 for sVM in self.asSkipVMs:
158 try: self.asTestVMs.remove(sVM);
159 except: pass;
160
161 # Remove skipped tests from the test list.
162 for sTest in self.asSkipTests:
163 try: self.asTests.remove(sTest);
164 except: pass;
165
166 # If no test2, then no test VMs.
167 if 'test2' not in self.asTests:
168 self.asTestVMs = [];
169
170 return vbox.TestDriver.completeOptions(self);
171
172 def getResourceSet(self):
173 # Construct the resource list the first time it's queried.
174 if self.asRsrcs is None:
175 self.asRsrcs = [];
176 if 'tst-rhel5' in self.asTestVMs:
177 self.asRsrcs.append('3.0/tcp/rhel5.vdi');
178 if 'tst-rhel5-64' in self.asTestVMs:
179 self.asRsrcs.append('3.0/tcp/rhel5-64.vdi');
180 if 'tst-sles11' in self.asTestVMs:
181 self.asRsrcs.append('3.0/tcp/sles11.vdi');
182 if 'tst-sles11-64' in self.asTestVMs:
183 self.asRsrcs.append('3.0/tcp/sles11-64.vdi');
184 if 'tst-oel' in self.asTestVMs:
185 self.asRsrcs.append('3.0/tcp/oel.vdi');
186 if 'tst-oel-64' in self.asTestVMs:
187 self.asRsrcs.append('3.0/tcp/oel-64.vdi');
188 if 'tst-win2k3ent' in self.asTestVMs:
189 self.asRsrcs.append('3.0/tcp/win2k3ent-acpi.vdi');
190 if 'tst-win2k3ent-64' in self.asTestVMs:
191 self.asRsrcs.append('3.0/tcp/win2k3ent-64.vdi');
192 if 'tst-win2k8' in self.asTestVMs:
193 self.asRsrcs.append('3.0/tcp/win2k8.vdi');
194 if 'tst-sol10' in self.asTestVMs:
195 self.asRsrcs.append('3.0/tcp/solaris10.vdi');
196 if 'tst-sol11' in self.asTestVMs:
197 self.asRsrcs.append('3.0/tcp/solaris11.vdi');
198 return self.asRsrcs;
199
200 def actionConfig(self):
201 ## @todo actionConfig() and getResourceSet() are working on the same
202 # set of VMs as tdNetBenchmark1, creating common base class would be
203 # a good idea.
204
205 # Some stupid trickery to guess the location of the iso. ## fixme - testsuite unzip ++
206 sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
207 if not os.path.isfile(sVBoxValidationKit_iso):
208 sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
209 if not os.path.isfile(sVBoxValidationKit_iso):
210 sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/validationkit/VBoxValidationKit.iso';
211 if not os.path.isfile(sVBoxValidationKit_iso):
212 sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/testsuite/VBoxTestSuite.iso';
213 if not os.path.isfile(sVBoxValidationKit_iso):
214 sCur = os.getcwd();
215 for i in range(0, 10):
216 sVBoxValidationKit_iso = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
217 if os.path.isfile(sVBoxValidationKit_iso):
218 break;
219 sVBoxValidationKit_iso = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
220 if os.path.isfile(sVBoxValidationKit_iso):
221 break;
222 sCur = os.path.abspath(os.path.join(sCur, '..'));
223 if i is not None: pass; # shut up pychecker/pylint.
224 if not os.path.isfile(sVBoxValidationKit_iso):
225 sVBoxValidationKit_iso = '/home/bird/validationkit/VBoxValidationKit.iso';
226 if not os.path.isfile(sVBoxValidationKit_iso):
227 sVBoxValidationKit_iso = '/home/bird/testsuite/VBoxTestSuite.iso';
228
229 # Make sure vboxapi has been imported so we can use the constants.
230 if not self.importVBoxApi():
231 return False;
232
233 #
234 # Configure the empty VMs we're going to use for the first tests.
235 #
236
237 if 'test1' in self.asTests:
238 #oVM = self.createTestVMs('tst-empty-hwvirt', 0, sKind = 'Other', fVirtEx = True);
239 #if oVM is None:
240 # return False;
241
242 oVM = self.createTestVMs('tst-empty-raw', 2, sKind = 'Other', fVirtEx = False);
243 if oVM is None:
244 return False;
245
246 #
247 # Configure the VMs we're going to use for the last test.
248 #
249
250 # Linux VMs
251 if 'tst-rhel5' in self.asTestVMs:
252 oVM = self.createTestVMs('tst-rhel5', 1, '3.0/tcp/rhel5.vdi', sKind = 'RedHat', fIoApic = True, \
253 sDvdImage = sVBoxValidationKit_iso);
254 if oVM is None:
255 return False;
256
257 if 'tst-rhel5-64' in self.asTestVMs:
258 oVM = self.createTestVMs('tst-rhel5-64', 1, '3.0/tcp/rhel5-64.vdi', sKind = 'RedHat_64', \
259 sDvdImage = sVBoxValidationKit_iso);
260 if oVM is None:
261 return False;
262
263 if 'tst-sles11' in self.asTestVMs:
264 oVM = self.createTestVMs('tst-sles11', 1, '3.0/tcp/sles11.vdi', sKind = 'OpenSUSE', fIoApic = True, \
265 sDvdImage = sVBoxValidationKit_iso);
266 if oVM is None:
267 return False;
268
269 if 'tst-sles11-64' in self.asTestVMs:
270 oVM = self.createTestVMs('tst-sles11-64', 1, '3.0/tcp/sles11-64.vdi', sKind = 'OpenSUSE_64', \
271 sDvdImage = sVBoxValidationKit_iso);
272 if oVM is None:
273 return False;
274
275 if 'tst-oel' in self.asTestVMs:
276 oVM = self.createTestVMs('tst-oel', 1, '3.0/tcp/oel.vdi', sKind = 'Oracle', fIoApic = True, \
277 sDvdImage = sVBoxValidationKit_iso);
278 if oVM is None:
279 return False;
280
281 if 'tst-oel-64' in self.asTestVMs:
282 oVM = self.createTestVMs('tst-oel-64', 1, '3.0/tcp/oel-64.vdi', sKind = 'Oracle_64', \
283 sDvdImage = sVBoxValidationKit_iso);
284 if oVM is None:
285 return False;
286
287 # Windows VMs
288 if 'tst-win2k3ent' in self.asTestVMs:
289 oVM = self.createTestVMs('tst-win2k3ent', 1, '3.0/tcp/win2k3ent-acpi.vdi', sKind = 'Windows2003', \
290 sDvdImage = sVBoxValidationKit_iso);
291 if oVM is None:
292 return False;
293
294 if 'tst-win2k3ent-64' in self.asTestVMs:
295 oVM = self.createTestVMs('tst-win2k3ent-64', 1, '3.0/tcp/win2k3ent-64.vdi', sKind = 'Windows2003_64', \
296 sDvdImage = sVBoxValidationKit_iso);
297 if oVM is None:
298 return False;
299
300 if 'tst-win2k8' in self.asTestVMs:
301 oVM = self.createTestVMs('tst-win2k8', 1, '3.0/tcp/win2k8.vdi', sKind = 'Windows2008_64', \
302 sDvdImage = sVBoxValidationKit_iso);
303 if oVM is None:
304 return False;
305
306 # Solaris VMs
307 if 'tst-sol10' in self.asTestVMs:
308 oVM = self.createTestVMs('tst-sol10', 1, '3.0/tcp/solaris10.vdi', sKind = 'Solaris_64', \
309 sDvdImage = sVBoxValidationKit_iso);
310 if oVM is None:
311 return False;
312
313 if 'tst-sol11' in self.asTestVMs:
314 oVM = self.createTestVMs('tst-sol11', 1, '3.0/tcp/os2009-11.vdi', sKind = 'Solaris_64', \
315 sDvdImage = sVBoxValidationKit_iso);
316 if oVM is None:
317 return False;
318
319 return True;
320
321 def actionExecute(self):
322 """
323 Execute the testcase.
324 """
325 fRc = 'test1' not in self.asTests or self.test1();
326 if fRc: fRc = 'test2' not in self.asTests or self.test2();
327 return fRc;
328
329
330 #
331 # Test config helpers.
332 #
333
334 def createTestVMs(self, sName, iGroup, *tArgs, **dKeywordArgs):
335 """
336 Wrapper around vbox.createTestVM for creating two VMs, the source
337 (sName-1) and target (sName-2).
338
339 Returns the 2nd VM object on success, None on failure.
340 """
341 sName1 = sName + '-1';
342 oVM = self.createTestVM(sName1, iGroup * 2, *tArgs, **dKeywordArgs);
343 if oVM is not None:
344 sName2 = sName + '-2';
345 oVM = self.createTestVM(sName2, iGroup * 2 + 1, *tArgs, **dKeywordArgs);
346 return oVM;
347
348
349 #
350 # Test execution helpers.
351 #
352
353 def test2Teleport(self, oVmSrc, oSessionSrc, oVmDst):
354 """
355 Attempts a teleportation.
356
357 Returns the input parameters for the next test2Teleport call (source
358 and destiation are switched around). The input session is closed and
359 removed from the task list, while the return session is in the list.
360 """
361
362 # Enable the teleporter of the VM.
363 oSession = self.openSession(oVmDst);
364 fRc = oSession is not None
365 if fRc:
366 fRc = oSession.enableTeleporter();
367 fRc = fRc and oSession.saveSettings();
368 fRc = oSession.close() and fRc and True; # pychecker hack.
369 if fRc:
370 # Start the destination VM.
371 oSessionDst, oProgressDst = self.startVmEx(oVmDst, fWait = False);
372 if oSessionDst is not None:
373 if oProgressDst.waitForOperation(iOperation = -3) == 0:
374
375 # Do the teleportation.
376 try:
377 uDstPort = oVmDst.teleporterPort;
378 except:
379 reporter.logXcpt();
380 uDstPort = 6502;
381 oProgressSrc = oSessionSrc.teleport('localhost', uDstPort, 'password', 1024);
382 if oProgressSrc is not None:
383 oProgressSrc.wait();
384 if oProgressSrc.isSuccess():
385 oProgressDst.wait();
386 if oProgressSrc.isSuccess() and oProgressDst.isSuccess():
387
388 # Terminate the source VM.
389 self.terminateVmBySession(oSessionSrc, oProgressSrc);
390
391 # Return with the source and destination swapped.
392 return oVmDst, oSessionDst, oVmSrc;
393
394 # Failure / bail out.
395 oProgressSrc.logResult();
396 oProgressDst.logResult();
397 self.terminateVmBySession(oSessionDst, oProgressDst);
398 return oVmSrc, oSessionSrc, oVmDst;
399
400 def test2OneCfg(self, sVmBaseName, cCpus, fHwVirt, fNestedPaging):
401 """
402 Runs the specified VM thru test #1.
403 """
404
405 # Reconfigure the source VM.
406 oVmSrc = self.getVmByName(sVmBaseName + '-1');
407 fRc = True;
408 oSession = self.openSession(oVmSrc);
409 if oSession is not None:
410 fRc = fRc and oSession.enableVirtEx(fHwVirt);
411 fRc = fRc and oSession.enableNestedPaging(fNestedPaging);
412 fRc = fRc and oSession.setCpuCount(cCpus);
413 fRc = fRc and oSession.setupTeleporter(False, uPort=6501, sPassword='password');
414 fRc = fRc and oSession.saveSettings();
415 fRc = oSession.close() and fRc and True; # pychecker hack.
416 oSession = None;
417 else:
418 fRc = False;
419
420 # Reconfigure the destination VM.
421 oVmDst = self.getVmByName(sVmBaseName + '-2');
422 oSession = self.openSession(oVmDst);
423 if oSession is not None:
424 fRc = fRc and oSession.enableVirtEx(fHwVirt);
425 fRc = fRc and oSession.enableNestedPaging(fNestedPaging);
426 fRc = fRc and oSession.setCpuCount(cCpus);
427 fRc = fRc and oSession.setupTeleporter(True, uPort=6502, sPassword='password');
428 fRc = fRc and oSession.saveSettings();
429 fRc = oSession.close() and fRc and True; # pychecker hack.
430 oSession = None;
431 else:
432 fRc = False;
433
434 # Simple test.
435 if fRc is True:
436 self.logVmInfo(oVmSrc);
437 self.logVmInfo(oVmDst);
438
439 # Start the source VM.
440 oSessionSrc = self.startVm(oVmSrc);
441 if oSessionSrc is not None:
442 # Simple back and forth to test the ice...
443 cTeleportations = 0;
444 oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(oVmSrc, oSessionSrc, oVmDst);
445 if reporter.testErrorCount() == 0:
446 cTeleportations += 1;
447 oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(oVmSrc, oSessionSrc, oVmDst);
448
449 # Teleport back and forth for a while.
450 msStart = base.timestampMilli();
451 while reporter.testErrorCount() == 0:
452 cTeleportations += 1;
453 if oSessionSrc.txsTryConnectViaTcp(2500, 'localhost') is True:
454 break;
455 oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(oVmSrc, oSessionSrc, oVmDst);
456 cMsElapsed = base.timestampMilli() - msStart;
457 if cMsElapsed > 5*60000:
458 reporter.testFailure('TXS did not show up after %u min of teleporting (%u)...' \
459 % (cMsElapsed / 60000.0, cTeleportations));
460 break;
461
462 # Clean up the source VM.
463 self.terminateVmBySession(oSessionSrc)
464 return None;
465
466 def test2OneVM(self, sVmBaseName, asSupVirtModes = None, rSupCpus = range(1, 256)):
467 """
468 Runs one VM (a pair really) thru the various configurations.
469 """
470 if asSupVirtModes is None:
471 asSupVirtModes = self.asVirtModes;
472
473 reporter.testStart(sVmBaseName);
474 for cCpus in self.acCpus:
475 if cCpus == 1: reporter.testStart('1 cpu');
476 else: reporter.testStart('%u cpus' % (cCpus));
477
478 for sVirtMode in self.asVirtModes:
479 if sVirtMode == 'raw' and cCpus > 1:
480 continue;
481 if cCpus not in rSupCpus:
482 continue;
483 if sVirtMode not in asSupVirtModes:
484 continue;
485 hsVirtModeDesc = {};
486 hsVirtModeDesc['raw'] = 'Raw-mode';
487 hsVirtModeDesc['hwvirt'] = 'HwVirt';
488 hsVirtModeDesc['hwvirt-np'] = 'NestedPaging';
489 reporter.testStart(hsVirtModeDesc[sVirtMode]);
490
491 fHwVirt = sVirtMode != 'raw';
492 fNestedPaging = sVirtMode == 'hwvirt-np';
493 self.test2OneCfg(sVmBaseName, cCpus, fHwVirt, fNestedPaging);
494
495 reporter.testDone();
496 reporter.testDone();
497 return reporter.testDone()[1] == 0;
498
499 def test2(self):
500 """
501 Executes test #2.
502 """
503
504 # Loop thru the test VMs.
505 fRc = True;
506 for sVM in self.asTestVMs:
507 # figure args.
508 asSupVirtModes = None;
509 if sVM in ('tst-sol11', 'tst-sol10'): # 64-bit only
510 asSupVirtModes = ['hwvirt', 'hwvirt-np',];
511
512 # run test on the VM.
513 if not self.test2OneVM(sVM, asSupVirtModes):
514 fRc = False;
515
516 return fRc;
517 #
518 # Test #1
519 #
520
521 def test1ResetVmConfig(self, oVM, fTeleporterEnabled = False):
522 """
523 Resets the teleportation config for the specified VM.
524 Returns True on success, False on failure.
525 """
526 oSession = self.openSession(oVM);
527 if oSession is not None:
528 fRc = oSession.setupTeleporter(fTeleporterEnabled, uPort=6502, sPassword='password');
529 fRc = fRc and oSession.saveSettings();
530 if not oSession.close(): fRc = False;
531 oSession = None;
532 else:
533 fRc = False;
534 return fRc;
535
536 def test1Sub7(self, oVmSrc, oVmDst):
537 """
538 Test the password check.
539 """
540 reporter.testStart('Bad password');
541 if self.test1ResetVmConfig(oVmSrc, fTeleporterEnabled = False) \
542 and self.test1ResetVmConfig(oVmDst, fTeleporterEnabled = True):
543 # Start the target VM.
544 oSessionDst, oProgressDst = self.startVmEx(oVmDst, fWait = False);
545 if oSessionDst is not None:
546 if oProgressDst.waitForOperation(iOperation = -3) == 0:
547 # Start the source VM.
548 oSessionSrc = self.startVm(oVmSrc);
549 if oSessionSrc is not None:
550 tsPasswords = ('password-bad', 'passwor', 'pass', 'p', '', 'Password', );
551 for sPassword in tsPasswords:
552 reporter.testStart(sPassword);
553 oProgressSrc = oSessionSrc.teleport('localhost', 6502, sPassword);
554 if oProgressSrc:
555 oProgressSrc.wait();
556 reporter.log('src: %s' % oProgressSrc.stringifyResult());
557 if oProgressSrc.isSuccess():
558 reporter.testFailure('IConsole::teleport succeeded with bad password "%s"' % sPassword);
559 elif oProgressSrc.getErrInfoResultCode() != vbox.ComError.E_FAIL:
560 reporter.testFailure('IConsole::teleport returns %s instead of E_FAIL' \
561 % (vbox.ComError.toString(oProgressSrc.getErrInfoResultCode()),));
562 elif oProgressSrc.getErrInfoText() != 'Invalid password':
563 reporter.testFailure('IConsole::teleport returns "%s" instead of "Invalid password"' \
564 % (oProgressSrc.getErrInfoText(),));
565 elif oProgressDst.isCompleted():
566 reporter.testFailure('Destination completed unexpectedly after bad password "%s"' \
567 % sPassword);
568 else:
569 reporter.testFailure('IConsole::teleport failed with password "%s"' % sPassword);
570 if reporter.testDone()[1] != 0:
571 break;
572 self.terminateVmBySession(oSessionSrc, oProgressSrc);
573 self.terminateVmBySession(oSessionDst, oProgressDst);
574 else:
575 reporter.testFailure('reconfig failed');
576 return reporter.testDone()[1] == 0;
577
578 def test1Sub6(self, oVmSrc, oVmDst):
579 """
580 Misconfigure the target VM and check that teleportation fails with the
581 same status and message on both ends.
582 xTracker: #4813
583 """
584 reporter.testStart('Misconfiguration & error message');
585 if self.test1ResetVmConfig(oVmSrc, fTeleporterEnabled = False) \
586 and self.test1ResetVmConfig(oVmDst, fTeleporterEnabled = True):
587 # Give the source a bit more RAM.
588 oSession = self.openSession(oVmSrc);
589 if oSession is not None:
590 try: cbMB = oVmSrc.memorySize + 4;
591 except: cbMB = 1; fRc = False;
592 fRc = oSession.setRamSize(cbMB);
593 if not oSession.saveSettings(): fRc = False;
594 if not oSession.close(): fRc = False;
595 oSession = None;
596 else:
597 fRc = False;
598 if fRc:
599 # Start the target VM.
600 oSessionDst, oProgressDst = self.startVmEx(oVmDst, fWait = False);
601 if oSessionDst is not None:
602 if oProgressDst.waitForOperation(iOperation = -3) == 0:
603 # Start the source VM.
604 oSessionSrc = self.startVm(oVmSrc);
605 if oSessionSrc is not None:
606 # Try teleport.
607 oProgressSrc = oSessionSrc.teleport('localhost', 6502, 'password');
608 if oProgressSrc:
609 oProgressSrc.wait();
610 oProgressDst.wait();
611
612 reporter.log('src: %s' % oProgressSrc.stringifyResult());
613 reporter.log('dst: %s' % oProgressDst.stringifyResult());
614
615 # Make sure it failed.
616 if oProgressSrc.isSuccess() and oProgressDst.isSuccess():
617 reporter.testFailure('The teleporation did not fail as expected');
618
619 # Compare the results.
620 if oProgressSrc.getResult() != oProgressDst.getResult():
621 reporter.testFailure('Result differs - src=%s dst=%s' \
622 % (vbox.ComError.toString(oProgressSrc.getResult()),\
623 vbox.ComError.toString(oProgressDst.getResult())));
624 elif oProgressSrc.getErrInfoResultCode() != oProgressDst.getErrInfoResultCode():
625 reporter.testFailure('ErrorInfo::resultCode differs - src=%s dst=%s' \
626 % (vbox.ComError.toString(oProgressSrc.getErrInfoResultCode()),\
627 vbox.ComError.toString(oProgressDst.getErrInfoResultCode())));
628 elif oProgressSrc.getErrInfoText() != oProgressDst.getErrInfoText():
629 reporter.testFailure('ErrorInfo::text differs - src="%s" dst="%s"' \
630 % (oProgressSrc.getErrInfoText(), oProgressDst.getErrInfoText()));
631
632 self.terminateVmBySession(oSessionSrc, oProgressSrc);
633 self.terminateVmBySession(oSessionDst, oProgressDst);
634 self.test1ResetVmConfig(oVmSrc, fTeleporterEnabled = False)
635 self.test1ResetVmConfig(oVmDst, fTeleporterEnabled = True);
636 else:
637 reporter.testFailure('reconfig #2 failed');
638 else:
639 reporter.testFailure('reconfig #1 failed');
640 return reporter.testDone()[1] == 0;
641
642 def test1Sub5(self, oVmSrc, oVmDst):
643 """
644 Test that basic teleporting works.
645 xTracker: #4749
646 """
647 reporter.testStart('Simple teleportation');
648 for cSecsX2 in range(0, 10):
649 if self.test1ResetVmConfig(oVmSrc, fTeleporterEnabled = False) \
650 and self.test1ResetVmConfig(oVmDst, fTeleporterEnabled = True):
651 # Start the target VM.
652 oSessionDst, oProgressDst = self.startVmEx(oVmDst, fWait = False);
653 if oSessionDst is not None:
654 if oProgressDst.waitForOperation(iOperation = -3) == 0:
655 # Start the source VM.
656 oSessionSrc = self.startVm(oVmSrc);
657 if oSessionSrc is not None:
658 self.sleep(cSecsX2 / 2);
659 # Try teleport.
660 oProgressSrc = oSessionSrc.teleport('localhost', 6502, 'password');
661 if oProgressSrc:
662 oProgressSrc.wait();
663 oProgressDst.wait();
664
665 self.terminateVmBySession(oSessionSrc, oProgressSrc);
666 self.terminateVmBySession(oSessionDst, oProgressDst);
667 else:
668 reporter.testFailure('reconfig failed');
669 return reporter.testDone()[1] == 0;
670
671 def test1Sub4(self, oVM):
672 """
673 Test that we can start and cancel a teleportation target.
674 (No source VM trying to connect here.)
675 xTracker: #4965
676 """
677 reporter.testStart('openRemoteSession cancel');
678 for cSecsX2 in range(0, 10):
679 if self.test1ResetVmConfig(oVM, fTeleporterEnabled = True):
680 oSession, oProgress = self.startVmEx(oVM, fWait = False);
681 if oSession is not None:
682 self.sleep(cSecsX2 / 2);
683 oProgress.cancel();
684 oProgress.wait();
685 self.terminateVmBySession(oSession, oProgress);
686 else:
687 reporter.testFailure('reconfig failed');
688 return reporter.testDone()[1] == 0;
689
690 def test1Sub3(self, oVM):
691 """
692 Test that starting a teleportation target VM will fail if we give it
693 a bad address to bind to.
694 """
695 reporter.testStart('bad IMachine::teleporterAddress');
696
697 # re-configure it with a bad bind-to address.
698 fRc = False;
699 oSession = self.openSession(oVM);
700 if oSession is not None:
701 fRc = oSession.setupTeleporter(True, uPort=6502, sAddress='no.such.hostname.should.ever.exist.duh');
702 if not oSession.saveSettings(fClose=True): fRc = False;
703 oSession = None;
704 if fRc:
705 # Try start it.
706 oSession, oProgress = self.startVmEx(oVM, fWait = False);
707 if oSession is not None:
708 oProgress.wait();
709 ## TODO: exact error code and look for the IPRT right string.
710 if not oProgress.isCompleted() or oProgress.getResult() >= 0:
711 reporter.testFailure('%s' % (oProgress.stringifyResult(),));
712 self.terminateVmBySession(oSession, oProgress);
713
714 # put back the old teleporter setup.
715 self.test1ResetVmConfig(oVM, fTeleporterEnabled = True);
716 else:
717 reporter.testFailure('reconfig #1 failed');
718 return reporter.testDone()[1] == 0;
719
720 # test1Sub2 - start
721
722 def test1Sub2SetEnabled(self, oSession, fEnabled):
723 """ This should never fail."""
724 try:
725 oSession.o.machine.teleporterEnabled = fEnabled;
726 except:
727 reporter.testFailureXcpt('machine.teleporterEnabled=%s' % (fEnabled,));
728 return False;
729 try:
730 fNew = oSession.o.machine.teleporterEnabled;
731 except:
732 reporter.testFailureXcpt();
733 return False;
734 if fNew != fEnabled:
735 reporter.testFailure('machine.teleporterEnabled=%s but afterwards it is actually %s' % (fEnabled, fNew));
736 return False;
737 return True;
738
739 def test1Sub2SetPassword(self, oSession, sPassword):
740 """ This should never fail."""
741 try:
742 oSession.o.machine.teleporterPassword = sPassword;
743 except:
744 reporter.testFailureXcpt('machine.teleporterPassword=%s' % (sPassword,));
745 return False;
746 try:
747 sNew = oSession.o.machine.teleporterPassword;
748 except:
749 reporter.testFailureXcpt();
750 return False;
751 if sNew != sPassword:
752 reporter.testFailure('machine.teleporterPassword="%s" but afterwards it is actually "%s"' % (sPassword, sNew));
753 return False;
754 return True;
755
756 def test1Sub2SetPort(self, oSession, uPort, fInvalid = False):
757 """ This can fail, thus fInvalid."""
758 if not fInvalid:
759 uOld = uPort;
760 else:
761 try: uOld = oSession.o.machine.teleporterPort;
762 except: return reporter.testFailureXcpt();
763
764 try:
765 oSession.o.machine.teleporterPort = uPort;
766 except Exception, oXcpt:
767 if not fInvalid or vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG):
768 return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort,));
769 else:
770 if fInvalid:
771 return reporter.testFailureXcpt('machine.teleporterPort=%u succeeded unexpectedly' % (uPort,));
772
773 try: uNew = oSession.o.machine.teleporterPort;
774 except: return reporter.testFailureXcpt();
775 if uNew != uOld:
776 if not fInvalid:
777 reporter.testFailure('machine.teleporterPort=%u but afterwards it is actually %u' % (uPort, uNew));
778 else:
779 reporter.testFailure('machine.teleporterPort is %u after failure, expected %u' % (uNew, uOld));
780 return False;
781 return True;
782
783 def test1Sub2SetAddress(self, oSession, sAddress):
784 """ This should never fail."""
785 try:
786 oSession.o.machine.teleporterAddress = sAddress;
787 except:
788 reporter.testFailureXcpt('machine.teleporterAddress=%s' % (sAddress,));
789 return False;
790 try:
791 sNew = oSession.o.machine.teleporterAddress;
792 except:
793 reporter.testFailureXcpt();
794 return False;
795 if sNew != sAddress:
796 reporter.testFailure('machine.teleporterAddress="%s" but afterwards it is actually "%s"' % (sAddress, sNew));
797 return False;
798 return True;
799
800 def test1Sub2(self, oVM):
801 """
802 Test the attributes, making sure that we get exceptions on bad values.
803 """
804 reporter.testStart('IMachine::teleport*');
805
806 # Save the original teleporter attributes for the discard test.
807 try:
808 sOrgAddress = oVM.teleporterAddress;
809 uOrgPort = oVM.teleporterPort;
810 sOrgPassword = oVM.teleporterPassword;
811 fOrgEnabled = oVM.teleporterEnabled;
812 except:
813 reporter.testFailureXcpt();
814 else:
815 # Open a session and start messing with the properties.
816 oSession = self.openSession(oVM);
817 if oSession is not None:
818 # Anything goes for the address.
819 reporter.testStart('teleporterAddress');
820 self.test1Sub2SetAddress(oSession, '');
821 self.test1Sub2SetAddress(oSession, '1');
822 self.test1Sub2SetAddress(oSession, 'Anything goes! ^&$@!$%^');
823 reporter.testDone();
824
825 # The port is restricted to {0..65535}.
826 reporter.testStart('teleporterPort');
827 for uPort in range(0, 1000) + range(16000, 17000) + range(32000, 33000) + range(65000, 65536):
828 if not self.test1Sub2SetPort(oSession, uPort):
829 break;
830 self.processPendingEvents();
831 reporter.testDone();
832
833 reporter.testStart('teleporterPort negative');
834 self.test1Sub2SetPort(oSession, 65536, True);
835 self.test1Sub2SetPort(oSession, 999999, True);
836 reporter.testDone();
837
838 # Anything goes for the password.
839 reporter.testStart('teleporterPassword');
840 self.test1Sub2SetPassword(oSession, 'password');
841 self.test1Sub2SetPassword(oSession, '');
842 self.test1Sub2SetPassword(oSession, '1');
843 self.test1Sub2SetPassword(oSession, 'Anything goes! ^&$@!$%^');
844 reporter.testDone();
845
846 # Just test that it works.
847 reporter.testStart('teleporterEnabled');
848 self.test1Sub2SetEnabled(oSession, True);
849 self.test1Sub2SetEnabled(oSession, True);
850 self.test1Sub2SetEnabled(oSession, False);
851 self.test1Sub2SetEnabled(oSession, False);
852 reporter.testDone();
853
854 # Finally, discard the changes, close the session and check
855 # that we're back to the originals.
856 if not oSession.discardSettings(True):
857 reporter.testFailure('Failed to discard settings & close the session')
858 else:
859 reporter.testFailure('Failed to open VM session')
860 try:
861 if oVM.teleporterAddress != sOrgAddress: reporter.testFailure('Rollback failed for teleporterAddress');
862 if oVM.teleporterPort != uOrgPort: reporter.testFailure('Rollback failed for teleporterPort');
863 if oVM.teleporterPassword != sOrgPassword: reporter.testFailure('Rollback failed for teleporterPassword');
864 if oVM.teleporterEnabled != fOrgEnabled: reporter.testFailure('Rollback failed for teleporterEnabled');
865 except:
866 reporter.testFailureXcpt();
867 return reporter.testDone()[1] != 0;
868
869 # test1Sub1 - start
870
871 def test1Sub1DoTeleport(self, oSession, sHostname, uPort, sPassword, cMsMaxDowntime, hrcExpected, sTestName):
872 """ Do a bad IConsole::teleport call and check the result."""
873 reporter.testStart(sTestName);
874 fRc = False;
875 try:
876 oProgress = oSession.o.console.teleport(sHostname, uPort, sPassword, cMsMaxDowntime);
877 except vbox.ComException, oXcpt:
878 if vbox.ComError.equal(oXcpt, hrcExpected):
879 fRc = True;
880 else:
881 reporter.testFailure('hresult %s, expected %s' \
882 % (vbox.ComError.toString(oXcpt.hresult),
883 vbox.ComError.toString(hrcExpected)));
884 except Exception, oXcpt:
885 reporter.testFailure('Unexpected exception %s' % (oXcpt));
886 else:
887 reporter.testFailure('Unpexected success');
888 oProgress.cancel();
889 oProgress.wait();
890 reporter.testDone();
891 return fRc;
892
893 def test1Sub1(self, oVM):
894 """ Test simple IConsole::teleport() failure paths. """
895 reporter.testStart('IConsole::teleport');
896 oSession = self.startVm(oVM);
897 if oSession:
898 self.test1Sub1DoTeleport(oSession, 'localhost', 65536, 'password', 10000,
899 vbox.ComError.E_INVALIDARG, 'Bad port value 65536');
900 self.test1Sub1DoTeleport(oSession, 'localhost', 0, 'password', 10000,
901 vbox.ComError.E_INVALIDARG, 'Bad port value 0');
902 self.test1Sub1DoTeleport(oSession, 'localhost', 5000, 'password', 0,
903 vbox.ComError.E_INVALIDARG, 'Bad max downtime');
904 self.test1Sub1DoTeleport(oSession, '', 5000, 'password', 10000,
905 vbox.ComError.E_INVALIDARG, 'No hostname');
906 self.test1Sub1DoTeleport(oSession, 'no.such.hostname.should.ever.exist.duh', 5000, 'password', 0,
907 vbox.ComError.E_INVALIDARG, 'Non-existing host');
908
909 self.terminateVmBySession(oSession)
910 else:
911 reporter.testFailure('startVm');
912 return reporter.testDone()[1] == 0;
913
914
915 def test1(self):
916 """
917 Executes test #1 - Negative API testing.
918
919 ASSUMES that the VMs are
920 """
921 reporter.testStart('Test 1');
922
923 # Get the VMs.
924 #oVmHwVirt1 = self.getVmByName('tst-empty-hwvirt-1');
925 #oVmHwVirt2 = self.getVmByName('tst-empty-hwvirt-2');
926 oVmRaw1 = self.getVmByName('tst-empty-raw-1');
927 oVmRaw2 = self.getVmByName('tst-empty-raw-2');
928
929 # Reset their teleportation related configuration.
930 fRc = True;
931 #for oVM in (oVmHwVirt1, oVmHwVirt2, oVmRaw1, oVmRaw2):
932 for oVM in (oVmRaw1, oVmRaw2):
933 if not self.test1ResetVmConfig(oVM): fRc = False;
934
935 # Do the testing (don't both with fRc on the subtests).
936 if fRc:
937 self.test1Sub1(oVmRaw1);
938 self.test1Sub2(oVmRaw2);
939 self.test1Sub3(oVmRaw2);
940 self.test1Sub4(oVmRaw2);
941 self.processPendingEvents();
942 self.test1Sub5(oVmRaw1, oVmRaw2);
943 self.test1Sub6(oVmRaw1, oVmRaw2);
944 self.test1Sub7(oVmRaw1, oVmRaw2);
945 else:
946 reporter.testFailure('Failed to reset the VM configs')
947 return reporter.testDone()[1] == 0;
948
949
950
951if __name__ == '__main__':
952 sys.exit(tdTeleportLocal1().main(sys.argv));
953
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