From 4aac7910a07d16e9709e84bbec9a4a6dcefaa1b3 Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Sat, 14 Dec 2019 16:43:35 -0500 Subject: [PATCH] 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 --- Client/Client.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Client/Client.py b/Client/Client.py index a30577b..ec1f32d 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -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)