Skip to content

Commit

Permalink
rubocop: autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Aug 17, 2023
1 parent 48594d2 commit 95334d2
Show file tree
Hide file tree
Showing 7 changed files with 575 additions and 520 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

Expand Down
63 changes: 63 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-08-17 21:29:37 UTC using RuboCop version 1.50.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/augeasproviders/mounttab/fstab.rb'
- 'lib/augeasproviders/mounttab/vfstab.rb'

# Offense count: 67
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'spec/unit/puppet/provider/mounttab/fstab_spec.rb'
- 'spec/unit/puppet/provider/mounttab/vfstab_spec.rb'

# Offense count: 4
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/unit/puppet/provider/mounttab/fstab_spec.rb'
- 'spec/unit/puppet/provider/mounttab/vfstab_spec.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, conditionals
Style/AndOr:
Exclude:
- 'lib/augeasproviders/mounttab/fstab.rb'
- 'lib/augeasproviders/mounttab/vfstab.rb'
- 'lib/puppet/provider/mounttab/augeas.rb'

# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'lib/augeasproviders.rb'
- 'lib/augeasproviders/mounttab.rb'
- 'lib/augeasproviders/mounttab/fstab.rb'
- 'lib/augeasproviders/mounttab/vfstab.rb'
- 'lib/puppet/provider/mounttab/augeas.rb'
- 'spec/unit/puppet/provider/mounttab/fstab_spec.rb'
- 'spec/unit/puppet/provider/mounttab/vfstab_spec.rb'

# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/augeasproviders/mounttab.rb'
- 'lib/augeasproviders/mounttab/fstab.rb'
- 'lib/augeasproviders/mounttab/vfstab.rb'
- 'lib/puppet/provider/mounttab/augeas.rb'
50 changes: 22 additions & 28 deletions lib/augeasproviders/mounttab/fstab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

module AugeasProviders::Mounttab
class Fstab

attr_reader :resource

def self.default_file
Expand All @@ -24,10 +23,11 @@ def self.lens

def self.get_resource(aug, mpath, target)
entry = {
:ensure => :present,
:target => target
ensure: :present,
target: target
}
return nil unless entry[:name] = aug.get("#{mpath}/file")

entry[:device] = aug.get("#{mpath}/spec")
entry[:fstype] = aug.get("#{mpath}/vfstype")

Expand All @@ -46,12 +46,12 @@ def self.get_resource(aug, mpath, target)
end

def self.create(aug, resource)
aug.set("$resource/spec", resource[:device])
aug.set("$resource/file", resource[:name])
aug.set("$resource/vfstype", resource[:fstype])
insoptions(aug, "$resource", resource)
aug.set("$resource/dump", resource[:dump].to_s)
aug.set("$resource/passno", resource[:pass].to_s)
aug.set('$resource/spec', resource[:device])
aug.set('$resource/file', resource[:name])
aug.set('$resource/vfstype', resource[:fstype])
insoptions(aug, '$resource', resource)
aug.set('$resource/dump', resource[:dump].to_s)
aug.set('$resource/passno', resource[:pass].to_s)
end

def self.insoptions(aug, entry, resource)
Expand All @@ -60,20 +60,20 @@ def self.insoptions(aug, entry, resource)
values = resource.original_parameters[:options]

aug.rm("#{entry}/opt")
insafter = "vfstype"
if values and not values.empty?
insafter = 'vfstype'
if values and !values.empty?
[values].flatten.each do |opt|
optk, optv = opt.split("=", 2)
aug.insert("#{entry}/#{insafter}", "opt", false)
optk, optv = opt.split('=', 2)
aug.insert("#{entry}/#{insafter}", 'opt', false)
aug.set("#{entry}/opt[last()]", optk)
aug.set("#{entry}/opt[last()]/value", optv) if optv
insafter = "opt[last()]"
insafter = 'opt[last()]'
end
else
# Strictly this is optional, but only Augeas > 0.10.0 has a lens that
# knows this is the case, so always fill it in.
aug.insert("#{entry}/#{insafter}", "opt", false)
aug.set("#{entry}/opt", "defaults")
aug.insert("#{entry}/#{insafter}", 'opt', false)
aug.set("#{entry}/opt", 'defaults')
end
end

