Skip to content

Commit

Permalink
Merge pull request #444 from l-lotz/puppet6
Browse files Browse the repository at this point in the history
Puppet 6 support
  • Loading branch information
bastelfreak authored Oct 17, 2018
2 parents 6b9955e + 3ced1da commit 139a3b7
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 146 deletions.
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ matrix:
- rvm: 2.5.1
env: PUPPET_VERSION="~> 5.0" CHECK=test
bundler_args: --without development
- rvm: 2.5.1
env: PUPPET_VERSION="~> 6.0" CHECK=test
bundler_args: --without development
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=debian8-64{hypervisor=docker} CHECK=beaker
Expand Down Expand Up @@ -51,3 +54,38 @@ matrix:
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=centos6-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=debian8-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=debian9-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=ubuntu1404-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=ubuntu1604-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=ubuntu1804-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=centos7-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
- rvm: 2.5.1
dist: trusty
env: BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_setfile=centos6-64{hypervisor=docker} CHECK=beaker
services: docker
sudo: required
Original file line number Diff line number Diff line change
Expand Up @@ -90,70 +90,63 @@ def simple_generate(obj)

end # end module


module Puppet::Parser::Functions
newfunction(:consul_sorted_json, :type => :rvalue, :doc => <<-EOS
This function takes unsorted hash and outputs JSON object making sure the keys are sorted.
Optionally you can pass 2 additional parameters, pretty generate and indent length.
*Examples:*
-------------------
-- UNSORTED HASH --
-------------------
unsorted_hash = {
'client_addr' => '127.0.0.1',
'bind_addr' => '192.168.34.56',
'start_join' => [
'192.168.34.60',
'192.168.34.61',
'192.168.34.62',
],
'ports' => {
'rpc' => 8567,
'https' => 8500,
'http' => -1,
},
}
-----------------
-- SORTED JSON --
-----------------
consul_sorted_json(unsorted_hash)
{"bind_addr":"192.168.34.56","client_addr":"127.0.0.1",
"ports":{"http":-1,"https":8500,"rpc":8567},
"start_join":["192.168.34.60","192.168.34.61","192.168.34.62"]}
------------------------
-- PRETTY SORTED JSON --
------------------------
Params: data <hash>, pretty <true|false>, indent <int>.
consul_sorted_json(unsorted_hash, true, 4)
{
"bind_addr": "192.168.34.56",
"client_addr": "127.0.0.1",
"ports": {
"http": -1,
"https": 8500,
"rpc": 8567
},
"start_join": [
"192.168.34.60",
"192.168.34.61",
"192.168.34.62"
]
}
EOS
) do |args|

unsorted_hash = args[0] || {}
pretty = args[1] || false
indent_len = args[2].to_i || 4
Puppet::Functions.create_function(:'consul::sorted_json') do
# This function takes unsorted hash and outputs JSON object making sure the keys are sorted.
# Optionally you can pass 2 additional parameters, pretty generate and indent length.
#
# *Examples:*
#
# -------------------
# -- UNSORTED HASH --
# -------------------
# unsorted_hash = {
# 'client_addr' => '127.0.0.1',
# 'bind_addr' => '192.168.34.56',
# 'start_join' => [
# '192.168.34.60',
# '192.168.34.61',
# '192.168.34.62',
# ],
# 'ports' => {
# 'rpc' => 8567,
# 'https' => 8500,
# 'http' => -1,
# },
# }
#
# -----------------
# -- SORTED JSON --
# -----------------
#
# consul::sorted_json(unsorted_hash)
#
# {"bind_addr":"192.168.34.56","client_addr":"127.0.0.1",
# "ports":{"http":-1,"https":8500,"rpc":8567},
# "start_join":["192.168.34.60","192.168.34.61","192.168.34.62"]}
#
# ------------------------
# -- PRETTY SORTED JSON --
# ------------------------
# Params: data <hash>, pretty <true|false>, indent <int>.
#
# consul::sorted_json(unsorted_hash, true, 4)
#
# {
# "bind_addr": "192.168.34.56",
# "client_addr": "127.0.0.1",
# "ports": {
# "http": -1,
# "https": 8500,
# "rpc": 8567
# },
# "start_join": [
# "192.168.34.60",
# "192.168.34.61",
# "192.168.34.62"
# ]
# }
#
def sorted_json(unsorted_hash = {}, pretty = false, indent_len = 4)

