File: test_systemd.py

package info (click to toggle)
ansible-core 2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 32,752 kB
  • sloc: python: 181,000; cs: 4,929; sh: 4,611; xml: 34; makefile: 21
file content (51 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations

import unittest
from ansible.modules.systemd import parse_systemctl_show


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',
            '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 }',
            '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',
        })