From 87db01e977e0fe55df762b7f4d26e669d47cbefd Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanino Date: Tue, 23 Jun 2015 23:49:50 -0400 Subject: [PATCH] Graceful shutdown WSGI/RPC server Change-ID I80487f559302b0e88953835ffb4a3bfe2a347501 introduces oslo.service into Cinder. The graceful shutdown of RPC server was introduced via merging of oslo.service. Actual fix was introduced by https://review.openstack.org/#/c/190175/ into oslo.service. The oslo.service fix provides this facility through it's wait() method, so we need to call it in Cinder Service wait() method which gets called when graceful shutdown is requested by sending the process SIGTERM. Change-Id: Iea877e062272103ea48583b5638dec6174e99de0 Closes-Bug: 1464822 --- cinder/service.py | 4 +++- cinder/tests/unit/test_service.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cinder/service.py b/cinder/service.py index b41f135d3..595e6da4c 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -135,6 +135,7 @@ class Service(service.Service): self.timers = [] setup_profiler(binary, host) + self.rpcserver = None def start(self): version_string = version.version_string() @@ -263,7 +264,6 @@ class Service(service.Service): # errors, go ahead and ignore them.. as we're shutting down anyway try: self.rpcserver.stop() - self.rpcserver.wait() except Exception: pass for x in self.timers: @@ -280,6 +280,8 @@ class Service(service.Service): x.wait() except Exception: pass + if self.rpcserver: + self.rpcserver.wait() def periodic_tasks(self, raise_on_error=False): """Tasks to be run at a periodic interval.""" diff --git a/cinder/tests/unit/test_service.py b/cinder/tests/unit/test_service.py index 5c95ed059..c70cbc484 100644 --- a/cinder/tests/unit/test_service.py +++ b/cinder/tests/unit/test_service.py @@ -240,6 +240,7 @@ class ServiceTestCase(test.TestCase): ) serv.start() serv.stop() + serv.wait() serv.rpcserver.start.assert_called_once_with() serv.rpcserver.stop.assert_called_once_with() serv.rpcserver.wait.assert_called_once_with() -- 2.45.2