X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fceph-detect-init%2Fintegration%2Ftest_main.py;fp=src%2Fceph%2Fsrc%2Fceph-detect-init%2Fintegration%2Ftest_main.py;h=c5b6a20e5ecc11d22086288c4318f04a83532fdd;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/ceph-detect-init/integration/test_main.py b/src/ceph/src/ceph-detect-init/integration/test_main.py new file mode 100644 index 0000000..c5b6a20 --- /dev/null +++ b/src/ceph/src/ceph-detect-init/integration/test_main.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# +# Copyright (C) 2015 SUSE LINUX GmbH +# Copyright (C) 2015 +# +# Author: Owen Synge +# Author: Loic Dachary +# +# 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 < {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: