Adam Spiers fe5616cfca 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.
2014-02-06 15:44:14 +00:00

34 lines
858 B
Ruby

require File.expand_path('../constraint', File.dirname(__FILE__))
class Pacemaker::Constraint::Colocation < Pacemaker::Constraint
TYPE = 'colocation'
register_type TYPE
attr_accessor :score, :resources
def self.from_chef_resource(resource)
attrs = %w(score resources)
new(resource.name).copy_attrs_from_chef_resource(resource, *attrs)
end
def parse_definition
rsc_re = /(\S+?)(?::(Started|Stopped))?/
unless definition =~ /^#{TYPE} (\S+) (\d+|[-+]?inf): (.+?)\s*$/
raise Pacemaker::CIBObject::DefinitionParseError, \
"Couldn't parse definition '#{definition}'"
end
self.name = $1
self.score = $2
self.resources = $3.split
end
def definition_string
"#{TYPE} #{name} #{score}: " + resources.join(' ')
end
def crm_configure_command
"crm configure " + definition_string
end
end