Skip to content

Commit

Permalink
down with stack traces and more consistent handling of exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nabil committed Apr 3, 2019
1 parent ce8e013 commit f33a1a4
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 124 deletions.
2 changes: 1 addition & 1 deletion demo/node_monitor/tenant_node_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def initthread():
except Exception as e:
common.echo_json_response(self, 400, "Exception error: %s"%e)
logger.warning("POST returning 400 response. Exception error: %s"%e)
logger.warning(traceback.format_exc())
logger.exception(e)

def put(self):
"""This method handles the PUT requests to add instances to the Node Monitor.
Expand Down
13 changes: 5 additions & 8 deletions keylime/cloud_verifier_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def post(self):
except Exception as e:
common.echo_json_response(self, 400, "Exception error: %s"%e)
logger.warning("POST returning 400 response. Exception error: %s"%e)
logger.warning(traceback.format_exc())
logger.exception(e)

self.finish()

Expand Down Expand Up @@ -272,7 +272,7 @@ def put(self):
except Exception as e:
common.echo_json_response(self, 400, "Exception error: %s"%e)
logger.warning("PUT returning 400 response. Exception error: %s"%e)
logger.warning(traceback.format_exc())
logger.exception(e)


self.finish()
Expand Down Expand Up @@ -332,8 +332,7 @@ def on_get_quote_response(self, instance, url, response):
# self.get_q_log_file.flush()

except Exception as e:
logger.debug(traceback.print_exc())
logger.critical("Unexpected exception occurred in worker_get_quote. Error: %s"%e )
logger.exception(e)



Expand Down Expand Up @@ -364,8 +363,6 @@ def on_provide_v_response(self, instance, url_with_params, response):
def process_instance(self, instance, new_operational_state):
try:
if instance is None:
#import traceback
traceback.print_stack()
main_instance_operational_state = instance['operational_state']
stored_instance = self.db.get_instance(instance['instance_id'])

Expand Down Expand Up @@ -462,8 +459,8 @@ def process_instance(self, instance, new_operational_state):
raise Exception("nothing should ever fall out of this!")

except Exception as e:
logger.warning("Polling thread Exception error: %s"%e)
logger.warning("Polling thread trace: " + traceback.format_exc())
logger.error("Polling thread error: %s"%e)
logger.exception(e)

def start_tornado(tornado_server, port):
tornado_server.listen(port)
Expand Down
4 changes: 1 addition & 3 deletions keylime/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import common
import uuid
import tornado_requests
import traceback

logger = common.init_logging('openstack')

Expand All @@ -37,6 +36,5 @@ def get_openstack_uuid(uuid_service_ip='169.254.169.254',
logger.debug("Forcing using locally generated uuid.")
return str(uuid.uuid4())
except Exception:
logger.debug(traceback.format_exc())
logger.debug("Exception: Using locally generated uuid.")
logger.debug("Using locally generated uuid. Error getting UUID from openstack: %s\n"%(e))
return str(uuid.uuid4())
4 changes: 1 addition & 3 deletions keylime/registrar_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import json
import tornado_requests
import traceback
import crypto
import base64
import common
Expand Down Expand Up @@ -119,8 +118,7 @@ def getKeys(registrar_ip,registrar_port,instance_id):

return response_body["results"]
except Exception as e:
logger.critical(traceback.format_exc())
logger.critical("An unexpected error occurred: " + str(e))
logger.exception(e)

return None

Expand Down
5 changes: 2 additions & 3 deletions keylime/registrar_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from urlparse import urlparse
import json
import threading
import traceback
import sys
import crypto
import base64
Expand Down Expand Up @@ -254,7 +253,7 @@ def do_POST(self):
except Exception as e:
common.echo_json_response(self, 400, "Error: %s"%e)
logger.warning("POST for " + instance_id + " returning 400 response. Error: %s"%e)
logger.warning(traceback.format_exc())
logger.exception(e)
return


Expand Down Expand Up @@ -344,7 +343,7 @@ def do_PUT(self):
except Exception as e:
common.echo_json_response(self, 400, "Error: %s"%e)
logger.warning("PUT for " + instance_id + " returning 400 response. Error: %s"%e)
logger.warning(traceback.format_exc())
logger.exception(e)
return


Expand Down
165 changes: 82 additions & 83 deletions keylime/tenant.py

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions keylime/tenant_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ def get_instance_state(self, instance_id):
"http://%s:%s/instances/%s"%(tenant_templ.cloudverifier_ip,tenant_templ.cloudverifier_port,instance_id),context=tenant_templ.context)
except Exception as e:
logger.error("Status command response: %s:%s Unexpected response from Cloud Verifier."%(tenant_templ.cloudverifier_ip,tenant_templ.cloudverifier_port))
logger.error(traceback.print_exc())
logger.error("Error: %s "%str(e))
logger.exception(e)
common.echo_json_response(self, 500, "Unexpected response from Cloud Verifier", str(e))
return

Expand Down Expand Up @@ -356,8 +355,7 @@ def get(self):
"http://%s:%s/instances/"%(tenant_templ.registrar_ip,tenant_templ.registrar_port),context=tenant_templ.context)
except Exception as e:
logger.error("Status command response: %s:%s Unexpected response from Registrar."%(tenant_templ.registrar_ip,tenant_templ.registrar_port))
logger.error(traceback.print_exc())
logger.error("Error: %s "%str(e))
logger.exception(e)
common.echo_json_response(self, 500, "Unexpected response from Registrar", str(e))
return

Expand Down
9 changes: 4 additions & 5 deletions keylime/tpm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import time
from tpm_abstract import *
from tpm_ek_ca import *
import traceback

logger = common.init_logging('tpm1')

Expand Down Expand Up @@ -418,7 +417,7 @@ def encryptAIK(self,uuid,pubaik,pubek,ek_tpm,aik_name):

except Exception as e:
logger.error("Error encrypting AIK: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
return False
finally:
if pubaikFile is not None:
Expand Down Expand Up @@ -465,7 +464,7 @@ def activate_identity(self,keyblob):

except Exception as e:
logger.error("Error decrypting AIK: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
return False
finally:
if keyblobFile is not None:
Expand Down Expand Up @@ -682,7 +681,7 @@ def check_deep_quote(self,nonce,data,quote,vAIK,hAIK,vtpm_policy={},tpm_policy={
retout = self.__checkdeepquote_c(hAIKFile.name, vAIKFile.name, quoteFile.name, nonce)
except Exception as e:
logger.error("Error verifying quote: %s"%(e))
logger.error(traceback.format_exc())
logger.exception(e)
return False
finally:
if vAIKFile is not None:
Expand Down Expand Up @@ -770,7 +769,7 @@ def check_quote(self,nonce,data,quote,aikFromRegistrar,tpm_policy={},ima_measure
retout = self.__check_quote_c(aikFile.name, quoteFile.name, nonce)
except Exception as e:
logger.error("Error verifying quote: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
return False
finally:
if aikFile is not None:
Expand Down
7 changes: 3 additions & 4 deletions keylime/tpm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import tempfile
import threading
import time
import traceback

import M2Crypto
from M2Crypto import m2
Expand Down Expand Up @@ -553,7 +552,7 @@ def encryptAIK(self, uuid, pubaik, pubek, ek_tpm, aik_name):

except Exception as e:
logger.error("Error encrypting AIK: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
return None
finally:
if pubekFile is not None:
Expand Down Expand Up @@ -597,7 +596,7 @@ def activate_identity(self, keyblob):

except Exception as e:
logger.error("Error decrypting AIK: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
return False
finally:
if keyblobFile is not None:
Expand Down Expand Up @@ -814,7 +813,7 @@ def check_quote(self, nonce, data, quote, aikFromRegistrar, tpm_policy={}, ima_m
code = retDict['code']
except Exception as e:
logger.error("Error verifying quote: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
return False
finally:
if aikFile is not None:
Expand Down
7 changes: 2 additions & 5 deletions scripts/script_check_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import os
import tempfile
import subprocess
import traceback
import base64

logging.basicConfig(stream=sys.stdout, level=logging.WARN,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
Expand Down Expand Up @@ -76,8 +75,7 @@
# print(line)
print("check_quote(raw): %d runs, total time %f, avg %f ms per run" % (runs,c,c/runs*1000))
except Exception as e:
logger.error("Error verifying quote: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
finally:
if aikFile is not None:
os.remove(aikFile.name)
Expand Down Expand Up @@ -152,8 +150,7 @@
print("check_deep_quote (raw): %d runs, total time %f, avg %f ms per run" % (runs,c,c/runs*1000))

except Exception as e:
logger.error("Error verifying quote: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
finally:
if vAIKFile is not None:
os.remove(vAIKFile.name)
Expand Down
7 changes: 2 additions & 5 deletions scripts/script_check_quote_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import os
import tempfile
import subprocess
import traceback
import base64

logging.basicConfig(stream=sys.stdout, level=logging.WARN,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
Expand Down Expand Up @@ -75,8 +74,7 @@
print("=output="+line)
print("check_quote (raw sig): %d runs, total time %f, avg %f us per run" % (runs,c,c/runs*1000*1000))
except Exception as e:
logger.error("Error verifying quote: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
finally:
if aikFile is not None:
os.remove(aikFile.name)
Expand Down Expand Up @@ -133,8 +131,7 @@
print("check_deep_quote (raw sig): %d runs, total time %f, avg %f us per run" % (runs,c,c/runs*1000*1000))

except Exception as e:
logger.error("Error verifying quote: "+str(e))
logger.error(traceback.format_exc())
logger.exception(e)
finally:
if vAIKFile is not None:
os.remove(vAIKFile.name)
Expand Down

0 comments on commit f33a1a4

Please sign in to comment.