Server may return 'Bad Machine'. Handle this in the new client

An issue appeared when an illegal machine id was passed, causing a raw text response from the server which fails to be converted into a dictionary later on. This is now handled by returning to the main loop, and resetting the machine id. This should never happen I had thought, but seems it can. One possible reason was failed FileIO, so now we only update the machine.txt when the ID has actually changed.

Resolves #43
This commit is contained in:
AndyGrant committed 2019-12-14 16:43:35 -05:00
1 parent 861914fd07
commit 4aac7910a0
1 file changed
+11 -3
+11 -3
View File
@@ -458,13 +458,21 @@ def completeWorkload(workRequestData, arguments):
print('[ERROR] Invalid Login Credentials')
sys.exit()
# Bad machines will be registered again
if data == 'Bad Machine':
workRequestData['machineid'] = 'None'
print('[NOTE] Invalid Machine ID')
return
# Convert response into a dictionary
data = ast.literal_eval(data)
# Update machine ID in case we got registered
workRequestData['machineid'] = data['machine']['id']
with open('machine.txt', 'w') as fout:
fout.write(str(workRequestData['machineid']))
if workRequestData['machineid'] != data['machine']['id']:
workRequestData['machineid'] = data['machine']['id']
with open('machine.txt', 'w') as fout:
fout.write(str(workRequestData['machineid']))
# Handle the actual workload's completion
processWorkload(arguments, data)