Expand All @@ -84,9 +84,7 @@ def self.dump(aug, resource)
def self.set_dump(aug, resource, value)
# Ensure "defaults" option is always set if dump is being set, as the
# opts field is optional
if aug.match("$target/*[file = '#{resource[:name]}']/opt").empty?
aug.set("$target/*[file = '#{resource[:name]}']/opt", "defaults")
end
aug.set("$target/*[file = '#{resource[:name]}']/opt", 'defaults') if aug.match("$target/*[file = '#{resource[:name]}']/opt").empty?

aug.set("$target/*[file = '#{resource[:name]}']/dump", value.to_s)
end
Expand All @@ -98,24 +96,20 @@ def self.pass(aug, resource)
def self.set_pass(aug, resource, value)
# Ensure "defaults" option is always set if passno is being set, as the
# opts field is optional
if aug.match("$target/*[file = '#{resource[:name]}']/opt").empty?
aug.set("$target/*[file = '#{resource[:name]}']/opt", "defaults")
end
aug.set("$target/*[file = '#{resource[:name]}']/opt", 'defaults') if aug.match("$target/*[file = '#{resource[:name]}']/opt").empty?

# Ensure dump is always set too
if aug.match("$target/*[file = '#{resource[:name]}']/dump").empty?
aug.set("$target/*[file = '#{resource[:name]}']/dump", "0")
end
aug.set("$target/*[file = '#{resource[:name]}']/dump", '0') if aug.match("$target/*[file = '#{resource[:name]}']/dump").empty?

aug.set("$target/*[file = '#{resource[:name]}']/passno", value.to_s)
end

def self.atboot(aug, resource)
def self.atboot(_aug, resource)
resource.should(:atboot)
end

def self.set_atboot(aug, resource, value)
return
def self.set_atboot(_aug, _resource, _value)
nil
end

def self.empty_options
Expand Down
60 changes: 28 additions & 32 deletions lib/augeasproviders/mounttab/vfstab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

module AugeasProviders::Mounttab
class Vfstab

attr_reader :resource

def self.default_file
Expand All @@ -24,14 +23,15 @@ def self.lens

def self.get_resource(aug, mpath, target)
entry = {
:ensure => :present,
:target => target
ensure: :present,
target: target
}
return nil unless entry[:name] = aug.get("#{mpath}/file")

entry[:device] = aug.get("#{mpath}/spec")
entry[:fstype] = aug.get("#{mpath}/vfstype")
entry[:blockdevice] = (aug.get("#{mpath}/fsck") or "-")
entry[:pass] = (aug.get("#{mpath}/passno") or "-")
entry[:blockdevice] = (aug.get("#{mpath}/fsck") or '-')
entry[:pass] = (aug.get("#{mpath}/passno") or '-')
entry[:atboot] = aug.get("#{mpath}/atboot")

options = []
Expand All @@ -42,24 +42,22 @@ def self.get_resource(aug, mpath, target)
options << opt
end
entry[:options] = if options.empty?
"-"
else
options
end
'-'
else
options
end

entry
end

def self.create(aug, resource)
aug.set("$resource/spec", resource[:device])
if resource[:blockdevice] and resource[:blockdevice] != ""
aug.set("$resource/fsck", resource[:blockdevice])
end
aug.set("$resource/file", resource[:name])
aug.set("$resource/vfstype", resource[:fstype])
aug.set("$resource/passno", resource[:pass].to_s) unless resource[:pass] == "-"
aug.set("$resource/atboot", resource[:atboot].to_s)
insoptions(aug, "$resource", resource)
aug.set('$resource/spec', resource[:device])
aug.set('$resource/fsck', resource[:blockdevice]) if resource[:blockdevice] and resource[:blockdevice] != ''
aug.set('$resource/file', resource[:name])
aug.set('$resource/vfstype', resource[:fstype])
aug.set('$resource/passno', resource[:pass].to_s) unless resource[:pass] == '-'
aug.set('$resource/atboot', resource[:atboot].to_s)
insoptions(aug, '$resource', resource)
end

def target
Expand All @@ -72,34 +70,32 @@ def self.insoptions(aug, entry, resource)
values = resource.original_parameters[:options]

aug.rm("#{entry}/opt")
if values and not values.empty?
[values].flatten.each do |opt|
optk, optv = opt.split("=", 2)
aug.set("#{entry}/opt[last()+1]", optk)
aug.set("#{entry}/opt[last()]/value", optv) if optv
end
return unless values and !values.empty?

