Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / tests / test_systemd.aug
1 (*
2 Module: Test_Systemd
3   Provides unit tests and examples for the <Systemd> lens.
4 *)
5
6 module Test_Systemd =
7
8 (* Variable: desc *)
9 let desc = "[Unit]
10 Description=RPC
11 Description=RPC bind service
12 Description=RPC bind\\
13 service
14 Description= Resets System Activity Logs
15 "
16 (* Test: Systemd.lns *)
17 test Systemd.lns get desc =
18   { "Unit"
19     { "Description"
20       { "value" = "RPC" }
21     }
22     { "Description"
23       { "value" = "RPC bind service" }
24     }
25     { "Description"
26       { "value" = "RPC bind\
27 service" }
28     }
29     { "Description"
30       { "value" = "Resets System Activity Logs" }
31     }
32   }
33
34 (* Variable: multi *)
35 let multi = "[Unit]
36 After=syslog.target network.target
37 Also=canberra-system-shutdown.service canberra-system-shutdown-reboot.service
38 Before=sysinit.target shutdown.target
39 CapabilityBoundingSet=CAP_SYS_ADMIN CAP_SETUID CAP_SETGID
40 Conflicts=emergency.service emergency.target
41 ControlGroup=%R/user/%I/shared cpu:/
42 ListenNetlink=kobject-uevent 1
43 Requires=shutdown.target umount.target final.target
44 Sockets=udev-control.socket udev-kernel.socket
45 WantedBy=halt.target poweroff.target
46 Wants=local-fs.target swap.target
47 Wants=local-fs.target \
48 swap.target
49 Wants=local-fs.target\
50 swap.target
51 Wants= local-fs.target
52 "
53 (* Test: Systemd.lns *)
54 test Systemd.lns get multi =
55   { "Unit"
56     { "After"
57       { "value" = "syslog.target" }
58       { "value" = "network.target" }
59     }
60     { "Also"
61       { "value" = "canberra-system-shutdown.service" }
62       { "value" = "canberra-system-shutdown-reboot.service" }
63     }
64     { "Before"
65       { "value" = "sysinit.target" }
66       { "value" = "shutdown.target" }
67     }
68     { "CapabilityBoundingSet"
69       { "value" = "CAP_SYS_ADMIN" }
70       { "value" = "CAP_SETUID" }
71       { "value" = "CAP_SETGID" }
72     }
73     { "Conflicts"
74       { "value" = "emergency.service" }
75       { "value" = "emergency.target" }
76     }
77     { "ControlGroup"
78       { "value" = "%R/user/%I/shared" }
79       { "value" = "cpu:/" }
80     }
81     { "ListenNetlink"
82       { "value" = "kobject-uevent" }
83       { "value" = "1" }
84     }
85     { "Requires"
86       { "value" = "shutdown.target" }
87       { "value" = "umount.target" }
88       { "value" = "final.target" }
89     }
90     { "Sockets"
91       { "value" = "udev-control.socket" }
92       { "value" = "udev-kernel.socket" }
93     }
94     { "WantedBy"
95       { "value" = "halt.target" }
96       { "value" = "poweroff.target" }
97     }
98     { "Wants"
99       { "value" = "local-fs.target" }
100       { "value" = "swap.target" }
101     }
102     { "Wants"
103       { "value" = "local-fs.target" }
104       { "value" = "swap.target" }
105     }
106     { "Wants"
107       { "value" = "local-fs.target" }
108       { "value" = "swap.target" }
109     }
110     { "Wants"
111       { "value" = "local-fs.target" }
112     }
113   }
114
115 (* Variable: exec *)
116 let exec = "[Service]
117 ExecStart=/bin/ls
118 ExecReload=/bin/kill -USR1 $MAINPID
119 ExecStart=/sbin/rpcbind -w
120 ExecStartPost=/bin/systemctl disable firstboot-graphical.service firstboot-text.service
121 ExecStartPre=/sbin/modprobe -qa $SUPPORTED_DRIVERS
122 ExecStop=/usr/sbin/aiccu stop
123 ExecStopPost=-/bin/systemctl poweroff
124 ExecStopPost=@/bin/systemctl poweroff
125 ExecStopPost=-@/bin/systemctl poweroff
126 ExecStopPost=/bin/systemctl\
127 poweroff
128 "
129 (* Test: Systemd.lns *)
130 test Systemd.lns get exec =
131   { "Service"
132     { "ExecStart"
133       { "command" = "/bin/ls" }
134     }
135     { "ExecReload"
136       { "command" = "/bin/kill" }
137       { "arguments"
138         { "1" = "-USR1" }
139         { "2" = "$MAINPID" }
140       }
141     }
142     { "ExecStart"
143       { "command" = "/sbin/rpcbind" }
144       { "arguments"
145         { "1" = "-w" }
146       }
147     }
148     { "ExecStartPost"
149       { "command" = "/bin/systemctl" }
150       { "arguments"
151         { "1" = "disable" }
152         { "2" = "firstboot-graphical.service" }
153         { "3" = "firstboot-text.service" }
154       }
155     }
156     { "ExecStartPre"
157       { "command" = "/sbin/modprobe" }
158       { "arguments"
159         { "1" = "-qa" }
160         { "2" = "$SUPPORTED_DRIVERS" }
161       }
162     }
163     { "ExecStop"
164       { "command" = "/usr/sbin/aiccu" }
165       { "arguments"
166         { "1" = "stop" }
167       }
168     }
169     { "ExecStopPost"
170       { "ignoreexit" }
171       { "command" = "/bin/systemctl" }
172       { "arguments"
173         { "1" = "poweroff" }
174       }
175     }
176     { "ExecStopPost"
177       { "arg0" }
178       { "command" = "/bin/systemctl" }
179       { "arguments"
180         { "1" = "poweroff" }
181       }
182     }
183     { "ExecStopPost"
184       { "ignoreexit" }
185       { "arg0" }
186       { "command" = "/bin/systemctl" }
187       { "arguments"
188         { "1" = "poweroff" }
189       }
190     }
191     { "ExecStopPost"
192       { "command" = "/bin/systemctl" }
193       { "arguments"
194         { "1" = "poweroff" }
195       }
196     }
197   }
198
199 (* Variable: env *)
200 let env = "[Service]
201 Environment=LANG=C
202 Environment=LANG=C FOO=BAR
203 Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
204 Environment=LANG=C\
205 FOO=BAR
206 Environment=\"LANG=foo bar\" FOO=BAR
207 Environment=OPTIONS=\"-LS0-6d\"
208 Environment=OPTIONS='-LS0-6d'
209 Environment=VAR=\"with some spaces\" VAR2='more spaces'
210 Environment=VAR='with some spaces'
211 "
212 (* Test: Systemd.lns *)
213 test Systemd.lns get env =
214   { "Service"
215     { "Environment"
216       { "LANG" = "C" }
217     }
218     { "Environment"
219       { "LANG" = "C" }
220       { "FOO" = "BAR" }
221     }
222     { "Environment"
223       { "LANG" }
224       { "LANGUAGE" }
225       { "LC_CTYPE" }
226       { "LC_NUMERIC" }
227       { "LC_TIME" }
228       { "LC_COLLATE" }
229       { "LC_MONETARY" }
230       { "LC_MESSAGES" }
231       { "LC_PAPER" }
232       { "LC_NAME" }
233       { "LC_ADDRESS" }
234       { "LC_TELEPHONE" }
235       { "LC_MEASUREMENT" }
236       { "LC_IDENTIFICATION" }
237     }
238     { "Environment"
239       { "LANG" = "C" }
240       { "FOO" = "BAR" }
241     }
242     { "Environment"
243       { "LANG" = "foo bar" }
244       { "FOO" = "BAR" }
245     }
246     { "Environment"
247       { "OPTIONS" = "\"-LS0-6d\"" }
248     }
249     { "Environment"
250       { "OPTIONS" = "'-LS0-6d'" }
251     }
252     { "Environment"
253       { "VAR" = "\"with some spaces\"" }
254       { "VAR2" = "'more spaces'" }
255     }
256     { "Environment"
257       { "VAR" = "'with some spaces'" }
258     }
259   }
260
261 (* Variable: unit *)
262 let unit = "#  This file is part of systemd.
263 #
264
265 # See systemd.special(7) for details
266
267 .include /etc/example
268
269 [Unit]
270 Description=Locale Service
271 # Add another file
272 .include /etc/example
273
274 [Service]
275 ExecStart=/lib/systemd/systemd-localed
276 Type=dbus
277 BusName=org.freedesktop.locale1
278 CapabilityBoundingSet=
279
280 "
281 (* Test: Systemd.lns *)
282 test Systemd.lns get unit =
283   { "#comment" = "This file is part of systemd." }
284   {}
285   {  }
286   { "#comment" = "See systemd.special(7) for details" }
287   {  }
288   { ".include" = "/etc/example" }
289   {  }
290   { "Unit"
291     { "Description"
292       { "value" = "Locale Service" }
293     }
294     { "#comment" = "Add another file" }
295     { ".include" = "/etc/example" }
296     {  }
297   }
298   { "Service"
299     { "ExecStart"
300       { "command" = "/lib/systemd/systemd-localed" }
301     }
302     { "Type"
303       { "value" = "dbus" }
304     }
305     { "BusName"
306       { "value" = "org.freedesktop.locale1" }
307     }
308     { "CapabilityBoundingSet" }
309     {  }
310   }
311
312 (* Test: Systemd.lns
313      Values can contain backslashes *)
314 test Systemd.entry_command get "ExecStart=/usr/bin/find /var/lib/sudo -exec /usr/bin/touch -t 198501010000 '{}' \073\n" =
315   { "ExecStart"
316     { "command" = "/usr/bin/find" }
317     { "arguments"
318       { "1" = "/var/lib/sudo" }
319       { "2" = "-exec" }
320       { "3" = "/usr/bin/touch" }
321       { "4" = "-t" }
322       { "5" = "198501010000" }
323       { "6" = "'{}'" }
324       { "7" = "\073" }
325     }
326   }
327
328 let exec_tmux = "ExecStart=/usr/bin/tmux unbind-key -a; \
329                         kill-window -t anaconda:shell; \
330                         bind-key ? list-keys\n"
331
332 (* Test: Systemd.lns
333      Semicolons are permitted in entry values, e.g. as part of a command *)
334 test Systemd.entry_command get exec_tmux =
335   { "ExecStart"
336     { "command" = "/usr/bin/tmux" }
337     { "arguments"
338       { "1" = "unbind-key" }
339       { "2" = "-a;" }
340       { "3" = "kill-window" }
341       { "4" = "-t" }
342       { "5" = "anaconda:shell;" }
343       { "6" = "bind-key" }
344       { "7" = "?" }
345       { "8" = "list-keys" } } }
346
347 (* Test: Systemd.lns
348      # and ; are OK for standalone comments, but # only for EOL comments *)
349 test Systemd.lns get "[Service]\n# hash\n; semicolon\nExecStart=/bin/echo # hash\n" =
350   { "Service"
351     { "#comment" = "hash" }
352     { "#comment" = "semicolon" }
353     { "ExecStart"
354       { "command" = "/bin/echo" }
355       { "#comment" = "hash" } } }
356
357 (* Test: Systemd.lns
358      empty quoted environment var values *)
359 test Systemd.lns get "[Service]\nEnvironment=TERM=linux PX_MODULE_PATH=\"\"\n" =
360   { "Service"
361     { "Environment"
362       { "TERM" = "linux" }
363       { "PX_MODULE_PATH" = "\"\"" } } }
364
365 (* Test: Systemd.lns
366      values may start with spaces *)
367 test Systemd.lns get "[Service]\nExecStart= /usr/bin/find\nEnvironment=  TERM=linux\n" =
368   { "Service"
369     { "ExecStart"
370       { "command" = "/usr/bin/find" } }
371     { "Environment"
372       { "TERM" = "linux" } } }