summaryrefslogtreecommitdiff
path: root/test/sysv-generator-test.py
diff options
context:
space:
mode:
authorLukas Nykryn <lnykryn@redhat.com>2016-01-20 15:16:32 +0100
committerLukas Nykryn <lnykryn@redhat.com>2016-01-21 12:53:14 +0100
commitc584ffc0b75d4b9e9229bf1d8edb7d89562be3c1 (patch)
tree8371dcfe3dccac9941ebbafb99c686b63e44db85 /test/sysv-generator-test.py
parent91c4b6db7840e68e4d7a019c3cb4d5d60d2a65c7 (diff)
sysv-generator: do not join dependencies on one line, split them
If there is a lot of initscripts and dependencies between them we might end generating After= (and similar) lines which are longer then LINE_MAX and thus rejected by parser in systemd. Fixes #2099
Diffstat (limited to 'test/sysv-generator-test.py')
-rw-r--r--test/sysv-generator-test.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py
index 721e53a4ee..aca5f1eec6 100644
--- a/test/sysv-generator-test.py
+++ b/test/sysv-generator-test.py
@@ -23,6 +23,7 @@ import subprocess
import tempfile
import shutil
from glob import glob
+import collections
try:
from configparser import RawConfigParser
@@ -32,6 +33,12 @@ except ImportError:
sysv_generator = os.path.join(os.environ.get('builddir', '.'), 'systemd-sysv-generator')
+class MultiDict(collections.OrderedDict):
+ def __setitem__(self, key, value):
+ if isinstance(value, list) and key in self:
+ self[key].extend(value)
+ else:
+ super(MultiDict, self).__setitem__(key, value)
class SysvGeneratorTest(unittest.TestCase):
def setUp(self):
@@ -77,7 +84,14 @@ class SysvGeneratorTest(unittest.TestCase):
for service in glob(self.out_dir + '/*.service'):
if os.path.islink(service):
continue
- cp = RawConfigParser()
+ try:
+ # for python3 we need here strict=False to parse multiple
+ # lines with the same key
+ cp = RawConfigParser(dict_type=MultiDict, strict=False)
+ except TypeError:
+ # RawConfigParser in python2 does not have the strict option
+ # but it allows multiple lines with the same key by default
+ cp = RawConfigParser(dict_type=MultiDict)
cp.optionxform = lambda o: o # don't lower-case option names
with open(service) as f:
cp.readfp(f)
@@ -224,7 +238,7 @@ class SysvGeneratorTest(unittest.TestCase):
s = self.run_generator()[1]['foo.service']
self.assertEqual(set(s.options('Unit')),
set(['Documentation', 'SourcePath', 'Description', 'After']))
- self.assertEqual(s.get('Unit', 'After'), 'nss-lookup.target rpcbind.target')
+ self.assertEqual(s.get('Unit', 'After').split(), ['nss-lookup.target', 'rpcbind.target'])
def test_lsb_deps(self):
'''LSB header dependencies to other services'''