jenkins-bot has submitted this change and it was merged. Change subject: service::node: Parse the configs when merging and update config ......................................................................
service::node: Parse the configs when merging and update config The merge_config parser function used to just take the two config strings and concatenate them. However, that creates problems when there are duplicate keys (when the service wants to override a setting). Therefore, the configs need to be parsed and merged as hashes. As of v0.3.2, services based on service-template-node need extra config settings that point to the MW and REST API endpoints. This commit adds them. Also, clean up the config for the mobilecontentservice module. Change-Id: Ifad5b3f772e6402e3b2eec533926324410cae53a --- M puppet/modules/mobilecontentservice/manifests/init.pp D puppet/modules/mobilecontentservice/templates/config.yaml.erb M puppet/modules/restbase/templates/config.yaml.erb M puppet/modules/service/lib/puppet/parser/functions/merge_config.rb M puppet/modules/service/templates/node/config.yaml.erb 5 files changed, 30 insertions(+), 27 deletions(-) Approvals: BryanDavis: Looks good to me, approved BearND: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/puppet/modules/mobilecontentservice/manifests/init.pp b/puppet/modules/mobilecontentservice/manifests/init.pp index 0f78fa5..dbff5c2 100644 --- a/puppet/modules/mobilecontentservice/manifests/init.pp +++ b/puppet/modules/mobilecontentservice/manifests/init.pp @@ -21,9 +21,6 @@ service::node { 'mobileapps': port => $port, log_level => $log_level, - config => { - restbase_uri => "localhost:${::restbase::port}", - }, } } diff --git a/puppet/modules/mobilecontentservice/templates/config.yaml.erb b/puppet/modules/mobilecontentservice/templates/config.yaml.erb deleted file mode 100644 index 41e1ab6..0000000 --- a/puppet/modules/mobilecontentservice/templates/config.yaml.erb +++ /dev/null @@ -1,9 +0,0 @@ -restbase_req: - uri: http://localhost:<%= scope.lookupvar('restbase::port') %>/{domain}/v1/page/html/{title} - headers: - user-agent: WMF Mobile Content Service MW-Vagrant -mwapi_req: - method: post - uri: http://{domain}/w/api.php - headers: - user-agent: WMF Mobile Content Service MW-Vagrant diff --git a/puppet/modules/restbase/templates/config.yaml.erb b/puppet/modules/restbase/templates/config.yaml.erb index 482671c..c5b7417 100644 --- a/puppet/modules/restbase/templates/config.yaml.erb +++ b/puppet/modules/restbase/templates/config.yaml.erb @@ -26,7 +26,7 @@ uri: http://localhost:<%= @eventlogging_service_port %>/v1/events topic: resource_change -wikimedia.org: &wikimedia.org +wikimedia.org: &wikimedia x-modules: - path: projects/wikimedia.org.yaml options: @@ -50,7 +50,7 @@ /{domain:<%= @domain %>}: *default_project # global domain - /{domain:wikimedia.org}: *wikimedia.org + /{domain:wikimedia.org}: *wikimedia salt: secret default_page_size: 100 diff --git a/puppet/modules/service/lib/puppet/parser/functions/merge_config.rb b/puppet/modules/service/lib/puppet/parser/functions/merge_config.rb index 3f51db7..df4d280 100644 --- a/puppet/modules/service/lib/puppet/parser/functions/merge_config.rb +++ b/puppet/modules/service/lib/puppet/parser/functions/merge_config.rb @@ -5,21 +5,19 @@ # configuration hash. # +def config_to_hash(conf) + return YAML.load(conf) unless conf.is_a?(Hash) + conf +end + module Puppet::Parser::Functions newfunction(:merge_config, type: :rvalue, arity: 2) do |args| - main_conf, service_conf = *args.map do |conf| - case conf - when Hash - conf.empty? ? '' : function_ordered_yaml([conf]) - when String - conf - else - '' - end + main_conf, service_conf = *args.map { |arg| config_to_hash(arg) } + begin + main_conf['services'][0]['conf'].update service_conf + rescue + fail('Badly formatted configuration.') end - main_conf += service_conf.split("\n").map do |line| - line.empty? ? '' : ' ' + line - end.join("\n") - main_conf + function_ordered_yaml([main_conf]) end end diff --git a/puppet/modules/service/templates/node/config.yaml.erb b/puppet/modules/service/templates/node/config.yaml.erb index 4dbaba5..f23792c 100644 --- a/puppet/modules/service/templates/node/config.yaml.erb +++ b/puppet/modules/service/templates/node/config.yaml.erb @@ -42,3 +42,20 @@ # cors: restricted.domain.org # URL of the outbound proxy to use (complete with protocol) # proxy: + # the UserAgent header to send when making requests + user_agent: <%= @title %>/MW-Vagrant + # the template used for contacting the MW API + mwapi_req: + method: post + uri: http://{domain}/w/api.php + headers: + host: '{{request.params.domain}}' + user-agent: '{{user-agent}}' + body: '{{ default(request.query, {}) }}' + # the template used for contacting RESTBase + restbase_req: + method: '{{request.method}}' + uri: http://localhost:<%= scope.lookupvar('restbase::port') %>/{{domain}}/v1/{+path} + query: '{{ default(request.query, {}) }}' + headers: '{{request.headers}}' + body: '{{request.body}}' -- To view, visit https://gerrit.wikimedia.org/r/300522 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifad5b3f772e6402e3b2eec533926324410cae53a Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/vagrant Gerrit-Branch: master Gerrit-Owner: Mobrovac <mobro...@wikimedia.org> Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits