From 5b15eded4b800c6babd727af7870979693cdef38 Mon Sep 17 00:00:00 2001 From: Lucian Cojocar Date: Mon, 11 Aug 2014 20:31:16 +0200 Subject: [PATCH] vmchecker: SubmitOnly feature Sometimes we want to use VMchecker only as a submit and save system. Signed-off-by: Lucian Cojocar --- vmchecker/config.py | 9 +++++++ vmchecker/examples/config-template | 8 ++++++ vmchecker/submit.py | 39 +++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/vmchecker/config.py b/vmchecker/config.py index fd06a08..43c3d7b 100644 --- a/vmchecker/config.py +++ b/vmchecker/config.py @@ -181,6 +181,15 @@ def revert_to_snapshot(self, assignment): val = val.strip().lower() return (val == 'yes') or (val == 'y') or (val == 'true') + def submit_only(self, assignment): + """This returns True, when there are no tests defined for this assignment. + This is useful when we want to use VMChecker only as a submission + system. Default is 'no. + """ + val = self.getd(assignment, 'SubmitOnly', 'no') + val = val.strip().lower() + return (val == 'yes') or (val == 'y') or (val == 'true') + def delay_between_tools_and_tests(self, assignment): """After Vmware tools are loaded, there may be some time diff --git a/vmchecker/examples/config-template b/vmchecker/examples/config-template index dea081e..e2bbfd2 100644 --- a/vmchecker/examples/config-template +++ b/vmchecker/examples/config-template @@ -180,6 +180,14 @@ Timeout = 120 # defines an amount of time (in seconds) to wait after tools are # up, but before starting to run the tests. # +# SubmitOnly = [yes|true|y|no] +# +# Optional parameter. +# +# Default is 'no'. If true, then this assignment is used only as a +# versioning system -- i.e. there is no testing involved, what is submited +# is saved in the storer. +# # # These are only for Large assignments # AssignmentStorage = Large # this is a MD5Submission. # AssignmentStoragePort = 22 # the ssh port to use diff --git a/vmchecker/submit.py b/vmchecker/submit.py index 61441a0..caea3f9 100644 --- a/vmchecker/submit.py +++ b/vmchecker/submit.py @@ -27,6 +27,8 @@ from . import submissions from . import vmlogging from . import tempfileutil +from . import callback + from .courselist import CourseList logger = vmlogging.create_module_logger('submit') @@ -191,6 +193,8 @@ def save_submission_in_storer(submission_filename, user, assignment, os.unlink(cur_sb) os.symlink(new_sb, cur_sb) + return sbcfg + @@ -385,8 +389,41 @@ def submit(submission_filename, assignment, user, course_id, check_valid_time(course_id, assignment, user, upload_time_str, skip_toosoon_check, False) - save_submission_in_storer(submission_filename, user, assignment, + sbcfg = save_submission_in_storer(submission_filename, user, assignment, course_id, upload_time_str) + + if vmcfg.assignments().submit_only(assignment): + conf_vars = dict(sbcfg.items('Assignment')) + + try: + t = callback.connect_to_host(conf_vars) + except Exception as e: + # this fails if HOME env var is not defined + # there's hack available + raise Exception("unable to connect to remote host %s" % (e)) + + try: + # prepare sftp connection + sftp = paramiko.SFTPClient.from_transport(t) + callback._setup_logging() + + # create a dummy results grade.vmr + callback.sftp_mkdir_if_not_exits(sftp, conf_vars['resultsdest']) + cmdline = "/bin/echo TODO > '%s'" % \ + os.path.join(conf_vars['resultsdest'], 'grade.vmr') + callback.call_remote_program(t, cmdline) + + # update results + cmdline = 'vmchecker-update-db --course_id=' + conf_vars['courseid'] + \ + ' --user=' + conf_vars['user'] + ' --assignment=' + conf_vars['assignment'] + callback.call_remote_program(t, cmdline) + except Exception as e: + logger.exception("exception while transfering the results: %s" % str(e)) + finally: + t.close() + + return + storage_type = vmcfg.assignments().getd(assignment, "AssignmentStorage", "") if storage_type.lower() != "large": queue_for_testing(assignment, user, course_id)