Skip to content

Commit 2f05918

Browse files
authored
Merge pull request #53 from caseywilliams/BKR-1484/platform-overrides
(BKR-1484) Packaging platform overrides for puppet5 install utils
2 parents 68d9c2a + 97d6eaa commit 2f05918

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

lib/beaker-puppet/install_utils/puppet5.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,29 @@ def fetch_build_details(sha_yaml_url)
2727
return sha_yaml_folder_url, file_hash[:platform_data]
2828
end
2929

30-
# gets the artifact & repo_config URLs for this host in the build
30+
# Get the host's packaging platform, based on beaker-hostgenerator's
31+
# osinfo hash and the environment. Set ENV['BEAKER_PACKAGING_PLATFORMS']
32+
# to override the default packaging platform specified by
33+
# beaker-hostgenerator. This should be a comma-separated string with
34+
# entries of the format `<host-platform>=<override-platform>`
35+
#
36+
# @param [Host] host Host whose packaging platform to determine
37+
# @return [String] The packaging platform
38+
def host_packaging_platform(host)
39+
packaging_platform = host[:packaging_platform]
40+
if ENV['BEAKER_PACKAGING_PLATFORMS']
41+
overrides = Hash[ENV['BEAKER_PACKAGING_PLATFORMS'].split(',').map { |e| e.split('=') }]
42+
logger.debug("Found packaging platform overrides: #{overrides}")
43+
if overrides[host[:platform]]
44+
platform = overrides[host[:platform]]
45+
logger.debug("Default beaker packaging platform '#{host[:packaging_platform]}' for '#{host[:platform]}' overridden as '#{platform}'")
46+
packaging_platform = platform
47+
end
48+
end
49+
packaging_platform
50+
end
51+
52+
# Gets the artifact & repo_config URLs for this host in the build.
3153
#
3254
# @param [Host] host Host to get artifact URL for
3355
# @param [Hash] build_details Details of the build in a hash
@@ -36,7 +58,7 @@ def fetch_build_details(sha_yaml_url)
3658
# @return [String, String] URL to the build artifact, URL to the repo_config
3759
# (nil if there is no repo_config for this platform for this build)
3860
def host_urls(host, build_details, build_url)
39-
packaging_platform = host[:packaging_platform]
61+
packaging_platform = host_packaging_platform(host)
4062
if packaging_platform.nil?
4163
message = <<-EOF
4264
:packaging_platform not provided for host '#{host}', platform '#{host[:platform]}'

spec/beaker-puppet/install_utils/puppet5_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def logger
7878
details
7979
}
8080

81+
before :each do
82+
allow( subject ).to receive( :host_packaging_platform ) { packaging_platform }
83+
end
84+
8185
it 'fails if there\'s no artifact value for the given platform' do
8286
allow( artifact_path ).to receive( :nil? ) { true }
8387
expect {
@@ -135,6 +139,41 @@ def logger
135139

136140
end
137141

142+
describe "#host_packaging_platform" do
143+
let( :default_platform ) { 'default-platform' }
144+
let( :overridden_platform ) { 'overridden-platform' }
145+
let( :overrides ) { 'default-platform=overridden-platform' || @overrides }
146+
let( :host ) {
147+
host = hosts[0]
148+
allow( host ).to receive( :[] ).with( :packaging_platform ) { default_platform }
149+
allow( host ).to receive( :[] ).with( :platform ) { default_platform }
150+
host
151+
}
152+
153+
before :each do
154+
@original_platforms = ENV['BEAKER_PACKAGING_PLATFORMS']
155+
end
156+
157+
after :each do
158+
ENV['BEAKER_PACKAGING_PLATFORMS'] = @original_platforms
159+
end
160+
161+
it "applies an override to a platform" do
162+
ENV['BEAKER_PACKAGING_PLATFORMS'] = overrides
163+
expect(subject.host_packaging_platform(host)).to eq(overridden_platform)
164+
end
165+
166+
it "applies a list of overrides to a platform" do
167+
ENV['BEAKER_PACKAGING_PLATFORMS'] = "aix-7.1-power=aix-6.1-power,#{overrides}"
168+
expect(subject.host_packaging_platform(host)).to eq(overridden_platform)
169+
end
170+
171+
it "doesn't apply overrides if the current host's platform isn't overridden" do
172+
ENV['BEAKER_PACKAGING_PLATFORMS'] = "aix-7.1-power=aix-6.1-power"
173+
expect(subject.host_packaging_platform(host)).to eq(default_platform)
174+
end
175+
end
176+
138177
describe '#install_artifact_on' do
139178

140179
let( :artifact_url ) { 'url://in/the/jungle/lies/the/prize.pnc' }

0 commit comments

Comments
 (0)