diff --git a/ironic_inspector/test/unit/test_wsgi_service.py b/ironic_inspector/test/unit/test_wsgi_service.py index 6c95a6c84..1eac5a21b 100644 --- a/ironic_inspector/test/unit/test_wsgi_service.py +++ b/ironic_inspector/test/unit/test_wsgi_service.py @@ -422,3 +422,20 @@ class TestCreateSSLContext(test_base.BaseTest): self.assertEqual(mock_context, con) mock_context.load_cert_chain.assert_called_once_with(cert_path, key_path) + + +class TestWSGIServiceOnSigHup(BaseWSGITest): + def setUp(self): + super(TestWSGIServiceOnSigHup, self).setUp() + self.mock_spawn = self.useFixture(fixtures.MockPatchObject( + wsgi_service.eventlet, 'spawn')).mock + self.mock_mutate_conf = self.useFixture(fixtures.MockPatchObject( + wsgi_service.CONF, 'mutate_config_files')).mock + + def test_on_sighup(self): + self.service._handle_sighup() + self.mock_spawn.assert_called_once_with(self.service._handle_sighup_bg) + + def test_on_sighup_bg(self): + self.service._handle_sighup_bg() + self.mock_mutate_conf.assert_called_once_with() diff --git a/ironic_inspector/wsgi_service.py b/ironic_inspector/wsgi_service.py index 3ff12b3b6..bdac392b3 100644 --- a/ironic_inspector/wsgi_service.py +++ b/ironic_inspector/wsgi_service.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +import signal import ssl import sys import traceback as traceback_mod @@ -41,6 +42,7 @@ class WSGIService(object): self.app = app.app self._periodics_worker = None self._shutting_down = semaphore.Semaphore() + signal.signal(signal.SIGHUP, self._handle_sighup) def _init_middleware(self): """Initialize WSGI middleware. @@ -189,6 +191,13 @@ class WSGIService(object): else: self.shutdown() + def _handle_sighup_bg(self, *args): + """Reload config on SIGHUP.""" + CONF.mutate_config_files() + + def _handle_sighup(self, *args): + eventlet.spawn(self._handle_sighup_bg, *args) + def periodic_clean_up(): # pragma: no cover try: diff --git a/releasenotes/notes/sighup-support-e6eaec034d963108.yaml b/releasenotes/notes/sighup-support-e6eaec034d963108.yaml new file mode 100644 index 000000000..17c404c7c --- /dev/null +++ b/releasenotes/notes/sighup-support-e6eaec034d963108.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + Issuing a SIGHUP to the ironic-inspector service will cause the service to + reload and use any changed values for *mutable* configuration options. + + Mutable configuration options are indicated as such in the `sample + configuration file `_ + by ``Note: This option can be changed without restarting``. + + A warning is logged for any changes to immutable configuration options. \ No newline at end of file