From c883413f4e7ef4642f9d18a0d383612f6abd9391 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 15 Nov 2017 16:50:24 +0530 Subject: - Add python-decouple package to requirements - Use sane defaults and python-decouple in yaksh.settings module - Replace hard coded localhost domain name referring to code server with dynamic settings variable --- yaksh/models.py | 10 +++++----- yaksh/settings.py | 11 ++++++++--- yaksh/views.py | 7 ++++--- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 1d24bda..bc0b4f1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -29,10 +29,10 @@ import tempfile from textwrap import dedent from ast import literal_eval from .file_utils import extract_files, delete_files -from yaksh.code_server import(submit, - get_result as get_result_from_code_server - ) -from yaksh.settings import SERVER_POOL_PORT +from yaksh.code_server import ( + submit, get_result as get_result_from_code_server +) +from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from django.conf import settings from django.forms.models import model_to_dict @@ -1705,7 +1705,7 @@ class AnswerPaper(models.Model): elif question.type == 'code' or question.type == "upload": user_dir = self.user.profile.get_user_dir() - url = 'http://localhost:%s' % server_port + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) submit(url, uid, json_data, user_dir) result = {'uid': uid, 'status': 'running'} return result diff --git a/yaksh/settings.py b/yaksh/settings.py index d500d93..e414e75 100644 --- a/yaksh/settings.py +++ b/yaksh/settings.py @@ -2,16 +2,21 @@ settings for yaksh app. """ +from decouple import config + # The number of code server processes to run.. -N_CODE_SERVERS = 5 +N_CODE_SERVERS = config('N_CODE_SERVERS', default=5, cast=int) # The server pool port. This is the server which returns available server # ports so as to minimize load. This is some random number where no other # service is running. It should be > 1024 and less < 65535 though. -SERVER_POOL_PORT = 53579 +SERVER_POOL_PORT = config('EMAIL_PORT', default=55555, cast=int) + +SERVER_HOST_NAME = config('SERVER_HOST_NAME', default='http://localhost') +#'localhost' # Timeout for the code to run in seconds. This is an integer! -SERVER_TIMEOUT = 4 +SERVER_TIMEOUT = config('SERVER_TIMEOUT', default=4, cast=int) # The root of the URL, for example you might be in the situation where you # are not hosted as host.org/exam/ but as host.org/foo/exam/ for whatever diff --git a/yaksh/views.py b/yaksh/views.py index a4d9e78..a001ffd 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -35,7 +35,7 @@ except ImportError: from io import BytesIO as string_io import re # Local imports. -from yaksh.code_server import get_result as get_result_from_code_server, SERVER_POOL_PORT +from yaksh.code_server import get_result as get_result_from_code_server, from yaksh.models import ( Answer, AnswerPaper, AssignmentUpload, Course, FileUpload, FloatTestCase, HookTestCase, IntegerTestCase, McqTestCase, Profile, @@ -51,6 +51,7 @@ from yaksh.forms import ( UploadFileForm, get_object_form, FileForm, QuestionPaperForm, LessonForm, LessonFileForm, LearningModuleForm, ExerciseForm ) +from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT from .file_utils import extract_files, is_csv from .send_emails import send_user_mail, generate_activation_key, send_bulk_mail @@ -782,7 +783,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, ) if current_question.type in ['code', 'upload']: if paper.time_left() <= 0 and not paper.question_paper.quiz.is_exercise: - url = 'http://localhost:%s' % SERVER_POOL_PORT + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) result_details = get_result_from_code_server(url, uid, block=True) result = json.loads(result_details.get('result')) next_question, error_message, paper = _update_paper(request, uid, @@ -807,7 +808,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, @csrf_exempt def get_result(request, uid, course_id, module_id): result = {} - url = 'http://localhost:%s' % SERVER_POOL_PORT + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) result_state = get_result_from_code_server(url, uid) result['status'] = result_state.get('status') if result['status'] == 'done': -- cgit From 6f2e29a067cbeaf88b8ea478bb7c24fe8772180a Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 20 Nov 2017 16:07:43 +0530 Subject: Multiple Changes: - Add python-decouple package to requirements - use sane defaults and python-decouple in yaksh.settings and online_test.settings module - Replace hardcoded localhost domain name referring to code server with dynamic - Move Dockerfile to dedicated directory - Add dynamic run-as-admin commands to the base command depending on OS - Replace linux specific commands like cp with Python functions --- yaksh/settings.py | 2 +- yaksh/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/settings.py b/yaksh/settings.py index e414e75..d895d19 100644 --- a/yaksh/settings.py +++ b/yaksh/settings.py @@ -10,7 +10,7 @@ N_CODE_SERVERS = config('N_CODE_SERVERS', default=5, cast=int) # The server pool port. This is the server which returns available server # ports so as to minimize load. This is some random number where no other # service is running. It should be > 1024 and less < 65535 though. -SERVER_POOL_PORT = config('EMAIL_PORT', default=55555, cast=int) +SERVER_POOL_PORT = config('SERVER_POOL_PORT', default=55555, cast=int) SERVER_HOST_NAME = config('SERVER_HOST_NAME', default='http://localhost') #'localhost' diff --git a/yaksh/views.py b/yaksh/views.py index a001ffd..8fe4523 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -35,7 +35,7 @@ except ImportError: from io import BytesIO as string_io import re # Local imports. -from yaksh.code_server import get_result as get_result_from_code_server, +from yaksh.code_server import get_result as get_result_from_code_server from yaksh.models import ( Answer, AnswerPaper, AssignmentUpload, Course, FileUpload, FloatTestCase, HookTestCase, IntegerTestCase, McqTestCase, Profile, -- cgit From 0713c60a5ad4b71d4a2050d13cf30afaf37d935b Mon Sep 17 00:00:00 2001 From: rohmhatre Date: Sun, 26 Nov 2017 00:25:02 +0530 Subject: Added docker compose configuration --- yaksh/code_server.py | 0 yaksh/docs/sample.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 yaksh/code_server.py mode change 100755 => 100644 yaksh/docs/sample.sh (limited to 'yaksh') diff --git a/yaksh/code_server.py b/yaksh/code_server.py old mode 100755 new mode 100644 diff --git a/yaksh/docs/sample.sh b/yaksh/docs/sample.sh old mode 100755 new mode 100644 -- cgit From e18e49376ce867720151adfc77ae5846917bbc87 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 12 Dec 2017 15:28:00 +0530 Subject: Fix bug to allow tests to run successfully --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index bc0b4f1..e733fc0 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1705,7 +1705,7 @@ class AnswerPaper(models.Model): elif question.type == 'code' or question.type == "upload": user_dir = self.user.profile.get_user_dir() - url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) + url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port) submit(url, uid, json_data, user_dir) result = {'uid': uid, 'status': 'running'} return result -- cgit From bbf844c6ebf9b29c436930b5d5129ebf77a3aad1 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 4 Jan 2018 16:20:00 +0530 Subject: Replace hardcoded codeserver URL in regrade method within models --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index e733fc0..2f616cf 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1740,7 +1740,7 @@ class AnswerPaper(models.Model): server_port=server_port ) if question.type == "code": - url = 'http://localhost:%s' % server_port + url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port) check_result = get_result_from_code_server(url, result['uid'], block=True ) -- cgit