From 0a94fac407e9fd124cf65345ddb552143dd6bc9b Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 15 Dec 2019 00:08:18 -0500 Subject: [PATCH] Fix bugs around passing master Was not passing properly and getting stuck sometimes, so modify the checking and route creation a bit to prevent it. Seems to work. --- node-daemon/pvcd/MetadataAPIInstance.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/node-daemon/pvcd/MetadataAPIInstance.py b/node-daemon/pvcd/MetadataAPIInstance.py index 15e02c4e..bd29faef 100644 --- a/node-daemon/pvcd/MetadataAPIInstance.py +++ b/node-daemon/pvcd/MetadataAPIInstance.py @@ -41,6 +41,7 @@ class MetadataAPIInstance(object): self.logger = logger self.thread = None self.md_http_server = None + self.add_routes() # Add flask routes inside our instance def add_routes(self): @@ -86,7 +87,6 @@ class MetadataAPIInstance(object): def launch_wsgi(self): try: - self.add_routes() self.md_http_server = gevent.pywsgi.WSGIServer( ('169.254.169.254', 80), self.mdapi, @@ -106,14 +106,17 @@ class MetadataAPIInstance(object): self.logger.out('Successfully started Metadata API thread', state='o') def stop(self): + if not self.md_http_server: + return + self.logger.out('Stopping Metadata API at 169.254.169.254:80', state='i') - if self.thread and self.md_http_server: - try: - self.md_http_server.stop() - self.md_http_server.close() - self.logger.out('Successfully stopped Metadata API', state='o') - except Exception as e: - self.logger.out('Error stopping Metadata API: {}'.format(e), state='e') + try: + self.md_http_server.stop() + self.md_http_server.close() + self.md_http_server = None + self.logger.out('Successfully stopped Metadata API', state='o') + except Exception as e: + self.logger.out('Error stopping Metadata API: {}'.format(e), state='e') # Helper functions def open_database(self):