Skip to content

Commit

Permalink
rubocop: autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Sep 26, 2023
1 parent 534fd0c commit 41c2466
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 123 deletions.
99 changes: 7 additions & 92 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-09-26 11:32:50 UTC using RuboCop version 1.54.2.
# on 2023-09-26 11:47:58 UTC using RuboCop version 1.54.2.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/beaker/hypervisor/vsphere.rb'

# Offense count: 2
Lint/DuplicateMethods:
Exclude:
- 'spec/mock_vsphere_helper.rb'

# Offense count: 1
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'spec/mock_vsphere.rb'

# Offense count: 2
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Expand Down Expand Up @@ -76,16 +75,6 @@ RSpec/AnyInstance:
Exclude:
- 'spec/beaker/hypervisor/fusion_spec.rb'

# Offense count: 12
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/beaker/hypervisor/fusion_spec.rb'
- 'spec/beaker/hypervisor/vsphere_helper_spec.rb'
- 'spec/beaker/hypervisor/vsphere_spec.rb'

# Offense count: 6
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Expand Down Expand Up @@ -128,15 +117,6 @@ Rake/Desc:
Exclude:
- 'Rakefile'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, conditionals
Style/AndOr:
Exclude:
- 'lib/beaker/hypervisor/fusion.rb'
- 'lib/beaker/hypervisor/vsphere_helper.rb'

# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowOnConstant, AllowOnSelfClass.
Expand All @@ -150,12 +130,6 @@ Style/ClassVars:
- 'spec/mock_fission.rb'
- 'spec/mock_vsphere_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CommentedKeyword:
Exclude:
- 'lib/beaker/hypervisor/fusion.rb'

# Offense count: 3
# Configuration parameters: AllowedConstants.
Style/Documentation:
Expand All @@ -175,40 +149,12 @@ Style/FormatString:
- 'lib/beaker/hypervisor/fusion.rb'
- 'lib/beaker/hypervisor/vsphere.rb'

# Offense count: 16
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/beaker/hypervisor/fusion.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/InfiniteLoop:
Exclude:
- 'lib/beaker/hypervisor/vsphere_helper.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/LineEndConcatenation:
Exclude:
- 'lib/beaker/hypervisor/vsphere.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'bin/beaker-vmware'
- 'lib/beaker-vmware/version.rb'

# Offense count: 2
Style/OpenStructUse:
Exclude:
Expand All @@ -221,37 +167,6 @@ Style/OptionalBooleanParameter:
Exclude:
- 'spec/mock_vsphere.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: short, verbose
Style/PreferredHashMethods:
Exclude:
- 'spec/mock_vsphere_helper.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowComments.
Style/RedundantInitialize:
Exclude:
- 'spec/mock_vsphere.rb'
- 'spec/mock_vsphere_helper.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'spec/mock_vsphere.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
# AllowedMethods: define_method
Style/SymbolProc:
Exclude:
- 'lib/beaker/hypervisor/fusion.rb'

# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
Expand Down
2 changes: 2 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

SimpleCov.configure do
add_filter 'spec/'
add_filter 'vendor/'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source ENV['GEM_SOURCE'] || 'https://rubygems.org'

gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'

namespace :test do
Expand Down
2 changes: 2 additions & 0 deletions beaker-vmware.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'beaker-vmware/version'

Expand Down
1 change: 1 addition & 0 deletions bin/beaker-vmware
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'rubygems' unless defined?(Gem)
require 'beaker-vmware'
Expand Down
2 changes: 2 additions & 0 deletions lib/beaker-vmware/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module BeakerVmware
VERSION = '2.0.0'
end
8 changes: 5 additions & 3 deletions lib/beaker/hypervisor/fusion.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Beaker
class Fusion < Beaker::Hypervisor
def initialize(fusion_hosts, options)
Expand All @@ -20,7 +22,7 @@ def initialize(fusion_hosts, options)
end

def provision
available = @fission.all.data.collect { |vm| vm.name }.sort.join(', ')
available = @fission.all.data.collect(&:name).sort.join(', ')
@logger.notify "Available VM names: #{available}"

@hosts.each do |host|
Expand All @@ -29,7 +31,7 @@ def provision
raise "Could not find VM '#{vm_name}' for #{host.name}!" unless vm.exists?

vm_snapshots = vm.snapshots.data
if vm_snapshots.nil? or vm_snapshots.empty?
if vm_snapshots.nil? || vm_snapshots.empty?
raise "No snapshots available for VM #{host.name} (vmname: '#{vm_name}')"
end

Expand All @@ -54,7 +56,7 @@ def provision
time = Time.now - start
@logger.notify 'Spent %.2f seconds resuming VM' % time
end
end # revert_fusion
end

def cleanup
@logger.notify 'No cleanup for fusion boxes'
Expand Down
14 changes: 8 additions & 6 deletions lib/beaker/hypervisor/vsphere.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'yaml' unless defined?(YAML)
require 'beaker/hypervisor/vsphere_helper'

