Class: TestbeatNode

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodename) ⇒ TestbeatNode



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spec_helper.rb', line 19

def initialize(nodename)
  @name = nodename
  if !@name || @name.length == 0
    logger.error { "Node name not set, at #{Dir.pwd}" }
    raise "Node name not set"
  end
  attributesFile = "#{folder}/chef.json"
  if File.exists?(attributesFile)
    @attributes = read_chef_attributes(attributesFile)
  else
    logger.warn { "Failed to locate node attributes, from #{attributesFile}, at #{Dir.pwd}" }
    @attributes = nil
  end
  logger.info { "Node initialized #{nodename}, attributes from #{attributesFile}" }
end

Instance Method Details

#[](key) ⇒ Object

Provides access to attributes, if available, as @node much like in chef cookbooks Use .keys to see if a key exists



59
60
61
62
63
64
# File 'lib/spec_helper.rb', line 59

def [](key)
  return nil if @attributes == nil
  # Raise exception so test issues are clearly displayed in rspec output (puts is displayed before test output, difficult to identify which test it comes from)
  raise "Missing attribute key '#{key}', got #{@attributes.keys}" if not @attributes.key?(key)
  @attributes[key]
end

#attributesObject

Attributes defined specifically on the node, not aggregated like in chef runs



49
50
51
# File 'lib/spec_helper.rb', line 49

def attributes
  @attributes
end

#attributes?Boolean



53
54
55
# File 'lib/spec_helper.rb', line 53

def attributes?
  @attributes != nil
end

#folderObject



39
40
41
# File 'lib/spec_helper.rb', line 39

def folder
  "nodes/#{@name}"
end

#hostObject

host is assumed to be equivalent with node name now, but we could read it from attributes, see ticket:1017



76
77
78
# File 'lib/spec_helper.rb', line 76

def host
  @name
end

#key?(key) ⇒ Boolean



71
72
73
# File 'lib/spec_helper.rb', line 71

def key?(key)
  @attributes.key?(key)
end

#keysObject

More methods to work like hash



67
68
69
# File 'lib/spec_helper.rb', line 67

def keys
  @attributes.keys
end

#loggerObject



35
36
37
# File 'lib/spec_helper.rb', line 35

def logger
  $logger
end

#provisionObject



94
95
96
97
98
99
100
# File 'lib/spec_helper.rb', line 94

def provision
  if not vagrant?
    raise "Provision support will probably require a vagrant box"
  else
    raise "Provision not implemented"
  end
end

#shellObject

return command line access, instance of TestbeatNodeRsh, or false if unsupported This is probably easier to support than get_bats; on vagrant nodes we have ‘vagrant ssh -c’



87
88
89
90
91
92
# File 'lib/spec_helper.rb', line 87

def shell
  if not vagrant?
    return TestbeatShellStub.new()
  end
  return TestbeatShellVagrant.new(folder)
end

#testauthObject

returns hash “username” and “password”, or false if unsupported



81
82
83
# File 'lib/spec_helper.rb', line 81

def testauth
  return false # we don't support authenticated nodes yet
end

#to_sObject



103
104
105
106
# File 'lib/spec_helper.rb', line 103

def to_s
  "Testbeat node #{@name}"
  #ap @attributes
end

#vagrant?Boolean



43
44
45
46
# File 'lib/spec_helper.rb', line 43

def vagrant?
  vagrantfile = "#{folder}/Vagrantfile"
  return File.exists?(vagrantfile)
end