Server sends back client data .. machine id saved
This commit is contained in:
1 parent
841d634e08
commit
009424b616
6 files changed
+45
-40
No files matched your search
+5
-5
@@ -31,7 +31,6 @@ OS_NAME = platform.system() + " " + platform.release()
|
|||||||
try:
|
try:
|
||||||
with open("machine.txt") as fin:
|
with open("machine.txt") as fin:
|
||||||
MACHINE_ID = int(fin.readlines()[0])
|
MACHINE_ID = int(fin.readlines()[0])
|
||||||
print("Machine ID = {0}".format(MACHINE_ID))
|
|
||||||
except:
|
except:
|
||||||
MACHINE_ID = None
|
MACHINE_ID = None
|
||||||
print("<Warning> Machine unregistered, will register with Server")
|
print("<Warning> Machine unregistered, will register with Server")
|
||||||
@@ -375,6 +374,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Server has nothing to run, ask again later
|
# Server has nothing to run, ask again later
|
||||||
if response == "None":
|
if response == "None":
|
||||||
|
print("<Warning> Server has no workloads for us")
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -392,12 +392,12 @@ if __name__ == "__main__":
|
|||||||
response = ast.literal_eval(response)
|
response = ast.literal_eval(response)
|
||||||
|
|
||||||
# Update and save our assigned machine ID
|
# Update and save our assigned machine ID
|
||||||
data["machineid"] = response["machineid"]
|
data["machineid"] = response["machine"]["id"]
|
||||||
with open("machine.txt") as fout:
|
with open("machine.txt", "w") as fout:
|
||||||
fout.write(data["machineid"])
|
fout.write(str(data["machineid"]))
|
||||||
|
|
||||||
# Update machine id in case ours was bad
|
# Update machine id in case ours was bad
|
||||||
data["machineid"] = response["machineid"]
|
data["machineid"] = response["machine"]["id"]
|
||||||
|
|
||||||
print (response)
|
print (response)
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -1,6 +1,8 @@
|
|||||||
import math, requests, random
|
import math, requests, random
|
||||||
|
|
||||||
from OpenBench.models import Engine, Profile, Machine, Test
|
from OpenBench.config import *
|
||||||
|
from OpenBench.models import Engine, Profile, Machine, Result, Test
|
||||||
|
|
||||||
|
|
||||||
def getSourceLocation(branch, repo):
|
def getSourceLocation(branch, repo):
|
||||||
|
|
||||||
@@ -142,13 +144,15 @@ def getWorkload(machine):
|
|||||||
target -= options[0].throughput
|
target -= options[0].throughput
|
||||||
options = options[1:]
|
options = options[1:]
|
||||||
|
|
||||||
def getResults(machine, test):
|
def getResult(machine, test):
|
||||||
|
|
||||||
# Can find an existing result by test and machine
|
# Can find an existing result by test and machine
|
||||||
results = Result.objects.filter(test=test)
|
results = Result.objects.filter(test=test)
|
||||||
results = list(Result.objects.filter(machine=machine))
|
results = list(Result.objects.filter(machine=machine))
|
||||||
|
if results != []: return results[0]
|
||||||
|
|
||||||
|
# Must make a new one for the machine
|
||||||
|
return Result.objects.create(test=test, machine=machine)
|
||||||
|
|
||||||
def workloadDictionary(machine, result, test):
|
def workloadDictionary(machine, result, test):
|
||||||
|
|
||||||
|
|||||||
+31
-30
@@ -42,7 +42,7 @@ def register(request):
|
|||||||
request.POST['password1']))
|
request.POST['password1']))
|
||||||
|
|
||||||
# Log the User in now
|
# Log the User in now
|
||||||
loginUser(request, User.objects.get(name=request.POST['username']))
|
loginUser(request, User.objects.get(username=request.POST['username']))
|
||||||
|
|
||||||
# Log the registration
|
# Log the registration
|
||||||
LogEvent.objects.create(
|
LogEvent.objects.create(
|
||||||
@@ -64,8 +64,9 @@ def login(request):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Attempt to login the user, and return to index
|
# Attempt to login the user, and return to index
|
||||||
user = authenticate(username=request.POST['username'], password=request.POST['password'])
|
loginUser(request, authenticate(
|
||||||
loginUser(request, user)
|
username=request.POST['username'],
|
||||||
|
password=request.POST['password']))
|
||||||
return HttpResponseRedirect('/index/')
|
return HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
# Bad data, kick back to index with error
|
# Bad data, kick back to index with error
|
||||||
@@ -81,7 +82,7 @@ def logout(request):
|
|||||||
@login_required(login_url='/login/')
|
@login_required(login_url='/login/')
|
||||||
def viewProfile(request):
|
def viewProfile(request):
|
||||||
|
|
||||||
# Build context dictionary for template
|
# Build context dictionary for profile template
|
||||||
profile = Profile.objects.get(user=request.user)
|
profile = Profile.objects.get(user=request.user)
|
||||||
data = {'profile' : profile}
|
data = {'profile' : profile}
|
||||||
return render(request, 'viewProfile.html', data)
|
return render(request, 'viewProfile.html', data)
|
||||||
@@ -101,8 +102,9 @@ def editProfile(request):
|
|||||||
if password1 != '' and password1 == password2:
|
if password1 != '' and password1 == password2:
|
||||||
profile.user.set_password(password1)
|
profile.user.set_password(password1)
|
||||||
profile.user.save()
|
profile.user.save()
|
||||||
user = authenticate(username=request.user.username, password=password1)
|
loginUser(request, authenticate(
|
||||||
loginUser(request, user)
|
username=request.user.username,
|
||||||
|
password=password1))
|
||||||
|
|
||||||
# Send back to see the changes
|
# Send back to see the changes
|
||||||
return HttpResponseRedirect('/viewProfile/')
|
return HttpResponseRedirect('/viewProfile/')
|
||||||
@@ -111,6 +113,7 @@ def index(request, page=0, username=None, error=''):
|
|||||||
|
|
||||||
# Get tests pending approval
|
# Get tests pending approval
|
||||||
pending = Test.objects.filter(approved=False)
|
pending = Test.objects.filter(approved=False)
|
||||||
|
pending = pending.exclude(finished=False)
|
||||||
pending = pending.exclude(deleted=True)
|
pending = pending.exclude(deleted=True)
|
||||||
pending = pending.order_by('-creation')
|
pending = pending.order_by('-creation')
|
||||||
|
|
||||||
@@ -120,17 +123,18 @@ def index(request, page=0, username=None, error=''):
|
|||||||
active = active.exclude(deleted=True)
|
active = active.exclude(deleted=True)
|
||||||
active = active.order_by('-priority', '-currentllr')
|
active = active.order_by('-priority', '-currentllr')
|
||||||
|
|
||||||
# Get the complted tests (sliced later)
|
# Get the completed tests (sliced later)
|
||||||
completed = Test.objects.filter(finished=True)
|
completed = Test.objects.filter(finished=True)
|
||||||
completed = completed.exclude(deleted=True)
|
completed = completed.exclude(deleted=True)
|
||||||
completed = completed.order_by('-completion')
|
completed = completed.order_by('-updated')
|
||||||
|
|
||||||
if username != None: # View from just one user
|
# Index is wrapped just to view one user
|
||||||
|
if username != None:
|
||||||
pending = pending.filter(author=username)
|
pending = pending.filter(author=username)
|
||||||
active = active.filter(author=username)
|
active = active.filter(author=username)
|
||||||
completed = completed.filter(author=username)
|
completed = completed.filter(author=username)
|
||||||
|
|
||||||
# Compile context dictionary
|
# Build context dictionary for index template
|
||||||
data = {
|
data = {
|
||||||
'pending' : pending,
|
'pending' : pending,
|
||||||
'active' : active,
|
'active' : active,
|
||||||
@@ -157,7 +161,7 @@ def machines(request):
|
|||||||
|
|
||||||
def eventLog(request):
|
def eventLog(request):
|
||||||
|
|
||||||
# Build context dictionary for template
|
# Build context dictionary for event log template
|
||||||
data = {'events': LogEvent.objects.all().order_by('-id')[:50]}
|
data = {'events': LogEvent.objects.all().order_by('-id')[:50]}
|
||||||
return render(request, 'eventLog.html', data)
|
return render(request, 'eventLog.html', data)
|
||||||
|
|
||||||
@@ -171,8 +175,7 @@ def newTest(request):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Throw out non-approved / disabled users
|
# Throw out non-approved / disabled users
|
||||||
profile = Profile.objects.get(user=request.user)
|
if not Profile.objects.get(user=request.user).enabled:
|
||||||
if not profile.enabled:
|
|
||||||
raise Exception('Account not Enabled')
|
raise Exception('Account not Enabled')
|
||||||
|
|
||||||
# Create test and verify fields
|
# Create test and verify fields
|
||||||
@@ -192,7 +195,7 @@ def newTest(request):
|
|||||||
def viewTest(request, id):
|
def viewTest(request, id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Find Test and Results
|
# Build context dictionary for test template
|
||||||
test = Test.objects.get(id=id)
|
test = Test.objects.get(id=id)
|
||||||
results = Result.objects.all().filter(test=test)
|
results = Result.objects.all().filter(test=test)
|
||||||
data = {'test' : test, 'results' : results}
|
data = {'test' : test, 'results' : results}
|
||||||
@@ -206,7 +209,7 @@ def viewTest(request, id):
|
|||||||
def editTest(request, id):
|
def editTest(request, id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Only let approvers or the author edit a test
|
# Only let approvers or the test author edit a test
|
||||||
test = Test.objects.get(id=id)
|
test = Test.objects.get(id=id)
|
||||||
profile = Profile.objects.get(user=request.user)
|
profile = Profile.objects.get(user=request.user)
|
||||||
if not profile.approver and test.author != profile.user.username:
|
if not profile.approver and test.author != profile.user.username:
|
||||||
@@ -218,11 +221,10 @@ def editTest(request, id):
|
|||||||
test.throughput = max(0, int(request.POST['throughput']))
|
test.throughput = max(0, int(request.POST['throughput']))
|
||||||
test.save()
|
test.save()
|
||||||
|
|
||||||
# Log the test stopping
|
# Log changes to the test settings
|
||||||
event = LogEvent()
|
LogEvent.objects.create(
|
||||||
event.data = 'Edit test {0} ({1}) P={2} TP={3}'.format(str(test), test.id, test.priority, test.throughput)
|
data='Edit test {0} ({1}) P={2} TP={3}'.format(str(test), test.id, test.priority, test.throughput),
|
||||||
event.author = request.user.username
|
author=request.user.username)
|
||||||
event.save()
|
|
||||||
|
|
||||||
return HttpResponseRedirect('/index/')
|
return HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
@@ -245,10 +247,9 @@ def approveTest(request, id):
|
|||||||
test.save()
|
test.save()
|
||||||
|
|
||||||
# Log the test approval
|
# Log the test approval
|
||||||
event = LogEvent()
|
LogEvent.objects.create(
|
||||||
event.data = 'Approved test {0} ({1})'.format(str(test), test.id)
|
data='Approved test {0} ({1})'.format(str(test), test.id),
|
||||||
event.author = request.user.username
|
author=request.user.username)
|
||||||
event.save()
|
|
||||||
|
|
||||||
return HttpResponseRedirect('/index/')
|
return HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
@@ -274,10 +275,9 @@ def restartTest(request, id):
|
|||||||
test.save()
|
test.save()
|
||||||
|
|
||||||
# Log the test stopping
|
# Log the test stopping
|
||||||
event = LogEvent()
|
LogEvent.objects.create(
|
||||||
event.data = 'Restart test {0} ({1})'.format(str(test), test.id)
|
data='Restarted test {0} ({1})'.format(str(test), test.id),
|
||||||
event.author = request.user.username
|
author=request.user.username)
|
||||||
event.save()
|
|
||||||
|
|
||||||
return HttpResponseRedirect('/index/')
|
return HttpResponseRedirect('/index/')
|
||||||
|
|
||||||
@@ -339,6 +339,7 @@ def deleteTest(request, id):
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
return index(request, error=str(error))
|
return index(request, error=str(error))
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
def getFiles(request):
|
def getFiles(request):
|
||||||
|
|
||||||
# Core Files should be sitting in framework's repo
|
# Core Files should be sitting in framework's repo
|
||||||
@@ -367,11 +368,11 @@ def getWorkload(request):
|
|||||||
except: return HttpResponse('None')
|
except: return HttpResponse('None')
|
||||||
|
|
||||||
# Create or fetch the Results
|
# Create or fetch the Results
|
||||||
try: results = OpenBench.utils.getResults(machine, test)
|
try: result = OpenBench.utils.getResult(machine, test)
|
||||||
except: return HttpResponse('None')
|
except: return HttpResponse('None')
|
||||||
|
|
||||||
# Send ID's and test information as a string dictionary
|
# Send ID's and test information as a string dictionary
|
||||||
return HttpResponse(str(workloadDictionary(machine, result, test)))
|
return HttpResponse(str(OpenBench.utils.workloadDictionary(machine, result, test)))
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def submitResults(request):
|
def submitResults(request):
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for profile in profiles %}
|
{% for profile in profiles %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/viewUser/{{profile.user.username}}">{{profile.user.username}}</a></td>
|
<td style="text-align:left"><a href="/viewUser/{{profile.user.username}}">{{profile.user.username}}</a></td>
|
||||||
<td>{{profile.games}}</td>
|
<td>{{profile.games}}</td>
|
||||||
<td>{{profile.tests}}</td>
|
<td>{{profile.tests}}</td>
|
||||||
<td><a href="{{profile.repo}}">{{profile.repo}}</a></td>
|
<td><a href="{{profile.repo}}">{{profile.repo}}</a></td>
|
||||||
|
|||||||
@@ -121,7 +121,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{result.machine.owner}}</th>
|
<td>{{result.machine.owner}}</th>
|
||||||
<td>{{result.machine.osname}}</th>
|
<td>{{result.machine.osname}}</th>
|
||||||
<td>{{result.lastseen}}</td>
|
<td>{{result.updated}}</td>
|
||||||
<td>{{result.games}}</td>
|
<td>{{result.games}}</td>
|
||||||
<td>{{result.wins}}</td>
|
<td>{{result.wins}}</td>
|
||||||
<td>{{result.losses}}</td>
|
<td>{{result.losses}}</td>
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in new issue
Block a user