summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-19 14:10:30 +0000
committerGerrit Code Review <review@openstack.org>2018-12-19 14:10:30 +0000
commit2c44e7fe43704e35da702959f0fc81ab7e51318f (patch)
treea69a790e4fa1bb2879f4d5d1fc3a0efa438dec8b
parent77d1918117392330e93b880563aa2536aaa0e478 (diff)
parent159ef2e1d26f25a5d7a0514d5155f3c74c4a8a86 (diff)
Merge "Restore correct signal handling in Python3"
-rw-r--r--oslo_service/service.py4
-rw-r--r--oslo_service/tests/test_service.py19
2 files changed, 18 insertions, 5 deletions
diff --git a/oslo_service/service.py b/oslo_service/service.py
index 2e56d30..133a6a2 100644
--- a/oslo_service/service.py
+++ b/oslo_service/service.py
@@ -28,7 +28,6 @@ import io
28import logging 28import logging
29import os 29import os
30import random 30import random
31import select
32import signal 31import signal
33import six 32import six
34import sys 33import sys
@@ -204,8 +203,9 @@ class SignalHandler(object):
204 For Python 3.5 and later, deal with the changes in PEP 475 that prevent 203 For Python 3.5 and later, deal with the changes in PEP 475 that prevent
205 a signal from interrupting eventlet's call to poll() or sleep(). 204 a signal from interrupting eventlet's call to poll() or sleep().
206 """ 205 """
206 select_module = eventlet.patcher.original('select')
207 self.__force_interrupt_on_signal = (sys.version_info >= (3, 5) and 207 self.__force_interrupt_on_signal = (sys.version_info >= (3, 5) and
208 hasattr(select, 'poll')) 208 hasattr(select_module, 'poll'))
209 209
210 if self.__force_interrupt_on_signal: 210 if self.__force_interrupt_on_signal:
211 try: 211 try:
diff --git a/oslo_service/tests/test_service.py b/oslo_service/tests/test_service.py
index 7c61600..0719bbd 100644
--- a/oslo_service/tests/test_service.py
+++ b/oslo_service/tests/test_service.py
@@ -478,17 +478,30 @@ class ProcessLauncherTest(base.ServiceBaseTestCase):
478 signal_handler.clear() 478 signal_handler.clear()
479 479
480 @mock.patch('sys.version_info', (3, 5)) 480 @mock.patch('sys.version_info', (3, 5))
481 @mock.patch.object(service, 'select', spec=[]) 481 def test_setup_signal_interruption_no_select_poll(self):
482 def test_setup_signal_interruption_no_select_poll(self, mock_select):
483 # NOTE(claudiub): SignalHandler is a singleton, which means that it 482 # NOTE(claudiub): SignalHandler is a singleton, which means that it
484 # might already be initialized. We need to clear to clear the cache 483 # might already be initialized. We need to clear to clear the cache
485 # in order to prevent race conditions between tests. 484 # in order to prevent race conditions between tests.
486 service.SignalHandler.__class__._instances.clear() 485 service.SignalHandler.__class__._instances.clear()
487 signal_handler = service.SignalHandler() 486 with mock.patch('eventlet.patcher.original',
487 return_value=object()) as get_original:
488 signal_handler = service.SignalHandler()
489 get_original.assert_called_with('select')
488 self.addCleanup(service.SignalHandler.__class__._instances.clear) 490 self.addCleanup(service.SignalHandler.__class__._instances.clear)
489 self.assertFalse( 491 self.assertFalse(
490 signal_handler._SignalHandler__force_interrupt_on_signal) 492 signal_handler._SignalHandler__force_interrupt_on_signal)
491 493
494 @mock.patch('sys.version_info', (3, 5))
495 def test_setup_signal_interruption_select_poll(self):
496 # NOTE(claudiub): SignalHandler is a singleton, which means that it
497 # might already be initialized. We need to clear to clear the cache
498 # in order to prevent race conditions between tests.
499 service.SignalHandler.__class__._instances.clear()
500 signal_handler = service.SignalHandler()
501 self.addCleanup(service.SignalHandler.__class__._instances.clear)
502 self.assertTrue(
503 signal_handler._SignalHandler__force_interrupt_on_signal)
504
492 @mock.patch('signal.alarm') 505 @mock.patch('signal.alarm')
493 @mock.patch("os.kill") 506 @mock.patch("os.kill")
494 @mock.patch("oslo_service.service.ProcessLauncher.stop") 507 @mock.patch("oslo_service.service.ProcessLauncher.stop")