puppet-lint-file_ensure-check 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfa9f5e1fc0ea251d4bad7cf61e5afe8826fd5f8
|
4
|
+
data.tar.gz: 77cdaaabc6993fe383d7c813104f49dbe0857f4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3970c7fb794837a782894fcd3690674219e099de8438038637375e3a9b305ab92a322c77786c83d4c033e0d3bd711d125ec19113a5c6b228df49996ad7ed3342
|
7
|
+
data.tar.gz: 4f2c9fa4a829aaf148b090a7825cedb90c594336e567917a1ac59b92fdd10e6c28c6c147512887a93ef0c108a0c59eb31975bb2ea58777853e04902886af01db
|
@@ -2,19 +2,33 @@ PuppetLint.new_check(:file_ensure) do
|
|
2
2
|
def check
|
3
3
|
resource_indexes.each do |resource|
|
4
4
|
if resource[:type].value == 'file'
|
5
|
-
attr = resource[:tokens].select { |t| t.type == :NAME &&
|
5
|
+
attr = resource[:tokens].select { |t| t.type == :NAME && \
|
6
|
+
t.value == 'ensure' && \
|
7
|
+
t.next_code_token.type == :FARROW }
|
6
8
|
unless attr.empty?
|
7
9
|
val_token = attr[0].next_code_token.next_code_token
|
8
10
|
if val_token.value == 'present'
|
9
11
|
notify :warning, {
|
10
|
-
:message
|
11
|
-
:line
|
12
|
-
:column
|
13
|
-
:token
|
12
|
+
:message => 'ensure set to present on file resource',
|
13
|
+
:line => val_token.line,
|
14
|
+
:column => val_token.column,
|
15
|
+
:token => val_token,
|
16
|
+
:resource => resource,
|
14
17
|
}
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
23
|
+
|
24
|
+
def fix(problem)
|
25
|
+
target_attr = problem[:resource][:tokens].select { |t| t.type == :NAME && \
|
26
|
+
t.value == 'target' && \
|
27
|
+
t.next_code_token.type == :FARROW }
|
28
|
+
if target_attr.empty?
|
29
|
+
problem[:token].value = 'file'
|
30
|
+
else
|
31
|
+
problem[:token].value = 'link'
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
@@ -12,7 +12,8 @@ describe 'file_ensure' do
|
|
12
12
|
}
|
13
13
|
|
14
14
|
file { '/etc/fstab':
|
15
|
-
ensure => '
|
15
|
+
ensure => 'target',
|
16
|
+
target => '/etc/mtab',
|
16
17
|
}
|
17
18
|
EOS
|
18
19
|
}
|
@@ -31,11 +32,12 @@ describe 'file_ensure' do
|
|
31
32
|
|
32
33
|
file { '/etc/fstab':
|
33
34
|
ensure => 'present',
|
35
|
+
target => '/etc/mtab',
|
34
36
|
}
|
35
37
|
EOS
|
36
38
|
}
|
37
39
|
|
38
|
-
it 'should detect
|
40
|
+
it 'should detect problems' do
|
39
41
|
expect(problems).to have(2).problems
|
40
42
|
end
|
41
43
|
|
@@ -45,4 +47,76 @@ describe 'file_ensure' do
|
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
50
|
+
|
51
|
+
context 'with fix enabled' do
|
52
|
+
before do
|
53
|
+
PuppetLint.configuration.fix = true
|
54
|
+
end
|
55
|
+
|
56
|
+
after do
|
57
|
+
PuppetLint.configuration.fix = false
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'correct file resource declarations' do
|
61
|
+
let (:code) {
|
62
|
+
<<-EOS
|
63
|
+
file { '/etc/sudoers':
|
64
|
+
ensure => file,
|
65
|
+
}
|
66
|
+
|
67
|
+
file { '/etc/fstab':
|
68
|
+
ensure => 'target',
|
69
|
+
target => '/etc/mtab',
|
70
|
+
}
|
71
|
+
EOS
|
72
|
+
}
|
73
|
+
|
74
|
+
it 'should not detect any problems' do
|
75
|
+
expect(problems).to have(0).problems
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not modify the manifest' do
|
79
|
+
expect(manifest).to eq(code)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'wrong file resource declarations' do
|
84
|
+
let (:code) {
|
85
|
+
<<-EOS
|
86
|
+
file { '/etc/sudoers':
|
87
|
+
ensure => present,
|
88
|
+
}
|
89
|
+
|
90
|
+
file { '/etc/fstab':
|
91
|
+
ensure => 'present',
|
92
|
+
target => '/etc/mtab',
|
93
|
+
}
|
94
|
+
EOS
|
95
|
+
}
|
96
|
+
|
97
|
+
it 'should detect two problems' do
|
98
|
+
expect(problems).to have(2).problems
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should create a warning' do
|
102
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(21)
|
103
|
+
expect(problems).to contain_fixed(msg).on_line(6).in_column(21)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should fix the ensure parameter' do
|
107
|
+
expect(manifest).to eq(
|
108
|
+
<<-EOS
|
109
|
+
file { '/etc/sudoers':
|
110
|
+
ensure => file,
|
111
|
+
}
|
112
|
+
|
113
|
+
file { '/etc/fstab':
|
114
|
+
ensure => 'link',
|
115
|
+
target => '/etc/mtab',
|
116
|
+
}
|
117
|
+
EOS
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
48
122
|
end
|