示例#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
示例#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)
示例#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)
示例#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 {}
示例#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 {}
示例#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
示例#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
示例#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
示例#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
示例#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)