38 changes: 7 additions & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
language: ruby
matrix:
include:
# 2018.1.11
# 2019.8.5 (LTS)
- rvm: 2.5.8
env: PUPPET_VERSION=6.21.1
# 2019.1.3
- rvm: 2.5.7
env: PUPPET_VERSION=6.12.0
# 2018.1.18
- rvm: 2.4.9
env: PUPPET_VERSION=5.5.17
# 2017.3.1
- rvm: 2.4.1
env: PUPPET_VERSION=5.3.1
# 2017.2.4
- rvm: 2.1.9
env: PUPPET_VERSION=4.10.8
# 2017.1.0
- rvm: 2.1.9
env: PUPPET_VERSION=4.9.4
# 2016.5.2
- rvm: 2.1.9
env: PUPPET_VERSION=4.8.2
# 2016.4.7
- rvm: 2.1.9
env: PUPPET_VERSION=4.10.5
# 2016.2.1
- rvm: 2.1.9
env: PUPPET_VERSION=4.5.2
# 2016.1.2
- rvm: 2.1.9
env: PUPPET_VERSION=4.4.2
# 2015.3.3
- rvm: 2.1.8
env: PUPPET_VERSION=4.3.2
# 2015.2.3
- rvm: 2.1.7
env: PUPPET_VERSION=4.2.3
# 3.8.6
- rvm: 2.1.7
env: PUPPET_VERSION=3.8.6
# 3.7.1
- rvm: 2.1.7
env: PUPPET_VERSION=3.7.1
script:
- "bundle exec rake spec"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2021-03-21 - Release 0.7.5

### Summary

- Fix `purge_behavior` bug which prevented node group creation when using this parameter
- Validate user input for the `override_environment` parameter. This parameter must be boolean to be valid. Previously, no error was raised until the type was synced. Now, the input will be validated early. Note that boolean-coerced strings such as "true", "false" are permitted.
- Additional Gemfile cleanup
- LTS Travis testing updates

## 2021-01-12 - Release 0.7.4

### Summary
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ group :development do
gem "guard-rake"
end

source 'https://rubygems.org'

