Top Level Namespace

Defined Under Namespace

Classes: GemfileRewrite, PuppetLint, String

Constant Summary collapse

MSG =

Public: Check the tokens of each File resource instance for a mode parameter and if found, record a warning if the value of that parameter is not a 4 digit octal value (0755) or a symbolic mode (‘o=rwx,g+r’).

puppet.com/docs/puppet/latest/style_guide.html#file-modes

'mode should be represented as a 4 digit octal value or symbolic mode'.freeze
SYM_RE =
'([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze
IGNORE_TYPES =
Set[:VARIABLE, :UNDEF, :FUNCTION_NAME]
MODE_RE =
%r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze
LEGACY_FACTS_VAR_TYPES =

Public: A puppet-lint custom check to detect legacy facts.

This check will optionally convert from legacy facts like $::operatingsystem or legacy hashed facts like $facts to the new structured facts like $facts[‘name’].

This plugin was adopted in to puppet-lint from github.com/mmckinst/puppet-lint-legacy_facts-check Thanks to @mmckinst, @seanmil, @rodjek, @baurmatt, @bart2 and @joshcooper for the original work.

Set[:VARIABLE, :UNENC_VARIABLE]
UNCONVERTIBLE_FACTS =

These facts that can’t be converted to new facts.

['memoryfree_mb', 'memorysize_mb', 'swapfree_mb',
'swapsize_mb', 'blockdevices', 'interfaces', 'zones',
'sshfp_dsa', 'sshfp_ecdsa', 'sshfp_ed25519',
'sshfp_rsa'].freeze
REGEX_FACTS =

These facts will depend on how a system is set up and can’t just be enumerated like the EASY_FACTS below.

For example a server might have two block devices named ‘sda’ and ‘sdb’ so there would be a $blockdeivce_sda_vendor and $blockdeivce_sdb_vendor fact for each device. Or it could have 26 block devices going all the way up to ‘sdz’. There is no way to know what the possibilities are so we have to use a regex to match them.

[%r{^blockdevice_(?<devicename>.*)_(?<attribute>model|size|vendor)$},
%r{^(?<attribute>ipaddress|ipaddress6|macaddress|mtu|netmask|netmask6|network|network6)_(?<interface>.*)$},
%r{^processor(?<id>[0-9]+)$},
%r{^sp_(?<name>.*)$},
%r{^ssh(?<algorithm>dsa|ecdsa|ed25519|rsa)key$},
%r{^ldom_(?<name>.*)$},
%r{^zone_(?<name>.*)_(?<attribute>brand|iptype|name|uuid|id|path|status)$}].freeze
EASY_FACTS =

These facts have a one to one correlation between a legacy fact and a new structured fact.

