コード例 #1
0
ファイル: verify_test.py プロジェクト: herlo/salt
    def test_max_open_files(self):

        with TestsLoggingHandler() as handler:
            logmsg_dbg = (
                'DEBUG:This salt-master instance has accepted {0} minion keys.'
            )
            logmsg_chk = (
                '{0}:The number of accepted minion keys({1}) should be lower '
                'than 1/4 of the max open files soft setting({2}). According '
                'to the system\'s hard limit, there\'s still a margin of {3} '
                'to raise the salt\'s max_open_files setting. Please consider '
                'raising this value.'
            )
            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! According to the '
                'system\'s hard limit, there\'s still a margin of {3} to '
                'raise the salt\'s max_open_files setting. Please consider '
                'raising this value.'
            )

            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))

            try:
                prev = 0
                for newmax, level in ((24, None), (66, 'INFO'),
                                      (127, 'WARNING'), (196, 'CRITICAL')):

                    for n in range(prev, newmax):
                        kpath = os.path.join(keys_dir, str(n))
                        with salt.utils.fopen(kpath, 'w') as fp_:
                            fp_.write(str(n))

                    opts = {
                        'max_open_files': newmax,
                        'pki_dir': tempdir
                    }

                    check_max_open_files(opts)

                    if level is None:
                        # No log message is triggered, only the DEBUG one which
                        # tells us how many minion keys were accepted.
                        self.assertEqual(
                            [logmsg_dbg.format(newmax)], handler.messages
                        )
                    else:
                        self.assertIn(
                            logmsg_dbg.format(newmax), handler.messages
                        )
                        self.assertIn(
                            logmsg_chk.format(
                                level,
                                newmax,
                                mof_test,
                                mof_h - newmax,
                            ),
                            handler.messages
                        )
                    handler.clear()
                    prev = newmax

                newmax = mof_test
                for n in range(prev, newmax):
                    kpath = os.path.join(keys_dir, str(n))
                    with salt.utils.fopen(kpath, 'w') as fp_:
                        fp_.write(str(n))

                opts = {
                    'max_open_files': newmax,
                    'pki_dir': tempdir
                }

                check_max_open_files(opts)
                self.assertIn(logmsg_dbg.format(newmax), handler.messages)
                self.assertIn(
                    logmsg_crash.format(
                        'CRITICAL',
                        newmax,
                        mof_test,
                        mof_h - newmax,
                    ),
                    handler.messages
                )
                handler.clear()
            except IOError as err:
                if err.errno == 24:
                    # Too many open files
                    self.skipTest('We\'ve hit the max open files setting')
                raise
            finally:
                shutil.rmtree(tempdir)
                resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
コード例 #2
0
ファイル: test_verify.py プロジェクト: cldeluna/salt
    def test_max_open_files(self):
        with TestsLoggingHandler() as handler:
            logmsg_dbg = (
                'DEBUG:This salt-master instance has accepted {0} minion keys.'
            )
            logmsg_chk = (
                '{0}:The number of accepted minion keys({1}) should be lower '
                'than 1/4 of the max open files soft setting({2}). According '
                'to the system\'s hard limit, there\'s still a margin of {3} '
                'to raise the salt\'s max_open_files setting. Please consider '
                'raising this value.')
            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! According to the '
                'system\'s hard limit, there\'s still a margin of {3} to '
                'raise the salt\'s max_open_files setting. Please consider '
                'raising this value.')

            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))

            try:
                prev = 0
                for newmax, level in ((24, None), (66, 'INFO'),
                                      (127, 'WARNING'), (196, 'CRITICAL')):

                    for n in range(prev, newmax):
                        kpath = os.path.join(keys_dir, str(n))
                        with salt.utils.fopen(kpath, 'w') as fp_:
                            fp_.write(str(n))

                    opts = {'max_open_files': newmax, 'pki_dir': tempdir}

                    check_max_open_files(opts)

                    if level is None:
                        # No log message is triggered, only the DEBUG one which
                        # tells us how many minion keys were accepted.
                        self.assertEqual([logmsg_dbg.format(newmax)],
                                         handler.messages)
                    else:
                        self.assertIn(logmsg_dbg.format(newmax),
                                      handler.messages)
                        self.assertIn(
                            logmsg_chk.format(
                                level,
                                newmax,
                                mof_test,
                                mof_h - newmax,
                            ), handler.messages)
                    handler.clear()
                    prev = newmax

                newmax = mof_test
                for n in range(prev, newmax):
                    kpath = os.path.join(keys_dir, str(n))
                    with salt.utils.fopen(kpath, 'w') as fp_:
                        fp_.write(str(n))

                opts = {'max_open_files': newmax, 'pki_dir': tempdir}

                check_max_open_files(opts)
                self.assertIn(logmsg_dbg.format(newmax), handler.messages)
                self.assertIn(
                    logmsg_crash.format(
                        'CRITICAL',
                        newmax,
                        mof_test,
                        mof_h - newmax,
                    ), handler.messages)
                handler.clear()
            except IOError as err:
                if err.errno == 24:
                    # Too many open files
                    self.skipTest('We\'ve hit the max open files setting')
                raise
            finally:
                shutil.rmtree(tempdir)
                resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
