puppet 3.4.2 → 3.4.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/ext/build_defaults.yaml +1 -1
- data/ext/redhat/puppet.spec.erb +8 -8
- data/lib/puppet/defaults.rb +5 -1
- data/lib/puppet/indirector/resource_type/parser.rb +58 -38
- data/lib/puppet/metatype/manager.rb +0 -1
- data/lib/puppet/network/http/connection.rb +8 -0
- data/lib/puppet/network/http/webrick.rb +4 -1
- data/lib/puppet/node/environment.rb +13 -32
- data/lib/puppet/parser/compiler.rb +1 -2
- data/lib/puppet/parser/functions/each.rb +4 -4
- data/lib/puppet/parser/type_loader.rb +20 -1
- data/lib/puppet/provider/package/dpkg.rb +13 -54
- data/lib/puppet/provider/package/rpm.rb +7 -11
- data/lib/puppet/transaction/resource_harness.rb +17 -17
- data/lib/puppet/type.rb +83 -117
- data/lib/puppet/type/exec.rb +42 -20
- data/lib/puppet/type/file.rb +4 -0
- data/lib/puppet/type/interface.rb +4 -0
- data/lib/puppet/type/mount.rb +4 -2
- data/lib/puppet/type/package.rb +4 -0
- data/lib/puppet/type/schedule.rb +14 -13
- data/lib/puppet/type/service.rb +9 -6
- data/lib/puppet/type/stage.rb +17 -9
- data/lib/puppet/type/user.rb +1 -1
- data/lib/puppet/util/monkey_patches.rb +16 -11
- data/lib/puppet/util/rdoc/code_objects.rb +4 -0
- data/lib/puppet/util/windows.rb +1 -0
- data/lib/puppet/util/windows/file.rb +36 -13
- data/lib/puppet/util/windows/process.rb +7 -4
- data/lib/puppet/util/windows/registry.rb +35 -1
- data/lib/puppet/util/windows/string.rb +14 -0
- data/lib/puppet/version.rb +1 -1
- data/spec/integration/util_spec.rb +31 -0
- data/spec/unit/node/environment_spec.rb +5 -13
- data/spec/unit/provider/package/aptitude_spec.rb +13 -10
- data/spec/unit/provider/package/aptrpm_spec.rb +2 -2
- data/spec/unit/provider/package/dpkg_spec.rb +93 -234
- data/spec/unit/provider/package/rpm_spec.rb +50 -74
- data/spec/unit/provider/package/yum_spec.rb +5 -6
- data/spec/unit/transaction/resource_harness_spec.rb +111 -3
- data/spec/unit/type/user_spec.rb +7 -5
- data/spec/unit/util/windows/registry_spec.rb +54 -0
- data/spec/unit/util/windows/string_spec.rb +54 -0
- data/tasks/benchmark.rake +110 -0
- data/tasks/ci.rake +1 -1
- metadata +11 -15
data/lib/puppet/type/file.rb
CHANGED
@@ -369,6 +369,10 @@ Puppet::Type.newtype(:file) do
|
|
369
369
|
stat ? true : false
|
370
370
|
end
|
371
371
|
|
372
|
+
def present?(current_values)
|
373
|
+
super && current_values[:ensure] != :false
|
374
|
+
end
|
375
|
+
|
372
376
|
# We have to do some extra finishing, to retrieve our bucket if
|
373
377
|
# there is one.
|
374
378
|
def finish
|
data/lib/puppet/type/mount.rb
CHANGED
@@ -7,8 +7,10 @@ module Puppet
|
|
7
7
|
information into the mount table. The actual behavior depends
|
8
8
|
on the value of the 'ensure' parameter.
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
**Refresh:** `mount` resources can respond to refresh events (via
|
11
|
+
`notify`, `subscribe`, or the `~>` arrow). If a `mount` receives an event
|
12
|
+
from another resource **and** its `ensure` attribute is set to `mounted`,
|
13
|
+
Puppet will try to unmount then remount that filesystem.
|
12
14
|
|
13
15
|
**Autorequires:** If Puppet is managing any parents of a mount resource ---
|
14
16
|
that is, other mount points higher up in the filesystem --- the child
|
data/lib/puppet/type/package.rb
CHANGED
data/lib/puppet/type/schedule.rb
CHANGED
@@ -52,16 +52,16 @@ module Puppet
|
|
52
52
|
|
53
53
|
newparam(:name) do
|
54
54
|
desc <<-EOT
|
55
|
-
The name of the schedule. This name is used
|
56
|
-
|
55
|
+
The name of the schedule. This name is used when assigning the schedule
|
56
|
+
to a resource with the `schedule` metaparameter:
|
57
57
|
|
58
|
-
schedule { '
|
58
|
+
schedule { 'everyday':
|
59
59
|
period => daily,
|
60
60
|
range => "2 - 4",
|
61
61
|
}
|
62
62
|
|
63
63
|
exec { "/usr/bin/apt-get update":
|
64
|
-
schedule => '
|
64
|
+
schedule => 'everyday',
|
65
65
|
}
|
66
66
|
|
67
67
|
EOT
|
@@ -236,8 +236,8 @@ module Puppet
|
|
236
236
|
|
237
237
|
newparam(:period) do
|
238
238
|
desc <<-EOT
|
239
|
-
The period of repetition for
|
240
|
-
to get applied every time Puppet runs.
|
239
|
+
The period of repetition for resources on this schedule. The default is
|
240
|
+
for resources to get applied every time Puppet runs.
|
241
241
|
|
242
242
|
Note that the period defines how often a given resource will get
|
243
243
|
applied but not when; if you would like to restrict the hours
|
@@ -256,10 +256,11 @@ module Puppet
|
|
256
256
|
|
257
257
|
This can cause Puppet to apply that resource up to every 10 minutes.
|
258
258
|
|
259
|
-
At the moment, Puppet cannot guarantee that level of
|
260
|
-
|
261
|
-
|
262
|
-
|
259
|
+
At the moment, Puppet cannot guarantee that level of repetition; that
|
260
|
+
is, the resource can applied _up to_ every 10 minutes, but internal
|
261
|
+
factors might prevent it from actually running that often (e.g. if a
|
262
|
+
Puppet run is still in progress when the next run is scheduled to start,
|
263
|
+
that next run will be suppressed).
|
263
264
|
|
264
265
|
See the `periodmatch` attribute for tuning whether to match
|
265
266
|
times by their distance apart or by their specific value.
|
@@ -347,9 +348,9 @@ module Puppet
|
|
347
348
|
The days of the week in which the schedule should be valid.
|
348
349
|
You may specify the full day name (Tuesday), the three character
|
349
350
|
abbreviation (Tue), or a number corresponding to the day of the
|
350
|
-
week where 0 is Sunday, 1 is Monday, etc.
|
351
|
-
|
352
|
-
|
351
|
+
week where 0 is Sunday, 1 is Monday, etc. Multiple days can be specified
|
352
|
+
as an array. If not specified, the day of the week will not be
|
353
|
+
considered in the schedule.
|
353
354
|
|
354
355
|
If you are also using a range match that spans across midnight
|
355
356
|
then this parameter will match the day that it was at the start
|
data/lib/puppet/type/service.rb
CHANGED
@@ -19,12 +19,15 @@ module Puppet
|
|
19
19
|
need to set `hasstatus` to false and possibly specify a custom status
|
20
20
|
command in the `status` attribute.
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
**Refresh:** `service` resources can respond to refresh events (via
|
23
|
+
`notify`, `subscribe`, or the `~>` arrow). If a `service` receives an
|
24
|
+
event from another resource, Puppet will restart the service it manages.
|
25
|
+
The actual command used to restart the service depends on the platform and
|
26
|
+
can be configured:
|
27
|
+
|
28
|
+
* If you set `hasrestart` to true, Puppet will use the init script's restart command.
|
29
|
+
* You can provide an explicit command for restarting with the `restart` attribute.
|
30
|
+
* If you do neither, the service's stop and start commands will be used."
|
28
31
|
|
29
32
|
feature :refreshable, "The provider can restart the service.",
|
30
33
|
:methods => [:restart]
|
data/lib/puppet/type/stage.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
1
1
|
Puppet::Type.newtype(:stage) do
|
2
|
-
desc "A resource type for
|
3
|
-
|
2
|
+
desc "A resource type for creating new run stages. Once a stage is available,
|
3
|
+
classes can be assigned to it by declaring them with the resource-like syntax
|
4
|
+
and using
|
5
|
+
[the `stage` metaparameter](http://docs.puppetlabs.com/references/latest/metaparameter.html#stage).
|
4
6
|
|
5
|
-
|
7
|
+
Note that new stages are not useful unless you also declare their order
|
8
|
+
in relation to the default `main` stage.
|
6
9
|
|
7
|
-
|
10
|
+
A complete run stage example:
|
8
11
|
|
9
|
-
|
12
|
+
stage { 'pre':
|
13
|
+
before => Stage['main'],
|
14
|
+
}
|
10
15
|
|
11
|
-
|
12
|
-
|
16
|
+
class { 'apt-updates':
|
17
|
+
stage => 'pre',
|
18
|
+
}
|
13
19
|
|
14
|
-
|
20
|
+
Individual resources cannot be assigned to run stages; you can only set stages
|
21
|
+
for classes."
|
15
22
|
|
16
23
|
newparam :name do
|
17
|
-
desc "The name of the stage.
|
24
|
+
desc "The name of the stage. Use this as the value for the `stage` metaparameter
|
25
|
+
when assigning classes to this stage."
|
18
26
|
end
|
19
27
|
end
|
data/lib/puppet/type/user.rb
CHANGED
@@ -165,7 +165,7 @@ module Puppet
|
|
165
165
|
newproperty(:comment) do
|
166
166
|
desc "A description of the user. Generally the user's full name."
|
167
167
|
munge do |v|
|
168
|
-
v.respond_to?(:
|
168
|
+
v.respond_to?(:force_encoding) ? v.force_encoding(Encoding::ASCII_8BIT) : v
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -67,19 +67,24 @@ class Object
|
|
67
67
|
end
|
68
68
|
|
69
69
|
class Symbol
|
70
|
-
# So, it turns out that one of the biggest memory allocation hot-spots in
|
71
|
-
#
|
72
|
-
#
|
70
|
+
# So, it turns out that one of the biggest memory allocation hot-spots in our
|
71
|
+
# code was using symbol-to-proc - because it allocated a new instance every
|
72
|
+
# time it was called, rather than caching (in Ruby 1.8.7 and earlier).
|
73
|
+
#
|
74
|
+
# In Ruby 1.9.3 and later Symbol#to_proc does implement a cache so we skip
|
75
|
+
# our monkey patch.
|
73
76
|
#
|
74
77
|
# Changing this means we can see XX memory reduction...
|
75
|
-
if
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
if RUBY_VERSION < "1.9.3"
|
79
|
+
if method_defined? :to_proc
|
80
|
+
alias __original_to_proc to_proc
|
81
|
+
def to_proc
|
82
|
+
@my_proc ||= __original_to_proc
|
83
|
+
end
|
84
|
+
else
|
85
|
+
def to_proc
|
86
|
+
@my_proc ||= Proc.new {|*args| args.shift.__send__(self, *args) }
|
87
|
+
end
|
83
88
|
end
|
84
89
|
end
|
85
90
|
|
data/lib/puppet/util/windows.rb
CHANGED
@@ -6,6 +6,7 @@ module Puppet::Util::Windows
|
|
6
6
|
require 'puppet/util/windows/security'
|
7
7
|
require 'puppet/util/windows/user'
|
8
8
|
require 'puppet/util/windows/process'
|
9
|
+
require 'puppet/util/windows/string'
|
9
10
|
require 'puppet/util/windows/file'
|
10
11
|
require 'puppet/util/windows/root_certs'
|
11
12
|
require 'puppet/util/windows/access_control_entry'
|
@@ -3,22 +3,31 @@ require 'puppet/util/windows'
|
|
3
3
|
module Puppet::Util::Windows::File
|
4
4
|
require 'ffi'
|
5
5
|
require 'windows/api'
|
6
|
-
require 'windows/wide_string'
|
7
6
|
|
8
|
-
ReplaceFileWithoutBackupW = Windows::API.new('ReplaceFileW', 'PPVLVV', 'B')
|
9
7
|
def replace_file(target, source)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
target_encoded = Puppet::Util::Windows::String.wide_string(target.to_s)
|
9
|
+
source_encoded = Puppet::Util::Windows::String.wide_string(source.to_s)
|
10
|
+
|
11
|
+
flags = 0x1
|
12
|
+
backup_file = nil
|
13
|
+
result = API.replace_file(
|
14
|
+
target_encoded,
|
15
|
+
source_encoded,
|
16
|
+
backup_file,
|
17
|
+
flags,
|
18
|
+
0,
|
19
|
+
0
|
20
|
+
)
|
21
|
+
|
22
|
+
return true if result
|
14
23
|
raise Puppet::Util::Windows::Error.new("ReplaceFile(#{target}, #{source})")
|
15
24
|
end
|
16
25
|
module_function :replace_file
|
17
26
|
|
18
27
|
MoveFileEx = Windows::API.new('MoveFileExW', 'PPL', 'B')
|
19
28
|
def move_file_ex(source, target, flags = 0)
|
20
|
-
result = MoveFileEx.call(
|
21
|
-
|
29
|
+
result = MoveFileEx.call(Puppet::Util::Windows::String.wide_string(source.to_s),
|
30
|
+
Puppet::Util::Windows::String.wide_string(target.to_s),
|
22
31
|
flags)
|
23
32
|
return true unless result == 0
|
24
33
|
raise Puppet::Util::Windows::Error.
|
@@ -31,6 +40,20 @@ module Puppet::Util::Windows::File
|
|
31
40
|
ffi_lib 'kernel32'
|
32
41
|
ffi_convention :stdcall
|
33
42
|
|
43
|
+
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa365512(v=vs.85).aspx
|
44
|
+
# BOOL WINAPI ReplaceFile(
|
45
|
+
# _In_ LPCTSTR lpReplacedFileName,
|
46
|
+
# _In_ LPCTSTR lpReplacementFileName,
|
47
|
+
# _In_opt_ LPCTSTR lpBackupFileName,
|
48
|
+
# _In_ DWORD dwReplaceFlags - 0x1 REPLACEFILE_WRITE_THROUGH,
|
49
|
+
# 0x2 REPLACEFILE_IGNORE_MERGE_ERRORS,
|
50
|
+
# 0x4 REPLACEFILE_IGNORE_ACL_ERRORS
|
51
|
+
# _Reserved_ LPVOID lpExclude,
|
52
|
+
# _Reserved_ LPVOID lpReserved
|
53
|
+
# );
|
54
|
+
attach_function :replace_file, :ReplaceFileW,
|
55
|
+
[:buffer_in, :buffer_in, :buffer_in, :uint, :uint, :uint], :bool
|
56
|
+
|
34
57
|
# BOOLEAN WINAPI CreateSymbolicLink(
|
35
58
|
# _In_ LPTSTR lpSymlinkFileName, - symbolic link to be created
|
36
59
|
# _In_ LPTSTR lpTargetFileName, - name of target for symbolic link
|
@@ -102,8 +125,8 @@ module Puppet::Util::Windows::File
|
|
102
125
|
|
103
126
|
def symlink(target, symlink)
|
104
127
|
flags = File.directory?(target) ? 0x1 : 0x0
|
105
|
-
result = API.create_symbolic_link(
|
106
|
-
|
128
|
+
result = API.create_symbolic_link(Puppet::Util::Windows::String.wide_string(symlink.to_s),
|
129
|
+
Puppet::Util::Windows::String.wide_string(target.to_s), flags)
|
107
130
|
return true if result
|
108
131
|
raise Puppet::Util::Windows::Error.new(
|
109
132
|
"CreateSymbolicLink(#{symlink}, #{target}, #{flags.to_s(8)})")
|
@@ -112,7 +135,7 @@ module Puppet::Util::Windows::File
|
|
112
135
|
|
113
136
|
INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF #define INVALID_FILE_ATTRIBUTES (DWORD (-1))
|
114
137
|
def self.get_file_attributes(file_name)
|
115
|
-
result = API.get_file_attributes(
|
138
|
+
result = API.get_file_attributes(Puppet::Util::Windows::String.wide_string(file_name.to_s))
|
116
139
|
return result unless result == INVALID_FILE_ATTRIBUTES
|
117
140
|
raise Puppet::Util::Windows::Error.new("GetFileAttributes(#{file_name})")
|
118
141
|
end
|
@@ -121,7 +144,7 @@ module Puppet::Util::Windows::File
|
|
121
144
|
def self.create_file(file_name, desired_access, share_mode, security_attributes,
|
122
145
|
creation_disposition, flags_and_attributes, template_file_handle)
|
123
146
|
|
124
|
-
result = API.create_file(
|
147
|
+
result = API.create_file(Puppet::Util::Windows::String.wide_string(file_name.to_s),
|
125
148
|
desired_access, share_mode, security_attributes, creation_disposition,
|
126
149
|
flags_and_attributes, template_file_handle)
|
127
150
|
|
@@ -173,7 +196,7 @@ module Puppet::Util::Windows::File
|
|
173
196
|
def self.open_symlink(link_name)
|
174
197
|
begin
|
175
198
|
yield handle = create_file(
|
176
|
-
|
199
|
+
Puppet::Util::Windows::String.wide_string(link_name.to_s),
|
177
200
|
GENERIC_READ,
|
178
201
|
FILE_SHARE_READ,
|
179
202
|
nil, # security_attributes
|
@@ -52,8 +52,8 @@ module Puppet::Util::Windows::Process
|
|
52
52
|
# _In_ LPCTSTR lpName,
|
53
53
|
# _Out_ PLUID lpLuid
|
54
54
|
# );
|
55
|
-
attach_function :lookup_privilege_value, :
|
56
|
-
[:
|
55
|
+
attach_function :lookup_privilege_value, :LookupPrivilegeValueA,
|
56
|
+
[:string, :string, :pointer], :bool
|
57
57
|
|
58
58
|
Token_Information = enum(
|
59
59
|
:token_user, 1,
|
@@ -169,8 +169,11 @@ module Puppet::Util::Windows::Process
|
|
169
169
|
|
170
170
|
def lookup_privilege_value(name, system_name = '')
|
171
171
|
luid = FFI::MemoryPointer.new(API::LUID.size)
|
172
|
-
result = API.lookup_privilege_value(
|
173
|
-
|
172
|
+
result = API.lookup_privilege_value(
|
173
|
+
system_name,
|
174
|
+
name.to_s,
|
175
|
+
luid
|
176
|
+
)
|
174
177
|
|
175
178
|
return API::LUID.new(luid) if result
|
176
179
|
raise Puppet::Util::Windows::Error.new(
|
@@ -29,8 +29,42 @@ module Puppet::Util::Windows
|
|
29
29
|
|
30
30
|
def values(subkey)
|
31
31
|
values = {}
|
32
|
-
subkey.each_value
|
32
|
+
subkey.each_value do |name, type, data|
|
33
|
+
case type
|
34
|
+
when Win32::Registry::REG_MULTI_SZ
|
35
|
+
data.each { |str| force_encoding(str) }
|
36
|
+
when Win32::Registry::REG_SZ, Win32::Registry::REG_EXPAND_SZ
|
37
|
+
force_encoding(data)
|
38
|
+
end
|
39
|
+
values[name] = data
|
40
|
+
end
|
33
41
|
values
|
34
42
|
end
|
43
|
+
|
44
|
+
if defined?(Encoding)
|
45
|
+
def force_encoding(str)
|
46
|
+
if @encoding.nil?
|
47
|
+
# See https://bugs.ruby-lang.org/issues/8943
|
48
|
+
# Ruby uses ANSI versions of Win32 APIs to read values from the
|
49
|
+
# registry. The encoding of these strings depends on the active
|
50
|
+
# code page. However, ruby incorrectly sets the string
|
51
|
+
# encoding to US-ASCII. So we must force the encoding to the
|
52
|
+
# correct value.
|
53
|
+
require 'windows/national'
|
54
|
+
begin
|
55
|
+
cp = Windows::National::GetACP.call
|
56
|
+
@encoding = Encoding.const_get("CP#{cp}")
|
57
|
+
rescue
|
58
|
+
@encoding = Encoding.default_external
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
str.force_encoding(@encoding)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
def force_encoding(str, enc)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
private :force_encoding
|
35
69
|
end
|
36
70
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'puppet/util/windows'
|
2
|
+
|
3
|
+
module Puppet::Util::Windows::String
|
4
|
+
def wide_string(str)
|
5
|
+
# ruby (< 2.1) does not respect multibyte terminators, so it is possible
|
6
|
+
# for a string to contain a single trailing null byte, followed by garbage
|
7
|
+
# causing buffer overruns.
|
8
|
+
#
|
9
|
+
# See http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=41920&view=revision
|
10
|
+
newstr = str + "\0".encode(str.encoding)
|
11
|
+
newstr.encode!('UTF-16LE')
|
12
|
+
end
|
13
|
+
module_function :wide_string
|
14
|
+
end
|
data/lib/puppet/version.rb
CHANGED
@@ -77,4 +77,35 @@ describe Puppet::Util do
|
|
77
77
|
new_sd.dacl.should == expected_sd.dacl
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
it "replace_file should work with filenames that include - and . (PUP-1389)", :if => Puppet.features.microsoft_windows? do
|
82
|
+
expected_content = 'some content'
|
83
|
+
dir = tmpdir('ReplaceFile_playground')
|
84
|
+
destination_file = File.join(dir, 'some-file.xml')
|
85
|
+
|
86
|
+
Puppet::Util.replace_file(destination_file, nil) do |temp_file|
|
87
|
+
temp_file.open
|
88
|
+
temp_file.write(expected_content)
|
89
|
+
end
|
90
|
+
|
91
|
+
actual_content = File.read(destination_file)
|
92
|
+
actual_content.should == expected_content
|
93
|
+
end
|
94
|
+
|
95
|
+
it "replace_file should work with filenames that include special characters (PUP-1389)", :if => Puppet.features.microsoft_windows? do
|
96
|
+
expected_content = 'some content'
|
97
|
+
dir = tmpdir('ReplaceFile_playground')
|
98
|
+
# http://www.fileformat.info/info/unicode/char/00e8/index.htm
|
99
|
+
# dest_name = "somèfile.xml"
|
100
|
+
dest_name = "som\u00E8file.xml"
|
101
|
+
destination_file = File.join(dir, dest_name)
|
102
|
+
|
103
|
+
Puppet::Util.replace_file(destination_file, nil) do |temp_file|
|
104
|
+
temp_file.open
|
105
|
+
temp_file.write(expected_content)
|
106
|
+
end
|
107
|
+
|
108
|
+
actual_content = File.read(destination_file)
|
109
|
+
actual_content.should == expected_content
|
110
|
+
end
|
80
111
|
end
|