Beispiel #1
0
def _doUpgradeApply(sUpgradeDir, asMembers):
    """
    # Apply the directories and files from the upgrade.
    returns True/False/Exception.
    """

    #
    # Create directories first since that's least intrusive.
    #
    for sMember in asMembers:
        if sMember[-1] == '/':
            sMember = sMember[len('testboxscript/'):]
            if sMember != '':
                sFull = os.path.join(g_ksValidationKitDir, sMember)
                if not os.path.isdir(sFull):
                    os.makedirs(sFull, 0755)

    #
    # Move the files into place.
    #
    fRc = True
    asOldFiles = []
    for sMember in asMembers:
        if sMember[-1] != '/':
            sSrc = os.path.join(sUpgradeDir, sMember)
            sDst = os.path.join(g_ksValidationKitDir,
                                sMember[len('testboxscript/'):])

            # Move the old file out of the way first.
            sDstRm = None
            if os.path.exists(sDst):
                testboxcommons.log2('Info: Installing "%s"' % (sDst, ))
                sDstRm = '%s-delete-me-%s' % (
                    sDst,
                    uuid.uuid4(),
                )
                try:
                    os.rename(sDst, sDstRm)
                except Exception, oXcpt:
                    testboxcommons.log(
                        'Error: failed to rename (old) "%s" to "%s": %s' %
                        (sDst, sDstRm, oXcpt))
                    try:
                        shutil.copy(sDst, sDstRm)
                    except Exception, oXcpt:
                        testboxcommons.log(
                            'Error: failed to copy (old) "%s" to "%s": %s' %
                            (sDst, sDstRm, oXcpt))
                        break
                    try:
                        os.unlink(sDst)
                    except Exception, oXcpt:
                        testboxcommons.log(
                            'Error: failed to unlink (old) "%s": %s' %
                            (sDst, oXcpt))
                        break
def _doUpgradeRemoveOldStuff(sUpgradeDir, asMembers):
    """
    Clean up all obsolete files and directories.
    Returns True (shouldn't fail or raise any exceptions).
    """

    try:
        shutil.rmtree(sUpgradeDir, ignore_errors=True)
    except:
        pass

    asKnownFiles = []
    asKnownDirs = []
    for sMember in asMembers:
        sMember = sMember[len('testboxscript/'):]
        if sMember == '':
            continue
        if sMember[-1] == '/':
            asKnownDirs.append(
                os.path.normpath(
                    os.path.join(g_ksValidationKitDir, sMember[:-1])))
        else:
            asKnownFiles.append(
                os.path.normpath(os.path.join(g_ksValidationKitDir, sMember)))

    for sDirPath, asDirs, asFiles in os.walk(g_ksValidationKitDir,
                                             topdown=False):
        for sDir in asDirs:
            sFull = os.path.normpath(os.path.join(sDirPath, sDir))
            if sFull not in asKnownDirs:
                testboxcommons.log2('Info: Removing obsolete directory "%s"' %
                                    (sFull, ))
                try:
                    os.rmdir(sFull)
                except Exception as oXcpt:
                    testboxcommons.log(
                        'Warning: failed to rmdir obsolete dir "%s": %s' %
                        (sFull, oXcpt))

        for sFile in asFiles:
            sFull = os.path.normpath(os.path.join(sDirPath, sFile))
            if sFull not in asKnownFiles:
                testboxcommons.log2('Info: Removing obsolete file "%s"' %
                                    (sFull, ))
                try:
                    os.unlink(sFull)
                except Exception as oXcpt:
                    testboxcommons.log(
                        'Warning: failed to unlink obsolete file "%s": %s' %
                        (sFull, oXcpt))
    return True
