puppet-lint-legacy_facts-check 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90c39fb6507da85f5d4bcd1d17587a2bdfb210fe0519c614cc2832bd04d5fda4
4
- data.tar.gz: 6312725c235f5e05212b5897b47a327557e40d6a674317dacda10c4fdd7c094a
3
+ metadata.gz: 9a7f2391ddc2702af498700ea0b6d0b8ba497c4a2e4ec5fe1c4435ccbf8bace9
4
+ data.tar.gz: f8d7e0285d707ff2573c5ab3c192d2ef0091471a00c889a0fa767acd22e4299a
5
5
  SHA512:
6
- metadata.gz: fb8cecf281e0eb2d27fe46b29de3812c4ad89ef36498cb416ef3c536cd6acaeb4e8d8a7974c3d49e26264d7c610b1d61e735bc848b507251f039780926f94b6a
7
- data.tar.gz: 8797b37fef673e69b04d139f2e2fb93d53d80706b60591e41e114091bd41adfc6b8b74989c8c9b05fffe1bcdf87b2ad6b6b3e542ada20f053ed513d6fd6d1427
6
+ metadata.gz: 20e2f8fe27fb5040a4de485946553c0c40571a3852f0f7b47ca88c7ee0e336a1c1aecf60b13abec13d79cf69d235e21168c0d85f3516a4aee6efa82f77ebd8e7
7
+ data.tar.gz: e52f2ab36c8181c51abc12adba813e364a13798291226b3c1750d6e4ca2dbd1388848feab44c8d9e96a5ded608b43fe472b43760f8a8f853e5caf5f914e50bfd
data/README.md CHANGED
@@ -66,6 +66,11 @@ PuppetLint.configuration.send('disable_legacy_facts')
66
66
 
67
67
  ## Limitations
68
68
 
