mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Make sure unix_socket_directories and stats_temp_directory exist (#1293)
Upon the start of Patroni and Postgres make sure that unix_socket_directories and stats_temp_directory exist or try to create them. Patroni will exit if failed to create them. Close https://github.com/zalando/patroni/issues/863
This commit is contained in:
committed by
Alexander Kukushkin
parent
2174d66f97
commit
7ff27d9e10
+24
-1
@@ -2,7 +2,7 @@ import unittest
|
||||
|
||||
from mock import Mock, patch
|
||||
from patroni.exceptions import PatroniException
|
||||
from patroni.utils import Retry, RetryFailedError, polling_loop
|
||||
from patroni.utils import Retry, RetryFailedError, polling_loop, validate_directory
|
||||
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
@@ -10,6 +10,29 @@ class TestUtils(unittest.TestCase):
|
||||
def test_polling_loop(self):
|
||||
self.assertEqual(list(polling_loop(0.001, interval=0.001)), [0])
|
||||
|
||||
@patch('os.path.exists', Mock(return_value=True))
|
||||
@patch('os.path.isdir', Mock(return_value=True))
|
||||
@patch('tempfile.mkstemp', Mock(return_value=("", "")))
|
||||
@patch('os.remove', Mock(side_effect=Exception))
|
||||
def test_validate_directory_writable(self):
|
||||
self.assertRaises(Exception, validate_directory, "/tmp")
|
||||
|
||||
@patch('os.path.exists', Mock(return_value=True))
|
||||
@patch('os.path.isdir', Mock(return_value=True))
|
||||
@patch('tempfile.mkstemp', Mock(side_effect=OSError))
|
||||
def test_validate_directory_not_writable(self):
|
||||
self.assertRaises(PatroniException, validate_directory, "/tmp")
|
||||
|
||||
@patch('os.path.exists', Mock(return_value=False))
|
||||
@patch('os.makedirs', Mock(side_effect=OSError))
|
||||
def test_validate_directory_couldnt_create(self):
|
||||
self.assertRaises(PatroniException, validate_directory, "/tmp")
|
||||
|
||||
@patch('os.path.exists', Mock(return_value=True))
|
||||
@patch('os.path.isdir', Mock(return_value=False))
|
||||
def test_validate_directory_is_not_a_directory(self):
|
||||
self.assertRaises(PatroniException, validate_directory, "/tmp")
|
||||
|
||||
|
||||
@patch('time.sleep', Mock())
|
||||
class TestRetrySleeper(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user