beaker 1.8.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,16 +42,6 @@ module Beaker
42
42
  end
43
43
  end
44
44
 
45
- def hack_etc_hosts hosts
46
- etc_hosts = "127.0.0.1\tlocalhost localhost.localdomain\n"
47
- hosts.each do |host|
48
- etc_hosts += "#{host['ip'].to_s}\t#{host.name}\n"
49
- end
50
- hosts.each do |host|
51
- set_etc_hosts(host, etc_hosts)
52
- end
53
- end
54
-
55
45
  def set_ssh_config host, user
56
46
  f = Tempfile.new("#{host.name}")
57
47
  ssh_config = Dir.chdir(@vagrant_path) do
@@ -1,8 +1,7 @@
1
1
  require 'yaml' unless defined?(YAML)
2
2
 
3
- module Beaker
3
+ module Beaker
4
4
  class Vcloud < Beaker::Hypervisor
5
- CHARMAP = [('a'..'z'),('0'..'9')].map{|r| r.to_a}.flatten
6
5
 
7
6
  def initialize(vcloud_hosts, options)
8
7
  @options = options
@@ -52,17 +51,15 @@ module Beaker
52
51
  end
53
52
  end
54
53
 
55
- def generate_host_name
56
- CHARMAP[rand(25)] + (0...14).map{CHARMAP[rand(CHARMAP.length)]}.join
57
- end
58
-
59
54
  def create_clone_spec host
60
55
  # Add VM annotation
61
56
  configSpec = RbVmomi::VIM.VirtualMachineConfigSpec(
62
57
  :annotation =>
63
58
  'Base template: ' + host['template'] + "\n" +
64
59
  'Creation time: ' + Time.now.strftime("%Y-%m-%d %H:%M") + "\n\n" +
65
- 'CI build link: ' + ( ENV['BUILD_URL'] || 'Deployed independently of CI' )
60
+ 'CI build link: ' + ( ENV['BUILD_URL'] || 'Deployed independently of CI' ) +
61
+ 'department: ' + @options[:department] +
62
+ 'project: ' + @options[:project]
66
63
  )
67
64
 
68
65
  # Are we using a customization spec?
@@ -95,44 +92,44 @@ module Beaker
95
92
  connect_to_vsphere
96
93
  begin
97
94
  vsphere_vms = {}
98
-
95
+
99
96
  try = 1
100
97
  attempts = @options[:timeout].to_i / 5
101
-
98
+
102
99
  start = Time.now
103
100
  tasks = []
104
101
  @hosts.each_with_index do |h, i|
105
102
  # Generate a randomized hostname
106
103
  h['vmhostname'] = generate_host_name
107
-
104
+
108
105
  if h['template'] =~ /\//
109
106
  templatefolders = h['template'].split('/')
110
107
  h['template'] = templatefolders.pop
111
108
  end
112
-
109
+
113
110
  @logger.notify "Deploying #{h['vmhostname']} (#{h.name}) to #{@options['folder']} from template '#{h['template']}'"
114
-
111
+
115
112
  vm = {}
116
-
113
+
117
114
  if templatefolders
118
115
  vm[h['template']] = @vsphere_helper.find_folder(templatefolders.join('/')).find(h['template'])
119
116
  else
120
117
  vm = @vsphere_helper.find_vms(h['template'])
121
118
  end
122
-
119
+
123
120
  if vm.length == 0
124
121
  raise "Unable to find template '#{h['template']}'!"
125
122
  end
126
-
123
+
127
124
  spec = create_clone_spec(h)
128
-
125
+
129
126
  # Deploy from specified template
130
127
  tasks << vm[h['template']].CloneVM_Task( :folder => @vsphere_helper.find_folder(@options['folder']), :name => h['vmhostname'], :spec => spec )
131
128
  end
132
129
  try = (Time.now - start) / 5
133
130
  @vsphere_helper.wait_for_tasks(tasks, try, attempts)
