diff --git a/lib/puppet/type/cs_clone.rb b/lib/puppet/type/cs_clone.rb index 89e3fcc1..4e249709 100644 --- a/lib/puppet/type/cs_clone.rb +++ b/lib/puppet/type/cs_clone.rb @@ -77,10 +77,11 @@ autos end - [:cs_primitive, :cs_clone].each do |type| - autorequire(type) do - [unmunge_cs_primitive(@parameters[:primitive].value)] - end + autorequire(:cs_primitive) do + autos = [] + autos << unmunge_cs_primitive(should(:primitive)) if should(:primitive) + + autos end def unmunge_cs_primitive(name) diff --git a/spec/spec_helper_corosync.rb b/spec/spec_helper_corosync.rb index 4ef48a2d..81b3efe1 100644 --- a/spec/spec_helper_corosync.rb +++ b/spec/spec_helper_corosync.rb @@ -33,3 +33,50 @@ def pcs_load_cib(cib) Puppet::Util::Execution::ProcessOutput.new(cib, 0) ) end + +def create_cs_clone_resource(primitive) + cs_clone_class = Puppet::Type.type(:cs_clone) + cs_clone_class.new( + name: "#{primitive}_clone", + primitive: primitive + ) +end + +def create_cs_clone_resource_with_cib(primitive, cib) + cs_clone_class = Puppet::Type.type(:cs_clone) + cs_clone_class.new( + name: "#{primitive}_clone", + primitive: primitive, + cib: cib + ) +end + +def create_cs_primitive_resource(primitive) + cs_primitive_class = Puppet::Type.type(:cs_primitive) + cs_primitive_class.new( + name: primitive + ) +end + +def create_cs_shadow_resource(cib) + cs_shadow_class = Puppet::Type.type(:cs_shadow) + cs_shadow_class.new( + name: cib + ) +end + +def create_service_resource(name) + cs_shadow_class = Puppet::Type.type(:service) + cs_shadow_class.new( + name: name + ) +end + +def create_catalog(*resources) + catalog = Puppet::Resource::Catalog.new + resources.each do |resource| + catalog.add_resource resource + end + + catalog +end diff --git a/spec/unit/puppet/type/cs_clone_spec.rb b/spec/unit/puppet/type/cs_clone_spec.rb index 7a2775af..3abd1bc3 100644 --- a/spec/unit/puppet/type/cs_clone_spec.rb +++ b/spec/unit/puppet/type/cs_clone_spec.rb @@ -58,4 +58,99 @@ end end end + + describe 'establishing autorequires between clones and primitives' do + let(:apache_primitive) { create_cs_primitive_resource('apache') } + let(:apache_clone) { create_cs_clone_resource('apache') } + let(:mysql_primitive) { create_cs_primitive_resource('mysql') } + let(:mysql_clone) { create_cs_clone_resource('ms_mysql') } + let(:puppetcib_shadow) { create_cs_shadow_resource('puppetcib') } + let(:nginx_clone_in_puppetcib_cib) { create_cs_clone_resource_with_cib('nginx', 'puppetcib') } + + before do + create_catalog(apache_primitive, apache_clone, mysql_primitive, mysql_clone, puppetcib_shadow, nginx_clone_in_puppetcib_cib) + end + + context 'between a clone and its primitive' do + let(:autorequire_relationship) { apache_clone.autorequire[0] } + + it 'has exactly one autorequire' do + expect(apache_clone.autorequire.count).to eq(1) + end + + it 'has apache primitive as source of autorequire' do + expect(autorequire_relationship.source).to eq apache_primitive + end + it 'has apache clone as target of autorequire' do + expect(autorequire_relationship.target).to eq apache_clone + end + end + + context 'between a clone and its master/slave primitive' do + let(:autorequire_relationship) { mysql_clone.autorequire[0] } + + it 'has exactly one autorequire' do + expect(mysql_clone.autorequire.count).to eq(1) + end + + it 'has mysql primitive as source of autorequire' do + expect(autorequire_relationship.source).to eq mysql_primitive + end + + it 'has mysql clone as target of autorequire' do + expect(autorequire_relationship.target).to eq mysql_clone + end + end + + context 'between a clone and its shadow cib' do + let(:autorequire_relationship) { nginx_clone_in_puppetcib_cib.autorequire[0] } + + it 'has exactly one autorequire' do + expect(nginx_clone_in_puppetcib_cib.autorequire.count).to eq(1) + end + + it 'has puppetcib shadow cib as source of autorequire' do + expect(autorequire_relationship.source).to eq puppetcib_shadow + end + + it 'has nginx clone as target of autorequire' do + expect(autorequire_relationship.target).to eq nginx_clone_in_puppetcib_cib + end + end + end + + describe 'establishing autorequires between clone and services' do + let(:pacemaker_service) { create_service_resource('pacemaker') } + let(:corosync_service) { create_service_resource('corosync') } + let(:mysql_clone) { create_cs_clone_resource('mysql') } + + before do + create_catalog(pacemaker_service, corosync_service, mysql_clone) + end + + context 'between a clone and the services' do + let(:autorequire_first_relationship) { mysql_clone.autorequire[0] } + let(:autorequire_second_relationship) { mysql_clone.autorequire[1] } + + it 'has exactly 2 autorequire' do + expect(mysql_clone.autorequire.count).to eq(2) + end + + it 'has corosync service as source of first autorequire' do + expect(autorequire_first_relationship.source).to eq corosync_service + end + + it 'has mysql clone as target of first autorequire' do + expect(autorequire_first_relationship.target).to eq mysql_clone + end + + it 'has pacemaker service as source of second autorequire' do + expect(autorequire_second_relationship.source).to eq pacemaker_service + end + + it 'has mysql clone as target of second autorequire' do + expect(autorequire_second_relationship.target).to eq mysql_clone + end + end + end end