Class: TestbeatNode
- Inherits:
-
Object
- Object
- TestbeatNode
- Defined in:
- lib/rspec/spec_helper.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Provides access to attributes, if available, as @node much like in chef cookbooks Use .keys to see if a key exists.
-
#attributes ⇒ Object
Attributes defined specifically on the node, not aggregated like in chef runs.
- #attributes? ⇒ Boolean
- #folder ⇒ Object
-
#host ⇒ Object
host is assumed to be equivalent with node name now, but we could read it from attributes, see ticket:1017.
-
#initialize(nodename) ⇒ TestbeatNode
constructor
A new instance of TestbeatNode.
- #key?(key) ⇒ Boolean
-
#keys ⇒ Object
More methods to work like hash.
- #logger ⇒ Object
- #provision ⇒ Object
-
#shell ⇒ Object
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’.
-
#testauth ⇒ Object
returns hash “username” and “password”, or false if unsupported.
- #to_s ⇒ Object
- #vagrant? ⇒ Boolean
Constructor Details
#initialize(nodename) ⇒ TestbeatNode
Returns a new instance of TestbeatNode.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rspec/spec_helper.rb', line 39 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
79 80 81 82 83 84 |
# File 'lib/rspec/spec_helper.rb', line 79 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 |
#attributes ⇒ Object
Attributes defined specifically on the node, not aggregated like in chef runs
69 70 71 |
# File 'lib/rspec/spec_helper.rb', line 69 def attributes @attributes end |
#attributes? ⇒ Boolean
73 74 75 |
# File 'lib/rspec/spec_helper.rb', line 73 def attributes? @attributes != nil end |
#folder ⇒ Object
59 60 61 |
# File 'lib/rspec/spec_helper.rb', line 59 def folder "nodes/#{@name}" end |
#host ⇒ Object
host is assumed to be equivalent with node name now, but we could read it from attributes, see ticket:1017
96 97 98 |
# File 'lib/rspec/spec_helper.rb', line 96 def host @name end |
#key?(key) ⇒ Boolean
91 92 93 |
# File 'lib/rspec/spec_helper.rb', line 91 def key?(key) @attributes.key?(key) end |
#keys ⇒ Object
More methods to work like hash
87 88 89 |
# File 'lib/rspec/spec_helper.rb', line 87 def keys @attributes.keys end |
#logger ⇒ Object
55 56 57 |
# File 'lib/rspec/spec_helper.rb', line 55 def logger $logger end |
#provision ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/rspec/spec_helper.rb', line 114 def provision if not vagrant? raise "Provision support will probably require a vagrant box" else raise "Provision not implemented" end end |
#shell ⇒ Object
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’
107 108 109 110 111 112 |
# File 'lib/rspec/spec_helper.rb', line 107 def shell if not vagrant? return TestbeatShellStub.new() end return TestbeatShellVagrant.new(folder) end |
#testauth ⇒ Object
returns hash “username” and “password”, or false if unsupported
101 102 103 |
# File 'lib/rspec/spec_helper.rb', line 101 def testauth return false # we don't support authenticated nodes yet end |
#to_s ⇒ Object
123 124 125 126 |
# File 'lib/rspec/spec_helper.rb', line 123 def to_s "Testbeat node #{@name}" #ap @attributes end |
#vagrant? ⇒ Boolean
63 64 65 66 |
# File 'lib/rspec/spec_helper.rb', line 63 def vagrant? vagrantfile = "#{folder}/Vagrantfile" return File.exists?(vagrantfile) end |