Merge "daemon: avoid raising UnboundLocalError to callers"
This commit is contained in:
commit
62ea46f625
@ -90,6 +90,7 @@ def daemon_start(config, filters):
|
|||||||
manager_cls = get_manager_class(config, filters)
|
manager_cls = get_manager_class(config, filters)
|
||||||
manager = manager_cls(address=socket_path)
|
manager = manager_cls(address=socket_path)
|
||||||
server = manager.get_server()
|
server = manager.get_server()
|
||||||
|
try:
|
||||||
# allow everybody to connect to the socket
|
# allow everybody to connect to the socket
|
||||||
rw_rw_rw_ = (stat.S_IRUSR | stat.S_IWUSR |
|
rw_rw_rw_ = (stat.S_IRUSR | stat.S_IWUSR |
|
||||||
stat.S_IRGRP | stat.S_IWGRP |
|
stat.S_IRGRP | stat.S_IWGRP |
|
||||||
@ -114,11 +115,11 @@ def daemon_start(config, filters):
|
|||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
finally:
|
finally:
|
||||||
conn = server.listener
|
conn = server.listener
|
||||||
# This will break accept() loop with EOFError if it was not in the main
|
# This will break accept() loop with EOFError if it was not in the
|
||||||
# thread (as in Python 3.x)
|
# main thread (as in Python 3.x)
|
||||||
conn.close()
|
conn.close()
|
||||||
# Closing all currently connected client sockets for reading to break
|
# Closing all currently connected client sockets for reading to
|
||||||
# worker threads blocked on recv()
|
# break worker threads blocked on recv()
|
||||||
for cl_conn in conn.get_accepted():
|
for cl_conn in conn.get_accepted():
|
||||||
try:
|
try:
|
||||||
cl_conn.half_close()
|
cl_conn.half_close()
|
||||||
@ -130,6 +131,7 @@ def daemon_start(config, filters):
|
|||||||
if thread.daemon:
|
if thread.daemon:
|
||||||
LOG.debug("Joining thread %s", thread)
|
LOG.debug("Joining thread %s", thread)
|
||||||
thread.join()
|
thread.join()
|
||||||
|
finally:
|
||||||
LOG.debug("Removing temporary directory %s", temp_dir)
|
LOG.debug("Removing temporary directory %s", temp_dir)
|
||||||
shutil.rmtree(temp_dir)
|
shutil.rmtree(temp_dir)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from six import moves
|
|||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from oslo_rootwrap import cmd
|
from oslo_rootwrap import cmd
|
||||||
|
from oslo_rootwrap import daemon
|
||||||
from oslo_rootwrap import filters
|
from oslo_rootwrap import filters
|
||||||
from oslo_rootwrap import wrapper
|
from oslo_rootwrap import wrapper
|
||||||
|
|
||||||
@ -583,3 +584,19 @@ class RunOneCommandTestCase(testtools.TestCase):
|
|||||||
|
|
||||||
def test_negative_returncode(self):
|
def test_negative_returncode(self):
|
||||||
self._test_returncode_helper(-1, 129)
|
self._test_returncode_helper(-1, 129)
|
||||||
|
|
||||||
|
|
||||||
|
class DaemonCleanupException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DaemonCleanupTestCase(testtools.TestCase):
|
||||||
|
|
||||||
|
@mock.patch('os.chmod')
|
||||||
|
@mock.patch('shutil.rmtree')
|
||||||
|
@mock.patch('tempfile.mkdtemp')
|
||||||
|
@mock.patch('multiprocessing.managers.BaseManager.get_server',
|
||||||
|
side_effect=DaemonCleanupException)
|
||||||
|
def test_daemon_no_cleanup_for_uninitialized_server(self, gs, *args):
|
||||||
|
self.assertRaises(DaemonCleanupException, daemon.daemon_start,
|
||||||
|
config=None, filters=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user