134
131
  @logger.notify 'Spent %.2f seconds deploying VMs' % (Time.now - start)
135
-
132
+
136
133
  try = (Time.now - start) / 5
137
134
  duration = run_and_report_duration do
138
135
  @hosts.each_with_index do |h, i|
@@ -140,7 +137,7 @@ module Beaker
140
137
  end
141
138
  end
142
139
  @logger.notify "Spent %.2f seconds booting and waiting for vSphere registration" % duration
143
-
140
+
144
141
  try = (Time.now - start) / 5
145
142
  duration = run_and_report_duration do
146
143
  @hosts.each_with_index do |h, i|
@@ -149,7 +146,7 @@ module Beaker
149
146
  end
150
147
  @logger.notify "Spent %.2f seconds waiting for DNS resolution" % duration
151
148
  rescue => e
152
- @vsphere_helper.close
149
+ @vsphere_helper.close
153
150
  report_and_raise(@logger, e, "Vcloud.provision")
154
151
  end
155
152
  end
@@ -163,7 +160,7 @@ module Beaker
163
160
  @logger.warn "Some hosts did not have vmhostname set correctly! This likely means VM provisioning was not successful"
164
161
  end
165
162
  vms = @vsphere_helper.find_vms vm_names
166
- begin
163
+ begin
167
164
  vm_names.each do |name|
168
165
  unless vm = vms[name]
169
166
  @logger.warn "Unable to cleanup #{name}, couldn't find VM #{name} in vSphere!"
@@ -178,7 +175,7 @@ module Beaker
178
175
  @logger.notify "Spent %.2f seconds halting #{vm.name}" % duration
179
176
  end
180
177
 
181
- duration = run_and_report_duration do
178
+ duration = run_and_report_duration do
182
179
  vm.Destroy_Task
183
180
  end
184
181
  @logger.notify "Spent %.2f seconds destroying #{vm.name}" % duration
@@ -4,7 +4,6 @@ require 'net/http'
4
4
 
5
5
  module Beaker
6
6
  class VcloudPooled < Beaker::Hypervisor
7
- CHARMAP = [('a'..'z'),('0'..'9')].map{|r| r.to_a}.flatten
8
7
  SSH_EXCEPTIONS = [
9
8
  SocketError,
10
9
  Timeout::Error,
@@ -5,7 +5,7 @@ module Beaker
5
5
  #An Object that parses, merges and normalizes all supported Beaker options and arguments
6
6
  class Parser
7
7
  GITREPO = 'git://github.com/puppetlabs'
8
- #These options can have the form of arg1,arg2 or [arg] or just arg,
8
+ #These options can have the form of arg1,arg2 or [arg] or just arg,
9
9
  #should default to []
10
10
  LONG_OPTS = [:helper, :load_path, :tests, :pre_suite, :post_suite, :install, :modules]
11
11
  #These options expand out into an array of .rb files
@@ -20,7 +20,9 @@ module Beaker
20
20
  :pe_dir => ENV['pe_dist_dir'],
21
21
  :pe_version_file => ENV['pe_version_file'],
22
22
  :pe_version_file_win => ENV['pe_version_file'],
23
- :pe_ver => ENV['pe_ver']
23
+ :pe_ver => ENV['pe_ver'],
24
+ :project => ENV['BEAKER_project'],
25
+ :department => ENV['BEAKER_department'],
24
26
  }.delete_if {|key, value| value.nil? or value.empty? })
25
27
  end
26
28
 
@@ -30,6 +32,8 @@ module Beaker
30
32
  def self.presets
31
33
  h = Beaker::Options::OptionsHash.new
