Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubocop: Fix layout cops #65

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ inherit_gem:

Metrics:
Enabled: false

Layout:
Enabled: false
24 changes: 20 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-03-27 16:53:47 UTC using RuboCop version 1.48.1.
# on 2023-03-27 17:58:31 UTC using RuboCop version 1.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -143,10 +143,10 @@ RSpec/EmptyLineAfterFinalLet:
- 'spec/beaker/hypervisor/vagrant_parallels_spec.rb'
- 'spec/beaker/hypervisor/vagrant_virtualbox_spec.rb'

# Offense count: 18
# Offense count: 19
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 16
Max: 17

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand Down Expand Up @@ -183,7 +183,7 @@ RSpec/HookArgument:
- 'spec/beaker/hypervisor/vagrant_custom_spec.rb'
- 'spec/beaker/hypervisor/vagrant_spec.rb'

# Offense count: 11
# Offense count: 17
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
Expand Down Expand Up @@ -307,6 +307,15 @@ Style/EnvHome:
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 9
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/beaker/hypervisor/vagrant.rb'
- 'lib/beaker/hypervisor/vagrant_desktop.rb'
- 'lib/beaker/hypervisor/vagrant_virtualbox.rb'
- 'lib/beaker/hypervisor/vagrant_workstation.rb'

# Offense count: 6
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/LineEndConcatenation:
Expand Down Expand Up @@ -365,3 +374,10 @@ Style/TrailingCommaInHashLiteral:
Exclude:
- 'lib/beaker/hypervisor/vagrant_virtualbox.rb'
- 'spec/beaker/hypervisor/vagrant_spec.rb'

# Offense count: 23
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 222
11 changes: 2 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'rspec/core/rake_task'

namespace :test do

namespace :spec do

desc 'Run spec tests'
RSpec::Core::RakeTask.new(:run) do |t|
t.rspec_opts = ['--color', '--format documentation']
Expand All @@ -16,16 +14,13 @@ namespace :test do
t.rspec_opts = ['--color', '--format documentation']
t.pattern = 'spec/'
end

end

namespace :acceptance do

desc <<-EOS
A quick acceptance test, named because it has no pre-suites to run
desc <<~EOS
A quick acceptance test, named because it has no pre-suites to run
EOS
task :quick do

# setup & load_path of beaker's acceptance base and lib directory
beaker_gem_spec = Gem::Specification.find_by_name('beaker')
beaker_gem_dir = beaker_gem_spec.gem_dir
Expand All @@ -39,9 +34,7 @@ A quick acceptance test, named because it has no pre-suites to run
'--load-path', load_path_option,
'--keyfile', ENV['KEY'] || "#{ENV.fetch('HOME', nil)}/.ssh/id_rsa")
end

end

end

# namespace-named default tasks.
Expand Down
2 changes: 1 addition & 1 deletion beaker-vagrant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = Gem::Requirement.new('>= 2.7')

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

# Testing dependencies
Expand Down
4 changes: 1 addition & 3 deletions bin/beaker-vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'rubygems' unless defined?(Gem)
require 'beaker-vagrant'

