Skip to content

Commit 1188e50

Browse files
Merge pull request #4397 from craigcomstock/ENT-5301
ENT-5301 test --simulate=manifest mode
2 parents 23de548 + d5a8e9e commit 1188e50

File tree

8 files changed

+414
-100
lines changed

8 files changed

+414
-100
lines changed

tests/acceptance/28_inform_testing/01_files/acl.cf.expected

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/acceptance/28_inform_testing/01_files/acl.cf.skip

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
body common control
2+
{
3+
inputs => { "../default.cf.sub" };
4+
bundlesequence => { default("$(this.promise_filename)") };
5+
version => "1.0";
6+
}
7+
8+
bundle agent init
9+
{
10+
files:
11+
"$(G.testroot)$(const.dirsep)delete-me"
12+
create => "true";
13+
"$(G.testroot)$(const.dirsep)sub-dir/."
14+
create => "true";
15+
"$(G.testroot)$(const.dirsep)sub-dir/sub-file"
16+
create => "true";
17+
"$(G.testroot)$(const.dirsep)set-colon-field"
18+
create => "true",
19+
content => "me:x:1001:1001::/home/me:/bin/sh";
20+
"$(G.testroot)$(const.dirsep)delete-lines-matching"
21+
create => "true",
22+
content => "
23+
foo 1
24+
bar 2
25+
baz 3
26+
me:x:101:doo
27+
";
28+
"$(G.testroot)$(const.dirsep)regex-replace"
29+
create => "true",
30+
content => "I dare you to change my policy foo";
31+
"$(G.testroot)$(const.dirsep)edit-template-string"
32+
create => "true",
33+
content => "From a particular point of view";
34+
"$(G.testroot)$(const.dirsep)xml-insert-tree"
35+
create => "true",
36+
edit_xml => xml_insert_tree_nopath("<Root/>");
37+
"$(G.testroot)$(const.dirsep)build-xpath"
38+
create => "true";
39+
"$(G.testroot)$(const.dirsep)perms"
40+
create => "true";
41+
"$(G.testroot)$(const.dirsep)rename-me"
42+
create => "true";
43+
"$(G.testroot)$(const.dirsep)transformer"
44+
create => "true";
45+
}
46+
47+
bundle agent test
48+
{
49+
meta:
50+
"test_soft_fail" string => "(solaris|aix|hpux)|(debian_7.i686)",
51+
meta => { "ENT-6537", "ENT-6540" };
52+
# ENT-6537 debian 7 dirent has extra ',' entry
53+
# ENT-6540 exotics fail to delete chroot
54+
55+
"description" -> { "ENT-5301" }
56+
string => "Test that files promises in --simulate=manifest mode produce proper output and only make changes in chroot";
57+
58+
commands:
59+
# add --verbose here and look at the .actual log for debugging sub policy runs
60+
"$(sys.cf_agent) -Kf $(this.promise_filename).sub --simulate=manifest > $(this.promise_filename).temp 2>&1"
61+
contain => in_shell,
62+
handle => "agent_run_complete",
63+
comment => "Run sub policy in manifest mode and capture output to $(this.promise_filename).actual file.";
64+
"$(G.sed)"
65+
args => " \
66+
-e 's,$(sys.workdir),WORKDIR,g' \
67+
-e 's/[0-9]*\.changes/PID.changes/' \
68+
-e 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}[[:blank:]][0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}[[:blank:]][-+][0-9]\{4\}/TIMESTAMP/' \
69+
-e 's/Size: [0-9]*/Size: SIZE/' \
70+
$(this.promise_filename).temp > $(this.promise_filename).actual",
71+
contain => in_shell,
72+
handle => "warning_line_normalized",
73+
depends_on => { "agent_run_complete" },
74+
comment => "Normalize pid, timestamp and file sizes so that we can compare to an expected output.";
75+
}
76+
77+
bundle agent check
78+
{
79+
methods:
80+
"check" usebundle => dcs_check_diff("$(this.promise_filename).actual",
81+
"$(this.promise_filename).expected",
82+
"$(this.promise_filename)");
83+
}
84+
bundle edit_xml xml_insert_tree_nopath(treestring)
85+
{
86+
insert_tree:
87+
'$(treestring)';
88+
}
89+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
warning: All changes in files will be made in the 'WORKDIR/state/PID.changes' chroot
2+
===========================================================================
3+
'WORKDIR/tmp/rename-newname' is the new name of 'WORKDIR/tmp/rename-me'
4+
===========================================================================
5+
'WORKDIR/tmp/source-file' is a regular file
6+
Size: SIZE
7+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
8+
Access: TIMESTAMP
9+
Modify: TIMESTAMP
10+
Change: TIMESTAMP
11+
12+
Contents of the file:
13+
These are my source file contents.
14+
\no newline at the end of file
15+
===========================================================================
16+
'WORKDIR/tmp/create-true' is a regular file
17+
Size: SIZE
18+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
19+
Access: TIMESTAMP
20+
Modify: TIMESTAMP
21+
Change: TIMESTAMP
22+
23+
Contents of the file:
24+
===========================================================================
25+
'WORKDIR/tmp/insert-lines' is a regular file
26+
Size: SIZE
27+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
28+
Access: TIMESTAMP
29+
Modify: TIMESTAMP
30+
Change: TIMESTAMP
31+
32+
Contents of the file:
33+
foobar
34+
===========================================================================
35+
'WORKDIR/tmp/SUBDIR' is a directory
36+
Size: SIZE
37+
Access: (0755/rwxr-xr-x) Uid: (0/root) Gid: (0/root)
38+
Access: TIMESTAMP
39+
Modify: TIMESTAMP
40+
Change: TIMESTAMP
41+
42+
Directory contents:
43+
===========================================================================
44+
'WORKDIR/tmp/copy-from' is a regular file
45+
Size: SIZE
46+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
47+
Access: TIMESTAMP
48+
Modify: TIMESTAMP
49+
Change: TIMESTAMP
50+
51+
Contents of the file:
52+
These are my source file contents.
53+
\no newline at the end of file
54+
===========================================================================
55+
'WORKDIR/tmp/delete-me' no longer exists
56+
===========================================================================
57+
'WORKDIR/tmp/sub-dir/./sub-file' no longer exists
58+
===========================================================================
59+
'WORKDIR/tmp/sub-dir/.' is a directory
60+
Size: SIZE
61+
Access: (0755/rwxr-xr-x) Uid: (0/root) Gid: (0/root)
62+
Access: TIMESTAMP
63+
Modify: TIMESTAMP
64+
Change: TIMESTAMP
65+
66+
Directory contents:
67+
===========================================================================
68+
'WORKDIR/tmp/set-colon-field' is a regular file
69+
Size: SIZE
70+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
71+
Access: TIMESTAMP
72+
Modify: TIMESTAMP
73+
Change: TIMESTAMP
74+
75+
Contents of the file:
76+
me:x:1001:1001::/my/new/shell:/bin/sh
77+
===========================================================================
78+
'WORKDIR/tmp/delete-lines-matching' is a regular file
79+
Size: SIZE
80+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
81+
Access: TIMESTAMP
82+
Modify: TIMESTAMP
83+
Change: TIMESTAMP
84+
85+
Contents of the file:
86+
87+
bar 2
88+
baz 3
89+
me:x:101:doo
90+
===========================================================================
91+
'WORKDIR/tmp/regex-replace' is a regular file
92+
Size: SIZE
93+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
94+
Access: TIMESTAMP
95+
Modify: TIMESTAMP
96+
Change: TIMESTAMP
97+
98+
Contents of the file:
99+
I dare you to change my policy FOO!
100+
===========================================================================
101+
'WORKDIR/tmp/edit-template-string' is a regular file
102+
Size: SIZE
103+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
104+
Access: TIMESTAMP
105+
Modify: TIMESTAMP
106+
Change: TIMESTAMP
107+
108+
Contents of the file:
109+
Darth Vader killed your father
110+
\no newline at the end of file
111+
===========================================================================
112+
'WORKDIR/tmp/build-xpath' is a regular file
113+
Size: SIZE
114+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
115+
Access: TIMESTAMP
116+
Modify: TIMESTAMP
117+
Change: TIMESTAMP
118+
119+
Contents of the file:
120+
<?xml version="1.0"?>
121+
<Server><Service><Engine><Host/></Engine></Service></Server>
122+
===========================================================================
123+
'WORKDIR/tmp/xml-insert-tree' is a regular file
124+
Size: SIZE
125+
Access: (0600/rw-------) Uid: (0/root) Gid: (0/root)
126+
Access: TIMESTAMP
127+
Modify: TIMESTAMP
128+
Change: TIMESTAMP
129+
130+
Contents of the file:
131+
<?xml version="1.0"?>
132+
<Root><x foo="bar">y</x></Root>
133+
===========================================================================
134+
'WORKDIR/tmp/perms' is a regular file
135+
Size: SIZE
136+
Access: (0000/---------) Uid: (0/root) Gid: (0/root)
137+
Access: TIMESTAMP
138+
Modify: TIMESTAMP
139+
Change: TIMESTAMP
140+
141+
Contents of the file:
142+
===========================================================================
143+
'WORKDIR/tmp/transformer' no longer exists
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
bundle common simulation_files_promises
2+
{
3+
vars:
4+
"inputs" slist => { "$(this.promise_dirname)/../default.cf.sub" };
5+
}
6+
7+
body common control
8+
{
9+
inputs => { "@(simulation_files_promises.inputs)" };
10+
}
11+
12+
bundle agent init
13+
{
14+
files:
15+
"$(G.testroot)$(const.dirsep)source-file"
16+
create => "true",
17+
content => "These are my source file contents.";
18+
}
19+
20+
bundle agent test
21+
{
22+
files:
23+
"$(G.testroot)$(const.dirsep)create-true"
24+
create => "true";
25+
"$(G.testroot)$(const.dirsep)insert-lines"
26+
create => "true",
27+
edit_line => insert_lines("foobar");
28+
"$(G.testroot)$(const.dirsep)SUBDIR/."
29+
create => "true";
30+
"$(G.testroot)$(const.dirsep)copy-from"
31+
copy_from => example("$(G.testroot)$(const.dirsep)source-file");
32+
"$(G.testroot)$(const.dirsep)delete-me"
33+
delete => tidy;
34+
"$(G.testroot)$(const.dirsep)sub-dir/."
35+
delete => tidy,
36+
file_select => all,
37+
depth_search => recurse("inf");
38+
"$(G.testroot)$(const.dirsep)set-colon-field"
39+
edit_line => set_colon_field("me","6","/my/new/shell");
40+
"$(G.testroot)$(const.dirsep)delete-lines-matching"
41+
edit_line => delete_lines_matching("foo 1");
42+
"$(G.testroot)$(const.dirsep)regex-replace"
43+
edit_line => regex_replace("foo","FOO!");
44+
"$(G.testroot)$(const.dirsep)edit-template-string"
45+
template_method => "inline_mustache",
46+
edit_template_string => "{{{name}}} killed your father",
47+
template_data => '{ "name": "Darth Vader" }';
48+
"$(G.testroot)$(const.dirsep)build-xpath"
49+
edit_xml => build_xpath("/Server/Service/Engine/Host");
50+
"$(G.testroot)$(const.dirsep)xml-insert-tree"
51+
edit_xml => xml_insert_tree("<x foo='bar'>y</x>", "//Root");
52+
"$(G.testroot)$(const.dirsep)perms"
53+
perms => m(000);
54+
"$(G.testroot)$(const.dirsep)rename-me"
55+
rename => newname("$(G.testroot)$(const.dirsep)rename-newname");
56+
"$(G.testroot)$(const.dirsep)transformer"
57+
transformer => "$(G.gzip) $(this.promiser)";
58+
}
59+
60+
61+
# TODO list the contents of the chroot so we can see transformer.gz for example?
62+
#bundle agent check
63+
#{
64+
# vars:
65+
# "result" string => execresult("$(G.ls) -laR $(sys.workdir)/state/", "noshell"),
66+
# meta => { "simulate_safe" };
67+
# reports:
68+
# "chroot files: $(result)";
69+
#}
70+
71+
bundle agent main
72+
{
73+
methods:
74+
"init";
75+
"test";
76+
# "check";
77+
}
78+
79+
body copy_from example(from)
80+
{
81+
source => "$(from)";
82+
compare => "digest";
83+
preserve => "true";
84+
}
85+
86+
bundle edit_xml xml_insert_tree(treestring, xpath)
87+
{
88+
insert_tree:
89+
'$(treestring)' select_xpath => "$(xpath)";
90+
}
91+
92+
bundle edit_xml build_xpath(xpath)
93+
{
94+
build_xpath:
95+
"$(xpath)";
96+
}
97+
98+
body rename newname(name)
99+
{
100+
newname => "$(name)";
101+
}

0 commit comments

Comments
 (0)