def test1Sub2SetPort(self, oSession, uPort, fInvalid = False): """ This can fail, thus fInvalid.""" if not fInvalid: uOld = uPort; else: try: uOld = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); try: oSession.o.machine.teleporterPort = uPort; except Exception as oXcpt: if not fInvalid or vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort,)); else: if fInvalid: return reporter.testFailureXcpt('machine.teleporterPort=%u succeeded unexpectedly' % (uPort,)); try: uNew = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); if uNew != uOld: if not fInvalid: reporter.testFailure('machine.teleporterPort=%u but afterwards it is actually %u' % (uPort, uNew)); else: reporter.testFailure('machine.teleporterPort is %u after failure, expected %u' % (uNew, uOld)); return False; return True;
def test1Sub2SetPort(self, oSession, uPort, fInvalid = False): """ This can fail, thus fInvalid.""" if not fInvalid: uOld = uPort; else: try: uOld = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); try: oSession.o.machine.teleporterPort = uPort; except Exception, oXcpt: if not fInvalid or vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort,));
def test1Sub2SetAddress(self, oSession, sAddress): """ This should never fail.""" try: oSession.o.machine.teleporterAddress = sAddress; except: reporter.testFailureXcpt('machine.teleporterAddress=%s' % (sAddress,)); return False; try: sNew = oSession.o.machine.teleporterAddress; except: reporter.testFailureXcpt(); return False; if sNew != sAddress: reporter.testFailure('machine.teleporterAddress="%s" but afterwards it is actually "%s"' % (sAddress, sNew)); return False; return True;
def test1Sub2SetPassword(self, oSession, sPassword): """ This should never fail.""" try: oSession.o.machine.teleporterPassword = sPassword; except: reporter.testFailureXcpt('machine.teleporterPassword=%s' % (sPassword,)); return False; try: sNew = oSession.o.machine.teleporterPassword; except: reporter.testFailureXcpt(); return False; if sNew != sPassword: reporter.testFailure('machine.teleporterPassword="******" but afterwards it is actually "%s"' % (sPassword, sNew)); return False; return True;
def test1Sub2SetEnabled(self, oSession, fEnabled): """ This should never fail.""" try: oSession.o.machine.teleporterEnabled = fEnabled; except: reporter.testFailureXcpt('machine.teleporterEnabled=%s' % (fEnabled,)); return False; try: fNew = oSession.o.machine.teleporterEnabled; except: reporter.testFailureXcpt(); return False; if fNew != fEnabled: reporter.testFailure('machine.teleporterEnabled=%s but afterwards it is actually %s' % (fEnabled, fNew)); return False; return True;
def test1Sub2(self, oVM): """ Test the attributes, making sure that we get exceptions on bad values. """ reporter.testStart('IMachine::teleport*'); # Save the original teleporter attributes for the discard test. try: sOrgAddress = oVM.teleporterAddress; uOrgPort = oVM.teleporterPort; sOrgPassword = oVM.teleporterPassword; fOrgEnabled = oVM.teleporterEnabled; except: reporter.testFailureXcpt(); else: # Open a session and start messing with the properties. oSession = self.openSession(oVM); if oSession is not None: # Anything goes for the address. reporter.testStart('teleporterAddress'); self.test1Sub2SetAddress(oSession, ''); self.test1Sub2SetAddress(oSession, '1'); self.test1Sub2SetAddress(oSession, 'Anything goes! ^&$@!$%^'); reporter.testDone(); # The port is restricted to {0..65535}. reporter.testStart('teleporterPort'); for uPort in range(0, 1000) + range(16000, 17000) + range(32000, 33000) + range(65000, 65536): if not self.test1Sub2SetPort(oSession, uPort): break; self.processPendingEvents(); reporter.testDone(); reporter.testStart('teleporterPort negative'); self.test1Sub2SetPort(oSession, 65536, True); self.test1Sub2SetPort(oSession, 999999, True); reporter.testDone(); # Anything goes for the password. reporter.testStart('teleporterPassword'); self.test1Sub2SetPassword(oSession, 'password'); self.test1Sub2SetPassword(oSession, ''); self.test1Sub2SetPassword(oSession, '1'); self.test1Sub2SetPassword(oSession, 'Anything goes! ^&$@!$%^'); reporter.testDone(); # Just test that it works. reporter.testStart('teleporterEnabled'); self.test1Sub2SetEnabled(oSession, True); self.test1Sub2SetEnabled(oSession, True); self.test1Sub2SetEnabled(oSession, False); self.test1Sub2SetEnabled(oSession, False); reporter.testDone(); # Finally, discard the changes, close the session and check # that we're back to the originals. if not oSession.discardSettings(True): reporter.testFailure('Failed to discard settings & close the session') else: reporter.testFailure('Failed to open VM session') try: if oVM.teleporterAddress != sOrgAddress: reporter.testFailure('Rollback failed for teleporterAddress'); if oVM.teleporterPort != uOrgPort: reporter.testFailure('Rollback failed for teleporterPort'); if oVM.teleporterPassword != sOrgPassword: reporter.testFailure('Rollback failed for teleporterPassword'); if oVM.teleporterEnabled != fOrgEnabled: reporter.testFailure('Rollback failed for teleporterEnabled'); except: reporter.testFailureXcpt(); return reporter.testDone()[1] != 0;
def test1Sub2SetPort(self, oSession, uPort, fInvalid = False): """ This can fail, thus fInvalid.""" if not fInvalid: uOld = uPort; else: try: uOld = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); try: oSession.o.machine.teleporterPort = uPort; except Exception, oXcpt: if not fInvalid or vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort,)); else: if fInvalid: return reporter.testFailureXcpt('machine.teleporterPort=%u succeeded unexpectedly' % (uPort,)); try: uNew = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); if uNew != uOld: if not fInvalid: reporter.testFailure('machine.teleporterPort=%u but afterwards it is actually %u' % (uPort, uNew)); else: reporter.testFailure('machine.teleporterPort is %u after failure, expected %u' % (uNew, uOld)); return False; return True; def test1Sub2SetAddress(self, oSession, sAddress): """ This should never fail.""" try: oSession.o.machine.teleporterAddress = sAddress;
def test1Sub2(self, oVM): """ Test the attributes, making sure that we get exceptions on bad values. """ reporter.testStart('IMachine::teleport*') # Save the original teleporter attributes for the discard test. try: sOrgAddress = oVM.teleporterAddress uOrgPort = oVM.teleporterPort sOrgPassword = oVM.teleporterPassword fOrgEnabled = oVM.teleporterEnabled except: reporter.testFailureXcpt() else: # Open a session and start messing with the properties. oSession = self.openSession(oVM) if oSession is not None: # Anything goes for the address. reporter.testStart('teleporterAddress') self.test1Sub2SetAddress(oSession, '') self.test1Sub2SetAddress(oSession, '1') self.test1Sub2SetAddress(oSession, 'Anything goes! ^&$@!$%^') reporter.testDone() # The port is restricted to {0..65535}. reporter.testStart('teleporterPort') for uPort in range(0, 1000) + range(16000, 17000) + range( 32000, 33000) + range(65000, 65536): if not self.test1Sub2SetPort(oSession, uPort): break self.processPendingEvents() reporter.testDone() reporter.testStart('teleporterPort negative') self.test1Sub2SetPort(oSession, 65536, True) self.test1Sub2SetPort(oSession, 999999, True) reporter.testDone() # Anything goes for the password. reporter.testStart('teleporterPassword') self.test1Sub2SetPassword(oSession, 'password') self.test1Sub2SetPassword(oSession, '') self.test1Sub2SetPassword(oSession, '1') self.test1Sub2SetPassword(oSession, 'Anything goes! ^&$@!$%^') reporter.testDone() # Just test that it works. reporter.testStart('teleporterEnabled') self.test1Sub2SetEnabled(oSession, True) self.test1Sub2SetEnabled(oSession, True) self.test1Sub2SetEnabled(oSession, False) self.test1Sub2SetEnabled(oSession, False) reporter.testDone() # Finally, discard the changes, close the session and check # that we're back to the originals. if not oSession.discardSettings(True): reporter.testFailure( 'Failed to discard settings & close the session') else: reporter.testFailure('Failed to open VM session') try: if oVM.teleporterAddress != sOrgAddress: reporter.testFailure( 'Rollback failed for teleporterAddress') if oVM.teleporterPort != uOrgPort: reporter.testFailure('Rollback failed for teleporterPort') if oVM.teleporterPassword != sOrgPassword: reporter.testFailure( 'Rollback failed for teleporterPassword') if oVM.teleporterEnabled != fOrgEnabled: reporter.testFailure( 'Rollback failed for teleporterEnabled') except: reporter.testFailureXcpt() return reporter.testDone()[1] != 0
try: uOld = oSession.o.machine.teleporterPort except: return reporter.testFailureXcpt() try: oSession.o.machine.teleporterPort = uPort except Exception, oXcpt: if not fInvalid or vbox.ComError.notEqual( oXcpt, vbox.ComError.E_INVALIDARG): return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort, )) else: if fInvalid: return reporter.testFailureXcpt( 'machine.teleporterPort=%u succeeded unexpectedly' % (uPort, )) try: uNew = oSession.o.machine.teleporterPort except: return reporter.testFailureXcpt() if uNew != uOld: if not fInvalid: reporter.testFailure( 'machine.teleporterPort=%u but afterwards it is actually %u' % (uPort, uNew)) else: reporter.testFailure( 'machine.teleporterPort is %u after failure, expected %u' % (uNew, uOld))