Merge pull request #51 from aspiers/order
refactoring and implement order LWRP
This commit is contained in:
commit
73edd77d1a
19
Guardfile
19
Guardfile
@ -7,9 +7,16 @@ guard_opts = {
|
|||||||
all_after_pass: true,
|
all_after_pass: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
def all_specs; 'spec' end
|
DEBUG = false
|
||||||
def library_specs; 'spec/libraries' end
|
|
||||||
def provider_specs; 'spec/providers' end
|
def reload(target)
|
||||||
|
puts "-> #{target}" if DEBUG
|
||||||
|
target
|
||||||
|
end
|
||||||
|
|
||||||
|
def all_specs; reload 'all_specs'; 'spec' end
|
||||||
|
def library_specs; reload 'library_specs'; 'spec/libraries' end
|
||||||
|
def provider_specs; reload 'provider_specs'; 'spec/providers' end
|
||||||
|
|
||||||
group :rspec do
|
group :rspec do
|
||||||
guard 'rspec', guard_opts do
|
guard 'rspec', guard_opts do
|
||||||
@ -20,14 +27,14 @@ group :rspec do
|
|||||||
watch(%r{^spec/fixtures/(.+)\.rb$}) { all_specs }
|
watch(%r{^spec/fixtures/(.+)\.rb$}) { all_specs }
|
||||||
watch(%r{^libraries/pacemaker\.rb$}) { all_specs }
|
watch(%r{^libraries/pacemaker\.rb$}) { all_specs }
|
||||||
watch(%r{^libraries/(.*mixin.*)\.rb$}) { library_specs }
|
watch(%r{^libraries/(.*mixin.*)\.rb$}) { library_specs }
|
||||||
watch(%r{^spec/.+_spec\.rb$})
|
watch(%r{^(spec/.+_spec\.rb)$}) { |m| reload m[1] }
|
||||||
watch(%r{^libraries/(.+)\.rb$}) { |m|
|
watch(%r{^libraries/(.+)\.rb$}) { |m|
|
||||||
"spec/libraries/#{m[1]}_spec.rb"
|
reload "spec/libraries/#{m[1]}_spec.rb"
|
||||||
}
|
}
|
||||||
watch(%r{^providers/common\.rb$}) { provider_specs }
|
watch(%r{^providers/common\.rb$}) { provider_specs }
|
||||||
watch(%r{^providers/(.*mixin.*)\.rb$}) { provider_specs }
|
watch(%r{^providers/(.*mixin.*)\.rb$}) { provider_specs }
|
||||||
watch(%r{^(?:resources|providers)/(.+)\.rb$}) { |m|
|
watch(%r{^(?:resources|providers)/(.+)\.rb$}) { |m|
|
||||||
"spec/providers/#{m[1]}_spec.rb"
|
reload "spec/providers/#{m[1]}_spec.rb"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
require File.expand_path('pacemaker/standard_cib_object.rb', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('pacemaker/runnable_resource.rb', File.dirname(__FILE__))
|
require File.expand_path('pacemaker/standard_cib_object.rb', this_dir)
|
||||||
|
require File.expand_path('pacemaker/runnable_resource.rb', this_dir)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
require 'chef/application'
|
require ::File.expand_path('standard_cib_object', File.dirname(__FILE__))
|
||||||
require ::File.expand_path('standard_cib_object', ::File.dirname(__FILE__))
|
|
||||||
|
|
||||||
# Common code used by Pacemaker LWRP providers for resources supporting
|
# Common code used by Pacemaker LWRP providers for resources supporting
|
||||||
# the :run action.
|
# the :run action.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
require 'chef/application'
|
|
||||||
require ::File.expand_path('../../../pacemaker/cib_object',
|
require ::File.expand_path('../../../pacemaker/cib_object',
|
||||||
::File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
# Common code used by Pacemaker LWRP providers
|
# Common code used by Pacemaker LWRP providers
|
||||||
|
|
||||||
|
31
libraries/pacemaker/constraint/order.rb
Normal file
31
libraries/pacemaker/constraint/order.rb
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
require File.expand_path('../constraint', File.dirname(__FILE__))
|
||||||
|
|
||||||
|
class Pacemaker::Constraint::Order < Pacemaker::Constraint
|
||||||
|
TYPE = 'order'
|
||||||
|
register_type TYPE
|
||||||
|
|
||||||
|
attr_accessor :score, :ordering
|
||||||
|
|
||||||
|
def self.attrs_to_copy_from_chef
|
||||||
|
%w(score ordering)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_definition
|
||||||
|
# FIXME: add support for symmetrical=<bool>
|
||||||
|
# Currently we take the easy way out and don't bother parsing the ordering.
|
||||||
|
# See the crm(8) man page for the official BNF grammar.
|
||||||
|
score_regexp = %r{\d+|[-+]?inf|Mandatory|Optional|Serialize}
|
||||||
|
unless definition =~ /^#{self.class::TYPE} (\S+) (#{score_regexp}): (.+?)\s*$/
|
||||||
|
raise Pacemaker::CIBObject::DefinitionParseError, \
|
||||||
|
"Couldn't parse definition '#{definition}'"
|
||||||
|
end
|
||||||
|
self.name = $1
|
||||||
|
self.score = $2
|
||||||
|
self.ordering = $3
|
||||||
|
end
|
||||||
|
|
||||||
|
def definition_string
|
||||||
|
"#{self.class::TYPE} #{name} #{score}: #{ordering}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,5 +1,6 @@
|
|||||||
require File.expand_path('../resource', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__))
|
require File.expand_path('../resource', this_dir)
|
||||||
|
require File.expand_path('../mixins/resource_meta', this_dir)
|
||||||
|
|
||||||
class Pacemaker::Resource::Clone < Pacemaker::Resource
|
class Pacemaker::Resource::Clone < Pacemaker::Resource
|
||||||
TYPE = 'clone'
|
TYPE = 'clone'
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require File.expand_path('../resource', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__))
|
require File.expand_path('../resource', this_dir)
|
||||||
|
require File.expand_path('../mixins/resource_meta', this_dir)
|
||||||
|
|
||||||
class Pacemaker::Resource::Group < Pacemaker::Resource
|
class Pacemaker::Resource::Group < Pacemaker::Resource
|
||||||
TYPE = 'group'
|
TYPE = 'group'
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require 'shellwords'
|
require 'shellwords'
|
||||||
require File.expand_path('../resource', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('../resource', this_dir)
|
||||||
|
require File.expand_path('../mixins/resource_meta', this_dir)
|
||||||
|
|
||||||
class Pacemaker::Resource::Primitive < Pacemaker::Resource
|
class Pacemaker::Resource::Primitive < Pacemaker::Resource
|
||||||
TYPE = 'primitive'
|
TYPE = 'primitive'
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
this_dir = ::File.dirname(__FILE__)
|
||||||
require ::File.expand_path('../libraries/chef/mixin/pacemaker',
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
include Chef::Mixin::Pacemaker::RunnableResource
|
include Chef::Mixin::Pacemaker::RunnableResource
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
this_dir = ::File.dirname(__FILE__)
|
||||||
require ::File.expand_path('../libraries/chef/mixin/pacemaker',
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
include Chef::Mixin::Pacemaker::StandardCIBObject
|
include Chef::Mixin::Pacemaker::StandardCIBObject
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
this_dir = ::File.dirname(__FILE__)
|
||||||
require ::File.expand_path('../libraries/chef/mixin/pacemaker',
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
include Chef::Mixin::Pacemaker::RunnableResource
|
include Chef::Mixin::Pacemaker::RunnableResource
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
this_dir = ::File.dirname(__FILE__)
|
||||||
require ::File.expand_path('../libraries/chef/mixin/pacemaker',
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
include Chef::Mixin::Pacemaker::StandardCIBObject
|
include Chef::Mixin::Pacemaker::StandardCIBObject
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
this_dir = ::File.dirname(__FILE__)
|
||||||
require ::File.expand_path('../libraries/chef/mixin/pacemaker',
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
include Chef::Mixin::Pacemaker::RunnableResource
|
include Chef::Mixin::Pacemaker::RunnableResource
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# Author:: Robert Choi
|
|
||||||
# Cookbook Name:: pacemaker
|
# Cookbook Name:: pacemaker
|
||||||
# Provider:: order
|
# Provider:: order
|
||||||
#
|
#
|
||||||
# Copyright:: 2013, Robert Choi
|
# Copyright:: 2013, Robert Choi
|
||||||
|
# Copyright:: 2014, SUSE
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -17,46 +17,57 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
this_dir = ::File.dirname(__FILE__)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/pacemaker/cib_object', this_dir)
|
||||||
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
|
include Chef::Mixin::Pacemaker::StandardCIBObject
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
priority = new_resource.priority
|
|
||||||
resources = new_resource.resources
|
|
||||||
|
|
||||||
unless resource_exists?(name)
|
if @current_resource_definition.nil?
|
||||||
cmd = "crm configure order #{name} #{priority}:"
|
create_resource(name)
|
||||||
resources.each do |rsc|
|
|
||||||
cmd << " #{rsc}"
|
|
||||||
end
|
|
||||||
|
|
||||||
cmd_ = Mixlib::ShellOut.new(cmd)
|
|
||||||
cmd_.environment['HOME'] = ENV.fetch('HOME', '/root')
|
|
||||||
cmd_.run_command
|
|
||||||
begin
|
|
||||||
cmd_.error!
|
|
||||||
if resource_exists?(name)
|
|
||||||
new_resource.updated_by_last_action(true)
|
|
||||||
Chef::Log.info "Successfully configured order '#{name}'."
|
|
||||||
else
|
else
|
||||||
Chef::Log.error "Failed to configure order #{name}."
|
maybe_modify_resource(name)
|
||||||
end
|
|
||||||
rescue
|
|
||||||
Chef::Log.error "Failed to configure order #{name}."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
action :delete do
|
action :delete do
|
||||||
name = new_resource.name
|
next unless @current_resource
|
||||||
cmd = "crm resource stop #{name}; crm configure delete #{name}"
|
standard_delete_resource
|
||||||
|
|
||||||
e = execute "delete order #{name}" do
|
|
||||||
command cmd
|
|
||||||
only_if { resource_exists?(name) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cib_object_class
|
||||||
|
::Pacemaker::Constraint::Order
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_current_resource
|
||||||
|
standard_load_current_resource
|
||||||
|
end
|
||||||
|
|
||||||
|
def init_current_resource
|
||||||
|
name = @new_resource.name
|
||||||
|
@current_resource = Chef::Resource::PacemakerOrder.new(name)
|
||||||
|
attrs = [:score, :ordering]
|
||||||
|
@current_cib_object.copy_attrs_to_chef_resource(@current_resource, *attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_resource(name)
|
||||||
|
standard_create_resource
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_modify_resource(name)
|
||||||
|
Chef::Log.info "Checking existing #{@current_cib_object} for modifications"
|
||||||
|
|
||||||
|
desired_order = cib_object_class.from_chef_resource(new_resource)
|
||||||
|
if desired_order.definition_string != @current_cib_object.definition_string
|
||||||
|
Chef::Log.debug "changed from [#{@current_cib_object.definition_string}] to [#{desired_order.definition_string}]"
|
||||||
|
cmd = desired_order.reconfigure_command
|
||||||
|
execute cmd do
|
||||||
|
action :nothing
|
||||||
|
end.run_action(:run)
|
||||||
new_resource.updated_by_last_action(true)
|
new_resource.updated_by_last_action(true)
|
||||||
Chef::Log.info "Deleted order '#{name}'."
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
this_dir = ::File.dirname(__FILE__)
|
||||||
require ::File.expand_path('../libraries/chef/mixin/pacemaker',
|
require ::File.expand_path('../libraries/pacemaker', this_dir)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
|
||||||
|
|
||||||
include Chef::Mixin::Pacemaker::RunnableResource
|
include Chef::Mixin::Pacemaker::RunnableResource
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
this_dir = ::File.dirname(__FILE__)
|
||||||
::File.dirname(__FILE__))
|
require ::File.expand_path('../libraries/pacemaker/cib_object', this_dir)
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
@ -22,5 +22,5 @@ actions :create, :delete
|
|||||||
default_action :create
|
default_action :create
|
||||||
|
|
||||||
attribute :name, :kind_of => String, :name_attribute => true
|
attribute :name, :kind_of => String, :name_attribute => true
|
||||||
attribute :priority, :kind_of => String
|
attribute :score, :kind_of => String
|
||||||
attribute :resources, :kind_of => Array
|
attribute :ordering, :kind_of => String
|
||||||
|
2
spec/fixtures/colocation_constraint.rb
vendored
2
spec/fixtures/colocation_constraint.rb
vendored
@ -1,5 +1,5 @@
|
|||||||
require ::File.expand_path('../../libraries/pacemaker/constraint/colocation',
|
require ::File.expand_path('../../libraries/pacemaker/constraint/colocation',
|
||||||
::File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
module Chef::RSpec
|
module Chef::RSpec
|
||||||
module Pacemaker
|
module Pacemaker
|
||||||
|
2
spec/fixtures/keystone_primitive.rb
vendored
2
spec/fixtures/keystone_primitive.rb
vendored
@ -1,5 +1,5 @@
|
|||||||
require ::File.expand_path('../../libraries/pacemaker/resource/primitive',
|
require ::File.expand_path('../../libraries/pacemaker/resource/primitive',
|
||||||
::File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
module Chef::RSpec
|
module Chef::RSpec
|
||||||
module Pacemaker
|
module Pacemaker
|
||||||
|
2
spec/fixtures/location_constraint.rb
vendored
2
spec/fixtures/location_constraint.rb
vendored
@ -1,5 +1,5 @@
|
|||||||
require ::File.expand_path('../../libraries/pacemaker/constraint/location',
|
require ::File.expand_path('../../libraries/pacemaker/constraint/location',
|
||||||
::File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
module Chef::RSpec
|
module Chef::RSpec
|
||||||
module Pacemaker
|
module Pacemaker
|
||||||
|
14
spec/fixtures/order_constraint.rb
vendored
Normal file
14
spec/fixtures/order_constraint.rb
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require ::File.expand_path('../../libraries/pacemaker/constraint/order',
|
||||||
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
|
module Chef::RSpec
|
||||||
|
module Pacemaker
|
||||||
|
module Config
|
||||||
|
ORDER_CONSTRAINT = \
|
||||||
|
::Pacemaker::Constraint::Order.new('order1')
|
||||||
|
ORDER_CONSTRAINT.score = 'Mandatory'
|
||||||
|
ORDER_CONSTRAINT.ordering = 'primitive1 clone1'
|
||||||
|
ORDER_CONSTRAINT_DEFINITION = 'order order1 Mandatory: primitive1 clone1'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,79 +1,13 @@
|
|||||||
# Shared code used to test providers of CIB objects
|
# Shared code used to test subclasses of Pacemaker::CIBObject
|
||||||
|
|
||||||
require 'mixlib/shellout'
|
require 'mixlib/shellout'
|
||||||
|
|
||||||
require File.expand_path('../../libraries/pacemaker/cib_object',
|
this_dir = File.dirname(__FILE__)
|
||||||
File.dirname(__FILE__))
|
require File.expand_path('../../libraries/pacemaker/cib_object', this_dir)
|
||||||
|
require File.expand_path('shellout', this_dir)
|
||||||
module Chef::RSpec
|
|
||||||
module Pacemaker
|
|
||||||
module CIBObject
|
|
||||||
# Return a Mixlib::ShellOut double which mimics successful
|
|
||||||
# execution of a command, returning the given string on STDOUT.
|
|
||||||
def succeeding_shellout_double(string)
|
|
||||||
shellout = double(Mixlib::ShellOut)
|
|
||||||
shellout.stub(:environment).and_return({})
|
|
||||||
shellout.stub(:run_command)
|
|
||||||
shellout.stub(:error!)
|
|
||||||
expect(shellout).to receive(:stdout).and_return(string)
|
|
||||||
shellout
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return a Mixlib::ShellOut double which mimics failed
|
|
||||||
# execution of a command, raising an exception when #error! is
|
|
||||||
# called. We expect #error! to be called, because if it isn't,
|
|
||||||
# that probably indicates the code isn't robust enough. This
|
|
||||||
# may need to be relaxed in the future.
|
|
||||||
def failing_shellout_double(stdout='', stderr='', exitstatus=1)
|
|
||||||
shellout = double(Mixlib::ShellOut)
|
|
||||||
shellout.stub(:environment).and_return({})
|
|
||||||
shellout.stub(:run_command)
|
|
||||||
shellout.stub(:stdout).and_return(stdout)
|
|
||||||
shellout.stub(:stderr).and_return(stderr)
|
|
||||||
shellout.stub(:exitstatus).and_return(exitstatus)
|
|
||||||
exception = Mixlib::ShellOut::ShellCommandFailed.new(
|
|
||||||
"Expected process to exit with 0, " +
|
|
||||||
"but received '#{exitstatus}'"
|
|
||||||
)
|
|
||||||
expect(shellout).to receive(:error!).and_raise(exception)
|
|
||||||
shellout
|
|
||||||
end
|
|
||||||
|
|
||||||
# This stubs Mixlib::ShellOut.new with a sequence of doubles
|
|
||||||
# with a corresponding sequence of behaviours. This allows us
|
|
||||||
# to simulate the output of a series of shell commands being run
|
|
||||||
# via Mixlib::ShellOut. Each double either mimics a successful
|
|
||||||
# command execution whose #stdout method returns the given
|
|
||||||
# string, or a failed execution with the given exit code and
|
|
||||||
# STDOUT/STDERR.
|
|
||||||
#
|
|
||||||
# results is an Array describing the sequence of behaviours;
|
|
||||||
# each element is either a string mimicking STDOUT from
|
|
||||||
# successful command execution, or a [stdout, stderr, exitcode]
|
|
||||||
# status mimicking command execution failure.
|
|
||||||
#
|
|
||||||
# For example, "crm configure show" is executed by
|
|
||||||
# #load_current_resource, and again later on for the :create
|
|
||||||
# action, to see whether to create or modify. So the first
|
|
||||||
# double in the sequence would return an empty definition if we
|
|
||||||
# wanted to test creation of a new CIB object, or an existing
|
|
||||||
# definition if we wanted to test modification of an existing
|
|
||||||
# one. If the test needs subsequent doubles to return different
|
|
||||||
# values then stdout_strings can have more than one element.
|
|
||||||
def stub_shellout(*results)
|
|
||||||
doubles = results.map { |result|
|
|
||||||
result.is_a?(String) ?
|
|
||||||
succeeding_shellout_double(result)
|
|
||||||
: failing_shellout_double(*result)
|
|
||||||
}
|
|
||||||
Mixlib::ShellOut.stub(:new).and_return(*doubles)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples "a CIB object" do
|
shared_examples "a CIB object" do
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
include Chef::RSpec::Mixlib::ShellOut
|
||||||
|
|
||||||
def expect_to_match_fixture(obj)
|
def expect_to_match_fixture(obj)
|
||||||
expect(obj.class).to eq(pacemaker_object_class)
|
expect(obj.class).to eq(pacemaker_object_class)
|
||||||
@ -101,21 +35,3 @@ shared_examples "a CIB object" do
|
|||||||
"Expected #{object_type} type but loaded definition was type sometype")
|
"Expected #{object_type} type but loaded definition was type sometype")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "action on non-existent resource" do |action, cmd, expected_error|
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
it "should not attempt to #{action.to_s} a non-existent resource" do
|
|
||||||
stub_shellout("")
|
|
||||||
|
|
||||||
if expected_error
|
|
||||||
expect { provider.run_action action }.to \
|
|
||||||
raise_error(RuntimeError, expected_error)
|
|
||||||
else
|
|
||||||
provider.run_action action
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(@chef_run).not_to run_execute(cmd)
|
|
||||||
expect(@resource).not_to be_updated
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
26
spec/helpers/non_runnable_resource.rb
Normal file
26
spec/helpers/non_runnable_resource.rb
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Shared code used to test providers of non-runnable Chef resources
|
||||||
|
# representing Pacemaker CIB objects. For example the provider for
|
||||||
|
# primitives is runnable (since primitives can be started and stopped)
|
||||||
|
# but constraints cannot.
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('provider', this_dir)
|
||||||
|
require File.expand_path('shellout', this_dir)
|
||||||
|
|
||||||
|
shared_examples "a non-runnable resource" do |fixture|
|
||||||
|
include Chef::RSpec::Mixlib::ShellOut
|
||||||
|
|
||||||
|
it_should_behave_like "all Pacemaker LWRPs", fixture
|
||||||
|
|
||||||
|
describe ":delete action" do
|
||||||
|
it "should delete a resource" do
|
||||||
|
stub_shellout(fixture.definition_string)
|
||||||
|
|
||||||
|
provider.run_action :delete
|
||||||
|
|
||||||
|
cmd = "crm configure delete '#{fixture.name}'"
|
||||||
|
expect(@chef_run).to run_execute(cmd)
|
||||||
|
expect(@resource).to be_updated
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
71
spec/helpers/provider.rb
Normal file
71
spec/helpers/provider.rb
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Shared code used to test providers of CIB objects
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('shellout', this_dir)
|
||||||
|
require File.expand_path('cib_object', this_dir)
|
||||||
|
|
||||||
|
shared_context "a Pacemaker LWRP" do
|
||||||
|
before(:each) do
|
||||||
|
runner_opts = {
|
||||||
|
:step_into => [lwrp_name]
|
||||||
|
}
|
||||||
|
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
||||||
|
@chef_run.converge "pacemaker::default"
|
||||||
|
@node = @chef_run.node
|
||||||
|
@run_context = @chef_run.run_context
|
||||||
|
|
||||||
|
camelized_subclass_name = "Pacemaker" + lwrp_name.capitalize
|
||||||
|
@resource_class = ::Chef::Resource.const_get(camelized_subclass_name)
|
||||||
|
@provider_class = ::Chef::Provider.const_get(camelized_subclass_name)
|
||||||
|
|
||||||
|
@resource = @resource_class.new(fixture.name, @run_context)
|
||||||
|
end
|
||||||
|
|
||||||
|
let (:provider) { @provider_class.new(@resource, @run_context) }
|
||||||
|
end
|
||||||
|
|
||||||
|
module Chef::RSpec
|
||||||
|
module Pacemaker
|
||||||
|
module CIBObject
|
||||||
|
include Chef::RSpec::Mixlib::ShellOut
|
||||||
|
|
||||||
|
def test_modify(expected_cmds)
|
||||||
|
yield
|
||||||
|
|
||||||
|
stub_shellout(fixture.definition_string)
|
||||||
|
|
||||||
|
provider.run_action :create
|
||||||
|
|
||||||
|
expected_cmds.each do |cmd|
|
||||||
|
expect(@chef_run).to run_execute(cmd)
|
||||||
|
end
|
||||||
|
expect(@resource).to be_updated
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples "action on non-existent resource" do |action, cmd, expected_error|
|
||||||
|
include Chef::RSpec::Mixlib::ShellOut
|
||||||
|
|
||||||
|
it "should not attempt to #{action.to_s} a non-existent resource" do
|
||||||
|
stub_shellout("")
|
||||||
|
|
||||||
|
if expected_error
|
||||||
|
expect { provider.run_action action }.to \
|
||||||
|
raise_error(RuntimeError, expected_error)
|
||||||
|
else
|
||||||
|
provider.run_action action
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(@chef_run).not_to run_execute(cmd)
|
||||||
|
expect(@resource).not_to be_updated
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples "all Pacemaker LWRPs" do |fixture|
|
||||||
|
describe ":delete action" do
|
||||||
|
it_should_behave_like "action on non-existent resource", \
|
||||||
|
:delete, "crm configure delete #{fixture.name}", nil
|
||||||
|
end
|
||||||
|
end
|
@ -1,25 +1,24 @@
|
|||||||
require File.expand_path('cib_object', File.dirname(__FILE__))
|
# Shared code used to test providers of runnable Chef resources
|
||||||
|
# representing Pacemaker CIB objects. For example the provider
|
||||||
|
# for primitives is runnable (since primitives can be started
|
||||||
|
# and stopped) but constraints cannot.
|
||||||
|
|
||||||
module Chef::RSpec
|
this_dir = File.dirname(__FILE__)
|
||||||
module Pacemaker
|
require File.expand_path('provider', this_dir)
|
||||||
module RunnableResource
|
require File.expand_path('shellout', this_dir)
|
||||||
|
|
||||||
|
shared_examples "a runnable resource" do |fixture|
|
||||||
def expect_running(running)
|
def expect_running(running)
|
||||||
expect_any_instance_of(cib_object_class) \
|
expect_any_instance_of(cib_object_class) \
|
||||||
.to receive(:running?) \
|
.to receive(:running?) \
|
||||||
.and_return(running)
|
.and_return(running)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples "a runnable resource" do |fixture|
|
it_should_behave_like "all Pacemaker LWRPs", fixture
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::RunnableResource
|
include Chef::RSpec::Mixlib::ShellOut
|
||||||
|
|
||||||
describe ":delete action" do
|
describe ":delete action" do
|
||||||
it_should_behave_like "action on non-existent resource", \
|
|
||||||
:delete, "crm configure delete #{fixture.name}", nil
|
|
||||||
|
|
||||||
it "should not delete a running resource" do
|
it "should not delete a running resource" do
|
||||||
stub_shellout(fixture.definition_string)
|
stub_shellout(fixture.definition_string)
|
||||||
expect_running(true)
|
expect_running(true)
|
||||||
|
68
spec/helpers/shellout.rb
Normal file
68
spec/helpers/shellout.rb
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
require 'mixlib/shellout'
|
||||||
|
|
||||||
|
module Chef::RSpec
|
||||||
|
module Mixlib
|
||||||
|
module ShellOut
|
||||||
|
# Return a Mixlib::ShellOut double which mimics successful
|
||||||
|
# execution of a command, returning the given string on STDOUT.
|
||||||
|
def succeeding_shellout_double(string)
|
||||||
|
shellout = double(Mixlib::ShellOut)
|
||||||
|
shellout.stub(:environment).and_return({})
|
||||||
|
shellout.stub(:run_command)
|
||||||
|
shellout.stub(:error!)
|
||||||
|
expect(shellout).to receive(:stdout).and_return(string)
|
||||||
|
shellout
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return a Mixlib::ShellOut double which mimics failed
|
||||||
|
# execution of a command, raising an exception when #error! is
|
||||||
|
# called. We expect #error! to be called, because if it isn't,
|
||||||
|
# that probably indicates the code isn't robust enough. This
|
||||||
|
# may need to be relaxed in the future.
|
||||||
|
def failing_shellout_double(stdout='', stderr='', exitstatus=1)
|
||||||
|
shellout = double(Mixlib::ShellOut)
|
||||||
|
shellout.stub(:environment).and_return({})
|
||||||
|
shellout.stub(:run_command)
|
||||||
|
shellout.stub(:stdout).and_return(stdout)
|
||||||
|
shellout.stub(:stderr).and_return(stderr)
|
||||||
|
shellout.stub(:exitstatus).and_return(exitstatus)
|
||||||
|
exception = ::Mixlib::ShellOut::ShellCommandFailed.new(
|
||||||
|
"Expected process to exit with 0, " +
|
||||||
|
"but received '#{exitstatus}'"
|
||||||
|
)
|
||||||
|
expect(shellout).to receive(:error!).and_raise(exception)
|
||||||
|
shellout
|
||||||
|
end
|
||||||
|
|
||||||
|
# This stubs Mixlib::ShellOut.new with a sequence of doubles
|
||||||
|
# with a corresponding sequence of behaviours. This allows us
|
||||||
|
# to simulate the output of a series of shell commands being run
|
||||||
|
# via Mixlib::ShellOut. Each double either mimics a successful
|
||||||
|
# command execution whose #stdout method returns the given
|
||||||
|
# string, or a failed execution with the given exit code and
|
||||||
|
# STDOUT/STDERR.
|
||||||
|
#
|
||||||
|
# results is an Array describing the sequence of behaviours;
|
||||||
|
# each element is either a string mimicking STDOUT from
|
||||||
|
# successful command execution, or a [stdout, stderr, exitcode]
|
||||||
|
# status mimicking command execution failure.
|
||||||
|
#
|
||||||
|
# For example, "crm configure show" is executed by
|
||||||
|
# #load_current_resource, and again later on for the :create
|
||||||
|
# action, to see whether to create or modify. So the first
|
||||||
|
# double in the sequence would return an empty definition if we
|
||||||
|
# wanted to test creation of a new CIB object, or an existing
|
||||||
|
# definition if we wanted to test modification of an existing
|
||||||
|
# one. If the test needs subsequent doubles to return different
|
||||||
|
# values then stdout_strings can have more than one element.
|
||||||
|
def stub_shellout(*results)
|
||||||
|
doubles = results.map { |result|
|
||||||
|
result.is_a?(String) ?
|
||||||
|
succeeding_shellout_double(result)
|
||||||
|
: failing_shellout_double(*result)
|
||||||
|
}
|
||||||
|
::Mixlib::ShellOut.stub(:new).and_return(*doubles)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,8 +1,10 @@
|
|||||||
require 'spec_helper'
|
|
||||||
require 'mixlib/shellout'
|
require 'mixlib/shellout'
|
||||||
|
|
||||||
require File.expand_path('../../../libraries/pacemaker', File.dirname(__FILE__))
|
require 'spec_helper'
|
||||||
require File.expand_path('../../fixtures/keystone_primitive', File.dirname(__FILE__))
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('../../../libraries/pacemaker', this_dir)
|
||||||
|
require File.expand_path('../../fixtures/keystone_primitive', this_dir)
|
||||||
|
|
||||||
describe Pacemaker::CIBObject do
|
describe Pacemaker::CIBObject do
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../../../../libraries/pacemaker/constraint/colocation',
|
require File.expand_path('../../../../libraries/pacemaker/constraint/colocation',
|
||||||
File.dirname(__FILE__))
|
this_dir)
|
||||||
require File.expand_path('../../../fixtures/colocation_constraint', File.dirname(__FILE__))
|
require File.expand_path('../../../fixtures/colocation_constraint', this_dir)
|
||||||
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__))
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
|
|
||||||
describe Pacemaker::Constraint::Colocation do
|
describe Pacemaker::Constraint::Colocation do
|
||||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup }
|
||||||
@ -10,10 +12,6 @@ describe Pacemaker::Constraint::Colocation do
|
|||||||
Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT_DEFINITION
|
Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT_DEFINITION
|
||||||
}
|
}
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
Mixlib::ShellOut.any_instance.stub(:run_command)
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_type
|
def object_type
|
||||||
'colocation'
|
'colocation'
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../../../../libraries/pacemaker/constraint/location',
|
require File.expand_path('../../../../libraries/pacemaker/constraint/location',
|
||||||
File.dirname(__FILE__))
|
this_dir)
|
||||||
require File.expand_path('../../../fixtures/location_constraint', File.dirname(__FILE__))
|
require File.expand_path('../../../fixtures/location_constraint', this_dir)
|
||||||
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__))
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
|
|
||||||
describe Pacemaker::Constraint::Location do
|
describe Pacemaker::Constraint::Location do
|
||||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup }
|
||||||
@ -10,10 +12,6 @@ describe Pacemaker::Constraint::Location do
|
|||||||
Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT_DEFINITION
|
Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT_DEFINITION
|
||||||
}
|
}
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
Mixlib::ShellOut.any_instance.stub(:run_command)
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_type
|
def object_type
|
||||||
'location'
|
'location'
|
||||||
end
|
end
|
||||||
|
61
spec/libraries/pacemaker/constraint/order_spec.rb
Normal file
61
spec/libraries/pacemaker/constraint/order_spec.rb
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('../../../../libraries/pacemaker/constraint/order',
|
||||||
|
this_dir)
|
||||||
|
require File.expand_path('../../../fixtures/order_constraint', this_dir)
|
||||||
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
|
|
||||||
|
describe Pacemaker::Constraint::Order do
|
||||||
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::ORDER_CONSTRAINT.dup }
|
||||||
|
let(:fixture_definition) {
|
||||||
|
Chef::RSpec::Pacemaker::Config::ORDER_CONSTRAINT_DEFINITION
|
||||||
|
}
|
||||||
|
|
||||||
|
def object_type
|
||||||
|
'order'
|
||||||
|
end
|
||||||
|
|
||||||
|
def pacemaker_object_class
|
||||||
|
Pacemaker::Constraint::Order
|
||||||
|
end
|
||||||
|
|
||||||
|
def fields
|
||||||
|
%w(name score ordering)
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like "a CIB object"
|
||||||
|
|
||||||
|
describe "#definition_string" do
|
||||||
|
it "should return the definition string" do
|
||||||
|
expect(fixture.definition_string).to eq(fixture_definition)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return a short definition string" do
|
||||||
|
order = pacemaker_object_class.new('foo')
|
||||||
|
order.definition = \
|
||||||
|
%!order order1 Mandatory: rsc1 rsc2!
|
||||||
|
order.parse_definition
|
||||||
|
expect(order.definition_string).to eq(<<'EOF'.chomp)
|
||||||
|
order order1 Mandatory: rsc1 rsc2
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#parse_definition" do
|
||||||
|
before(:each) do
|
||||||
|
@parsed = pacemaker_object_class.new(fixture.name)
|
||||||
|
@parsed.definition = fixture_definition
|
||||||
|
@parsed.parse_definition
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should parse the score" do
|
||||||
|
expect(@parsed.score).to eq(fixture.score)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should parse the ordering" do
|
||||||
|
expect(@parsed.ordering).to eq(fixture.ordering)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,10 +1,10 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require File.expand_path('../../../../libraries/pacemaker/resource/clone',
|
|
||||||
File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../../../fixtures/clone_resource', File.dirname(__FILE__))
|
require File.expand_path('../../../../libraries/pacemaker/resource/clone', this_dir)
|
||||||
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__))
|
require File.expand_path('../../../fixtures/clone_resource', this_dir)
|
||||||
require File.expand_path('../../../helpers/meta_examples',
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
File.dirname(__FILE__))
|
require File.expand_path('../../../helpers/meta_examples', this_dir)
|
||||||
|
|
||||||
describe Pacemaker::Resource::Clone do
|
describe Pacemaker::Resource::Clone do
|
||||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup }
|
||||||
@ -12,10 +12,6 @@ describe Pacemaker::Resource::Clone do
|
|||||||
Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE_DEFINITION
|
Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE_DEFINITION
|
||||||
}
|
}
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
Mixlib::ShellOut.any_instance.stub(:run_command)
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_type
|
def object_type
|
||||||
'clone'
|
'clone'
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
require File.expand_path('../../../../libraries/pacemaker/resource/group',
|
require File.expand_path('../../../../libraries/pacemaker/resource/group',
|
||||||
File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
require File.expand_path('../../../fixtures/resource_group', File.dirname(__FILE__))
|
require File.expand_path('../../../fixtures/resource_group', File.dirname(__FILE__))
|
||||||
@ -12,10 +13,6 @@ describe Pacemaker::Resource::Group do
|
|||||||
Chef::RSpec::Pacemaker::Config::RESOURCE_GROUP_DEFINITION
|
Chef::RSpec::Pacemaker::Config::RESOURCE_GROUP_DEFINITION
|
||||||
}
|
}
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
Mixlib::ShellOut.any_instance.stub(:run_command)
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_type
|
def object_type
|
||||||
'group'
|
'group'
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require File.expand_path('../../../../libraries/pacemaker/resource/ms',
|
|
||||||
File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../../../fixtures/ms_resource', File.dirname(__FILE__))
|
require File.expand_path('../../../../libraries/pacemaker/resource/ms', this_dir)
|
||||||
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__))
|
require File.expand_path('../../../fixtures/ms_resource', this_dir)
|
||||||
require File.expand_path('../../../helpers/meta_examples',
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
File.dirname(__FILE__))
|
require File.expand_path('../../../helpers/meta_examples', this_dir)
|
||||||
|
|
||||||
describe Pacemaker::Resource::MasterSlave do
|
describe Pacemaker::Resource::MasterSlave do
|
||||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup }
|
||||||
@ -12,10 +12,6 @@ describe Pacemaker::Resource::MasterSlave do
|
|||||||
Chef::RSpec::Pacemaker::Config::MS_RESOURCE_DEFINITION
|
Chef::RSpec::Pacemaker::Config::MS_RESOURCE_DEFINITION
|
||||||
}
|
}
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
Mixlib::ShellOut.any_instance.stub(:run_command)
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_type
|
def object_type
|
||||||
'ms'
|
'ms'
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../../../../libraries/pacemaker/resource/primitive',
|
require File.expand_path('../../../../libraries/pacemaker/resource/primitive',
|
||||||
File.dirname(__FILE__))
|
this_dir)
|
||||||
require File.expand_path('../../../fixtures/keystone_primitive',
|
require File.expand_path('../../../fixtures/keystone_primitive', this_dir)
|
||||||
File.dirname(__FILE__))
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
require File.expand_path('../../../helpers/cib_object',
|
require File.expand_path('../../../helpers/meta_examples', this_dir)
|
||||||
File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../../../helpers/meta_examples',
|
|
||||||
File.dirname(__FILE__))
|
|
||||||
|
|
||||||
describe Pacemaker::Resource::Primitive do
|
describe Pacemaker::Resource::Primitive do
|
||||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
require 'mixlib/shellout'
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require File.expand_path('../../../libraries/pacemaker/resource',
|
|
||||||
File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../../fixtures/keystone_primitive',
|
require File.expand_path('../../../libraries/pacemaker/resource', this_dir)
|
||||||
File.dirname(__FILE__))
|
require File.expand_path('../../fixtures/keystone_primitive', this_dir)
|
||||||
|
|
||||||
describe Pacemaker::Resource do
|
describe Pacemaker::Resource do
|
||||||
describe "#running?" do
|
describe "#running?" do
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
require 'chef/application'
|
require 'spec_helper'
|
||||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
|
require File.expand_path('../helpers/runnable_resource', this_dir)
|
||||||
require File.expand_path('../fixtures/clone_resource', File.dirname(__FILE__))
|
require File.expand_path('../fixtures/clone_resource', this_dir)
|
||||||
|
|
||||||
describe "Chef::Provider::PacemakerClone" do
|
describe "Chef::Provider::PacemakerClone" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
@ -10,41 +10,25 @@ describe "Chef::Provider::PacemakerClone" do
|
|||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
fixture = Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup
|
fixture = Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup
|
||||||
|
|
||||||
before(:each) do
|
def lwrp_name
|
||||||
runner_opts = {
|
'clone'
|
||||||
:step_into => ['pacemaker_clone']
|
|
||||||
}
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
|
||||||
@chef_run.converge "pacemaker::default"
|
|
||||||
@node = @chef_run.node
|
|
||||||
@run_context = @chef_run.run_context
|
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerClone.new(fixture.name, @run_context)
|
|
||||||
@resource.rsc fixture.rsc.dup
|
|
||||||
@resource.meta Hash[fixture.meta.dup]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerClone.new(@resource, @run_context) }
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@resource.rsc fixture.rsc.dup
|
||||||
|
@resource.meta Hash[fixture.meta.dup]
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
Pacemaker::Resource::Clone
|
Pacemaker::Resource::Clone
|
||||||
end
|
end
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
describe ":create action" do
|
describe ":create action" do
|
||||||
def test_modify(expected_cmds)
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
yield
|
|
||||||
|
|
||||||
stub_shellout(fixture.definition_string)
|
|
||||||
|
|
||||||
provider.run_action :create
|
|
||||||
|
|
||||||
expected_cmds.each do |cmd|
|
|
||||||
expect(@chef_run).to run_execute(cmd)
|
|
||||||
end
|
|
||||||
expect(@resource).to be_updated
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should modify the clone if the resource is changed" do
|
it "should modify the clone if the resource is changed" do
|
||||||
expected = fixture.dup
|
expected = fixture.dup
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
require 'chef/application'
|
require 'spec_helper'
|
||||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../fixtures/colocation_constraint', File.dirname(__FILE__))
|
require File.expand_path('../helpers/provider', this_dir)
|
||||||
|
require File.expand_path('../helpers/non_runnable_resource', this_dir)
|
||||||
|
require File.expand_path('../fixtures/colocation_constraint', this_dir)
|
||||||
|
|
||||||
describe "Chef::Provider::PacemakerColocation" do
|
describe "Chef::Provider::PacemakerColocation" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
@ -9,41 +11,25 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
fixture = Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup
|
fixture = Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup
|
||||||
|
|
||||||
before(:each) do
|
def lwrp_name
|
||||||
runner_opts = {
|
'colocation'
|
||||||
:step_into => ['pacemaker_colocation']
|
|
||||||
}
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
|
||||||
@chef_run.converge "pacemaker::default"
|
|
||||||
@node = @chef_run.node
|
|
||||||
@run_context = @chef_run.run_context
|
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerColocation.new(fixture.name, @run_context)
|
|
||||||
@resource.score fixture.score
|
|
||||||
@resource.resources fixture.resources.dup
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerColocation.new(@resource, @run_context) }
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@resource.score fixture.score
|
||||||
|
@resource.resources fixture.resources.dup
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
Pacemaker::Constraint::Colocation
|
Pacemaker::Constraint::Colocation
|
||||||
end
|
end
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
describe ":create action" do
|
describe ":create action" do
|
||||||
def test_modify(expected_cmds)
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
yield
|
|
||||||
|
|
||||||
stub_shellout(fixture.definition_string)
|
|
||||||
|
|
||||||
provider.run_action :create
|
|
||||||
|
|
||||||
expected_cmds.each do |cmd|
|
|
||||||
expect(@chef_run).to run_execute(cmd)
|
|
||||||
end
|
|
||||||
expect(@resource).to be_updated
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should modify the constraint if it has a different score" do
|
it "should modify the constraint if it has a different score" do
|
||||||
new_score = '100'
|
new_score = '100'
|
||||||
@ -75,9 +61,6 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ":delete action" do
|
it_should_behave_like "a non-runnable resource", fixture
|
||||||
it_should_behave_like "action on non-existent resource", \
|
|
||||||
:delete, "crm configure delete #{fixture.name}", nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
require 'chef/application'
|
require 'spec_helper'
|
||||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
|
require File.expand_path('../helpers/runnable_resource', this_dir)
|
||||||
require File.expand_path('../fixtures/resource_group', File.dirname(__FILE__))
|
require File.expand_path('../fixtures/resource_group', this_dir)
|
||||||
|
|
||||||
describe "Chef::Provider::PacemakerGroup" do
|
describe "Chef::Provider::PacemakerGroup" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
@ -10,41 +10,25 @@ describe "Chef::Provider::PacemakerGroup" do
|
|||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
fixture = Chef::RSpec::Pacemaker::Config::RESOURCE_GROUP.dup
|
fixture = Chef::RSpec::Pacemaker::Config::RESOURCE_GROUP.dup
|
||||||
|
|
||||||
before(:each) do
|
def lwrp_name
|
||||||
runner_opts = {
|
'group'
|
||||||
:step_into => ['pacemaker_group']
|
|
||||||
}
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
|
||||||
@chef_run.converge "pacemaker::default"
|
|
||||||
@node = @chef_run.node
|
|
||||||
@run_context = @chef_run.run_context
|
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerGroup.new(fixture.name, @run_context)
|
|
||||||
@resource.members fixture.members.dup
|
|
||||||
@resource.meta Hash[fixture.meta.dup]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerGroup.new(@resource, @run_context) }
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@resource.members fixture.members.dup
|
||||||
|
@resource.meta Hash[fixture.meta.dup]
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
Pacemaker::Resource::Group
|
Pacemaker::Resource::Group
|
||||||
end
|
end
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
describe ":create action" do
|
describe ":create action" do
|
||||||
def test_modify(expected_cmds)
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
yield
|
|
||||||
|
|
||||||
stub_shellout(fixture.definition_string)
|
|
||||||
|
|
||||||
provider.run_action :create
|
|
||||||
|
|
||||||
expected_cmds.each do |cmd|
|
|
||||||
expect(@chef_run).to run_execute(cmd)
|
|
||||||
end
|
|
||||||
expect(@resource).to be_updated
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should modify the group if it has a member resource added" do
|
it "should modify the group if it has a member resource added" do
|
||||||
expected = fixture.dup
|
expected = fixture.dup
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
require 'chef/application'
|
require 'spec_helper'
|
||||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../fixtures/location_constraint', File.dirname(__FILE__))
|
require File.expand_path('../helpers/provider', this_dir)
|
||||||
|
require File.expand_path('../helpers/non_runnable_resource', this_dir)
|
||||||
|
require File.expand_path('../fixtures/location_constraint', this_dir)
|
||||||
|
|
||||||
describe "Chef::Provider::PacemakerLocation" do
|
describe "Chef::Provider::PacemakerLocation" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
@ -9,42 +11,25 @@ describe "Chef::Provider::PacemakerLocation" do
|
|||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
fixture = Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup
|
fixture = Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup
|
||||||
|
|
||||||
before(:each) do
|
def lwrp_name
|
||||||
runner_opts = {
|
'location'
|
||||||
:step_into => ['pacemaker_location']
|
end
|
||||||
}
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
|
||||||
@chef_run.converge "pacemaker::default"
|
|
||||||
@node = @chef_run.node
|
|
||||||
@run_context = @chef_run.run_context
|
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerLocation.new(fixture.name, @run_context)
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
@resource.rsc fixture.rsc
|
@resource.rsc fixture.rsc
|
||||||
@resource.score fixture.score
|
@resource.score fixture.score
|
||||||
@resource.node fixture.node.dup
|
@resource.node fixture.node.dup
|
||||||
end
|
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerLocation.new(@resource, @run_context) }
|
end
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
Pacemaker::Constraint::Location
|
Pacemaker::Constraint::Location
|
||||||
end
|
end
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
describe ":create action" do
|
describe ":create action" do
|
||||||
def test_modify(expected_cmds)
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
yield
|
|
||||||
|
|
||||||
stub_shellout(fixture.definition_string)
|
|
||||||
|
|
||||||
provider.run_action :create
|
|
||||||
|
|
||||||
expected_cmds.each do |cmd|
|
|
||||||
expect(@chef_run).to run_execute(cmd)
|
|
||||||
end
|
|
||||||
expect(@resource).to be_updated
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should modify the constraint if it has a different resource" do
|
it "should modify the constraint if it has a different resource" do
|
||||||
new_resource = 'group2'
|
new_resource = 'group2'
|
||||||
@ -75,9 +60,6 @@ describe "Chef::Provider::PacemakerLocation" do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ":delete action" do
|
it_should_behave_like "a non-runnable resource", fixture
|
||||||
it_should_behave_like "action on non-existent resource", \
|
|
||||||
:delete, "crm configure delete #{fixture.name}", nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
require 'chef/application'
|
require 'spec_helper'
|
||||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
|
require File.expand_path('../helpers/runnable_resource', this_dir)
|
||||||
require File.expand_path('../fixtures/ms_resource', File.dirname(__FILE__))
|
require File.expand_path('../fixtures/ms_resource', this_dir)
|
||||||
|
|
||||||
describe "Chef::Provider::PacemakerMs" do
|
describe "Chef::Provider::PacemakerMs" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
@ -10,41 +10,25 @@ describe "Chef::Provider::PacemakerMs" do
|
|||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
fixture = Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup
|
fixture = Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup
|
||||||
|
|
||||||
before(:each) do
|
def lwrp_name
|
||||||
runner_opts = {
|
'ms'
|
||||||
:step_into => ['pacemaker_ms']
|
|
||||||
}
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
|
||||||
@chef_run.converge "pacemaker::default"
|
|
||||||
@node = @chef_run.node
|
|
||||||
@run_context = @chef_run.run_context
|
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerMs.new(fixture.name, @run_context)
|
|
||||||
@resource.rsc fixture.rsc.dup
|
|
||||||
@resource.meta Hash[fixture.meta.dup]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerMs.new(@resource, @run_context) }
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@resource.rsc fixture.rsc.dup
|
||||||
|
@resource.meta Hash[fixture.meta.dup]
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
Pacemaker::Resource::MasterSlave
|
Pacemaker::Resource::MasterSlave
|
||||||
end
|
end
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
describe ":create action" do
|
describe ":create action" do
|
||||||
def test_modify(expected_cmds)
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
yield
|
|
||||||
|
|
||||||
stub_shellout(fixture.definition_string)
|
|
||||||
|
|
||||||
provider.run_action :create
|
|
||||||
|
|
||||||
expected_cmds.each do |cmd|
|
|
||||||
expect(@chef_run).to run_execute(cmd)
|
|
||||||
end
|
|
||||||
expect(@resource).to be_updated
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should modify the resource if it's changed" do
|
it "should modify the resource if it's changed" do
|
||||||
expected = fixture.dup
|
expected = fixture.dup
|
||||||
|
66
spec/providers/order_spec.rb
Normal file
66
spec/providers/order_spec.rb
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('../helpers/provider', this_dir)
|
||||||
|
require File.expand_path('../helpers/non_runnable_resource', this_dir)
|
||||||
|
require File.expand_path('../fixtures/order_constraint', this_dir)
|
||||||
|
|
||||||
|
describe "Chef::Provider::PacemakerOrder" do
|
||||||
|
# for use inside examples:
|
||||||
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::ORDER_CONSTRAINT.dup }
|
||||||
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
|
fixture = Chef::RSpec::Pacemaker::Config::ORDER_CONSTRAINT.dup
|
||||||
|
|
||||||
|
def lwrp_name
|
||||||
|
'order'
|
||||||
|
end
|
||||||
|
|
||||||
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@resource.score fixture.score
|
||||||
|
@resource.ordering fixture.ordering.dup
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def cib_object_class
|
||||||
|
Pacemaker::Constraint::Order
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ":create action" do
|
||||||
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
|
|
||||||
|
it "should modify the constraint if it has a different score" do
|
||||||
|
new_score = '100'
|
||||||
|
fixture.score = new_score
|
||||||
|
expected_configure_cmd_args = [fixture.reconfigure_command]
|
||||||
|
test_modify(expected_configure_cmd_args) do
|
||||||
|
@resource.score new_score
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should modify the constraint if it has a resource added" do
|
||||||
|
new_resource = 'bar:Stopped'
|
||||||
|
expected = fixture.dup
|
||||||
|
expected.ordering = expected.ordering.dup + ' ' + new_resource
|
||||||
|
expected_configure_cmd_args = [expected.reconfigure_command]
|
||||||
|
test_modify(expected_configure_cmd_args) do
|
||||||
|
@resource.ordering expected.ordering
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should modify the constraint if it has a different ordering" do
|
||||||
|
new_ordering = 'clone1 primitive1'
|
||||||
|
fixture.ordering = new_ordering
|
||||||
|
expected_configure_cmd_args = [fixture.reconfigure_command]
|
||||||
|
test_modify(expected_configure_cmd_args) do
|
||||||
|
@resource.ordering new_ordering
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like "a non-runnable resource", fixture
|
||||||
|
|
||||||
|
end
|
@ -1,8 +1,8 @@
|
|||||||
require 'chef/application'
|
require 'spec_helper'
|
||||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
||||||
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
|
this_dir = File.dirname(__FILE__)
|
||||||
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
|
require File.expand_path('../helpers/runnable_resource', this_dir)
|
||||||
require File.expand_path('../fixtures/keystone_primitive', File.dirname(__FILE__))
|
require File.expand_path('../fixtures/keystone_primitive', this_dir)
|
||||||
|
|
||||||
describe "Chef::Provider::PacemakerPrimitive" do
|
describe "Chef::Provider::PacemakerPrimitive" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
@ -10,43 +10,26 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
fixture = Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE
|
fixture = Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE
|
||||||
|
|
||||||
before(:each) do
|
def lwrp_name
|
||||||
runner_opts = {
|
'primitive'
|
||||||
:step_into => ['pacemaker_primitive']
|
end
|
||||||
}
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(runner_opts)
|
|
||||||
@chef_run.converge "pacemaker::default"
|
|
||||||
@node = @chef_run.node
|
|
||||||
@run_context = @chef_run.run_context
|
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerPrimitive.new(fixture.name, @run_context)
|
include_context "a Pacemaker LWRP"
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
@resource.agent fixture.agent
|
@resource.agent fixture.agent
|
||||||
@resource.params Hash[fixture.params]
|
@resource.params Hash[fixture.params]
|
||||||
@resource.meta Hash[fixture.meta]
|
@resource.meta Hash[fixture.meta]
|
||||||
@resource.op Hash[fixture.op]
|
@resource.op Hash[fixture.op]
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerPrimitive.new(@resource, @run_context) }
|
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
Pacemaker::Resource::Primitive
|
Pacemaker::Resource::Primitive
|
||||||
end
|
end
|
||||||
|
|
||||||
include Chef::RSpec::Pacemaker::CIBObject
|
|
||||||
|
|
||||||
describe ":create action" do
|
describe ":create action" do
|
||||||
def test_modify(expected_cmds)
|
include Chef::RSpec::Pacemaker::CIBObject
|
||||||
yield
|
include Chef::RSpec::Mixlib::ShellOut
|
||||||
|
|
||||||
stub_shellout(fixture.definition_string)
|
|
||||||
|
|
||||||
provider.run_action :create
|
|
||||||
|
|
||||||
expected_cmds.each do |cmd|
|
|
||||||
expect(@chef_run).to run_execute(cmd)
|
|
||||||
end
|
|
||||||
expect(@resource).to be_updated
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should modify the primitive if it has different params" do
|
it "should modify the primitive if it has different params" do
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user