def run()

in core/lib/payload/base.py [0:0]


    def run(self):
        """
        Main logic of the payload
        """
        log.info("reading SQL files")
        self.read_ddl_files()

        # Get the connection to MySQL ready, so we don't have to create a new
        # connection each time we want to execute a SQL
        if not self.init_conn():
            raise OSCError(
                "FAILED_TO_CONNECT_DB", {"user": self.mysql_user, "socket": self.socket}
            )
        self.set_no_binlog()

        # Check database existence
        if not bool(self.db_list):
            raise OSCError("DB_NOT_GIVEN")

        # Check database existence
        non_exist_dbs = self.check_db_existence()
        if non_exist_dbs:
            raise OSCError("DB_NOT_EXIST", {"db_list": ", ".join(non_exist_dbs)})

        # Test whether the replication role matches
        if self.repl_status:
            if not self.check_replication_type():
                raise OSCError("REPL_ROLE_MISMATCH", {"given_role": self.repl_status})

        # Fetch mysql variables from server
        if not self.fetch_mysql_vars():
            raise OSCError("FAILED_TO_FETCH_MYSQL_VARS")

        # Iterate through all the specified databases
        for db in self.db_list:
            log.info("Running changes for database: '{}'".format(db))
            # Iterate through all the given sql files
            for job in self.sql_list:
                log.info("Running SQLs from file: '{}'".format(job["filepath"]))
                try:
                    if not self.init_conn():
                        raise OSCError(
                            "FAILED_TO_CONNECT_DB",
                            {"user": self.mysql_user, "socket": self.socket},
                        )
                    if self.standardize:
                        self.run_ddl(db, job["sql_obj"].to_sql())
                    else:
                        self.run_ddl(db, job["raw_sql"])
                    log.info(
                        "Successfully run changes from file: '{}'".format(
                            job["filepath"]
                        )
                    )
                except Exception as e:
                    if not self.force:
                        raise
                    else:
                        log.warning(
                            "Following error is ignored because of "
                            "force mode is enabled: "
                        )
                        log.warning("\t{}".format(e))
            log.info("Changes for database '{}' finished".format(db))