{
  'architecture' => "facts['os']['architecture']",
  'augeasversion' => "facts['augeas']['version']",
  'bios_release_date' => "facts['dmi']['bios']['release_date']",
  'bios_vendor' => "facts['dmi']['bios']['vendor']",
  'bios_version' => "facts['dmi']['bios']['version']",
  'boardassettag' => "facts['dmi']['board']['asset_tag']",
  'boardmanufacturer' => "facts['dmi']['board']['manufacturer']",
  'boardproductname' => "facts['dmi']['board']['product']",
  'boardserialnumber' => "facts['dmi']['board']['serial_number']",
  'chassisassettag' => "facts['dmi']['chassis']['asset_tag']",
  'chassistype' => "facts['dmi']['chassis']['type']",
  'domain' => "facts['networking']['domain']",
  'fqdn' => "facts['networking']['fqdn']",
  'gid' => "facts['identity']['group']",
  'hardwareisa' => "facts['processors']['isa']",
  'hardwaremodel' => "facts['os']['hardware']",
  'hostname' => "facts['networking']['hostname']",
  'id' => "facts['identity']['user']",
  'ipaddress' => "facts['networking']['ip']",
  'ipaddress6' => "facts['networking']['ip6']",
  'lsbdistcodename' => "facts['os']['distro']['codename']",
  'lsbdistdescription' => "facts['os']['distro']['description']",
  'lsbdistid' => "facts['os']['distro']['id']",
  'lsbdistrelease' => "facts['os']['distro']['release']['full']",
  'lsbmajdistrelease' => "facts['os']['distro']['release']['major']",
  'lsbminordistrelease' => "facts['os']['distro']['release']['minor']",
  'lsbrelease' => "facts['os']['distro']['release']['specification']",
  'macaddress' => "facts['networking']['mac']",
  'macosx_buildversion' => "facts['os']['macosx']['build']",
  'macosx_productname' => "facts['os']['macosx']['product']",
  'macosx_productversion' => "facts['os']['macosx']['version']['full']",
  'macosx_productversion_major' => "facts['os']['macosx']['version']['major']",
  'macosx_productversion_minor' => "facts['os']['macosx']['version']['minor']",
  'manufacturer' => "facts['dmi']['manufacturer']",
  'memoryfree' => "facts['memory']['system']['available']",
  'memorysize' => "facts['memory']['system']['total']",
  'netmask' => "facts['networking']['netmask']",
  'netmask6' => "facts['networking']['netmask6']",
  'network' => "facts['networking']['network']",
  'network6' => "facts['networking']['network6']",
  'operatingsystem' => "facts['os']['name']",
  'operatingsystemmajrelease' => "facts['os']['release']['major']",
  'operatingsystemrelease' => "facts['os']['release']['full']",
  'osfamily' => "facts['os']['family']",
  'physicalprocessorcount' => "facts['processors']['physicalcount']",
  'processorcount' => "facts['processors']['count']",
  'productname' => "facts['dmi']['product']['name']",
  'rubyplatform' => "facts['ruby']['platform']",
  'rubysitedir' => "facts['ruby']['sitedir']",
  'rubyversion' => "facts['ruby']['version']",
  'selinux' => "facts['os']['selinux']['enabled']",
  'selinux_config_mode' => "facts['os']['selinux']['config_mode']",
  'selinux_config_policy' => "facts['os']['selinux']['config_policy']",
  'selinux_current_mode' => "facts['os']['selinux']['current_mode']",
  'selinux_enforced' => "facts['os']['selinux']['enforced']",
  'selinux_policyversion' => "facts['os']['selinux']['policy_version']",
  'serialnumber' => "facts['dmi']['product']['serial_number']",
  'swapencrypted' => "facts['memory']['swap']['encrypted']",
  'swapfree' => "facts['memory']['swap']['available']",
  'swapsize' => "facts['memory']['swap']['total']",
  'system32' => "facts['os']['windows']['system32']",
  'uptime' => "facts['system_uptime']['uptime']",
  'uptime_days' => "facts['system_uptime']['days']",
  'uptime_hours' => "facts['system_uptime']['hours']",
  'uptime_seconds' => "facts['system_uptime']['seconds']",
  'uuid' => "facts['dmi']['product']['uuid']",
  'xendomains' => "facts['xen']['domains']",
  'zonename' => "facts['solaris_zones']['current']"
}.freeze
HASH_KEY_TYPES =

A list of valid hash key token types

Set[
  :STRING,  # Double quoted string
  :SSTRING, # Single quoted string
  :NAME,    # Unquoted single word
].freeze
WHITESPACE_TYPES =

Public: Check the raw manifest string for lines containing hard tab characters and record an error for each instance found.

puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace

Set[:INDENT, :WHITESPACE]
DEFAULT_SCOPE_VARS =

Public: Test the manifest tokens for any variables that are referenced in the manifest. If the variables are not fully qualified or one of the variables automatically created in the scope, check that they have been defined in the local scope and record a warning for each variable that has not.

puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables

Set[
  'name',
  'title',
  'module_name',
  'environment',
  'clientcert',
  'clientversion',
  'servername',
  'serverip',
  'serverversion',
  'caller_module_name',
  'alias',
  'audit',
  'before',
  'loglevel',
  'noop',
  'notify',
  'require',
  'schedule',
  'stage',
  'subscribe',
  'tag',
  'facts',
  'trusted',
  'server_facts',
]
POST_VAR_TOKENS =
Set[:COMMA, :EQUALS, :RPAREN]
STRING_TYPES =

Public: Check the manifest tokens for any double or single quoted strings containing only a boolean value and record a warning for each instance found.

No style guide reference

Set[:STRING, :SSTRING]
BOOLEANS =
Set['true', 'false']
TOP_SCOPE_FACTS_VAR_TYPES =

Public: A puppet-lint plugin that will check for the use of top scope facts. For example, the fact ‘$facts` should be used over `$::kernel`.

The check only finds facts using the top-scope: ie it will find $::operatingsystem but not $operatingsystem. It also all top scope variables are facts. If you have top scope variables that aren’t facts you should configure the linter to ignore them.

You can allowlist top scope variables to ignore via the Rake task. You should insert the following line to your Rakefile. ‘PuppetLint.configuration.top_scope_variables = [’location’, ‘role’]‘

This plugin was adopted in to puppet-lint from github.com/mmckinst/puppet-lint-top_scope_facts-check Thanks to @mmckinst, @seanmil and @alexjfisher for the original work.

Set[:VARIABLE, :UNENC_VARIABLE]
COMMENT_TYPES =

Public: Check the manifest tokens for any arrows (=>) in a grouping ({}) that are not aligned with other arrows in that grouping.

puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace

Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT]
COMMENT_TOKENS =

Public: Check the manifest tokens for any class or defined type that does not have a comment directly above it (hopefully, explaining the usage of it) and record a warning for each instance found.

puppet.com/docs/puppet/latest/style_guide.html#public-and-private

Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT]
WHITESPACE_TOKENS =
Set[:WHITESPACE, :NEWLINE, :INDENT]
TOKEN_TYPES =

Public: Check the tokens of each File resource instance for a mode parameter and if found, record a warning if the value of that parameter is not a quoted string.

puppet.com/docs/puppet/latest/style_guide.html#file-modes

Set[:NAME, :NUMBER]
VAR_TYPES =

Public: Check the manifest tokens for double quoted strings that contain a single variable only and record a warning for each instance found.

puppet.com/docs/puppet/latest/style_guide.html#quoting

Set[:VARIABLE, :UNENC_VARIABLE]
ESCAPE_CHAR_RE =

Public: Check the manifest tokens for any double quoted strings that don’t contain any variables or common escape characters and record a warning for each instance found.

puppet.com/docs/puppet/latest/style_guide.html#quoting

%r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze
STRING_TOKEN_TYPES =

Public: Check the manifest tokens for any variables in a string that have not been enclosed by braces ({}) and record a warning for each instance found.

puppet.com/docs/puppet/latest/style_guide.html#quoting

Set[
  :DQMID,
  :DQPOST,
  :HEREDOC_MID,
  :HEREDOC_POST,
]
VARIABLE_LOWERCASE_TYPES =

Public: Test the manifest tokens for variables that contain an uppercase letter and record a warning for each instance found.

No style guide reference

Set[:VARIABLE, :UNENC_VARIABLE]
VARIABLE_DASH_TYPES =

Public: Test the manifest tokens for variables that contain a dash and record a warning for each instance found.

No style guide reference

Set[:VARIABLE, :UNENC_VARIABLE]
CLASS_DEFINE_TOKENS =

Public: Test the manifest tokens for any classes or defined types that are defined inside another class.

puppet.com/docs/puppet/latest/style_guide.html#nested-classes-or-defined-types

Set[:CLASS, :DEFINE]

Instance Method Summary collapse

Instance Method Details

#run_cmd(message, *cmd) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet-lint/tasks/release_test.rb', line 5

def run_cmd(message, *cmd)
  print("  #{message}... ")

  if Open3.respond_to?(:capture2e)
    output, status = Open3.capture2e(*cmd)
  else
    output = ''

    Open3.popen3(*cmd) do |stdin, stdout, stderr|
      stdin.close
      output += stdout.read
      output += stderr.read
    end
    status = $CHILD_STATUS.dup
  end

  if status.success?
    puts 'Done'
  else
    puts 'FAILED'
  end

  [output.strip, status.success?]
end

#with_puppet_lint_head(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet-lint/tasks/release_test.rb', line 30

def with_puppet_lint_head(&block)
  print('  Updating Gemfile to use puppet-lint HEAD... ')

  buffer = Parser::Source::Buffer.new('Gemfile')
  buffer.source = File.read('Gemfile')
  parser = Parser::CurrentRuby.new
  ast = parser.parse(buffer)

  modified_gemfile = GemfileRewrite.new.rewrite(buffer, ast)
  if modified_gemfile == buffer.source
    puppet_lint_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
    File.open('Gemfile', 'a') do |f|
      f.puts "gem 'puppet-lint', :path => '#{puppet_lint_root}'"
    end
  else
    File.open('Gemfile', 'w') do |f|
      f.puts modified_gemfile
    end
  end

  puts 'Done'

  Bundler.with_clean_env(&block)

  run_cmd('Restoring Gemfile', 'git', 'checkout', '--', 'Gemfile')
end