def _doUpgradeApply(sUpgradeDir, asMembers):
    """
    # Apply the directories and files from the upgrade.
    returns True/False/Exception.
    """

    #
    # Create directories first since that's least intrusive.
    #
    for sMember in asMembers:
        if sMember[-1] == "/":
            sMember = sMember[len("testboxscript/") :]
            if sMember != "":
                sFull = os.path.join(g_ksValidationKitDir, sMember)
                if not os.path.isdir(sFull):
                    os.makedirs(sFull, 0755)

    #
    # Move the files into place.
    #
    fRc = True
    asOldFiles = []
    for sMember in asMembers:
        if sMember[-1] != "/":
            sSrc = os.path.join(sUpgradeDir, sMember)
            sDst = os.path.join(g_ksValidationKitDir, sMember[len("testboxscript/") :])

            # Move the old file out of the way first.
            sDstRm = None
            if os.path.exists(sDst):
                testboxcommons.log2('Info: Installing "%s"' % (sDst,))
                sDstRm = "%s-delete-me-%s" % (sDst, uuid.uuid4())
                try:
                    os.rename(sDst, sDstRm)
                except Exception, oXcpt:
                    testboxcommons.log('Error: failed to rename (old) "%s" to "%s": %s' % (sDst, sDstRm, oXcpt))
                    try:
                        shutil.copy(sDst, sDstRm)
                    except Exception, oXcpt:
                        testboxcommons.log('Error: failed to copy (old) "%s" to "%s": %s' % (sDst, sDstRm, oXcpt))
                        break
                    try:
                        os.unlink(sDst)
                    except Exception, oXcpt:
                        testboxcommons.log('Error: failed to unlink (old) "%s": %s' % (sDst, oXcpt))
                        break
def _doUpgradeRemoveOldStuff(sUpgradeDir, asMembers):
    """
    Clean up all obsolete files and directories.
    Returns True (shouldn't fail or raise any exceptions).
    """

    try:
        shutil.rmtree(sUpgradeDir, ignore_errors = True);
    except:
        pass;

    asKnownFiles = [];
    asKnownDirs  = [];
    for sMember in asMembers:
        sMember = sMember[len('testboxscript/'):];
        if sMember == '':
            continue;
        if sMember[-1] == '/':
            asKnownDirs.append(os.path.normpath(os.path.join(g_ksValidationKitDir, sMember[:-1])));
        else:
            asKnownFiles.append(os.path.normpath(os.path.join(g_ksValidationKitDir, sMember)));

    for sDirPath, asDirs, asFiles in os.walk(g_ksValidationKitDir, topdown=False):
        for sDir in asDirs:
            sFull = os.path.normpath(os.path.join(sDirPath, sDir));
            if sFull not in asKnownDirs:
                testboxcommons.log2('Info: Removing obsolete directory "%s"' % (sFull,));
                try:
                    os.rmdir(sFull);
                except Exception as oXcpt:
                    testboxcommons.log('Warning: failed to rmdir obsolete dir "%s": %s' % (sFull, oXcpt));

        for sFile in asFiles:
            sFull = os.path.normpath(os.path.join(sDirPath, sFile));
            if sFull not in asKnownFiles:
                testboxcommons.log2('Info: Removing obsolete file "%s"' % (sFull,));
                try:
                    os.unlink(sFull);
                except Exception as oXcpt:
                    testboxcommons.log('Warning: failed to unlink obsolete file "%s": %s' % (sFull, oXcpt));
    return True;
Beispiel #5
0
                        shutil.copy(sDst, sDstRm)
                    except Exception, oXcpt:
                        testboxcommons.log(
                            'Error: failed to copy (old) "%s" to "%s": %s' %
                            (sDst, sDstRm, oXcpt))
                        break
                    try:
                        os.unlink(sDst)
                    except Exception, oXcpt:
                        testboxcommons.log(
                            'Error: failed to unlink (old) "%s": %s' %
                            (sDst, oXcpt))
                        break

            # Move/copy the new one into place.
            testboxcommons.log2('Info: Installing "%s"' % (sDst, ))
            try:
                os.rename(sSrc, sDst)
            except Exception, oXcpt:
                testboxcommons.log(
                    'Warning: failed to rename (new) "%s" to "%s": %s' %
                    (sSrc, sDst, oXcpt))
                try:
                    shutil.copy(sSrc, sDst)
                except:
                    testboxcommons.log(
                        'Error: failed to copy (new) "%s" to "%s": %s' %
                        (sSrc, sDst, oXcpt))
                    fRc = False
                    break
