Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-detect-init / integration / test_main.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2015 SUSE LINUX GmbH
4 # Copyright (C) 2015 <contact@redhat.com>
5 #
6 # Author: Owen Synge <osynge@suse.com>
7 # Author: Loic Dachary <loic@dachary.org>
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU Library Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU Library Public License for more details.
18 #
19 import logging
20 import shutil
21 import subprocess
22 import testtools
23
24 from ceph_detect_init import main
25
26 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
27                     level=logging.DEBUG)
28
29
30 def run(os):
31     name = 'ceph-detect-init-' + os
32     shutil.rmtree(name, ignore_errors=True)
33     script = """\
34 docker build -t {name} --file integration/{os}.dockerfile .
35 toplevel=$(git rev-parse --show-toplevel)
36 mkdir {name}
37 cat > {name}/try.sh <<EOF
38   virtualenv {name}
39   . {name}/bin/activate
40   pip install -r requirements.txt
41   python setup.py install
42   ceph-detect-init > {name}/init
43 EOF
44
45 docker run -v $toplevel:$toplevel -w $(pwd) --user $(id -u) {name} bash -x {name}/try.sh
46 """.format(name=name,
47            os=os)
48     subprocess.check_call(script, shell=True)
49     init = open(name + '/init').read().strip()
50     shutil.rmtree(name)
51     return init
52
53
54 class TestCephDetectInit(testtools.TestCase):
55
56     def test_alpine_3_4(self):
57         self.assertEqual('openrc', run('alpine-3.4'))
58
59     def test_centos_6(self):
60         self.assertEqual('sysvinit', run('centos-6'))
61
62     def test_centos_7(self):
63         self.assertEqual('sysvinit', run('centos-7'))
64
65     def test_ubuntu_12_04(self):
66         self.assertEqual('upstart', run('ubuntu-12.04'))
67
68     def test_ubuntu_14_04(self):
69         self.assertEqual('upstart', run('ubuntu-14.04'))
70
71     def test_ubuntu_15_04(self):
72         self.assertEqual('upstart', run('ubuntu-15.04'))
73
74     def test_debian_squeeze(self):
75         self.assertEqual('sysvinit', run('debian-squeeze'))
76
77     def test_debian_wheezy(self):
78         self.assertEqual('sysvinit', run('debian-wheezy'))
79
80     def test_debian_jessie(self):
81         self.assertEqual('sysvinit', run('debian-jessie'))
82
83     def test_debian_sid(self):
84         self.assertEqual('sysvinit', run('debian-sid'))
85
86     def test_fedora_21(self):
87         self.assertEqual('sysvinit', run('fedora-21'))
88
89     def test_opensuse_13_1(self):
90         self.assertEqual('systemd', run('opensuse-13.1'))
91
92     def test_opensuse_13_2(self):
93         self.assertEqual('systemd', run('opensuse-13.2'))
94
95 # Local Variables:
96 # compile-command: "cd .. ; .tox/py27/bin/py.test integration/test_main.py"
97 # End: