Make Sahara cluster group type idempotent

Node groups parameter is an array with random element order.
Hence it requires custom implementation for comparison between existing
and expected states.

Change-Id: I016352003db9adbd183067aa0e7548c39c368723
Closes-bug: #1526882
This commit is contained in:
Kyrylo Galanov 2016-01-28 15:59:11 +02:00
parent 2e2ce2f328
commit 32b79ba82e
2 changed files with 30 additions and 0 deletions

View File

@ -20,6 +20,20 @@ Puppet::Type.newtype(:sahara_cluster_template) do
newproperty(:node_groups, :array_matching => :all) do newproperty(:node_groups, :array_matching => :all) do
desc 'The array of node groups for cluster' desc 'The array of node groups for cluster'
defaultto { fail 'node groups is required!' } defaultto { fail 'node groups is required!' }
def insync?(is)
return false unless is.count == should.count
should.sort_by! { |n| n["name"] }
is.sort_by! { |n| n["name"] }
should.zip(is).each do |should_node,is_node|
should_node.keys.each do |field|
unless (is_node.has_key?(field) && should_node[field].to_s == is_node[field].to_s)
return false
end
end
end
return true
end
end end
newproperty(:hadoop_version) do newproperty(:hadoop_version) do

View File

@ -31,6 +31,18 @@ describe Puppet::Type.type(:sahara_cluster_template).provider(:ruby) do
provider provider
end end
let (:groups_property) do
resource.property(:node_groups)
end
let (:is_groups) do
[{"volume_local_to_instance"=>false, "availability_zone"=>nil,"updated_at"=>nil, "node_group_template_id"=>"d79d30d8-fac3-42c4-b8ff-f4c4d2269563",
"volumes_per_node"=>0, "id"=>"218b2274-efbf-4c1c-a8cf-58727ec4697a", "security_groups"=>nil, "shares"=>nil, "node_configs"=>{}, "auto_security_group"=>true,
"volumes_availability_zone"=>nil, "volume_mount_prefix"=>"/volumes/disk", "floating_ip_pool"=>"4dd3f47d-c85a-4649-b679-35ba2904fd0f", "image_id"=>nil,
"volumes_size"=>0, "is_proxy_gateway"=>false, "count"=>1, "name"=>"hdp-2-master", "created_at"=>"2016-02-07T21:47:29", "volume_type"=>nil,
"node_processes"=>["namenode", "resourcemanager", "oozie", "historyserver"], "flavor_id"=>"3", "use_autoconfig"=>true}]
end
let(:cluster_templates_list) do let(:cluster_templates_list) do
[ [
OpenStruct.new( OpenStruct.new(
@ -123,6 +135,10 @@ describe Puppet::Type.type(:sahara_cluster_template).provider(:ruby) do
expect(provider.extract).to eq extracted_property_hash expect(provider.extract).to eq extracted_property_hash
end end
it 'node_groups are in sync' do
expect(groups_property.insync?(is_groups)).to be_truthy
end
it 'can check if the cluster_template exists' do it 'can check if the cluster_template exists' do
provider.extract provider.extract
expect(provider.exists?).to eq true expect(provider.exists?).to eq true