def _doUpgradeApply(sUpgradeDir, asMembers):
    """
    # Apply the directories and files from the upgrade.
    returns True/False/Exception.
    """

    #
    # Create directories first since that's least intrusive.
    #
    for sMember in asMembers:
        if sMember[-1] == '/':
            sMember = sMember[len('testboxscript/'):]
            if sMember != '':
                sFull = os.path.join(g_ksValidationKitDir, sMember)
                if not os.path.isdir(sFull):
                    os.makedirs(sFull, 0o755)

    #
    # Move the files into place.
    #
    fRc = True
    asOldFiles = []
    for sMember in asMembers:
        if sMember[-1] != '/':
            sSrc = os.path.join(sUpgradeDir, sMember)
            sDst = os.path.join(g_ksValidationKitDir,
                                sMember[len('testboxscript/'):])

            # Move the old file out of the way first.
            sDstRm = None
            if os.path.exists(sDst):
                testboxcommons.log2('Info: Installing "%s"' % (sDst, ))
                sDstRm = '%s-delete-me-%s' % (
                    sDst,
                    uuid.uuid4(),
                )
                try:
                    os.rename(sDst, sDstRm)
                except Exception as oXcpt:
                    testboxcommons.log(
                        'Error: failed to rename (old) "%s" to "%s": %s' %
                        (sDst, sDstRm, oXcpt))
                    try:
                        shutil.copy(sDst, sDstRm)
                    except Exception as oXcpt:
                        testboxcommons.log(
                            'Error: failed to copy (old) "%s" to "%s": %s' %
                            (sDst, sDstRm, oXcpt))
                        break
                    try:
                        os.unlink(sDst)
                    except Exception as oXcpt:
                        testboxcommons.log(
                            'Error: failed to unlink (old) "%s": %s' %
                            (sDst, oXcpt))
                        break

            # Move/copy the new one into place.
            testboxcommons.log2('Info: Installing "%s"' % (sDst, ))
            try:
                os.rename(sSrc, sDst)
            except Exception as oXcpt:
                testboxcommons.log(
                    'Warning: failed to rename (new) "%s" to "%s": %s' %
                    (sSrc, sDst, oXcpt))
                try:
                    shutil.copy(sSrc, sDst)
                except:
                    testboxcommons.log(
                        'Error: failed to copy (new) "%s" to "%s": %s' %
                        (sSrc, sDst, oXcpt))
                    fRc = False
                    break

    #
    # Roll back on failure.
    #
    if fRc is not True:
        testboxcommons.log('Attempting to roll back old files...')
        for sDstRm in asOldFiles:
            sDst = sDstRm[:sDstRm.rfind('-delete-me')]
            testboxcommons.log2('Info: Rolling back "%s" (%s)' %
                                (sDst, os.path.basename(sDstRm)))
            try:
                shutil.move(sDstRm, sDst)
            except:
                testboxcommons.log(
                    'Error: failed to rollback "%s" onto "%s": %s' %
                    (sDstRm, sDst, oXcpt))
        return False
    return True
