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
@@ -51,7 +51,6 @@ describe Puppet::Node::Environment do
|
|
51
51
|
before do
|
52
52
|
@collection = Puppet::Resource::TypeCollection.new(env)
|
53
53
|
env.stubs(:perform_initial_import).returns(Puppet::Parser::AST::Hostclass.new(''))
|
54
|
-
$known_resource_types = nil
|
55
54
|
end
|
56
55
|
|
57
56
|
it "should create a resource type collection if none exists" do
|
@@ -75,18 +74,13 @@ describe Puppet::Node::Environment do
|
|
75
74
|
env.known_resource_types.should equal(@collection)
|
76
75
|
end
|
77
76
|
|
78
|
-
it "should return the current thread associated collection if there is one" do
|
79
|
-
$known_resource_types = @collection
|
80
|
-
|
81
|
-
env.known_resource_types.should equal(@collection)
|
82
|
-
end
|
83
|
-
|
84
77
|
it "should generate a new TypeCollection if the current one requires reparsing" do
|
85
78
|
old_type_collection = env.known_resource_types
|
86
79
|
old_type_collection.stubs(:require_reparse?).returns true
|
87
|
-
$known_resource_types = nil
|
88
|
-
new_type_collection = env.known_resource_types
|
89
80
|
|
81
|
+
env.check_for_reparse
|
82
|
+
|
83
|
+
new_type_collection = env.known_resource_types
|
90
84
|
new_type_collection.should be_a Puppet::Resource::TypeCollection
|
91
85
|
new_type_collection.should_not equal(old_type_collection)
|
92
86
|
end
|
@@ -416,10 +410,9 @@ describe Puppet::Node::Environment do
|
|
416
410
|
|
417
411
|
it "should fail helpfully if there is an error importing" do
|
418
412
|
Puppet::FileSystem::File.stubs(:exist?).returns true
|
419
|
-
env.stubs(:known_resource_types).returns Puppet::Resource::TypeCollection.new(env)
|
420
413
|
@parser.expects(:file=).once
|
421
414
|
@parser.expects(:parse).raises ArgumentError
|
422
|
-
lambda { env.
|
415
|
+
lambda { env.known_resource_types }.should raise_error(Puppet::Error)
|
423
416
|
end
|
424
417
|
|
425
418
|
it "should not do anything if the ignore_import settings is set" do
|
@@ -432,9 +425,8 @@ describe Puppet::Node::Environment do
|
|
432
425
|
|
433
426
|
it "should mark the type collection as needing a reparse when there is an error parsing" do
|
434
427
|
@parser.expects(:parse).raises Puppet::ParseError.new("Syntax error at ...")
|
435
|
-
env.stubs(:known_resource_types).returns Puppet::Resource::TypeCollection.new(env)
|
436
428
|
|
437
|
-
lambda { env.
|
429
|
+
lambda { env.known_resource_types }.should raise_error(Puppet::Error, /Syntax error at .../)
|
438
430
|
env.known_resource_types.require_reparse?.should be_true
|
439
431
|
end
|
440
432
|
end
|
@@ -10,24 +10,27 @@ describe Puppet::Type.type(:package).provider(:aptitude) do
|
|
10
10
|
it { should be_versionable }
|
11
11
|
|
12
12
|
context "when retrieving ensure" do
|
13
|
+
let(:dpkgquery_path) { '/bin/dpkg-query' }
|
14
|
+
|
13
15
|
before do
|
14
|
-
|
16
|
+
Puppet::Util.stubs(:which).with('/usr/bin/dpkg-query').returns(dpkgquery_path)
|
15
17
|
end
|
16
18
|
|
17
|
-
{ :absent => "deinstall ok config-files faff 1.2.3-1
|
18
|
-
"1.2.3-1" => "install ok installed faff 1.2.3-1
|
19
|
+
{ :absent => "deinstall ok config-files faff 1.2.3-1\n",
|
20
|
+
"1.2.3-1" => "install ok installed faff 1.2.3-1\n",
|
19
21
|
}.each do |expect, output|
|
20
|
-
it "
|
21
|
-
Puppet::Util::Execution.expects(:
|
22
|
-
|
23
|
-
|
22
|
+
it "detects #{expect} packages" do
|
23
|
+
Puppet::Util::Execution.expects(:execute).with(
|
24
|
+
[dpkgquery_path, '-W', '--showformat', "'${Status} ${Package} ${Version}\\n'", 'faff'],
|
25
|
+
{:failonfail => true, :combine => true, :custom_environment => {}}
|
26
|
+
).returns(output)
|
24
27
|
|
25
|
-
pkg.property(:ensure).retrieve.
|
28
|
+
expect(pkg.property(:ensure).retrieve).to eq(expect)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
|
-
it "
|
33
|
+
it "installs when asked" do
|
31
34
|
pkg.provider.expects(:aptitude).
|
32
35
|
with('-y', '-o', 'DPkg::Options::=--force-confold', :install, 'faff').
|
33
36
|
returns(0)
|
@@ -35,7 +38,7 @@ describe Puppet::Type.type(:package).provider(:aptitude) do
|
|
35
38
|
pkg.provider.install
|
36
39
|
end
|
37
40
|
|
38
|
-
it "
|
41
|
+
it "purges when asked" do
|
39
42
|
pkg.provider.expects(:aptitude).with('-y', 'purge', 'faff').returns(0)
|
40
43
|
pkg.provider.purge
|
41
44
|
end
|
@@ -19,7 +19,7 @@ describe Puppet::Type.type(:package).provider(:aptrpm) do
|
|
19
19
|
def rpm
|
20
20
|
pkg.provider.expects(:rpm).
|
21
21
|
with('-q', 'faff', '--nosignature', '--nodigest', '--qf',
|
22
|
-
"%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}
|
22
|
+
"%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\\n")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should report absent packages" do
|
@@ -28,7 +28,7 @@ describe Puppet::Type.type(:package).provider(:aptrpm) do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should report present packages correctly" do
|
31
|
-
rpm.returns("faff-1.2.3-1 0 1.2.3-1 5 i686
|
31
|
+
rpm.returns("faff-1.2.3-1 0 1.2.3-1 5 i686\n")
|
32
32
|
pkg.property(:ensure).retrieve.should == "1.2.3-1-5"
|
33
33
|
end
|
34
34
|
end
|
@@ -6,100 +6,51 @@ provider_class = Puppet::Type.type(:package).provider(:dpkg)
|
|
6
6
|
|
7
7
|
describe provider_class do
|
8
8
|
let(:bash_version) { '4.2-5ubuntu3' }
|
9
|
-
let(:bash_installed_output)
|
10
|
-
install ok installed bash #{bash_version} :DESC: GNU Bourne Again SHell
|
11
|
-
Bash is an sh-compatible command language interpreter that executes
|
12
|
-
commands read from the standard input or from a file. Bash also
|
13
|
-
incorporates useful features from the Korn and C shells (ksh and csh).
|
14
|
-
.
|
15
|
-
Bash is ultimately intended to be a conformant implementation of the
|
16
|
-
IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).
|
17
|
-
.
|
18
|
-
The Programmable Completion Code, by Ian Macdonald, is now found in
|
19
|
-
the bash-completion package.
|
20
|
-
:DESC:
|
21
|
-
EOS
|
22
|
-
end
|
9
|
+
let(:bash_installed_output) { "install ok installed bash #{bash_version}\n" }
|
23
10
|
let(:bash_installed_io) { StringIO.new(bash_installed_output) }
|
24
|
-
|
25
|
-
let(:vim_installed_output) do <<-EOS
|
26
|
-
install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi editor
|
27
|
-
Vim is an almost compatible version of the UNIX editor Vi.
|
28
|
-
.
|
29
|
-
Many new features have been added: multi level undo, syntax
|
30
|
-
highlighting, command line history, on-line help, filename
|
31
|
-
completion, block operations, folding, Unicode support, etc.
|
32
|
-
.
|
33
|
-
This package contains a version of vim compiled with a rather
|
34
|
-
standard set of features. This package does not provide a GUI
|
35
|
-
version of Vim. See the other vim-* packages if you need more
|
36
|
-
(or less).
|
37
|
-
:DESC:
|
38
|
-
EOS
|
39
|
-
end
|
40
|
-
|
11
|
+
let(:vim_installed_output) { "install ok installed vim 2:7.3.547-6ubuntu5\n" }
|
41
12
|
let(:all_installed_io) { StringIO.new([bash_installed_output, vim_installed_output].join) }
|
42
|
-
let(:args) { ['
|
13
|
+
let(:args) { ['-W', '--showformat', %Q{'${Status} ${Package} ${Version}\\n'}] }
|
14
|
+
let(:execute_options) do
|
15
|
+
{:failonfail => true, :combine => true, :custom_environment => {}}
|
16
|
+
end
|
43
17
|
let(:resource_name) { 'package' }
|
44
18
|
let(:resource) { stub 'resource', :[] => resource_name }
|
45
19
|
let(:provider) { provider_class.new(resource) }
|
46
20
|
|
47
|
-
|
48
|
-
provider_class.stubs(:command).with(:dpkgquery).returns 'myquery'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should have documentation" do
|
21
|
+
it "has documentation" do
|
52
22
|
expect(provider_class.doc).to be_instance_of(String)
|
53
23
|
end
|
54
24
|
|
55
25
|
describe "when listing all instances" do
|
26
|
+
let(:execpipe_args) { args.unshift('myquery') }
|
56
27
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
provider_class.instances
|
28
|
+
before do
|
29
|
+
provider_class.stubs(:command).with(:dpkgquery).returns 'myquery'
|
61
30
|
end
|
62
31
|
|
63
|
-
it "
|
64
|
-
Puppet::Util::Execution.expects(:execpipe).with(
|
32
|
+
it "creates and return an instance for a single dpkg-query entry" do
|
33
|
+
Puppet::Util::Execution.expects(:execpipe).with(execpipe_args).yields bash_installed_io
|
65
34
|
|
66
35
|
installed = mock 'bash'
|
67
|
-
provider_class.expects(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :
|
36
|
+
provider_class.expects(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg).returns installed
|
68
37
|
|
69
38
|
expect(provider_class.instances).to eq([installed])
|
70
39
|
end
|
71
40
|
|
72
|
-
it "
|
73
|
-
Puppet::Util::Execution.expects(:execpipe).with(
|
41
|
+
it "parses multiple dpkg-query multi-line entries in the output" do
|
42
|
+
Puppet::Util::Execution.expects(:execpipe).with(execpipe_args).yields all_installed_io
|
74
43
|
|
75
44
|
bash = mock 'bash'
|
76
|
-
provider_class.expects(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :
|
45
|
+
provider_class.expects(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg).returns bash
|
77
46
|
vim = mock 'vim'
|
78
|
-
provider_class.expects(:new).with(:ensure => "2:7.3.547-6ubuntu5", :error => "ok", :desired => "install", :name => "vim", :status => "installed", :
|
47
|
+
provider_class.expects(:new).with(:ensure => "2:7.3.547-6ubuntu5", :error => "ok", :desired => "install", :name => "vim", :status => "installed", :provider => :dpkg).returns vim
|
79
48
|
|
80
49
|
expect(provider_class.instances).to eq([bash, vim])
|
81
50
|
end
|
82
51
|
|
83
|
-
it "
|
84
|
-
Puppet::Util::Execution.expects(:execpipe).with(
|
85
|
-
|
86
|
-
Puppet.expects(:warning)
|
87
|
-
provider_class.expects(:new).never
|
88
|
-
|
89
|
-
expect(provider_class.instances).to eq([])
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should not warn on extra multiline description lines which we are ignoring" do
|
93
|
-
Puppet::Util::Execution.expects(:execpipe).with(args).yields all_installed_io
|
94
|
-
|
95
|
-
Puppet.expects(:warning).never
|
96
|
-
provider_class.instances
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should warn if encounters bad lines between good entries without failing" do
|
100
|
-
Puppet::Util::Execution.expects(:execpipe).with(args).yields StringIO.new([bash_installed_output, "foobar\n", vim_installed_output].join)
|
101
|
-
|
102
|
-
Puppet.expects(:warning)
|
52
|
+
it "continues without failing if it encounters bad lines between good entries" do
|
53
|
+
Puppet::Util::Execution.expects(:execpipe).with(execpipe_args).yields StringIO.new([bash_installed_output, "foobar\n", vim_installed_output].join)
|
103
54
|
|
104
55
|
bash = mock 'bash'
|
105
56
|
vim = mock 'vim'
|
@@ -107,226 +58,134 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
|
|
107
58
|
|
108
59
|
expect(provider_class.instances).to eq([bash, vim])
|
109
60
|
end
|
110
|
-
|
111
|
-
it "should warn on a broken entry while still parsing a good one" do
|
112
|
-
Puppet::Util::Execution.expects(:execpipe).with(args).yields StringIO.new([
|
113
|
-
bash_installed_output,
|
114
|
-
%Q{install ok installed broken 1.0 this shouldn't be here :DESC: broken description\n extra description\n:DESC:\n},
|
115
|
-
vim_installed_output,
|
116
|
-
].join)
|
117
|
-
|
118
|
-
Puppet.expects(:warning).times(3)
|
119
|
-
|
120
|
-
bash = mock('bash')
|
121
|
-
vim = mock('vim')
|
122
|
-
saved = mock('saved')
|
123
|
-
provider_class.expects(:new).twice.returns(bash, vim)
|
124
|
-
|
125
|
-
expect(provider_class.instances).to eq([bash, vim])
|
126
|
-
end
|
127
61
|
end
|
128
62
|
|
129
63
|
describe "when querying the current state" do
|
130
|
-
let(:
|
131
|
-
|
132
|
-
|
133
|
-
|
64
|
+
let(:dpkgquery_path) { '/bin/dpkg-query' }
|
65
|
+
let(:query_args) do
|
66
|
+
args.unshift(dpkgquery_path)
|
67
|
+
args.push(resource_name)
|
134
68
|
end
|
135
69
|
|
136
|
-
|
137
|
-
|
138
|
-
def replace_in_bash_output(search, replace)
|
139
|
-
StringIO.new(bash_installed_output.gsub(search, replace))
|
70
|
+
def dpkg_query_execution_returns(output)
|
71
|
+
Puppet::Util::Execution.expects(:execute).with(query_args, execute_options).returns(output)
|
140
72
|
end
|
141
73
|
|
142
|
-
|
143
|
-
Puppet::Util
|
144
|
-
|
145
|
-
provider.query
|
74
|
+
before do
|
75
|
+
Puppet::Util.stubs(:which).with('/usr/bin/dpkg-query').returns(dpkgquery_path)
|
146
76
|
end
|
147
77
|
|
148
|
-
it "
|
149
|
-
Puppet::Util::Execution.expects(:
|
78
|
+
it "considers the package purged if dpkg-query fails" do
|
79
|
+
Puppet::Util::Execution.expects(:execute).with(query_args, execute_options).raises Puppet::ExecutionFailure.new("eh")
|
150
80
|
|
151
81
|
expect(provider.query[:ensure]).to eq(:purged)
|
152
82
|
end
|
153
83
|
|
154
|
-
it "
|
155
|
-
|
84
|
+
it "returns a hash of the found package status for an installed package" do
|
85
|
+
dpkg_query_execution_returns(bash_installed_output)
|
156
86
|
|
157
|
-
expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg
|
87
|
+
expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg})
|
158
88
|
end
|
159
89
|
|
160
|
-
it "
|
161
|
-
|
90
|
+
it "considers the package absent if the dpkg-query result cannot be interpreted" do
|
91
|
+
dpkg_query_execution_returns('some-bad-data')
|
162
92
|
|
163
93
|
expect(provider.query[:ensure]).to eq(:absent)
|
164
94
|
end
|
165
95
|
|
166
|
-
it "
|
167
|
-
|
96
|
+
it "fails if an error is discovered" do
|
97
|
+
dpkg_query_execution_returns(bash_installed_output.gsub("ok","error"))
|
168
98
|
|
169
99
|
expect { provider.query }.to raise_error(Puppet::Error)
|
170
100
|
end
|
171
101
|
|
172
|
-
it "
|
102
|
+
it "considers the package purged if it is marked 'not-installed'" do
|
173
103
|
not_installed_bash = bash_installed_output.gsub("installed", "not-installed")
|
174
104
|
not_installed_bash.gsub!(bash_version, "")
|
175
|
-
|
105
|
+
dpkg_query_execution_returns(not_installed_bash)
|
176
106
|
|
177
107
|
expect(provider.query[:ensure]).to eq(:purged)
|
178
108
|
end
|
179
109
|
|
180
|
-
it "
|
181
|
-
|
110
|
+
it "considers the package absent if it is marked 'config-files'" do
|
111
|
+
dpkg_query_execution_returns(bash_installed_output.gsub("installed","config-files"))
|
182
112
|
expect(provider.query[:ensure]).to eq(:absent)
|
183
113
|
end
|
184
114
|
|
185
|
-
it "
|
186
|
-
|
115
|
+
it "considers the package absent if it is marked 'half-installed'" do
|
116
|
+
dpkg_query_execution_returns(bash_installed_output.gsub("installed","half-installed"))
|
187
117
|
expect(provider.query[:ensure]).to eq(:absent)
|
188
118
|
end
|
189
119
|
|
190
|
-
it "
|
191
|
-
|
120
|
+
it "considers the package absent if it is marked 'unpacked'" do
|
121
|
+
dpkg_query_execution_returns(bash_installed_output.gsub("installed","unpacked"))
|
192
122
|
expect(provider.query[:ensure]).to eq(:absent)
|
193
123
|
end
|
194
124
|
|
195
|
-
it "
|
196
|
-
|
125
|
+
it "considers the package absent if it is marked 'half-configured'" do
|
126
|
+
dpkg_query_execution_returns(bash_installed_output.gsub("installed","half-configured"))
|
197
127
|
expect(provider.query[:ensure]).to eq(:absent)
|
198
128
|
end
|
199
129
|
|
200
|
-
it "
|
201
|
-
|
130
|
+
it "considers the package held if its state is 'hold'" do
|
131
|
+
dpkg_query_execution_returns(bash_installed_output.gsub("install","hold"))
|
202
132
|
expect(provider.query[:ensure]).to eq(:held)
|
203
133
|
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "parsing tests" do
|
207
|
-
let(:resource_name) { 'name' }
|
208
|
-
let(:package_hash) do
|
209
|
-
{
|
210
|
-
:desired => 'desired',
|
211
|
-
:error => 'ok',
|
212
|
-
:status => 'status',
|
213
|
-
:name => resource_name,
|
214
|
-
:ensure => 'ensure',
|
215
|
-
:description => 'summary text',
|
216
|
-
:provider => :dpkg,
|
217
|
-
}
|
218
|
-
end
|
219
|
-
let(:query_args) { args.push(resource_name) }
|
220
|
-
|
221
|
-
it "warns about excess lines if encounters a delimiter in description but does not fail" do
|
222
|
-
broken_description = <<-EOS
|
223
|
-
desired ok status name ensure :DESC: summary text
|
224
|
-
more description
|
225
|
-
:DESC:
|
226
|
-
1 whoops ^^ should not happen, because dpkg-query is supposed to prefix description lines with
|
227
|
-
2 whitespace. So we should see three warnings for these four additional lines when we try
|
228
|
-
3 and process next-pkg (vv the :DESC: is line number 4)
|
229
|
-
:DESC:
|
230
|
-
desired ok status next-pkg ensure :DESC: next summary
|
231
|
-
:DESC:
|
232
|
-
EOS
|
233
|
-
Puppet.expects(:warning).times(4)
|
234
|
-
|
235
|
-
pipe = StringIO.new(broken_description)
|
236
|
-
expect(provider_class.parse_multi_line(pipe)).to eq(package_hash)
|
237
|
-
|
238
|
-
next_package = package_hash.merge(:name => 'next-pkg', :description => 'next summary')
|
239
|
-
|
240
|
-
hash = provider_class.parse_multi_line(pipe) until hash # warn about bad lines
|
241
|
-
expect(hash).to eq(next_package)
|
242
|
-
end
|
243
|
-
|
244
|
-
def parser_test(dpkg_output_string, gold_hash)
|
245
|
-
pipe = StringIO.new(dpkg_output_string)
|
246
|
-
Puppet::Util::Execution.expects(:execpipe).with(query_args).yields pipe
|
247
|
-
Puppet.expects(:warning).never
|
248
|
-
|
249
|
-
expect(provider.query).to eq(gold_hash)
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should parse properly even if delimiter is in version" do
|
253
|
-
version_delimiter = <<-EOS
|
254
|
-
desired ok status name 1.2.3-:DESC: :DESC: summary text
|
255
|
-
more description
|
256
|
-
:DESC:
|
257
|
-
EOS
|
258
|
-
parser_test(version_delimiter, package_hash.merge(:ensure => '1.2.3-:DESC:'))
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should parse properly even if delimiter is name" do
|
262
|
-
name_delimiter = <<-EOS
|
263
|
-
desired ok status :DESC: ensure :DESC: summary text
|
264
|
-
more description
|
265
|
-
:DESC:
|
266
|
-
EOS
|
267
|
-
parser_test(name_delimiter, package_hash.merge(:name => ':DESC:'))
|
268
|
-
end
|
269
134
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
:
|
275
|
-
|
276
|
-
|
277
|
-
|
135
|
+
describe "parsing tests" do
|
136
|
+
let(:resource_name) { 'name' }
|
137
|
+
let(:package_hash) do
|
138
|
+
{
|
139
|
+
:desired => 'desired',
|
140
|
+
:error => 'ok',
|
141
|
+
:status => 'status',
|
142
|
+
:name => resource_name,
|
143
|
+
:ensure => 'ensure',
|
144
|
+
:provider => :dpkg,
|
145
|
+
}
|
146
|
+
end
|
147
|
+
let(:package_not_found_hash) do
|
148
|
+
{:ensure => :purged, :status => 'missing', :name => resource_name, :error => 'ok'}
|
149
|
+
end
|
278
150
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
:DESC:
|
284
|
-
EOS
|
285
|
-
parser_test(extra_description_delimiter, package_hash)
|
286
|
-
end
|
151
|
+
def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
|
152
|
+
dpkg_query_execution_returns(dpkg_output_string)
|
153
|
+
Puppet.expects(:warning).never
|
154
|
+
Puppet.expects(:debug).times(number_of_debug_logs)
|
287
155
|
|
288
|
-
|
289
|
-
|
290
|
-
parser_test(no_description, package_hash.merge(:description => ''))
|
291
|
-
end
|
156
|
+
expect(provider.query).to eq(gold_hash)
|
157
|
+
end
|
292
158
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
Puppet::Util::Execution.expects(:execpipe).with(query_args).yields(pipe).raises(Puppet::ExecutionFailure.new('no package found'))
|
159
|
+
it "parses properly even if optional ensure field is missing" do
|
160
|
+
no_ensure = 'desired ok status name '
|
161
|
+
parser_test(no_ensure, package_hash.merge(:ensure => ''))
|
162
|
+
end
|
298
163
|
|
299
|
-
|
164
|
+
it "provides debug logging of unparsable lines" do
|
165
|
+
parser_test('an unexpected dpkg msg with an exit code of 0', package_not_found_hash.merge(:ensure => :absent), 1)
|
300
166
|
end
|
301
|
-
end
|
302
167
|
|
303
|
-
|
304
|
-
|
305
|
-
Puppet
|
306
|
-
pipe = StringIO.new("dpkg-query: no packages found matching non-existent-package")
|
307
|
-
Puppet::Util::Execution.expects(:execpipe).with(query_args).yields(pipe).raises(Puppet::ExecutionFailure.new('no package found'))
|
168
|
+
it "does not log if execution returns with non-zero exit code" do
|
169
|
+
Puppet::Util::Execution.expects(:execute).with(query_args, execute_options).raises Puppet::ExecutionFailure.new("failed")
|
170
|
+
Puppet::expects(:debug).never
|
308
171
|
|
309
|
-
expect(provider.query).to eq(
|
172
|
+
expect(provider.query).to eq(package_not_found_hash)
|
310
173
|
end
|
311
174
|
end
|
312
175
|
end
|
313
176
|
|
314
|
-
it "should be able to install" do
|
315
|
-
expect(provider).to respond_to(:install)
|
316
|
-
end
|
317
|
-
|
318
177
|
describe "when installing" do
|
319
178
|
before do
|
320
179
|
resource.stubs(:[]).with(:source).returns "mypkg"
|
321
180
|
end
|
322
181
|
|
323
|
-
it "
|
182
|
+
it "fails to install if no source is specified in the resource" do
|
324
183
|
resource.expects(:[]).with(:source).returns nil
|
325
184
|
|
326
185
|
expect { provider.install }.to raise_error(ArgumentError)
|
327
186
|
end
|
328
187
|
|
329
|
-
it "
|
188
|
+
it "uses 'dpkg -i' to install the package" do
|
330
189
|
resource.expects(:[]).with(:source).returns "mypackagefile"
|
331
190
|
provider.expects(:unhold)
|
332
191
|
provider.expects(:dpkg).with { |*command| command[-1] == "mypackagefile" and command[-2] == "-i" }
|
@@ -334,7 +193,7 @@ desired ok status name ensure :DESC: summary text
|
|
334
193
|
provider.install
|
335
194
|
end
|
336
195
|
|
337
|
-
it "
|
196
|
+
it "keeps old config files if told to do so" do
|
338
197
|
resource.expects(:[]).with(:configfiles).returns :keep
|
339
198
|
provider.expects(:unhold)
|
340
199
|
provider.expects(:dpkg).with { |*command| command[0] == "--force-confold" }
|
@@ -342,7 +201,7 @@ desired ok status name ensure :DESC: summary text
|
|
342
201
|
provider.install
|
343
202
|
end
|
344
203
|
|
345
|
-
it "
|
204
|
+
it "replaces old config files if told to do so" do
|
346
205
|
resource.expects(:[]).with(:configfiles).returns :replace
|
347
206
|
provider.expects(:unhold)
|
348
207
|
provider.expects(:dpkg).with { |*command| command[0] == "--force-confnew" }
|
@@ -350,7 +209,7 @@ desired ok status name ensure :DESC: summary text
|
|
350
209
|
provider.install
|
351
210
|
end
|
352
211
|
|
353
|
-
it "
|
212
|
+
it "ensures any hold is removed" do
|
354
213
|
provider.expects(:unhold).once
|
355
214
|
provider.expects(:dpkg)
|
356
215
|
provider.install
|
@@ -365,44 +224,44 @@ desired ok status name ensure :DESC: summary text
|
|
365
224
|
Tempfile.stubs(:new).returns tempfile
|
366
225
|
end
|
367
226
|
|
368
|
-
it "
|
227
|
+
it "installs first if holding" do
|
369
228
|
provider.stubs(:execute)
|
370
229
|
provider.expects(:install).once
|
371
230
|
provider.hold
|
372
231
|
end
|
373
232
|
|
374
|
-
it "
|
233
|
+
it "executes dpkg --set-selections when holding" do
|
375
234
|
provider.stubs(:install)
|
376
235
|
provider.expects(:execute).with([:dpkg, '--set-selections'], {:failonfail => false, :combine => false, :stdinfile => tempfile.path}).once
|
377
236
|
provider.hold
|
378
237
|
end
|
379
238
|
|
380
|
-
it "
|
239
|
+
it "executes dpkg --set-selections when unholding" do
|
381
240
|
provider.stubs(:install)
|
382
241
|
provider.expects(:execute).with([:dpkg, '--set-selections'], {:failonfail => false, :combine => false, :stdinfile => tempfile.path}).once
|
383
242
|
provider.hold
|
384
243
|
end
|
385
244
|
end
|
386
245
|
|
387
|
-
it "
|
246
|
+
it "uses :install to update" do
|
388
247
|
provider.expects(:install)
|
389
248
|
provider.update
|
390
249
|
end
|
391
250
|
|
392
251
|
describe "when determining latest available version" do
|
393
|
-
it "
|
252
|
+
it "returns the version found by dpkg-deb" do
|
394
253
|
resource.expects(:[]).with(:source).returns "myfile"
|
395
254
|
provider.expects(:dpkg_deb).with { |*command| command[-1] == "myfile" }.returns "package\t1.0"
|
396
255
|
expect(provider.latest).to eq("1.0")
|
397
256
|
end
|
398
257
|
|
399
|
-
it "
|
258
|
+
it "warns if the package file contains a different package" do
|
400
259
|
provider.expects(:dpkg_deb).returns("foo\tversion")
|
401
260
|
provider.expects(:warning)
|
402
261
|
provider.latest
|
403
262
|
end
|
404
263
|
|
405
|
-
it "
|
264
|
+
it "copes with names containing ++" do
|
406
265
|
resource = stub 'resource', :[] => "package++"
|
407
266
|
provider = provider_class.new(resource)
|
408
267
|
provider.expects(:dpkg_deb).returns "package++\t1.0"
|
@@ -410,12 +269,12 @@ desired ok status name ensure :DESC: summary text
|
|
410
269
|
end
|
411
270
|
end
|
412
271
|
|
413
|
-
it "
|
272
|
+
it "uses 'dpkg -r' to uninstall" do
|
414
273
|
provider.expects(:dpkg).with("-r", resource_name)
|
415
274
|
provider.uninstall
|
416
275
|
end
|
417
276
|
|
418
|
-
it "
|
277
|
+
it "uses 'dpkg --purge' to purge" do
|
419
278
|
provider.expects(:dpkg).with("--purge", resource_name)
|
420
279
|
provider.purge
|
421
280
|
end
|