64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/os_version.rb', line 64
newfunction(:os_version, :type => :rvalue, :arity => 1) do |args|
self_release = lookupvar('lsbdistrelease')
self_id = lookupvar('lsbdistid')
if self_release.nil? || self_id.nil?
fail('os_version(): LSB facts are not set; is lsb-release installed?')
end
unless args.first.is_a?(String)
fail(ArgumentError, 'os_version(): string argument required')
end
clauses = args.first.split('||').map(&:strip)
clauses.any? do |clause|
unless /^(?<id>\w+) *(?<operator>[<>=]*) *(?<release>[\w\.]+)$/ =~ clause
fail(ArgumentError, "os_version(): invalid expression '#{clause}'")
end
other_id = id.capitalize
other_release = release.downcase
if os_versions[other_id].key?(other_release)
other_release = os_versions[other_id][other_release]
other_was_codename = true
elsif /^[\d.]+$/ !~ other_release
fail(ArgumentError,
"os_version(): unknown #{other_id} release '#{other_release}'")
end
min_version = min_supported_versions[other_id]
if Puppet::Util::Package.versioncmp(other_release, min_version) < 0 ||
(Puppet::Util::Package.versioncmp(other_release, min_version) == 0 &&
(operator == '<=' || operator == '<'))
message = "os_version(): obsolete distribution check in #{clause}"
if defined? Puppet::Pops::PuppetStack.stacktrace
stacktrace = Puppet::Pops::PuppetStack.stacktrace()[0]
file = stacktrace[0]
line = stacktrace[1]
message = "#{message} at #{file}:#{line}"
end
warning(message)
end
next unless self_id == other_id
if other_id == 'Debian' && other_was_codename
self_release = self_release.split('.')[0]
end
cmp = Puppet::Util::Package.versioncmp(self_release, other_release)
case operator
when '', '==' then cmp == 0
when '!=' then cmp != 0
when '>' then cmp == 1
when '<' then cmp == -1
when '>=' then cmp >= 0
when '<=' then cmp <= 0
else fail(ArgumentError,
"os_version(): unknown comparison operator '#{operator}'")
end
end
end
|