Beispiel #7
0
    def _threadProc(self):
        """
        Do the work of an EXEC command.
        """

        sResult = constants.result.PASSED;

        #
        # Start by preparing the scratch directories.
        #
        # Note! Failures at this stage are not treated as real errors since
        #       they may be caused by the previous test and other circumstances
        #       so we don't want to go fail a build because of this.
        #
        fRc = self._oTestBoxScript.reinitScratch(self._logInternal);
        fNeedCleanUp = fRc;
        if fRc is True:
            fRc = self._downloadAndUnpackScriptZips();
            testboxcommons.log2('_threadProc: _downloadAndUnpackScriptZips -> %s' % (fRc,));
        if fRc is not True:
            sResult = constants.result.BAD_TESTBOX;

        #
        # Make sure the script exists.
        #
        if fRc is True:
            sScript = self._assembleArguments('none', fWithInterpreter = False)[0];
            if not os.path.exists(sScript):
                self._log('The test driver script "%s" cannot be found.' % (sScript,));
                sDir = sScript;
                while len(sDir) > 3:
                    sDir = os.path.dirname(sDir);
                    if os.path.exists(sDir):
                        self._log('First existing parent directory is "%s".' % (sDir,));
                        break;
                fRc = False;

        if fRc is True:
            #
            # Start testdriver script.
            #
            fRc = self._saveState();
            if fRc:
                (fRc, self._oChild) = self._spawnChild('all');
                testboxcommons.log2('_threadProc: _spawnChild -> %s, %s' % (fRc, self._oChild));
            if fRc:
                (fRc, sResult) = self._monitorChild(self._cSecTimeout);
                testboxcommons.log2('_threadProc: _monitorChild -> %s' % (fRc,));

                # If the run failed, do explicit cleanup.
                if fRc is not True:
                    testboxcommons.log2('_threadProc: explicit cleanups...');
                    self._terminateChild();
                    self._cleanupAfter();
                    fNeedCleanUp = False;
            assert self._oChild is None;

        #
        # Clean up scratch.
        #
        if fNeedCleanUp:
            if self._oTestBoxScript.reinitScratch(self._logInternal, cRetries = 6) is not True:
                self._log('post run reinitScratch failed.');
                fRc = False;

        #
        # Report status and everything back to the test manager.
        #
        if fRc is False and sResult == constants.result.PASSED:
            sResult = constants.result.FAILED;
        self._reportDone(sResult);
        return fRc;
    def _threadProc(self):
        """
        Do the work of an EXEC command.
        """

        sResult = constants.result.PASSED;

        #
        # Start by preparing the scratch directories.
        #
        # Note! Failures at this stage are not treated as real errors since
        #       they may be caused by the previous test and other circumstances
        #       so we don't want to go fail a build because of this.
        #
        fRc = self._oTestBoxScript.reinitScratch(self._logInternal);
        fNeedCleanUp = fRc;
        if fRc is True:
            fRc = self._downloadAndUnpackScriptZips();
            testboxcommons.log2('_threadProc: _downloadAndUnpackScriptZips -> %s' % (fRc,));
        if fRc is not True:
            sResult = constants.result.BAD_TESTBOX;

        #
        # Make sure the script exists.
        #
        if fRc is True:
            sScript = self._assembleArguments('none', fWithInterpreter = False)[0];
            if not os.path.exists(sScript):
                self._log('The test driver script "%s" cannot be found.' % (sScript,));
                sDir = sScript;
                while len(sDir) > 3:
                    sDir = os.path.dirname(sDir);
                    if os.path.exists(sDir):
                        self._log('First existing parent directory is "%s".' % (sDir,));
                        break;
                fRc = False;

        if fRc is True:
            #
            # Start testdriver script.
            #
            fRc = self._saveState();
            if fRc:
                (fRc, self._oChild) = self._spawnChild('all');
                testboxcommons.log2('_threadProc: _spawnChild -> %s, %s' % (fRc, self._oChild));
            if fRc:
                (fRc, sResult) = self._monitorChild(self._cSecTimeout);
                testboxcommons.log2('_threadProc: _monitorChild -> %s' % (fRc,));

                # If the run failed, do explicit cleanup.
                if fRc is not True:
                    testboxcommons.log2('_threadProc: explicit cleanups...');
                    self._terminateChild();
                    self._cleanupAfter();
                    fNeedCleanUp = False;
            assert self._oChild is None;

        #
        # Clean up scratch.
        #
        if fNeedCleanUp:
            if self._oTestBoxScript.reinitScratch(self._logInternal, cRetries = 6) is not True:
                self._log('post run reinitScratch failed.');
                fRc = False;

        #
        # Report status and everything back to the test manager.
        #
        if fRc is False and sResult == constants.result.PASSED:
            sResult = constants.result.FAILED;
        self._reportDone(sResult);
        return fRc;
                    os.rename(sDst, sDstRm)
                except Exception, oXcpt:
                    testboxcommons.log('Error: failed to rename (old) "%s" to "%s": %s' % (sDst, sDstRm, oXcpt))
                    try:
                        shutil.copy(sDst, sDstRm)
                    except Exception, oXcpt:
                        testboxcommons.log('Error: failed to copy (old) "%s" to "%s": %s' % (sDst, sDstRm, oXcpt))
                        break
                    try:
                        os.unlink(sDst)
                    except Exception, oXcpt:
                        testboxcommons.log('Error: failed to unlink (old) "%s": %s' % (sDst, oXcpt))
                        break

            # Move/copy the new one into place.
            testboxcommons.log2('Info: Installing "%s"' % (sDst,))
            try:
                os.rename(sSrc, sDst)
            except Exception, oXcpt:
                testboxcommons.log('Warning: failed to rename (new) "%s" to "%s": %s' % (sSrc, sDst, oXcpt))
                try:
                    shutil.copy(sSrc, sDst)
                except:
                    testboxcommons.log('Error: failed to copy (new) "%s" to "%s": %s' % (sSrc, sDst, oXcpt))
                    fRc = False
                    break

    #
    # Roll back on failure.
    #
    if fRc is not True:
