Update Machine to be tied to a User, not a string

This commit is contained in:
Andrew Grant committed 2020-05-02 20:00:22 -04:00
1 parent 2917b90784
commit b295842066
5 files changed
+14 -15

No files matched your search

+2 -2
View File
@@ -50,7 +50,7 @@ class Profile(Model):
class Machine(Model): class Machine(Model):
owner = CharField(max_length=64) user = ForeignKey(User, PROTECT, related_name='owner')
osname = CharField(max_length=128) osname = CharField(max_length=128)
threads = IntegerField(default=0) threads = IntegerField(default=0)
mnps = FloatField(default=0.00) mnps = FloatField(default=0.00)
@@ -58,7 +58,7 @@ class Machine(Model):
workload = ForeignKey('Test', PROTECT, related_name='workload', default=1) workload = ForeignKey('Test', PROTECT, related_name='workload', default=1)
def __str__(self): def __str__(self):
return '{0}-{1} ({2})'.format(self.owner, self.osname, self.id) return '{0}-{1} ({2})'.format(self.user.username, self.osname, self.id)
class Result(Model): class Result(Model):
+5 -6
View File
@@ -75,7 +75,7 @@ def getMachineStatus(username=None):
machines = getRecentMachines() machines = getRecentMachines()
if username != None: if username != None:
machines = machines.filter(owner=username) machines = machines.filter(user__username=username)
return "{0} Machines ".format(len(machines)) + \ return "{0} Machines ".format(len(machines)) + \
"{0} Threads ".format(sum([f.threads for f in machines])) + \ "{0} Threads ".format(sum([f.threads for f in machines])) + \
@@ -251,7 +251,7 @@ def createNewTest(request):
return test, None return test, None
def getMachine(machineid, owner, osname, threads): def getMachine(machineid, user, osname, threads):
try: # Create a new or fetch an existing Machine try: # Create a new or fetch an existing Machine
if machineid == 'None': machine = Machine() if machineid == 'None': machine = Machine()
@@ -260,11 +260,11 @@ def getMachine(machineid, owner, osname, threads):
# Verify that the fetched Machine matches # Verify that the fetched Machine matches
if machineid != 'None': if machineid != 'None':
if machine.owner != owner: return 'Bad Machine' if machine.user != user: return 'Bad Machine'
if machine.osname != osname: return 'Bad Machine' if machine.osname != osname: return 'Bad Machine'
# Update the Machine's running status # Update the Machine's running status
machine.owner = owner ; machine.osname = osname machine.user = user ; machine.osname = osname
machine.threads = int(threads) ; machine.mnps = 0.00 machine.threads = int(threads) ; machine.mnps = 0.00
return machine return machine
@@ -282,12 +282,11 @@ def getWorkload(user, request):
# Extract worker information # Extract worker information
machineid = request.POST['machineid'] machineid = request.POST['machineid']
owner = request.POST['username' ]
osname = request.POST['osname' ] osname = request.POST['osname' ]
threads = request.POST['threads' ] threads = request.POST['threads' ]
# If we don't get a Machine back, there was an error # If we don't get a Machine back, there was an error
machine = getMachine(machineid, owner, osname, threads) machine = getMachine(machineid, user, osname, threads)
if type(machine) == str: return machine if type(machine) == str: return machine
machine.save() machine.save()
+4 -4
View File
@@ -491,7 +491,7 @@ def clientWrongBench(request):
# Verify the Machine belongs to the User # Verify the Machine belongs to the User
machine = Machine.objects.get(id=int(request.POST['machineid'])) machine = Machine.objects.get(id=int(request.POST['machineid']))
if machine.owner != user.username: return HttpResponse('Bad Machine') if machine.user != user: return HttpResponse('Bad Machine')
# Find and stop the test with the bad bench # Find and stop the test with the bad bench
test = Test.objects.get(id=int(request.POST['testid'])) test = Test.objects.get(id=int(request.POST['testid']))
@@ -533,7 +533,7 @@ def clientSubmitNPS(request):
# Verify the Machine belongs to the User # Verify the Machine belongs to the User
machine = Machine.objects.get(id=int(request.POST['machineid'])) machine = Machine.objects.get(id=int(request.POST['machineid']))
if machine.owner != user.username: return HttpResponse('Bad Machine') if machine.user != user: return HttpResponse('Bad Machine')
# Update the NPS and return 'None' to signal no errors # Update the NPS and return 'None' to signal no errors
machine.mnps = float(request.POST['nps']) / 1e6; machine.save() machine.mnps = float(request.POST['nps']) / 1e6; machine.save()
@@ -559,7 +559,7 @@ def clientSubmitError(request):
# Verify the Machine belongs to the User # Verify the Machine belongs to the User
machine = Machine.objects.get(id=int(request.POST['machineid'])) machine = Machine.objects.get(id=int(request.POST['machineid']))
if machine.owner != user.username: return HttpResponse('Bad Machine') if machine.user != user: return HttpResponse('Bad Machine')
# Log the Error into the Events table # Log the Error into the Events table
LogEvent.objects.create( LogEvent.objects.create(
@@ -581,7 +581,7 @@ def clientSubmitResults(request):
# Verify the Machine belongs to the User # Verify the Machine belongs to the User
machine = Machine.objects.get(id=int(request.POST['machineid'])) machine = Machine.objects.get(id=int(request.POST['machineid']))
if machine.owner != user.username: return HttpResponse('Bad Machine') if machine.user != user: return HttpResponse('Bad Machine')
# updateTest() will return 'None' or 'Stop' # updateTest() will return 'None' or 'Stop'
return HttpResponse(OpenBench.utils.updateTest(request, user)) return HttpResponse(OpenBench.utils.updateTest(request, user))
+2 -2
View File
@@ -19,8 +19,8 @@
{% for machine in machines %} {% for machine in machines %}
<tr> <tr>
<td class="numeric">{{machine.id}}</td> <td class="numeric">{{machine.id}}</td>
<td>{{machine.owner}}</td> <td>{{machine.user.username}}</td>
<td>{{machine.osname}}</td> <td>{{machine.osname|truncatewords:1|slice:":-4"}}</td>
<td>{{machine.updated|date:'Y-m-d H:i'}}</td> <td>{{machine.updated|date:'Y-m-d H:i'}}</td>
<td> <a href="/test/{{machine.workload.id}}">{{machine.workload.dev.name|prettyName}}</a></td> <td> <a href="/test/{{machine.workload.id}}">{{machine.workload.dev.name|prettyName}}</a></td>
<td class="numeric">{{machine.threads}}</td> <td class="numeric">{{machine.threads}}</td>
+1 -1
View File
@@ -117,7 +117,7 @@
{% for result in results %} {% for result in results %}
<tr> <tr>
<td>{{result.machine.id}}</td> <td>{{result.machine.id}}</td>
<td>{{result.machine.owner|slice:"6"}}</td> <td>{{result.machine.user.username|slice:"6"}}</td>
<td>{{result.machine.osname|truncatewords:1|slice:":-4"}}</td> <td>{{result.machine.osname|truncatewords:1|slice:":-4"}}</td>
<td>{{result.updated|date:'Y-m-d H:i'}}</td> <td>{{result.updated|date:'Y-m-d H:i'}}</td>
<td class="numeric">{{result.games}}</td> <td class="numeric">{{result.games}}</td>