diff --git a/Client/Client.py b/Client/Client.py index a8693c9..e6443ba 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -31,8 +31,7 @@ import zipfile import shutil import multiprocessing -from subprocess import PIPE, Popen, call - +from subprocess import PIPE, Popen, call, STDOUT from itertools import combinations_with_replacement # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -49,7 +48,7 @@ from itertools import combinations_with_replacement TIMEOUT_HTTP = 30 # Timeout in seconds for HTTP requests TIMEOUT_ERROR = 10 # Timeout in seconds when any errors are thrown TIMEOUT_WORKLOAD = 30 # Timeout in seconds between workload requests -CLIENT_VERSION = '2' # Client version to send to the Server +CLIENT_VERSION = '3' # Client version to send to the Server SYZYGY_WDL_PATH = None # Pathway to WDL Syzygy Tables BASE_GAMES_PER_CORE = 32 # Typical games played per-thread @@ -305,6 +304,23 @@ def kill_cutechess(cutechess): except Exception: pass +def find_pgn_error(reason, command): + + pgn_file = command.split('-pgnout ')[1].split()[0] + with open(pgn_file, 'r') as fin: + data = fin.readlines() + + reason = reason.split('{')[1] + for ii in range(len(data) - 1, -1, -1): + if reason in data[ii]: + break + + pgn = "" + while "[Event " not in data[ii]: + pgn = data[ii] + pgn + ii = ii - 1 + return data[ii] + pgn + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # All functions used to make requests to the OpenBench server. Workload # @@ -444,14 +460,15 @@ def server_request_workload(arguments): target = url_join(arguments.server, 'clientGetWorkload') return requests.post(target, data=payload, timeout=TIMEOUT_HTTP) -def server_report_build_fail(arguments, workload, branch): +def server_report_build_fail(arguments, workload, branch, compiler_output): payload = { 'username' : arguments.username, 'password' : arguments.password, 'testid' : workload['test']['id'], 'machineid' : workload['machine']['id'], - 'error' : '%s build failed' % (workload['test'][branch]['name']) + 'error' : '%s build failed' % (workload['test'][branch]['name']), + 'logs' : compiler_output, } target = url_join(arguments.server, 'clientSubmitError') @@ -483,7 +500,7 @@ def server_report_nps(arguments, workload, dev_nps, base_nps): target = url_join(arguments.server, 'clientSubmitNPS') requests.post(target, data=data, timeout=TIMEOUT_ERROR) -def server_report_engine_error(arguments, workload, cutechess_str): +def server_report_engine_error(arguments, workload, cutechess_str, pgn): pairing = cutechess_str.split('(')[1].split(')')[0] white, black = pairing.split(' vs ') @@ -493,11 +510,12 @@ def server_report_engine_error(arguments, workload, cutechess_str): error = error.replace('Black', '-'.join(black.split('-')[1:]).rstrip()) payload = { - 'username' : arguments.username, - 'password' : arguments.password, + 'username' : arguments.username, + 'password' : arguments.password, 'testid' : workload['test']['id'], 'machineid' : workload['machine']['id'], - 'error' : error, + 'error' : error, + 'logs' : pgn, } target = url_join(arguments.server, 'clientSubmitError') @@ -685,9 +703,11 @@ def download_engine(arguments, workload, branch, network): # Build the engine and drop it into src_path print('\nBuilding [%s]' % (final_path)) - command = make_command(arguments, engine, src_path, network) - Popen(command, cwd=src_path).wait() output_name = os.path.join(src_path, engine) + command = make_command(arguments, engine, src_path, network) + process = Popen(command, cwd=src_path, stdout=PIPE, stderr=STDOUT) + compiler_output = process.communicate()[0].decode('utf-8') + print (compiler_output) # Move the file to the final location ( Linux ) if os.path.isfile(output_name): @@ -702,7 +722,7 @@ def download_engine(arguments, workload, branch, network): return final_name + '.exe' # Notify the server if the build failed - server_report_build_fail(arguments, workload, branch) + server_report_build_fail(arguments, workload, branch, compiler_output) return None def run_benchmarks(arguments, workload, branch, engine): @@ -807,7 +827,8 @@ def run_and_parse_cutechess(arguments, workload, concurrency, update_interval, c # Forcefully report any engine failures to the server for error in errors: if error in score_reason: - server_report_engine_error(arguments, workload, line) + pgn = find_pgn_error(score_reason, command) + server_report_engine_error(arguments, workload, line, pgn) # All remaining processing is for score updates only if not line.startswith('Score of'): diff --git a/OpenBench/config.py b/OpenBench/config.py index bea9663..e8ea294 100644 --- a/OpenBench/config.py +++ b/OpenBench/config.py @@ -23,7 +23,7 @@ USE_CROSS_APPROVAL = False OPENBENCH_CONFIG = { # Server Client version control - 'client_version' : '2', + 'client_version' : '3', # Generic Error Messages useful to those setting up their own instance 'error' : { diff --git a/OpenBench/models.py b/OpenBench/models.py index 1d42584..ef32e14 100644 --- a/OpenBench/models.py +++ b/OpenBench/models.py @@ -135,13 +135,17 @@ class Test(Model): class LogEvent(Model): - data = CharField(max_length=256) - author = CharField(max_length=64) - test = ForeignKey('Test', PROTECT, related_name='test1') - creation = DateTimeField(auto_now_add=True) + author = CharField(max_length=128) # Username for the OpenBench Profile + summary = CharField(max_length=128) # Quick summary of the Event or Error + log_file = CharField(max_length=128) # .log file stored in /Media/ + + machine_id = IntegerField(default=0) # Only set for Client based Log Events + test_id = IntegerField(default=0) # Should always be set + + created = DateTimeField(auto_now_add=True) def __str__(self): - return "{0} {1} {2}".format(self.author, str(self.test), self.data) + return "{0} {1} {2}".format(self.author, str(self.test_id), self.summary) class Network(Model): diff --git a/OpenBench/templatetags/mytags.py b/OpenBench/templatetags/mytags.py index b86d579..cf059c5 100644 --- a/OpenBench/templatetags/mytags.py +++ b/OpenBench/templatetags/mytags.py @@ -153,6 +153,12 @@ def resolveNetworkURL(sha256): return '/networks/download/{0}'.format(sha256) return sha256 # Legacy Networks +def testIdToPrettyName(test_id): + return prettyName(OpenBench.models.Test.objects.get(id=test_id).dev.name) + +def testIdToTimeControl(test_id): + return OpenBench.models.Test.objects.get(id=test_id).timecontrol + register = django.template.Library() register.filter('oneDigitPrecision', oneDigitPrecision) register.filter('twoDigitPrecision', twoDigitPrecision) @@ -166,3 +172,5 @@ register.filter('prettyName', prettyName) register.filter('prettyDevName', prettyDevName) register.filter('testIsFRC', testIsFRC) register.filter('resolveNetworkURL', resolveNetworkURL) +register.filter('testIdToPrettyName', testIdToPrettyName) +register.filter('testIdToTimeControl', testIdToTimeControl) diff --git a/OpenBench/urls.py b/OpenBench/urls.py index 53d06bf..50dc759 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -36,6 +36,7 @@ urlpatterns = [ django.urls.path(r'search/', OpenBench.views.search), django.urls.path(r'user//', OpenBench.views.user), django.urls.path(r'user///', OpenBench.views.user), + django.urls.path(r'event//', OpenBench.views.event), # Links for viewing general information tables django.urls.path(r'users/', OpenBench.views.users), diff --git a/OpenBench/views.py b/OpenBench/views.py index 8d37593..c558b24 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -37,6 +37,7 @@ from django.db.models import F from django.http import HttpResponse, FileResponse from django.views.decorators.csrf import csrf_exempt from django.core.files.storage import FileSystemStorage +from django.core.files.base import ContentFile from htmlmin.decorators import not_minified_response # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -329,6 +330,13 @@ def user(request, username, page=1): return render(request, 'index.html', data) +def event(request, id): + + try: + with open(os.path.join(MEDIA_ROOT, LogEvent.objects.get(id=id).log_file)) as fin: + return render(request, 'event.html', { 'content' : fin.read() }) + except: + return HttpResponseRedirect('/index/') # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # GENERAL DATA TABLE VIEWS # @@ -431,7 +439,7 @@ def test(request, id, action=None): test.save() action += " P={0} TP={1}".format(test.priority, test.throughput) - LogEvent.objects.create(data=action, author=user.username, test=test) + LogEvent.objects.create(author=user.username, summary=action, log_file='', test_id=test.id) return django.http.HttpResponseRedirect('/index/') def newTest(request): @@ -470,7 +478,7 @@ def newTest(request): username = request.user.username profile = Profile.objects.get(user=request.user) - LogEvent.objects.create(data="CREATE", author=username, test=test) + LogEvent.objects.create(author=username, summary='CREATE', log_file='', test_id=test.id) approved = Test.objects.filter(approved=True) A = approved.filter( dev__sha=test.dev.sha).exists() @@ -481,12 +489,12 @@ def newTest(request): if (A or B) and (C or D): test.approved = True; test.save() action = "AUTOAPP P={0} TP={1}".format(test.priority, test.throughput) - LogEvent.objects.create(data=action, author=username, test=test) + LogEvent.objects.create(author=username, summary=action, log_file='', test_id=test.id) elif not OpenBench.config.USE_CROSS_APPROVAL and profile.approver: test.approved = True; test.save() action = "APPROVE P={0} TP={1}".format(test.priority, test.throughput) - LogEvent.objects.create(data=action, author=username, test=test) + LogEvent.objects.create(author=username, summary=action, log_file='', test_id=test.id) return django.http.HttpResponseRedirect('/index/') @@ -693,14 +701,16 @@ def clientWrongBench(request): name = request.POST['engine'] # Format a nice Error message - message = 'Got {0} Expected {1} for {2} [{3}]' - message = message.format(wrong, correct, name, int(request.POST['machineid'])) + message = 'Got {0} Expected {1} for {2}' + message = message.format(wrong, correct, name) # Log the error into the Events table LogEvent.objects.create( - test = test, - data = message, - author = user.username) + author = user.username, + summary = message, + log_file = '', + machine_id = int(request.POST['machineid']), + test_id = int(request.POST['testid'])) return HttpResponse('None') @@ -731,7 +741,7 @@ def clientSubmitError(request): # # # POST : Report en Engine error to the server. This could be a crash, a # # timeloss, a disconnect, or an illegal move. Log the Error into # - # the Events table. # + # the Events table. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -745,10 +755,17 @@ def clientSubmitError(request): test.error = True; test.save() # Log the Error into the Events table - LogEvent.objects.create( - test = test, - author = user.username, - data = request.POST['error']) + event = LogEvent.objects.create( + author = user.username, + summary = request.POST['error'], + log_file = '', + machine_id = int(request.POST['machineid']), + test_id = int(request.POST['testid'])) + + # Save the Logs to /Media/ to be viewed later + logfile = ContentFile(request.POST['logs']) + FileSystemStorage().save('event%d.log' % (event.id), logfile) + event.log_file = 'event%d.log' % (event.id); event.save() return HttpResponse('None') diff --git a/Templates/OpenBench/event.html b/Templates/OpenBench/event.html new file mode 100644 index 0000000..79e6036 --- /dev/null +++ b/Templates/OpenBench/event.html @@ -0,0 +1,7 @@ + + + + +
{{content}}
+    
+
diff --git a/Templates/OpenBench/events.html b/Templates/OpenBench/events.html
index 309c8ed..6cf1825 100644
--- a/Templates/OpenBench/events.html
+++ b/Templates/OpenBench/events.html
@@ -10,17 +10,19 @@
             Date
             User
             Test
-            Time
-            Action
+            TC
+            Summary
+            Logs
         
 
         {% for event in events %}
             
-                {{event.creation|date:'U'}}
+                {{event.created|date:'U'}}
                 {{event.author|capfirst}}
-                {{event.test.dev.name|prettyName}}
-                {{event.test.timecontrol}}
-                {{event.data}}
+                {{event.test_id|testIdToPrettyName}}
+                {{event.test_id|testIdToTimeControl}}
+                {{event.summary}}
+                 {% if event.log_file %} View {% endif %} 
             
         {% endfor %}