forked from Normation/ncf
/
file_copy_from_local_source_recursion.cf
93 lines (74 loc) · 3.37 KB
/
file_copy_from_local_source_recursion.cf
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#######################################################
#
# Test checking if a file can be copied from a local source
#
#######################################################
bundle common acc_path
{
vars:
"root" string => getenv("NCF_TESTS_ACCEPTANCE", 1024);
}
body common control
{
inputs => { "${acc_path.root}/default.cf.sub", "${acc_path.root}/default_ncf.cf.sub", "@{ncf_inputs.default_files}" };
bundlesequence => { configuration, default("${this.promise_filename}") };
version => "1.0";
}
#######################################################
bundle agent init
{
vars:
"tmp" string => getenv("TEMP", 1024);
"source_file[0]" string => "${tmp}/source_test_0";
"destination_file[0]" string => "${tmp}/destination_test_0";
"expected_result[0]" string => "repaired";
"recursion[0]" string => "0";
"mode" string => "665";
"owner" string => "root";
"group" string => "0";
"indices" slist => getindices("source_file");
files:
"${source_file[0]}"
create => "true",
perms => mog("${mode}", "${owner}", "${group}");
}
#######################################################
bundle agent test
{
vars:
"args${init.indices}" slist => { "${init.source_file[${init.indices}]}", "${init.destination_file[0]}", "${init.recursion[${init.indices}]}" };
methods:
"ph0" usebundle => apply_gm("file_copy_from_local_source_recursion", @{args0}, "${init.expected_result[0]}", "ph0", "enforce" );
}
#######################################################
bundle agent check
{
vars:
"owner_id" int => getuid("${init.owner}");
"permissions_test_mode" string => "/usr/bin/test ${const.dollar}(${test_utils.file_perms} ${init.destination_file[0]}) = \"${init.mode}\"";
"permissions_test_owner" string => "/usr/bin/test ${const.dollar}(${test_utils.file_owner} ${init.destination_file[0]}) = \"${owner_id}\"";
"permissions_test_group" string => "/usr/bin/test ${const.dollar}(${test_utils.file_group} ${init.destination_file[0]}) = \"${init.group}\"";
classes:
# By default, file_copy_from_local_source_type_recursion should create the file if it doesn't exist
"permissions_test_mode_ok"
expression => returnszero("${permissions_test_mode}", "useshell"),
ifvarclass => canonify("file_copy_from_local_source_${init.destination_file}_reached");
"permissions_test_owner_ok"
expression => returnszero("${permissions_test_owner}", "useshell"),
ifvarclass => canonify("file_copy_from_local_source_${init.destination_file}_reached");
"permissions_test_group_ok"
expression => returnszero("${permissions_test_group}", "useshell"),
ifvarclass => canonify("file_copy_from_local_source_${init.destination_file}_reached");
"ok" expression => "permissions_test_mode_ok.permissions_test_owner_ok.permissions_test_group_ok.ph0_ok";
reports:
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
!permissions_test_mode_ok::
"test command doesn't return 0 for command: ${permissions_test_mode}";
!permissions_test_owner_ok::
"test command doesn't return 0 for command: ${permissions_test_owner}";
!permissions_test_group_ok::
"test command doesn't return 0 for command: ${permissions_test_group}";
}