Skip to content

Commit

Permalink
[Feature:System] schema validator on gradeable build (Submitty#5632)
Browse files Browse the repository at this point in the history
* Added schema validation to the assignment build process

* Use better error message function

* Fix permissions for web building

Co-authored-by: Barb Cutler <[email protected]>
  • Loading branch information
emaicus and bmcutler authored Jul 13, 2020
1 parent ca76c9a commit 0eba409
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .setup/INSTALL_SUBMITTY_HELPER_BIN.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash


########################################################################################################################
########################################################################################################################
Expand Down Expand Up @@ -34,7 +34,7 @@ for i in "${array[@]}"; do
done

# COURSE_BUILDERS & DAEMON_USER need access to these scripts
array=( build_homework_function.sh make_assignments_txt_file.py make_generated_output.py )
array=( build_homework_function.sh make_assignments_txt_file.py make_generated_output.py config_syntax_check.py json_schemas json_schemas/complete_config_schema.json )
for i in "${array[@]}"; do
chown ${DAEMON_USER}:${COURSE_BUILDERS_GROUP} ${SUBMITTY_INSTALL_DIR}/bin/${i}
chmod 550 ${SUBMITTY_INSTALL_DIR}/bin/${i}
Expand Down
9 changes: 7 additions & 2 deletions bin/build_homework_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ function build_homework {
date
echo "INSTALL assignment config: $hw_source"
echo " destination: $hw_build_path"




# copy the files to the build directory
# copy the files to the build directory
rsync -ruz --delete $hw_source/ $hw_build_path || ( echo 'ERROR: configuration source directory does not exist or DAEMON_USER cannot read this directory' ; exit 1 )
find $hw_build_path -type d -exec chmod -f ug+rwx,g+s,o= {} \;
find $hw_build_path -type f -exec chmod -f ug+rw,o= {} \;
Expand Down Expand Up @@ -176,6 +175,12 @@ function build_homework {
# quit (don't continue on to build other homeworks) if there is a compile error
make -j 8 > $hw_build_path/log_make_output.txt 2>&1

# run the schema validator on the complete_config generated by the build process
$SUBMITTY_INSTALL_DIR/bin/config_syntax_check.py $hw_source $assignment $semester $course

# generate queue file for generated_output
$SUBMITTY_INSTALL_DIR/bin/make_generated_output.py $hw_source $assignment $semester $course

# capture exit code of make
make_res=$?
chmod -f 660 $hw_build_path/log_make_output.txt
Expand Down
77 changes: 77 additions & 0 deletions bin/config_syntax_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3

"""
# USAGE
# config_syntax_check.py <path to config file for gradeable> <assignment> <semester> <course>
"""

import argparse
import json
import os
from submitty_utils import submitty_schema_validator
import sys
import traceback

CONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'config')
with open(os.path.join(CONFIG_PATH, 'submitty.json')) as open_file:
OPEN_JSON = json.load(open_file)
SUBMITTY_INSTALL_DIR = OPEN_JSON['submitty_install_dir']
SUBMITTY_DATA_DIR = OPEN_JSON['submitty_data_dir']


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("config_file_path")
parser.add_argument("assignment")
parser.add_argument("semester")
parser.add_argument("course")
return parser.parse_args()


def main():
# Parse the argument necessary to find the complete config json.
args = parse_args()
# Grab the path to the complete config json for this assignment
complete_config_json_path = os.path.join(
SUBMITTY_DATA_DIR,
'courses',
args.semester,
args.course,
'config',
'complete_config',
f'complete_config_{args.assignment}.json'
)

# Get the path to the complete config schema.
complete_config_schema_path = os.path.join(
SUBMITTY_INSTALL_DIR,
'bin',
'json_schemas',
'complete_config_schema.json'
)

# Verify that the two files exist
for json_path in [complete_config_json_path, complete_config_schema_path]:
if not os.path.isfile(json_path):
print(f"Error, the following file is missing on your system: {json_path}")
sys.exit(1)

# Run the schema validator, printing an error on failure.
try:
submitty_schema_validator.validate_complete_config_schema_using_filenames(
complete_config_json_path,
complete_config_schema_path,
warn=False
)
except submitty_schema_validator.SubmittySchemaException as s:
s.print_human_readable_error()
print("The submitty configuration validator detected the above error in your config.")
print("This is a new feature. If you feel that an error was incorrectly identified,")
print("please submit an error report at https://github.com/Submitty/Submitty")
print()
except Exception:
traceback.print_exc()


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def print_human_readable_error(self):
print(("The portion of your configuration that caused "
"the error is:"), file=sys.stderr)
print(json.dumps(self.config_json, indent=4), file=sys.stderr)
print(self.schema_message, file=sys.stderr)


def validate_testcases(testcases, s_, name='', warn=None):
Expand Down

0 comments on commit 0eba409

Please sign in to comment.