def confirmYesOrNo(message):
    message = message + "\n\nYour answer:\n\n(Y) Yes \n(<any other key>) No "
    answer = getAnswerFromUser(message)
    if (re.compile('^y$', re.I)).match(answer):
        return True
    else:
        return False
def continueOrCancel(message):
    message = message + "\n\nSelect your action:\n\n(I) Continue execution \n(<any other key>) Raise error and get the option to rollback (NOTE: Some actions cannot be rolled back) "
    answer = getAnswerFromUser(message)
    if (re.compile('^i$', re.I)).match(answer):
        pass
    else:
        raise Exception
Exemple #3
0
 def undoSuper(self):
     # If script runs in attended mode then ask
     if not lib.OptParser.options.unattended:                         
         a = getAnswerFromUser("Action '" + self.__class__.__name__ + "' " + str(self.__dict__) + " is ready to execute a rollback action.\n\n Action Documentation:\n" + self.__doc__ +" \n\nSelect your action:\n\n(U) Execute action and continue unattended rollback \n(X) Don't execute current rollback action \n(<any other key>) Execute current action rollback")
         if (re.compile('^u$', re.I)).match(a): lib.OptParser.options.unattended = True
         if (re.compile('^x$', re.I)).match(a):
             log.warn("Skipping the rollback operation of this action '" + self.__class__.__name__ + "' " + str(self.__dict__) + "'")
             return
         
     # Run subclass undo function            
     self.undo()  
