Class: Onceover::Controlrepo
- Inherits:
-
Object
- Object
- Onceover::Controlrepo
- Defined in:
- lib/onceover/controlrepo.rb
Constant Summary collapse
- @@existing_controlrepo =
This exists for caching. Each time a new one of these objects is created it gets dumped in here so that it’s values can be called without reference to the initial object itself
nil
Instance Attribute Summary collapse
-
#environmentpath ⇒ Object
Returns the value of attribute environmentpath.
-
#facts_files ⇒ Object
Returns the value of attribute facts_files.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#nodeset_file ⇒ Object
Returns the value of attribute nodeset_file.
-
#onceover_yaml ⇒ Object
Returns the value of attribute onceover_yaml.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#profile_regex ⇒ Object
Returns the value of attribute profile_regex.
-
#puppetfile ⇒ Object
Returns the value of attribute puppetfile.
-
#role_regex ⇒ Object
Returns the value of attribute role_regex.
-
#root ⇒ Object
Returns the value of attribute root.
-
#spec_dir ⇒ Object
Returns the value of attribute spec_dir.
-
#temp_modulepath ⇒ Object
Returns the value of attribute temp_modulepath.
-
#tempdir ⇒ Object
Returns the value of attribute tempdir.
Class Method Summary collapse
- .classes ⇒ Object
- .config ⇒ Object
- .create_dirs_and_log(dir) ⇒ Object
- .evaluate_template(template_name, bind) ⇒ Object
- .facts(filter = nil) ⇒ Object
- .facts_files ⇒ Object
- .generate_nodesets(repo) ⇒ Object
- .generate_onceover_yaml(repo) ⇒ Object
- .hiera_config_file ⇒ Object
- .init(repo) ⇒ Object
- .init_write_file(contents, out_file) ⇒ Object
- .profiles ⇒ Object
- .puppetfile ⇒ Object
- .roles ⇒ Object
-
.root ⇒ Object
Create methods on self so that we can access these basic things without having to actually instantiate the class, I’m debating how much stuff I should be putting in here, we don’t reeeally need to instantiate the object unless we want to modify it’s parameters, so maybe everything.
- .trusted_facts(filter = nil) ⇒ Object
Instance Method Summary collapse
- #classes ⇒ Object
- #config ⇒ Object
- #facts(filter = nil, key = 'values') ⇒ Object
- #fixtures ⇒ Object
- #hiera_config ⇒ Object
- #hiera_config=(data) ⇒ Object
- #hiera_config_file ⇒ Object
- #hiera_config_file_relative_path ⇒ Object
- #hiera_data ⇒ Object
-
#initialize(opts = {}) ⇒ Controlrepo
constructor
End class methods.
- #print_puppetfile_table ⇒ Object
- #profiles ⇒ Object
- #r10k_config ⇒ Object
- #r10k_config=(data) ⇒ Object
- #r10k_config_file ⇒ Object
- #roles ⇒ Object
-
#spec_tests(&block) ⇒ Object
Returns the deduplicted and verified output of testconfig.spec_tests for use in Rspec tests so that we don’t have to deal with more than one object.
- #temp_manifest ⇒ Object
- #to_s ⇒ Object
- #update_puppetfile ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Controlrepo
End class methods
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/onceover/controlrepo.rb', line 87 def initialize(opts = {}) # When we initialize the object it is going to set some instance vars # We want people to be able to run this from anywhere within the repo # so traverse up until we think we are in a controlrepo. if opts[:path] @root = opts[:path] else @root = Dir.pwd until File.exist?(File.('./environment.conf', @root)) do # Throw an exception if we can't go any further up throw "Could not file root of the controlrepo anywhere above #{Dir.pwd}" if @root == File.('../', @root) # Step up and try again @root = File.('../', @root) end end @onceover_yaml = ENV['ONCEOVER_YAML'] || opts[:onceover_yaml] || File.("#{@root}/spec/onceover.yaml") if File.exist?(@onceover_yaml) && _data = YAML.load_file(@onceover_yaml) opts.merge!(_data.fetch('opts',{})||{}) end opts.fetch(:facts_dir,'').sub!(%r{^[^/.].+} ){|path| File.(path, @root)} opts.fetch(:facts_files,[]).map!{|path| path =~ %r{^[/.]} ? path : File.(path, @root)} @environmentpath = opts[:environmentpath] || 'etc/puppetlabs/code/environments' @puppetfile = opts[:puppetfile] || File.('./Puppetfile', @root) @environment_conf = opts[:environment_conf] || File.('./environment.conf', @root) @spec_dir = opts[:spec_dir] || File.('./spec', @root) @facts_dir = opts[:facts_dir] || File.('factsets', @spec_dir) _facts_dirs = [@facts_dir, File.('../../../factsets', __FILE__)] _facts_files = opts[:facts_files] || _facts_dirs.map{|d| File.join(d, '*.json')} @facts_files = _facts_files.map{|_path| Dir[_path]}.flatten @nodeset_file = opts[:nodeset_file] || File.('./spec/acceptance/nodesets/onceover-nodes.yml', @root) @role_regex = opts[:role_regex] ? Regexp.new(opts[:role_regex]) : /role[s]?:{2}/ @profile_regex = opts[:profile_regex] ? Regexp.new(opts[:profile_regex]) : /profile[s]?:{2}/ @tempdir = opts[:tempdir] || File.('./.onceover', @root) $temp_modulepath = nil @manifest = opts[:manifest] || config['manifest'] ? File.(config['manifest'], @root) : nil @opts = opts logger.level = :debug if @opts[:debug] @@existing_controlrepo = self end |
Instance Attribute Details
#environmentpath ⇒ Object
Returns the value of attribute environmentpath.
22 23 24 |
# File 'lib/onceover/controlrepo.rb', line 22 def environmentpath @environmentpath end |
#facts_files ⇒ Object
Returns the value of attribute facts_files.
21 22 23 |
# File 'lib/onceover/controlrepo.rb', line 21 def facts_files @facts_files end |
#manifest ⇒ Object
Returns the value of attribute manifest.
28 29 30 |
# File 'lib/onceover/controlrepo.rb', line 28 def manifest @manifest end |
#nodeset_file ⇒ Object
Returns the value of attribute nodeset_file.
27 28 29 |
# File 'lib/onceover/controlrepo.rb', line 27 def nodeset_file @nodeset_file end |
#onceover_yaml ⇒ Object
Returns the value of attribute onceover_yaml.
30 31 32 |
# File 'lib/onceover/controlrepo.rb', line 30 def onceover_yaml @onceover_yaml end |
#opts ⇒ Object
Returns the value of attribute opts.
31 32 33 |
# File 'lib/onceover/controlrepo.rb', line 31 def opts @opts end |
#profile_regex ⇒ Object
Returns the value of attribute profile_regex.
24 25 26 |
# File 'lib/onceover/controlrepo.rb', line 24 def profile_regex @profile_regex end |
#puppetfile ⇒ Object
Returns the value of attribute puppetfile.
20 21 22 |
# File 'lib/onceover/controlrepo.rb', line 20 def puppetfile @puppetfile end |
#role_regex ⇒ Object
Returns the value of attribute role_regex.
23 24 25 |
# File 'lib/onceover/controlrepo.rb', line 23 def role_regex @role_regex end |
#root ⇒ Object
Returns the value of attribute root.
19 20 21 |
# File 'lib/onceover/controlrepo.rb', line 19 def root @root end |
#spec_dir ⇒ Object
Returns the value of attribute spec_dir.
25 26 27 |
# File 'lib/onceover/controlrepo.rb', line 25 def spec_dir @spec_dir end |
#temp_modulepath ⇒ Object
Returns the value of attribute temp_modulepath.
26 27 28 |
# File 'lib/onceover/controlrepo.rb', line 26 def temp_modulepath @temp_modulepath end |
#tempdir ⇒ Object
Returns the value of attribute tempdir.
29 30 31 |
# File 'lib/onceover/controlrepo.rb', line 29 def tempdir @tempdir end |
Class Method Details
.classes ⇒ Object
56 57 58 |
# File 'lib/onceover/controlrepo.rb', line 56 def self.classes @@existing_controlrepo.classes end |
.config ⇒ Object
68 69 70 |
# File 'lib/onceover/controlrepo.rb', line 68 def self.config @@existing_controlrepo.config end |
.create_dirs_and_log(dir) ⇒ Object
547 548 549 550 551 552 553 554 |
# File 'lib/onceover/controlrepo.rb', line 547 def self.create_dirs_and_log(dir) Pathname.new(dir).descend do |folder| unless folder.directory? FileUtils.mkdir(folder) puts "#{'created'.green} #{folder.relative_path_from(Pathname.new(Dir.pwd)).to_s}" end end end |
.evaluate_template(template_name, bind) ⇒ Object
556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/onceover/controlrepo.rb', line 556 def self.evaluate_template(template_name, bind) logger.debug "Evaluating template #{template_name}" template_dir = File.('../../templates', File.dirname(__FILE__)) if File.file?(File.("./spec/templates/#{template_name}", @root)) puts "Using Custom #{template_name}" template = File.read(File.("./spec/templates/#{template_name}", @root)) else template = File.read(File.("./#{template_name}", template_dir)) end ERB.new(template, nil, '-').result(bind) end |
.facts(filter = nil) ⇒ Object
72 73 74 |
# File 'lib/onceover/controlrepo.rb', line 72 def self.facts(filter = nil) @@existing_controlrepo.facts(filter, 'values') end |
.facts_files ⇒ Object
52 53 54 |
# File 'lib/onceover/controlrepo.rb', line 52 def self.facts_files @@existing_controlrepo.facts_files end |
.generate_nodesets(repo) ⇒ Object
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/onceover/controlrepo.rb', line 498 def self.generate_nodesets(repo) warn "[DEPRECATION] #{__method__} is deprecated due to the removal of Beaker" require 'onceover/beaker' require 'multi_json' require 'net/http' hosts_hash = {} repo.facts.each do |fact_set| node_name = File.basename(repo.facts_files[repo.facts.index(fact_set)], '.json') boxname = Onceover::Beaker.facts_to_vagrant_box(fact_set) platform = Onceover::Beaker.facts_to_platform(fact_set) logger.debug "Querying hashicorp API for Vagrant box that matches #{boxname}" uri = URI("https://atlas.hashicorp.com:443/api/v1/box/#{boxname}") request = Net::HTTP.new(uri.host, uri.port) request.use_ssl = true response = request.get(uri) url = 'URL goes here' if response.code == "404" comment_out = true else comment_out = false box_info = MultiJson.load(response.body) box_info['current_version']['providers'].each do |provider| if provider['name'] == 'virtualbox' url = provider['original_url'] end end end # Add the resulting info to the hosts hash. This is what the # template will output hosts_hash[node_name] = { :platform => platform, :boxname => boxname, :url => url, :comment_out => comment_out } end # Use an ERB template evaluate_template('nodeset.yaml.erb', binding) end |
.generate_onceover_yaml(repo) ⇒ Object
493 494 495 496 |
# File 'lib/onceover/controlrepo.rb', line 493 def self.generate_onceover_yaml(repo) # This will return a controlrepo.yaml that can be written to a file evaluate_template('controlrepo.yaml.erb', binding) end |
.hiera_config_file ⇒ Object
80 81 82 |
# File 'lib/onceover/controlrepo.rb', line 80 def self.hiera_config_file @@existing_controlrepo.hiera_config_file end |
.init(repo) ⇒ Object
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/onceover/controlrepo.rb', line 450 def self.init(repo) # This code will initialise a controlrepo with all of the config # that it needs require 'pathname' require 'colored' Onceover::Controlrepo.init_write_file(generate_onceover_yaml(repo), repo.onceover_yaml) # [DEPRECATION] Writing nodesets is deprecated due to the removal of Beaker" #Onceover::Controlrepo.init_write_file(generate_nodesets(repo),repo.nodeset_file) init_write_file( evaluate_template('pre_conditions_README.md.erb', binding), File.('./pre_conditions/README.md', repo.spec_dir) ) init_write_file( evaluate_template('factsets_README.md.erb', binding), File.('./factsets/README.md', repo.spec_dir) ) init_write_file( evaluate_template('Rakefile.erb', binding), File.('./Rakefile', repo.root) ) init_write_file( evaluate_template('Gemfile.erb', binding), File.('./Gemfile', repo.root) ) # Add .onceover to Gitignore gitignore_path = File.('.gitignore', repo.root) if File.exist? gitignore_path gitignore_content = (File.open(gitignore_path, 'r') {|f| f.read }).split("\n") = "#{'changed'.green}" else = "#{'created'.green}" gitignore_content = [] end unless gitignore_content.include?(".onceover") gitignore_content << ".onceover\n" File.open(gitignore_path, 'w') {|f| f.write(gitignore_content.join("\n")) } puts "#{} #{Pathname.new(gitignore_path).relative_path_from(Pathname.new(Dir.pwd)).to_s}" end end |
.init_write_file(contents, out_file) ⇒ Object
568 569 570 571 572 573 574 575 576 |
# File 'lib/onceover/controlrepo.rb', line 568 def self.init_write_file(contents, out_file) create_dirs_and_log(File.dirname(out_file)) if File.exist?(out_file) puts "#{'skipped'.yellow} #{Pathname.new(out_file).relative_path_from(Pathname.new(Dir.pwd)).to_s} #{'(exists)'.yellow}" else File.open(out_file,'w') {|f| f.write(contents)} puts "#{'created'.green} #{Pathname.new(out_file).relative_path_from(Pathname.new(Dir.pwd)).to_s}" end end |
.profiles ⇒ Object
64 65 66 |
# File 'lib/onceover/controlrepo.rb', line 64 def self.profiles @@existing_controlrepo.profiles end |
.puppetfile ⇒ Object
48 49 50 |
# File 'lib/onceover/controlrepo.rb', line 48 def self.puppetfile @@existing_controlrepo.puppetfile end |
.roles ⇒ Object
60 61 62 |
# File 'lib/onceover/controlrepo.rb', line 60 def self.roles @@existing_controlrepo.roles end |
.root ⇒ Object
Create methods on self so that we can access these basic things without having to actually instantiate the class, I’m debating how much stuff I should be putting in here, we don’t reeeally need to instantiate the object unless we want to modify it’s parameters, so maybe everything. We shall see…
And yeah I know this makes little sense, but it will look nicer to type, promise
Also it’s probably pretty memory hungry, but let’s be honest, how many times would be be calling this? If we call it over and over you can just instantiate it anyway
44 45 46 |
# File 'lib/onceover/controlrepo.rb', line 44 def self.root @@existing_controlrepo.root end |
.trusted_facts(filter = nil) ⇒ Object
76 77 78 |
# File 'lib/onceover/controlrepo.rb', line 76 def self.trusted_facts(filter = nil) @@existing_controlrepo.facts(filter, 'trusted') end |
Instance Method Details
#classes ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/onceover/controlrepo.rb', line 158 def classes logger.debug('scanning for classes specified in onceover.yaml') # Get all of the possible places for puppet code and look for classes code_dirs = self.config['modulepath'] # Remove interpolated references code_dirs.delete_if { |dir| dir[0] == '$'} # Include all r10k-downloaded modules to support vendored and/or separate # role and profile classes code_dirs << "#{@tempdir}/#{@environmentpath}/production/modules" # Make sure that the paths are relative to the controlrepo root code_dirs.map! do |dir| File.(dir, @root) end # Get all the classes from all of the manifests classes = [] code_dirs.each do |dir| classes << get_classes(dir) end classes.flatten end |
#config ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/onceover/controlrepo.rb', line 401 def config logger.debug "Reading #{@environment_conf}" env_conf = File.read(@environment_conf) env_conf = env_conf.split("\n") # Delete commented out lines env_conf.delete_if { |l| l =~ /^\s*#/} # Map the lines into a hash environment_config = {} env_conf.each do |line| if matches = line.match(/^(\S+)\s*=(.*)$/) environment_config[matches[1]] = matches[2].strip end end # Finally, split the modulepath values and return begin environment_config['modulepath'] = environment_config['modulepath'].split(':') rescue raise "modulepath was not found in environment.conf, don't know where to look for roles & profiles" end environment_config end |
#facts(filter = nil, key = 'values') ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/onceover/controlrepo.rb', line 183 def facts(filter = nil, key = 'values') # Returns an array facts hashes all_facts = [] logger.debug "Reading factsets" @facts_files.each do |file| all_facts << read_facts(file)[key] end if filter # Allow us to pass a hash of facts to filter by raise "Filter param must be a hash" unless filter.is_a?(Hash) all_facts.keep_if do |hash| matches = [] filter.each do |filter_fact,value| matches << keypair_is_in_hash(hash,filter_fact,value) end if matches.include? false false else true end end end return all_facts end |
#fixtures ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/onceover/controlrepo.rb', line 304 def fixtures # Load up the Puppetfile using R10k puppetfile = R10K::Puppetfile.new(@root) fail 'Could not load Puppetfile' unless puppetfile.load modules = puppetfile.modules # Iterate over everything and seperate it out for the sake of readability symlinks = [] forge_modules = [] repositories = [] modules.each do |mod| logger.debug "Converting #{mod.to_s} to .fixtures.yml format" # This logic could probably be cleaned up. A lot. if mod.is_a? R10K::Module::Forge if mod.expected_version.is_a?(Hash) # Set it up as a symlink, because we are using local files in the Puppetfile symlinks << { 'name' => mod.name, 'dir' => mod.expected_version[:path] } elsif mod.expected_version.is_a?(String) # Set it up as a normal forge module forge_modules << { 'name' => mod.name, 'repo' => mod.title, 'ref' => mod.expected_version } end elsif mod.is_a? R10K::Module::Git # Set it up as a git repo repositories << { 'name' => mod.name, # I know I shouldn't be doing this, but trust me, there are no methods # anywhere that expose this value, I looked. 'repo' => mod.instance_variable_get(:@remote), 'ref' => mod.version } end end # also add synlinks for anything that is in environment.conf code_dirs = self.config['modulepath'] code_dirs.delete_if { |dir| dir[0] == '$'} code_dirs.each do |dir| # We need to traverse down into these directories and create a symlink for each # module we find because fixtures.yml is expecting the module's root not the # root of modulepath Dir["#{dir}/*"].each do |mod| symlinks << { 'name' => File.basename(mod), 'dir' => Pathname.new(File.(mod)).relative_path_from(Pathname.new(@root))#File.expand_path(mod) } end end # Use an ERB template to write the files Onceover::Controlrepo.evaluate_template('.fixtures.yml.erb', binding) end |
#hiera_config ⇒ Object
379 380 381 382 383 384 385 386 |
# File 'lib/onceover/controlrepo.rb', line 379 def hiera_config begin YAML.load_file(hiera_config_file) rescue TypeError puts "WARNING: Could not find hiera config file, continuing" nil end end |
#hiera_config=(data) ⇒ Object
388 389 390 |
# File 'lib/onceover/controlrepo.rb', line 388 def hiera_config=(data) File.write(hiera_config_file,data.to_yaml) end |
#hiera_config_file ⇒ Object
364 365 366 367 368 369 370 371 372 373 |
# File 'lib/onceover/controlrepo.rb', line 364 def hiera_config_file case when File.exist?(File.('./hiera.yaml', @spec_dir)) File.('./hiera.yaml', @spec_dir) when File.exist?(File.('./hiera.yaml', @root)) File.('./hiera.yaml', @root) else nil end end |
#hiera_config_file_relative_path ⇒ Object
375 376 377 |
# File 'lib/onceover/controlrepo.rb', line 375 def hiera_config_file_relative_path Pathname.new(hiera_config_file).relative_path_from(Pathname.new(root)).to_s if hiera_config_file end |
#hiera_data ⇒ Object
392 393 394 395 396 397 398 399 |
# File 'lib/onceover/controlrepo.rb', line 392 def hiera_data # This is going to try to find your hiera data directory, if you have named it something # unexpected it won't work possibe_datadirs = Dir["#{@root}/*/"] possibe_datadirs.keep_if { |dir| dir =~ /hiera(?:.*data)?/i } raise "There were too many directories that looked like hiera data: #{possibe_datadirs}" if possibe_datadirs.count > 1 File.(possibe_datadirs[0]) end |
#print_puppetfile_table ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/onceover/controlrepo.rb', line 208 def print_puppetfile_table require 'table_print' require 'versionomy' require 'colored' require 'r10k/puppetfile' # Load up the Puppetfile using R10k logger.debug "Reading puppetfile from #{@root}" puppetfile = R10K::Puppetfile.new(@root) logger.debug "Loading modules from Puppetfile" puppetfile.load! output_array = [] threads = [] puppetfile.modules.each do |mod| threads << Thread.new do return_hash = {} logger.debug "Loading data for #{mod.full_name}" return_hash[:full_name] = mod.full_name if mod.is_a?(R10K::Module::Forge) return_hash[:current_version] = mod.expected_version return_hash[:latest_version] = mod.v3_module.current_release.version return_hash[:endorsement] = mod.v3_module.endorsement superseded_by = mod.v3_module.superseded_by return_hash[:superseded_by] = superseded_by.nil? ? '' : superseded_by[:slug] current = Versionomy.parse(return_hash[:current_version]) latest = Versionomy.parse(return_hash[:latest_version]) if current.major < latest.major return_hash[:out_of_date] = "Major".red elsif current.minor < latest.minor return_hash[:out_of_date] = "Minor".yellow elsif current.tiny < latest.tiny return_hash[:out_of_date] = "Tiny".green else return_hash[:out_of_date] = "No".green end else return_hash[:current_version] = "N/A" return_hash[:latest_version] = "N/A" return_hash[:out_of_date] = "N/A" return_hash[:endorsement] = "N/A" return_hash[:superseded_by] = "N/A" end output_array << return_hash end end threads.map(&:join) tp output_array, {:full_name => {:display_name => "Full Name"}}, {:current_version => {:display_name => "Current Version"}}, {:latest_version => {:display_name => "Latest Version"}}, {:out_of_date => {:display_name => "Out of Date?"}}, {:endorsement => {:display_name => "Endorsement"}}, {:superseded_by => {:display_name => "Superseded by"}} end |
#profiles ⇒ Object
154 155 156 |
# File 'lib/onceover/controlrepo.rb', line 154 def profiles classes.keep_if { |c| c =~ @profile_regex } end |
#r10k_config ⇒ Object
438 439 440 |
# File 'lib/onceover/controlrepo.rb', line 438 def r10k_config YAML.load_file(r10k_config_file) end |
#r10k_config=(data) ⇒ Object
442 443 444 |
# File 'lib/onceover/controlrepo.rb', line 442 def r10k_config=(data) File.write(r10k_config_file, data.to_yaml) end |
#r10k_config_file ⇒ Object
427 428 429 430 431 432 433 434 435 436 |
# File 'lib/onceover/controlrepo.rb', line 427 def r10k_config_file case when File.exist?(File.('./r10k.yaml', @spec_dir)) File.('./r10k.yaml', @spec_dir) when File.exist?(File.('./r10k.yaml', @root)) File.('./r10k.yaml', @root) else nil end end |
#roles ⇒ Object
150 151 152 |
# File 'lib/onceover/controlrepo.rb', line 150 def roles classes.keep_if { |c| c =~ @role_regex } end |
#spec_tests(&block) ⇒ Object
Returns the deduplicted and verified output of testconfig.spec_tests for use in Rspec tests so that we don’t have to deal with more than one object
580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/onceover/controlrepo.rb', line 580 def spec_tests(&block) require 'onceover/testconfig' # Load up all of the tests and deduplicate them testconfig = Onceover::TestConfig.new(@onceover_yaml, @opts) testconfig.spec_tests.each { |tst| testconfig.verify_spec_test(self, tst) } tests = testconfig.run_filters(Onceover::Test.deduplicate(testconfig.spec_tests)) # Loop over each test, executing the user's block on each tests.each do |tst| block.call(tst.classes[0].name, tst.nodes[0].name, tst.nodes[0].fact_set, testconfig.pre_condition) end end |
#temp_manifest ⇒ Object
446 447 448 |
# File 'lib/onceover/controlrepo.rb', line 446 def temp_manifest config['manifest'] ? File.(config['manifest'], @tempdir) : nil end |
#to_s ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/onceover/controlrepo.rb', line 134 def to_s require 'colored' <<-END.gsub(/^\s{4}/,'') #{'puppetfile'.green} #{@puppetfile} #{'environment_conf'.green} #{@environment_conf} #{'facts_dir'.green} #{@facts_dir} #{'spec_dir'.green} #{@spec_dir} #{'facts_files'.green} #{@facts_files} #{'nodeset_file'.green} #{@nodeset_file} #{'roles'.green} #{roles} #{'profiles'.green} #{profiles} #{'onceover.yaml'.green} #{@onceover_yaml} END end |
#update_puppetfile ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/onceover/controlrepo.rb', line 266 def update_puppetfile require 'r10k/puppetfile' # Read in the Puppetfile as a string and as an object puppetfile_string = File.read(@puppetfile).split("\n") puppetfile = R10K::Puppetfile.new(@root) puppetfile.load! # TODO: Make sure we can deal with :latest # Create threading resources threads = [] queue = Queue.new queue.push(puppetfile_string) puppetfile.modules.keep_if {|m| m.is_a?(R10K::Module::Forge)} puppetfile.modules.each do |mod| threads << Thread.new do logger.debug "Getting latest version of #{mod.full_name}" latest_version = mod.v3_module.current_release.version # Get the data off the queue, or wait if something else is using it puppetfile_string_temp = queue.pop line_index = puppetfile_string_temp.index {|l| l =~ /^\s*[^#]*#{mod.owner}[\/-]#{mod.name}/} puppetfile_string_temp[line_index].gsub!(mod.expected_version,latest_version) # Put the data back into the queue once we are done with it queue.push(puppetfile_string_temp) end end threads.map(&:join) puppetfile_string = queue.pop File.open(@puppetfile, 'w') {|f| f.puts(puppetfile_string.join("\n")) } puts "#{'changed'.yellow} #{@puppetfile}" end |