Index: /trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py
===================================================================
--- /trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py	(revision 84614)
+++ /trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py	(revision 84615)
@@ -414,14 +414,9 @@
         return (fRc, uExitStatus, iExitCode, aBuf);
 
-    def uploadString(self, oSession, sSrcString, sDst):
+    def uploadString(self, oGuestSession, sSrcString, sDst):
         """
         Upload the string into guest.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'vbox session for installing guest additions',
-                                                'vbox', 'password', cMsTimeout = 10 * 1000, fIsError = True);
-        if fRc is not True:
-            return reporter.errorXcpt('Upload string failed: Could not create session for vbox');
-
+        fRc = True;
         try:
             oFile = oGuestSession.fileOpenEx(sDst, vboxcon.FileAccessMode_ReadWrite, vboxcon.FileOpenAction_CreateOrReplace,
@@ -439,17 +434,11 @@
             fRc = reporter.errorXcpt('Upload string failed. Could not close the file %s' % sDst);
 
-        self.closeSession(oGuestSession);
-        return fRc;
-
-    def uploadFile(self, oSession, sSrc, sDst):
+        return fRc;
+
+    def uploadFile(self, oGuestSession, sSrc, sDst):
         """
         Upload the string into guest.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'vbox session for upload the file',
-                                                'vbox', 'password', cMsTimeout = 10 * 1000, fIsError = True);
-        if fRc is not True:
-            return reporter.errorXcpt('Upload file failed: Could not create session for vbox');
-
+        fRc = True;
         try:
             if self.fpApiVer >= 5.0:
@@ -472,20 +461,11 @@
                 fRc = reporter.error('No progress object returned');
 
-        self.closeSession(oGuestSession);
-        return fRc;
-
-    def downloadFile(self, oSession, sSrc, sDst, fIgnoreErrors = False):
+        return fRc;
+
+    def downloadFile(self, oGuestSession, sSrc, sDst, fIgnoreErrors = False):
         """
         Upload the string into guest.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'vbox session for download the file',
-                                                'vbox', 'password', cMsTimeout = 10 * 1000, fIsError = True);
-        if fRc is not True:
-            if not fIgnoreErrors:
-                return reporter.errorXcpt('Download file failed: Could not create session for vbox');
-            reporter.log('warning: Download file failed: Could not create session for vbox');
-            return False;
-
+        fRc = True;
         try:
             if self.fpApiVer >= 5.0:
@@ -514,8 +494,7 @@
                 fRc = False;
 
-        self.closeSession(oGuestSession);
-        return fRc;
-
-    def downloadFiles(self, oSession, asFiles, fIgnoreErrors = False):
+        return fRc;
+
+    def downloadFiles(self, oGuestSession, asFiles, fIgnoreErrors = False):
         """
         Convenience function to get files from the guest and stores it
@@ -535,5 +514,5 @@
             ## @todo Check for already existing files on the host and create a new
             #        name for the current file to download.
-            fRc = self.downloadFile(oSession, sGstFile, sTmpFile, fIgnoreErrors);
+            fRc = self.downloadFile(oGuestSession, sGstFile, sTmpFile, fIgnoreErrors);
             if fRc:
                 reporter.addLogFile(sTmpFile, 'misc/other', 'guest - ' + sGstFile);
@@ -560,4 +539,5 @@
         """
         Waits the VM is ready after start or reboot.
+        Returns result (true or false) and guest session obtained
         """
         # Give the VM a time to reboot
@@ -568,5 +548,5 @@
 
         cAttempt = 0;
-
+        oGuestSession = None;
         while cAttempt < 30:
             fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
@@ -577,6 +557,4 @@
                                                           ['ifconfig',],
                                                           False, False);
-                fRc = self.closeSession(oGuestSession, False) and fRc and True; # pychecker hack.
-
             if fRc:
                 break;
@@ -585,16 +563,11 @@
             cAttempt += 1;
 
-        return fRc;
-
-    def rebootVMAndCheckReady(self, oSession):
+        return (fRc, oGuestSession);
+
+    def rebootVMAndCheckReady(self, oSession, oGuestSession):
         """
         Reboot the VM and wait the VM is ready.
-        """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
-
+        Returns result and guest session obtained after reboot
+        """
         (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Reboot the VM',
                                                   30 * 1000, '/usr/bin/sudo',
@@ -602,18 +575,17 @@
                                                   False, True);
         fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        fRc = fRc and self.waitVMisReady(oSession);
-        return fRc;
-
-    def powerDownVM(self, oSession):
+        if fRc:
+            (fRc, oGuestSession) = self.waitVMisReady(oSession);
+        return (fRc, oGuestSession);
+
+    def powerDownVM(self, oGuestSession):
         """
         Power down the VM by calling guest process without wating