Expand All @@ -12,8 +14,8 @@ def initialize(vsphere_hosts, options)
def provision
vsphere_credentials = VsphereHelper.load_config(@options[:dot_fog])

@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]}" +
" with credentials for #{vsphere_credentials[:user]}"
@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]} " \
"with credentials for #{vsphere_credentials[:user]}"

vsphere_helper = VsphereHelper.new(vsphere_credentials)

Expand All @@ -24,7 +26,7 @@ def provision
end
vms = vsphere_helper.find_vms(vsphere_vms.keys)
vsphere_vms.each_pair do |name, snap|
unless vm = vms[name]
unless (vm = vms[name])
raise "Couldn't find VM #{name} in vSphere!"
end

Expand Down Expand Up @@ -57,15 +59,15 @@ def cleanup
@logger.notify 'Destroying vsphere boxes'
vsphere_credentials = VsphereHelper.load_config(@options[:dot_fog])

@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]}" +
" with credentials for #{vsphere_credentials[:user]}"
@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]} " \
"with credentials for #{vsphere_credentials[:user]}"

vsphere_helper = VsphereHelper.new(vsphere_credentials)

vm_names = @hosts.map { |h| h['vmname'] || h.name }
vms = vsphere_helper.find_vms vm_names
vm_names.each do |name|
unless vm = vms[name]
unless (vm = vms[name])
raise "Couldn't find VM #{name} in vSphere!"
end

Expand Down
7 changes: 4 additions & 3 deletions lib/beaker/hypervisor/vsphere_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'yaml' unless defined?(YAML)
require 'rbvmomi'
require 'beaker/logger'
Expand Down Expand Up @@ -137,7 +139,7 @@ def find_pool(dc, poolname)
end
end

base = base.resourcePool unless base.is_a?(RbVmomi::VIM::ResourcePool) and base.respond_to?(:resourcePool)
base = base.resourcePool unless base.is_a?(RbVmomi::VIM::ResourcePool) && base.respond_to?(:resourcePool)
base
end

Expand All @@ -162,7 +164,7 @@ def wait_for_tasks(tasks, try, attempts)
partialUpdates: false,
)
ver = ''
while true
loop do
result = @connection.propertyCollector.WaitForUpdates(version: ver)
ver = result.version
complete = 0
Expand All @@ -175,7 +177,6 @@ def wait_for_tasks(tasks, try, attempts)

sleep 5
try += 1

end

filter.DestroyPropertyFilter
Expand Down
8 changes: 5 additions & 3 deletions spec/beaker/hypervisor/fusion_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# frozen_string_literal: true

require 'spec_helper'

module Beaker
describe Fusion do
let(:fusion) { Beaker::Fusion.new(@hosts, make_opts) }
let(:fusion) { described_class.new(@hosts, make_opts) }

before do
stub_const('Fission::VM', true)
@hosts = make_hosts
MockFission.presets(@hosts)
allow_any_instance_of(Fusion).to receive(:require).with('fission').and_return(true)
allow_any_instance_of(described_class).to receive(:require).with('fission').and_return(true)
fusion.instance_variable_set(:@fission, MockFission)
end

Expand All @@ -33,7 +35,7 @@ module Beaker

it 'host fails init with nil snapshot' do
@hosts[0][:snapshot] = nil
expect { Beaker::Fusion.new(@hosts, make_opts) }.to raise_error(/specify a snapshot/)
expect { described_class.new(@hosts, make_opts) }.to raise_error(/specify a snapshot/)
end
end
end
8 changes: 5 additions & 3 deletions spec/beaker/hypervisor/vsphere_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

module Beaker
Expand All @@ -6,7 +8,7 @@ module Beaker
let(:vInfo) do
{ server: 'vsphere.labs.net', user: '[email protected]', pass: 'supersekritpassword' }
end
let(:vsphere_helper) { VsphereHelper.new(vInfo.merge({ logger: logger })) }
let(:vsphere_helper) { described_class.new(vInfo.merge({ logger: logger })) }
let(:snaplist) do
{ 'snap1' => { 'snap1sub1' => nil,
'snap1sub2' => nil, },
Expand All @@ -30,13 +32,13 @@ module Beaker
allow(File).to receive(:exist?).and_return(true)
allow(YAML).to receive(:load_file).and_return(fog_file_contents)

expect(VsphereHelper.load_config).to be === vInfo
expect(described_class.load_config).to be === vInfo
end

it 'raises an error when the .fog file is missing' do
allow(File).to receive(:exist?).and_return(false)

expect { VsphereHelper.load_config }.to raise_error(ArgumentError)
expect { described_class.load_config }.to raise_error(ArgumentError)
end
end

Expand Down
Loading

0 comments on commit 41c2466

Please sign in to comment.