VERSION_STRING =
"
"
_ .--.
( ` )
beaker-vagrant .-' `--,
Expand All @@ -25,8 +25,6 @@ VERSION_STRING =
'=='
"



puts BeakerVagrant::Version

exit 0
95 changes: 51 additions & 44 deletions lib/beaker/hypervisor/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

module Beaker
class Vagrant < Beaker::Hypervisor

require 'beaker/hypervisor/vagrant/mount_folder'
require 'beaker/hypervisor/vagrant_virtualbox'

def rand_chunk
rand(2..254).to_s # don't want a 0, 1, or a 255
end

def randip(hypervisor=nil)
def randip(hypervisor = nil)
case hypervisor
when /libvirt/
"10.254.#{rand_chunk}.#{rand_chunk}"
Expand All @@ -22,9 +21,9 @@ def randip(hypervisor=nil)
def private_network_generator(host)
private_network_string = " v.vm.network :private_network, ip: \"#{host['ip'].to_s}\", :netmask => \"#{host['netmask'] ||= '255.255.0.0'}\""
private_network_string << if host['network_mac']
", :mac => \"#{host['network_mac']}\"\n"
else
"\n"
", :mac => \"#{host['network_mac']}\"\n"
else
"\n"
end
end

Expand All @@ -33,30 +32,35 @@ def connection_preference(host)
end

def shell_provisioner_generator(provisioner_config)
raise 'No path defined for shell_provisioner or path empty' if provisioner_config['path'].nil? || provisioner_config['path'].empty?
if provisioner_config['args'].nil?
" v.vm.provision 'shell', :path => '#{provisioner_config['path']}'\n"
else
" v.vm.provision 'shell', :path => '#{provisioner_config['path']}', :args => '#{provisioner_config['args']}' \n"
end
if provisioner_config['path'].nil? || provisioner_config['path'].empty?
raise 'No path defined for shell_provisioner or path empty'
end

if provisioner_config['args'].nil?
" v.vm.provision 'shell', :path => '#{provisioner_config['path']}'\n"
else
" v.vm.provision 'shell', :path => '#{provisioner_config['path']}', :args => '#{provisioner_config['args']}' \n"
end
end

def make_vfile(hosts, options = {})
#HACK: HACK HACK - add checks here to ensure that we have box + box_url
#generate the VagrantFile
# HACK: HACK HACK - add checks here to ensure that we have box + box_url
# generate the VagrantFile
v_file = "Vagrant.configure(\"2\") do |c|\n"
v_file << " c.ssh.forward_agent = true\n" if options[:forward_ssh_agent] == true
v_file << " c.ssh.insert_key = false\n"

hosts.each do |host|
host.name.tr!('_','-') # Rewrite Hostname with hyphens instead of underscores to get legal hostname
host.name.tr!('_', '-') # Rewrite Hostname with hyphens instead of underscores to get legal hostname
set_host_default_ip(host)
v_file << " c.vm.define '#{host.name}' do |v|\n"
v_file << " v.vm.hostname = '#{host.name}'\n"
v_file << " v.vm.box = '#{host['box']}'\n"
v_file << " v.vm.box_url = '#{host['box_url']}'\n" unless host['box_url'].nil?
v_file << " v.vm.box_version = '#{host['box_version']}'\n" unless host['box_version'].nil?
v_file << " v.vm.box_download_insecure = '#{host['box_download_insecure']}'\n" unless host['box_download_insecure'].nil?
unless host['box_download_insecure'].nil?
v_file << " v.vm.box_download_insecure = '#{host['box_download_insecure']}'\n"
end
v_file << " v.vm.box_check_update = '#{host['box_check_update'] ||= 'true'}'\n"
v_file << " v.vm.synced_folder '.', '/vagrant', disabled: true\n" if host['synced_folder'] == 'disabled'
v_file << shell_provisioner_generator(host['shell_provisioner']) if host['shell_provisioner']
Expand Down Expand Up @@ -88,9 +92,9 @@ def make_vfile(hosts, options = {})
end

if /windows/i.match(host['platform'])
#due to a regression bug in versions of vagrant 1.6.2, 1.6.3, 1.6.4, >= 1.7.3 ssh fails to forward
#automatically (note <=1.6.1, 1.6.5, 1.7.0 - 1.7.2 are uneffected)
#Explicitly setting SSH port forwarding due to this bug
# due to a regression bug in versions of vagrant 1.6.2, 1.6.3, 1.6.4, >= 1.7.3 ssh fails to forward
# automatically (note <=1.6.1, 1.6.5, 1.7.0 - 1.7.2 are uneffected)
# Explicitly setting SSH port forwarding due to this bug
v_file << " v.vm.network :forwarded_port, guest: 22, host: 2222, id: 'ssh', auto_correct: true\n"
v_file << " v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true\n"
v_file << " v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true\n"
Expand All @@ -116,9 +120,9 @@ def make_vfile(hosts, options = {})
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=167105
#
v_file << if host['vagrant_freebsd_nfs'].nil?
" v.vm.synced_folder '.', '/vagrant', type: 'rsync'\n"
else
" v.vm.synced_folder '.', '/vagrant', :nfs => true\n"
" v.vm.synced_folder '.', '/vagrant', type: 'rsync'\n"
else
" v.vm.synced_folder '.', '/vagrant', :nfs => true\n"
end
end

Expand Down Expand Up @@ -152,16 +156,16 @@ def set_all_ssh_config

set_ssh_config host, 'vagrant'

#copy vagrant's keys to roots home dir, to allow for login as root
# copy vagrant's keys to roots home dir, to allow for login as root
copy_ssh_to_root host, @options
#ensure that root login is enabled for this host
# ensure that root login is enabled for this host
enable_root_login host, @options
#shut down connection, will reconnect on next exec
# shut down connection, will reconnect on next exec
host.close

set_ssh_config host, default_user

#allow the user to set the env
# allow the user to set the env
begin
host.ssh_permit_user_environment
host.close
Expand Down Expand Up @@ -200,14 +204,17 @@ def initialize(vagrant_hosts, options)
@options = options
@logger = options[:logger]
@hosts = vagrant_hosts
@vagrant_path = File.expand_path(File.join('.vagrant', 'beaker_vagrant_files', 'beaker_' + File.basename(options[:hosts_file])))
@vagrant_path = File.expand_path(File.join('.vagrant', 'beaker_vagrant_files',
'beaker_' + File.basename(options[:hosts_file])))
@vagrant_file = File.expand_path(File.join(@vagrant_path, 'Vagrantfile'))
@vagrant_env = { 'RUBYLIB' => '', 'RUBYOPT' => '' }
end

def configure(opts = {})
unless @options[:provision]
raise "Beaker is configured with provision = false but no vagrant file was found at #{@vagrant_file}. You need to enable provision" unless File.file?(@vagrant_file)
unless File.file?(@vagrant_file)
raise "Beaker is configured with provision = false but no vagrant file was found at #{@vagrant_file}. You need to enable provision"
end

set_all_ssh_config
end
Expand All @@ -217,8 +224,8 @@ def configure(opts = {})
def provision(provider = nil)
FileUtils.mkdir_p(@vagrant_path)

#setting up new vagrant hosts
#make sure that any old boxes are dead dead dead
# setting up new vagrant hosts
# make sure that any old boxes are dead dead dead
begin
vagrant_cmd('destroy --force') if File.file?(@vagrant_file)
rescue RuntimeError => e
Expand Down Expand Up @@ -253,22 +260,22 @@ def cleanup

def vagrant_cmd(args)
Dir.chdir(@vagrant_path) do
retries ||=0
Open3.popen3(@vagrant_env, "vagrant #{args}") do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets
@logger.info(line)
end

raise "Failed to exec 'vagrant #{args}'. Error was #{stderr.read}" unless wait_thr.value.success?
retries ||= 0
Open3.popen3(@vagrant_env, "vagrant #{args}") do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets
@logger.info(line)
end
rescue StandardError => e
if e.to_s =~ /WinRM/m
sleep(10)

retry if (retries += 1) < 6
end
raise "Failed to exec 'vagrant #{args}'. Error was #{stderr.read}" unless wait_thr.value.success?
end
rescue StandardError => e
if e.to_s =~ /WinRM/m
sleep(10)

raise e
retry if (retries += 1) < 6
end

raise e
end
end

Expand All @@ -289,8 +296,8 @@ def self.memsize(host, options)
options['vagrant_memsize']
elsif host['platform'] =~ /windows/
'2048'
else
'1024'
else
'1024'
end
end

Expand Down
14 changes: 9 additions & 5 deletions lib/beaker/hypervisor/vagrant_desktop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ def provision(provider = 'vmware_desktop')
super
end

def self.provider_vfile_section(host, options)
def self.provider_vfile_section(host, options)
v_provider = " v.vm.provider :vmware_desktop do |v|\n"
v_provider << " v.vmx['gui'] = true\n" if host['gui'] == true
v_provider << " v.vmx['memsize'] = '#{memsize(host,options)}'\n"
v_provider << " v.vmx['whitelist_verified'] = '#{host['whitelist_verified']}'\n" unless host['whitelist_verified'].nil?
v_provider << " v.vmx['functional_hgfs'] = '#{host['functional_hgfs']}'\n" unless host['functional_hgfs'].nil?
v_provider << " v.vmx['unmount_default_hgfs'] = '#{host['unmount_default_hgfs']}'\n" unless host['unmount_default_hgfs'].nil?
v_provider << " v.vmx['memsize'] = '#{memsize(host, options)}'\n"
unless host['whitelist_verified'].nil?
v_provider << " v.vmx['whitelist_verified'] = '#{host['whitelist_verified']}'\n"
end
v_provider << " v.vmx['functional_hgfs'] = '#{host['functional_hgfs']}'\n" unless host['functional_hgfs'].nil?
unless host['unmount_default_hgfs'].nil?
v_provider << " v.vmx['unmount_default_hgfs'] = '#{host['unmount_default_hgfs']}'\n"
end
v_provider << " v.vmx['utility_port'] = '#{host['utility_port']}'\n" unless host['utility_port'].nil?
v_provider << " end\n"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/hypervisor/vagrant_parallels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.provider_vfile_section(host, options)
provider_section = ''
provider_section << " v.vm.provider :parallels do |prl|\n"
provider_section << " prl.optimize_power_consumption = false\n"
provider_section << " prl.memory = '#{memsize(host,options)}'\n"
provider_section << " prl.memory = '#{memsize(host, options)}'\n"
provider_section << " prl.update_guest_tools = false\n" if options[:prl_update_guest_tools] == 'disable'
provider_section << " end\n"

Expand Down
Loading