-        the VM is really powered off.
+        the VM is really powered off. Also, closes the guest session.
         It helps the terminateBySession to stop the VM without aborting.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
+        
+        if oGuestSession is None:
+            return False;
 
         (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Power down the VM',
@@ -624,13 +596,10 @@
         return fRc;
 
-    def installAdditions(self, oSession, oVM):
+    def installAdditions(self, oSession, oGuestSession, oVM):
         """
         Install guest additions in the guest.
         """
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
-
+        
+        fRc = False;
         # Install Kernel headers, which are required for actually installing the Linux Additions.
         if oVM.OSTypeId.startswith('Debian') \
@@ -671,5 +640,5 @@
 
         else:
-            reporter.error('Installing Linux Additions for kind "%s" is not supported yet' % oVM.sKind);
+            reporter.error('Installing Linux Additions for the "%s" is not supported yet' % oVM.OSTypeId);
             fRc = False;
 
@@ -688,5 +657,7 @@
                 # Due to the GA updates as separate process the above function returns before
                 # the actual installation finished. So just wait until the GA installed
-                fRc = self.waitVMisReady(oSession);
+                fRc = self.closeSession(oGuestSession);
+                if fRc:
+                    (fRc, oGuestSession) = self.waitVMisReady(oSession);
 
                 # Download log files.
@@ -696,13 +667,12 @@
                     asLogFile = [];
                     asLogFile.append('/var/log/vboxadd-install.log');
-                    self.downloadFiles(oSession, asLogFile, fIgnoreErrors = True);
-
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        if fRc:
-            fRc = self.rebootVMAndCheckReady(oSession);
-
-        return fRc;
-
-    def installVirtualBox(self, oSession):
+                    self.downloadFiles(oGuestSession, asLogFile, fIgnoreErrors = True);
+
+        if fRc:
+            (fRc, oGuestSession) = self.rebootVMAndCheckReady(oSession, oGuestSession);
+
+        return (fRc, oGuestSession);
+
+    def installVirtualBox(self, oGuestSession):
         """
         Install VirtualBox in the guest.
@@ -711,10 +681,5 @@
             return False;
 
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
-
-        fRc = self.uploadFile(oSession, self.sTestBuild,
+        fRc = self.uploadFile(oGuestSession, self.sTestBuild,
                               '/tmp/' + os.path.basename(self.sTestBuild));
 
@@ -732,18 +697,11 @@
                                                        '/tmp/' + os.path.basename(self.sTestBuild),],
                                                       False, True);
-
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        return fRc;
-
-    def configureAutostart(self, oSession, sDefaultPolicy = 'allow',
+        return fRc;
+
+    def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow',
                            asUserAllow = (), asUserDeny = ()):
         """
         Configures the autostart feature in the guest.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for confiure autostart',
-                                                'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
 
         # Create autostart database directory writeable for everyone
@@ -755,5 +713,5 @@
         sVBoxCfg =   'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg\n' \
                    + 'VBOXAUTOSTART_DB=/etc/vbox/autostart.d\n';
-        fRc = fRc and self.uploadString(oSession, sVBoxCfg, '/tmp/virtualbox');
+        fRc = fRc and self.uploadString(oGuestSession, sVBoxCfg, '/tmp/virtualbox');
         if fRc:
             (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Moving to destination',
@@ -770,5 +728,5 @@
 
         sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
-        fRc = fRc and self.uploadString(oSession, sVBoxCfg, '/tmp/autostart.cfg');
+        fRc = fRc and self.uploadString(oGuestSession, sVBoxCfg, '/tmp/autostart.cfg');
         if fRc:
             (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Moving to destination',
@@ -783,25 +741,20 @@
                                                        '/etc/vbox/autostart.cfg'],
                                                       False, True);
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        return fRc;
-
-    def createUser(self, oSession, sUser):
+        return fRc;
+
+    def createUser(self, oGuestSession, sUser):
         """
         Create a new user with the given name
         """
 
-        fRc, oGuestSession = self.createSession(oSession, 'Creating new user',
-                                                'vbox', 'password', 10 * 1000, True);
-        if fRc:
-            (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating new user',
-                                                      30 * 1000, '/usr/bin/sudo',
-                                                      ['/usr/bin/sudo', '/usr/sbin/useradd', '-m', '-U',
-                                                       sUser], False, True);
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
+        (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Creating new user',
+                                                  30 * 1000, '/usr/bin/sudo',
+                                                  ['/usr/bin/sudo', '/usr/sbin/useradd', '-m', '-U',
+                                                   sUser], False, True);
         return fRc;
 
     # pylint: enable=too-many-arguments
 
-    def createTestVM(self, oSession, sUser, sVmName):
+    def createTestVM(self, oSession, oGuestSession, sUser, sVmName):
         """
         Create a test VM in the guest and enable autostart.
@@ -809,9 +762,6 @@
         all calls will be perfomed using 'sudo -u sUser'
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for create VM for user: %s' % (sUser,),
-                                                'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
+        
+        _ = oSession;
 
         (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Configuring autostart database',
@@ -832,8 +782,7 @@
                                                        '/opt/VirtualBox/VBoxManage', 'modifyvm',
                                                       sVmName, '--autostart-enabled', 'on'], False, True);
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        return fRc;
-
-    def checkForRunningVM(self, oSession, sUser, sVmName):
+        return fRc;
+
+    def checkForRunningVM(self, oSession, oGuestSession, sUser, sVmName):
         """
         Check for VM running in the guest after autostart.
@@ -842,8 +791,5 @@
         """
 
-        fRc, oGuestSession = self.createSession(oSession, 'Session for checking running VMs for user: %s' % (sUser,),
-                                                'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
+        _ = oSession;
 
         (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM',
@@ -857,5 +803,4 @@
             fRc = bufWrapper.sVmRunning == sVmName;
 
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
         return fRc;
 
@@ -906,5 +851,5 @@
 
         cAttempt = 0;
-
+        oGuestSession = None;
         while cAttempt < 10:
             fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
@@ -915,6 +860,4 @@
                                                           ['C:\\Windows\\System32\\ipconfig.exe',],
                                                           False, False);
-                fRc = self.closeSession(oGuestSession, False) and fRc and True; # pychecker hack.
-
             if fRc:
                 break;
@@ -923,15 +866,10 @@
             cAttempt += 1;
 
-        return fRc;
-
-    def rebootVMAndCheckReady(self, oSession):
+        return (fRc, oGuestSession);
+
+    def rebootVMAndCheckReady(self, oSession, oGuestSession):
         """
         Reboot the VM and wait the VM is ready.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
 
         (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Reboot the VM',
@@ -941,19 +879,17 @@
                                                   False, True);
         fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-
-        fRc = fRc and self.waitVMisReady(oSession);
-        return fRc;
-
-    def powerDownVM(self, oSession):
+        if fRc:
+            (fRc, oGuestSession) = self.waitVMisReady(oSession);
+        return (fRc, oGuestSession);
+
+    def powerDownVM(self, oGuestSession):
         """
         Power down the VM by calling guest process without wating
-        the VM is really powered off.
+        the VM is really powered off. Also, closes the guest session.
         It helps the terminateBySession to stop the VM without aborting.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
+        
+        if oGuestSession is None:
+            return False;
 
         (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Power down the VM',
@@ -965,12 +901,8 @@
         return fRc;
 
-    def installAdditions(self, oSession, oVM):
+    def installAdditions(self, oSession, oGuestSession, oVM):
         """
         Installs the Windows guest additions using the test execution service.
         """
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
         #
         # Delete relevant log files.
@@ -1000,5 +932,5 @@
             except: pass;
 
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
+        fRc = self.closeSession(oGuestSession, True); # pychecker hack.
 
         try:
@@ -1020,28 +952,31 @@
 
         if fRc:
-            fRc = self.rebootVMAndCheckReady(oSession);
+            fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
+                                            'vbox', 'password', 10 * 1000, True);
             if fRc is True:
-                # Add the Windows Guest Additions installer files to the files we want to download
-                # from the guest.
-                sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/';
-                asLogFiles.append(sGuestAddsDir + 'install.log');
-                # Note: There won't be a install_ui.log because of the silent installation.
-                asLogFiles.append(sGuestAddsDir + 'install_drivers.log');
-                asLogFiles.append('C:/Windows/setupapi.log');
-
-                # Note: setupapi.dev.log only is available since Windows 2000.
-                if fHaveSetupApiDevLog:
-                    asLogFiles.append('C:/Windows/setupapi.dev.log');
-
-                #
-                # Download log files.
-                # Ignore errors as all files above might not be present (or in different locations)
-                # on different Windows guests.
-                #
-                self.downloadFiles(oSession, asLogFiles, fIgnoreErrors = True);
-
-        return fRc;
-
-    def installVirtualBox(self, oSession):
+                (fRc, oGuestSession) = self.rebootVMAndCheckReady(oSession, oGuestSession);
+                if fRc is True:
+                    # Add the Windows Guest Additions installer files to the files we want to download
+                    # from the guest.
+                    sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/';
+                    asLogFiles.append(sGuestAddsDir + 'install.log');
+                    # Note: There won't be a install_ui.log because of the silent installation.
+                    asLogFiles.append(sGuestAddsDir + 'install_drivers.log');
+                    asLogFiles.append('C:/Windows/setupapi.log');
+    
+                    # Note: setupapi.dev.log only is available since Windows 2000.
+                    if fHaveSetupApiDevLog:
+                        asLogFiles.append('C:/Windows/setupapi.dev.log');
+    
+                    #
+                    # Download log files.
+                    # Ignore errors as all files above might not be present (or in different locations)
+                    # on different Windows guests.
+                    #
+                    self.downloadFiles(oGuestSession, asLogFiles, fIgnoreErrors = True);
+
+        return (fRc, oGuestSession);
+
+    def installVirtualBox(self, oGuestSession):
         """
         Install VirtualBox in the guest.
@@ -1051,12 +986,7 @@
             return False;
 
-        fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
-                                            'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
-
         # Used windows image already contains the C:\Temp
-        fRc = fRc and self.uploadFile(oSession, self.sTestBuild,
-                                      'C:\\Temp\\' + os.path.basename(self.sTestBuild));
+        fRc = self.uploadFile(oGuestSession, self.sTestBuild,
+                              'C:\\Temp\\' + os.path.basename(self.sTestBuild));
 
         if fRc:
@@ -1072,18 +1002,11 @@
                                                         ['C:\\Temp\\' + os.path.basename(self.sTestBuild), '--silent'],
                                                         False, True);
-
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        return fRc;
-
-    def configureAutostart(self, oSession, sDefaultPolicy = 'allow',
+        return fRc;
+
+    def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow',
                            asUserAllow = (), asUserDeny = ()):
         """
         Configures the autostart feature in the guest.
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Session for confiure autostart',
-                                                'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
 
         # Create autostart database directory writeable for everyone
@@ -1098,12 +1021,12 @@
 
         sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
-        fRc = fRc and self.uploadString(oSession, sVBoxCfg, 'C:\\ProgramData\\autostart.cfg');
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
-        return fRc;
-
-    def createTestVM(self, oSession, sUser, sVmName):
+        fRc = fRc and self.uploadString(oGuestSession, sVBoxCfg, 'C:\\ProgramData\\autostart.cfg');
+        return fRc;
+
+    def createTestVM(self, oSession, oGuestSession, sUser, sVmName):
         """
         Create a test VM in the guest and enable autostart.
         """
+        _ = oGuestSession;
 
         fRc, oGuestSession = self.createSession(oSession, 'Session for user: %s' % (sUser,),
@@ -1123,5 +1046,5 @@
                                          ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
                                           'modifyvm', sVmName, '--autostart-enabled', 'on'], False, True);
-        fRc = fRc and self.uploadString(oSession, 'password', 'C:\\ProgramData\\password.cfg');
+        fRc = fRc and self.uploadString(oGuestSession, 'password', 'C:\\ProgramData\\password.cfg');
         if fRc:
             (fRc, _, _, _) = \
@@ -1136,9 +1059,11 @@
         return fRc;
 
-    def checkForRunningVM(self, oSession, sUser, sVmName):
+    def checkForRunningVM(self, oSession, oGuestSession, sUser, sVmName):
         """
         Check for VM running in the guest after autostart.
         """
 
+        _ = oGuestSession;
+        
         fRc, oGuestSession = self.createSession(oSession, 'Session for user: %s' % (sUser,),
                                                 sUser, 'password', 10 * 1000, True);
@@ -1159,13 +1084,8 @@
         return fRc;
 
-    def createUser(self, oSession, sUser):
+    def createUser(self, oGuestSession, sUser):
         """
         Create a new user with the given name
         """
-
-        fRc, oGuestSession = self.createSession(oSession, 'Creating user %s to run a VM' % sUser,
-                                                'vbox', 'password', 10 * 1000, True);
-        if not fRc:
-            return fRc;
 
         # Create user
@@ -1216,5 +1136,5 @@
 WScript.Echo "Logon As A Service Right granted to user '"& strUserName &"'"
                            """ % sUser;
-        fRc = fRc and self.uploadString(oSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs');
+        fRc = fRc and self.uploadString(oGuestSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs');
         if fRc:
             (fRc, _, _, _) = self.guestProcessExecute(oGuestSession,
@@ -1226,6 +1146,4 @@
         except:
             fRc = reporter.errorXcpt('Removing policy script failed');
-
-        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
         return fRc;
 
@@ -1245,5 +1163,5 @@
         vbox.TestDriver.__init__(self);
         self.asRsrcs            = None;
-        self.asTestVMsDef       = [self.ksOsLinux, self.ksOsWindows];
+        self.asTestVMsDef       = [self.ksOsWindows, self.ksOsLinux]; #[self.ksOsLinux, self.ksOsWindows];
         self.asTestVMs          = self.asTestVMsDef;
         self.asSkipVMs          = [];
@@ -1428,28 +1346,29 @@
         if oGuestOsHlp is not None:
             #wait the VM is ready after starting
-            fRc = oGuestOsHlp.waitVMisReady(oSession);
+            (fRc, oGuestSession) = oGuestOsHlp.waitVMisReady(oSession);
             #install fresh guest additions
-            fRc = fRc and oGuestOsHlp.installAdditions(oSession, oVM);
+            if fRc:
+                (fRc, oGuestSession) = oGuestOsHlp.installAdditions(oSession, oGuestSession, oVM);
             # Create two new users
-            fRc = fRc and oGuestOsHlp.createUser(oSession, sTestUserAllow);
-            fRc = fRc and oGuestOsHlp.createUser(oSession, sTestUserDeny);
+            fRc = fRc and oGuestOsHlp.createUser(oGuestSession, sTestUserAllow);
+            fRc = fRc and oGuestOsHlp.createUser(oGuestSession, sTestUserDeny);
             if fRc is True:
                 # Install VBox first
-                fRc = oGuestOsHlp.installVirtualBox(oSession);
+                fRc = oGuestOsHlp.installVirtualBox(oGuestSession);
                 if fRc is True:
-                    fRc = oGuestOsHlp.configureAutostart(oSession, 'allow', (sTestUserAllow,), (sTestUserDeny,));
+                    fRc = oGuestOsHlp.configureAutostart(oGuestSession, 'allow', (sTestUserAllow,), (sTestUserDeny,));
                     if fRc is True:
                         # Create a VM with autostart enabled in the guest for both users
-                        fRc = oGuestOsHlp.createTestVM(oSession, sTestUserAllow, sTestVmName);
-                        fRc = fRc and oGuestOsHlp.createTestVM(oSession, sTestUserDeny, sTestVmName);
+                        fRc = oGuestOsHlp.createTestVM(oSession, oGuestSession, sTestUserAllow, sTestVmName);
+                        fRc = fRc and oGuestOsHlp.createTestVM(oSession, oGuestSession, sTestUserDeny, sTestVmName);
                         if fRc is True:
                             # Reboot the guest
-                            fRc = oGuestOsHlp.rebootVMAndCheckReady(oSession);
+                            (fRc, oGuestSession) = oGuestOsHlp.rebootVMAndCheckReady(oSession, oGuestSession);
                             if fRc is True:
                                 # Fudge factor - Allow the guest to finish starting up.
                                 self.sleep(30);
-                                fRc = oGuestOsHlp.checkForRunningVM(oSession, sTestUserAllow, sTestVmName);
+                                fRc = oGuestOsHlp.checkForRunningVM(oSession, oGuestSession, sTestUserAllow, sTestVmName);
                                 if fRc is True:
-                                    fRc = oGuestOsHlp.checkForRunningVM(oSession, sTestUserDeny, sTestVmName);
+                                    fRc = oGuestOsHlp.checkForRunningVM(oSession, oGuestSession, sTestUserDeny, sTestVmName);
                                     if fRc is True:
                                         reporter.error('Test VM is running inside the guest for denied user');
@@ -1468,7 +1387,7 @@
                 reporter.log('Creating test users failed');
 
-            try:    oGuestOsHlp.powerDownVM(oSession);
-            except: pass;
-
+            if oGuestSession is not None:
+                try:    oGuestOsHlp.powerDownVM(oGuestSession);
+                except: pass;
         else:
             reporter.log('Guest OS helper not created for VM %s' % (sVmName));
