Faidon Liambotis has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/403700 )
Change subject: wmflib/hiera: wrap long lines
......................................................................
wmflib/hiera: wrap long lines
Therefore allowing us to reduce Metrics/LineLength from 159 to 144 (due
to long lines in other parts of the tree).
Change-Id: If8db5728a76b5a5cb0b54288a176fe09bdcff03a
---
M .rubocop_todo.yml
M modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
M modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
M modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
M modules/wmflib/lib/hiera/backend/proxy_backend.rb
M modules/wmflib/lib/hiera/backend/role_backend.rb
M modules/wmflib/lib/hiera/httpcache.rb
M modules/wmflib/lib/hiera/mwcache.rb
M modules/wmflib/spec/hiera/role_backend_spec.rb
9 files changed, 73 insertions(+), 29 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/00/403700/1
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 9f6df5b..44dd0da 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,5 +1,5 @@
Metrics/LineLength:
- Max: 159
+ Max: 144
Style/BlockDelimiters:
Enabled: false
diff --git a/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
b/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
index 3106cf5..8e77d02 100644
--- a/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
@@ -15,7 +15,8 @@
# Small hack: We don't want to search any datasource but the
# httpyaml/%{::labsproject} hierarchy here; so we plainly exit
# in any other case.
- next unless source.start_with?('httpyaml/') && source.length >
'httpyaml/'.length
+ next unless source.start_with?('httpyaml/') &&
+ source.length > 'httpyaml/'.length
data = @cache.read(source)
@@ -25,11 +26,15 @@
new_answer = Backend.parse_answer(data[key], scope)
case resolution_type
when :array
- raise Exception, "Hiera type mismatch: expected Array and got
#{new_answer.class}" unless new_answer.kind_of?(Array) ||
new_answer.kind_of?(String)
+ unless new_answer.kind_of?(Array) || new_answer.kind_of?(String)
+ raise Exception, "Hiera mismatch: expected Array, got
#{new_answer.class}"
+ end
answer ||= []
answer << new_answer
when :hash
- raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
+ unless new_answer.kind_of? Hash
+ raise Exception, "Hiera mismatch: expected Hash, got
#{new_answer.class}"
+ end
answer ||= {}
answer = Backend.merge_answer(new_answer, answer)
else
diff --git a/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
b/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
index fd3aabb..b0e61f9 100644
--- a/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
@@ -15,7 +15,8 @@
# Small hack: We don't want to search any datasource but the
# labs/%{::labsproject} hierarchy here; so we plainly exit
# in any other case.
- next unless source.start_with?('labs/') && source.length >
'labs/'.length
+ next unless source.start_with?('labs/') &&
+ source.length > 'labs/'.length
# For hieradata/, the hierarchy is defined as
# "labs/%{::labsproject}/host/%{::hostname}" and
@@ -35,11 +36,15 @@
new_answer = Backend.parse_answer(data[key], scope)
case resolution_type
when :array
- raise Exception, "Hiera type mismatch: expected Array and got
#{new_answer.class}" unless new_answer.kind_of?(Array) ||
new_answer.kind_of?(String)
+ unless new_answer.kind_of?(Array) || new_answer.kind_of?(String)
+ raise Exception, "Hiera mismatch: expected Array, got
#{new_answer.class}"
+ end
answer ||= []
answer << new_answer
when :hash
- raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
+ unless new_answer.kind_of? Hash
+ raise Exception, "Hiera mismatch: expected Hash, got
#{new_answer.class}"
+ end
answer ||= {}
answer = Backend.merge_answer(new_answer, answer)
else
diff --git a/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
b/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
index 9dd48d2..dae4224 100644
--- a/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
@@ -187,11 +187,15 @@
case resolution_type
when :array
- raise Exception, "Hiera type mismatch: expected Array and got
#{new_answer.class}" unless new_answer.kind_of?(Array) ||
new_answer.kind_of?(String)
+ unless new_answer.kind_of?(Array) || new_answer.kind_of?(String)
+ raise Exception, "Hiera mismatch: expected Array, got
#{new_answer.class}"
+ end
answer ||= []
answer << new_answer
when :hash
- raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
+ unless new_answer.kind_of? Hash
+ raise Exception, "Hiera mismatch: expected Hash, got
#{new_answer.class}"
+ end
answer ||= {}
answer = Backend.merge_answer(new_answer, answer)
else
diff --git a/modules/wmflib/lib/hiera/backend/proxy_backend.rb
b/modules/wmflib/lib/hiera/backend/proxy_backend.rb
index d73fbb1..d2dfeec 100644
--- a/modules/wmflib/lib/hiera/backend/proxy_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/proxy_backend.rb
@@ -71,12 +71,16 @@
case resolution_type
when :array
- raise Exception, "Hiera type mismatch: expected Array and got
#{new_answer.class}" unless new_answer.kind_of? Array
+ unless new_answer.kind_of? Array
+ raise Exception, "Hiera mismatch: expected Array, got
#{new_answer.class}"
+ end
# The plugins already return an array of answers, so just
concatenate it.
answer ||= []
answer += new_answer
when :hash
- raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
+ unless new_answer.kind_of? Hash
+ raise Exception, "Hiera mismatch: expected Hash, got
#{new_answer.class}"
+ end
answer ||= {}
answer = Backend.merge_answer(new_answer, answer)
else
diff --git a/modules/wmflib/lib/hiera/backend/role_backend.rb
b/modules/wmflib/lib/hiera/backend/role_backend.rb
index 0ce9ed6..cedfe91 100644
--- a/modules/wmflib/lib/hiera/backend/role_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/role_backend.rb
@@ -101,11 +101,15 @@
def merge_answer(new_answer, answer, resolution_type)
case resolution_type
when :array
- raise Exception, "Hiera type mismatch: expected Array and got
#{new_answer.class}" unless new_answer.kind_of?(Array) ||
new_answer.kind_of?(String)
+ unless new_answer.kind_of?(Array) || new_answer.kind_of?(String)
+ raise Exception, "Hiera mismatch: expected Array, got
#{new_answer.class}"
+ end
answer ||= []
answer << new_answer
when :hash
- raise Exception, "Hiera type mismatch: expected Hash and got
#{new_answer.class}" unless new_answer.kind_of? Hash
+ unless new_answer.kind_of? Hash
+ raise Exception, "Hiera mismatch: expected Hash, got
#{new_answer.class}"
+ end
answer ||= {}
answer = Backend.merge_answer(new_answer, answer)
else
diff --git a/modules/wmflib/lib/hiera/httpcache.rb
b/modules/wmflib/lib/hiera/httpcache.rb
index 8849ee9..70ae6b5 100644
--- a/modules/wmflib/lib/hiera/httpcache.rb
+++ b/modules/wmflib/lib/hiera/httpcache.rb
@@ -9,8 +9,9 @@
@url_prefix = config[:url_prefix]
@http = HTTPClient.new(:agent_name => 'HieraHttpCache/0.1')
- # Use the operating system's certificate store, not ruby-httpclient's
cacert.p7s which doesn't
- # even have the root used to sign Let's Encrypt CAs (DST Root CA X3)
+ # Use the operating system's certificate store, not ruby-httpclient's
+ # cacert.p7s which doesn't even have the root used to sign Let's Encrypt
+ # CAs (DST Root CA X3)
@http.ssl_config.clear_cert_store
@http.ssl_config.set_default_paths
@@ -27,7 +28,8 @@
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
+ # When failing to read data, we raise an exception
+ # see https://phabricator.wikimedia.org/T78408
error = "Reading data from #{path} failed: #{detail.class}: #{detail}"
raise error
end
@@ -70,7 +72,8 @@
Hiera.debug("Fetching #{url}")
res = @http.get(url)
if res.status_code != 200
- raise IOError, "Could not correctly fetch revision for #{path}, HTTP
status code #{res.status_code}, content #{res.data}"
+ raise IOError, "Could not correctly fetch revision for #{path}, " +
+ "HTTP status code #{res.status_code}, content
#{res.data}"
end
# We shamelessly throw exceptions here, and catch them upper in the chain
# specifically in Hiera::Mwcache.stale? and Hiera::Mwcache.read
diff --git a/modules/wmflib/lib/hiera/mwcache.rb
b/modules/wmflib/lib/hiera/mwcache.rb
index e1acc6b..a8f058c 100644
--- a/modules/wmflib/lib/hiera/mwcache.rb
+++ b/modules/wmflib/lib/hiera/mwcache.rb
@@ -13,8 +13,9 @@
@endpoint = config[:endpoint] || '/w/api.php'
@http = HTTPClient.new(:agent_name => 'HieraMwCache/0.1')
- # Use the operating system's certificate store, not ruby-httpclient's
cacert.p7s which doesn't
- # even have the root used to sign Let's Encrypt CAs (DST Root CA X3)
+ # Use the operating system's certificate store, not ruby-httpclient's
+ # cacert.p7s which doesn't even have the root used to sign Let's Encrypt
+ # CAs (DST Root CA X3)
@http.ssl_config.clear_cert_store
@http.ssl_config.set_default_paths
@@ -31,11 +32,13 @@
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.
+ # Any errors other than this will cause hiera to raise an error and
+ # puppet to fail.
Hiera.debug("Page #{detail} is non-existent, setting defaults
#{default}")
@cache[path][:data] = default
rescue => detail
- # When failing to read data, we raise an exception, see
https://phabricator.wikimedia.org/T78408
+ # When failing to read data, we raise an exception
+ # see https://phabricator.wikimedia.org/T78408
error = "Reading data from #{path} failed: #{detail.class}: #{detail}"
raise error
end
@@ -48,7 +51,9 @@
@cache[path][:data] = block_given? ? yield(data) : data
if !@cache[path][:data].nil? &&
!@cache[path][:data].is_a?(expected_type)
- raise TypeError, "Data retrieved from #{path} is
#{@cache[path][:data].class}, not #{expected_type} or nil"
+ raise TypeError, "Data retrieved from #{path} is " +
+ "#{@cache[path][:data].class}, " +
+ "not #{expected_type} or nil"
end
end
@@ -105,7 +110,8 @@
Hiera.debug("Fetching #{url}")
res = @http.get(url)
if res.status_code != 200
- raise IOError, "Could not correctly fetch revision for #{path}, HTTP
status code #{res.status_code}"
+ raise IOError, "Could not correctly fetch revision for #{path}, " +
+ "HTTP status code #{res.status_code}"
end
# We shamelessly throw exceptions here, and catch them upper in the chain
# specifically in Hiera::Mwcache.stale? and Hiera::Mwcache.read
diff --git a/modules/wmflib/spec/hiera/role_backend_spec.rb
b/modules/wmflib/spec/hiera/role_backend_spec.rb
index c8972ee..00b7a02 100644
--- a/modules/wmflib/spec/hiera/role_backend_spec.rb
+++ b/modules/wmflib/spec/hiera/role_backend_spec.rb
@@ -23,30 +23,43 @@
end
it "get_path returns the correct path" do
- expect(@backend.get_path('pippo', 'test', 'common', @scope)).to
eq("spec/fixtures/hieradata/role/common/test.yaml")
+ path = @backend.get_path('pippo', 'test', 'common', @scope)
+ expect(path).to eq("spec/fixtures/hieradata/role/common/test.yaml")
end
it "lookup returns nil when no role is defined" do
- expect(@backend.lookup('admin::groups', @topscope, nil, nil)).to eq(nil)
+ groups = @backend.lookup('admin::groups', @topscope, nil, nil)
+ expect(groups).to eq(nil)
end
it "lookup returns a value when a role is defined" do
@scope.function_role(['test'])
- expect(@backend.lookup('admin::groups', @topscope, nil, nil)).to
eq(['FooBar'])
+ groups = @backend.lookup('admin::groups', @topscope, nil, nil)
+ expect(groups).to eq(['FooBar'])
end
it "lookup raises an error if conflicting values are given in different
roles" do
@scope.function_role(['test', 'test2'])
- expect {@backend.lookup('admin::groups', @topscope, nil, nil)}.to
raise_error(Exception, "Conflicting value for admin::groups found in role
test2")
+ groups = @backend.lookup('admin::groups', @topscope, nil, nil)
+ expect(groups).to raise_exception
end
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']])
+ groups = @backend.lookup('admin::groups', @topscope, nil, nil)
+ expect(groups).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})
+ an_hash = @backend.lookup('an_hash', @topscope, nil, :hash)
+ expected_hash = {
+ "test2" => true,
+ "test3" => {
+ "another" => "level"
+ },
+ "test" => true,
+ }
+ expect(an_hash).to eq(expected_hash)
end
end
--
To view, visit https://gerrit.wikimedia.org/r/403700
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If8db5728a76b5a5cb0b54288a176fe09bdcff03a
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Faidon Liambotis <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits