mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix unit.utils.test_verify
for Windows
Use Windows api to get and set the maxstdio Change messages to work with Windows
This commit is contained in:
parent
a9592dd3e2
commit
e496d28cbf
1 changed files with 34 additions and 8 deletions
|
@ -10,10 +10,15 @@ import os
|
|||
import sys
|
||||
import stat
|
||||
import shutil
|
||||
import resource
|
||||
import tempfile
|
||||
import socket
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
import win32file
|
||||
except ImportError:
|
||||
import resource
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
from tests.support.paths import TMP
|
||||
|
@ -82,7 +87,10 @@ class TestVerify(TestCase):
|
|||
writer = FakeWriter()
|
||||
sys.stderr = writer
|
||||
# Now run the test
|
||||
self.assertFalse(check_user('nouser'))
|
||||
if salt.utils.is_windows():
|
||||
self.assertTrue(check_user('nouser'))
|
||||
else:
|
||||
self.assertFalse(check_user('nouser'))
|
||||
# Restore sys.stderr
|
||||
sys.stderr = stderr
|
||||
if writer.output != 'CRITICAL: User not found: "nouser"\n':
|
||||
|
@ -118,7 +126,6 @@ class TestVerify(TestCase):
|
|||
# not support IPv6.
|
||||
pass
|
||||
|
||||
@skipIf(True, 'Skipping until we can find why Jenkins is bailing out')
|
||||
def test_max_open_files(self):
|
||||
with TestsLoggingHandler() as handler:
|
||||
logmsg_dbg = (
|
||||
|
@ -139,15 +146,31 @@ class TestVerify(TestCase):
|
|||
'raise the salt\'s max_open_files setting. Please consider '
|
||||
'raising this value.'
|
||||
)
|
||||
if salt.utils.is_windows():
|
||||
logmsg_crash = (
|
||||
'{0}:The number of accepted minion keys({1}) should be lower '
|
||||
'than 1/4 of the max open files soft setting({2}). '
|
||||
'salt-master will crash pretty soon! Please consider '
|
||||
'raising this value.'
|
||||
)
|
||||
|
||||
mof_s, mof_h = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||
if sys.platform.startswith('win'):
|
||||
# Check the Windows API for more detail on this
|
||||
# http://msdn.microsoft.com/en-us/library/xt874334(v=vs.71).aspx
|
||||
# and the python binding http://timgolden.me.uk/pywin32-docs/win32file.html
|
||||
mof_s = mof_h = win32file._getmaxstdio()
|
||||
else:
|
||||
mof_s, mof_h = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||
tempdir = tempfile.mkdtemp(prefix='fake-keys')
|
||||
keys_dir = os.path.join(tempdir, 'minions')
|
||||
os.makedirs(keys_dir)
|
||||
|
||||
mof_test = 256
|
||||
|
||||
resource.setrlimit(resource.RLIMIT_NOFILE, (mof_test, mof_h))
|
||||
if salt.utils.is_windows():
|
||||
win32file._setmaxstdio(mof_test)
|
||||
else:
|
||||
resource.setrlimit(resource.RLIMIT_NOFILE, (mof_test, mof_h))
|
||||
|
||||
try:
|
||||
prev = 0
|
||||
|
@ -181,7 +204,7 @@ class TestVerify(TestCase):
|
|||
level,
|
||||
newmax,
|
||||
mof_test,
|
||||
mof_h - newmax,
|
||||
mof_test - newmax if salt.utils.is_windows() else mof_h - newmax,
|
||||
),
|
||||
handler.messages
|
||||
)
|
||||
|
@ -206,7 +229,7 @@ class TestVerify(TestCase):
|
|||
'CRITICAL',
|
||||
newmax,
|
||||
mof_test,
|
||||
mof_h - newmax,
|
||||
mof_test - newmax if salt.utils.is_windows() else mof_h - newmax,
|
||||
),
|
||||
handler.messages
|
||||
)
|
||||
|
@ -218,7 +241,10 @@ class TestVerify(TestCase):
|
|||
raise
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
|
||||
if salt.utils.is_windows():
|
||||
win32file._setmaxstdio(mof_h)
|
||||
else:
|
||||
resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
def test_verify_log(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue