Top Level Namespace
Defined Under Namespace
Modules: Puppet, PuppetlabsSpec, PuppetlabsSpecHelper, RSpec
Instance Method Summary
collapse
-
#auto_symlink ⇒ Object
-
#beaker_node_sets ⇒ Array<String>
get the array of Beaker set names.
-
#check_directory_for_symlinks(dir = '.') ⇒ Object
-
#clone_repo(scm, remote, target, subdir = nil, ref = nil, branch = nil, flags = nil) ⇒ Object
-
#current_thread_count(items) ⇒ Object
returns the current thread count that is currently active a status of false or nil means the thread completed so when anything else we count that as a active thread.
-
#fixtures(category) ⇒ Object
-
#logger ⇒ Object
creates a logger so we can log events with certain levels.
-
#max_thread_limit ⇒ Object
returns the max_thread_count because we may want to limit ssh or https connections.
-
#module_working_directory ⇒ Object
-
#param_value(subject, type, title, param) ⇒ Object
-
#remove_subdirectory(target, subdir) ⇒ Object
-
#repositories ⇒ Object
cache the repositories and retruns and hash object.
-
#revision(scm, target, ref) ⇒ Object
-
#source_dir ⇒ Object
This is a helper for the self-symlink entry of fixtures.yml.
-
#vagrant_ssh(set, node = nil) ⇒ Object
Use “vagrant ssh” to login to the given node in the node set.
-
#verify_contents(subject, title, expected_lines) ⇒ Object
Instance Method Details
#auto_symlink ⇒ Object
130
131
132
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 130
def auto_symlink
{ File.basename(Dir.pwd).split('-').last => '#{source_dir}' }
end
|
#beaker_node_sets ⇒ Array<String>
get the array of Beaker set names
98
99
100
101
102
103
104
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 98
def beaker_node_sets
return @beaker_nodes if @beaker_nodes
@beaker_nodes = Dir['spec/acceptance/nodesets/*.yml'].sort.map do |node_set|
node_set.slice!('.yml')
File.basename(node_set)
end
end
|
#check_directory_for_symlinks(dir = '.') ⇒ Object
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 590
def check_directory_for_symlinks(dir='.')
dir = Pathname.new(dir) unless dir.is_a?(Pathname)
results = []
dir.each_child(true) do |child|
if child.symlink?
results << child
elsif child.directory? && child.basename.to_s != '.git'
results.concat(check_directory_for_symlinks(child))
end
end
results
end
|
#clone_repo(scm, remote, target, subdir = nil, ref = nil, branch = nil, flags = nil) ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 182
def clone_repo(scm, remote, target, subdir=nil, ref=nil, branch=nil, flags = nil)
args = []
case scm
when 'hg'
args.push('clone')
args.push('-b', branch) if branch
args.push(flags) if flags
args.push(remote, target)
when 'git'
args.push('clone')
args.push('--depth 1') unless ref
args.push('-b', branch) if branch
args.push(flags) if flags
args.push(remote, target)
else
fail "Unfortunately #{scm} is not supported yet"
end
result = system("#{scm} #{args.flatten.join ' '}")
unless File::exists?(target)
fail "Failed to clone #{scm} repository #{remote} into #{target}"
end
result
end
|
#current_thread_count(items) ⇒ Object
returns the current thread count that is currently active a status of false or nil means the thread completed so when anything else we count that as a active thread
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 254
def current_thread_count(items)
active_threads = items.find_all do |item, opts|
if opts[:thread]
opts[:thread].status
else
false
end
end
logger.debug "Current thread count #{active_threads.count}"
active_threads.count
end
|
#fixtures(category) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 134
def fixtures(category)
if File.exists?('.fixtures.yml')
fixtures_yaml = '.fixtures.yml'
elsif File.exists?('.fixtures.yaml')
fixtures_yaml = '.fixtures.yaml'
else
fixtures_yaml = ''
end
begin
fixtures = (YAML.load_file(ENV['FIXTURES_YML'] || fixtures_yaml) || { fixtures: {} })["fixtures"]
rescue Errno::ENOENT
fixtures = {}
rescue Psych::SyntaxError => e
abort("Found malformed YAML in #{fixtures_yaml} on line #{e.line} column #{e.column}: #{e.problem}")
end
if fixtures['symlinks'].nil?
fixtures['symlinks'] = auto_symlink
end
result = {}
if fixtures.include? category and fixtures[category] != nil
fixtures[category].each do |fixture, opts|
if opts.instance_of?(String)
source = opts
target = "spec/fixtures/modules/#{fixture}"
real_source = eval('"'+source+'"')
result[real_source] = target
elsif opts.instance_of?(Hash)
if opts["target"]
real_target = eval('"'+opts["target"]+'"')
end
unless real_target
real_target = "spec/fixtures/modules"
end
real_source = eval('"'+opts["repo"]+'"')
result[real_source] = { "target" => File.join(real_target,fixture), "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"], "flags" => opts["flags"], "subdir" => opts["subdir"]}
end
end
end
return result
end
|
#logger ⇒ Object
creates a logger so we can log events with certain levels
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 230
def logger
unless @logger
require 'logger'
if ENV['ENABLE_LOGGER']
level = Logger::DEBUG
else
level = Logger::INFO
end
@logger = Logger.new(STDERR)
@logger.level = level
end
@logger
end
|
#max_thread_limit ⇒ Object
returns the max_thread_count because we may want to limit ssh or https connections
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 268
def max_thread_limit
unless @max_thread_limit
if ENV['MAX_FIXTURE_THREAD_COUNT'].to_i > 0
@max_thread_limit = ENV['MAX_FIXTURE_THREAD_COUNT'].to_i
else
@max_thread_limit = 10 end
end
@max_thread_limit
end
|
#module_working_directory ⇒ Object
244
245
246
247
248
249
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 244
def module_working_directory
File.expand_path(ENV['MODULE_WORKING_DIR'] ? ENV['MODULE_WORKING_DIR'] : 'spec/fixtures/work-dir')
end
|
#param_value(subject, type, title, param) ⇒ Object
5
6
7
|
# File 'lib/puppetlabs_spec_helper/module_spec_helper.rb', line 5
def param_value(subject, type, title, param)
subject.resource(type, title).send(:parameters)[param.to_sym]
end
|
#remove_subdirectory(target, subdir) ⇒ Object
219
220
221
222
223
224
225
226
227
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 219
def remove_subdirectory(target, subdir)
unless subdir.nil?
Dir.mktmpdir {|tmpdir|
FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
FileUtils.rm_rf("#{target}/#{subdir}")
FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), "#{target}")
}
end
end
|
#repositories ⇒ Object
cache the repositories and retruns and hash object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 84
def repositories
unless @repositories
@repositories = fixtures('repositories')
@repositories.each do |remote, opts|
if opts.instance_of?(String)
@repositories[remote] = {"target" => opts} end
end
end
@repositories
end
|
#revision(scm, target, ref) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 206
def revision(scm, target, ref)
args = []
case scm
when 'hg'
args.push('update', '--clean', '-r', ref)
when 'git'
args.push('reset', '--hard', ref)
else
fail "Unfortunately #{scm} is not supported yet"
end
system("cd #{target} && #{scm} #{args.flatten.join ' '}")
end
|
#source_dir ⇒ Object
This is a helper for the self-symlink entry of fixtures.yml
79
80
81
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 79
def source_dir
Dir.pwd
end
|
#vagrant_ssh(set, node = nil) ⇒ Object
Use “vagrant ssh” to login to the given node in the node set
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 109
def vagrant_ssh(set, node = nil)
vagrant_yml_dir = File.join '.vagrant', 'beaker_vagrant_files', "#{set}.yml"
vagrant_file = File.join vagrant_yml_dir, 'Vagrantfile'
unless File.file? vagrant_file
puts "There is no Vagrantfile at: '#{vagrant_file}'. Perhaps, the node is not created or is destroyed."
exit 1
end
Dir.chdir(vagrant_yml_dir) do
command = 'vagrant ssh'
command += " #{node}" if node
env = {
'RUBYLIB' => nil,
'GEM_PATH' => nil,
'BUNDLE_BIN_PATH' => nil,
}
system env, command
end
end
|
#verify_contents(subject, title, expected_lines) ⇒ Object
9
10
11
12
|
# File 'lib/puppetlabs_spec_helper/module_spec_helper.rb', line 9
def verify_contents(subject, title, expected_lines)
content = subject.resource('file', title).send(:parameters)[:content]
expect(content.split("\n") & expected_lines).to match_array expected_lines.uniq
end
|