Exemplo n.º 1
0
    def load(self, file_names=None):
        """Load either all check plugins or the given file_names"""
        import cmk.base.config as config  # pylint: disable=import-outside-toplevel
        import cmk.base.check_api as check_api  # pylint: disable=import-outside-toplevel
        import cmk.utils.paths  # pylint: disable=import-outside-toplevel

        if config.all_checks_loaded():
            return self  # No need to load more

        if file_names is None:
            raise RuntimeError(
                "Loading all checks is not supported. Use the fixture "
                "\"config_load_all_checks\" instead")

        if not set(file_names) - CheckManager._CHECK_FILES_LOADED:
            return self  # Everything needed is already loaded

        # On first call, initialize the basic data structures
        if not CheckManager._CHECK_FILES_LOADED:
            config._initialize_data_structures()

        CheckManager._CHECK_FILES_LOADED.update(set(file_names))

        config.load_checks(
            check_api.get_check_api_context,
            [os.path.join(cmk.utils.paths.checks_dir, f) for f in file_names])

        return self
Exemplo n.º 2
0
    def __init__(self):
        # Local import to have faster pytest initialization
        import cmk.base.api.agent_based.register as register  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.check_api as check_api  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.inventory_plugins as inventory_plugins  # pylint: disable=bad-option-value,import-outside-toplevel

        config._initialize_data_structures()
        assert config.check_info == {}

        with cmk_debug_enabled():  # fail if a plugin can't be loaded
            config.load_all_agent_based_plugins(
                check_api.get_check_api_context)
            inventory_plugins.load_legacy_inventory_plugins(
                check_api.get_check_api_context,
                register.inventory_plugins_legacy.get_inventory_context,
            )

        # some sanitiy checks, may decrease as we migrate
        assert len(config.check_info) > 1000
        assert len(config.snmp_info) > 400
        assert len(inventory_plugins._inv_info) > 60

        self._snmp_sections = copy.deepcopy(
            register._config.registered_snmp_sections)
        self._agent_sections = copy.deepcopy(
            register._config.registered_agent_sections)
        self._check_plugins = copy.deepcopy(
            register._config.registered_check_plugins)
        self._inventory_plugins = copy.deepcopy(
            register._config.registered_inventory_plugins)
Exemplo n.º 3
0
def _config_load_all_checks():
    # this is needed in cmk/base *and* checks/ :-(
    import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
    import cmk.base.check_api as check_api  # pylint: disable=bad-option-value,import-outside-toplevel

    config._initialize_data_structures()
    assert config.check_info == {}

    with cmk_debug_enabled():  # fail if a plugin can't be loaded
        config.load_all_checks(check_api.get_check_api_context)

    assert len(config.check_info) > 1000  # sanitiy check
Exemplo n.º 4
0
def _config_load_all_checks():
    # Local import to have faster pytest initialization
    import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
    import cmk.base.check_api as check_api  # pylint: disable=bad-option-value,import-outside-toplevel

    config._initialize_data_structures()
    assert config.check_info == {}

    with cmk_debug_enabled():  # fail if a plugin can't be loaded
        config.load_all_agent_based_plugins(check_api.get_check_api_context)

    assert len(config.check_info) > 1000  # sanitiy check
Exemplo n.º 5
0
    def load(self, file_names=None):
        """Load either all check plugins or the given file_names"""
        import cmk.base.config as config  # pylint: disable=import-outside-toplevel
        import cmk.base.check_api as check_api  # pylint: disable=import-outside-toplevel
        import cmk.utils.paths  # pylint: disable=import-outside-toplevel

        if file_names is None:
            config.load_all_checks(check_api.get_check_api_context)  # loads all checks
        else:
            config._initialize_data_structures()
            config.load_checks(check_api.get_check_api_context,
                               [os.path.join(cmk.utils.paths.checks_dir, f) for f in file_names])

        return self
Exemplo n.º 6
0
    def load(self, file_names=None):
        """Load either all check plugins or the given file_names"""
        if sys.version_info[0] < 3:
            # This has not been ported to Python 3 yet. Prevent mypy in Python 3 mode from following
            import cmk.base.config as config
            import cmk.base.check_api as check_api
            import cmk.utils.paths

        if file_names is None:
            config.load_all_checks(
                check_api.get_check_api_context)  # loads all checks
        else:
            config._initialize_data_structures()
            config.load_checks(check_api.get_check_api_context, [
                os.path.join(cmk.utils.paths.checks_dir, f) for f in file_names
            ])

        return self
Exemplo n.º 7
0
    def __init__(self) -> None:
        # Local import to have faster pytest initialization
        import cmk.base.api.agent_based.register as register  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.check_api as check_api  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.inventory_plugins as inventory_plugins  # pylint: disable=bad-option-value,import-outside-toplevel

        config._initialize_data_structures()
        assert config.check_info == {}

        config.load_all_agent_based_plugins(
            check_api.get_check_api_context,
            inventory_plugins.load_legacy_inventory_plugins,
        )

        # our test environment does not deal with namespace packages properly. load plus plugins:
        try:
            load_plugins = list(
                load_plugins_with_exceptions(
                    "plus.cmk.base.plugins.agent_based"))
        except ModuleNotFoundError:
            pass
        else:
            for _plugin, exception in load_plugins:
                raise exception

        inventory_plugins.load_legacy_inventory_plugins(
            check_api.get_check_api_context,
            register.inventory_plugins_legacy.get_inventory_context,
        )

        self._snmp_sections = copy.deepcopy(
            register._config.registered_snmp_sections)
        self._agent_sections = copy.deepcopy(
            register._config.registered_agent_sections)
        self._check_plugins = copy.deepcopy(
            register._config.registered_check_plugins)
        self._inventory_plugins = copy.deepcopy(
            register._config.registered_inventory_plugins)
Exemplo n.º 8
0
    def __init__(self):
        # Local import to have faster pytest initialization
        import cmk.base.api.agent_based.register as register  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.check_api as check_api  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.inventory_plugins as inventory_plugins  # pylint: disable=bad-option-value,import-outside-toplevel

        config._initialize_data_structures()
        assert config.check_info == {}

        config.load_all_agent_based_plugins(check_api.get_check_api_context)
        inventory_plugins.load_legacy_inventory_plugins(
            check_api.get_check_api_context,
            register.inventory_plugins_legacy.get_inventory_context,
        )

        self._snmp_sections = copy.deepcopy(
            register._config.registered_snmp_sections)
        self._agent_sections = copy.deepcopy(
            register._config.registered_agent_sections)
        self._check_plugins = copy.deepcopy(
            register._config.registered_check_plugins)
        self._inventory_plugins = copy.deepcopy(
            register._config.registered_inventory_plugins)
Exemplo n.º 9
0
def test_load_checks():
    config._initialize_data_structures()
    assert config.check_info == {}
    config.load_all_checks(check_api.get_check_api_context)
    assert len(config.check_info) > 1000