Github user kaknikhil commented on a diff in the pull request:
https://github.com/apache/madlib/pull/271#discussion_r191607552
--- Diff: src/madpack/madpack.py ---
@@ -824,6 +873,246 @@ def parse_arguments():
# Get the arguments
return parser.parse_args()
+def run_install_check(args, testcase):
+ schema = args['schema']
+ dbrev = args['dbrev']
+ # 1) Compare OS and DB versions. Continue if OS = DB.
+ if get_rev_num(dbrev) != get_rev_num(rev):
+ _print_revs(rev, dbrev, con_args, schema)
+ info_(this, "Versions do not match. Install-check stopped.", True)
+ return
+
+ # Create install-check user
+ test_user = ('madlib_' +
+ rev.replace('.', '').replace('-', '_') +
+ '_installcheck')
+ try:
+ _internal_run_query("DROP USER IF EXISTS %s;" % (test_user), False)
+ except:
+ _internal_run_query("DROP OWNED BY %s CASCADE;" % (test_user),
True)
+ _internal_run_query("DROP USER IF EXISTS %s;" % (test_user), True)
+ _internal_run_query("CREATE USER %s;" % (test_user), True)
+
+ _internal_run_query("GRANT USAGE ON SCHEMA %s TO %s;" % (schema,
test_user), True)
+
+ # 2) Run test SQLs
+ info_(this, "> Running test scripts for:", verbose)
+
+ caseset = (set([test.strip() for test in testcase.split(',')])
+ if testcase != "" else set())
+
+ modset = {}
+ for case in caseset:
+ if case.find('/') > -1:
+ [mod, algo] = case.split('/')
+ if mod not in modset:
+ modset[mod] = []
+ if algo not in modset[mod]:
+ modset[mod].append(algo)
+ else:
+ modset[case] = []
+
+ # Loop through all modules
+ for moduleinfo in portspecs['modules']:
+
+ # Get module name
+ module = moduleinfo['name']
+
+ # Skip if doesn't meet specified modules
+ if modset is not None and len(modset) > 0 and module not in modset:
+ continue
+ # JIRA: MADLIB-1078 fix
+ # Skip pmml during install-check (when run without the -t option).
+ # We can still run install-check on pmml with '-t' option.
+ if not modset and module in ['pmml']:
+ continue
+ info_(this, "> - %s" % module, verbose)
+
+ # Make a temp dir for this module (if doesn't exist)
+ cur_tmpdir = tmpdir + '/' + module + '/test' # tmpdir is a global
variable
+ _make_dir(cur_tmpdir)
+
+ # Find the Python module dir (platform specific or generic)
+ if os.path.isdir(maddir + "/ports/" + portid + "/" + dbver +
"/modules/" + module):
+ maddir_mod_py = maddir + "/ports/" + portid + "/" + dbver +
"/modules"
+ else:
+ maddir_mod_py = maddir + "/modules"
+
+ # Find the SQL module dir (platform specific or generic)
+ if os.path.isdir(maddir + "/ports/" + portid + "/modules/" +
module):
+ maddir_mod_sql = maddir + "/ports/" + portid + "/modules"
+ else:
+ maddir_mod_sql = maddir + "/modules"
+
+ # Prepare test schema
+ test_schema = "madlib_installcheck_%s" % (module)
+ _internal_run_query("DROP SCHEMA IF EXISTS %s CASCADE; CREATE
SCHEMA %s;" %
+ (test_schema, test_schema), True)
+ _internal_run_query("GRANT ALL ON SCHEMA %s TO %s;" %
+ (test_schema, test_user), True)
+
+ # Switch to test user and prepare the search_path
+ pre_sql = '-- Switch to test user:\n' \
+ 'SET ROLE %s;\n' \
+ '-- Set SEARCH_PATH for install-check:\n' \
+ 'SET search_path=%s,%s;\n' \
+ % (test_user, test_schema, schema)
+
+ # Loop through all test SQL files for this module
+ sql_files = maddir_mod_sql + '/' + module + '/test/*.sql_in'
+ for sqlfile in sorted(glob.glob(sql_files), reverse=True):
+ algoname = os.path.basename(sqlfile).split('.')[0]
+ # run only algo specified
+ if (module in modset and modset[module] and
+ algoname not in modset[module]):
+ continue
+
+ # Set file names
+ tmpfile = cur_tmpdir + '/' + os.path.basename(sqlfile) + '.tmp'
+ logfile = cur_tmpdir + '/' + os.path.basename(sqlfile) + '.log'
+
+ # If there is no problem with the SQL file
+ milliseconds = 0
+
+ # Run the SQL
+ run_start = datetime.datetime.now()
+ retval = _run_sql_file_install_check(schema, maddir_mod_py,
+ module, sqlfile, tmpfile,
+ logfile, pre_sql)
+ # Runtime evaluation
+ run_end = datetime.datetime.now()
+ milliseconds = round((run_end - run_start).seconds * 1000 +
+ (run_end - run_start).microseconds / 1000)
+
+ # Check the exit status
+ result = _parse_result_logfile(retval, logfile, tmpfile,
sqlfile,
+ module, milliseconds)
+
+ # Cleanup test schema for the module
+ _internal_run_query("DROP SCHEMA IF EXISTS %s CASCADE;" %
(test_schema), True)
+
+ # Drop install-check user
+ _internal_run_query("DROP OWNED BY %s CASCADE;" % (test_user), True)
+ _internal_run_query("DROP USER %s;" % (test_user), True)
+
+def create_install_madlib_sqlfile(args, madpack_cmd, testcase):
+ upgrade = args['upgrade']
+ schema = args['schema']
+ dbrev = args['dbrev']
+ is_schema_in_db = args['is_schema_in_db']
+ with open(args['output_filename'], 'a+') as output_filehandle:
+ # COMMAND: uninstall/reinstall
--- End diff --
can we create separate functions for uninstall , reinstall/install and
upgrade ?
---