puppet 2.7.25 → 2.7.26

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.

Files changed (77) hide show
  1. data/bin/puppet +4 -0
  2. data/ext/build_defaults.yaml +4 -4
  3. data/ext/debian/control +1 -1
  4. data/ext/packaging/Gemfile +8 -0
  5. data/ext/packaging/Gemfile.lock +28 -0
  6. data/ext/packaging/README.md +31 -4
  7. data/ext/packaging/lib/packaging.rb +21 -0
  8. data/ext/packaging/lib/packaging/config.rb +277 -0
  9. data/ext/packaging/lib/packaging/config/params.rb +175 -0
  10. data/ext/packaging/lib/packaging/tar.rb +186 -0
  11. data/ext/packaging/lib/packaging/util.rb +44 -0
  12. data/ext/packaging/lib/packaging/util/date.rb +15 -0
  13. data/ext/packaging/lib/packaging/util/file.rb +60 -0
  14. data/ext/packaging/lib/packaging/util/jira.rb +83 -0
  15. data/ext/packaging/lib/packaging/util/net.rb +16 -0
  16. data/ext/packaging/lib/packaging/util/rake_utils.rb +57 -0
  17. data/ext/packaging/lib/packaging/util/serialization.rb +19 -0
  18. data/ext/packaging/lib/packaging/util/tool.rb +30 -0
  19. data/ext/packaging/lib/packaging/util/version.rb +300 -0
  20. data/ext/packaging/packaging.rake +10 -5
  21. data/ext/packaging/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  22. data/ext/packaging/spec/fixtures/config/ext/project_data.yaml +2 -0
  23. data/ext/packaging/spec/fixtures/config/params.yaml +2 -0
  24. data/ext/packaging/spec/fixtures/util/pre_tasks.yaml +4 -0
  25. data/ext/packaging/spec/lib/packaging/config_spec.rb +330 -0
  26. data/ext/packaging/spec/lib/packaging/tar_spec.rb +122 -0
  27. data/ext/packaging/spec/lib/packaging/util/file_spec.rb +48 -0
  28. data/ext/packaging/spec/lib/packaging/util/jira_spec.rb +50 -0
  29. data/ext/packaging/spec/lib/packaging/util/net_spec.rb +23 -0
  30. data/ext/packaging/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  31. data/ext/packaging/spec/lib/packaging/util/version_spec.rb +67 -0
  32. data/ext/packaging/spec/lib/packaging_spec.rb +19 -0
  33. data/ext/packaging/spec/spec_helper.rb +10 -0
  34. data/ext/packaging/spec/tasks/00_utils_spec.rb +218 -88
  35. data/ext/packaging/tasks/00_utils.rake +63 -320
  36. data/ext/packaging/tasks/30_metrics.rake +4 -4
  37. data/ext/packaging/tasks/apple.rake +28 -13
  38. data/ext/packaging/tasks/build.rake +2 -176
  39. data/ext/packaging/tasks/deb.rake +61 -20
  40. data/ext/packaging/tasks/deb_repos.rake +12 -12
  41. data/ext/packaging/tasks/doc.rake +5 -5
  42. data/ext/packaging/tasks/fetch.rake +9 -9
  43. data/ext/packaging/tasks/gem.rake +59 -33
  44. data/ext/packaging/tasks/ips.rake +22 -23
  45. data/ext/packaging/tasks/jenkins.rake +34 -34
  46. data/ext/packaging/tasks/jenkins_dynamic.rake +22 -19
  47. data/ext/packaging/tasks/load_extras.rake +21 -0
  48. data/ext/packaging/tasks/mock.rake +16 -16
  49. data/ext/packaging/tasks/pe_deb.rake +2 -2
  50. data/ext/packaging/tasks/pe_remote.rake +9 -9
  51. data/ext/packaging/tasks/pe_rpm.rake +1 -1
  52. data/ext/packaging/tasks/pe_ship.rake +48 -37
  53. data/ext/packaging/tasks/pe_sign.rake +5 -5
  54. data/ext/packaging/tasks/release.rake +5 -5
  55. data/ext/packaging/tasks/remote_build.rake +27 -27
  56. data/ext/packaging/tasks/retrieve.rake +5 -5
  57. data/ext/packaging/tasks/rpm.rake +27 -10
  58. data/ext/packaging/tasks/rpm_repos.rake +13 -12
  59. data/ext/packaging/tasks/ship.rake +67 -45
  60. data/ext/packaging/tasks/sign.rake +37 -30
  61. data/ext/packaging/tasks/tar.rake +14 -69
  62. data/ext/packaging/tasks/tickets.rake +449 -0
  63. data/ext/packaging/tasks/update.rake +2 -2
  64. data/ext/packaging/tasks/vendor_gems.rake +2 -2
  65. data/ext/packaging/tasks/version.rake +8 -38
  66. data/ext/packaging/tasks/z_data_dump.rake +35 -3
  67. data/ext/packaging/templates/downstream.xml.erb +2 -2
  68. data/ext/packaging/templates/packaging.xml.erb +13 -13
  69. data/ext/packaging/templates/repo.xml.erb +9 -7
  70. data/lib/puppet/indirector/facts/facter.rb +1 -1
  71. data/lib/puppet/version.rb +1 -1
  72. data/spec/unit/indirector/facts/facter_spec.rb +2 -2
  73. metadata +38 -13
  74. data/ext/packaging/spec/tasks/build_object_spec.rb +0 -178
  75. data/ext/packaging/tasks/10_setupvars.rake +0 -135
  76. data/ext/packaging/tasks/20_setupextravars.rake +0 -53
  77. data/ext/packaging/tasks/template.rake +0 -27
