2020-06-22 22:27:08 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2017-02-23 07:41:38 +01:00
|
|
|
|
2018-10-13 05:01:14 +02:00
|
|
|
from units.compat import unittest
|
2020-05-14 04:14:53 +02:00
|
|
|
from ansible.modules.systemd import parse_systemctl_show
|
2017-02-23 07:41:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ParseSystemctlShowTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
lines = [
|
|
|
|
'Type=simple',
|
|
|
|
'Restart=no',
|
|
|
|
'Requires=system.slice sysinit.target',
|
|
|
|
'Description=Blah blah blah',
|
|
|
|
]
|
|
|
|
parsed = parse_systemctl_show(lines)
|
|
|
|
self.assertEqual(parsed, {
|
|
|
|
'Type': 'simple',
|
|
|
|
'Restart': 'no',
|
|
|
|
'Requires': 'system.slice sysinit.target',
|
|
|
|
'Description': 'Blah blah blah',
|
|
|
|
})
|
|
|
|
|
|
|
|
def test_multiline_exec(self):
|
|
|
|
# This was taken from a real service that specified "ExecStart=/bin/echo foo\nbar"
|
|
|
|
lines = [
|
|
|
|
'Type=simple',
|
|
|
|
'ExecStart={ path=/bin/echo ; argv[]=/bin/echo foo',
|
|
|
|
'bar ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }',
|
|
|
|
'Description=blah',
|
|
|
|
]
|
|
|
|
parsed = parse_systemctl_show(lines)
|
|
|
|
self.assertEqual(parsed, {
|
|
|
|
'Type': 'simple',
|
2017-04-28 00:51:44 +02:00
|
|
|
'ExecStart': '{ path=/bin/echo ; argv[]=/bin/echo foo\n'
|
|
|
|
'bar ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }',
|
2017-02-23 07:41:38 +01:00
|
|
|
'Description': 'blah',
|
|
|
|
})
|
|
|
|
|
|
|
|
def test_single_line_with_brace(self):
|
|
|
|
lines = [
|
|
|
|
'Type=simple',
|
|
|
|
'Description={ this is confusing',
|
|
|
|
'Restart=no',
|
|
|
|
]
|
|
|
|
parsed = parse_systemctl_show(lines)
|
|
|
|
self.assertEqual(parsed, {
|
|
|
|
'Type': 'simple',
|
|
|
|
'Description': '{ this is confusing',
|
|
|
|
'Restart': 'no',
|
|
|
|
})
|