stop libraries being required multiple times
The previous use of require caused File.join on several occasions to calculate different paths to the same library, depending on which __FILE__ the library was being calculated as relative to; e.g. /some/path/prefix/spec/one/bar.rb would do the equivalent of: require '/some/path/prefix/spec/one/../../libraries/foo/mylib.rb' and /some/path/prefix/spec/two/baz.rb would do the equivalent of: require '/some/path/prefix/spec/two/../../libraries/foo/mylib.rb' This would result in mylib.rb being loaded multiple times, causing warnings from constants being redefined, and worse, multiple objects representing the same class hierarchy (@@foo) variables. The latter actually broke the @@subclasses registration mechanism in Pacemaker::CIBObject. By switching to File.expand_path, we ensure we always refer to each library using a single absolute path, which means Ruby's require mechanism works as it should, only loading the code the first time round.
This commit is contained in:
parent
a2e9b7f018
commit
fe5616cfca
@ -1,3 +1,3 @@
|
||||
require File.join(File.dirname(__FILE__), %w(pacemaker resource primitive))
|
||||
require File.join(File.dirname(__FILE__), %w(pacemaker resource clone))
|
||||
require File.join(File.dirname(__FILE__), %w(pacemaker constraint colocation))
|
||||
require File.expand_path('pacemaker/resource/primitive', File.dirname(__FILE__))
|
||||
require File.expand_path('pacemaker/resource/clone', File.dirname(__FILE__))
|
||||
require File.expand_path('pacemaker/constraint/colocation', File.dirname(__FILE__))
|
||||
|
@ -1,4 +1,4 @@
|
||||
require File.join(File.dirname(__FILE__), 'cib_object')
|
||||
require File.expand_path('cib_object', File.dirname(__FILE__))
|
||||
|
||||
module Pacemaker
|
||||
class Constraint < Pacemaker::CIBObject
|
||||
|
@ -1,4 +1,4 @@
|
||||
require File::join(File.dirname(__FILE__), %w(.. constraint))
|
||||
require File.expand_path('../constraint', File.dirname(__FILE__))
|
||||
|
||||
class Pacemaker::Constraint::Colocation < Pacemaker::Constraint
|
||||
TYPE = 'colocation'
|
||||
|
@ -1,5 +1,5 @@
|
||||
require 'chef/mixin/shell_out'
|
||||
require File::join(File.dirname(__FILE__), 'cib_object')
|
||||
require File.expand_path('cib_object', File.dirname(__FILE__))
|
||||
|
||||
module Pacemaker
|
||||
class Resource < Pacemaker::CIBObject
|
||||
|
@ -1,4 +1,4 @@
|
||||
require File::join(File.dirname(__FILE__), %w(.. resource))
|
||||
require File.expand_path('../resource', File.dirname(__FILE__))
|
||||
|
||||
class Pacemaker::Resource::Clone < Pacemaker::Resource
|
||||
register_type 'clone'
|
||||
|
@ -1,5 +1,5 @@
|
||||
require 'shellwords'
|
||||
require File::join(File.dirname(__FILE__), %w(.. resource))
|
||||
require File.expand_path('../resource', File.dirname(__FILE__))
|
||||
|
||||
class Pacemaker::Resource::Primitive < Pacemaker::Resource
|
||||
TYPE = 'primitive'
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. libraries pacemaker cib_object))
|
||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
action :create do
|
||||
name = new_resource.name
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries pacemaker))
|
||||
require ::File.join(::File.dirname(__FILE__), 'common')
|
||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
||||
require ::File.expand_path('common', ::File.dirname(__FILE__))
|
||||
|
||||
include Chef::Mixin::PacemakerCommon
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
require 'chef/application'
|
||||
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries pacemaker))
|
||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
||||
|
||||
class Chef
|
||||
module Mixin::PacemakerCommon
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. libraries pacemaker cib_object))
|
||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
action :create do
|
||||
name = new_resource.name
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. libraries pacemaker cib_object))
|
||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
action :create do
|
||||
name = new_resource.name
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. libraries pacemaker cib_object))
|
||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
action :create do
|
||||
name = new_resource.name
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries pacemaker))
|
||||
require ::File.join(::File.dirname(__FILE__), 'common')
|
||||
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__))
|
||||
require ::File.expand_path('common', ::File.dirname(__FILE__))
|
||||
|
||||
include Chef::Mixin::PacemakerCommon
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. libraries pacemaker cib_object))
|
||||
require ::File.expand_path('../libraries/pacemaker/cib_object',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
action :create do
|
||||
name = new_resource.name
|
||||
|
6
spec/fixtures/clone_resource.rb
vendored
6
spec/fixtures/clone_resource.rb
vendored
@ -1,6 +1,6 @@
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. .. libraries pacemaker resource clone))
|
||||
require ::File.join(::File.dirname(__FILE__), 'keystone_primitive')
|
||||
require ::File.expand_path('../../libraries/pacemaker/resource/clone',
|
||||
::File.dirname(__FILE__))
|
||||
require ::File.expand_path('keystone_primitive', ::File.dirname(__FILE__))
|
||||
|
||||
module Chef::RSpec
|
||||
module Pacemaker
|
||||
|
4
spec/fixtures/colocation_constraint.rb
vendored
4
spec/fixtures/colocation_constraint.rb
vendored
@ -1,5 +1,5 @@
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. .. libraries pacemaker constraint colocation))
|
||||
require ::File.expand_path('../../libraries/pacemaker/constraint/colocation',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
module Chef::RSpec
|
||||
module Pacemaker
|
||||
|
4
spec/fixtures/keystone_primitive.rb
vendored
4
spec/fixtures/keystone_primitive.rb
vendored
@ -1,5 +1,5 @@
|
||||
require ::File.join(::File.dirname(__FILE__),
|
||||
*%w(.. .. libraries pacemaker resource primitive))
|
||||
require ::File.expand_path('../../libraries/pacemaker/resource/primitive',
|
||||
::File.dirname(__FILE__))
|
||||
|
||||
module Chef::RSpec
|
||||
module Pacemaker
|
||||
|
@ -1,5 +1,6 @@
|
||||
require 'mixlib/shellout'
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. libraries pacemaker cib_object))
|
||||
require File.expand_path('../../libraries/pacemaker/cib_object',
|
||||
File.dirname(__FILE__))
|
||||
|
||||
shared_examples "a CIB object" do
|
||||
def expect_to_match_fixture(obj)
|
||||
|
@ -1,8 +1,8 @@
|
||||
require 'spec_helper'
|
||||
require 'mixlib/shellout'
|
||||
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. libraries pacemaker))
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. fixtures keystone_primitive))
|
||||
require File.expand_path('../../../libraries/pacemaker', File.dirname(__FILE__))
|
||||
require File.expand_path('../../fixtures/keystone_primitive', File.dirname(__FILE__))
|
||||
|
||||
describe Pacemaker::CIBObject do
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
require 'spec_helper'
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. ..
|
||||
libraries pacemaker constraint colocation))
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. fixtures colocation_constraint))
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. helpers common_object_examples))
|
||||
require File.expand_path('../../../../libraries/pacemaker/constraint/colocation',
|
||||
File.dirname(__FILE__))
|
||||
require File.expand_path('../../../fixtures/colocation_constraint', File.dirname(__FILE__))
|
||||
require File.expand_path('../../../helpers/common_object_examples', File.dirname(__FILE__))
|
||||
|
||||
describe Pacemaker::Constraint::Colocation do
|
||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup }
|
||||
|
@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. .. libraries pacemaker resource primitive))
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. fixtures keystone_primitive))
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. helpers common_object_examples))
|
||||
require File.expand_path('../../../../libraries/pacemaker/resource/primitive', File.dirname(__FILE__))
|
||||
require File.expand_path('../../../fixtures/keystone_primitive', File.dirname(__FILE__))
|
||||
require File.expand_path('../../../helpers/common_object_examples', File.dirname(__FILE__))
|
||||
|
||||
describe Pacemaker::Resource::Primitive do
|
||||
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }
|
||||
|
@ -1,5 +1,6 @@
|
||||
require 'spec_helper'
|
||||
require File.join(File.dirname(__FILE__), %w(.. .. .. libraries pacemaker resource))
|
||||
require File.expand_path('../../../libraries/pacemaker/resource',
|
||||
File.dirname(__FILE__))
|
||||
|
||||
describe Pacemaker::Resource do
|
||||
describe "#running?" do
|
||||
|
@ -1,7 +1,7 @@
|
||||
require 'chef/application'
|
||||
require File.join(File.dirname(__FILE__), %w(.. spec_helper))
|
||||
require File.join(File.dirname(__FILE__), %w(.. helpers common))
|
||||
require File.join(File.dirname(__FILE__), %w(.. fixtures colocation_constraint))
|
||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
require File.expand_path('../helpers/common', File.dirname(__FILE__))
|
||||
require File.expand_path('../fixtures/colocation_constraint', File.dirname(__FILE__))
|
||||
|
||||
describe "Chef::Provider::PacemakerColocation" do
|
||||
# for use inside examples:
|
||||
|
@ -1,7 +1,7 @@
|
||||
require 'chef/application'
|
||||
require File.join(File.dirname(__FILE__), %w(.. spec_helper))
|
||||
require File.join(File.dirname(__FILE__), %w(.. helpers common))
|
||||
require File.join(File.dirname(__FILE__), %w(.. fixtures keystone_primitive))
|
||||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
require File.expand_path('../helpers/common', File.dirname(__FILE__))
|
||||
require File.expand_path('../fixtures/keystone_primitive', File.dirname(__FILE__))
|
||||
|
||||
describe "Chef::Provider::PacemakerPrimitive" do
|
||||
# for use inside examples:
|
||||
|
Loading…
x
Reference in New Issue
Block a user