Chameleon fault tolerance

Change-Id: Id7060f121f85a444005dfeff6279daef51a59295
diff --git a/chameleon/web_server/web_server.py b/chameleon/web_server/web_server.py
index af8c6c5..c46ad88 100644
--- a/chameleon/web_server/web_server.py
+++ b/chameleon/web_server/web_server.py
@@ -25,6 +25,7 @@
 from twisted.internet.tcp import Port
 from twisted.web.server import Site
 from twisted.web.static import File
+from werkzeug.exceptions import BadRequest
 
 log = get_logger()
 
@@ -43,23 +44,13 @@
             os.path.join(os.path.dirname(__file__), '../swagger_ui'))
 
         self.tcp_port = None
+        self.shutting_down = False
 
     @inlineCallbacks
     def run(self):
         yield self._open_endpoint()
-        yield self._load_generated_routes()
         returnValue(self)
 
-    def _load_generated_routes(self):
-        for fname in os.listdir(self.work_dir):
-            if fname.endswith('_gw.py'):
-                module_name = fname.replace('.py', '')
-                print 'module_name', module_name
-                m = __import__(module_name)
-                print dir(m)
-                assert hasattr(m, 'add_routes')
-                m.add_routes(self.app, self.grpc_client)
-
     @inlineCallbacks
     def _open_endpoint(self):
         endpoint = endpoints.TCP4ServerEndpoint(reactor, self.port)
@@ -70,10 +61,20 @@
 
     @inlineCallbacks
     def shutdown(self):
-        if self.tcp_porte is not None:
+        self.shutting_down = True
+        if self.tcp_port is not None:
             assert isinstance(self.tcp_port, Port)
             yield self.tcp_port.socket.close()
 
+    def reload_generated_routes(self):
+        for fname in os.listdir(self.work_dir):
+            if fname.endswith('_gw.py'):
+                module_name = fname.replace('.py', '')
+                m = __import__(module_name)
+                assert hasattr(m, 'add_routes')
+                m.add_routes(self.app, self.grpc_client)
+                log.info('routes-loaded', module=module_name)
+
     # static swagger_ui website as landing page (for now)
 
     @app.route('/', branch=True)