From 91b6bb649c8d0d0fbd54d18293d5ce6244391c42 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 9 Aug 2012 13:28:13 -0400 Subject: [PATCH 1/9] Move queue interface url and auth into configuration, rather than hardcoding it --- cms/envs/common.py | 9 +++++++++ common/lib/capa/capa/xqueue_interface.py | 9 ++------- lms/djangoapps/courseware/module_render.py | 14 ++++++++++---- lms/envs/aws.py | 2 ++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 6faecafec1..3226d99005 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -90,6 +90,15 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ################################# Jasmine ################################### JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' + +#################### CAPA External Code Evaluation ############################# +XQUEUE_INTERFACE = { + 'url': 'http://localhost:8888', + 'auth': {'username': 'local', + 'password': 'local'} +} + + ################################# Middleware ################################### # List of finder classes that know how to find static files in # various locations. diff --git a/common/lib/capa/capa/xqueue_interface.py b/common/lib/capa/capa/xqueue_interface.py index 70f086120e..399cce9b6d 100644 --- a/common/lib/capa/capa/xqueue_interface.py +++ b/common/lib/capa/capa/xqueue_interface.py @@ -7,13 +7,10 @@ import logging import requests import time -# TODO: Collection of parameters to be hooked into rest of edX system -XQUEUE_LMS_AUTH = { 'username': 'LMS', - 'password': 'PaloAltoCA' } -XQUEUE_URL = 'http://xqueue.edx.org' log = logging.getLogger('mitx.' + __name__) + def make_hashkey(seed=None): ''' Generate a string key by hashing @@ -63,7 +60,7 @@ class XqueueInterface: Interface to the external grading system ''' - def __init__(self, url=XQUEUE_URL, auth=XQUEUE_LMS_AUTH): + def __init__(self, url, auth): self.url = url self.auth = auth self.session = requests.session() @@ -117,5 +114,3 @@ class XqueueInterface: return (1, 'unexpected HTTP status code [%d]' % r.status_code) return parse_xreply(r.text) - -qinterface = XqueueInterface() diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 85eeb72c24..46889c878b 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -7,9 +7,9 @@ from django.http import Http404 from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt +from capa.xqueue_interface import XQueueInterface from django.contrib.auth.models import User from xmodule.modulestore.django import modulestore -from capa.xqueue_interface import qinterface from mitxmako.shortcuts import render_to_string from models import StudentModule, StudentModuleCache from static_replace import replace_urls @@ -23,6 +23,12 @@ from courseware.courses import (has_staff_access_to_course, log = logging.getLogger("mitx.courseware") +xqueue_interface = XQueueInterface( + settings.XQUEUE_INTERFACE['url'], + settings.XQUEUE_INTERFACE['auth'] +) + + def make_track_function(request): ''' Make a tracking function that logs what happened. @@ -172,9 +178,9 @@ def get_module(user, request, location, student_module_cache, position=None): # TODO: Queuename should be derived from 'course_settings.json' of each course xqueue_default_queuename = descriptor.location.org + '-' + descriptor.location.course - xqueue = { 'interface': qinterface, - 'callback_url': xqueue_callback_url, - 'default_queuename': xqueue_default_queuename.replace(' ','_') } + xqueue = {'interface': xqueue_interface, + 'callback_url': xqueue_callback_url, + 'default_queuename': xqueue_default_queuename.replace(' ', '_')} def _get_module(location): return get_module(user, request, location, diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 460ec18d27..c704fd164e 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -54,3 +54,5 @@ AWS_ACCESS_KEY_ID = AUTH_TOKENS["AWS_ACCESS_KEY_ID"] AWS_SECRET_ACCESS_KEY = AUTH_TOKENS["AWS_SECRET_ACCESS_KEY"] DATABASES = AUTH_TOKENS['DATABASES'] + +XQUEUE_INTERFACE = AUTH_TOKENS['XQUEUE_INTERFACE'] From 09fc932a207d3560949654387dc3ede77ccea04c Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 09:14:31 -0400 Subject: [PATCH 2/9] Add default XQUEUE_INTERFACE to the dev environment --- lms/envs/dev.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lms/envs/dev.py b/lms/envs/dev.py index 85850e81e3..38d38034b5 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -53,6 +53,14 @@ CACHES = { } } +XQUEUE_INTERFACE = { + "url": "http://xqueue.sandbox.edx.org", + "auth": { + "username": "lms", + "password": "***REMOVED***" + } +} + # Make the keyedcache startup warnings go away CACHE_TIMEOUT = 0 From f09aca917fdb51e6a02303b4f9eb464bb656c939 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 09:17:37 -0400 Subject: [PATCH 3/9] Fix name of XQueueInterface --- common/lib/capa/capa/xqueue_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/capa/capa/xqueue_interface.py b/common/lib/capa/capa/xqueue_interface.py index 399cce9b6d..9573599245 100644 --- a/common/lib/capa/capa/xqueue_interface.py +++ b/common/lib/capa/capa/xqueue_interface.py @@ -55,7 +55,7 @@ def parse_xreply(xreply): return (return_code, content) -class XqueueInterface: +class XQueueInterface: ''' Interface to the external grading system ''' From 43745dacca737453a2f4691e7d456b538848a7b4 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 09:31:42 -0400 Subject: [PATCH 4/9] Add queue interface for test purposes --- lms/envs/test.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lms/envs/test.py b/lms/envs/test.py index cd0e984940..7af7acfc37 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -50,6 +50,15 @@ COMMON_TEST_DATA_ROOT = COMMON_ROOT / "test" / "data" GITHUB_REPO_ROOT = ENV_ROOT / "data" +XQUEUE_INTERFACE = { + "url": "http://xqueue.sandbox.edx.org", + "auth": { + "username": "lms", + "password": "***REMOVED***" + } +} + + # TODO (cpennington): We need to figure out how envs/test.py can inject things # into common.py so that we don't have to repeat this sort of thing STATICFILES_DIRS = [ From c4bed2c1281b0f9dc3bdcc0a60cda18b29e806be Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 11:32:39 -0400 Subject: [PATCH 5/9] Add basic authentication support for requests made to the xqueue server --- cms/envs/common.py | 5 +++-- common/lib/capa/capa/xqueue_interface.py | 6 +++--- lms/djangoapps/courseware/module_render.py | 3 ++- lms/envs/dev.py | 5 +++-- lms/envs/test.py | 5 +++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 3226d99005..1767202141 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -94,8 +94,9 @@ JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' #################### CAPA External Code Evaluation ############################# XQUEUE_INTERFACE = { 'url': 'http://localhost:8888', - 'auth': {'username': 'local', - 'password': 'local'} + 'django_auth': {'username': 'local', + 'password': 'local'}, + 'basic_auth': None, } diff --git a/common/lib/capa/capa/xqueue_interface.py b/common/lib/capa/capa/xqueue_interface.py index 9573599245..d9822d24f3 100644 --- a/common/lib/capa/capa/xqueue_interface.py +++ b/common/lib/capa/capa/xqueue_interface.py @@ -60,10 +60,10 @@ class XQueueInterface: Interface to the external grading system ''' - def __init__(self, url, auth): + def __init__(self, url, django_auth, basic_auth=None): self.url = url - self.auth = auth - self.session = requests.session() + self.auth = django_auth + self.session = requests.session(auth=basic_auth) def send_to_queue(self, header, body, file_to_upload=None): ''' diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 46889c878b..08c11b50b7 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -25,7 +25,8 @@ log = logging.getLogger("mitx.courseware") xqueue_interface = XQueueInterface( settings.XQUEUE_INTERFACE['url'], - settings.XQUEUE_INTERFACE['auth'] + settings.XQUEUE_INTERFACE['django_auth'], + settings.XQUEUE_INTERFACE['basic_auth'], ) diff --git a/lms/envs/dev.py b/lms/envs/dev.py index 38d38034b5..882a82b8f0 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -55,10 +55,11 @@ CACHES = { XQUEUE_INTERFACE = { "url": "http://xqueue.sandbox.edx.org", - "auth": { + "django_auth": { "username": "lms", "password": "***REMOVED***" - } + }, + "basic_auth": ('anant', 'agarwal'), } # Make the keyedcache startup warnings go away diff --git a/lms/envs/test.py b/lms/envs/test.py index 7af7acfc37..187cb5c68e 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -52,10 +52,11 @@ GITHUB_REPO_ROOT = ENV_ROOT / "data" XQUEUE_INTERFACE = { "url": "http://xqueue.sandbox.edx.org", - "auth": { + "django_auth": { "username": "lms", "password": "***REMOVED***" - } + }, + "basic_auth": ('anant', 'agarwal'), } From 8ce12b10b2befbe1bbecb3fbf7bf7e0720b9b333 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 12:32:52 -0400 Subject: [PATCH 6/9] Pass HttpBasicAuth object to requests, rather than a list, which it didn't understand --- common/lib/capa/capa/xqueue_interface.py | 4 ++-- lms/djangoapps/courseware/module_render.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/common/lib/capa/capa/xqueue_interface.py b/common/lib/capa/capa/xqueue_interface.py index d9822d24f3..75db0870c0 100644 --- a/common/lib/capa/capa/xqueue_interface.py +++ b/common/lib/capa/capa/xqueue_interface.py @@ -60,10 +60,10 @@ class XQueueInterface: Interface to the external grading system ''' - def __init__(self, url, django_auth, basic_auth=None): + def __init__(self, url, django_auth, requests_auth=None): self.url = url self.auth = django_auth - self.session = requests.session(auth=basic_auth) + self.session = requests.session(auth=requests_auth) def send_to_queue(self, header, body, file_to_upload=None): ''' diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 08c11b50b7..b269023fab 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -19,14 +19,20 @@ from xmodule_modifiers import replace_static_urls, add_histogram, wrap_xmodule from courseware.courses import (has_staff_access_to_course, has_staff_access_to_location) +from requests import HttpBasicAuth log = logging.getLogger("mitx.courseware") +if settings.XQUEUE_INTERFACE['basic_auth'] is not None: + requests_auth = HttpBasicAuth(*settings.XQUEUE_INTERFACE['basic_auth']) +else: + requests_auth = None + xqueue_interface = XQueueInterface( settings.XQUEUE_INTERFACE['url'], settings.XQUEUE_INTERFACE['django_auth'], - settings.XQUEUE_INTERFACE['basic_auth'], + requests_auth, ) From 6e88777126b943ba1b39c9f7c8aa7d52da842293 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 12:34:25 -0400 Subject: [PATCH 7/9] Import HttpBasicAuth from the right place --- lms/djangoapps/courseware/module_render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index b269023fab..940ef9246e 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -19,7 +19,7 @@ from xmodule_modifiers import replace_static_urls, add_histogram, wrap_xmodule from courseware.courses import (has_staff_access_to_course, has_staff_access_to_location) -from requests import HttpBasicAuth +from requests.auth import HttpBasicAuth log = logging.getLogger("mitx.courseware") From 814f55aad06c6f54641c37a8e6346e334d9313c8 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 12:45:34 -0400 Subject: [PATCH 8/9] Fix the name of HTTPBasicAuth --- lms/djangoapps/courseware/module_render.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 940ef9246e..5184cd9866 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -19,13 +19,13 @@ from xmodule_modifiers import replace_static_urls, add_histogram, wrap_xmodule from courseware.courses import (has_staff_access_to_course, has_staff_access_to_location) -from requests.auth import HttpBasicAuth +from requests.auth import HTTPBasicAuth log = logging.getLogger("mitx.courseware") if settings.XQUEUE_INTERFACE['basic_auth'] is not None: - requests_auth = HttpBasicAuth(*settings.XQUEUE_INTERFACE['basic_auth']) + requests_auth = HTTPBasicAuth(*settings.XQUEUE_INTERFACE['basic_auth']) else: requests_auth = None From 9c0e41691c51c0711a2fc903cac1d97db7326df9 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 14 Aug 2012 15:57:07 -0400 Subject: [PATCH 9/9] Make XQueueInterface a new-style class --- common/lib/capa/capa/xqueue_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/capa/capa/xqueue_interface.py b/common/lib/capa/capa/xqueue_interface.py index 75db0870c0..2847968a89 100644 --- a/common/lib/capa/capa/xqueue_interface.py +++ b/common/lib/capa/capa/xqueue_interface.py @@ -55,7 +55,7 @@ def parse_xreply(xreply): return (return_code, content) -class XQueueInterface: +class XQueueInterface(object): ''' Interface to the external grading system '''