32
34
  h.merge({
35
+ :project => 'Beaker',
36
+ :department => ENV['USER'] || ENV['USERNAME'] || 'unknown',
33
37
  :log_level => 'verbose',
34
38
  :trace_limit => 10,
35
39
  :hosts_file => 'sample.cfg',
@@ -1,8 +1,10 @@
1
1
  module Beaker
2
+ #This class create a Platform object inheriting from String. It supports all String methods while adding
3
+ #several platform-specific use cases.
2
4
  class Platform < String
3
- #supported platforms
5
+ #Supported platforms
4
6
  PLATFORMS = /^(centos|fedora|debian|oracle|redhat|scientific|sles|ubuntu|windows|solaris|aix|el)\-.+\-.+$/
5
-
7
+ #Platform version numbers vs. codenames conversion hash
6
8
  PLATFORM_VERSION_CODES =
7
9
  { :debian => { "wheezy" => "7",
8
10
  "squeeze" => "6",
@@ -15,6 +17,20 @@ module Beaker
15
17
  },
16
18
  }
17
19
 
20
+ #Creates the Platform object. Checks to ensure that the platform String provided meets the platform
21
+ #formatting rules. Platforms name must be of the format /^OSFAMILY-VERSION-ARCH.*$/ where OSFAMILY is one of:
22
+ # * centos
23
+ # * fedora
24
+ # * debian
25
+ # * oracle
26
+ # * redhat
27
+ # * scientific
28
+ # * sles
29
+ # * ubuntu
30
+ # * windows
31
+ # * solaris
32
+ # * aix
33
+ # * el
18
34
  def initialize(name)
19
35
  if name !~ PLATFORMS
20
36
  raise ArgumentError, "Unsupported platform name #{name}"
@@ -22,6 +38,10 @@ module Beaker
22
38
  super
23
39
  end
24
40
 
41
+ # Returns the platform string with the platform version as a codename. If no conversion is
42
+ # necessary then the original, unchanged platform String is returned.
43
+ # @example Platform.new('debian-7-xxx').with_version_codename == 'debian-wheezy-xxx'
44
+ # @return [String] the platform string with the platform version represented as a codename
25
45
  def with_version_codename
26
46
  name, version, extra = self.split('-', 3)
27
47
  PLATFORM_VERSION_CODES.each_key do |platform|
@@ -39,6 +59,10 @@ module Beaker
39
59
  [name, version, extra].join('-')
40
60
  end
41
61
 
62
+ # Returns the platform string with the platform version as a number. If no conversion is necessary
63
+ # then the original, unchanged platform String is returned.
64
+ # @example Platform.new('debian-wheezy-xxx').with_version_number == 'debian-7-xxx'
65
+ # @return [String] the platform string with the platform version represented as a number
42
66
  def with_version_number
43
67
  name, version, extra = self.split('-', 3)
44
68
  PLATFORM_VERSION_CODES.each_key do |platform|
@@ -1,5 +1,5 @@
1
1
  module Beaker
2
2
  module Version
3
- STRING = '1.8.2'
3
+ STRING = '1.9.0'
4
4
  end
5
5
  end
@@ -169,7 +169,7 @@ describe ClassMixedWithDSLInstallUtils do
169
169
  path = unixhost['pe_dir']
170
170
  filename = "#{ unixhost['dist'] }"
171
171
  extension = '.tar'
172
- subject.should_receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | tar -xvf -" ).once
172
+ subject.should_receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | tar -xvf -" ).once
173
173
  subject.fetch_puppet( [unixhost], {} )
174
174
  end
175
175
 
@@ -182,7 +182,7 @@ describe ClassMixedWithDSLInstallUtils do
182
182
  path = unixhost['pe_dir']
183
183
  filename = "#{ unixhost['dist'] }"
184
184
  extension = '.tar.gz'
185
- subject.should_receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | gunzip | tar -xvf -" ).once
185
+ subject.should_receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | gunzip | tar -xvf -" ).once
186
186
  subject.fetch_puppet( [unixhost], {} )
187
187
  end
188
188
 
@@ -21,6 +21,21 @@ module Beaker
21
21
  expect{ fusion.provision }.to raise_error
22
22
  end
23
23
 
24
+ it 'raises an error if snapshots is nil' do
25
+ MockFissionVM.set_snapshots(nil)
26
+ expect{ fusion.provision }.to raise_error(/No snapshots available/)
27
+ end
28
+
29
+ it 'raises an error if snapshots are empty' do
30
+ MockFissionVM.set_snapshots([])
31
+ expect{ fusion.provision }.to raise_error(/No snapshots available/)
32
+ end
33
+
34
+ it 'host fails init with nil snapshot' do
35
+ @hosts[0][:snapshot] = nil
36
+ expect{ Beaker::Fusion.new( @hosts, make_opts) }.to raise_error(/specify a snapshot/)
37
+ end
38
+
24
39
  end
25
40
 
26
41
  end
@@ -38,7 +38,7 @@ module Beaker
38
38
 
39
39
  generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
40
40
 
41
- match = generated_file.match(/vb.customize \["modifyvm", :id, "--memory", "hello!"]/)
41
+ match = generated_file.match(/vb.customize \["modifyvm", :id, "--memory", "hello!"\]/)
42
42
 
43
43
  expect( match ).to_not be nil
44
44
 
@@ -50,7 +50,7 @@ module Beaker
50
50
  vagrant.should_receive( :set_etc_hosts ).with( host, "127.0.0.1\tlocalhost localhost.localdomain\nip.address.for.vm1\tvm1\nip.address.for.vm2\tvm2\nip.address.for.vm3\tvm3\n" ).once
51
51
  end
52
52
 
53
- vagrant.hack_etc_hosts( @hosts )
53
+ vagrant.hack_etc_hosts( @hosts, options )
54
54
 
55
55
  end
56
56
 
@@ -133,7 +133,7 @@ module Beaker
133
133
  it "can correctly combine arguments from different sources" do
134
134
  FakeFS.deactivate!
135
135
  args = ["-h", hosts_path, "--log-level", "debug", "--type", "git", "--install", "PUPPET/1.0,HIERA/hello"]
136
- expect(parser.parse_args(args)).to be === {:log_level=>"debug", :trace_limit=>10, :hosts_file=>hosts_path, :options_file=>nil, :type=>"git", :provision=>true, :preserve_hosts=>'never', :root_keys=>false, :quiet=>false, :xml=>false, :color=>true, :dry_run=>false, :timeout=>300, :fail_mode=>'slow', :timesync=>false, :repo_proxy=>false, :add_el_extras=>false, :add_master_entry=>false, :consoleport=>443, :pe_dir=>"/opt/enterprise/dists", :pe_version_file=>"LATEST", :pe_version_file_win=>"LATEST-win", :dot_fog=>"#{home}/.fog", :help=>false, :ec2_yaml=>"config/image_templates/ec2.yaml", :ssh=>{:config=>false, :paranoid=>false, :timeout=>300, :auth_methods=>["publickey"], :port=>22, :forward_agent=>true, :keys=>["#{home}/.ssh/id_rsa"], :user_known_hosts_file=>"#{home}/.ssh/known_hosts"}, :install=>["git://github.com/puppetlabs/puppet.git#1.0", "git://github.com/puppetlabs/hiera.git#hello"], :HOSTS=>{:"pe-ubuntu-lucid"=>{:roles=>["agent", "dashboard", "database", "master"], :vmname=>"pe-ubuntu-lucid", :platform=>"ubuntu-10.04-i386", :snapshot=>"clean-w-keys", :hypervisor=>"fusion"}, :"pe-centos6"=>{:roles=>["agent"], :vmname=>"pe-centos6", :platform=>"el-6-i386", :hypervisor=>"fusion", :snapshot=>"clean-w-keys"}}, :nfs_server=>"none", :helper=>[], :load_path=>[], :tests=>[], :pre_suite=>[], :post_suite=>[], :modules=>[]}
136
+ expect(parser.parse_args(args)).to be === {:project=>"Beaker", :department=>"#{ENV['USER']}", :log_level=>"debug", :trace_limit=>10, :hosts_file=>hosts_path, :options_file=>nil, :type=>"git", :provision=>true, :preserve_hosts=>'never', :root_keys=>false, :quiet=>false, :xml=>false, :color=>true, :dry_run=>false, :timeout=>300, :fail_mode=>'slow', :timesync=>false, :repo_proxy=>false, :add_el_extras=>false, :add_master_entry=>false, :consoleport=>443, :pe_dir=>"/opt/enterprise/dists", :pe_version_file=>"LATEST", :pe_version_file_win=>"LATEST-win", :dot_fog=>"#{home}/.fog", :help=>false, :ec2_yaml=>"config/image_templates/ec2.yaml", :ssh=>{:config=>false, :paranoid=>false, :timeout=>300, :auth_methods=>["publickey"], :port=>22, :forward_agent=>true, :keys=>["#{home}/.ssh/id_rsa"], :user_known_hosts_file=>"#{home}/.ssh/known_hosts"}, :install=>["git://github.com/puppetlabs/puppet.git#1.0", "git://github.com/puppetlabs/hiera.git#hello"], :HOSTS=>{:"pe-ubuntu-lucid"=>{:roles=>["agent", "dashboard", "database", "master"], :vmname=>"pe-ubuntu-lucid", :platform=>"ubuntu-10.04-i386", :snapshot=>"clean-w-keys", :hypervisor=>"fusion"}, :"pe-centos6"=>{:roles=>["agent"], :vmname=>"pe-centos6", :platform=>"el-6-i386", :hypervisor=>"fusion", :snapshot=>"clean-w-keys"}}, :nfs_server=>"none", :helper=>[], :load_path=>[], :tests=>[], :pre_suite=>[], :post_suite=>[], :modules=>[]}
137
137
  end
138
138
 
139
139
  it "ensures that fail-mode is one of fast/slow" do
@@ -53,7 +53,11 @@ module HostHelpers
53
53
  :pooling_api => 'http://vcloud.delivery.puppetlabs.net/',
54
54
  :datastore => 'instance0',
55
55
  :folder => 'Delivery/Quality Assurance/Staging/Dynamic',
56
- :resourcepool => 'delivery/Quality Assurance/Staging/Dynamic' } )
56
+ :resourcepool => 'delivery/Quality Assurance/Staging/Dynamic',
57
+ :gce_project => 'beaker-compute',
58
+ :gce_keyfile => '/path/to/keyfile.p12',
59
+ :gce_password => 'notasecret',
60
+ :gce_email => '12345678910@developer.gserviceaccount.com' } )
57
61
  end
58
62
 
59
63
  def generate_result (name, opts )
@@ -1,5 +1,5 @@
1
1
  class MockShip
2
- attr_accessor :name, :ports, :image_id, :flavor, :region, :username, :dns
2
+ attr_accessor :name, :ports, :image_id, :flavor, :region, :username, :dns, :tags
3
3
 
4
4
  def initialize
5
5
  @dns = "my.ip.address"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppetlabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2014-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 10.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 10.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - ~>
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0.4'
209
+ - !ruby/object:Gem::Dependency
210
+ name: google-api-client
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ~>
214
+ - !ruby/object:Gem::Version
215
+ version: 0.6.4
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ~>
221
+ - !ruby/object:Gem::Version
222
+ version: 0.6.4
209
223
  - !ruby/object:Gem::Dependency
210
224
  name: nokogiri
211
225
  requirement: !ruby/object:Gem::Requirement
@@ -306,6 +320,8 @@ files:
306
320
  - lib/beaker/hypervisor/aixer.rb
307
321
  - lib/beaker/hypervisor/blimper.rb
308
322
  - lib/beaker/hypervisor/fusion.rb
323
+ - lib/beaker/hypervisor/google_compute.rb
324
+ - lib/beaker/hypervisor/google_compute_helper.rb
309
325
  - lib/beaker/hypervisor/solaris.rb
310
326
  - lib/beaker/hypervisor/vagrant.rb
311
327
  - lib/beaker/hypervisor/vcloud.rb