Exemple #4
0
    def __init__(self):       
        '''
        Appends this Action to Rollback queue
        '''

        # If script runs in attended mode then ask
        if not lib.OptParser.options.unattended:
            a = getAnswerFromUser("Action '" + self.__class__.__name__ + "' " + str(self.__dict__) + " is ready to execute.\n\n Action Documentation:\n" + self.__doc__ +"\n\nSelect your action:\n\n(U) Execute action and continue unattended \n(X) Don't execute current action \n(<any other key>) Execute current action")
            if (re.compile('^u$', re.I)).match(a): lib.OptParser.options.unattended = True
            if (re.compile('^x$', re.I)).match(a):
                log.warn("Skipping current action '" + self.__class__.__name__ + "' " + str(self.__dict__) + "'")
                return
        
        # Run subclass __call__ function
        self()
        
        # Append this action to rollback queue
        log.debug("Appending action '" + self.__class__.__name__ + "' " + str(self.__dict__) + " to rollback queue" )
        scriptGlobals.executedActionList.append(self)
    def __init__(self, module):
        """
        Constructor
        """
        ActionBundle.__init__(self, module)

        unzippedPackagePath = module.executionContext["unzippedPackagePath"]
        versionInfo = module.executionContext["versionInfo"]
        revisionInfo = module.executionContext["revisionInfo"]
        majorVersionInfo = module.executionContext["majorVersionInfo"]
        guid = module.executionContext["guid"]

        # Compose Oracle DB Connection String
        oracleConnectionString = "%s/%s@%s" % (
            extractOracleDatabaseCredentials(
                module.name,
                lib.OptParser.options.envprops,
                "VNA_CRM_USERNAMEBASE",
                "VNA_CRM_PASSWORDBASE",
                "DBConnectionString",
            )
        )

        # Determine last executed script
        result = getLatestExecutedScript(versionInfo, majorVersionInfo, oracleConnectionString)
        lastExecutedPath, lastExecutedFilename = os.path.split(result.strip())

        if "no rows selected" in lastExecutedFilename:
            answer = getAnswerFromUser(
                "Unable to determine last executed script on '"
                + oracleConnectionString
                + "'. There is a possibility that the scripts in the log table are of an older major version than '"
                + majorVersionInfo
                + "'. (In this case you may want to run all the scripts in your upgrade folder '"
                + unzippedPackagePath
                + scriptGlobals.osDirSeparator
                + module.relativeDatabaseUpgradeFilePath
                + "'). \n\nSelect your actions: \n(E) Execute all scripts in the upgrade folder in alphabetical order \n(<any other key>) Don't run any scripts and continue installation: "
            )
            if (re.compile("^e$", re.I)).match(answer):
                log.info(
                    "Running ALL scripts contained in '"
                    + unzippedPackagePath
                    + scriptGlobals.osDirSeparator
                    + module.relativeDatabaseUpgradeFilePath
                    + "' in alphabetical order."
                )

                # Run scripts on DB
                ls = os.listdir(
                    unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeDatabaseUpgradeFilePath
                )
                ls.sort()
                for patch in ls:
                    appendRequiredStringsToOracleSQLFile(
                        unzippedPackagePath
                        + scriptGlobals.osDirSeparator
                        + module.relativeDatabaseUpgradeFilePath
                        + scriptGlobals.osDirSeparator
                        + patch
                    )
                    RunOracleScriptFromFile(
                        unzippedPackagePath
                        + scriptGlobals.osDirSeparator
                        + module.relativeDatabaseUpgradeFilePath
                        + scriptGlobals.osDirSeparator
                        + patch,
                        oracleConnectionString,
                    )
                    # Log executed scripts
                    logOracleScriptInDBLog(
                        patch,
                        guid,
                        lib.OptParser.options.action,
                        module.name,
                        versionInfo,
                        revisionInfo,
                        oracleConnectionString,
                    )

        else:
            log.info(
                "According to log table, the last script executed on '"
                + oracleConnectionString
                + "' was '"
                + lastExecutedFilename
                + "'"
            )

            # Run scripts on DB
            ls = os.listdir(unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeDatabaseUpgradeFilePath)
            ls.sort()
            found = False
            for patch in ls:
                if found:
                    appendRequiredStringsToOracleSQLFile(
                        unzippedPackagePath
                        + scriptGlobals.osDirSeparator
                        + module.relativeDatabaseUpgradeFilePath
                        + scriptGlobals.osDirSeparator
                        + patch
                    )
                    RunOracleScriptFromFile(
                        unzippedPackagePath
                        + scriptGlobals.osDirSeparator
                        + module.relativeDatabaseUpgradeFilePath
                        + scriptGlobals.osDirSeparator
                        + patch,
                        oracleConnectionString,
                    )
                    # Log executed scripts
                    logOracleScriptInDBLog(
                        patch,
                        guid,
                        lib.OptParser.options.action,
                        module.name,
                        versionInfo,
                        revisionInfo,
                        oracleConnectionString,
                    )
                if patch == lastExecutedFilename:
                    found = True
    prelogic = initClassFromStringWithModule(module.preExecutionLogicClass, module)

    # Initialize & Execute ActionBundles
    for actionbundleClass in module.actionBundleGroupClasses[parser.options.action]:
        ab = initClassFromStringWithModule(actionbundleClass, module)

    # Initialize Post-Execution Logic
    postlogic = initClassFromStringWithModule(module.postExecutionLogicClass, module)

    #    import code; code.interact(local=locals())
except (Exception, KeyboardInterrupt):

    # Actions for rollback exist and this is not Rollback mode?
    if (len(scriptGlobals.executedActionList) > 0) and (not type(sys.exc_info()[1]) == RollbackTriggerException):
        log.error(str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])) 
        answer = getAnswerFromUser(str(sys.exc_info()[0]) + " detected. \n\nSelect your action:\n\n(R) Rollback all actions performed so far \n(<any other key>) Show Exception & Quit")
        if (re.compile('^r$', re.I)).match(answer): rollbackActions(scriptGlobals.executedActionList)
        log.debug("Printing initial exception below")
        log.debug("If you think this error is a bug please file it here: https://jira.velti.com/jira40/browse/FW")
        raise
    # Actions for rollback exist and this is Rollback mode?
    elif (len(scriptGlobals.executedActionList) > 0) and (type(sys.exc_info()[1]) == RollbackTriggerException):
        log.info("Manual rollback mode initiated")
        rollbackActions(scriptGlobals.executedActionList)

    # No Actions for rollback exist        
    else:
        log.error(str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1]))
        log.debug("The executed Action list has 0 elements. Nothing to Rollback.")
        log.debug("Printing initial exception below")
        log.debug("If you think this error is a bug please file it here: https://jira.velti.com/jira40/browse/FW")