augeas 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +510 -0
- data/NEWS +41 -0
- data/README.rdoc +86 -0
- data/Rakefile +96 -0
- data/ext/augeas/_augeas.c +646 -0
- data/ext/augeas/_augeas.h +48 -0
- data/ext/augeas/extconf.rb +46 -0
- data/lib/augeas.rb +383 -0
- data/tests/root/etc/group +26 -0
- data/tests/root/etc/hosts +6 -0
- data/tests/root/etc/inittab +53 -0
- data/tests/root/etc/ssh/sshd_config +2 -0
- data/tests/tc_augeas.rb +666 -0
- metadata +88 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
root:x:0:root
|
2
|
+
bin:x:1:root,bin,daemon
|
3
|
+
daemon:x:2:root,bin,daemon
|
4
|
+
sys:x:3:root,bin,adm
|
5
|
+
adm:x:4:root,adm,daemon
|
6
|
+
tty:x:5:
|
7
|
+
disk:x:6:root
|
8
|
+
lp:x:7:daemon,lp
|
9
|
+
mem:x:8:
|
10
|
+
kmem:x:9:
|
11
|
+
wheel:x:10:root
|
12
|
+
mail:x:12:mail,postfix
|
13
|
+
uucp:x:14:uucp
|
14
|
+
man:x:15:
|
15
|
+
games:x:20:
|
16
|
+
gopher:x:30:
|
17
|
+
dip:x:40:
|
18
|
+
ftp:x:50:
|
19
|
+
lock:x:54:
|
20
|
+
nobody:x:99:
|
21
|
+
users:x:100:
|
22
|
+
floppy:x:19:
|
23
|
+
vcsa:x:69:
|
24
|
+
rpc:x:32:asfd
|
25
|
+
rpcuser:x:29:
|
26
|
+
nfsnobody:x:499:
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# Do not remove the following line, or various programs
|
2
|
+
# that require network functionality will fail.
|
3
|
+
127.0.0.1 localhost.localdomain localhost galia.watzmann.net galia
|
4
|
+
#172.31.122.254 granny.watzmann.net granny puppet
|
5
|
+
#172.31.122.1 galia.watzmann.net galia
|
6
|
+
172.31.122.14 orange.watzmann.net orange
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# inittab This file describes how the INIT process should set up
|
3
|
+
# the system in a certain run-level.
|
4
|
+
#
|
5
|
+
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
|
6
|
+
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
|
7
|
+
#
|
8
|
+
|
9
|
+
# Default runlevel. The runlevels used by RHS are:
|
10
|
+
# 0 - halt (Do NOT set initdefault to this)
|
11
|
+
# 1 - Single user mode
|
12
|
+
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
|
13
|
+
# 3 - Full multiuser mode
|
14
|
+
# 4 - unused
|
15
|
+
# 5 - X11
|
16
|
+
# 6 - reboot (Do NOT set initdefault to this)
|
17
|
+
#
|
18
|
+
id:5:initdefault:
|
19
|
+
|
20
|
+
# System initialization.
|
21
|
+
si::sysinit:/etc/rc.d/rc.sysinit
|
22
|
+
|
23
|
+
l0:0:wait:/etc/rc.d/rc 0
|
24
|
+
l1:1:wait:/etc/rc.d/rc 1
|
25
|
+
l2:2:wait:/etc/rc.d/rc 2
|
26
|
+
l3:3:wait:/etc/rc.d/rc 3
|
27
|
+
l4:4:wait:/etc/rc.d/rc 4
|
28
|
+
l5:5:wait:/etc/rc.d/rc 5
|
29
|
+
l6:6:wait:/etc/rc.d/rc 6
|
30
|
+
|
31
|
+
# Trap CTRL-ALT-DELETE
|
32
|
+
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
|
33
|
+
|
34
|
+
# When our UPS tells us power has failed, assume we have a few minutes
|
35
|
+
# of power left. Schedule a shutdown for 2 minutes from now.
|
36
|
+
# This does, of course, assume you have powerd installed and your
|
37
|
+
# UPS connected and working correctly.
|
38
|
+
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
|
39
|
+
|
40
|
+
# If power was restored before the shutdown kicked in, cancel it.
|
41
|
+
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
|
42
|
+
|
43
|
+
|
44
|
+
# Run gettys in standard runlevels
|
45
|
+
1:2345:respawn:/sbin/mingetty tty1
|
46
|
+
2:2345:respawn:/sbin/mingetty tty2
|
47
|
+
3:2345:respawn:/sbin/mingetty tty3
|
48
|
+
4:2345:respawn:/sbin/mingetty tty4
|
49
|
+
5:2345:respawn:/sbin/mingetty tty5
|
50
|
+
6:2345:respawn:/sbin/mingetty tty6
|
51
|
+
|
52
|
+
# Run xdm in runlevel 5
|
53
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
data/tests/tc_augeas.rb
ADDED
@@ -0,0 +1,666 @@
|
|
1
|
+
##
|
2
|
+
# Augeas tests
|
3
|
+
#
|
4
|
+
# Copyright (C) 2011 Red Hat Inc.
|
5
|
+
# Copyright (C) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU Lesser General Public
|
9
|
+
# License as published by the Free Software Foundation; either
|
10
|
+
# version 2.1 of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
# Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public
|
18
|
+
# License along with this library; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#
|
21
|
+
# Authors: David Lutterkort <dlutter@redhat.com>
|
22
|
+
# Ionuț Arțăriși <iartarisi@suse.cz>
|
23
|
+
##
|
24
|
+
|
25
|
+
require 'test/unit'
|
26
|
+
|
27
|
+
TOPDIR = File::expand_path(File::join(File::dirname(__FILE__), ".."))
|
28
|
+
|
29
|
+
$:.unshift(File::join(TOPDIR, "lib"))
|
30
|
+
$:.unshift(File::join(TOPDIR, "ext", "augeas"))
|
31
|
+
|
32
|
+
require 'augeas'
|
33
|
+
require 'fileutils'
|
34
|
+
|
35
|
+
class TestAugeas < Test::Unit::TestCase
|
36
|
+
|
37
|
+
SRC_ROOT = File::expand_path(File::join(TOPDIR, "tests", "root")) + "/."
|
38
|
+
TST_ROOT = File::expand_path(File::join(TOPDIR, "build", "root")) + "/"
|
39
|
+
|
40
|
+
def test_basics
|
41
|
+
aug = aug_create(:save_mode => :newfile)
|
42
|
+
assert_equal("newfile", aug.get("/augeas/save"))
|
43
|
+
assert_equal(TST_ROOT, aug.get("/augeas/root"))
|
44
|
+
|
45
|
+
assert(aug.exists("/augeas/root"))
|
46
|
+
assert_not_nil(aug.get("/augeas/root"))
|
47
|
+
node = "/ruby/test/node"
|
48
|
+
assert_nothing_raised {
|
49
|
+
aug.set(node, "value")
|
50
|
+
}
|
51
|
+
assert_equal("value", aug.get(node))
|
52
|
+
assert_nothing_raised {
|
53
|
+
aug.clear(node)
|
54
|
+
}
|
55
|
+
assert_equal(nil, aug.get(node))
|
56
|
+
m = aug.match("/*")
|
57
|
+
["/augeas", "/ruby"].each do |p|
|
58
|
+
assert(m.include?(p))
|
59
|
+
assert(aug.exists(p))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_no_new
|
64
|
+
assert_raise NoMethodError do
|
65
|
+
Augeas.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_create_unknown_argument
|
70
|
+
assert_raise ArgumentError do
|
71
|
+
Augeas::create(:bogus => false)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_create_invalid_save_mode
|
76
|
+
assert_raise ArgumentError do
|
77
|
+
Augeas::create(:save_mode => :bogus)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_create_block
|
82
|
+
foo = nil
|
83
|
+
Augeas::create do |aug|
|
84
|
+
aug.set('/foo', 'bar')
|
85
|
+
foo = aug.get('/foo')
|
86
|
+
end
|
87
|
+
assert_equal(foo, 'bar')
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_load
|
91
|
+
aug = aug_create(no_load: true)
|
92
|
+
assert_equal([], aug.match("/files/etc/*"))
|
93
|
+
aug.rm("/augeas/load/*");
|
94
|
+
assert_nothing_raised {
|
95
|
+
aug.load
|
96
|
+
}
|
97
|
+
assert_equal([], aug.match("/files/etc/*"))
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_transform
|
101
|
+
aug = aug_create(no_load: true)
|
102
|
+
aug.clear_transforms
|
103
|
+
aug.transform(:lens => "Hosts.lns",
|
104
|
+
:incl => "/etc/hosts")
|
105
|
+
assert_raise(ArgumentError) {
|
106
|
+
aug.transform(:name => "Fstab",
|
107
|
+
:incl => [ "/etc/fstab" ],
|
108
|
+
:excl => [ "*~", "*.rpmnew" ])
|
109
|
+
}
|
110
|
+
aug.transform(:lens => "Inittab",
|
111
|
+
:incl => "/etc/inittab")
|
112
|
+
aug.transform(:lens => "Fstab.lns",
|
113
|
+
:incl => "/etc/fstab*",
|
114
|
+
:excl => "*~")
|
115
|
+
assert_equal(["/augeas/load/Fstab", "/augeas/load/Fstab/excl",
|
116
|
+
"/augeas/load/Fstab/incl", "/augeas/load/Fstab/lens",
|
117
|
+
"/augeas/load/Hosts", "/augeas/load/Hosts/incl",
|
118
|
+
"/augeas/load/Hosts/lens", "/augeas/load/Inittab",
|
119
|
+
"/augeas/load/Inittab/incl",
|
120
|
+
"/augeas/load/Inittab/lens"],
|
121
|
+
aug.match("/augeas/load//*").sort)
|
122
|
+
aug.load
|
123
|
+
assert_equal(["/files/etc/hosts", "/files/etc/inittab"],
|
124
|
+
aug.match("/files/etc/*").sort)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_defvar
|
128
|
+
Augeas::create(root: "/dev/null") do |aug|
|
129
|
+
aug.set("/a/b", "bval")
|
130
|
+
aug.set("/a/c", "cval")
|
131
|
+
assert aug.defvar("var", "/a/b")
|
132
|
+
assert_equal(["/a/b"], aug.match("$var"))
|
133
|
+
assert aug.defvar("var", nil)
|
134
|
+
assert_raises(SystemCallError) {
|
135
|
+
aug.match("$var")
|
136
|
+
}
|
137
|
+
assert ! aug.defvar("var", "/foo/")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_close
|
142
|
+
aug = Augeas::create(:root => "/tmp", :save_mode => :newfile)
|
143
|
+
assert_equal("newfile", aug.get("/augeas/save"))
|
144
|
+
aug.close
|
145
|
+
|
146
|
+
assert_raise(SystemCallError) {
|
147
|
+
aug.get("/augeas/save")
|
148
|
+
}
|
149
|
+
|
150
|
+
assert_raise(SystemCallError) {
|
151
|
+
aug.close
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_mv
|
156
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
157
|
+
aug.set("/a/b", "value")
|
158
|
+
aug.mv("/a/b", "/x/y")
|
159
|
+
assert_equal("value", aug.get("/x/y"))
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_mv_descendent_error
|
164
|
+
aug = aug_create
|
165
|
+
aug.set("/foo", "bar")
|
166
|
+
assert_raises(Augeas::DescendantError) {aug.mv("/foo", "/foo/bar/baz")}
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_mv_multiple_matches_error
|
170
|
+
aug = aug_create
|
171
|
+
aug.set("/foo/bar", "bar")
|
172
|
+
aug.set("/foo/baz", "baz")
|
173
|
+
assert_raises(Augeas::MultipleMatchesError) {aug.mv("/foo/*", "/qux")}
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_mv_invalid_path_error
|
177
|
+
aug = aug_create
|
178
|
+
assert_raises(Augeas::InvalidPathError) {aug.mv("/foo", "[]")}
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_mv_no_match_error
|
182
|
+
aug = aug_create
|
183
|
+
assert_raises(Augeas::NoMatchError) {aug.mv("/nonexistent", "/")}
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_mv_mutiple_dest_error
|
187
|
+
aug = aug_create
|
188
|
+
aug.set("/foo", "bar")
|
189
|
+
assert_raises(Augeas::CommandExecutionError) {aug.mv("/foo", "/bar/baz/*")}
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_load
|
193
|
+
aug = aug_create(:no_load => true)
|
194
|
+
assert_equal([], aug.match("/files/etc/*"))
|
195
|
+
aug.rm("/augeas/load/*");
|
196
|
+
assert_nothing_raised {
|
197
|
+
aug.load
|
198
|
+
}
|
199
|
+
assert_equal([], aug.match("/files/etc/*"))
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_load_bad_lens
|
203
|
+
aug = aug_create(:no_load => true)
|
204
|
+
aug.transform(:lens => "bad_lens", :incl => "irrelevant")
|
205
|
+
assert_raises(Augeas::LensNotFoundError) { aug.load }
|
206
|
+
assert_equal "Can not find lens bad_lens", aug.error[:details]
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_transform
|
210
|
+
aug = aug_create(:no_load => true)
|
211
|
+
aug.clear_transforms
|
212
|
+
aug.transform(:lens => "Hosts.lns",
|
213
|
+
:incl => "/etc/hosts")
|
214
|
+
assert_raise(ArgumentError) {
|
215
|
+
aug.transform(:name => "Fstab",
|
216
|
+
:incl => [ "/etc/fstab" ],
|
217
|
+
:excl => [ "*~", "*.rpmnew" ])
|
218
|
+
}
|
219
|
+
aug.transform(:lens => "Inittab.lns",
|
220
|
+
:incl => "/etc/inittab")
|
221
|
+
aug.transform(:lens => "Fstab.lns",
|
222
|
+
:incl => "/etc/fstab*",
|
223
|
+
:excl => "*~")
|
224
|
+
assert_equal(["/augeas/load/Fstab", "/augeas/load/Fstab/excl",
|
225
|
+
"/augeas/load/Fstab/incl", "/augeas/load/Fstab/lens",
|
226
|
+
"/augeas/load/Hosts", "/augeas/load/Hosts/incl",
|
227
|
+
"/augeas/load/Hosts/lens", "/augeas/load/Inittab",
|
228
|
+
"/augeas/load/Inittab/incl",
|
229
|
+
"/augeas/load/Inittab/lens"],
|
230
|
+
aug.match("/augeas/load//*").sort)
|
231
|
+
aug.load
|
232
|
+
assert_equal(["/files/etc/hosts", "/files/etc/inittab"],
|
233
|
+
aug.match("/files/etc/*").sort)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_transform_invalid_path
|
237
|
+
aug = aug_create
|
238
|
+
assert_raises (Augeas::InvalidPathError) {
|
239
|
+
aug.transform :lens => '//', :incl => 'foo' }
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_clear_transforms
|
243
|
+
aug = aug_create
|
244
|
+
assert_not_equal [], aug.match("/augeas/load/*")
|
245
|
+
aug.clear_transforms
|
246
|
+
assert_equal [], aug.match("/augeas/load/*")
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_clear
|
250
|
+
aug = aug_create
|
251
|
+
aug.set("/foo/bar", "baz")
|
252
|
+
aug.clear("/foo/bar")
|
253
|
+
assert_equal aug.get("/foo/bar"), nil
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_rm
|
257
|
+
aug = aug_create
|
258
|
+
aug.set("/foo/bar", "baz")
|
259
|
+
assert aug.get("/foo/bar")
|
260
|
+
assert_equal 2, aug.rm("/foo")
|
261
|
+
assert_nil aug.get("/foo")
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_rm_invalid_path
|
265
|
+
aug = aug_create
|
266
|
+
assert_raises(Augeas::InvalidPathError) { aug.rm('//') }
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_defvar
|
270
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
271
|
+
aug.set("/a/b", "bval")
|
272
|
+
aug.set("/a/c", "cval")
|
273
|
+
assert aug.defvar("var", "/a/b")
|
274
|
+
assert_equal(["/a/b"], aug.match("$var"))
|
275
|
+
assert aug.defvar("var", nil)
|
276
|
+
assert_raises(SystemCallError) {
|
277
|
+
aug.match("$var")
|
278
|
+
}
|
279
|
+
assert ! aug.defvar("var", "/foo/")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_defnode
|
284
|
+
aug = aug_create
|
285
|
+
assert aug.defnode("x", "/files/etc/hosts/*[ipaddr = '127.0.0.1']", nil)
|
286
|
+
assert_equal(["/files/etc/hosts/1"], aug.match("$x"))
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_insert_before
|
290
|
+
aug = aug_create
|
291
|
+
aug.set("/parent/child", "foo")
|
292
|
+
aug.insert("/parent/child", "sibling", true)
|
293
|
+
assert_equal ["/parent/sibling", "/parent/child"], aug.match("/parent/*")
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_insert_after
|
297
|
+
aug = aug_create
|
298
|
+
aug.set("/parent/child", "foo")
|
299
|
+
aug.insert("/parent/child", "sibling", false)
|
300
|
+
assert_equal ["/parent/child", "/parent/sibling"], aug.match("/parent/*")
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_insert_no_match
|
304
|
+
aug = aug_create
|
305
|
+
assert_raises (Augeas::NoMatchError) { aug.insert "foo", "bar", "baz" }
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_insert_invalid_path
|
309
|
+
aug = aug_create
|
310
|
+
assert_raises (Augeas::InvalidPathError) { aug.insert "//", "bar", "baz" }
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_insert_too_many_matches
|
314
|
+
aug = aug_create
|
315
|
+
assert_raises (Augeas::MultipleMatchesError) { aug.insert "/*", "a", "b" }
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_match
|
319
|
+
aug = aug_create
|
320
|
+
aug.set("/foo/bar", "baz")
|
321
|
+
aug.set("/foo/baz", "qux")
|
322
|
+
aug.set("/foo/qux", "bar")
|
323
|
+
|
324
|
+
assert_equal(["/foo/bar", "/foo/baz", "/foo/qux"], aug.match("/foo/*"))
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_match_empty_list
|
328
|
+
aug = aug_create
|
329
|
+
assert_equal([], aug.match("/nonexistent"))
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_match_invalid_path
|
333
|
+
aug = aug_create
|
334
|
+
assert_raises(Augeas::InvalidPathError) { aug.match('//') }
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_save
|
338
|
+
aug = aug_create
|
339
|
+
aug.set("/files/etc/hosts/1/garbage", "trash")
|
340
|
+
assert_raises(Augeas::CommandExecutionError) { aug.save }
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_save_tree_error
|
344
|
+
aug = aug_create(:no_load => true)
|
345
|
+
aug.set("/files/etc/sysconfig/iptables", "bad")
|
346
|
+
assert_raises(Augeas::CommandExecutionError) {aug.save}
|
347
|
+
assert aug.get("/augeas/files/etc/sysconfig/iptables/error")
|
348
|
+
assert_equal("No such file or directory",
|
349
|
+
aug.get("/augeas/files/etc/sysconfig/iptables/error/message"))
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_set_invalid_path
|
353
|
+
aug = aug_create
|
354
|
+
assert_raises(Augeas::InvalidPathError) { aug.set("files/etc//", nil) }
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_set_multiple_matches_error
|
358
|
+
aug = aug_create
|
359
|
+
# for some reason Augeas does not set aug_error for this,
|
360
|
+
# but just returns -1 from aug_set. Should raise Augeas::MultipleMatchesError instead.
|
361
|
+
assert_raises(Augeas::CommandExecutionError) { aug.set("files/etc/*", nil) }
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_set
|
365
|
+
aug = aug_create
|
366
|
+
aug.set("/files/etc/group/disk/user[last()+1]",["user1","user2"])
|
367
|
+
assert_equal(aug.get("/files/etc/group/disk/user[1]"), "root")
|
368
|
+
assert_equal(aug.get("/files/etc/group/disk/user[2]"), "user1")
|
369
|
+
assert_equal(aug.get("/files/etc/group/disk/user[3]"), "user2")
|
370
|
+
|
371
|
+
aug.set("/files/etc/group/new_group/user[last()+1]",
|
372
|
+
"nuser1",["nuser2","nuser3"])
|
373
|
+
assert_equal(aug.get("/files/etc/group/new_group/user[1]"), "nuser1")
|
374
|
+
assert_equal(aug.get("/files/etc/group/new_group/user[2]"), "nuser2")
|
375
|
+
assert_equal(aug.get("/files/etc/group/new_group/user[3]"), "nuser3")
|
376
|
+
|
377
|
+
aug.rm("/files/etc/group/disk/user")
|
378
|
+
aug.set("/files/etc/group/disk/user[last()+1]", "testuser")
|
379
|
+
assert_equal(aug.get("/files/etc/group/disk/user"), "testuser")
|
380
|
+
|
381
|
+
aug.rm("/files/etc/group/disk/user")
|
382
|
+
aug.set("/files/etc/group/disk/user[last()+1]", nil)
|
383
|
+
assert_equal(aug.get("/files/etc/group/disk/user"), nil)
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_setm
|
387
|
+
aug = aug_create
|
388
|
+
|
389
|
+
aug.setm("/files/etc/group/*[label() =~ regexp(\"rpc.*\")]",
|
390
|
+
"users", "testuser1")
|
391
|
+
assert_equal(aug.get("/files/etc/group/rpc/users"), "testuser1")
|
392
|
+
assert_equal(aug.get("/files/etc/group/rpcuser/users"), "testuser1")
|
393
|
+
|
394
|
+
aug.setm("/files/etc/group/*[label() =~ regexp(\"rpc.*\")]/users",
|
395
|
+
nil, "testuser2")
|
396
|
+
assert_equal(aug.get("/files/etc/group/rpc/users"), "testuser2")
|
397
|
+
assert_equal(aug.get("/files/etc/group/rpcuser/users"), "testuser2")
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_setm_invalid_path
|
401
|
+
aug = aug_create
|
402
|
+
assert_raises (Augeas::InvalidPathError) { aug.setm("[]", "bar", "baz") }
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_exists
|
406
|
+
aug = aug_create
|
407
|
+
assert_equal false, aug.exists("/foo")
|
408
|
+
aug.set("/foo", "bar")
|
409
|
+
assert aug.exists("/foo")
|
410
|
+
end
|
411
|
+
|
412
|
+
def test_exists_invalid_path_error
|
413
|
+
aug = aug_create
|
414
|
+
assert_raises(Augeas::InvalidPathError) {aug.exists("[]")}
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_get_multiple_matches_error
|
418
|
+
aug = aug_create
|
419
|
+
|
420
|
+
# Cause an error
|
421
|
+
assert_raises (Augeas::MultipleMatchesError) {
|
422
|
+
aug.get("/files/etc/hosts/*") }
|
423
|
+
|
424
|
+
err = aug.error
|
425
|
+
assert_equal(Augeas::EMMATCH, err[:code])
|
426
|
+
assert err[:message]
|
427
|
+
assert err[:details]
|
428
|
+
assert err[:minor].nil?
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_get_invalid_path
|
432
|
+
aug = aug_create
|
433
|
+
assert_raises (Augeas::InvalidPathError) { aug.get("//") }
|
434
|
+
|
435
|
+
err = aug.error
|
436
|
+
assert_equal(Augeas::EPATHX, err[:code])
|
437
|
+
assert err[:message]
|
438
|
+
assert err[:details]
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_defvar
|
442
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
443
|
+
aug.set("/a/b", "bval")
|
444
|
+
aug.set("/a/c", "cval")
|
445
|
+
assert aug.defvar("var", "/a/b")
|
446
|
+
assert_equal(["/a/b"], aug.match("$var"))
|
447
|
+
assert aug.defvar("var", nil)
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_defvar_invalid_path
|
452
|
+
aug = aug_create
|
453
|
+
assert_raises(Augeas::InvalidPathError) { aug.defvar('var', 'F#@!$#@') }
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_defnode
|
457
|
+
aug = aug_create
|
458
|
+
assert aug.defnode("x", "/files/etc/hosts/*[ipaddr = '127.0.0.1']", nil)
|
459
|
+
assert_equal(["/files/etc/hosts/1"], aug.match("$x"))
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_defnode_invalid_path
|
463
|
+
aug = aug_create
|
464
|
+
assert_raises (Augeas::InvalidPathError) { aug.defnode('x', '//', nil)}
|
465
|
+
end
|
466
|
+
|
467
|
+
def test_span
|
468
|
+
aug = aug_create
|
469
|
+
|
470
|
+
aug.set("/augeas/span", "enable")
|
471
|
+
aug.rm("/files/etc")
|
472
|
+
aug.load
|
473
|
+
|
474
|
+
span = aug.span("/files/etc/ssh/sshd_config/Protocol")
|
475
|
+
assert_not_nil(span[:filename])
|
476
|
+
assert_equal(29..37, span[:label])
|
477
|
+
assert_equal(38..39, span[:value])
|
478
|
+
assert_equal(29..40, span[:span])
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_span_no_span_info
|
482
|
+
aug = aug_create
|
483
|
+
# this error should be raised because we haven't enabled the span
|
484
|
+
assert_raises(Augeas::NoSpanInfoError) {
|
485
|
+
aug.span("/files/etc/ssh/sshd_config/Protocol") }
|
486
|
+
end
|
487
|
+
|
488
|
+
def test_span_no_matches
|
489
|
+
aug = aug_create
|
490
|
+
assert_raises(Augeas::NoMatchError) { aug.span("bogus") }
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_flag_save_noop
|
494
|
+
aug = aug_create(:save_mode => :noop)
|
495
|
+
assert_equal("noop", aug.get("/augeas/save"))
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_flag_no_load
|
499
|
+
aug = aug_create(:no_load => true)
|
500
|
+
assert_equal([], aug.match("/files/*"))
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_flag_no_modl_autoload
|
504
|
+
aug = aug_create(:no_modl_autoload => true)
|
505
|
+
assert_equal([], aug.match("/files/*"))
|
506
|
+
end
|
507
|
+
|
508
|
+
def test_flag_enable_span
|
509
|
+
aug = aug_create(:enable_span => true)
|
510
|
+
assert_equal("enable", aug.get("/augeas/span"))
|
511
|
+
end
|
512
|
+
|
513
|
+
def test_set
|
514
|
+
aug = aug_create
|
515
|
+
aug.set("/files/etc/group/disk/user[last()+1]",["user1","user2"])
|
516
|
+
assert_equal( aug.get("/files/etc/group/disk/user[1]"),"root" )
|
517
|
+
assert_equal( aug.get("/files/etc/group/disk/user[2]"),"user1" )
|
518
|
+
assert_equal( aug.get("/files/etc/group/disk/user[3]"),"user2" )
|
519
|
+
|
520
|
+
aug.set("/files/etc/group/new_group/user[last()+1]",
|
521
|
+
"nuser1",["nuser2","nuser3"])
|
522
|
+
assert_equal( aug.get("/files/etc/group/new_group/user[1]"),"nuser1")
|
523
|
+
assert_equal( aug.get("/files/etc/group/new_group/user[2]"),"nuser2" )
|
524
|
+
assert_equal( aug.get("/files/etc/group/new_group/user[3]"),"nuser3" )
|
525
|
+
|
526
|
+
aug.rm("/files/etc/group/disk/user")
|
527
|
+
aug.set("/files/etc/group/disk/user[last()+1]","testuser")
|
528
|
+
assert_equal( aug.get("/files/etc/group/disk/user"),"testuser")
|
529
|
+
|
530
|
+
aug.rm("/files/etc/group/disk/user")
|
531
|
+
aug.set("/files/etc/group/disk/user[last()+1]", nil)
|
532
|
+
assert_equal( aug.get("/files/etc/group/disk/user"), nil)
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_setm
|
536
|
+
aug = aug_create
|
537
|
+
|
538
|
+
aug.setm("/files/etc/group/*[label() =~ regexp(\"rpc.*\")]","users", "testuser1")
|
539
|
+
assert_equal( aug.get("/files/etc/group/rpc/users"), "testuser1")
|
540
|
+
assert_equal( aug.get("/files/etc/group/rpcuser/users"), "testuser1")
|
541
|
+
|
542
|
+
aug.setm("/files/etc/group/*[label() =~ regexp(\"rpc.*\")]/users",nil, "testuser2")
|
543
|
+
assert_equal( aug.get("/files/etc/group/rpc/users"), "testuser2")
|
544
|
+
assert_equal( aug.get("/files/etc/group/rpcuser/users"), "testuser2")
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_error
|
548
|
+
aug = aug_create
|
549
|
+
|
550
|
+
# Cause an error
|
551
|
+
aug.get("/files/etc/hosts/*") rescue nil
|
552
|
+
err = aug.error
|
553
|
+
assert_equal(Augeas::EMMATCH, err[:code])
|
554
|
+
assert err[:message]
|
555
|
+
assert err[:details]
|
556
|
+
assert err[:minor].nil?
|
557
|
+
end
|
558
|
+
|
559
|
+
def test_span
|
560
|
+
aug = aug_create
|
561
|
+
|
562
|
+
assert_raises(Augeas::NoSpanInfoError) { aug.span("/files/etc/ssh/sshd_config/Protocol") }
|
563
|
+
|
564
|
+
aug.set("/augeas/span", "enable")
|
565
|
+
aug.rm("/files/etc")
|
566
|
+
aug.load
|
567
|
+
|
568
|
+
span = aug.span("/files/etc/ssh/sshd_config/Protocol")
|
569
|
+
assert_not_nil(span[:filename])
|
570
|
+
assert_equal(29..37, span[:label])
|
571
|
+
assert_equal(38..39, span[:value])
|
572
|
+
assert_equal(29..40, span[:span])
|
573
|
+
end
|
574
|
+
|
575
|
+
def test_srun
|
576
|
+
aug = aug_create
|
577
|
+
|
578
|
+
path = "/files/etc/hosts/*[canonical='localhost.localdomain']/ipaddr"
|
579
|
+
r, out = aug.srun("get #{path}\n")
|
580
|
+
assert_equal(1, r)
|
581
|
+
assert_equal("#{path} = 127.0.0.1\n", out)
|
582
|
+
|
583
|
+
assert_equal(0, aug.srun(" ")[0])
|
584
|
+
assert_raises(Augeas::CommandExecutionError) { aug.srun("foo") }
|
585
|
+
assert_raises(Augeas::CommandExecutionError) { aug.srun("set") }
|
586
|
+
assert_equal(-2, aug.srun("quit")[0])
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_label
|
590
|
+
Augeas::create(root: "/dev/null") do |aug|
|
591
|
+
assert_equal 'augeas', aug.label('/augeas')
|
592
|
+
assert_equal 'files', aug.label('/files')
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
def test_rename
|
597
|
+
Augeas::create(root: "/dev/null") do |aug|
|
598
|
+
assert_raises(Augeas::InvalidLabelError) { aug.rename('/files', 'invalid/label') }
|
599
|
+
assert_equal 0, aug.rename('/nonexistent', 'label')
|
600
|
+
assert_equal ['/files'], aug.match('/files')
|
601
|
+
assert_equal 1, aug.rename('/files', 'label')
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
def test_text_store_retrieve
|
606
|
+
Augeas::create(root: "/dev/null") do |aug|
|
607
|
+
# text_store errors
|
608
|
+
assert_raises(Augeas::NoMatchError) { aug.text_store('Simplelines.lns', '/input', '/store') }
|
609
|
+
|
610
|
+
# text_store
|
611
|
+
aug.set('/input', "line1\nline2\n")
|
612
|
+
assert aug.text_store('Simplelines.lns', '/input', '/store')
|
613
|
+
assert_equal 'line2', aug.get('/store/2')
|
614
|
+
|
615
|
+
# text_retrieve errors
|
616
|
+
assert_raises(Augeas::NoMatchError) { aug.text_retrieve('Simplelines.lns', '/unknown', '/store', '/output') }
|
617
|
+
|
618
|
+
# text_retrieve
|
619
|
+
aug.set('/store/3', 'line3')
|
620
|
+
assert aug.text_retrieve('Simplelines.lns', '/input', '/store', '/output')
|
621
|
+
assert_equal "line1\nline2\nline3\n", aug.get('/output')
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
def test_context
|
626
|
+
Augeas::create(root: "/dev/null") do |aug|
|
627
|
+
aug.context = '/augeas'
|
628
|
+
assert_equal '/augeas', aug.get('/augeas/context')
|
629
|
+
assert_equal '/augeas', aug.get('context')
|
630
|
+
assert_equal '/augeas', aug.context
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
def test_touch
|
635
|
+
Augeas::create(root: "/dev/null") do |aug|
|
636
|
+
assert_equal [], aug.match('/foo')
|
637
|
+
aug.touch '/foo'
|
638
|
+
assert_equal ['/foo'], aug.match('/foo')
|
639
|
+
|
640
|
+
aug.set '/foo', 'bar'
|
641
|
+
aug.touch '/foo'
|
642
|
+
assert_equal 'bar', aug.get('/foo')
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
def test_clearm
|
647
|
+
Augeas::create(root: "/dev/null") do |aug|
|
648
|
+
aug.set('/foo/a', '1')
|
649
|
+
aug.set('/foo/b', '2')
|
650
|
+
aug.clearm('/foo', '*')
|
651
|
+
assert_nil aug.get('/foo/a')
|
652
|
+
assert_nil aug.get('/foo/b')
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
private
|
657
|
+
def aug_create(flags={})
|
658
|
+
if File::directory?(TST_ROOT)
|
659
|
+
FileUtils::rm_rf(TST_ROOT)
|
660
|
+
end
|
661
|
+
FileUtils::mkdir_p(TST_ROOT)
|
662
|
+
FileUtils::cp_r(SRC_ROOT, TST_ROOT)
|
663
|
+
|
664
|
+
Augeas::create({:root => TST_ROOT, :loadpath => nil}.merge(flags))
|
665
|
+
end
|
666
|
+
end
|