beaker-google 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,5 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/core/rake_task'
2
4
 
5
+ begin
6
+ require 'voxpupuli/rubocop/rake'
7
+ rescue LoadError
8
+ # the voxpupuli-rubocop gem is optional
9
+ end
10
+
3
11
  ###########################################################
4
12
  #
5
13
  # Documentation Tasks
@@ -13,12 +21,12 @@ def running?(cmdline)
13
21
  found = ps.lines.grep(/#{Regexp.quote(cmdline)}/)
14
22
  raise StandardError, "Found multiple YARD Servers. Don't know what to do." if found.length > 1
15
23
 
16
- yes = found.empty? ? false : true
24
+ yes = !found.empty?
17
25
  [yes, found.first]
18
26
  end
19
27
 
20
28
  def pid_from(output)
21
- output.squeeze(' ').strip.split(' ')[1]
29
+ output.squeeze(' ').strip.split[1]
22
30
  end
23
31
 
24
32
  desc 'Start the documentation server in the foreground'
@@ -44,7 +52,7 @@ namespace :docs do
44
52
  Dir.chdir(__dir__)
45
53
  output = `bundle exec yard doc`
46
54
  puts output
47
- raise 'Errors/Warnings during yard documentation generation' if output =~ /\[warn\]|\[error\]/
55
+ raise 'Errors/Warnings during yard documentation generation' if /\[warn\]|\[error\]/.match?(output)
48
56
 
49
57
  Dir.chdir(original_dir)
50
58
  end
@@ -63,6 +71,7 @@ namespace :docs do
63
71
  end
64
72
  end
65
73
 
74
+ desc 'Alias for `background`'
66
75
  task(:bg) { Rake::Task['docs:background'].invoke }
67
76
 
68
77
  desc 'Check the status of the documentation server'
@@ -84,10 +93,10 @@ namespace :docs do
84
93
  puts "Found a YARD Server running with pid #{pid}"
85
94
  `kill #{pid}`
86
95
  puts 'Stopping...'
87
- yes, output = running?(DOCS_DAEMON)
96
+ yes, = running?(DOCS_DAEMON)
88
97
  if yes
89
98
  `kill -9 #{pid}`
90
- yes, output = running?(DOCS_DAEMON)
99
+ yes, = running?(DOCS_DAEMON)
91
100
  if yes
92
101
  puts 'Could not Stop Server!'
93
102
  else
@@ -106,9 +115,10 @@ begin
106
115
  require 'rubygems'
107
116
  require 'github_changelog_generator/task'
108
117
  rescue LoadError
118
+ # the github_changelog_generator gem is optional
109
119
  else
110
120
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
111
- config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog}
121
+ config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog]
112
122
  config.user = 'voxpupuli'
113
123
  config.project = 'beaker-google'
114
124
  gem_version = Gem::Specification.load("#{config.project}.gemspec").version
@@ -1,35 +1,36 @@
1
- # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
3
4
  require 'beaker-google/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "beaker-google"
7
+ s.name = 'beaker-google'
7
8
  s.version = BeakerGoogle::VERSION
8
- s.authors = ["Puppet", "Voxpupuli"]
9
- s.email = ["voxpupuli@groups.io"]
10
- s.homepage = "https://github.com/voxpupuli/beaker-google"
11
- s.summary = %q{Beaker DSL Extension Helpers!}
12
- s.description = %q{Google Compute Engine support for the Beaker acceptance testing tool.}
13
- s.license = 'Apache2'
9
+ s.authors = %w[Puppet Voxpupuli]
10
+ s.email = ['voxpupuli@groups.io']
11
+ s.homepage = 'https://github.com/voxpupuli/beaker-google'
12
+ s.summary = 'Beaker DSL Extension Helpers!'
13
+ s.description = 'Google Compute Engine support for the Beaker acceptance testing tool.'
14
+ s.license = 'Apache-2.0'
14
15
 
15
16
  s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
19
 
20
- s.required_ruby_version = Gem::Requirement.new('>= 2.4')
20
+ s.required_ruby_version = Gem::Requirement.new('>= 2.7')
21
21
 
22
22
  # Testing dependencies
23
- s.add_development_dependency 'rspec', '~> 3.0'
24
- s.add_development_dependency 'rspec-its'
25
23
  s.add_development_dependency 'fakefs', '~> 2.4'
26
- s.add_development_dependency 'rake', '~> 13.0'
27
- s.add_development_dependency 'simplecov'
28
24
  s.add_development_dependency 'pry', '~> 0.10'
25
+ s.add_development_dependency 'rake', '~> 13.0'
26
+ s.add_development_dependency 'rspec', '~> 3.0'
27
+ s.add_development_dependency 'rspec-its', '~> 1.3'
28
+ s.add_development_dependency 'simplecov', '~> 0.22.0'
29
+ s.add_development_dependency 'voxpupuli-rubocop', '~> 2.7.0'
29
30
 
30
31
  # Documentation dependencies
31
- s.add_development_dependency 'yard'
32
- s.add_development_dependency 'thin'
32
+ s.add_development_dependency 'thin', '~> 1.8', '>= 1.8.2'
33
+ s.add_development_dependency 'yard', '~> 0.9.36'
33
34
 
34
35
  # Run time dependencies
35
36
  s.add_runtime_dependency 'stringify-hash', '~> 0.0.0'
data/bin/beaker-google CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems' unless defined?(Gem)
4
5
  require 'beaker-google'
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'beaker/hypervisor/google_compute'
2
4
 
3
- class Beaker::Google < Beaker::GoogleCompute
5
+ module Beaker
6
+ class Google < Beaker::GoogleCompute
7
+ end
4
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
 
3
5
  module Beaker
@@ -5,6 +7,8 @@ module Beaker
5
7
  class GoogleCompute < Beaker::Hypervisor
6
8
  SLEEPWAIT = 5
7
9
 
10
+ WINDOWS_IMAGE_PROJECT = %w[windows-cloud windows-sql-cloud].freeze
11
+
8
12
  # Do some reasonable sleuthing on the SSH public key for GCE
9
13
 
10
14
  ##
@@ -15,9 +19,12 @@ module Beaker
15
19
  # @raise [Error] if the private key can not be found
16
20
  def find_google_ssh_private_key
17
21
  private_keyfile = ENV.fetch('BEAKER_gce_ssh_public_key',
18
- File.join(ENV.fetch('HOME', nil), '.ssh', 'google_compute_engine'))
19
- private_keyfile = @options[:gce_ssh_private_key] if @options[:gce_ssh_private_key] && !File.exist?(private_keyfile)
22
+ File.join(Dir.home, '.ssh', 'google_compute_engine'))
23
+ if @options[:gce_ssh_private_key] && !File.exist?(private_keyfile)
24
+ private_keyfile = @options[:gce_ssh_private_key]
25
+ end
20
26
  raise("Could not find GCE Private SSH key at '#{keyfile}'") unless File.exist?(private_keyfile)
27
+
21
28
  @options[:gce_ssh_private_key] = private_keyfile
22
29
  private_keyfile
23
30
  end
@@ -33,6 +40,7 @@ module Beaker
33
40
  public_keyfile = private_keyfile << '.pub'
34
41
  public_keyfile = @options[:gce_ssh_public_key] if @options[:gce_ssh_public_key] && !File.exist?(public_keyfile)
35
42
  raise("Could not find GCE Public SSH key at '#{keyfile}'") unless File.exist?(public_keyfile)
43
+
36
44
  @options[:gce_ssh_public_key] = public_keyfile
37
45
  public_keyfile
38
46
  end
@@ -89,25 +97,40 @@ module Beaker
89
97
  # set firewall to open pe ports
90
98
  network = @gce_helper.get_network
91
99
 
92
- @external_firewall_name = test_group_identifier + '-external'
100
+ @external_firewall_name = "#{test_group_identifier}-external"
93
101
 
94
102
  # Always allow ssh from anywhere as it's needed for Beaker to run
95
- @gce_helper.create_firewall(@external_firewall_name, network, allow: @options[:gce_ports] + ['22/tcp'], source_ranges: ['0.0.0.0/0'], target_tags: [test_group_identifier])
103
+ @gce_helper.create_firewall(
104
+ @external_firewall_name,
105
+ network,
106
+ allow: @options[:gce_ports] + ['22/tcp'],
107
+ source_ranges: ['0.0.0.0/0'],
108
+ target_tags: [test_group_identifier],
109
+ )
96
110
 
97
111
  @logger.debug("Created External Google Compute firewall #{@external_firewall_name}")
98
112
 
99
113
  # Create a firewall that opens everything between all the hosts in this test group
100
- @internal_firewall_name = test_group_identifier + '-internal'
114
+ @internal_firewall_name = "#{test_group_identifier}-internal"
101
115
  internal_ports = ['1-65535/tcp', '1-65535/udp', '-1/icmp']
102
- @gce_helper.create_firewall(@internal_firewall_name, network, allow: internal_ports, source_tags: [test_group_identifier], target_tags: [test_group_identifier])
116
+ @gce_helper.create_firewall(
117
+ @internal_firewall_name,
118
+ network,
119
+ allow: internal_ports,
120
+ source_tags: [test_group_identifier],
121
+ target_tags: [test_group_identifier],
122
+ )
103
123
  @logger.debug("Created test group Google Compute firewall #{@internal_firewall_name}")
104
124
 
105
125
  @hosts.each do |host|
106
126
  machine_type_name = ENV.fetch('BEAKER_gce_machine_type', host['gce_machine_type'])
107
127
  raise "Must provide a machine type name in 'gce_machine_type'." if machine_type_name.nil?
128
+
108
129
  # Get the GCE machine type object for this host
109
130
  machine_type = @gce_helper.get_machine_type(machine_type_name)
110
- raise "Unable to find machine type named #{machine_type_name} in region #{@compute.default_zone}" if machine_type.nil?
131
+ if machine_type.nil?
132
+ raise "Unable to find machine type named #{machine_type_name} in region #{@compute.default_zone}"
133
+ end
111
134
 
