sysv-generator-test.py revision 56401ac57a543395d06690768e63b92633ad15dd
# systemd-sysv-generator integration test
#
# (C) 2015 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
#
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# systemd 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
import unittest
import sys
import os
import subprocess
import tempfile
import shutil
try:
from configparser import RawConfigParser
except ImportError:
# python 2
from ConfigParser import RawConfigParser
#
# Helper methods
#
'''Run sysv-generator.
Fail if stderr contains any "Fail", unless expect_error is True.
Return (stderr, filename -> ConfigParser) pair with ouput to stderr and
parsed generated units.
'''
if not expect_error:
results = {}
continue
cp = RawConfigParser()
'''Create a SysV init script with the given keys in the LSB header
There are sensible default values for all fields.
If enable is True, links will be created in the rcN.d dirs. In that
case, the priority can be given with "prio" (default to 1).
Return path of generated script.
'''
f.write('#!/bin/init-d-interpreter\n### BEGIN INIT INFO\n')
if v is not None:
f.write('### END INIT INFO\ncode --goes here\n')
if enable:
return script
'''assert that a unit is enabled in precisely the given runlevels'''
# should be enabled
for runlevel in all_runlevels:
else:
'%s unexpectedly exists' % link)
#
# test cases
#
def test_nothing(self):
'''no input files'''
def test_simple_disabled(self):
'''simple service without dependencies, disabled'''
# no enablement links or other stuff
s = results['foo.service']
# $local_fs does not need translation, don't expect any dependency
# fields here
'%s start' % init_script)
'%s stop' % init_script)
def test_simple_enabled_all(self):
'''simple service without dependencies, enabled in all runlevels'''
def test_simple_enabled_some(self):
'''simple service without dependencies, enabled in some runlevels'''
'''single LSB macro dependency: $network'''
def test_lsb_macro_dep_multi(self):
'''multiple LSB macro dependencies'''
def test_lsb_deps(self):
'''LSB header dependencies to other services'''
# also give symlink priorities here; they should be ignored
'Should-Start': 'may1 ne_may2'},
# do not create ne_may2
['foo.service', 'may1.service', 'must1.service', 'must2.service'])
# foo should depend on all of them
['may1.service', 'must1.service', 'must2.service', 'ne_may2.service'])
# other services should not depend on each other
def test_symlink_prio_deps(self):
'''script without LSB headers use rcN.d priority'''
# create two init.d scripts without LSB header and enable them with
# startup priorities
f.write('#!/bin/init-d-interpreter\ncode --goes here\n')
'provider.service')
def test_multiple_provides(self):
'''multiple Provides: names'''
# should create symlinks for the alternative names
for f in ['bar.service', 'baz.service']:
'foo.service')
'''ignores non-executable init.d script'''
if __name__ == '__main__':