def _doUpgradeApply(sUpgradeDir, asMembers):
    """
    # Apply the directories and files from the upgrade.
    returns True/False/Exception.
    """

    #
    # Create directories first since that's least intrusive.
    #
    for sMember in asMembers:
        if sMember[-1] == '/':
            sMember = sMember[len('testboxscript/'):];
            if sMember != '':
                sFull = os.path.join(g_ksValidationKitDir, sMember);
                if not os.path.isdir(sFull):
                    os.makedirs(sFull, 0o755);

    #
    # Move the files into place.
    #
    fRc = True;
    asOldFiles = [];
    for sMember in asMembers:
        if sMember[-1] != '/':
            sSrc = os.path.join(sUpgradeDir, sMember);
            sDst = os.path.join(g_ksValidationKitDir, sMember[len('testboxscript/'):]);

            # Move the old file out of the way first.
            sDstRm = None;
            if os.path.exists(sDst):
                testboxcommons.log2('Info: Installing "%s"' % (sDst,));
                sDstRm = '%s-delete-me-%s' % (sDst, uuid.uuid4(),);
                try:
                    os.rename(sDst, sDstRm);
                except Exception as oXcpt:
                    testboxcommons.log('Error: failed to rename (old) "%s" to "%s": %s' % (sDst, sDstRm, oXcpt));
                    try:
                        shutil.copy(sDst, sDstRm);
                    except Exception as oXcpt:
                        testboxcommons.log('Error: failed to copy (old) "%s" to "%s": %s' % (sDst, sDstRm, oXcpt));
                        break;
                    try:
                        os.unlink(sDst);
                    except Exception as oXcpt:
                        testboxcommons.log('Error: failed to unlink (old) "%s": %s' % (sDst, oXcpt));
                        break;

            # Move/copy the new one into place.
            testboxcommons.log2('Info: Installing "%s"' % (sDst,));
            try:
                os.rename(sSrc, sDst);
            except Exception as oXcpt:
                testboxcommons.log('Warning: failed to rename (new) "%s" to "%s": %s' % (sSrc, sDst, oXcpt));
                try:
                    shutil.copy(sSrc, sDst);
                except:
                    testboxcommons.log('Error: failed to copy (new) "%s" to "%s": %s' % (sSrc, sDst, oXcpt));
                    fRc = False;
                    break;

    #
    # Roll back on failure.
    #
    if fRc is not True:
        testboxcommons.log('Attempting to roll back old files...');
        for sDstRm in asOldFiles:
            sDst = sDstRm[:sDstRm.rfind('-delete-me')];
            testboxcommons.log2('Info: Rolling back "%s" (%s)' % (sDst, os.path.basename(sDstRm)));
            try:
                shutil.move(sDstRm, sDst);
            except:
                testboxcommons.log('Error: failed to rollback "%s" onto "%s": %s' % (sDstRm, sDst, oXcpt));
        return False;
    return True;