Github user njayaram2 commented on a diff in the pull request: https://github.com/apache/madlib/pull/271#discussion_r192191872 --- Diff: src/madpack/madpack.py --- @@ -238,6 +311,88 @@ def _run_sql_file(schema, maddir_mod_py, module, sqlfile, return retval # ------------------------------------------------------------------------------ +def _run_sql_file(schema, sqlfile): + """ + Run SQL file + @param schema name of the target schema + @param sqlfile name of the file to parse + """ + # Run the SQL using DB command-line utility + if portid in SUPPORTED_PORTS: + sqlcmd = 'psql' + # Test the DB cmd line utility + std, err = subprocess.Popen(['which', sqlcmd], stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate() + if not std: + error_(this, "Command not found: %s" % sqlcmd, True) + + runcmd = [sqlcmd, '-a', + '-v', 'ON_ERROR_STOP=1', + '-h', con_args['host'].split(':')[0], + '-p', con_args['host'].split(':')[1], + '-d', con_args['database'], + '-U', con_args['user'], + '--no-password', + '--single-transaction', + '-f', sqlfile] + runenv = os.environ + if 'password' in con_args: + runenv["PGPASSWORD"] = con_args['password'] + runenv["PGOPTIONS"] = '-c client_min_messages=notice' + + # Open log file + logfile = sqlfile + '.log' + try: + log = open(logfile, 'w') + except: + error_(this, "Cannot create log file: %s" % logfile, False) + raise Exception + + # Run the SQL + try: + info_(this, "> ... executing " + sqlfile, verbose) + info_(this, ' '.join(runcmd), verbose) + retval = subprocess.call(runcmd, env=runenv, stdout=log, stderr=log) + except: + error_(this, "Failed executing %s" % sqlfile, False) + raise Exception + finally: + log.close() + # Check the exit status + result = _parse_result_logfile(retval, logfile, sqlfile) + return result +# ------------------------------------------------------------------------------ + +def _parse_result_logfile(retval, logfile, sql_abspath, + sql_filename=None, module=None, milliseconds=None): + """ + Function to parse the logfile and return if its content indicate a failure + or success. + """ + is_install_check_logfile = bool(sql_filename and module) + # Check the exit status + if retval != 0: + result = 'FAIL' + global keeplogs + keeplogs = True + # Since every single statement in the test file gets logged, + # an empty log file indicates an empty or a failed test + elif os.path.isfile(logfile) and os.path.getsize(logfile) > 0: + result = 'PASS' + # Otherwise + else: + result = 'ERROR' + + if is_install_check_logfile: --- End diff -- That would change the order of messages. If we want to preserve the order, then we would have to duplicate the code wherever this function gets called.
---