mirror of
https://github.com/ceph/ceph
synced 2025-02-21 18:17:42 +00:00
src: remove ceph-detect-init tool
Signed-off-by: Alfredo Deza <adeza@redhat.com>
This commit is contained in:
parent
328807f80b
commit
16ff21f142
14
src/ceph-detect-init/.gitignore
vendored
14
src/ceph-detect-init/.gitignore
vendored
@ -1,14 +0,0 @@
|
||||
*~
|
||||
*.pyc
|
||||
*.pyo
|
||||
.coverage
|
||||
.tox
|
||||
*.egg-info
|
||||
*.egg
|
||||
dist
|
||||
virtualenv
|
||||
build
|
||||
wheelhouse*
|
||||
*.log
|
||||
*.trs
|
||||
.cache
|
@ -1,2 +0,0 @@
|
||||
- Owen Synge <osynge@suse.com>
|
||||
- Loic Dachary <loic@dachary.org>
|
@ -1,12 +0,0 @@
|
||||
set(CEPH_DETECT_INIT_VIRTUALENV ${CEPH_BUILD_VIRTUALENV}/ceph-detect-init-virtualenv)
|
||||
|
||||
add_custom_target(ceph-detect-init
|
||||
COMMAND
|
||||
${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh --python=python2.7 ${CEPH_DETECT_INIT_VIRTUALENV} &&
|
||||
${CEPH_DETECT_INIT_VIRTUALENV}/bin/pip install --no-index --find-links=file:${CMAKE_SOURCE_DIR}/src/ceph-detect-init/wheelhouse -e .
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ceph-detect-init
|
||||
COMMENT "ceph-detect-init is being created")
|
||||
add_dependencies(tests ceph-detect-init)
|
||||
|
||||
include(Distutils)
|
||||
distutils_install_module(ceph_detect_init)
|
@ -1 +0,0 @@
|
||||
include AUTHORS.rst
|
@ -1,28 +0,0 @@
|
||||
ceph-detect-init
|
||||
================
|
||||
|
||||
ceph-detect-init is a command line tool that displays a normalized
|
||||
string describing the init system of the host on which it is running:
|
||||
|
||||
Home page : https://pypi.python.org/pypi/ceph-detect-init
|
||||
|
||||
Hacking
|
||||
=======
|
||||
|
||||
* Get the code : git clone https://git.ceph.com/ceph.git
|
||||
* Run the unit tests : tox
|
||||
* Run the integration tests (requires docker) : tox -e integration
|
||||
* Check the documentation : rst2html < README.rst > /tmp/a.html
|
||||
* Prepare a new version
|
||||
|
||||
- version=1.0.0 ; perl -pi -e "s/^version.*/version='$version',/" setup.py ; do python setup.py sdist ; amend=$(git log -1 --oneline | grep --quiet "version $version" && echo --amend) ; git commit $amend -m "version $version" setup.py ; git tag -a -f -m "version $version" $version ; done
|
||||
|
||||
* Publish a new version
|
||||
|
||||
- python setup.py sdist upload --sign
|
||||
- git push ; git push --tags
|
||||
|
||||
* pypi maintenance
|
||||
|
||||
- python setup.py register # if the project does not yet exist
|
||||
- trim old versions at https://pypi.python.org/pypi/ceph-detect-init
|
@ -1,158 +0,0 @@
|
||||
# Copyright (C) 2015 <contact@redhat.com>
|
||||
#
|
||||
# Author: Alfredo Deza <adeza@redhat.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Library Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Library Public License for more details.
|
||||
#
|
||||
from ceph_detect_init import alpine
|
||||
from ceph_detect_init import arch
|
||||
from ceph_detect_init import centos
|
||||
from ceph_detect_init import debian
|
||||
from ceph_detect_init import exc
|
||||
from ceph_detect_init import fedora
|
||||
from ceph_detect_init import rhel
|
||||
from ceph_detect_init import suse
|
||||
from ceph_detect_init import gentoo
|
||||
from ceph_detect_init import freebsd
|
||||
from ceph_detect_init import docker
|
||||
from ceph_detect_init import oraclevms
|
||||
import os
|
||||
import logging
|
||||
import platform
|
||||
|
||||
|
||||
def get(use_rhceph=False):
|
||||
distro_name, release, codename = platform_information()
|
||||
# Not all distributions have a concept that maps to codenames
|
||||
# (or even releases really)
|
||||
if not codename and not _get_distro(distro_name):
|
||||
raise exc.UnsupportedPlatform(
|
||||
distro=distro_name,
|
||||
codename=codename,
|
||||
release=release)
|
||||
|
||||
module = _get_distro(distro_name, use_rhceph=use_rhceph)
|
||||
module.name = distro_name
|
||||
module.normalized_name = _normalized_distro_name(distro_name)
|
||||
module.distro = module.normalized_name
|
||||
module.is_el = module.normalized_name in ['redhat', 'centos',
|
||||
'fedora', 'scientific',
|
||||
'oraclel']
|
||||
module.release = release
|
||||
module.codename = codename
|
||||
module.init = module.choose_init()
|
||||
return module
|
||||
|
||||
|
||||
def _get_distro(distro, use_rhceph=False):
|
||||
if not distro:
|
||||
return
|
||||
|
||||
distro = _normalized_distro_name(distro)
|
||||
distributions = {
|
||||
'alpine': alpine,
|
||||
'arch': arch,
|
||||
'debian': debian,
|
||||
'ubuntu': debian,
|
||||
'linuxmint': debian,
|
||||
'centos': centos,
|
||||
'scientific': centos,
|
||||
'oraclel': centos,
|
||||
'oraclevms': oraclevms,
|
||||
'redhat': centos,
|
||||
'fedora': fedora,
|
||||
'suse': suse,
|
||||
'gentoo': gentoo,
|
||||
'funtoo': gentoo,
|
||||
'exherbo': gentoo,
|
||||
'freebsd': freebsd,
|
||||
'docker': docker,
|
||||
'virtuozzo': centos,
|
||||
}
|
||||
|
||||
if distro == 'redhat' and use_rhceph:
|
||||
return rhel
|
||||
else:
|
||||
return distributions.get(distro)
|
||||
|
||||
|
||||
def _normalized_distro_name(distro):
|
||||
distro = distro.lower()
|
||||
if distro.startswith(('redhat', 'red hat')):
|
||||
return 'redhat'
|
||||
elif distro.startswith(('scientific', 'scientific linux')):
|
||||
return 'scientific'
|
||||
elif distro.startswith(('suse', 'opensuse')):
|
||||
return 'suse'
|
||||
elif distro.startswith('centos'):
|
||||
return 'centos'
|
||||
elif distro.startswith('oracle linux'):
|
||||
return 'oraclel'
|
||||
elif distro.startswith('oracle vm'):
|
||||
return 'oraclevms'
|
||||
elif distro.startswith(('gentoo', 'funtoo', 'exherbo')):
|
||||
return 'gentoo'
|
||||
elif distro.startswith('virtuozzo'):
|
||||
return 'virtuozzo'
|
||||
return distro
|
||||
|
||||
|
||||
def platform_information():
|
||||
"""detect platform information from remote host."""
|
||||
try:
|
||||
file_name = '/proc/self/cgroup'
|
||||
with open(file_name, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
if "docker" in line.split(':')[2]:
|
||||
return ('docker', 'docker', 'docker')
|
||||
except Exception as err:
|
||||
logging.debug("platform_information: ",
|
||||
"Error while opening %s : %s" % (file_name, err))
|
||||
|
||||
if os.path.isfile('/.dockerenv'):
|
||||
return ('docker', 'docker', 'docker')
|
||||
|
||||
if platform.system() == 'Linux':
|
||||
linux_distro = platform.linux_distribution(
|
||||
supported_dists=platform._supported_dists + ('alpine', 'arch'))
|
||||
logging.debug('platform_information: linux_distribution = ' +
|
||||
str(linux_distro))
|
||||
distro, release, codename = linux_distro
|
||||
elif platform.system() == 'FreeBSD':
|
||||
distro = 'freebsd'
|
||||
release = platform.release()
|
||||
codename = platform.version().split(' ')[3].split(':')[0]
|
||||
logging.debug(
|
||||
'platform_information: release = {}, version = {}'.format(
|
||||
platform.release(), platform.version()))
|
||||
else:
|
||||
raise exc.UnsupportedPlatform(platform.system(), '', '')
|
||||
|
||||
distro_lower = distro.lower()
|
||||
# this could be an empty string in Debian
|
||||
if not codename and 'debian' in distro_lower:
|
||||
pass
|
||||
# this is an empty string in Oracle
|
||||
elif distro_lower.startswith('oracle linux'):
|
||||
codename = 'OL' + release
|
||||
elif distro_lower.startswith('oracle vm'):
|
||||
codename = 'OVS' + release
|
||||
# this could be an empty string in Virtuozzo linux
|
||||
elif distro_lower.startswith('virtuozzo linux'):
|
||||
codename = 'virtuozzo'
|
||||
|
||||
return (
|
||||
str(distro).rstrip(),
|
||||
str(release).rstrip(),
|
||||
str(codename).rstrip()
|
||||
)
|
@ -1,11 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
return 'openrc'
|
@ -1,11 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
return 'systemd'
|
@ -1,13 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
if release and int(release.split('.')[0]) >= 7:
|
||||
return 'systemd'
|
||||
return 'sysvinit'
|
@ -1,21 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
# yes, this is heuristics
|
||||
if os.path.isdir('/run/systemd/system'):
|
||||
return 'systemd'
|
||||
if not subprocess.call('. /lib/lsb/init-functions ; init_is_upstart',
|
||||
shell=True):
|
||||
return 'upstart'
|
||||
if os.path.isfile('/sbin/init') and not os.path.islink('/sbin/init'):
|
||||
return 'sysvinit'
|
@ -1,3 +0,0 @@
|
||||
def choose_init():
|
||||
"""Returns 'none' because we are running in a container"""
|
||||
return 'none'
|
@ -1,35 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2015 <contact@redhat.com>
|
||||
#
|
||||
# Author: Alfredo Deza <adeza@redhat.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see `<http://www.gnu.org/licenses/>`.
|
||||
#
|
||||
|
||||
|
||||
class UnsupportedPlatform(Exception):
|
||||
"""Platform is not supported."""
|
||||
def __init__(self, distro, codename, release):
|
||||
self.distro = distro
|
||||
self.codename = codename
|
||||
self.release = release
|
||||
|
||||
def __str__(self):
|
||||
return '{doc}: {distro} {codename} {release}'.format(
|
||||
doc=self.__doc__.strip(),
|
||||
distro=self.distro,
|
||||
codename=self.codename,
|
||||
release=self.release,
|
||||
)
|
@ -1,13 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
if release and int(release.split('.')[0]) >= 22:
|
||||
return 'systemd'
|
||||
return 'sysvinit'
|
@ -1,11 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
return 'bsdrc'
|
@ -1,34 +0,0 @@
|
||||
import os
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
# From ceph-disk, but there is no way to access it since it's not in a module
|
||||
def is_systemd():
|
||||
"""
|
||||
Detect whether systemd is running;
|
||||
WARNING: not mutually exclusive with openrc
|
||||
"""
|
||||
with open('/proc/1/comm') as i:
|
||||
return 'systemd' in i.read()
|
||||
|
||||
|
||||
def is_openrc():
|
||||
"""
|
||||
Detect whether openrc is running.
|
||||
"""
|
||||
OPENRC_CGROUP = '/sys/fs/cgroup/openrc'
|
||||
return os.path.isdir(OPENRC_CGROUP)
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
if is_openrc():
|
||||
return 'openrc'
|
||||
if is_systemd():
|
||||
return 'systemd'
|
||||
return 'unknown'
|
@ -1,63 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2015 <contact@redhat.com>
|
||||
# Copyright (C) 2015 SUSE LINUX GmbH
|
||||
#
|
||||
# Author: Alfredo Deza <alfredo.deza@inktank.com>
|
||||
# Author: Owen Synge <osynge@suse.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Library Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Library Public License for more details.
|
||||
#
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import ceph_detect_init
|
||||
from ceph_detect_init import exc
|
||||
|
||||
|
||||
def parser():
|
||||
parser = argparse.ArgumentParser(
|
||||
'ceph-detect-init',
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
default=None,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--use-rhceph",
|
||||
action="store_true",
|
||||
default=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--default",
|
||||
default=None,
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def run(argv=None, namespace=None):
|
||||
args = parser().parse_args(argv, namespace)
|
||||
|
||||
if args.verbose:
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
||||
level=logging.DEBUG)
|
||||
try:
|
||||
print(ceph_detect_init.get(args.use_rhceph).init)
|
||||
except exc.UnsupportedPlatform:
|
||||
if args.default:
|
||||
print(args.default)
|
||||
else:
|
||||
raise
|
||||
|
||||
return 0
|
@ -1,11 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
return 'sysvinit'
|
@ -1,13 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
if release and int(release.split('.')[0]) >= 7:
|
||||
return 'systemd'
|
||||
return 'sysvinit'
|
@ -1,13 +0,0 @@
|
||||
distro = None
|
||||
release = None
|
||||
codename = None
|
||||
|
||||
|
||||
def choose_init():
|
||||
"""Select a init system
|
||||
|
||||
Returns the name of a init system (upstart, sysvinit ...).
|
||||
"""
|
||||
if release and int(release.split('.')[0]) >= 12:
|
||||
return 'systemd'
|
||||
return 'sysvinit'
|
@ -1,3 +0,0 @@
|
||||
FROM alpine:3.4
|
||||
|
||||
RUN apk --update add --no-cache py-pip py-virtualenv git bash
|
@ -1,4 +0,0 @@
|
||||
FROM centos:6
|
||||
|
||||
RUN yum install -y yum-utils && yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/6/x86_64/ && yum install --nogpgcheck -y epel-release && rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 && rm /etc/yum.repos.d/dl.fedoraproject.org*
|
||||
RUN yum install -y python-pip python-virtualenv git
|
@ -1,4 +0,0 @@
|
||||
FROM centos:7
|
||||
|
||||
RUN yum install -y yum-utils && yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/7/x86_64/ && yum install --nogpgcheck -y epel-release && rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 && rm /etc/yum.repos.d/dl.fedoraproject.org*
|
||||
RUN yum install -y python-pip python-virtualenv git
|
@ -1,6 +0,0 @@
|
||||
FROM debian:jessie
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y python-virtualenv python-pip git
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
FROM debian:sid
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y python-virtualenv python-pip git
|
@ -1,4 +0,0 @@
|
||||
FROM debian:squeeze
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y python-virtualenv python-pip git
|
@ -1,4 +0,0 @@
|
||||
FROM debian:wheezy
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y python-virtualenv python-pip git
|
@ -1,3 +0,0 @@
|
||||
FROM fedora:21
|
||||
|
||||
RUN yum install -y python-pip python-virtualenv git
|
@ -1,3 +0,0 @@
|
||||
FROM opensuse:13.1
|
||||
|
||||
RUN zypper --non-interactive --gpg-auto-import-keys install lsb python-pip python-virtualenv git
|
@ -1,3 +0,0 @@
|
||||
FROM opensuse:13.2
|
||||
|
||||
RUN zypper --non-interactive --gpg-auto-import-keys install python-pip python-virtualenv git
|
@ -1,97 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2015 SUSE LINUX GmbH
|
||||
# Copyright (C) 2015 <contact@redhat.com>
|
||||
#
|
||||
# Author: Owen Synge <osynge@suse.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Library Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Library Public License for more details.
|
||||
#
|
||||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
import testtools
|
||||
|
||||
from ceph_detect_init import main
|
||||
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
||||
level=logging.DEBUG)
|
||||
|
||||
|
||||
def run(os):
|
||||
name = 'ceph-detect-init-' + os
|
||||
shutil.rmtree(name, ignore_errors=True)
|
||||
script = """\
|
||||
docker build -t {name} --file integration/{os}.dockerfile .
|
||||
toplevel=$(git rev-parse --show-toplevel)
|
||||
mkdir {name}
|
||||
cat > {name}/try.sh <<EOF
|
||||
virtualenv {name}
|
||||
. {name}/bin/activate
|
||||
pip install -r requirements.txt
|
||||
python setup.py install
|
||||
ceph-detect-init > {name}/init
|
||||
EOF
|
||||
|
||||
docker run -v $toplevel:$toplevel -w $(pwd) --user $(id -u) {name} bash -x {name}/try.sh
|
||||
""".format(name=name,
|
||||
os=os)
|
||||
subprocess.check_call(script, shell=True)
|
||||
init = open(name + '/init').read().strip()
|
||||
shutil.rmtree(name)
|
||||
return init
|
||||
|
||||
|
||||
class TestCephDetectInit(testtools.TestCase):
|
||||
|
||||
def test_alpine_3_4(self):
|
||||
self.assertEqual('openrc', run('alpine-3.4'))
|
||||
|
||||
def test_centos_6(self):
|
||||
self.assertEqual('sysvinit', run('centos-6'))
|
||||
|
||||
def test_centos_7(self):
|
||||
self.assertEqual('sysvinit', run('centos-7'))
|
||||
|
||||
def test_ubuntu_12_04(self):
|
||||
self.assertEqual('upstart', run('ubuntu-12.04'))
|
||||
|
||||
def test_ubuntu_14_04(self):
|
||||
self.assertEqual('upstart', run('ubuntu-14.04'))
|
||||
|
||||
def test_ubuntu_15_04(self):
|
||||
self.assertEqual('upstart', run('ubuntu-15.04'))
|
||||
|
||||
def test_debian_squeeze(self):
|
||||
self.assertEqual('sysvinit', run('debian-squeeze'))
|
||||
|
||||
def test_debian_wheezy(self):
|
||||
self.assertEqual('sysvinit', run('debian-wheezy'))
|
||||
|
||||
def test_debian_jessie(self):
|
||||
self.assertEqual('sysvinit', run('debian-jessie'))
|
||||
|
||||
def test_debian_sid(self):
|
||||
self.assertEqual('sysvinit', run('debian-sid'))
|
||||
|
||||
def test_fedora_21(self):
|
||||
self.assertEqual('sysvinit', run('fedora-21'))
|
||||
|
||||
def test_opensuse_13_1(self):
|
||||
self.assertEqual('systemd', run('opensuse-13.1'))
|
||||
|
||||
def test_opensuse_13_2(self):
|
||||
self.assertEqual('systemd', run('opensuse-13.2'))
|
||||
|
||||
# Local Variables:
|
||||
# compile-command: "cd .. ; .tox/py27/bin/py.test integration/test_main.py"
|
||||
# End:
|
@ -1,4 +0,0 @@
|
||||
FROM ubuntu:12.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y python-virtualenv python-pip git
|
@ -1,6 +0,0 @@
|
||||
FROM ubuntu:14.04
|
||||
|
||||
RUN apt-get update
|
||||
# http://stackoverflow.com/questions/27341064/how-do-i-fix-importerror-cannot-import-name-incompleteread
|
||||
RUN apt-get install -y python-setuptools && easy_install -U pip
|
||||
RUN apt-get install -y python-virtualenv git
|
@ -1,4 +0,0 @@
|
||||
FROM ubuntu:15.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y python-pip python-virtualenv git
|
@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (C) 2015 SUSE LINUX GmbH
|
||||
# Copyright (C) 2016 <contact@redhat.com>
|
||||
#
|
||||
# Author: Owen Synge <osynge@suse.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Library Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Library Public License for more details.
|
||||
#
|
||||
|
||||
# run from the ceph-detect-init directory or from its parent
|
||||
: ${CEPH_DETECT_INIT_VIRTUALENV:=/tmp/ceph-detect-init-virtualenv}
|
||||
test -d ceph-detect-init && cd ceph-detect-init
|
||||
|
||||
if [ -e tox.ini ]; then
|
||||
TOX_PATH=`readlink -f tox.ini`
|
||||
else
|
||||
TOX_PATH=`readlink -f $(dirname $0)/tox.ini`
|
||||
fi
|
||||
|
||||
source ${CEPH_DETECT_INIT_VIRTUALENV}/bin/activate
|
||||
tox -c ${TOX_PATH}
|
@ -1,71 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2015 SUSE LINUX GmbH
|
||||
# Copyright (C) 2015 <contact@redhat.com>
|
||||
#
|
||||
# Author: Owen Synge <osynge@suse.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see `<http://www.gnu.org/licenses/>`.
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
from setuptools import setup
|
||||
from setuptools import find_packages
|
||||
|
||||
assert sys.version_info >= (2, 7), \
|
||||
"Python version lower than 2.7 is not supported"
|
||||
|
||||
def read(fname):
|
||||
path = os.path.join(os.path.dirname(__file__), fname)
|
||||
f = open(path)
|
||||
return f.read()
|
||||
|
||||
tests_require = read('test-requirements.txt').split()
|
||||
|
||||
setup(
|
||||
name='ceph-detect-init',
|
||||
version='1.0.1',
|
||||
packages=find_packages(),
|
||||
|
||||
author='Owen Synge, Loic Dachary',
|
||||
author_email='osynge@suse.de, loic@dachary.org',
|
||||
description='display the normalized name of the init system',
|
||||
long_description=read('README.rst'),
|
||||
license='LGPLv2+',
|
||||
keywords='ceph',
|
||||
url="https://git.ceph.com/?p=ceph.git;a=summary",
|
||||
|
||||
install_requires=['setuptools'],
|
||||
tests_require=tests_require,
|
||||
|
||||
classifiers=[
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: Information Technology',
|
||||
'Intended Audience :: System Administrators',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Topic :: Utilities',
|
||||
],
|
||||
|
||||
entry_points={
|
||||
|
||||
'console_scripts': [
|
||||
'ceph-detect-init = ceph_detect_init.main:run',
|
||||
],
|
||||
|
||||
},
|
||||
)
|
@ -1,10 +0,0 @@
|
||||
coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.14
|
||||
python-subunit
|
||||
testrepository>=0.0.17
|
||||
testtools>=0.9.32
|
||||
mock
|
||||
pytest
|
||||
tox
|
||||
flake8==3.0.4
|
@ -1,331 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2015 SUSE LINUX GmbH
|
||||
# Copyright (C) 2015 <contact@redhat.com>
|
||||
#
|
||||
# Author: Owen Synge <osynge@suse.com>
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see `<http://www.gnu.org/licenses/>`.
|
||||
#
|
||||
import logging
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
import ceph_detect_init
|
||||
from ceph_detect_init import alpine
|
||||
from ceph_detect_init import arch
|
||||
from ceph_detect_init import centos
|
||||
from ceph_detect_init import debian
|
||||
from ceph_detect_init import exc
|
||||
from ceph_detect_init import fedora
|
||||
from ceph_detect_init import main
|
||||
from ceph_detect_init import rhel
|
||||
from ceph_detect_init import suse
|
||||
from ceph_detect_init import gentoo
|
||||
from ceph_detect_init import freebsd
|
||||
from ceph_detect_init import docker
|
||||
from ceph_detect_init import oraclevms
|
||||
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
||||
level=logging.DEBUG)
|
||||
|
||||
|
||||
class TestCephDetectInit(testtools.TestCase):
|
||||
|
||||
def test_alpine(self):
|
||||
self.assertEqual('openrc', alpine.choose_init())
|
||||
|
||||
def test_arch(self):
|
||||
self.assertEqual('systemd', arch.choose_init())
|
||||
|
||||
def test_freebsd(self):
|
||||
self.assertEqual('bsdrc', freebsd.choose_init())
|
||||
|
||||
def test_docker(self):
|
||||
self.assertEqual('none', docker.choose_init())
|
||||
|
||||
def test_oraclevms(self):
|
||||
self.assertEqual('sysvinit', oraclevms.choose_init())
|
||||
|
||||
def test_centos(self):
|
||||
with mock.patch('ceph_detect_init.centos.release',
|
||||
'7.0'):
|
||||
self.assertEqual('systemd', centos.choose_init())
|
||||
self.assertEqual('sysvinit', centos.choose_init())
|
||||
|
||||
def test_debian(self):
|
||||
with mock.patch.multiple('os.path',
|
||||
isdir=lambda x: x == '/run/systemd/system'):
|
||||
self.assertEqual('systemd', debian.choose_init())
|
||||
|
||||
def mock_call_with_upstart(*args, **kwargs):
|
||||
if args[0] == '. /lib/lsb/init-functions ; init_is_upstart' and \
|
||||
kwargs['shell']:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
with mock.patch.multiple('os.path',
|
||||
isdir=lambda x: False,
|
||||
isfile=lambda x: False):
|
||||
with mock.patch.multiple('subprocess',
|
||||
call=mock_call_with_upstart):
|
||||
self.assertEqual('upstart', debian.choose_init())
|
||||
with mock.patch.multiple('os.path',
|
||||
isdir=lambda x: False,
|
||||
isfile=lambda x: x == '/sbin/init',
|
||||
islink=lambda x: x != '/sbin/init'):
|
||||
with mock.patch.multiple('subprocess',
|
||||
call=lambda *args, **kwargs: 1):
|
||||
self.assertEqual('sysvinit', debian.choose_init())
|
||||
with mock.patch.multiple('os.path',
|
||||
isdir=lambda x: False,
|
||||
isfile=lambda x: False):
|
||||
with mock.patch.multiple('subprocess',
|
||||
call=lambda *args, **kwargs: 1):
|
||||
self.assertIs(None, debian.choose_init())
|
||||
|
||||
def test_fedora(self):
|
||||
with mock.patch('ceph_detect_init.fedora.release',
|
||||
'22'):
|
||||
self.assertEqual('systemd', fedora.choose_init())
|
||||
self.assertEqual('sysvinit', fedora.choose_init())
|
||||
|
||||
def test_rhel(self):
|
||||
with mock.patch('ceph_detect_init.rhel.release',
|
||||
'7.0'):
|
||||
self.assertEqual('systemd', rhel.choose_init())
|
||||
self.assertEqual('sysvinit', rhel.choose_init())
|
||||
|
||||
def test_suse(self):
|
||||
with mock.patch('ceph_detect_init.suse.release',
|
||||
'11'):
|
||||
self.assertEqual('sysvinit', suse.choose_init())
|
||||
with mock.patch('ceph_detect_init.suse.release',
|
||||
'12'):
|
||||
self.assertEqual('systemd', suse.choose_init())
|
||||
with mock.patch('ceph_detect_init.suse.release',
|
||||
'13.1'):
|
||||
self.assertEqual('systemd', suse.choose_init())
|
||||
with mock.patch('ceph_detect_init.suse.release',
|
||||
'13.2'):
|
||||
self.assertEqual('systemd', suse.choose_init())
|
||||
|
||||
def test_gentoo_is_openrc(self):
|
||||
with mock.patch('os.path.isdir', return_value=True):
|
||||
self.assertEqual(gentoo.is_openrc(), True)
|
||||
with mock.patch('os.path.isdir', return_value=False):
|
||||
self.assertEqual(gentoo.is_openrc(), False)
|
||||
|
||||
def test_gentoo_is_systemd(self):
|
||||
import sys
|
||||
if sys.version_info >= (3, 0):
|
||||
mocked_fn = 'builtins.open'
|
||||
else:
|
||||
mocked_fn = '__builtin__.open'
|
||||
|
||||
f = mock.mock_open(read_data='systemd')
|
||||
with mock.patch(mocked_fn, f, create=True) as m:
|
||||
self.assertEqual(gentoo.is_systemd(), True)
|
||||
m.assert_called_once_with('/proc/1/comm')
|
||||
f = mock.mock_open(read_data='init')
|
||||
with mock.patch(mocked_fn, f, create=True) as m:
|
||||
self.assertEqual(gentoo.is_systemd(), False)
|
||||
m.assert_called_once_with('/proc/1/comm')
|
||||
f = mock.mock_open(read_data='upstart')
|
||||
with mock.patch(mocked_fn, f, create=True) as m:
|
||||
self.assertEqual(gentoo.is_systemd(), False)
|
||||
m.assert_called_once_with('/proc/1/comm')
|
||||
|
||||
def test_gentoo(self):
|
||||
with mock.patch.multiple('ceph_detect_init.gentoo',
|
||||
is_systemd=(lambda: True),
|
||||
is_openrc=(lambda: True)):
|
||||
self.assertEqual('openrc', gentoo.choose_init())
|
||||
with mock.patch.multiple('ceph_detect_init.gentoo',
|
||||
is_systemd=(lambda: True),
|
||||
is_openrc=(lambda: False)):
|
||||
self.assertEqual('systemd', gentoo.choose_init())
|
||||
with mock.patch.multiple('ceph_detect_init.gentoo',
|
||||
is_systemd=(lambda: False),
|
||||
is_openrc=(lambda: True)):
|
||||
self.assertEqual('openrc', gentoo.choose_init())
|
||||
with mock.patch.multiple('ceph_detect_init.gentoo',
|
||||
is_systemd=(lambda: False),
|
||||
is_openrc=(lambda: False)):
|
||||
self.assertEqual('unknown', gentoo.choose_init())
|
||||
|
||||
def test_get(self):
|
||||
with mock.patch.multiple(
|
||||
'platform',
|
||||
system=lambda: 'Linux',
|
||||
linux_distribution=lambda **kwargs: (('unknown', '', ''))):
|
||||
g = ceph_detect_init.get
|
||||
self.assertRaises(exc.UnsupportedPlatform, g)
|
||||
try:
|
||||
g()
|
||||
except exc.UnsupportedPlatform as e:
|
||||
self.assertIn('Platform is not supported', str(e))
|
||||
|
||||
with mock.patch.multiple(
|
||||
'platform',
|
||||
system=lambda: 'Linux',
|
||||
linux_distribution=lambda **kwargs: (('debian', '6.0', ''))):
|
||||
distro = ceph_detect_init.get()
|
||||
self.assertEqual(debian, distro)
|
||||
self.assertEqual('debian', distro.name)
|
||||
self.assertEqual('debian', distro.normalized_name)
|
||||
self.assertEqual('debian', distro.distro)
|
||||
self.assertEqual(False, distro.is_el)
|
||||
self.assertEqual('6.0', distro.release)
|
||||
|
||||
with mock.patch.multiple('platform',
|
||||
system=lambda: 'FreeBSD',
|
||||
release=lambda: '12.0-CURRENT',
|
||||
version=lambda: 'FreeBSD 12.0 #1 r306554M:'):
|
||||
distro = ceph_detect_init.get()
|
||||
self.assertEqual(freebsd, distro)
|
||||
self.assertEqual('freebsd', distro.name)
|
||||
self.assertEqual('freebsd', distro.normalized_name)
|
||||
self.assertEqual('freebsd', distro.distro)
|
||||
self.assertFalse(distro.is_el)
|
||||
self.assertEqual('12.0-CURRENT', distro.release)
|
||||
self.assertEqual('r306554M', distro.codename)
|
||||
self.assertEqual('bsdrc', distro.init)
|
||||
|
||||
with mock.patch('platform.system',
|
||||
lambda: 'cephix'):
|
||||
self.assertRaises(exc.UnsupportedPlatform, ceph_detect_init.get)
|
||||
|
||||
def test_get_distro(self):
|
||||
g = ceph_detect_init._get_distro
|
||||
self.assertEqual(None, g(None))
|
||||
self.assertEqual(debian, g('debian'))
|
||||
self.assertEqual(debian, g('ubuntu'))
|
||||
self.assertEqual(centos, g('centos'))
|
||||
self.assertEqual(centos, g('scientific'))
|
||||
self.assertEqual(centos, g('Oracle Linux Server'))
|
||||
self.assertEqual(oraclevms, g('Oracle VM server'))
|
||||
self.assertEqual(fedora, g('fedora'))
|
||||
self.assertEqual(suse, g('suse'))
|
||||
self.assertEqual(rhel, g('redhat', use_rhceph=True))
|
||||
self.assertEqual(gentoo, g('gentoo'))
|
||||
self.assertEqual(centos, g('virtuozzo'))
|
||||
|
||||
def test_normalized_distro_name(self):
|
||||
n = ceph_detect_init._normalized_distro_name
|
||||
self.assertEqual('redhat', n('RedHat'))
|
||||
self.assertEqual('redhat', n('redhat'))
|
||||
self.assertEqual('redhat', n('Red Hat'))
|
||||
self.assertEqual('redhat', n('red hat'))
|
||||
self.assertEqual('scientific', n('scientific'))
|
||||
self.assertEqual('scientific', n('Scientific'))
|
||||
self.assertEqual('scientific', n('Scientific Linux'))
|
||||
self.assertEqual('scientific', n('scientific linux'))
|
||||
self.assertEqual('oraclel', n('Oracle Linux Server'))
|
||||
self.assertEqual('oraclevms', n('Oracle VM server'))
|
||||
self.assertEqual('suse', n('SUSE'))
|
||||
self.assertEqual('suse', n('suse'))
|
||||
self.assertEqual('suse', n('openSUSE'))
|
||||
self.assertEqual('suse', n('opensuse'))
|
||||
self.assertEqual('centos', n('CentOS'))
|
||||
self.assertEqual('centos', n('centos'))
|
||||
self.assertEqual('debian', n('Debian'))
|
||||
self.assertEqual('debian', n('debian'))
|
||||
self.assertEqual('ubuntu', n('Ubuntu'))
|
||||
self.assertEqual('ubuntu', n('ubuntu'))
|
||||
self.assertEqual('gentoo', n('Gentoo'))
|
||||
self.assertEqual('gentoo', n('gentoo'))
|
||||
self.assertEqual('gentoo', n('Funtoo'))
|
||||
self.assertEqual('gentoo', n('funtoo'))
|
||||
self.assertEqual('gentoo', n('Exherbo'))
|
||||
self.assertEqual('gentoo', n('exherbo'))
|
||||
self.assertEqual('virtuozzo', n('Virtuozzo Linux'))
|
||||
|
||||
@mock.patch('platform.system', lambda: 'Linux')
|
||||
def test_platform_information_linux(self):
|
||||
with mock.patch('platform.linux_distribution',
|
||||
lambda **kwargs: (('debian', '8.0', ''))):
|
||||
self.assertEqual(('debian', '8.0'),
|
||||
ceph_detect_init.platform_information()[:-1])
|
||||
|
||||
with mock.patch('platform.linux_distribution',
|
||||
lambda **kwargs: (('Oracle Linux Server', '7.3', ''))):
|
||||
self.assertEqual(('Oracle Linux Server', '7.3', 'OL7.3'),
|
||||
ceph_detect_init.platform_information())
|
||||
|
||||
with mock.patch('platform.linux_distribution',
|
||||
lambda **kwargs: (('Oracle VM server', '3.4.2', ''))):
|
||||
self.assertEqual(('Oracle VM server', '3.4.2', 'OVS3.4.2'),
|
||||
ceph_detect_init.platform_information())
|
||||
|
||||
with mock.patch('platform.linux_distribution',
|
||||
lambda **kwargs: (('Virtuozzo Linux', '7.3', ''))):
|
||||
self.assertEqual(('Virtuozzo Linux', '7.3', 'virtuozzo'),
|
||||
ceph_detect_init.platform_information())
|
||||
|
||||
@mock.patch('platform.linux_distribution')
|
||||
def test_platform_information_container(self, mock_linux_dist):
|
||||
import sys
|
||||
if sys.version_info >= (3, 0):
|
||||
mocked_fn = 'builtins.open'
|
||||
else:
|
||||
mocked_fn = '__builtin__.open'
|
||||
|
||||
with mock.patch(mocked_fn,
|
||||
mock.mock_open(read_data="""1:name=systemd:/system.slice \
|
||||
/docker-39cc1fb.scope"""),
|
||||
create=True) as m:
|
||||
self.assertEqual(('docker',
|
||||
'docker',
|
||||
'docker'),
|
||||
ceph_detect_init.platform_information(),)
|
||||
m.assert_called_once_with('/proc/self/cgroup', 'r')
|
||||
|
||||
with mock.patch(mocked_fn, mock.mock_open(), create=True) as m:
|
||||
m.side_effect = IOError()
|
||||
mock_linux_dist.return_value = ('Red Hat Enterprise Linux Server',
|
||||
'7.3', 'Maipo')
|
||||
# Just run the code to validate the code won't raise IOError
|
||||
ceph_detect_init.platform_information()
|
||||
|
||||
with mock.patch('os.path.isfile', mock.MagicMock()) as m:
|
||||
m.return_value = True
|
||||
self.assertEqual(('docker',
|
||||
'docker',
|
||||
'docker'),
|
||||
ceph_detect_init.platform_information(),)
|
||||
m.assert_called_once_with('/.dockerenv')
|
||||
|
||||
@mock.patch('platform.system', lambda: 'FreeBSD')
|
||||
def test_platform_information_freebsd(self):
|
||||
with mock.patch.multiple('platform',
|
||||
release=lambda: '12.0-CURRENT',
|
||||
version=lambda: 'FreeBSD 12.0 #1 r306554M:'):
|
||||
self.assertEqual(('freebsd', '12.0-CURRENT', 'r306554M'),
|
||||
ceph_detect_init.platform_information())
|
||||
|
||||
def test_run(self):
|
||||
argv = ['--use-rhceph', '--verbose']
|
||||
self.assertEqual(0, main.run(argv))
|
||||
|
||||
with mock.patch.multiple(
|
||||
'platform',
|
||||
system=lambda: 'Linux',
|
||||
linux_distribution=lambda **kwargs: (('unknown', '', ''))):
|
||||
self.assertRaises(exc.UnsupportedPlatform, main.run, argv)
|
||||
self.assertEqual(0, main.run(argv + ['--default=sysvinit']))
|
||||
|
||||
# Local Variables:
|
||||
# compile-command: "cd .. ; .tox/py27/bin/py.test tests/test_all.py"
|
||||
# End:
|
@ -1,30 +0,0 @@
|
||||
[tox]
|
||||
envlist = pep8,py27,py3
|
||||
skip_missing_interpreters = True
|
||||
|
||||
[testenv]
|
||||
basepython =
|
||||
py27: python2.7
|
||||
py3: python3
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
usedevelop = true
|
||||
deps =
|
||||
{env:NO_INDEX:}
|
||||
--find-links=file://{toxinidir}/wheelhouse
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
|
||||
commands = coverage run --source=ceph_detect_init {envbindir}/py.test -v tests
|
||||
coverage report --show-missing --fail-under=100
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python2
|
||||
commands = flake8 ceph_detect_init tests
|
||||
|
||||
[testenv:integration]
|
||||
basepython = python2
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
|
||||
commands = {envbindir}/py.test -v integration/test_main.py
|
Loading…
Reference in New Issue
Block a user