@@ -0,0 +1,19 @@
1
+ # Utility methods for dealing with serialization of Config params
2
+
3
+ module Pkg::Util::Serialization
4
+ class << self
5
+
6
+ # Given the path to a yaml file, load the yaml file into an object and return the object.
7
+ def load_yaml(file)
8
+ require 'yaml'
9
+ file = File.expand_path(file)
10
+ begin
11
+ input_data = YAML.load_file(file) || {}
12
+ rescue
13
+ fail "There was an error loading data from #{file}."
14
+ end
15
+ input_data
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,30 @@
1
+ # Utility methods for handling system binaries
2
+
3
+ module Pkg::Util::Tool
4
+
5
+ # Set up utility methods for handling system binaries
6
+ #
7
+ class << self
8
+ def check_tool(tool)
9
+ find_tool(tool, :required => true)
10
+ end
11
+
12
+ def find_tool(tool, args={:required => false})
13
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |root|
14
+ location = File.join(root, tool)
15
+ return location if FileTest.executable? location
16
+ end
17
+ fail "#{tool} tool not found...exiting" if args[:required]
18
+ return nil
19
+ end
20
+
21
+ alias :has_tool :find_tool
22
+
23
+ end
24
+
25
+ # Set up paths to system tools we use in the packaging repo
26
+ # no matter what distribution we're packaging for.
27
+
28
+ GIT = Pkg::Util::Tool.find_tool('git', :required => :true)
29
+
30
+ end
@@ -0,0 +1,300 @@
1
+ # Utility methods used for versioning projects for various kinds of packaging
2
+
3
+ module Pkg::Util::Version
4
+ class << self
5
+
6
+ GIT = Pkg::Util::Tool::GIT
7
+
8
+ def git_co(ref)
9
+ Pkg::Util.in_project_root do
10
+ %x{#{GIT} reset --hard ; #{GIT} checkout #{ref}}
11
+ $?.success? or fail "Could not checkout #{ref} git branch to build package from...exiting"
12
+ end
13
+ end
14
+
15
+ def git_tagged?
16
+ Pkg::Util.in_project_root do
17
+ %x{#{GIT} describe >/dev/null 2>&1}
18
+ $?.success?
19
+ end
20
+ end
21
+
22
+ def git_describe
23
+ Pkg::Util.in_project_root do
24
+ %x{#{GIT} describe}.strip
25
+ end
26
+ end
27
+
28
+ # return the sha of HEAD on the current branch
29
+ def git_sha
30
+ Pkg::Util.in_project_root do
31
+ %x{#{GIT} rev-parse HEAD}.strip
32
+ end
33
+ end
34
+
35
+ # Return the ref type of HEAD on the current branch
36
+ def git_ref_type
37
+ Pkg::Util.in_project_root do
38
+ %x{#{GIT} cat-file -t #{git_describe}}.strip
39
+ end
40
+ end
41
+
42
+ # If HEAD is a tag, return the tag. Otherwise return the sha of HEAD.
43
+ def git_sha_or_tag
44
+ if git_ref_type == "tag"
45
+ git_describe
46
+ else
47
+ git_sha
48
+ end
49
+ end
50
+
51
+ # Return true if we're in a git repo, otherwise false
52
+ def is_git_repo?
53
+ Pkg::Util.in_project_root do
54
+ %x{#{GIT} rev-parse --git-dir > /dev/null 2>&1}
55
+ $?.success?
56
+ end
57
+ end
58
+
59
+ alias :is_git_repo :is_git_repo?
60
+
61
+ # Return the basename of the project repo
62
+ def git_project_name
63
+ Pkg::Util.in_project_root do
64
+ %x{#{GIT} config --get remote.origin.url}.split('/')[-1].chomp(".git").chomp
65
+ end
66
+ end
67
+
68
+ # Return information about the current tree, using `git describe`, ready for
69
+ # further processing.
70
+ #
71
+ # Returns an array of one to four elements, being:
72
+ # * version (three dot-joined numbers, leading `v` stripped)
73
+ # * the string 'rcX' (if the last tag was an rc release, where X is the rc number)
74
+ # * commits (string containing integer, number of commits since that version was tagged)
75
+ # * dirty (string 'dirty' if local changes exist in the repo)
76
+ def git_describe_version
77
+ return nil unless is_git_repo and raw = run_git_describe_internal
78
+ # reprocess that into a nice set of output data
79
+ # The elements we select potentially change if this is an rc
80
+ # For an rc with added commits our string will be something like '0.7.0-rc1-63-g51ccc51'
81
+ # and our return will be [0.7.0, rc1, 63, <dirty>]
82
+ # For a final with added commits, it will look like '0.7.0-63-g51ccc51'
83
+ # and our return will be [0.7.0, 64, <dirty>]
84
+ info = raw.chomp.sub(/^v/, '').split('-')
85
+ if git_ref_type == "tag"
86
+ version_string = info.compact
87
+ elsif info[1].to_s.match('^[\d]+')
88
+ version_string = info.values_at(0,1,3).compact
89
+ else
90
+ version_string = info.values_at(0,1,2,4).compact
91
+ end
92
+ version_string
93
+ end
94
+
95
+ # This is a stub to ease testing...
96
+ def run_git_describe_internal
97
+ Pkg::Util.in_project_root do
98
+ raw = %x{#{GIT} describe --tags --dirty 2>/dev/null}
99
+ $?.success? ? raw : nil
100
+ end
101
+ end
102
+
103
+ def get_dash_version
104
+ if info = git_describe_version
105
+ info.join('-')
106
+ else
107
+ get_pwd_version
108
+ end
109
+ end
110
+
111
+ def uname_r
112
+ uname = Pkg::Util::Tool.find_tool('uname', :required => true)
113
+ %x{#{uname} -r}.chomp
114
+ end
115
+
116
+ def get_ips_version
117
+ if info = git_describe_version
118
+ version, commits, dirty = info
119
+ if commits.to_s.match('^rc[\d]+')
120
+ commits = info[2]
121
+ dirty = info[3]
122
+ end
123
+ osrelease = uname_r
124
+ "#{version},#{osrelease}-#{commits.to_i}#{dirty ? '-dirty' : ''}"
125
+ else
126
+ get_pwd_version
127
+ end
128
+ end
129
+
130
+ def get_dot_version
131
+ get_dash_version.gsub('-', '.')
132
+ end
133
+
134
+ def get_pwd_version
135
+ Dir.pwd.split('.')[-1]
136
+ end
137
+
138
+ def get_base_pkg_version
139
+ dash = get_dash_version
140
+ if dash.include?("rc")
141
+ # Grab the rc number
142
+ rc_num = dash.match(/rc(\d+)/)[1]
143
+ ver = dash.sub(/-?rc[0-9]+/, "-0.#{Pkg::Config.release}rc#{rc_num}").gsub(/(rc[0-9]+)-(\d+)?-?/, '\1.\2')
144
+ else
145
+ ver = dash.gsub('-','.') + "-#{Pkg::Config.release}"
146
+ end
147
+
148
+ ver.split('-')
149
+ end
150
+
151
+ def get_debversion
152
+ get_base_pkg_version.join('-') << "#{Pkg::Config.packager}1"
153
+ end
154
+
155
+ def get_origversion
156
+ Pkg::Config.debversion.split('-')[0]
157
+ end
158
+
159
+ def get_rpmversion
160
+ get_base_pkg_version[0]
161
+ end
162
+
163
+ def get_rpmrelease
164
+ get_base_pkg_version[1]
165
+ end
166
+
167
+ def source_dirty?
168
+ git_describe_version.include?('dirty')
169
+ end
170
+
171
+ def fail_on_dirty_source
172
+ if source_dirty?
173
+ fail "
174
+ The source tree is dirty, e.g. there are uncommited changes. Please
175
+ commit/discard changes and try again."
176
+ end
177
+ end
178
+
179
+ # Determines if this package is a final package via the
180
+ # selected version_strategy.
181
+ # There are currently two supported version strategies.
182
+ #
183
+ # This method calls down to the version strategy indicated, defaulting to the
184
+ # rc_final strategy. The methods themselves will return false if it is a final
185
+ # release, so their return values are collected and then inverted before being
186
+ # returned.
187
+ def is_final?
188
+ ret = nil
189
+ case Pkg::Config.version_strategy
190
+ when "rc_final"
191
+ ret = is_rc?
192
+ when "odd_even"
193
+ ret = is_odd?
194
+ when "zero_based"
195
+ ret = is_less_than_one?
196
+ when nil
197
+ ret = is_rc?
198
+ end
199
+ return (! ret)
200
+ end
201
+
202
+ # the rc_final strategy (default)
203
+ # Assumes version strings in the formats:
204
+ # final:
205
+ # '0.7.0'
206
+ # '0.7.0-63'
207
+ # '0.7.0-63-dirty'
208
+ # development:
209
+ # '0.7.0rc1 (we don't actually use this format anymore, but once did)
210
+ # '0.7.0-rc1'
211
+ # '0.7.0-rc1-63'
212
+ # '0.7.0-rc1-63-dirty'
213
+ def is_rc?
214
+ return TRUE if get_dash_version =~ /^\d+\.\d+\.\d+-*rc\d+/
215
+ return FALSE
216
+ end
217
+
218
+ # the odd_even strategy (mcollective)
219
+ # final:
220
+ # '0.8.0'
221
+ # '1.8.0-63'
222
+ # '0.8.1-63-dirty'
223
+ # development:
224
+ # '0.7.0'
225
+ # '1.7.0-63'
226
+ # '0.7.1-63-dirty'
227
+ def is_odd?
228
+ return TRUE if get_dash_version.match(/^\d+\.(\d+)\.\d+/)[1].to_i.odd?
229
+ return FALSE
230
+ end
231
+
232
+ # the pre-1.0 strategy (node classifier)
233
+ # final:
234
+ # '1.8.0'
235
+ # '1.8.0-63'
236
+ # '1.8.1-63-dirty'
237
+ # development:
238
+ # '0.7.0'
239
+ # '0.7.0-63'
240
+ # '0.7.1-63-dirty'
241
+ def is_less_than_one?
242
+ return TRUE if get_dash_version.match(/^(\d+)\.\d+\.\d+/)[1].to_i.zero?
243
+ return FALSE
244
+ end
245
+
246
+ # Utility method to return the dist method if this is a redhat box. We use this
247
+ # in rpm packaging to define a dist macro, and we use it in the pl:fetch task
248
+ # to disable ssl checking for redhat 5 because it has a certs bundle so old by
249
+ # default that it's useless for our purposes.
250
+ def el_version
251
+ if File.exists?('/etc/fedora-release')
252
+ nil
253
+ elsif File.exists?('/etc/redhat-release')
254
+ rpm = Pkg::Util::Tool.find_tool('rpm', :required => true)
255
+ return %x{#{rpm} -q --qf \"%{VERSION}\" $(#{rpm} -q --whatprovides /etc/redhat-release )}
256
+ end
257
+ end
258
+
259
+ # This is to support packages that only burn-in the version number in the
260
+ # release artifact, rather than storing it two (or more) times in the
261
+ # version control system. Razor is a good example of that; see
262
+ # https://github.com/puppetlabs/Razor/blob/master/lib/project_razor/version.rb
263
+ # for an example of that this looks like.
264
+ #
265
+ # If you invoke this the version will only be modified in the temporary copy,
266
+ # with the intent that it never change the official source tree.
267
+ def versionbump(workdir=nil)
268
+ version = ENV['VERSION'] || Pkg::Config.version.to_s.strip
269
+ new_version = '"' + version + '"'
270
+
271
+ version_file = "#{workdir ? workdir + '/' : ''}#{Pkg::Config.version_file}"
272
+
273
+ # Read the previous version file in...
274
+ contents = IO.read(version_file)
275
+
276
+ # Match version files containing 'VERSION = "x.x.x"' and just x.x.x
277
+ if version_string = contents.match(/VERSION =.*/)
278
+ old_version = version_string.to_s.split()[-1]
279
+ else
280
+ old_version = contents
281
+ end
282
+
283
+ puts "Updating #{old_version} to #{new_version} in #{version_file}"
284
+ if contents.match("@DEVELOPMENT_VERSION@")
285
+ contents.gsub!("@DEVELOPMENT_VERSION@", version)
286
+ elsif contents.match('version\s*=\s*[\'"]DEVELOPMENT[\'"]')
287
+ contents.gsub!(/version\s*=\s*['"]DEVELOPMENT['"]/, "version = '#{version}'")
288
+ elsif contents.match("VERSION = #{old_version}")
289
+ contents.gsub!("VERSION = #{old_version}", "VERSION = #{new_version}")
290
+ elsif contents.match("#{Pkg::Config.project.upcase}VERSION = #{old_version}")
291
+ contents.gsub!("#{Pkg::Config.project.upcase}VERSION = #{old_version}", "#{Pkg::Config.project.upcase}VERSION = #{new_version}")
292
+ else
293
+ contents.gsub!(old_version, Pkg::Config.version)
294
+ end
295
+
296
+ # ...and write it back on out.
297
+ File.open(version_file, 'w') {|f| f.write contents }
298
+ end
299
+ end
300
+ end
@@ -1,14 +1,17 @@
1
+ # Load the packaging repo libraries
2
+
3
+ require File.join(File.dirname(__FILE__), 'lib', 'packaging.rb')
4
+
1
5
  # Load packaging repo tasks
2
6
 
3
7
  # These are ordered
4
8
 
5
- PACKAGING_PATH = File.join(File.dirname(__FILE__), 'tasks')
9
+ PACKAGING_ROOT = File.expand_path(File.dirname(__FILE__))
10
+ PACKAGING_TASK_DIR = File.join(PACKAGING_ROOT, 'tasks')
6
11
 
7
12
  @using_loader = true
8
13
 
9
14
  [ '00_utils.rake',
10
- '10_setupvars.rake',
11
- '20_setupextravars.rake',
12
15
  '30_metrics.rake',
13
16
  'apple.rake',
14
17
  'build.rake',
@@ -21,6 +24,7 @@ PACKAGING_PATH = File.join(File.dirname(__FILE__), 'tasks')
21
24
  'ips.rake',
22
25
  'jenkins.rake',
23
26
  'jenkins_dynamic.rake',
27
+ 'load_extras.rake',
24
28
  'mock.rake',
25
29
  'pe_deb.rake',
26
30
  'pe_remote.rake',
@@ -37,9 +41,10 @@ PACKAGING_PATH = File.join(File.dirname(__FILE__), 'tasks')
37
41
  'sign.rake',
38
42
  'tag.rake',
39
43
  'tar.rake',
40
- 'template.rake',
44
+ 'tickets.rake',
41
45
  'update.rake',
42
46
  'vendor_gems.rake',
43
47
  'version.rake',
44
- 'z_data_dump.rake'].each { |t| load File.join(PACKAGING_PATH, t)}
48
+ 'z_data_dump.rake'].each { |t| load File.join(PACKAGING_TASK_DIR, t)}
45
49
 
50
+ Pkg::Util::RakeUtils.evaluate_pre_tasks
@@ -0,0 +1,2 @@
1
+ ---
2
+ :apt_host: foo
@@ -0,0 +1,2 @@
1
+ ---
2
+ :apt_host: foo
@@ -0,0 +1,4 @@
1
+ ---
2
+ pre_tasks:
3
+ foo: 'bar'
4
+
@@ -0,0 +1,330 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+ require 'yaml'
4
+
5
+ describe "Pkg::Config" do
6
+
7
+ Build_Params = [:apt_host,
8
+ :apt_repo_path,
9
+ :apt_repo_url,
10
+ :author,
11
+ :benchmark,
12
+ :build_date,
13
+ :build_defaults,
14
+ :build_dmg,
15
+ :build_doc,
16
+ :build_gem,
17
+ :build_ips,
18
+ :build_pe,
19
+ :builder_data_file,
20
+ :bundle_platforms,
21
+ :certificate_pem,
22
+ :cows,
23
+ :db_table,
24
+ :deb_build_host,
25
+ :deb_build_mirrors,
26
+ :debversion,
27
+ :debug,
28
+ :default_cow,
29
+ :default_mock,
30
+ :description,
31
+ :dmg_path,
32
+ :email,
33
+ :files,
34
+ :final_mocks,
35
+ :freight_conf,
36
+ :gem_default_executables,
37
+ :gem_dependencies,
38
+ :gem_description,
39
+ :gem_devel_dependencies,
40
+ :gem_development_dependencies,
41
+ :gem_excludes,
42
+ :gem_executables,
43
+ :gem_files,
44
+ :gem_forge_project,
45
+ :gem_name,
46
+ :gem_platform_dependencies,
47
+ :gem_rdoc_options,
48
+ :gem_require_path,
49
+ :gem_runtime_dependencies,
50
+ :gem_summary,
51
+ :gem_test_files,
52
+ :gemversion,
53
+ :gpg_key,
54
+ :gpg_name,
55
+ :homepage,
56
+ :ips_build_host,
57
+ :ips_host,
58
+ :ips_inter_cert,
59
+ :ips_package_host,
60
+ :ips_path,
61
+ :ips_repo,
62
+ :ips_store,
63
+ :ipsversion,
64
+ :jenkins_build_host,
65
+ :jenkins_packaging_job,
66
+ :jenkins_repo_path,
67
+ :metrics,
68
+ :metrics_url,
69
+ :name,
70
+ :notify,
71
+ :project,
72
+ :origversion,
73
+ :osx_build_host,
74
+ :packager,
75
+ :packaging_repo,
76
+ :packaging_root,
77
+ :packaging_url,
78
+ :pbuild_conf,
79
+ :pe_name,
80
+ :pe_version,
81
+ :pg_major_version,
82
+ :pre_tar_task,
83
+ :pre_tasks,
84
+ :privatekey_pem,
85
+ :random_mockroot,
86
+ :rc_mocks,
87
+ :release,
88
+ :rpm_build_host,
89
+ :rpmrelease,
90
+ :rpmversion,
91
+ :ref,
92
+ :sign_tar,
93
+ :summary,
94
+ :tar_excludes,
95
+ :tar_host,
96
+ :tarball_path,
97
+ :team,
98
+ :templates,
99
+ :update_version_file,
100
+ :version,
101
+ :version_file,
102
+ :version_strategy,
103
+ :yum_host,
104
+ :yum_repo_path]
105
+
106
+ describe "#new" do
107
+ Build_Params.each do |param|
108
+ it "should have r/w accessors for #{param}" do
109
+ Pkg::Config.should respond_to(param)
110
+ Pkg::Config.should respond_to("#{param.to_s}=")
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "#config_from_hash" do
116
+ good_params = { :yum_host => 'foo', :pe_name => 'bar' }
117
+ context "given a valid params hash #{good_params}" do
118
+ it "should set instance variable values for each param" do
119
+ good_params.each do |param, value|
120
+ Pkg::Config.should_receive(:instance_variable_set).with("@#{param}", value)
121
+ end
122
+ Pkg::Config.config_from_hash(good_params)
123
+ end
124
+ end
125
+
126
+ bad_params = { :foo => 'bar' }
127
+ context "given an invalid params hash #{bad_params}" do
128
+ bad_params.each do |param, value|
129
+ it "should print a warning that param '#{param}' is not valid" do
130
+ Pkg::Config.should_receive(:warn).with(/No build data parameter found for '#{param}'/)
131
+ Pkg::Config.config_from_hash(bad_params)
132
+ end
133
+
134
+ it "should not try to set instance variable @:#{param}" do
135
+ Pkg::Config.should_not_receive(:instance_variable_set).with("@#{param}", value)
136
+ Pkg::Config.config_from_hash(bad_params)
137
+ end
138
+ end
139
+ end
140
+
141
+ mixed_params = { :sign_tar => TRUE, :baz => 'qux' }
142
+ context "given a hash with both valid and invalid params" do
143
+ it "should set the valid param" do
144
+ Pkg::Config.should_receive(:instance_variable_set).with("@sign_tar", TRUE)
145
+ Pkg::Config.config_from_hash(mixed_params)
146
+ end
147
+
148
+ it "should issue a warning that the invalid param is not valid" do
149
+ Pkg::Config.should_receive(:warn).with(/No build data parameter found for 'baz'/)
150
+ Pkg::Config.config_from_hash(mixed_params)
151
+ end
152
+
153
+ it "should not try to set instance variable @:baz" do
154
+ Pkg::Config.should_not_receive(:instance_variable_set).with("@baz", "qux")
155
+ Pkg::Config.config_from_hash(mixed_params)
156
+ end
157
+ end
158
+ end
159
+
160
+ describe "#params" do
161
+ it "should return a hash containing keys for all build parameters" do
162
+ params = Pkg::Config.config
163
+ Build_Params.each { |param| params.has_key?(param).should == TRUE }
164
+ end
165
+ end
166
+
167
+ describe "#config_to_yaml" do
168
+ it "should write a valid yaml file" do
169
+ file = double('file')
170
+ File.should_receive(:open).with(anything(), 'w').and_yield(file)
171
+ file.should_receive(:puts).with(instance_of(String))
172
+ YAML.should_receive(:load_file).with(file)
173
+ expect { YAML.load_file(file) }.to_not raise_error
174
+ Pkg::Config.config_to_yaml
175
+ end
176
+ end
177
+
178
+ describe "#get_binding" do
179
+ it "should return the binding of the Pkg::Config object" do
180
+ # test by eval'ing using the binding before and after setting a param
181
+ orig = Pkg::Config.apt_host
182
+ Pkg::Config.apt_host = "foo"
183
+ expect(eval("@apt_host", Pkg::Config.get_binding)).to eq("foo")
184
+ Pkg::Config.apt_host = "bar"
185
+ expect(eval("@apt_host", Pkg::Config.get_binding)).to eq("bar")
186
+ Pkg::Config.apt_host = orig
187
+ end
188
+ end
189
+
190
+ describe "#config_from_yaml" do
191
+ context "given a yaml file" do
192
+ it "should, use it to set params" do
193
+ # apt_host: is set to "foo" in the fixture
194
+ orig = Pkg::Config.apt_host
195
+ Pkg::Config.apt_host = "bar"
196
+ Pkg::Config.config_from_yaml(File.join(FIXTURES, 'config', 'params.yaml'))
197
+ expect(Pkg::Config.apt_host).to eq("foo")
198
+ Pkg::Config.apt_host = orig
199
+ end
200
+ end
201
+ end
202
+
203
+ describe "#cow_list" do
204
+ it "should return a list of the cows for a project" do
205
+ Pkg::Config.cows = "base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-saucy-i386.cow base-saucy-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-trusty-i386.cow base-trusty-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow"
206
+ Pkg::Config.cow_list.should eq "lucid precise quantal saucy sid squeeze stable testing trusty unstable wheezy"
207
+ end
208
+ end
209
+
210
+ describe "#config" do
211
+ context "given :format => :hash" do
212
+ it "should call Pkg::Config.config_to_hash" do
213
+ expect(Pkg::Config).to receive(:config_to_hash)
214
+ Pkg::Config.config(:target => nil, :format => :hash)
215
+ end
216
+ end
217
+
218
+ context "given :format => :yaml" do
219
+ it "should call Pkg::Config.config_to_yaml if given :format => :yaml" do
220
+ expect(Pkg::Config).to receive(:config_to_yaml)
221
+ Pkg::Config.config(:target => nil, :format => :yaml)
222
+ end
223
+ end
224
+ end
225
+
226
+ describe "#issue_reassignments" do
227
+ before :all do
228
+ prev_tar_host = Pkg::Config.tar_host
229
+ Pkg::Config.tar_host = nil
230
+ end
231
+
232
+ it "should set tar_host to yum_host" do
233
+ Pkg::Config.config_from_hash({ :yum_host => 'foo' })
234
+ Pkg::Config.issue_reassignments
235
+ Pkg::Config.tar_host.should eq("foo")
236
+ end
237
+
238
+ after :all do
239
+ Pkg::Config.tar_host = prev_tar_host
240
+ end
241
+ end
242
+
243
+ describe "#config_to_hash" do
244
+ it "should return a hash object" do
245
+ hash = Pkg::Config.config_to_hash
246
+ hash.should be_a(Hash)
247
+ end
248
+
249
+ it "should return a hash with the current parameters" do
250
+ Pkg::Config.apt_host = "foo"
251
+ Pkg::Config.config_to_hash[:apt_host].should eq("foo")
252
+ Pkg::Config.apt_host = "bar"
253
+ Pkg::Config.config_to_hash[:apt_host].should eq("bar")
254
+ end
255
+ end
256
+
257
+ describe "#load_default_configs" do
258
+ context "given ext/build_defaults.yaml and ext/project_data.yaml are readable" do
259
+ it "should try to load build_defaults.yaml and project_data.yaml" do
260
+ orig = Pkg::Config.project_root
261
+ Pkg::Config.project_root = File.join(FIXTURES, 'config')
262
+ test_project_data = File.join(FIXTURES, 'config', 'ext', 'project_data.yaml')
263
+ test_build_defaults = File.join(FIXTURES, 'config', 'ext', 'build_defaults.yaml')
264
+ expect(Pkg::Config).to receive(:config_from_yaml).with(test_project_data)
265
+ expect(Pkg::Config).to receive(:config_from_yaml).with(test_build_defaults)
266
+ Pkg::Config.load_default_configs
267
+ Pkg::Config.project_root = orig
268
+ end
269
+ end
270
+
271
+ context "given ext/build_defaults.yaml and ext/project_data.yaml are not readable" do
272
+ it "should not try to load build_defaults.yaml and project_data.yaml" do
273
+ orig = Pkg::Config.project_root
274
+ Pkg::Config.project_root = 'foo'
275
+ expect(Pkg::Config).to_not receive(:config_from_yaml)
276
+ Pkg::Config.load_default_configs
277
+ Pkg::Config.project_root = orig
278
+ end
279
+
280
+ it "should set the project root to nil" do
281
+ orig = Pkg::Config.project_root
282
+ Pkg::Config.project_root = 'foo'
283
+ Pkg::Config.load_default_configs
284
+ expect(Pkg::Config.project_root).to be(nil)
285
+ Pkg::Config.project_root = orig
286
+ end
287
+ end
288
+ end
289
+
290
+ describe "#load_versioning" do
291
+ # We let the actual version determination testing happen in the version
292
+ # tests. Here we just test that we try when we should.
293
+ context "When project root is nil" do
294
+ it "should not try to load versioning" do
295
+ Pkg::Config.stub(:project_root) {nil}
296
+ expect(Pkg::Config).to_not receive(:git_sha_or_tag)
297
+ end
298
+ end
299
+ end
300
+
301
+ describe "#load_envvars" do
302
+ # We're going to pollute the environment with this test, so afterwards we
303
+ # explicitly set everything to nil to prevent any hazardous effects on
304
+ # the rest of the tests.
305
+ after(:all) do
306
+ reset_env(Pkg::Params::ENV_VARS.map {|hash| hash[:envvar].to_s})
307
+ end
308
+
309
+ Pkg::Params::ENV_VARS.each do |v|
310
+ if v[:type] == :bool
311
+ it "should set boolean value on #{v[:var]} for :type == :bool" do
312
+ ENV[v[:envvar].to_s] = "FOO"
313
+ Pkg::Util.stub(:boolean_value) {"FOO"}
314
+ allow(Pkg::Config).to receive(:instance_variable_set)
315
+ expect(Pkg::Util).to receive(:boolean_value).with("FOO")
316
+ expect(Pkg::Config).to receive(:instance_variable_set).with("@#{v[:var]}", "FOO")
317
+ Pkg::Config.load_envvars
318
+ end
319
+ else
320
+ it "should set Pkg::Config##{v[:var]} to ENV[#{v[:envvar].to_s}]" do
321
+ ENV[v[:envvar].to_s] = "FOO"
322
+ Pkg::Util.stub(:boolean_value) {"FOO"}
323
+ allow(Pkg::Config).to receive(:instance_variable_set)
324
+ expect(Pkg::Config).to receive(:instance_variable_set).with("@#{v[:var]}", "FOO")
325
+ Pkg::Config.load_envvars
326
+ end
327
+ end
328
+ end
329
+ end
330
+ end