Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve (and test!) cs_clone autorequires #365

Merged
merged 1 commit into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/puppet/type/cs_clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename the autos to something more predictable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

end

def unmunge_cs_primitive(name)
Expand Down
47 changes: 47 additions & 0 deletions spec/spec_helper_corosync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
95 changes: 95 additions & 0 deletions spec/unit/puppet/type/cs_clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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