コード例 #3
0
ファイル: test_verify.py プロジェクト: crimv42/saltstack
    def test_max_open_files(self):
        with TstSuiteLoggingHandler() as handler:
            logmsg_dbg = (
                'DEBUG:This salt-master instance has accepted {0} minion keys.'
            )
            logmsg_chk = (
                '{0}:The number of accepted minion keys({1}) should be lower '
                'than 1/4 of the max open files soft setting({2}). According '
                'to the system\'s hard limit, there\'s still a margin of {3} '
                'to raise the salt\'s max_open_files setting. Please consider '
                'raising this value.')
            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! According to the '
                'system\'s hard limit, there\'s still a margin of {3} to '
                'raise the salt\'s max_open_files setting. Please consider '
                'raising this value.')
            if sys.platform.startswith('win'):
                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.')

            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

            if sys.platform.startswith('win'):
                win32file._setmaxstdio(mof_test)
            else:
                resource.setrlimit(resource.RLIMIT_NOFILE, (mof_test, mof_h))

            try:
                prev = 0
                for newmax, level in ((24, None), (66, 'INFO'),
                                      (127, 'WARNING'), (196, 'CRITICAL')):

                    for n in range(prev, newmax):
                        kpath = os.path.join(keys_dir, six.text_type(n))
                        with salt.utils.files.fopen(kpath, 'w') as fp_:
                            fp_.write(
                                str(n)
                            )  # future lint: disable=blacklisted-function

                    opts = {'max_open_files': newmax, 'pki_dir': tempdir}

                    check_max_open_files(opts)

                    if level is None:
                        # No log message is triggered, only the DEBUG one which
                        # tells us how many minion keys were accepted.
                        self.assertEqual([logmsg_dbg.format(newmax)],
                                         handler.messages)
                    else:
                        self.assertIn(logmsg_dbg.format(newmax),
                                      handler.messages)
                        self.assertIn(
                            logmsg_chk.format(
                                level,
                                newmax,
                                mof_test,
                                mof_test - newmax
                                if sys.platform.startswith('win') else mof_h -
                                newmax,
                            ), handler.messages)
                    handler.clear()
                    prev = newmax

                newmax = mof_test
                for n in range(prev, newmax):
                    kpath = os.path.join(keys_dir, six.text_type(n))
                    with salt.utils.files.fopen(kpath, 'w') as fp_:
                        fp_.write(str(
                            n))  # future lint: disable=blacklisted-function

                opts = {'max_open_files': newmax, 'pki_dir': tempdir}

                check_max_open_files(opts)
                self.assertIn(logmsg_dbg.format(newmax), handler.messages)
                self.assertIn(
                    logmsg_crash.format(
                        'CRITICAL',
                        newmax,
                        mof_test,
                        mof_test -
                        newmax if sys.platform.startswith('win') else mof_h -
                        newmax,
                    ), handler.messages)
                handler.clear()
            except IOError as err:
                if err.errno == 24:
                    # Too many open files
                    self.skipTest('We\'ve hit the max open files setting')
                raise
            finally:
                if sys.platform.startswith('win'):
                    win32file._setmaxstdio(mof_h)
                else:
                    resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
                shutil.rmtree(tempdir)
コード例 #4
0
ファイル: test_verify.py プロジェクト: nicholasmhughes/salt
    def test_max_open_files(self):
        with TstSuiteLoggingHandler() as handler:
            logmsg_dbg = "DEBUG:This salt-master instance has accepted {0} minion keys."
            logmsg_chk = (
                "{0}:The number of accepted minion keys({1}) should be lower "
                "than 1/4 of the max open files soft setting({2}). According "
                "to the system's hard limit, there's still a margin of {3} "
                "to raise the salt's max_open_files setting. Please consider "
                "raising this value."
            )
            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! According to the "
                "system's hard limit, there's still a margin of {3} to "
                "raise the salt's max_open_files setting. Please consider "
                "raising this value."
            )
            if sys.platform.startswith("win"):
                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."
                )

            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

            if sys.platform.startswith("win"):
                win32file._setmaxstdio(mof_test)
            else:
                resource.setrlimit(resource.RLIMIT_NOFILE, (mof_test, mof_h))

            try:
                prev = 0
                for newmax, level in (
                    (24, None),
                    (66, "INFO"),
                    (127, "WARNING"),
                    (196, "CRITICAL"),
                ):

                    for n in range(prev, newmax):
                        kpath = os.path.join(keys_dir, str(n))
                        with salt.utils.files.fopen(kpath, "w") as fp_:
                            fp_.write(str(n))

                    opts = {"max_open_files": newmax, "pki_dir": tempdir}

                    check_max_open_files(opts)

                    if level is None:
                        # No log message is triggered, only the DEBUG one which
                        # tells us how many minion keys were accepted.
                        self.assertEqual([logmsg_dbg.format(newmax)], handler.messages)
                    else:
                        self.assertIn(logmsg_dbg.format(newmax), handler.messages)
                        self.assertIn(
                            logmsg_chk.format(
                                level,
                                newmax,
                                mof_test,
                                mof_test - newmax
                                if sys.platform.startswith("win")
                                else mof_h - newmax,
                            ),
                            handler.messages,
                        )
                    handler.clear()
                    prev = newmax

                newmax = mof_test
                for n in range(prev, newmax):
                    kpath = os.path.join(keys_dir, str(n))
                    with salt.utils.files.fopen(kpath, "w") as fp_:
                        fp_.write(str(n))

                opts = {"max_open_files": newmax, "pki_dir": tempdir}

                check_max_open_files(opts)
                self.assertIn(logmsg_dbg.format(newmax), handler.messages)
                self.assertIn(
                    logmsg_crash.format(
                        "CRITICAL",
                        newmax,
                        mof_test,
                        mof_test - newmax
                        if sys.platform.startswith("win")
                        else mof_h - newmax,
                    ),
                    handler.messages,
                )
                handler.clear()
            except OSError as err:
                if err.errno == 24:
                    # Too many open files
                    self.skipTest("We've hit the max open files setting")
                raise
            finally:
                if sys.platform.startswith("win"):
                    win32file._setmaxstdio(mof_h)
                else:
                    resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
                shutil.rmtree(tempdir)