jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/393494 )
Change subject: wmflib: Copy from 626a7ccc09 upstream
......................................................................
wmflib: Copy from 626a7ccc09 upstream
Copy in the upstream operations/puppet.git wmflib module@ 626a7ccc09
Bug: T181354
Change-Id: I1d0fd5be73fccb606a699abefc2dfd101aacee32
---
M puppet/modules/wmflib/README.md
M puppet/modules/wmflib/Rakefile
M puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
M puppet/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
M puppet/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
M puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb
M puppet/modules/wmflib/lib/hiera/backend/role_backend.rb
M puppet/modules/wmflib/lib/hiera/httpcache.rb
M puppet/modules/wmflib/lib/hiera/mwcache.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/conftool.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/cron_splay.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/ensure_mounted.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/get_clusters.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/hash_deselect_re.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/hash_select_re.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/htpasswd.rb
A puppet/modules/wmflib/lib/puppet/parser/functions/init_template.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/ipresolve.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/os_version.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/puppet_ssldir.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/require_package.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/requires_os.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/role.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/shell_exports.rb
M puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb
A puppet/modules/wmflib/lib/puppet/parser/functions/systemd_template.rb
A puppet/modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb
A puppet/modules/wmflib/lib/puppet/parser/functions/upstart_template.rb
A
puppet/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
M puppet/modules/wmflib/spec/functions/conftool_spec.rb
M puppet/modules/wmflib/spec/functions/ensure_mounted_spec.rb
A puppet/modules/wmflib/spec/functions/init_template_spec.rb
M puppet/modules/wmflib/spec/functions/ipresolve_spec.rb
A puppet/modules/wmflib/spec/functions/os_version_spec.rb
M puppet/modules/wmflib/spec/functions/role_spec.rb
M puppet/modules/wmflib/spec/hiera/proxy_backend_spec.rb
M puppet/modules/wmflib/spec/hiera/role_backend_spec.rb
38 files changed, 348 insertions(+), 215 deletions(-)
Approvals:
BryanDavis: Looks good to me, approved
jenkins-bot: Verified
diff --git a/puppet/modules/wmflib/README.md b/puppet/modules/wmflib/README.md
index f6ab3fe..baea3fb 100644
--- a/puppet/modules/wmflib/README.md
+++ b/puppet/modules/wmflib/README.md
@@ -231,8 +231,8 @@
### Examples
- # True if Ubuntu Trusty or newer or Debian Jessie or newer
- os_version('ubuntu >= trusty || debian >= Jessie')
+ # True if Ubuntu Trusty or newer or Debian jessie or newer
+ os_version('ubuntu >= trusty || debian >= jessie')
# True if exactly Debian Jessie
os_version('debian jessie')
diff --git a/puppet/modules/wmflib/Rakefile b/puppet/modules/wmflib/Rakefile
index a0c3b79..cd3d379 100644
--- a/puppet/modules/wmflib/Rakefile
+++ b/puppet/modules/wmflib/Rakefile
@@ -1,37 +1 @@
-require 'rake'
-require 'fileutils'
-
-require 'rspec/core/rake_task'
-
-modulename = File.basename(File.expand_path(File.dirname(__FILE__)))
-
-symlinks = { 'spec/fixtures/modules/%s/files' % modulename =>
'../../../../files',
- 'spec/fixtures/modules/%s/manifests' % modulename =>
'../../../../manifests',
- 'spec/fixtures/modules/%s/templates' % modulename =>
'../../../../templates',
- }
-
-
-task :setup do
- FileUtils.mkdir_p('spec/fixtures/modules/%s' % modulename)
- symlinks.each do |x|
- if !File.exist?(x[0])
- FileUtils.ln_s(x[1], x[0])
- end
- end
-end
-
-task :teardown do
- symlinks.each { |x| FileUtils.rm(x[0], :force => true) }
- FileUtils.rmdir('spec/fixtures/modules/%s' % modulename)
- FileUtils.rmdir('spec/fixtures/modules')
-end
-
-RSpec::Core::RakeTask.new(:realspec) do |t|
- t.fail_on_error = false
- t.pattern = 'spec/*/*_spec.rb'
-end
-
-task :spec_standalone => [ :setup, :realspec, :teardown]
-
-task :default => :spec do
-end
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
b/puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
index fae9f51..3106cf5 100644
--- a/puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
+++ b/puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
@@ -1,6 +1,7 @@
require "hiera/httpcache"
class Hiera
module Backend
+ # This naming is required by puppet.
class Httpyaml_backend
def initialize
@cache = Httpcache.new
diff --git a/puppet/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
b/puppet/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
index 5f6253e..fd3aabb 100644
--- a/puppet/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
+++ b/puppet/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
@@ -1,8 +1,9 @@
require "hiera/mwcache"
class Hiera
module Backend
+ # This naming is required by puppet.
class Mwyaml_backend
- def initialize(cache=nil)
+ def initialize(cache = nil)
@cache = cache || Mwcache.new
end
@@ -40,14 +41,14 @@
when :hash
raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
answer ||= {}
- answer = Backend.merge_answer(new_answer,answer)
+ answer = Backend.merge_answer(new_answer, answer)
else
answer = new_answer
break
end
end
- return answer
+ answer
end
end
end
diff --git a/puppet/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
b/puppet/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
index ad01bf9..9dd48d2 100644
--- a/puppet/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
+++ b/puppet/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
@@ -49,7 +49,7 @@
#
# === Example
# Say you have a lookup for "cluster", and you have
-#"regex/%{hostname}" in your hierarchy; also, let's say that your
+# "regex/%{hostname}" in your hierarchy; also, let's say that your
# scope contains hostname = "web1001.local". So if your regex.yaml
# file contains:
#
@@ -66,9 +66,9 @@
#
class Hiera
module Backend
+ # This naming is required by puppet.
class Nuyaml_backend
-
- def initialize(cache=nil)
+ def initialize(cache = nil)
require 'yaml'
@cache = cache || Filecache.new
config = Config[:nuyaml]
@@ -78,7 +78,7 @@
def get_path(key, scope, source)
config_section = :nuyaml
# Special case: regex
- if m = /^regex\//.match(source)
+ if %r{^regex/}.match(source)
Hiera.debug("Regex match going on - using regex.yaml")
return Backend.datafile(config_section, scope, 'regex', "yaml")
end
@@ -87,18 +87,18 @@
# We use a different datadir in this case.
# Example: private/common will search in the common source
# within the private datadir
- if m = /private\/(.*)/.match(source)
+ if %r{private/(.*)} =~ source
config_section = :private
- source = m[1]
+ source = Regexp.last_match(1)
end
# Special case: 'secret' repository. This is practically labs only
# We use a different datadir in this case.
# Example: private/common will search in the common source
# within the private datadir
- if m = /secret\/(.*)/.match(source)
- config_section = :secret
- source = m[1]
+ if %r{secret/(.*)} =~ source
+ config_section = :secret
+ source = Regexp.last_match(1)
end
Hiera.debug("The source is: #{source}")
@@ -109,7 +109,7 @@
# $apache::mpm::worker will be in common/apache/mpm.yaml
paths = @expand_path.map{ |x| Backend.parse_string(x, scope) }
if paths.include? source
- namespaces = key.gsub(/^::/,'').split('::')
+ namespaces = key.gsub(/^::/, '').split('::')
namespaces.pop
unless namespaces.empty?
@@ -117,12 +117,12 @@
end
end
- return Backend.datafile(config_section, scope, source, "yaml")
+ Backend.datafile(config_section, scope, source, "yaml")
end
def plain_lookup(key, data, scope)
return nil unless data.include?(key)
- return Backend.parse_answer(data[key], scope)
+ Backend.parse_answer(data[key], scope)
end
def regex_lookup(key, matchon, data, scope)
@@ -164,8 +164,8 @@
next if data.nil?
- if m = /regex\/(.*)$/.match(source)
- matchto = m[1]
+ if %r{regex/(.*)$} =~ source
+ matchto = Regexp.last_match(1)
new_answer = regex_lookup(key, matchto, data, scope)
else
new_answer = plain_lookup(key, data, scope)
@@ -193,14 +193,14 @@
when :hash
raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
answer ||= {}
- answer = Backend.merge_answer(new_answer,answer)
+ answer = Backend.merge_answer(new_answer, answer)
else
answer = new_answer
break
end
end
- return answer
+ answer
end
end
end
diff --git a/puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb
b/puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb
index b8a77b2..77ba195 100644
--- a/puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb
+++ b/puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb
@@ -13,7 +13,7 @@
# lookup each
class Hiera::Config
class << self
- def []=(key,value)
+ def []=(key, value)
@config[key] = value
end
end
@@ -21,16 +21,17 @@
class Hiera
module Backend
+ # This naming is required by puppet.
class Proxy_backend
def initialize
Hiera.debug "Starting the proxy backend"
@config = Config[:proxy]
- self.load_plugins
+ load_plugins
end
def load_plugins
- @plugins ||={}
- #Load plugins only once
+ @plugins ||= {}
+ # Load plugins only once
@config[:plugins].each do |plugin|
Hiera.debug "Loading plugin #{plugin}"
begin
@@ -53,7 +54,7 @@
else
plugin = @config[:default_plugin]
end
- if not @plugins.include? plugin
+ unless @plugins.include? plugin
Hiera.
warn "Hierarchy specifies to use plugin '#{plugin}' but can't
find it"
next
@@ -77,7 +78,7 @@
when :hash
raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
answer ||= {}
- answer = Backend.merge_answer(new_answer,answer)
+ answer = Backend.merge_answer(new_answer, answer)
else
answer = new_answer
break
diff --git a/puppet/modules/wmflib/lib/hiera/backend/role_backend.rb
b/puppet/modules/wmflib/lib/hiera/backend/role_backend.rb
index 8de978c..0ce9ed6 100644
--- a/puppet/modules/wmflib/lib/hiera/backend/role_backend.rb
+++ b/puppet/modules/wmflib/lib/hiera/backend/role_backend.rb
@@ -69,21 +69,22 @@
require 'yaml'
class Hiera
module Backend
+ # This naming is required by puppet.
class Role_backend
- def initialize(cache=nil)
+ def initialize(cache = nil)
@cache = cache || Filecache.new
end
- def get_path(key, role, source, scope)
+ def get_path(_key, role, source, scope)
config_section = :role
# Special case: 'private' repository.
# We use a different datadir in this case.
# Example: private/common will search in the role/common source
# within the private datadir
- if m = /private\/(.*)/.match(source)
+ if %r{private/(.*)} =~ source
config_section = :private
- source = m[1]
+ source = Regexp.last_match(1)
end
# Variables for role::foo::bar will be searched in:
@@ -94,7 +95,7 @@
src = "role/#{source}/#{path}"
# Use the datadir for the 'role' section of the config
- return Backend.datafile(config_section, scope, src, "yaml")
+ Backend.datafile(config_section, scope, src, "yaml")
end
def merge_answer(new_answer, answer, resolution_type)
@@ -106,12 +107,13 @@
when :hash
raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
answer ||= {}
- answer = Backend.merge_answer(new_answer,answer)
+ answer = Backend.merge_answer(new_answer, answer)
else
answer = new_answer
return true, answer
end
- return false, answer
+
+ [false, answer]
end
def lookup(key, scope, order_override, resolution_type)
@@ -130,7 +132,7 @@
Hiera.debug("Looking in hierarchy for role #{role}")
answer = nil
Backend.datasources(scope, order_override, hierarchy) do |source|
- yamlfile = get_path(key,role,source, scope)
+ yamlfile = get_path(key, role, source, scope)
next if yamlfile.nil?
Hiera.debug("Searching in file #{yamlfile} for #{key}")
next unless File.exist?(yamlfile)
diff --git a/puppet/modules/wmflib/lib/hiera/httpcache.rb
b/puppet/modules/wmflib/lib/hiera/httpcache.rb
index 270c449..8849ee9 100644
--- a/puppet/modules/wmflib/lib/hiera/httpcache.rb
+++ b/puppet/modules/wmflib/lib/hiera/httpcache.rb
@@ -24,7 +24,7 @@
end
end
- def read(path, expected_type=Hash, default=nil)
+ def read(path, _expected_type = Hash, _default = nil)
read_file(path)
rescue => detail
# When failing to read data, we raise an exception, see
https://phabricator.wikimedia.org/T78408
@@ -37,7 +37,7 @@
data = get_from_http(path)
@cache[path][:data] = data
- if !@cache[path][:data].is_a?(Object)
+ unless @cache[path][:data].is_a?(Object)
raise TypeError, "Data retrieved from #{path} is #{data.class} not
Object"
end
end
diff --git a/puppet/modules/wmflib/lib/hiera/mwcache.rb
b/puppet/modules/wmflib/lib/hiera/mwcache.rb
index 191eedb..e1acc6b 100644
--- a/puppet/modules/wmflib/lib/hiera/mwcache.rb
+++ b/puppet/modules/wmflib/lib/hiera/mwcache.rb
@@ -28,7 +28,7 @@
end
end
- def read(path, expected_type, default=nil, &block)
+ def read(path, expected_type, default = nil, &block)
read_file(path, expected_type, &block)
rescue Hiera::MediawikiPageNotFoundError => detail
# Any errors other than this will cause hiera to raise an error and
puppet to fail.
@@ -40,6 +40,7 @@
raise error
end
+ # rubocop: disable Lint/UnusedMethodArgument
def read_file(path, expected_type = Object, &block)
if stale?(path)
resp = get_from_mediawiki(path, true)
@@ -53,6 +54,7 @@
@cache[path][:data]
end
+ # rubocop: enable Lint/Unusedmethodargument
private
@@ -93,11 +95,10 @@
# TODO: add some locking mechanism for requests? Maybe overkill, maybe
not.
revision = get_from_mediawiki(path, false)["revid"]
- return {:ts => now, :revision => revision}
+ {:ts => now, :revision => revision}
end
-
- def get_from_mediawiki(path,want_content)
+ def get_from_mediawiki(path, want_content)
what = want_content ? 'content' : 'ids'
query_string =
"action=query&prop=revisions&format=json&rvprop=#{what}&titles=Hiera:#{path}"
url = "#{@httphost}#{@endpoint}?#{query_string}"
@@ -114,9 +115,9 @@
if pages.keys.include? "-1"
raise Hiera::MediawikiPageNotFoundError, "Hiera:#{path}"
end
- #yes, it's that convoluted.
+ # yes, it's that convoluted.
key = pages.keys[0]
- return pages[key]["revisions"][0]
+ pages[key]["revisions"][0]
end
end
end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/conftool.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/conftool.rb
index 867ad1e..f3c9ce5 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/conftool.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/conftool.rb
@@ -53,8 +53,8 @@
result.push({'name' => obj_name, 'tags' => tags, 'value' =>
entry[obj_name]})
end
result
- rescue
- raise Puppet::ParseError, "Unable to read data from conftool"
+ rescue StandardError => e
+ raise Puppet::ParseError, "Unable to read data from conftool. Wrapped
error is #{e}: #{e.message}"
end
end
end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/cron_splay.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/cron_splay.rb
index af76bf6..382396d 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/cron_splay.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/cron_splay.rb
@@ -39,8 +39,10 @@
EOS
) do |arguments|
- raise(Puppet::ParseError, "cron_splay(): Wrong number of arguments " +
- "given (#{arguments.size} for 3)") if arguments.size != 3
+ unless arguments.size == 3
+ raise(Puppet::ParseError, "cron_splay(): Wrong number of arguments " +
+ "given (#{arguments.size} for 3)")
+ end
hosts = arguments[0]
period = arguments[1]
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/ensure_mounted.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/ensure_mounted.rb
index 7a5e321..a069948 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/ensure_mounted.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/ensure_mounted.rb
@@ -24,7 +24,6 @@
#
module Puppet::Parser::Functions
newfunction(:ensure_mounted, :type => :rvalue, :arity => 1) do |args|
-
ensure_param = args.first
case ensure_param
when 'present', 'true', true then 'mounted'
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/get_clusters.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/get_clusters.rb
index 979a7b6..2cc90e4 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/get_clusters.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/get_clusters.rb
@@ -24,7 +24,7 @@
newfunction(:get_clusters, :type => :rvalue) do |args|
all = {}
# Ganglia config is the source of truth about clusters/site
- cluster_config = function_hiera(['ganglia_clusters', {}])
+ cluster_config = call_function(:hiera, ['ganglia_clusters', {}])
# Arguments are an hash of selectors
selector ||= {}
@@ -41,10 +41,10 @@
sites = false
end
- function_query_resources([false, '@@Ganglia::Cluster', false]).each do
|node|
+ function_query_resources([false, 'Class["Profile::Cumin::Target"]', false,
'certname asc']).each do |node|
cluster = node['parameters']['cluster']
site = node['parameters']['site']
- fqdn = node['title']
+ fqdn = node['certname']
next unless clusters.include?cluster
next if sites && !sites.include?(site)
all[cluster] ||= {}
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/hash_deselect_re.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/hash_deselect_re.rb
index c779625..8f0597f 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/hash_deselect_re.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/hash_deselect_re.rb
@@ -18,8 +18,10 @@
EOS
) do |arguments|
- raise(Puppet::ParseError, "hash_deselect_re(): Wrong number of arguments "
+
- "given (#{arguments.size} for 2)") if arguments.size != 2
+ unless arguments.size == 2
+ raise(Puppet::ParseError, "hash_deselect_re(): Wrong number of arguments
" +
+ "given (#{arguments.size} for 2)")
+ end
pattern = Regexp.new(arguments[0])
in_hash = arguments[1]
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/hash_select_re.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/hash_select_re.rb
index b5aa204..5bfdf6a 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/hash_select_re.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/hash_select_re.rb
@@ -18,8 +18,10 @@
EOS
) do |arguments|
- raise(Puppet::ParseError, "hash_select_re(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size != 2
+ unless arguments.size == 2
+ raise(Puppet::ParseError, "hash_select_re(): Wrong number of arguments "
+
+ "given (#{arguments.size} for 2)")
+ end
pattern = Regexp.new(arguments[0])
in_hash = arguments[1]
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/htpasswd.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/htpasswd.rb
index e6d9335..7438d92 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/htpasswd.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/htpasswd.rb
@@ -12,7 +12,6 @@
# Original code Copyright (c) 2008 Jeremy Hinegardner
# Modifications Copyright (c) 2017 Giuseppe Lavagetto, Wikimedia Foundation,
Inc.
class Apr1Md5
-
DIGEST_LENGTH = 16
def initialize(salt)
@@ -34,7 +33,6 @@
end
r.string
end
-
# this algorithm pulled straight from apr_md5_encode() and converted to ruby
syntax
def encode(password)
@@ -72,12 +70,11 @@
1000.times do |x|
ctx = ::Digest::MD5.new
ctx << (((x & 1) == 1) ? password : pd[0, DIGEST_LENGTH])
- (ctx << @salt) unless (x % 3) == 0
- (ctx << password) unless (x % 7) == 0
- ctx << (((x & 1) == 0) ? password : pd[0, DIGEST_LENGTH])
+ (ctx << @salt) unless (x % 3).zero?
+ (ctx << password) unless (x % 7).zero?
+ ctx << (((x & 1).zero?) ? password : pd[0, DIGEST_LENGTH])
pd = ctx.digest
end
-
pd = pd.bytes.to_a
@@ -100,7 +97,6 @@
encoded_password
end
end
-
module Puppet::Parser::Functions
newfunction(:htpasswd, :type => :rvalue, :arity => 2) do |args|
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/init_template.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/init_template.rb
new file mode 100644
index 0000000..49f9f82
--- /dev/null
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/init_template.rb
@@ -0,0 +1,17 @@
+# == Function: init_template
+#
+# Loads a template from a predefined location, and returns its contents.
+#
+# Based on the value of the two mandatory arguments, the template path will be
+# determined as follows:
+#
+# ${module_name}/initscripts/${arg}.${initsystem}.erb
+#
+module Puppet::Parser::Functions
+ newfunction(:init_template, :type => :rvalue, :arity => 2) do |args|
+ tpl_name, initsystem = args
+ module_name = lookupvar('module_name')
+ tpl_arg = "#{module_name}/initscripts/#{tpl_name}.#{initsystem}.erb"
+ function_template([tpl_arg])
+ end
+end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/ipresolve.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/ipresolve.rb
index 02afde3..3399a5b 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/ipresolve.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/ipresolve.rb
@@ -1,14 +1,14 @@
-# == Function: ipresolve( string $name_to_resolve, bool $ipv6 = false)
+# == Function: ipresolve(string $name_to_resolve, string $type = '4', string
$nameserver = nil)
#
-# Copyright (c) 2015 Wikimedia Foundation Inc.
+# Copyright (c) 2015-2017 Wikimedia Foundation Inc.
#
-# Performs a name resolution (for A AND AAAA records only) and returns
-# an hash of arrays.
+# Performs a name resolution (for A, AAAA and PTR records only) and returns a
+# string.
#
-# Takes one or more names to resolve, and returns an array of all the
-# A or AAAA records found. The resolution is actually only done when
-# the ttl has expired. A particular nameserver can also be specified
-# so only that is used, rather than the system default.
+# Takes one name to resolve, and returns a string of the A, AAAA or PTR record
+# found. The resolution is actually only done when the ttl has expired. A
+# particular nameserver can also be specified so only that is used, rather than
+# the system default.
#
require 'resolv'
@@ -19,12 +19,12 @@
@ttl = Time.now.to_i + ttl
end
- def is_valid?(time)
- return @ttl > time
+ def valid?(time)
+ @ttl > time
end
def value
- return @value.to_s
+ @value.to_s
end
end
@@ -41,27 +41,28 @@
@cache.delete(key) if @cache.key?(key)
end
- def is_valid?(key)
+ def valid?(key)
# If the key exists, and its ttl has not expired, return true.
# Return false (and maybe clean up the stale entry) otherwise.
return false unless @cache.key?(key)
t = Time.now.to_i
- return true if @cache[key].is_valid?t
- return false
+ return true if @cache[key].valid?t
+
+ false
end
def read(key)
- if is_valid?key
+ if valid?key
return @cache[key].value
end
- return nil
+ nil
end
def read_stale(key)
if @cache.key?(key)
return @cache[key].value
end
- return nil
+ nil
end
end
@@ -74,13 +75,13 @@
def get_resource(name, type, nameserver)
if nameserver.nil?
- dns = Resolv::DNS.open()
+ dns = Resolv::DNS.open
else
dns = Resolv::DNS.open(:nameserver => [nameserver])
end
cache_key = "#{name}_#{type}_#{nameserver}"
res = @cache.read(cache_key)
- if (res.nil?)
+ if res.nil?
begin
res = dns.getresource(name, type)
# Ruby < 1.9 returns nil as the ttl...
@@ -109,7 +110,6 @@
end
end
end
-
module Puppet::Parser::Functions
dns = DNSCached.new
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb
index 64973f4..8a459d1 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb
@@ -10,7 +10,7 @@
# content => ordered_yaml($options),
# }
#
-require 'puppet/util/zaml.rb'
+require 'yaml'
def sort_keys_recursive(value)
# Prepare a value for YAML serialization by sorting its keys (if it is
@@ -44,6 +44,6 @@
module Puppet::Parser::Functions
newfunction(:ordered_yaml, :type => :rvalue, :arity => 1) do |args|
- dedent_string(ZAML.dump(sort_keys_recursive(args.first)).gsub(/^---.*?\n/,
'')) << "\n"
+ dedent_string(YAML.dump(sort_keys_recursive(args.first)).gsub(/^---.*?\n/,
'')) << "\n"
end
end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/os_version.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/os_version.rb
index badeb79..f7235a9 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/os_version.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/os_version.rb
@@ -13,10 +13,10 @@
#
# === Examples
#
-# # True if Ubuntu Trusty or newer or Debian Jessie or newer
-# os_version('ubuntu >= trusty || debian >= Jessie')
+# # True if Ubuntu Trusty or newer or Debian jessie or newer
+# os_version('ubuntu >= trusty || debian >= jessie')
#
-# # True if exactly Debian Jessie
+# # True if exactly Debian jessie
# os_version('debian jessie')
#
require 'puppet/util/package'
@@ -24,71 +24,101 @@
module Puppet::Parser::Functions
os_versions = {
'Ubuntu' => {
- 'Hardy' => '8.04',
- 'Intrepid' => '8.10',
- 'Jaunty' => '9.04',
- 'Karmic' => '9.10',
- 'Lucid' => '10.04',
- 'Maverick' => '10.10',
- 'Natty' => '11.04',
- 'Oneiric' => '11.10',
- 'Precise' => '12.04',
- 'Quantal' => '12.10',
- 'Raring' => '13.04',
- 'Saucy' => '13.10',
- 'Trusty' => '14.04',
- 'Utopic' => '14.10',
- 'Vivid' => '15.04',
- 'Wily' => '15.10',
- 'Xenial' => '16.04',
- 'Yakkety' => '16.10',
+ 'hardy' => '8.04',
+ 'intrepid' => '8.10',
+ 'jaunty' => '9.04',
+ 'karmic' => '9.10',
+ 'lucid' => '10.04',
+ 'maverick' => '10.10',
+ 'natty' => '11.04',
+ 'oneiric' => '11.10',
+ 'precise' => '12.04',
+ 'quantal' => '12.10',
+ 'raring' => '13.04',
+ 'saucy' => '13.10',
+ 'trusty' => '14.04',
+ 'utopic' => '14.10',
+ 'vivid' => '15.04',
+ 'wily' => '15.10',
+ 'xenial' => '16.04',
+ 'yakkety' => '16.10',
+ 'zesty' => '17.04',
},
'Debian' => {
- 'Wheezy' => '7',
- 'Jessie' => '8',
- 'Stretch' => '9',
- 'Buster' => '10',
+ 'wheezy' => '7',
+ 'jessie' => '8',
+ 'stretch' => '9',
+ 'buster' => '10',
}
}
- newfunction(:os_version, :type => :rvalue, :arity => 1) do |args|
- self_release = lookupvar('lsbdistrelease').capitalize
- self_id = lookupvar('lsbdistid').capitalize
+ # minimum supported version per OS; a warning will be emitted if a comparison
+ # is made against a version lower than these
+ min_supported_versions = {
+ 'Debian' => '8',
+ 'Ubuntu' => '14.04',
+ }
- fail(ArgumentError, 'os_version(): string argument required') unless
args.first.is_a?(String)
+ 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 /^(\w+) *([<>=]*) *([\w\.]+)$/ =~ clause
+ unless /^(?<id>\w+) *(?<operator>[<>=]*) *(?<release>[\w\.]+)$/ =~ clause
fail(ArgumentError, "os_version(): invalid expression '#{clause}'")
end
- # for ruby 1.8; replace with named groups with ruby >= 1.9
- other_id = Regexp.last_match(1)
- operator = Regexp.last_match(2)
- other_release = Regexp.last_match(3)
- [other_id, other_release].each(&:capitalize!)
+ # OS names are in caps, distributions in lowercase
+ other_id = id.capitalize
+ other_release = release.downcase
- next unless self_id == other_id
-
+ # if a codename was passed, get the numeric release
if os_versions[other_id].key?(other_release)
+ other_release = os_versions[other_id][other_release]
other_was_codename = true
- end
-
- other_release = os_versions[other_id][other_release] || other_release
-
- unless /^[\d.]+$/ =~ other_release
+ elsif /^[\d.]+$/ !~ other_release
fail(ArgumentError,
"os_version(): unknown #{other_id} release '#{other_release}'")
end
+ # emit a warning if the release given to compare with is not supported
+ min_version = min_supported_versions[other_id]
+ # rubocop:disable Style/NumericPredicate
+ 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}"
+ # rubocop:enable Style/NumericPredicate
+
+ 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
+
+ # skip this clause unless it's matching our operating system
+ next unless self_id == other_id
+
# special-case Debian point-releases, as e.g. jessie is all of 8.x
- if other_id == "Debian" && other_was_codename
- self_release = self_release.split(".")[0]
+ if other_id == 'Debian' && other_was_codename
+ self_release = self_release.split('.')[0]
end
cmp = Puppet::Util::Package.versioncmp(self_release, other_release)
+ # rubocop:disable Style/NumericPredicate
case operator
when '', '==' then cmp == 0
when '!=' then cmp != 0
@@ -99,6 +129,7 @@
else fail(ArgumentError,
"os_version(): unknown comparison operator '#{operator}'")
end
+ # rubocop:enable Style/NumericPredicate
end
end
end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/puppet_ssldir.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/puppet_ssldir.rb
index d0e8446..8bcdd87 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/puppet_ssldir.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/puppet_ssldir.rb
@@ -23,11 +23,11 @@
# Check arguments
override = overrides[0]
- fail("Only 'master', 'client' and undef " \
- "are valid arguments of puppet_ssldir") unless
- ['master', 'client', nil].include?override
+ unless ['master', 'client', nil].include?override
+ fail("puppet_ssldir(): only 'master', 'client' and undef are valid")
+ end
- default = '/var/lib/puppet/ssl'
+ default = '/var/lib/puppet/ssl'
self_master = '/var/lib/puppet/server/ssl'
self_client = '/var/lib/puppet/client/ssl'
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/require_package.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/require_package.rb
index 996462f..dacf820 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/require_package.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/require_package.rb
@@ -30,7 +30,7 @@
host = compiler.topscope.find_hostclass(class_name)
unless host
host = Puppet::Resource::Type.new(:hostclass, class_name)
- known_resource_types.add_hostclass(host)
+ compiler.environment.known_resource_types.add_hostclass(host)
end
# Create class scope
@@ -44,14 +44,13 @@
begin
host_scope = compiler.topscope.class_scope(host)
- host_scope.function_create_resources(
- ['package', { package_name => { :ensure => :present } }])
+ host_scope.call_function(:create_resources,
+ ['package', { package_name => { :ensure =>
:present } }])
rescue Puppet::Resource::Catalog::DuplicateResourceError
end
# Declare dependency
-
- send Puppet::Parser::Functions.function(:require), [class_name]
+ call_function :require, [class_name]
end
end
end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/requires_os.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/requires_os.rb
index 026affe..7ab47d8 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/requires_os.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/requires_os.rb
@@ -7,11 +7,11 @@
#
# === Examples
#
-# # Fail unless version is exactly Debian Jessie
+# # Fail unless version is exactly Debian jessie
# requires_os('debian jessie')
#
-# # Fail unless Ubuntu Trusty or newer or Debian Jessie or newer
-# requires_os('ubuntu >= trusty || debian >= Jessie')
+# # Fail unless Ubuntu Trusty or newer or Debian jessie or newer
+# requires_os('ubuntu >= trusty || debian >= jessie')
#
module Puppet::Parser::Functions
newfunction(:requires_os, :arity => 1) do |args|
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/role.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/role.rb
index e03cd8a..5087eab 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/role.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/role.rb
@@ -42,7 +42,7 @@
# - Include class role::#{arg} if present
# Prevent use outside of node definitions
- if not self.is_nodescope?
+ if !is_nodescope?
raise Puppet::ParseError,
"role can only be used in node scope, while you are in scope
#{self}"
end
diff --git a/puppet/modules/wmflib/lib/puppet/parser/functions/shell_exports.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/shell_exports.rb
index 233ef3b..577adab 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/shell_exports.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/shell_exports.rb
@@ -22,7 +22,7 @@
# export APACHE_PID_FILE="/var/run/apache2/apache2.pid"
#
module Puppet::Parser::Functions
- newfunction(:shell_exports, :type => :rvalue, :arity => 1) do |args|
+ newfunction(:shell_exports, :type => :rvalue, :arity => 1) do |args|
vars, uppercase_keys = args
fail(ArgumentError, 'validate_ensure(): hash argument required') unless
vars.is_a?(Hash)
vars = Hash[vars.map { |k, v| [k.upcase, v] }] unless uppercase_keys ==
false
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb
index 6143766..e12ced2 100644
--- a/puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/ssl_ciphersuite.rb
@@ -64,13 +64,12 @@
module Puppet::Parser::Functions
# Basic list chunks, used to construct bigger lists
# General preference ordering for fullest combined list:
- # 0) Enc: 3DES < ALL (SWEET32)
# 1) Kx: (EC)DHE > RSA (Forward Secrecy)
# 2) Mac: AEAD > ALL (AES-GCM/CHAPOLY > Others)
- # 3) Enc: CHAPOLY > AESGCM (Old client perf, sec)
- # 4) Kx: ECDHE > DHE (Perf, mostly)
- # 5) Enc: AES256 > AES128 (sec)
- # 6) Auth: ECDSA > RSA (Perf, mostly)
+ # 3) Auth: ECDSA > RSA (Perf, mostly)
+ # 4) Enc: CHAPOLY > AESGCM (Old client perf, sec)
+ # 5) Enc: AES256 > AES128 (sec, batch attacks?)
+ # 6) Kx: ECDHE > DHE (Perf, mostly)
#
# After all of that, the fullest list of reasonably-acceptable mid/compat
# ciphers has been filtered further to reduce pointless clutter:
@@ -81,21 +80,24 @@
# AES256 performance differentials. SHA-2 HMAC variants were filtered
# similarly, as all clients that would negotiate x-SHA256 also negotiate
x-SHA
# and there's no effective security difference between the two.
- # *) The 'compat' list has been reduced to just the two weakest and
- # most-popular reasonable options there. The others were mostly
statistically
- # insignificant, and things are so bad at this level it's not worth worrying
- # about slight cipher strength gains.
+ # *) The 'compat' list has been reduced to just AES128-SHA after the removal
+ # of 3DES in Nov 2017. There are other possible entries here (AES256 and/or
+ # GCM), but in practice very few clients ever negotiate them anyways. All
+ # such clients fall back to AES128-SHA, and things are so bad at this level
+ # it's not worth worrying about slight cipher strength gains.
basic = {
# Forward-Secret + AEAD
'strong' => [
'-ALL',
- 'ECDHE-ECDSA-CHACHA20-POLY1305', # openssl-1.1.0, 1.0.2+cloudflare
- 'ECDHE-RSA-CHACHA20-POLY1305', # openssl-1.1.0, 1.0.2+cloudflare
+ 'TLS13-CHACHA20-POLY1305-SHA256',
+ 'TLS13-AES-256-GCM-SHA384',
+ 'TLS13-AES-128-GCM-SHA256',
+ 'ECDHE-ECDSA-CHACHA20-POLY1305',
'ECDHE-ECDSA-AES256-GCM-SHA384',
- 'ECDHE-RSA-AES256-GCM-SHA384',
'ECDHE-ECDSA-AES128-GCM-SHA256',
+ 'ECDHE-RSA-CHACHA20-POLY1305',
+ 'ECDHE-RSA-AES256-GCM-SHA384',
'ECDHE-RSA-AES128-GCM-SHA256',
- 'DHE-RSA-AES128-GCM-SHA256',
],
# Forward-Secret, but not AEAD
'mid' => [
@@ -106,7 +108,6 @@
# not-forward-secret compat for ancient stuff
'compat' => [
'AES128-SHA', # Mostly evil proxies, also ancient devices
- 'DES-CBC3-SHA', # Mostly IE7-8 on XP, also ancient devices
],
}
@@ -118,7 +119,7 @@
}
# Our standard HSTS for all public canonical domains
- hsts_val = "max-age=31536000; includeSubDomains; preload"
+ hsts_val = "max-age=106384710; includeSubDomains; preload"
newfunction(
:ssl_ciphersuite,
@@ -163,8 +164,10 @@
# OS / Server -dependant feature flags:
nginx_always_ok = true
dhe_ok = true
+ libssl_has_x25519 = true
if !function_os_version(['debian >= jessie'])
nginx_always_ok = false
+ libssl_has_x25519 = false
if server == 'apache'
dhe_ok = false
end
@@ -192,6 +195,7 @@
output.push('SSLProtocol all -SSLv2 -SSLv3')
end
output.push("SSLCipherSuite #{cipherlist}")
+ # Note: missing config to restrict ECDH curves
output.push('SSLHonorCipherOrder On')
if dhe_ok
output.push('SSLOpenSSLConfCmd DHParameters "/etc/ssl/dhparam.pem"')
@@ -206,6 +210,11 @@
output.push('ssl_protocols TLSv1 TLSv1.1 TLSv1.2;')
end
output.push("ssl_ciphers #{cipherlist};")
+ if libssl_has_x25519
+ output.push("ssl_ecdh_curve X25519:prime256v1;")
+ else
+ output.push("ssl_ecdh_curve prime256v1;")
+ end
output.push('ssl_prefer_server_ciphers on;')
if dhe_ok
output.push('ssl_dhparam /etc/ssl/dhparam.pem;')
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/systemd_template.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/systemd_template.rb
new file mode 100644
index 0000000..4d5b27a
--- /dev/null
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/systemd_template.rb
@@ -0,0 +1,15 @@
+# == Function: systemd_template
+#
+# Loads a template from a predefined location, and returns its contents.
+#
+# Based on the value of the only mandatory argument, the template path will be
+# determined as follows:
+#
+# ${module_name}/initscripts/${arg}.systemd.erb
+#
+module Puppet::Parser::Functions
+ newfunction(:systemd_template, :type => :rvalue, :arity => 1) do |args|
+ args << 'systemd'
+ function_init_template(args)
+ end
+end
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb
new file mode 100644
index 0000000..4200316
--- /dev/null
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb
@@ -0,0 +1,15 @@
+# == Function: sysvinit_template
+#
+# Loads a template from a predefined location, and returns its contents.
+#
+# Based on the value of the only mandatory argument, the template path will be
+# determined as follows:
+#
+# ${module_name}/initscripts/${arg}.sysvinit.erb
+#
+module Puppet::Parser::Functions
+ newfunction(:sysvinit_template, :type => :rvalue, :arity => 1) do |args|
+ args << 'sysvinit'
+ function_init_template(args)
+ end
+end
diff --git
a/puppet/modules/wmflib/lib/puppet/parser/functions/upstart_template.rb
b/puppet/modules/wmflib/lib/puppet/parser/functions/upstart_template.rb
new file mode 100644
index 0000000..4a2bf81
--- /dev/null
+++ b/puppet/modules/wmflib/lib/puppet/parser/functions/upstart_template.rb
@@ -0,0 +1,15 @@
+# == Function: upstart_template
+#
+# Loads a template from a predefined location, and returns its contents.
+#
+# Based on the value of the only mandatory argument, the template path will be
+# determined as follows:
+#
+# ${module_name}/initscripts/${arg}.upstart.erb
+#
+module Puppet::Parser::Functions
+ newfunction(:upstart_template, :type => :rvalue, :arity => 1) do |args|
+ args << 'upstart'
+ function_init_template(args)
+ end
+end
diff --git
a/puppet/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
b/puppet/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
new file mode 100644
index 0000000..55d5dd1
--- /dev/null
+++
b/puppet/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
@@ -0,0 +1 @@
+This is a test!
diff --git a/puppet/modules/wmflib/spec/functions/conftool_spec.rb
b/puppet/modules/wmflib/spec/functions/conftool_spec.rb
index 888c51b..c6a660c 100644
--- a/puppet/modules/wmflib/spec/functions/conftool_spec.rb
+++ b/puppet/modules/wmflib/spec/functions/conftool_spec.rb
@@ -3,7 +3,6 @@
require 'json'
describe 'conftool' do
-
def gen_conftool_call(selector)
['/usr/bin/conftool', '--object-type', 'node', 'select', selector, 'get']
end
diff --git a/puppet/modules/wmflib/spec/functions/ensure_mounted_spec.rb
b/puppet/modules/wmflib/spec/functions/ensure_mounted_spec.rb
index 0923893..72da1f4 100644
--- a/puppet/modules/wmflib/spec/functions/ensure_mounted_spec.rb
+++ b/puppet/modules/wmflib/spec/functions/ensure_mounted_spec.rb
@@ -32,5 +32,4 @@
it "should return 'false' for param 'false'" do
expect(scope.function_ensure_mounted([false])).to eq(false)
end
-
end
diff --git a/puppet/modules/wmflib/spec/functions/init_template_spec.rb
b/puppet/modules/wmflib/spec/functions/init_template_spec.rb
new file mode 100755
index 0000000..1d5b5e3
--- /dev/null
+++ b/puppet/modules/wmflib/spec/functions/init_template_spec.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe 'init_template' do
+ before(:each) { scope.expects(:lookupvar).with('module_name').returns('foo')
}
+
+ it 'correctly renders the template' do
+ is_expected.to run.with_params('fooservice', 'systemd').and_return("This
is a test!\n")
+ end
+end
diff --git a/puppet/modules/wmflib/spec/functions/ipresolve_spec.rb
b/puppet/modules/wmflib/spec/functions/ipresolve_spec.rb
index 070dc01..d9ea833 100644
--- a/puppet/modules/wmflib/spec/functions/ipresolve_spec.rb
+++ b/puppet/modules/wmflib/spec/functions/ipresolve_spec.rb
@@ -1,20 +1,20 @@
require 'spec_helper'
-describe 'ipresolve' do
+describe 'ipresolve' do
it "should resolve ipv4 addresses by default" do
- should
run.with_params('install1002.wikimedia.org').and_return('208.80.154.86')
+ should
run.with_params('install1002.wikimedia.org').and_return('208.80.154.22')
end
it "should resolve ipv4 addresses when explicitly asked to" do
- should run.with_params('install1002.wikimedia.org',
'4').and_return('208.80.154.86')
+ should run.with_params('install1002.wikimedia.org',
'4').and_return('208.80.154.22')
end
it "should resolve ipv6 addresses" do
- should run.with_params('install1002.wikimedia.org',
'6').and_return('2620::861:1:208:80:154:86')
+ should run.with_params('install1002.wikimedia.org',
'6').and_return('2620:0:861:1:208:80:154:22')
end
it "should be able to perform a reverse DNS lookup" do
- should run.with_params('2620::861:1:208:80:154:86',
'ptr').and_return('install1002.wikimedia.org')
- should run.with_params('208.80.154.86',
'ptr').and_return('install1002.wikimedia.org')
+ should run.with_params('2620:0:861:1:208:80:154:22',
'ptr').and_return('install1002.wikimedia.org')
+ should run.with_params('208.80.154.22',
'ptr').and_return('install1002.wikimedia.org')
end
it "fails when resolving an inexistent name" do
diff --git a/puppet/modules/wmflib/spec/functions/os_version_spec.rb
b/puppet/modules/wmflib/spec/functions/os_version_spec.rb
new file mode 100644
index 0000000..f422356
--- /dev/null
+++ b/puppet/modules/wmflib/spec/functions/os_version_spec.rb
@@ -0,0 +1,55 @@
+require 'spec_helper'
+
+describe 'os_version' do
+ it 'should be defined' do
+ expect(subject).to_not be_nil
+ end
+
+ context 'when invoked with no arguments' do
+ it 'raises an error' do
+ expect(subject).to run.with_params.and_raise_error(ArgumentError)
+ end
+ end
+
+ context 'when running on Ubuntu Trusty 14.04' do
+ let(:facts) do
+ {
+ :lsbdistrelease => '14.04',
+ :lsbdistid => 'Ubuntu',
+ }
+ end
+
+ it 'matches properly' do
+ expect(subject).to run.with_params('Ubuntu == trusty').and_return(true)
+ expect(subject).to run.with_params('Ubuntu >= trusty').and_return(true)
+ expect(subject).to run.with_params('Ubuntu <= trusty').and_return(true)
+ expect(subject).to run.with_params('Ubuntu > trusty').and_return(false)
+ expect(subject).to run.with_params('Ubuntu < trusty').and_return(false)
+ end
+ end
+
+ context 'when running on Debian Jessie 8' do
+ let(:facts) do
+ {
+ :lsbdistrelease => '8.7',
+ :lsbdistid => 'Debian',
+ }
+ end
+
+ it 'matches comparing current release' do
+ expect(subject).to run.with_params('Debian == jessie').and_return(true)
+ expect(subject).to run.with_params('Debian >= jessie').and_return(true)
+ expect(subject).to run.with_params('Debian <= jessie').and_return(true)
+ expect(subject).to run.with_params('Debian > jessie').and_return(false)
+ expect(subject).to run.with_params('Debian < jessie').and_return(false)
+ end
+
+ it 'matches comparing with next release' do
+ expect(subject).to run.with_params('Debian == stretch').and_return(false)
+ expect(subject).to run.with_params('Debian >= stretch').and_return(false)
+ expect(subject).to run.with_params('Debian <= stretch').and_return(true)
+ expect(subject).to run.with_params('Debian > stretch').and_return(false)
+ expect(subject).to run.with_params('Debian < stretch').and_return(true)
+ end
+ end
+end
diff --git a/puppet/modules/wmflib/spec/functions/role_spec.rb
b/puppet/modules/wmflib/spec/functions/role_spec.rb
index fd9a3b5..0f8c4dc 100644
--- a/puppet/modules/wmflib/spec/functions/role_spec.rb
+++ b/puppet/modules/wmflib/spec/functions/role_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
describe 'role' do
-
before :each do
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
@scope = Puppet::Parser::Scope.new(@compiler)
@@ -29,7 +28,7 @@
end
it "includes the role class" do
- expect { @scope.function_role(['test']) }.to_not raise_error()
+ expect { @scope.function_role(['test']) }.to_not raise_error
end
it "raises an error when called more than once in a scope" do
diff --git a/puppet/modules/wmflib/spec/hiera/proxy_backend_spec.rb
b/puppet/modules/wmflib/spec/hiera/proxy_backend_spec.rb
index 9b0574e..4523158 100644
--- a/puppet/modules/wmflib/spec/hiera/proxy_backend_spec.rb
+++ b/puppet/modules/wmflib/spec/hiera/proxy_backend_spec.rb
@@ -7,7 +7,7 @@
# Build a node with two roles applied
@hiera = Hiera.new({:config => 'spec/fixtures/hiera.proxy.yaml'})
Hiera::Config.load('spec/fixtures/hiera.proxy.yaml')
- @backend = Hiera::Backend::Proxy_backend.new()
+ @backend = Hiera::Backend::Proxy_backend.new
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
@scope = Puppet::Parser::Scope.new(@compiler)
@scope.source = Puppet::Resource::Type.new(:node, :foo)
@@ -26,27 +26,26 @@
it "lookup returns the default when no role is defined" do
expect(
- @backend.lookup('mysql::innodb_threads',@topscope, nil, nil)
+ @backend.lookup('mysql::innodb_threads', @topscope, nil, nil)
).to eq(15)
end
it "lookup returns the role-specific value if a role is defined" do
@scope.function_role(['test'])
expect(
- @backend.lookup('mysql::innodb_threads',@topscope, nil, nil)
+ @backend.lookup('mysql::innodb_threads', @topscope, nil, nil)
).to eq(50)
end
it "return the host-overridden value for a role-defined variable" do
@scope.function_role(['test'])
expect(
- @backend.lookup('admin::groups',@topscope, nil, nil)
+ @backend.lookup('admin::groups', @topscope, nil, nil)
).to eq(['go-spurs'])
end
it "merges values when using an array lookup" do
@scope.function_role(['test'])
- expect(@backend.lookup('admin::groups', @topscope, nil, :array)).to
eq([['go-spurs'],['FooBar']])
+ expect(@backend.lookup('admin::groups', @topscope, nil, :array)).to
eq([['go-spurs'], ['FooBar']])
end
-
end
diff --git a/puppet/modules/wmflib/spec/hiera/role_backend_spec.rb
b/puppet/modules/wmflib/spec/hiera/role_backend_spec.rb
index 19c436a..c8972ee 100644
--- a/puppet/modules/wmflib/spec/hiera/role_backend_spec.rb
+++ b/puppet/modules/wmflib/spec/hiera/role_backend_spec.rb
@@ -4,10 +4,9 @@
describe 'role_backend' do
before :each do
-
@hiera = Hiera.new({:config => 'spec/fixtures/hiera.yaml'})
Hiera::Config.load('spec/fixtures/hiera.yaml')
- @backend = Hiera::Backend::Role_backend.new()
+ @backend = Hiera::Backend::Role_backend.new
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
@scope = Puppet::Parser::Scope.new(@compiler)
@scope.source = Puppet::Resource::Type.new(:node, :foo)
@@ -43,11 +42,11 @@
it "merges values when using an array lookup" do
@scope.function_role(['test', 'test2'])
- expect(@backend.lookup('admin::groups', @topscope, nil, :array)).to
eq([['FooBar'],['FooBar1']])
+ expect(@backend.lookup('admin::groups', @topscope, nil, :array)).to
eq([['FooBar'], ['FooBar1']])
end
it "merges values when using hash lookup" do
@scope.function_role(['test', 'test2'])
- expect(@backend.lookup('an_hash', @topscope, nil, :hash)).to
eq({"test2"=>true, "test3"=>{"another"=>"level"}, "test"=>true})
+ expect(@backend.lookup('an_hash', @topscope, nil, :hash)).to eq({"test2"
=> true, "test3" => {"another" => "level"}, "test" => true})
end
end
--
To view, visit https://gerrit.wikimedia.org/r/393494
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1d0fd5be73fccb606a699abefc2dfd101aacee32
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: stretch-migration
Gerrit-Owner: BryanDavis <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Dduvall <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits