Giuseppe Lavagetto has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371452 )

Change subject: wmflib: add init_template functions
......................................................................

wmflib: add init_template functions

Since puppet scoping rules changed, we have to convert most of the
current base::systemd_unit defines, moving the evaluation of the
template within the calling resource. This set of helper functions will
auto-require the correct template and render it - it will find the
template in the same location as the code within base::service_unit did.

Bug: T173078
Change-Id: I4be9bda432d322ca728073b073d9cdafeffdc479
---
A modules/wmflib/lib/puppet/parser/functions/init_template.rb
A modules/wmflib/lib/puppet/parser/functions/systemd_template.rb
A modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb
A modules/wmflib/lib/puppet/parser/functions/upstart_template.rb
A 
modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
A modules/wmflib/spec/functions/init_template_spec.rb
6 files changed, 73 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/52/371452/1

diff --git a/modules/wmflib/lib/puppet/parser/functions/init_template.rb 
b/modules/wmflib/lib/puppet/parser/functions/init_template.rb
new file mode 100644
index 0000000..49f9f82
--- /dev/null
+++ b/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/modules/wmflib/lib/puppet/parser/functions/systemd_template.rb 
b/modules/wmflib/lib/puppet/parser/functions/systemd_template.rb
new file mode 100644
index 0000000..4d5b27a
--- /dev/null
+++ b/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/modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb 
b/modules/wmflib/lib/puppet/parser/functions/sysvinit_template.rb
new file mode 100644
index 0000000..4200316
--- /dev/null
+++ b/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/modules/wmflib/lib/puppet/parser/functions/upstart_template.rb 
b/modules/wmflib/lib/puppet/parser/functions/upstart_template.rb
new file mode 100644
index 0000000..4a2bf81
--- /dev/null
+++ b/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/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
 
b/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
new file mode 100644
index 0000000..55d5dd1
--- /dev/null
+++ 
b/modules/wmflib/spec/fixtures/modules/foo/templates/initscripts/fooservice.systemd.erb
@@ -0,0 +1 @@
+This is a test!
diff --git a/modules/wmflib/spec/functions/init_template_spec.rb 
b/modules/wmflib/spec/functions/init_template_spec.rb
new file mode 100755
index 0000000..1d5b5e3
--- /dev/null
+++ b/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

-- 
To view, visit https://gerrit.wikimedia.org/r/371452
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4be9bda432d322ca728073b073d9cdafeffdc479
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to