112
135
  # Find the image to use to create the new VM.
113
136
  # Either `image` or `family` must be set in the configuration. Accepted formats
@@ -122,7 +145,7 @@ module Beaker
122
145
  if host[:image]
123
146
  image_selector = host[:image]
124
147
  # Do we have a project name?
125
- if %r{/}.match?(image_selector)
148
+ if image_selector.include?('/')
126
149
  image_project, image_name = image_selector.split('/')[0..1]
127
150
  else
128
151
  image_project = @gce_helper.options[:gce_project]
@@ -133,7 +156,7 @@ module Beaker
133
156
  elsif host[:family]
134
157
  image_selector = host[:family]
135
158
  # Do we have a project name?
136
- if %r{/}.match?(image_selector)
159
+ if image_selector.include?('/')
137
160
  image_project, family_name = image_selector.split('/')
138
161
  else
139
162
  image_project = @gce_helper.options[:gce_project]
@@ -145,7 +168,7 @@ module Beaker
145
168
  raise('You must specify either :image or :family')
146
169
  end
147
170
 
148
- unique_host_id = test_group_identifier + '-' + generate_host_name
171
+ unique_host_id = "#{test_group_identifier}-#{generate_host_name}"
149
172
 
150
173
  boot_size = host['volume_size'] || img.disk_size_gb
151
174
 
@@ -160,8 +183,15 @@ module Beaker
160
183
  # add a new instance of the image
161
184
  operation = @gce_helper.create_instance(host['vmhostname'], img, machine_type, boot_size, host.name)
162
185
  unless operation.error.nil?
163
- raise "Unable to create Google Compute Instance #{host.name}: [#{operation.error.errors[0].code}] #{operation.error.errors[0].message}"
186
+ raise "Unable to create Google Compute Instance #{
187
+ host.name
188
+ }: [#{
189
+ operation.error.errors[0].code
190
+ }] #{
191
+ operation.error.errors[0].message
192
+ }"
164
193
  end
194
+
165
195
  @logger.debug("Created Google Compute instance for #{host.name}: #{host['vmhostname']}")
166
196
  instance = @gce_helper.get_instance(host['vmhostname'])
167
197
 
@@ -169,11 +199,11 @@ module Beaker
169
199
  @logger.debug("Added network tag #{test_group_identifier} to instance")
170
200
 
171
201
  # Make sure we have a non root/Adminsitor user to log in as
172
- if host['user'] == "root" || host['user'] == "Administrator" || host['user'].empty?
173
- initial_user = 'google_compute'
174
- else
175
- initial_user = host['user']
176
- end
202
+ initial_user = if host['user'] == 'root' || host['user'] == 'Administrator' || host['user'].empty?
203
+ 'google_compute'
204
+ else
205
+ host['user']
206
+ end
177
207
 
178
208
  # add metadata to instance, if there is any to set
179
209
  # mdata = format_metadata
@@ -181,18 +211,18 @@ module Beaker
181
211
  mdata = [
182
212
  {
183
213
  key: 'ssh-keys',
184
- value: "#{initial_user}:#{File.read(find_google_ssh_public_key).strip}"
214
+ value: "#{initial_user}:#{File.read(find_google_ssh_public_key).strip}",
185
215
  },
186
216
  # For now oslogin needs to be disabled as there's no way to log in as root and it would
187
217
  # take too much work on beaker to add sudo support to everything
188
218
  {
189
219
  key: 'enable-oslogin',
190
- value: 'FALSE'
220
+ value: 'FALSE',
191
221
  },
192
222
  ]
193
223
 
194
224
  # Check for google's default windows images and turn on ssh if found
195
- if image_project == "windows-cloud" || image_project == "windows-sql-cloud"
225
+ if WINDOWS_IMAGE_PROJECT.include?(image_project)
196
226
  # Turn on SSH on GCP's default windows images
197
227
  mdata << {
198
228
  key: 'enable-windows-ssh',
@@ -200,12 +230,12 @@ module Beaker
200
230
  }
201
231
  mdata << {
202
232
  key: 'sysprep-specialize-script-cmd',
203
- value: 'start /wait googet -noconfirm=true update && start /wait googet -noconfirm=true install google-compute-engine-ssh',
233
+ value: 'start /wait googet -noconfirm=true update && start /wait googet -noconfirm=true install google-compute-engine-ssh', # rubocop:disable Layout/LineLength
204
234
  }
205
235
  # Some versions of windows don't seem to add the OpenSSH directory to the path which prevents scp from working
206
236
  mdata << {
207
237
  key: 'sysprep-specialize-script-ps1',
208
- value: '[Environment]::SetEnvironmentVariable( "PATH", "$ENV:PATH;C:\Program Files\OpenSSH", [EnvironmentVariableTarget]::Machine )',
238
+ value: '[Environment]::SetEnvironmentVariable( "PATH", "$ENV:PATH;C:\Program Files\OpenSSH", [EnvironmentVariableTarget]::Machine )', # rubocop:disable Layout/LineLength
209
239
  }
210
240
  end
211
241
  unless mdata.empty?