From: Alfredo Deza Date: Thu, 22 Aug 2013 13:45:07 +0000 (-0400) Subject: move the lsb_fallback to the lsb module X-Git-Tag: v1.2.2~3^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5b7ee2dd3f8499de8f2e6fa6691fb67cf0084ef5;p=ceph-deploy.git move the lsb_fallback to the lsb module Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/hosts/__init__.py b/ceph_deploy/hosts/__init__.py index 33cba50..5fc9730 100644 --- a/ceph_deploy/hosts/__init__.py +++ b/ceph_deploy/hosts/__init__.py @@ -5,8 +5,7 @@ that remote host and set all the special cases for running commands depending on the type of distribution/version we are dealing with. """ import logging -import ceph_deploy -from ceph_deploy import exc +from ceph_deploy import exc, lsb from ceph_deploy.util import wrappers from ceph_deploy.sudo_pushy import get_transport from ceph_deploy.hosts import debian, centos, fedora, suse @@ -15,6 +14,7 @@ from ceph_deploy.hosts import debian, centos, fedora, suse import pushy from ceph_deploy import sudo_pushy sudo_pushy.patch() + logger = logging.getLogger() @@ -36,11 +36,7 @@ def get(hostname, fallback=None): :param fallback: Optional fallback to use if no supported distro is found """ sudo_conn = pushy.connect(get_transport(hostname)) - if not has_lsb(sudo_conn): - logger.warning('lsb_release was not found - inferring OS details') - (distro, release, codename) = lsb_fallback(sudo_conn) - else: - (distro, release, codename) = ceph_deploy.lsb.get_lsb_release(sudo_conn) + (distro, release, codename) = lsb.get_lsb_release(sudo_conn) module = _get_distro(distro) module.name = distro @@ -51,27 +47,6 @@ def get(hostname, fallback=None): return module -def lsb_fallback(conn): - """ - This fallback will attempt to detect the distro, release and codename for - a given remote host when lsb fails. It uses the - ``platform.linux_distribution`` module that should be fairly robust and - would prevent us from adding repositories and installing a package just to - detect a platform. - """ - distro, release, codename = conn.modules.platform.linux_distribution() - return ( - str(distro).rstrip(), - str(release).rstrip(), - str(codename).rstrip() - ) - - -def has_lsb(conn): - _, _, ret_code = wrappers.Popen(conn, logger, ['which', 'lsb_release']) - return ret_code == 0 - - def _get_distro(distro, fallback=None): distro = _normalized_distro_name(distro) distributions = { diff --git a/ceph_deploy/lsb.py b/ceph_deploy/lsb.py index 2ed6cab..b7f3e73 100644 --- a/ceph_deploy/lsb.py +++ b/ceph_deploy/lsb.py @@ -1,6 +1,10 @@ -from . import hosts +import logging from . import exc + +logger = logging.getLogger(__name__) + + def check_lsb_release(): """ Verify if lsb_release command is available @@ -18,6 +22,23 @@ def check_lsb_release(): if ret != 0: raise RuntimeError('The lsb_release command was not found on remote host. Please install the lsb-release package.') + +def lsb_fallback(conn): + """ + This fallback will attempt to detect the distro, release and codename for + a given remote host when lsb fails. It uses the + ``platform.linux_distribution`` module that should be fairly robust and + would prevent us from adding repositories and installing a package just to + detect a platform. + """ + distro, release, codename = conn.modules.platform.linux_distribution() + return ( + str(distro).rstrip(), + str(release).rstrip(), + str(codename).rstrip() + ) + + def lsb_release(): """ Get LSB release information from lsb_release. @@ -82,7 +103,8 @@ def get_lsb_release(sudo): check_lsb_release_r = sudo.compile(check_lsb_release) status = check_lsb_release_r() except RuntimeError as e: - return hosts.lsb_fallback(sudo) + logger.warning('lsb_release was not found - inferring OS details') + return lsb_fallback(sudo) lsb_release_r = sudo.compile(lsb_release) return lsb_release_r()