gem 'puppet', nil || ENV['PUPPET_VERSION']
gem 'puppetlabs_spec_helper'
gem 'webmock'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node_manager [![Build Status](https://travis-ci.org/WhatsARanjit/puppet-node_manager.svg?branch=master)](https://travis-ci.org/WhatsARanjit/puppet-node_manager)
# node_manager [![Build Status](https://app.travis-ci.com/WhatsARanjit/puppet-node_manager.svg?branch=master)](https://app.travis-ci.com/WhatsARanjit/puppet-node_manager)

#### Table of Contents

Expand Down Expand Up @@ -137,11 +137,11 @@ This parameter is supported for PE >=2017.3.x.

* `purge_behavior`

Defines how purging of classification or data will be handled. By default, or when set to `all`, the node\_group resource will ensure classes and data are matched exactly, and remove any values not described by the resource. When set to `none`, the node\_group resource will ensure data and classes described are present with the prescribed values, but will not remove other classification, or other data, present in the node group. The `data` setting purges only data values, and the `classes` setting purges only classes values.
Defines how purging of classification, data and rules will be handled. By default, or when set to `all`, the node\_group resource will ensure classes, data and rules are matched exactly, and remove any values not described by the resource. When set to `none`, the node\_group resource will ensure data, classes and rules described are present with the prescribed values, but will not remove other classification, or other data, present in the node group. The `data` setting purges only data values, the `classes` setting purges only classes values and the `rule` setting purges only rule values. In case of conflict with the node classifiers `Nodes must match all rules.` and `Nodes may match any rule.` radio buttons. The node classifier takes precedence over defined node_group code.

Default: `all`

Values: `all`, `data`, `classes`, `none`
Values: `all`, `data`, `classes`, `rule`, `none`

## Tasks

Expand Down
13 changes: 7 additions & 6 deletions lib/puppet/provider/node_group/https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ def create
@noflush = true
# Only passing parameters that are given
send_data = Hash.new
@resource.original_parameters.each do |k,v|
next if [:ensure, :provider].include? k
next if @resource.parameter(k).metaparam?
key = k.to_s
@resource.properties.each do |property|
next if [:ensure].include? property.name
key = property.to_s
# key changed for usability
key = 'environment_trumps' if key == 'override_environment'
key = 'config_data' if key == 'data'
send_data[key] = v
send_data[key] = property.value
end
# namevar may not be in this hash
send_data['name'] = @resource[:name] unless send_data['name']
# Passing an empty hash in the type results in undef
send_data['classes'] = {} unless send_data['classes']
# Ensure environment_trumps is a boolean
send_data['environment_trumps'] = Puppet::Coercion.boolean(send_data['environment_trumps']) if send_data['environment_trumps']

send_data['parent'] = '00000000-0000-4000-8000-000000000000' if !send_data['parent']
unless send_data['parent'] =~ /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/
Expand Down Expand Up @@ -209,7 +210,7 @@ def add_nulls(current, new)
_current = current.is_a?(Hash) ? current[k] : {}
newhash[k] = add_nulls(_current, new[k])
else
newhash[k] = new[k] || nil
newhash[k] = new[k]
end
end

Expand Down
83 changes: 80 additions & 3 deletions lib/puppet/type/node_group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppet_x/node_manager/common'
require 'puppet/property/boolean'

Puppet::Type.newtype(:node_group) do
desc 'The node_group type creates and manages node groups for the PE Node Manager'
Expand All @@ -8,7 +9,7 @@
end
newparam(:purge_behavior) do
desc 'Whether or not to remove data or class parameters not specified'
newvalues(:none, :data, :classes, :all)
newvalues(:none, :data, :classes, :rule, :all)
defaultto :all
end
newproperty(:id) do
Expand All @@ -17,9 +18,11 @@
fail("ID is read-only")
end
end
newproperty(:override_environment) do
newproperty(:override_environment, :boolean => true) do
desc 'Override parent environments'
newvalues(:false, :true)
munge do |value|
Puppet::Coercion.boolean(value).to_s.to_sym
end
end
newproperty(:parent) do
desc 'The ID of the parent group'
Expand All @@ -32,6 +35,80 @@
end
newproperty(:rule, :array_matching => :all) do
desc 'Match conditions for this group'
def should
case @resource[:purge_behavior]
when :rule, :all
super
else
a = @resource.property(:rule).retrieve || {}
b = shouldorig
aorig = a.map(&:clone)
atmp = a.map(&:clone)
# check if the node classifer has any rules defined before attempting merge.
if a.length >= 2
if a[0] == "or" and a[1][0] == "or" or a[1][0] == "and"
# Merging both rules and pinned nodes
if b[0] == "or" and b[1][0] == "or" or b[1][0] == "and"
# b has rules to merge
rules = (atmp[1] + b[1].drop(1)).uniq
atmp[1] = rules
pinned = (b[2,b.length] + atmp[2,atmp.length]).uniq
merged = (atmp + pinned).uniq
elsif b[0] == "and" or b[0] == "or" and PuppetX::Node_manager::Common.factcheck(b)
# b only has rules to merge
rules = (atmp[1] + b.drop(1)).uniq
atmp[1] = rules
merged = atmp
else
pinned = (b[1,b.length] + atmp[2,atmp.length]).uniq
merged = (atmp + pinned).uniq
end
elsif b[0] == "or" and b[1][0] == "or" or b[1][0] == "and"
# Merging both rules and pinned nodes
rules = b[1] # no rules to merge on a side
pinned = (b[2,b.length] + a[1,a.length]).uniq
merged = (b + pinned).uniq
elsif a[0] == "and" or a[0] == "or" and PuppetX::Node_manager::Common.factcheck(a)
# a only has fact rules
if b[0] == "or" and not PuppetX::Node_manager::Common.factcheck(b)
# b only has pinned nodes
rules = atmp
temp = ['or']
temp[1] = atmp
merged = (temp + b[1,b.length]).uniq
else
# b only has rules
merged = (a + b.drop(1)).uniq
end
elsif a[0] == "or" and a[1][1] == "name"
# a only has pinned nodes
if b[0] == "or" and not PuppetX::Node_manager::Common.factcheck(b)
# b only has pinned nodes
merged = (b + a.drop(1)).uniq
else
# b only has rules
temp = ['or']
temp[1] = b
merged = (temp + atmp[1,atmp.length]).uniq
end
else
# default fall back.
merged = (b + a.drop(1)).uniq
end
if merged == aorig
# values are the same, returning orginal value"
aorig
else
merged
end
else
b
end
end
end
def insync?(is)
is == should
end
end
newproperty(:environment) do
desc 'Environment for this group'
Expand Down
15 changes: 15 additions & 0 deletions lib/puppet_x/node_manager/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ def self.sort_hash(data)
end
newhash
end

# check for fact rules in deep array
def self.factcheck(rulecheck)
rulecheck.each_with_index {|x, i|
if x == "fact" and i == 0
return true
end
if x.kind_of?(Array)
if factcheck(x)
return true
end
end
}
false
end
end
7 changes: 3 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "WhatsARanjit-node_manager",
"version": "0.7.4",
"version": "0.7.5",
"author": "WhatsARanjit",
"summary": "Create and manage PE Console node groups as resources.",
"description": "Create and manage PE Console node groups as resources.",
"license": "Apache-2.0",
"source": "https://github.com/WhatsARanjit/puppet-node_manager",
"project_page": "https://github.com/WhatsARanjit/puppet-node_manager",
Expand Down Expand Up @@ -55,6 +55,5 @@
"name": "puppet",
"version_requirement": ">= 3.7.1 < 8.0.0"
}
],
"description": "Node_manager module"
]
}
8 changes: 4 additions & 4 deletions spec/integration/puppet/provider/node_group/https_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
EOS

HCREATE_REQUEST = {
"environment_trumps" => "false",
"environment_trumps" => false,
"parent" => "00000000-0000-4000-8000-000000000000",
"rule" => ["or", ["=", "name", "master.puppetlabs.vm"]],
"environment" => "stubenvironment",
"classes" => {"puppet_enterprise::profile::amq::broker" => {}},
"variables" => {
"stubkey" => "stubvalue",
"stubkey2" => "stubvalue2"
},
"rule" => ["or", ["=", "name", "master.puppetlabs.vm"]],
"environment" => "stubenvironment",
"classes" => {"puppet_enterprise::profile::amq::broker" => {}},
"description" => "Sample message",
"name" => "stub_name",
}.to_json
Expand Down
Loading