Skip to content

Commit 868bf83

Browse files
committed
Merge remote-tracking branch 'upstream/stable'
* upstream/stable: (PUP-3248) Use tmpdir for generating environments (PUP-3248) Fix PMT tests for directory environment (maint) Remove the resource/host/should_query test (maint) Ensure config acceptance resets uid
2 parents 68075ab + 9e5b0f4 commit 868bf83

35 files changed

+295
-246
lines changed

acceptance/lib/puppet/acceptance/module_utils.rb

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@ module Puppet
22
module Acceptance
33
module ModuleUtils
44

5+
# Return an array of module paths for a given host.
6+
#
7+
# Example return value:
8+
#
9+
# [
10+
# "/etc/puppetlabs/puppet/environments/production/modules",
11+
# "/etc/puppetlabs/puppet/modules",
12+
# "/opt/puppet/share/puppet/modules",
13+
# ]
14+
#
15+
# @param host [String] hostname
16+
# @return [Array] paths for found modulepath
17+
def get_modulepaths_for_host (host)
18+
separator = ':'
19+
if host['platform'] =~ /windows/
20+
separator = ';'
21+
end
22+
environment = on(host, puppet("config print environment")).stdout.chomp
23+
on(host, puppet("config print modulepath --environment #{environment}")).stdout.chomp.split(separator)
24+
end
25+
26+
# Return a string of the default (first) path in modulepath for a given host.
27+
#
28+
# Example return value:
29+
#
30+
# "/etc/puppetlabs/puppet/environments/production/modules"
31+
#
32+
# @param host [String] hostname
33+
# @return [String] first path for found modulepath
34+
def get_default_modulepath_for_host (host)
35+
get_modulepaths_for_host(host)[0]
36+
end
37+
538
# Return an array of paths to installed modules for a given host.
639
#
740
# Example return value:
@@ -77,7 +110,7 @@ def rm_installed_modules_from_hosts (beginning_hash, ending_hash)
77110
ending_hash.each do |host, mod_array|
78111
mod_array.each do |mod|
79112
if ! beginning_hash[host].include? mod
80-
on host, "rm -rf #{mod}"
113+
on host, "rm -rf '#{mod}'"
81114
end
82115
end
83116
end
@@ -139,11 +172,21 @@ def assert_module_installed_ui ( stdout, module_author, module_name, module_vers
139172
# Assert that a module is installed on disk.
140173
#
141174
# @param host [HOST] the host object to make the remote call on
142-
# @param moduledir [String] the path where the module should be
143175
# @param module_name [String] the name portion of a module name
144-
def assert_module_installed_on_disk ( host, moduledir, module_name )
145-
# module directory should exist
146-
on host, %Q{[ -d "#{moduledir}/#{module_name}" ]}
176+
# @param optional moduledir [String, Array] the path where the module should be, will
177+
# iterate over components of the modulepath by default.
178+
def assert_module_installed_on_disk (host, module_name, moduledir=nil)
179+
moduledir ||= get_modulepaths_for_host(host)
180+
modulepath = moduledir.is_a?(Array) ? moduledir : [moduledir]
181+
moduledir= nil
182+
183+
modulepath.each do |i|
184+
# module directory should exist
185+
if on(host, %Q{[ -d "#{i}/#{module_name}" ]}, :acceptable_exit_codes => (0..255)).exit_code == 0
186+
moduledir = i
187+
end
188+
end
189+
fail_test('module directory not found') unless moduledir
147190

148191
owner = ''
149192
group = ''
@@ -172,10 +215,18 @@ def assert_module_installed_on_disk ( host, moduledir, module_name )
172215
# Assert that a module is not installed on disk.
173216
#
174217
# @param host [HOST] the host object to make the remote call on
175-
# @param moduledir [String] the path where the module should be
176218
# @param module_name [String] the name portion of a module name
177-
def assert_module_not_installed_on_disk ( host, moduledir, module_name )
178-
on host, %Q{[ ! -d "#{moduledir}/#{module_name}" ]}
219+
# @param optional moduledir [String, Array] the path where the module should be, will
220+
# iterate over components of the modulepath by default.
221+
def assert_module_not_installed_on_disk (host, module_name, moduledir=nil)
222+
moduledir ||= get_modulepaths_for_host(host)
223+
modulepath = moduledir.is_a?(Array) ? moduledir : [moduledir]
224+
moduledir= nil
225+
226+
modulepath.each do |i|
227+
# module directory should not exist
228+
on host, %Q{[ ! -d "#{i}/#{module_name}" ]}
229+
end
179230
end
180231

181232
# Create a simple legacy and directory environment at :path_to_environments.
@@ -216,6 +267,9 @@ def generate_base_legacy_and_directory_environments(path_to_environments)
216267
}
217268
}
218269

