Skip to content

Commit

Permalink
rubocop style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Sep 25, 2018
1 parent 807fcdb commit 091a742
Show file tree
Hide file tree
Showing 20 changed files with 322 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ locale/*.mo
locale/*/*.edit.po
locale/*/*.po.time_stamp
locale/*/*.pox
*.gem
*.lock
103 changes: 93 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,106 @@
inherit_from:
- .rubocop_todo.yml

AllCops:
Exclude:
- 'doc/plugins/**'

Rails:
Enabled: true

Rails/Date:
Enabled: false

# Don't enforce documentation
Style/Documentation:
Enabled: false

# Force before_filter until upgrade to Rails 4
Rails/ActionFilter:
EnforcedStyle: filter

Metrics/MethodLength:
Max: 20
Max: 40

Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

Style/RedundantSelf:
Enabled: false

Metrics/ClassLength:
Max: 500
Exclude:
- 'test/**/*'

Naming/FileName:
Exclude:
- 'db/seeds.d/*'

Style/WordArray:
Enabled: false

Style/BracesAroundHashParameters:
Enabled: false

Style/RescueModifier:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/EachWithObject:
Enabled: false

Style/GuardClause:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'config/routes.rb'
- 'test/**/*'

Metrics/ParameterLists:
Enabled: false

Naming/VariableNumber:
Enabled: false

# a == 0 is not the same as a.zero?, when a is not a number
Style/NumericPredicate:
Enabled: false

Style/FormatStringToken:
EnforcedStyle: template

Rails/SkipsModelValidations:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/FormatString:
Enabled: false

Naming/HeredocDelimiterNaming:
Enabled: false

Style/RescueStandardError:
Enabled: false

Metrics/LineLength:
Max: 111 # TODO: discuss and set this
Style/SafeNavigation:
Enabled: false

Style/Next:
Lint/BooleanSymbol:
Enabled: false

# Support both ruby19 and hash_rockets
Style/HashSyntax:
Metrics/PerceivedComplexity:
Max: 11

Metrics/AbcSize:
Max: 45

Style/FrozenStringLiteralComment:
Enabled: false
106 changes: 106 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-09-13 15:11:07 -0400 using RuboCop version 0.59.0.
# 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: 3
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'app/helpers/concerns/foreman_m2/images_helper_extensions.rb'
- 'app/models/concerns/foreman_m2/nic_orchestration_extensions.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Exclude:
- 'app/helpers/concerns/foreman_m2/images_helper_extensions.rb'
- 'app/models/concerns/foreman_m2/host_extensions.rb'
- 'app/models/concerns/foreman_m2/host_orchestration_extensions.rb'
- 'foreman_m2.gemspec'

# Offense count: 26
# Cop supports --auto-correct.
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'app/helpers/concerns/foreman_m2/images_helper_extensions.rb'
- 'app/models/concerns/foreman_m2/host_extensions.rb'
- 'app/models/concerns/foreman_m2/host_orchestration_extensions.rb'
- 'app/models/concerns/foreman_m2/nic_orchestration_extensions.rb'
- 'db/seeds.d/071-m2_prov_templates.rb'
- 'test/test_plugin_helper.rb'

# Offense count: 1
Lint/UselessAssignment:
Exclude:
- 'app/models/concerns/foreman_m2/host_extensions.rb'

# Offense count: 1
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 48

# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 3
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db
Naming/UncommunicativeMethodParamName:
Exclude:
- 'app/helpers/concerns/foreman_m2/images_helper_extensions.rb'

# Offense count: 4
# Configuration parameters: EnforcedStyle.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
Exclude:
- 'app/controllers/foreman_m2/hosts_controller.rb'
- 'app/models/concerns/foreman_m2/host_extensions.rb'
- 'app/models/foreman_m2/m2.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
Exclude:
- 'app/models/concerns/foreman_m2/host_orchestration_extensions.rb'

# Offense count: 69
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Exclude:
- 'app/controllers/foreman_m2/hosts_controller.rb'
- 'app/helpers/concerns/foreman_m2/images_helper_extensions.rb'
- 'app/lib/proxy_api/m2.rb'
- 'app/models/concerns/foreman_m2/host_extensions.rb'
- 'app/models/concerns/foreman_m2/nic_extensions.rb'
- 'app/models/concerns/foreman_m2/nic_orchestration_extensions.rb'
- 'app/overrides/give_ids.rb'
- 'app/overrides/hybrid_js.rb'
- 'db/seeds.d/071-m2_prov_templates.rb'
- 'db/seeds.d/111-m2_sp_features.rb'
- 'lib/foreman_m2/engine.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength.
# SupportedStyles: skip_modifier_ifs, always
Style/Next:
Exclude:
- 'app/models/concerns/foreman_m2/host_extensions.rb'
- 'rename.rb'
3 changes: 1 addition & 2 deletions app/controllers/foreman_m2/hosts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class HostsController < ::HostsController
def new_action
# automatically renders view/foreman_m2/hosts/new_action