[values].flatten.each do |opt|
optk, optv = opt.split('=', 2)
aug.set("#{entry}/opt[last()+1]", optk)
aug.set("#{entry}/opt[last()]/value", optv) if optv
end
end

def self.dump(aug, resource)
def self.dump(_aug, resource)
resource.should(:dump)
end

def self.set_dump(aug, resource, value)
return
def self.set_dump(_aug, _resource, _value)
nil
end

def self.pass(aug, resource)
aug.get("$target/*[file = '#{resource[:name]}']/passno") or "-"
aug.get("$target/*[file = '#{resource[:name]}']/passno") or '-'
end

def self.set_pass(aug, resource, value)
if value == "-"
if value == '-'
aug.rm("$target/*[file = '#{resource[:name]}']/passno")
else
if aug.match("$target/*[file = '#{resource[:name]}']/passno").empty?
aug.insert("$target/*[file = '#{resource[:name]}']/vfstype", "passno", false)
end
aug.insert("$target/*[file = '#{resource[:name]}']/vfstype", 'passno', false) if aug.match("$target/*[file = '#{resource[:name]}']/passno").empty?
aug.set("$target/*[file = '#{resource[:name]}']/passno", value.to_s)
end
end
Expand Down
29 changes: 14 additions & 15 deletions lib/puppet/provider/mounttab/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
require File.dirname(__FILE__) + '/../../../augeasproviders/mounttab/fstab'
require File.dirname(__FILE__) + '/../../../augeasproviders/mounttab/vfstab'

raise("Missing augeasproviders_core dependency") if Puppet::Type.type(:augeasprovider).nil?
Puppet::Type.type(:mounttab).provide(:augeas, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do
desc "Uses Augeas API to update the /etc/(v)fstab file"
raise('Missing augeasproviders_core dependency') if Puppet::Type.type(:augeasprovider).nil?

Puppet::Type.type(:mounttab).provide(:augeas, parent: Puppet::Type.type(:augeasprovider).provider(:default)) do
desc 'Uses Augeas API to update the /etc/(v)fstab file'

def self.osimpl
os = Facter.value(:osfamily) or Facter.value(:operatingsystem)
case os
when "Solaris"
when 'Solaris'
AugeasProviders::Mounttab::Vfstab
else
AugeasProviders::Mounttab::Fstab
Expand All @@ -39,21 +40,21 @@ def self.osimpl
"$target/*[file = '#{resource[:name]}']"
end

confine :feature => :augeas
defaultfor :feature => :augeas
confine feature: :augeas
defaultfor feature: :augeas

def self.instances
augopen do |aug|
resources = []
aug.match("$target/*").each do |mpath|
aug.match('$target/*').each do |mpath|
entry = osimpl.get_resource(aug, mpath, target)
resources << new(entry) unless entry.nil?
end
resources
end
end

def create
def create
augopen! do |aug|
aug.defnode('resource', "$target/#{next_seq(aug.match('$target/*'))}", nil)
self.class.osimpl.create(aug, resource)
Expand All @@ -74,18 +75,16 @@ def device=(value)

def blockdevice
augopen do |aug|
aug.get('$resource/fsck') or "-"
aug.get('$resource/fsck') or '-'
end
end

def blockdevice=(value)
augopen! do |aug|
if value == "-"
if value == '-'
aug.rm('$resource/fsck')
else
if aug.match('$resource/fsck').empty?
aug.insert('$resource/spec', 'fsck', false)
end
aug.insert('$resource/spec', 'fsck', false) if aug.match('$resource/fsck').empty?
aug.set('$resource/fsck', value.to_s)
end
end
Expand All @@ -112,7 +111,7 @@ def options
opt = "#{opt}=#{optv}" if optv
opts << opt
end
opts = opts.join(",")
opts = opts.join(',')

# [] and ["defaults"] are synonyms, so return what the user requested if
# the current value is one of these to avoid changes
Expand All @@ -129,7 +128,7 @@ def insoptions(aug, entry, resource)
self.class.osimpl.insoptions(aug, entry, resource)
end

def options=(values)
def options=(_values)
augopen! do |aug|
insoptions(aug, '$resource', resource)
end
Expand Down
Loading

0 comments on commit 95334d2

Please sign in to comment.