if pretty
return JSON.sorted_pretty_generate(unsorted_hash, indent_len) << "\n"
Expand Down
45 changes: 45 additions & 0 deletions lib/puppet/functions/consul/validate_checks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Puppet::Functions.create_function(:'consul::validate_checks') do

local_types do
type 'HashOrArray = Variant[Hash,Array]'
end

dispatch :validate_checks do
param 'HashOrArray', :obj
end

def validate_checks(obj)
case obj
when Array
obj.each do |c|
validate_checks(c)
end
when Hash
if ( (obj.key?("http") || ( obj.key?("script") || obj.key?("args") ) || obj.key?("tcp")) && (! obj.key?("interval")) )
raise Puppet::ParseError.new('interval must be defined for tcp, http, and script checks')
end

if obj.key?("ttl")
if (obj.key?("http") || ( obj.key?("args") || obj.key?("script") ) || obj.key?("tcp") || obj.key?("interval"))
raise Puppet::ParseError.new('script, http, tcp, and interval must not be defined for ttl checks')
end
elsif obj.key?("http")
if (( obj.key?("args") || obj.key?("script") ) || obj.key?("tcp"))
raise Puppet::ParseError.new('script and tcp must not be defined for http checks')
end
elsif obj.key?("tcp")
if (obj.key?("http") || ( obj.key?("args") || obj.key?("script") ))
raise Puppet::ParseError.new('script and http must not be defined for tcp checks')
end
elsif ( obj.key?("args") || obj.key?("script") )
if (obj.key?("http") || obj.key?("tcp"))
raise Puppet::ParseError.new('http and tcp must not be defined for script checks')
end
else
raise Puppet::ParseError.new('One of ttl, script, tcp, or http must be defined.')
end
else
raise Puppet::ParseError.new("Unable to handle object of type <%s>" % obj.class.to_s)
end
end
end
55 changes: 0 additions & 55 deletions lib/puppet/parser/functions/consul_validate_checks.rb

This file was deleted.

4 changes: 2 additions & 2 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
check => delete_undef_values($basic_hash)
}

consul_validate_checks($check_hash[check])
consul::validate_checks($check_hash[check])

$escaped_id = regsubst($id,'\/','_','G')
File[$consul::config_dir]
Expand All @@ -96,7 +96,7 @@
owner => $consul::user_real,
group => $consul::group_real,
mode => $consul::config_mode,
content => consul_sorted_json($check_hash, $consul::pretty_config, $consul::pretty_config_indent),
content => consul::sorted_json($check_hash, $consul::pretty_config, $consul::pretty_config_indent),
} ~> Class['consul::reload_service']

}
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
owner => $::consul::user_real,
group => $::consul::group_real,
mode => $::consul::config_mode,
content => consul_sorted_json($config_hash, $::consul::pretty_config, $::consul::pretty_config_indent),
content => consul::sorted_json($config_hash, $::consul::pretty_config, $::consul::pretty_config_indent),
require => File[$::consul::config_dir],
}

Expand Down
4 changes: 2 additions & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
) {
include consul

consul_validate_checks($checks)
consul::validate_checks($checks)

if versioncmp($consul::version, '1.1.0') >= 0 {
$override_key = 'enable_tag_override'
Expand Down Expand Up @@ -75,7 +75,7 @@
owner => $consul::user_real,
group => $consul::group_real,
mode => $consul::config_mode,
content => consul_sorted_json($service_hash, $consul::pretty_config, $consul::pretty_config_indent),
content => consul::sorted_json($service_hash, $consul::pretty_config, $consul::pretty_config_indent),
require => File[$consul::config_dir],
} ~> Class['consul::reload_service']
}
2 changes: 1 addition & 1 deletion manifests/watch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
owner => $consul::user_real,
group => $consul::group_real,
mode => $consul::config_mode,
content => consul_sorted_json($watch_hash, $consul::pretty_config, $consul::pretty_config_indent),
content => consul::sorted_json($watch_hash, $consul::pretty_config, $consul::pretty_config_indent),
} ~> Class['consul::reload_service']

}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.7.1 < 6.0.0"
"version_requirement": ">= 4.7.1 < 7.0.0"
}
],
"dependencies": [
Expand Down
Loading

0 comments on commit 139a3b7

Please sign in to comment.