270+
# remove environmentpath entry from config
271+
on master, "sed '/environmentpath/d' #{puppet_conf} > #{path_to_environments}/tmp && mv #{path_to_environments}/tmp #{puppet_conf}"
272+
219273
on master, puppet("config", "set",
220274
"modulepath", "#{legacy_env}/modules",
221275
"--section", "legacyenv",

acceptance/tests/config/puppet_manages_own_configuration_in_robust_manner.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@
4545
# user and group ids back to the original uid and gid
4646
on master, 'rm -rf $(puppet master --configprint yamldir)'
4747

48+
if master.use_service_scripts?
49+
on(master, puppet('resource', 'service', master['puppetservice'], 'ensure=stopped'))
50+
end
51+
4852
hosts.each do |host|
49-
apply_manifest_on(host, <<-ORIG)
53+
apply_manifest_on(host, <<-ORIG, :catch_failures => true)
5054
#{original_state[host][:ug_resources]}
5155
ORIG
5256
end

acceptance/tests/modules/install/already_installed.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
end
1818

1919
step "Check that module is not installed" do
20-
on master, %Q{[ ! -d "#{master['distmoduledir']}/#{module_name}" ]}
20+
assert_module_not_installed_on_disk(master, module_name)
2121
end
2222

2323
step "Install module" do
2424
on master, puppet("module install #{module_reference}")
25-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
25+
assert_module_installed_on_disk(master, module_name)
2626
end
2727

2828
step "Try to install a module that is already installed" do
2929
on master, puppet("module install #{module_reference}"), :acceptable_exit_codes => [0] do
3030
assert_match(/#{module_reference}.*is already installed/, stdout,
3131
"Error that module was already installed was not displayed")
3232
end
33-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
33+
assert_module_installed_on_disk(master, module_name)
3434
end
3535

3636
step "Try to install a specific version of a module that is already installed" do
@@ -40,12 +40,12 @@
4040
assert_match(/#{module_reference}.*is already installed/, stderr,
4141
"Error that module was already installed was not displayed")
4242
end
43-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
43+
assert_module_installed_on_disk(master, module_name)
4444
end
4545

4646
step "Install a module that is already installed (with --force)" do
4747
on master, puppet("module install #{module_reference} --force") do
4848
assert_module_installed_ui(stdout, module_author, module_name)
4949
end
50-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
50+
assert_module_installed_on_disk(master, module_name)
5151
end

acceptance/tests/modules/install/already_installed_elsewhere.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
apply_manifest_on master, <<-PP
2020
file {
2121
[
22-
'#{master['distmoduledir']}',
2322
'#{master['sitemoduledir']}',
2423
'#{master['sitemoduledir']}/#{module_name}',
2524
]: ensure => directory;
@@ -35,12 +34,14 @@
3534
}
3635
PP
3736

37+
default_moduledir = get_default_modulepath_for_host(master)
38+
3839
step "Try to install a module that is already installed"
39-
on master, puppet("module install #{module_author}-#{module_name}"), :acceptable_exit_codes => [0] do
40+
on master, puppet("module install #{module_author}-#{module_name}") do
4041
assert_match(/#{module_reference}.*is already installed/, stdout,
4142
"Error that module was already installed was not displayed")
4243
end
43-
assert_module_not_installed_on_disk(master, master['distmoduledir'], module_name)
44+
assert_module_not_installed_on_disk(master, module_name, default_moduledir)
4445

4546
step "Try to install a specific version of a module that is already installed"
4647
on master, puppet("module install #{module_author}-#{module_name} --version 1.x"), :acceptable_exit_codes => [1] do
@@ -49,16 +50,16 @@
4950
assert_match(/#{module_author}-#{module_name}.*is already installed/, stderr,
5051
"Error that module was already installed was not displayed")
5152
end
52-
assert_module_not_installed_on_disk(master, master['distmoduledir'], module_name)
53+
assert_module_not_installed_on_disk(master, module_name, default_moduledir)
5354

5455
step "Install a specifc module version that is already installed (with --force)"
5556
on master, puppet("module install #{module_author}-#{module_name} --force --version 0.0.1") do
5657
assert_module_installed_ui(stdout, module_author, module_name, '0.0.1', '==')
5758
end
58-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
59+
assert_module_installed_on_disk(master, module_name, default_moduledir)
5960

6061
step "Install a module that is already installed (with --force)"
6162
on master, puppet("module install #{module_author}-#{module_name} --force") do
6263
assert_module_installed_ui(stdout, module_author, module_name)
6364
end
64-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
65+
assert_module_installed_on_disk(master, module_name, default_moduledir)

acceptance/tests/modules/install/already_installed_with_local_changes.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
module_author = "pmtacceptance"
66
module_name = "nginx"
77
module_reference = "#{module_author}-#{module_name}"
8-
module_path = "#{master['distmoduledir']}/#{module_name}"
98
module_dependencies = []
109

1110
orig_installed_modules = get_installed_modules_for_hosts hosts
@@ -18,15 +17,16 @@
1817
end
1918

2019
step "Check that module is not installed" do
21-
on master, %Q{[ ! -d "#{module_path}" ]}
20+
assert_module_not_installed_on_disk(master, module_name)
2221
end
2322

2423
step "Install module" do
2524
on master, puppet("module install #{module_reference}")
26-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
25+
assert_module_installed_on_disk(master, module_name)
2726
end
2827

2928
step "Make local changes in installed module" do
29+
module_path = "#{get_default_modulepath_for_host(master)}/#{module_name}"
3030
on master, "echo 'changed' >> #{module_path}/README"
3131
end
3232

@@ -39,13 +39,13 @@
3939
assert_match(/changes made locally/, stderr,
4040
"Error that module has local changes was not displayed")
4141
end
42-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
42+
assert_module_installed_on_disk(master, module_name)
4343
end
4444

4545
step "Install a module that is already installed (with --force)" do
4646
on master, puppet("module install #{module_reference} --force") do
4747
assert_module_installed_ui(stdout, module_author, module_name)
4848
end
49-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
49+
assert_module_installed_on_disk(master, module_name)
5050
#validate checksum
5151
end

acceptance/tests/modules/install/basic_install.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
step 'setup'
1616
stub_forge_on(agent)
1717

18-
distmoduledir = on(agent, puppet("agent", "--configprint", "confdir")).stdout.chomp + "/modules"
19-
2018
step "install module '#{module_author}-#{module_name}'"
2119
on(agent, puppet("module install #{module_author}-#{module_name}")) do
2220
assert_module_installed_ui(stdout, module_author, module_name)
2321
end
24-
assert_module_installed_on_disk(agent, distmoduledir, module_name)
22+
assert_module_installed_on_disk(agent, module_name)
2523
end

acceptance/tests/modules/install/force_ignores_dependencies.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
assert_match(/No version of '#{module_author}-#{module_name}' can satisfy all dependencies/, stderr,
2121
"Error that module dependencies could not be met was not displayed")
2222
end
23-
assert_module_not_installed_on_disk(master, master['distmoduledir'], module_name)
23+
assert_module_not_installed_on_disk(master, module_name)
2424
module_dependencies.each do |dependency|
25-
assert_module_not_installed_on_disk(master, master['distmoduledir'], dependency)
25+
assert_module_not_installed_on_disk(master, dependency)
2626
end
2727

2828
step "Install an unsatisfiable module with force"
2929
on master, puppet("module install #{module_author}-#{module_name} --force") do
3030
assert_module_installed_ui(stdout, module_author, module_name)
3131
end
32-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
32+
assert_module_installed_on_disk(master, module_name)
3333
module_dependencies.each do |dependency|
34-
assert_module_not_installed_on_disk(master, master['distmoduledir'], dependency)
34+
assert_module_not_installed_on_disk(master, dependency)
3535
end

acceptance/tests/modules/install/ignoring_dependencies.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
on master, puppet("module install #{module_author}-#{module_name} --ignore-dependencies") do
1919
assert_module_installed_ui(stdout, module_author, module_name)
2020
end
21-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
21+
assert_module_installed_on_disk(master, module_name)
2222
module_dependencies.each do |dependency|
23-
assert_module_not_installed_on_disk(master, master['distmoduledir'], dependency)
23+
assert_module_not_installed_on_disk(master, dependency)
2424
end

acceptance/tests/modules/install/nonexistent_directory.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
module_name = "nginx"
77
module_dependencies = []
88

9+
default_moduledir = get_default_modulepath_for_host(master)
10+
911
orig_installed_modules = get_installed_modules_for_hosts hosts
1012
teardown do
13+
on master, "mv #{default_moduledir}-bak #{default_moduledir}", :acceptable_exit_codes => [0, 1]
1114
rm_installed_modules_from_hosts orig_installed_modules, (get_installed_modules_for_hosts hosts)
1215
end
1316

@@ -23,14 +26,12 @@
2326
on master, puppet("module install #{module_author}-#{module_name} --target-dir /tmp/modules") do
2427
assert_module_installed_ui(stdout, module_author, module_name)
2528
end
26-
assert_module_installed_on_disk(master, '/tmp/modules', module_name)
29+
assert_module_installed_on_disk(master, module_name, '/tmp/modules')
2730

2831
step "Try to install a module to a non-existent implicit directory"
2932
# This test relies on destroying the default module directory...
30-
on master, "mv #{master['distmoduledir']} #{master['distmoduledir']}-bak"
33+
on master, "mv #{default_moduledir} #{default_moduledir}-bak"
3134
on master, puppet("module install #{module_author}-#{module_name}") do
3235
assert_module_installed_ui(stdout, module_author, module_name)
3336
end
34-
assert_module_installed_on_disk(master, master['distmoduledir'], module_name)
35-
# Restore default module directory...
36-
on master, "mv #{master['distmoduledir']}-bak #{master['distmoduledir']}"
37+
assert_module_installed_on_disk(master, module_name, default_moduledir)

acceptance/tests/modules/install/nonexistent_module.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
module_name = "nonexistent"
77
module_dependencies = []
88

9+
default_moduledir = get_default_modulepath_for_host(master)
10+
911
orig_installed_modules = get_installed_modules_for_hosts hosts
1012
teardown do
1113
rm_installed_modules_from_hosts orig_installed_modules, (get_installed_modules_for_hosts hosts)
@@ -36,7 +38,7 @@
3638
assert_equal 'failure', json['result']
3739
assert_equal "#{module_author}-#{module_name}", json['module_name']
3840
assert_equal '>= 0.0.0', json['module_version']
39-
assert_equal master['distmoduledir'], json['install_dir']
41+
assert_equal default_moduledir, json['install_dir']
4042
assert_match oneline_expectation, json['error']['oneline']
4143
assert_match multiline_expectation, json['error']['multiline']
4244
end

0 commit comments

Comments
 (0)