Class: Controlrepo::Beaker
- Inherits:
-
Object
- Object
- Controlrepo::Beaker
- Defined in:
- lib/controlrepo/beaker.rb
Class Method Summary collapse
-
.deploy_controlrepo_on(host, repo = Controlrepo.new()) ⇒ Object
This little method will deploy a Controlrepo object to a host, just using r10k deploy.
-
.facts_to_platform(facts) ⇒ Object
This will take a fact set and return the beaker platform of that machine This is necissary as beaker needs the platform set up correctly to know which commands to run when we do stuff.
- .facts_to_vagrant_box(facts) ⇒ Object
-
.provision_and_test(host, puppet_class, opts = {}, repo = Controlrepo.new) ⇒ Object
This actually provisions a node and checks that puppet will be able to run and be idempotent.
Class Method Details
.deploy_controlrepo_on(host, repo = Controlrepo.new()) ⇒ Object
This little method will deploy a Controlrepo object to a host, just using r10k deploy
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 |
# File 'lib/controlrepo/beaker.rb', line 103 def self.deploy_controlrepo_on(host, repo = Controlrepo.new()) require 'beaker-rspec' require 'controlrepo' if host.is_a?(Array) hosts.each do |single_host| deploy_controlrepo_on(single_host) end end # Use a beaker helper to do the install (*nix only) install_r10k_on(host) # Use beaker to install git host.install_package('git') # copy the file over to the host (Maybe I should be changing the directory here??) scp_to(host,repo.r10k_config_file,'/tmp/r10k.yaml') # Do an r10k deploy r10k_deploy(host,{ :puppetfile => true, :configfile => '/tmp/r10k.yaml', }) end |
.facts_to_platform(facts) ⇒ Object
This will take a fact set and return the beaker platform of that machine This is necissary as beaker needs the platform set up correctly to know which commands to run when we do stuff. Personally I would prefer beaker to detect the platform as it would not be that hard, especially once puppet is installed, oh well.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/controlrepo/beaker.rb', line 57 def self.facts_to_platform(facts) if facts.is_a?(Array) returnval = [] facts.each do |fact| returnval << self.facts_to_platform(fact) end return returnval end begin if facts['os']['family'] == 'RedHat' platform = 'el' version = facts['os']['release']['major'] end rescue # Do nothing, this is the easiest way to handle the hash being in different formats end begin if facts['os']['distro']['id'] == 'Ubuntu' platform = 'ubuntu' version = facts['os']['distro']['release']['major'] end rescue # Do nothing, this is the easiest way to handle the hash being in different formats end begin if facts['os']['distro']['id'] == 'Debian' platform = 'debian' version = facts['os']['distro']['release']['full'] end rescue # Do nothing end if facts['os']['architecture'] =~ /64/ arch = '64' else arch = '32' end "#{platform}-#{version}-#{arch}" end |
.facts_to_vagrant_box(facts) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/controlrepo/beaker.rb', line 3 def self.facts_to_vagrant_box(facts) # Gets the most similar vagrant box to the facts set provided, will accept a single fact # se or an array if facts.is_a?(Array) returnval = [] facts.each do |fact| returnval << self.facts_to_vagrant_box(fact) end return returnval end begin if facts['os']['distro']['id'] == 'Ubuntu' os = 'ubuntu' version = facts['os']['distro']['release']['major'] end rescue # Do nothing, this is the easiest way to handle the hash bing in different formats end begin if facts['os']['distro']['id'] == 'Debian' os = 'Debian' version = facts['os']['distro']['release']['full'] end rescue # Do nothing end begin if facts['os']['family'] == "RedHat" os = 'centos' version = "#{facts['os']['release']['major']}.#{facts['os']['release']['minor']}" end rescue # Do nothing end return "UNKNOWN" unless os.is_a?(String) if facts['os']['architecture'] =~ /64/ arch = '64' else arch = '32' end "puppetlabs/#{os}-#{version}-#{arch}-puppet" end |
.provision_and_test(host, puppet_class, opts = {}, repo = Controlrepo.new) ⇒ Object
This actually provisions a node and checks that puppet will be able to run and be idempotent. It hacks the beaker NetworkManager object to do this. The reason is that beaker is designed to run in the following order:
1. Spin up nodes
2. Run all tests
3. Kill all nodes
This is not helpful for us. We want to be able to test all of our classes on all of our nodes, this could be a lot of vms and having them all running at once would be a real kick in the dick for whatever system was running it.
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 |
# File 'lib/controlrepo/beaker.rb', line 139 def self.provision_and_test(host,puppet_class,opts = {},repo = Controlrepo.new) opts = {:runs_before_idempotency => 1}.merge(opts) opts = {:check_idempotency => true}.merge(opts) opts = {:deploy_controlrepo => true}.merge(opts) raise "Hosts must be a single host object, not an array" if host.is_a?(Array) raise "Class must be a single Class [String], not an array" unless puppet_class.is_a?(String) # Create our own NWM object that we are going to interact with # Note here that 'options', 'logger' and are exposed within the rspec tests # if this is run outside of that context it will fail network_manager = ::Beaker::NetworkManager.new(,logger) # Hack the network manager to smash our host in there without provisioning network_manager.instance_variable_set(:@hosts,[host]) # Now that we have a working network manager object, we can provision, but only if # we need to, ahhh smart... unless host.up? network_manager.provision network_manager.proxy_package_manager network_manager.validate network_manager.configure end # Actually run the tests manifest = "include #{puppet_class}" opts[:runs_before_idempotency].times do apply_manifest_on(host,manifest,{:catch_failures => true}) end if opts[:check_idempotency] apply_manifest_on(host,manifest,{:catch_changes => true}) end network_manager.cleanup end |