69
+ The linter will only find and work on top scope facts like `$::osfamily`,
70
+ non-top scope facts like `$osfamily` will not be found or fixed. The
71
+ [top_scope_facts-check ](https://github.com/mmckinst/puppet-lint-top_scope_facts-check)
72
+ puppet linter can be used to fix that problem
73
+
69
74
  Some facts have no equivalent in the structured fact list:
70
75
 
71
76
  ### `memoryfree_mb`
@@ -76,7 +81,7 @@ The closest equivalent is `$facts['memory']['system'][available']` or
76
81
  `$facts['memory']['system']['available_bytes']`.
77
82
 
78
83
  See
79
- [facter documentation on memory](https://docs.puppet.com/facter/3.4/core_facts.html#memory).
84
+ [facter documentation on memory](https://puppet.com/docs/facter/3.12/core_facts.html#memory).
80
85
 
81
86
  ### `memorysize_mb`
82
87
 
@@ -85,7 +90,7 @@ There is no fact that returns exclusively in MiB.
85
90
  The closest equivalent is `$facts['memory']['system']['total']` or
86
91
  `$facts['memory']['system']['total_bytes']`.
87
92
 
88
- See [facter documentation on memory](https://docs.puppet.com/facter/3.4/core_facts.html#memory).
93
+ See [facter documentation on memory](https://puppet.com/docs/facter/3.12/core_facts.html#memory).
89
94
 
90
95
  ### `swapfree_mb`
91
96
 
@@ -94,7 +99,7 @@ There is no fact that returns exclusively in MiB.
94
99
  The closest equivalent is `$facts['memory']['swap']['available']` or
95
100
  `$facts['memory']['swap']['available_bytes']`.
96
101
 
97
- See [facter documentation on memory](https://docs.puppet.com/facter/3.4/core_facts.html#memory).
102
+ See [facter documentation on memory](https://puppet.com/docs/facter/3.12/core_facts.html#memory).
98
103
 
99
104
  ### `swapsize_mb`
100
105
 
@@ -103,7 +108,7 @@ There is no fact that returns exclusively in MiB.
103
108
  The closest equivalent is `$facts['memory']['swap']['used']` or
104
109
  `$facts['memory']['swap']['used_bytes']`.
105
110
 
106
- See [facter documentation on memory](https://docs.puppet.com/facter/3.4/core_facts.html#memory).
111
+ See [facter documentation on memory](https://puppet.com/docs/facter/3.12/core_facts.html#memory).
107
112
 
108
113
  ### `blockdevices`
109
114
 
@@ -1,9 +1,20 @@
1
1
  PuppetLint.new_check(:legacy_facts) do
2
+
3
+ # These facts that can't be converted to new facts for reasons documented at
4
+ # https://github.com/mmckinst/puppet-lint-legacy_facts-check#limitations
2
5
  UNCONVERTIBLE_FACTS = ['memoryfree_mb', 'memorysize_mb', 'swapfree_mb',
3
6
  'swapsize_mb', 'blockdevices', 'interfaces', 'zones',
4
7
  'sshfp_dsa', 'sshfp_ecdsa', 'sshfp_ed25519',
5
8
  'sshfp_rsa']
6
9
 
10
+ # These facts will depend on how a system is set up and can't just be
11
+ # enumerated like the EASY_FACTS below.
12
+ #
13
+ # For example a sever might have two block devices named 'sda' and 'sdb' so
14
+ # there would be a $blockdeivce_sda_vendor and $blockdeivce_sdb_vendor fact
15
+ # for each device. Or it could have 26 block devices going all the way up to
16
+ # 'sdz'. There is no way to know what the possibilities are so we have to use
17
+ # a regex to match them.
7
18
  REGEX_FACTS = [/^blockdevice_(?<devicename>.*)_(?<attribute>model|size|vendor)$/,
8
19
  /^(?<attribute>ipaddress|ipaddress6|macaddress|mtu|netmask|netmask6|network|network6)_(?<interface>.*)$/,
9
20
  /^processor(?<id>[0-9]+)$/,
@@ -12,6 +23,8 @@ PuppetLint.new_check(:legacy_facts) do
12
23
  /^ldom_(?<name>.*)$/,
13
24
  /^zone_(?<name>.*)_(?<attribute>brand|iptype|name|uuid|id|path|status)$/]
14
25
 
26
+ # These facts have a one to one correlation between a legacy fact and a new
27
+ # structured fact.
15
28
  EASY_FACTS = {
16
29
  'architecture' => "facts['os']['architecture']",
17
30
  'augeasversion' => "facts['augeas']['version']",
@@ -85,11 +98,19 @@ PuppetLint.new_check(:legacy_facts) do
85
98
  def check
86
99
  tokens.select { |x| x.type == :VARIABLE}.each do |token|
87
100
  fact_name = ''
101
+
102
+ # Get rid of the top scope before we do our work. We don't need to
103
+ # preserve it because it won't work with the new structured facts.
88
104
  if token.value.start_with?('::') then
89
105
  fact_name = token.value.sub(/^::/, '')
106
+
107
+ # This matches using legacy facts in a the new structured fact. For
108
+ # example this would match 'uuid' in $facts['uuid'] so it can be converted
109
+ # to facts['dmi']['product']['uuid']"
90
110
  elsif token.value.start_with?("facts['") then
91
111
  fact_name = token.value.match(/facts\['(.*)'\]/)[1]
92
112
  end
113
+
93
114
  if EASY_FACTS.include?(fact_name) or UNCONVERTIBLE_FACTS.include?(fact_name) or fact_name.match(Regexp.union(REGEX_FACTS)) then
94
115
  notify :warning, {
95
116
  :message => 'legacy fact',
@@ -105,8 +126,14 @@ PuppetLint.new_check(:legacy_facts) do
105
126
  # This probably should never occur, but if it does then bail out:
106
127
  raise PuppetLint::NoFix if problem[:token].raw and problem[:token].value != problem[:token].raw
107
128
 
129
+ # Get rid of the top scope before we do our work. We don't need to
130
+ # preserve it because it won't work with the new structured facts.
108
131
  if problem[:token].value.start_with?('::') then
109
132
  fact_name = problem[:token].value.sub(/^::/, '')
133
+
134
+ # This matches using legacy facts in a the new structured fact. For
135
+ # example this would match 'uuid' in $facts['uuid'] so it can be converted
136
+ # to facts['dmi']['product']['uuid']"
110
137
  elsif problem[:token].value.start_with?("facts['") then
111
138
  fact_name = problem[:token].value.match(/facts\['(.*)'\]/)[1]
112
139
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-legacy_facts-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark McKinstry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -141,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.7.8
144
+ rubygems_version: 3.0.2
146
145
  signing_key:
147
146
  specification_version: 4
148
147
  summary: A puppet-lint plugin to check you are not using legacy facts like $::operatingsystem