#proxy = ::ProxyAPI::M2.new(url: SmartProxy.with_features('M2').first.url)
proxy = SmartProxy.find_by name: "proxy_m2"
proxy = SmartProxy.find_by name: 'proxy_m2'
proxyAPI = ::ProxyAPI::M2.new(url: proxy.url)
@response = proxyAPI.get_images(:project => 'ian')
@snaps = proxyAPI.get_snapshots(:project => 'ian')
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/concerns/foreman_m2/images_helper_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def image_field(f, opts = {})
select_f f, :uuid, images.to_a.sort_by { |image| image.name.downcase },
:id, :name, {}, :label => _('Image')
else
text_f f, :uuid, :label => opts[:label] || _('Image ID'), :help_inline => opts[:help_inline] || _('Image ID as provided by the compute resource, e.g. ami-..')
text_f f, :uuid, :label => opts[:label] ||
_('Image ID'), :help_inline => opts[:help_inline] ||
_('Image ID as provided by the compute resource, e.g. ami-..')
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions app/lib/proxy_api/m2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ def initialize(args)
def get_images(_args)
# img_strings = parse(get("image_list?project=#{args[:project]}"))
img_strings = parse(get('image_list'))
# rescue => e
# raise ProxyException.new(url, e, N_("Unable to get M2 images. args: " + args.inspect))

id = 0
imgs = []
Expand All @@ -22,12 +20,10 @@ def get_images(_args)
end

def get_iscsi_target(args)
# get("iscsi_target?project=#{args[:project]}&disk=#{args[:disk]}&image=#{args[:image]}").body
get("iscsi_target?disk=#{args[:disk]}&image=#{args[:image]}").body
end

def delete_iscsi_target(args)
# delete("iscsi_target?project=#{args[:project]}&disk=#{args[:disk]}&image=#{args[:image]}").body
delete("iscsi_target?disk=#{args[:disk]}").body
end

Expand Down
49 changes: 35 additions & 14 deletions app/models/concerns/foreman_m2/host_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ module HostExtensions

included do
# execute callbacks
# before_destroy :destroy_disk, :if => compute_resource.type == "ForemanM2::M2"
before_destroy :destroy_disk, prepend: true
validates :root_pass, :length => { :minimum => 8, :message => _('should be 8 characters or more') },
:presence => { :message => N_('should not be blank - consider setting a global or host group default') },
:if => proc { |host| host.managed && (host.pxe_build? || host.hybrid_build?) && build? }
# TODO: Destroy disk only if M2
#before_destroy :destroy_disk #, prepend: true
validates :root_pass, :length => { :minimum => 8, :message =>
_('should be 8 characters or more') },
:presence => { :message =>
N_('should not be blank - ' \
'consider setting a global or ' \
'host group default') },
:if => proc { |host|
host.managed &&
(host.pxe_build? ||
host.hybrid_build?) && build?
}
end

# create or overwrite instance methods...
Expand All @@ -23,16 +31,20 @@ class ::Host::Managed::Jail < Safemode::Jail
end

def can_be_built?
managed? && SETTINGS[:unattended] && (pxe_build? || hybrid_build?) && !build?
managed? && SETTINGS[:unattended] && (pxe_build? || hybrid_build?) &&
!build?
end

def inherited_attributes
inherited_attrs = %w[domain_id]
if SETTINGS[:unattended]
inherited_attrs.concat(%w[operatingsystem_id architecture_id compute_resource_id])
inherited_attrs.concat(
%w[operatingsystem_id architecture_id compute_resource_id]
)
inherited_attrs << 'subnet_id' unless compute_provides?(:ip)
inherited_attrs << 'subnet6_id' unless compute_provides?(:ip6)
inherited_attrs.concat(%w[medium_id ptable_id pxe_loader]) if pxe_build? || hybrid_build?
inherited_attrs.concat(%w[medium_id ptable_id pxe_loader]) \
if pxe_build? || hybrid_build?
end
inherited_attrs
end
Expand All @@ -43,21 +55,30 @@ def hybrid_build?

def ensure_associations
status = true
if SETTINGS[:unattended] && managed? && os && (pxe_build? || hybrid_build?)
if SETTINGS[:unattended] && managed? && os &&
(pxe_build? || hybrid_build?)
%w[ptable medium architecture].each do |e|
value = send(e.to_sym)
next if value.blank?

unless os.send(e.pluralize.to_sym).include?(value)
errors.add("#{e}_id".to_sym, format(_('%{value} does not belong to %{os} operating system'), :value => value, :os => os))
errors.add("#{e}_id".to_sym,
format(_('%{value} does not belong to %{os} '\
'operating system'),
:value => value, :os => os))
status = false
end
end
end

if environment
puppetclasses.select('puppetclasses.id,puppetclasses.name').distinct.each do |e|
puppetclasses.select('puppetclasses.id,puppetclasses.name')
.distinct.each do |e|
unless environment.puppetclasses.map(&:id).include?(e.id)
errors.add(:puppetclasses, format(_('%{e} does not belong to the %{environment} environment'), :e => e, :environment => environment))
errors.add(:puppetclasses,
format(_('%{e} does not belong to the '\
'%{environment} environment'),
:e => e, :environment => environment))
status = false
end
end
Expand All @@ -67,7 +88,7 @@ def ensure_associations

def iscsi_target
logger.info "Creating disk #{name}"
proxy = SmartProxy.find_by name: "proxy_m2"
proxy = SmartProxy.find_by name: 'proxy_m2'
proxyAPI = ::ProxyAPI::M2.new(url: proxy.url)
img = Image.find_by name: image_name
# project = img.uuid
Expand All @@ -76,7 +97,7 @@ def iscsi_target

def destroy_disk
logger.info "Destroying disk #{name}"
proxy = SmartProxy.find_by name: "proxy_m2"
proxy = SmartProxy.find_by name: 'proxy_m2'
proxyAPI = ::ProxyAPI::M2.new(url: proxy.url)
proxyAPI.delete_iscsi_target(:disk => name)
end
Expand Down
Loading

0 comments on commit 091a742

Please sign in to comment.