Exemplo n.º 1
0
def get_configurator():
    """ Get correct configurator class based on the OS fingerprint """
    logger = logging.getLogger(__name__)
    os_name, os_version = util.get_os_info()
    os_name = os_name.lower()
    override_class = None
    logger.info("OS identified and as: %s", os_name)
    # Special case for older Fedora versions
    if os_name == 'fedora' and LooseVersion(os_version) < LooseVersion('29'):
        os_name = 'fedora_old'

    try:
        override_class = OVERRIDE_CLASSES[os_name]
        logger.info("Configuration for the OS successfully identified")
    except KeyError:
        # OS not found in the list
        logger.warning(
            "OS not found in the list, beginning to try to find a similar OS")
        os_like = util.get_systemd_os_like()
        if os_like:
            for os_name in os_like:
                if os_name in OVERRIDE_CLASSES.keys():
                    override_class = OVERRIDE_CLASSES[os_name]
                    logger.info(
                        "OS Identified as: %s, configuration for the OS found",
                        os_name)
        if not override_class:
            # No override class found, return the generic configurator
            override_class = configurator.ApacheConfigurator
            logger.warning(
                "Similar OS not found, default configurator returned."
                "You may need to inspect the defaults")
    return override_class
Exemplo n.º 2
0
    def test_systemd_os_release_like(self):
        from certbot.util import get_systemd_os_like

        with mock.patch('os.path.isfile', return_value=True):
            id_likes = get_systemd_os_like(test_util.vector_path("os-release"))
            self.assertEqual(len(id_likes), 3)
            self.assertTrue("debian" in id_likes)
Exemplo n.º 3
0
    def test_systemd_os_release_like(self):
        from certbot.util import get_systemd_os_like

        with mock.patch('os.path.isfile', return_value=True):
            id_likes = get_systemd_os_like(test_util.vector_path(
                "os-release"))
            self.assertEqual(len(id_likes), 3)
            self.assertTrue("debian" in id_likes)
Exemplo n.º 4
0
def os_like_constants():
    """
    Try to get constants for distribution with
    similar layout and configuration, indicated by
    /etc/os-release variable "LIKE"

    :returns: Constants dictionary
    :rtype: `dict`
    """

    os_like = util.get_systemd_os_like()
    if os_like:
        for os_name in os_like:
            if os_name in CLI_DEFAULTS.keys():
                return CLI_DEFAULTS[os_name]
    return {}
Exemplo n.º 5
0
def os_like_constants():
    """
    Try to get constants for distribution with
    similar layout and configuration, indicated by
    /etc/os-release variable "LIKE"

    :returns: Constants dictionary
    :rtype: `dict`
    """

    os_like = util.get_systemd_os_like()
    if os_like:
        for os_name in os_like:
            if os_name in CLI_DEFAULTS.keys():
                return CLI_DEFAULTS[os_name]
    return {}
Exemplo n.º 6
0
def get_configurator():
    """ Get correct configurator class based on the OS fingerprint """
    os_info = util.get_os_info()
    override_class = None
    try:
        override_class = OVERRIDE_CLASSES[os_info[0].lower()]
    except KeyError:
        # OS not found in the list
        os_like = util.get_systemd_os_like()
        if os_like:
            for os_name in os_like:
                if os_name in OVERRIDE_CLASSES.keys():
                    override_class = OVERRIDE_CLASSES[os_name]
        if not override_class:
            # No override class found, return the generic configurator
            override_class = configurator.ApacheConfigurator
    return override_class
Exemplo n.º 7
0
def get_configurator():
    """ Get correct configurator class based on the OS fingerprint """
    os_info = util.get_os_info()
    override_class = None
    try:
        override_class = OVERRIDE_CLASSES[os_info[0].lower()]
    except KeyError:
        # OS not found in the list
        os_like = util.get_systemd_os_like()
        if os_like:
            for os_name in os_like:
                if os_name in OVERRIDE_CLASSES.keys():
                    override_class = OVERRIDE_CLASSES[os_name]
        if not override_class:
            # No override class found, return the generic configurator
            override_class = configurator.ApacheConfigurator
    return override_class
Exemplo n.º 8
0
def get_configurator():
    """ Get correct configurator class based on the OS fingerprint """
    os_name, os_version = util.get_os_info()
    os_name = os_name.lower()
    override_class = None

    # Special case for older Fedora versions
    if os_name == 'fedora' and LooseVersion(os_version) < LooseVersion('29'):
        os_name = 'fedora_old'

    try:
        override_class = OVERRIDE_CLASSES[os_name]
    except KeyError:
        # OS not found in the list
        os_like = util.get_systemd_os_like()
        if os_like:
            for os_name in os_like:
                if os_name in OVERRIDE_CLASSES.keys():
                    override_class = OVERRIDE_CLASSES[os_name]
        if not override_class:
            # No override class found, return the generic configurator
            override_class = configurator.ApacheConfigurator
    return override_class
Exemplo n.º 9
0
def get_configurator():
    """ Get correct configurator class based on the OS fingerprint """
    os_name, os_version = util.get_os_info()
    os_name = os_name.lower()
    override_class = None

    # Special case for older Fedora versions
    if os_name == 'fedora' and LooseVersion(os_version) < LooseVersion('29'):
        os_name = 'fedora_old'

    try:
        override_class = OVERRIDE_CLASSES[os_name]
    except KeyError:
        # OS not found in the list
        os_like = util.get_systemd_os_like()
        if os_like:
            for os_name in os_like:
                if os_name in OVERRIDE_CLASSES.keys():
                    override_class = OVERRIDE_CLASSES[os_name]
        if not override_class:
            # No override class found, return the generic configurator
            override_class = configurator.ApacheConfigurator
    return override_class
Exemplo n.º 10
0
 def test_systemd_os_release_like(self, m_distro):
     import certbot.util as cbutil
     m_distro.like.return_value = "first debian third"
     id_likes = cbutil.get_systemd_os_like()
     self.assertEqual(len(id_likes), 3)
     self.assertIn("debian", id_likes)