From 32b79ba82e51914dca22a4e95086abc097ce13b2 Mon Sep 17 00:00:00 2001 From: Kyrylo Galanov Date: Thu, 28 Jan 2016 15:59:11 +0200 Subject: [PATCH] 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 --- .../lib/puppet/type/sahara_cluster_template.rb | 14 ++++++++++++++ .../sahara_cluster_template/ruby_spec.rb | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/deployment/puppet/sahara_templates/lib/puppet/type/sahara_cluster_template.rb b/deployment/puppet/sahara_templates/lib/puppet/type/sahara_cluster_template.rb index 40fb4bfdab..9d9714b4f7 100644 --- a/deployment/puppet/sahara_templates/lib/puppet/type/sahara_cluster_template.rb +++ b/deployment/puppet/sahara_templates/lib/puppet/type/sahara_cluster_template.rb @@ -20,6 +20,20 @@ Puppet::Type.newtype(:sahara_cluster_template) do newproperty(:node_groups, :array_matching => :all) do desc 'The array of node groups for cluster' 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 newproperty(:hadoop_version) do diff --git a/deployment/puppet/sahara_templates/spec/unit/puppet/provider/sahara_cluster_template/ruby_spec.rb b/deployment/puppet/sahara_templates/spec/unit/puppet/provider/sahara_cluster_template/ruby_spec.rb index 6f3fb56a82..c491185c82 100644 --- a/deployment/puppet/sahara_templates/spec/unit/puppet/provider/sahara_cluster_template/ruby_spec.rb +++ b/deployment/puppet/sahara_templates/spec/unit/puppet/provider/sahara_cluster_template/ruby_spec.rb @@ -31,6 +31,18 @@ describe Puppet::Type.type(:sahara_cluster_template).provider(:ruby) do provider 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 [ OpenStruct.new( @@ -123,6 +135,10 @@ describe Puppet::Type.type(:sahara_cluster_template).provider(:ruby) do expect(provider.extract).to eq extracted_property_hash 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 provider.extract expect(provider.exists?).to eq true