Class: CemAcpt::Platform::Base

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/platform/base.rb

Overview

Base class for all platform classes. This class provides an API for interacting with the underlying platform.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

current_log_config, #current_log_config, current_log_format, current_log_level, #current_log_level, included, #logger, new_log_config, #new_log_config, new_log_formatter, new_log_level, #new_log_level

Constructor Details

#initialize(conf, single_test_data, local_port) ⇒ Base

Returns a new instance of Base.

Parameters:

  • conf (CemAcpt::Config)

    the config object.

  • single_test_data (Hash)

    the test data for the current test.

  • local_port (Integer)

    the local port to use for the test.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
# File 'lib/cem_acpt/platform/base.rb', line 18

def initialize(conf, single_test_data, local_port)
  raise ArgumentError, 'single_test_data must be a Hash' unless single_test_data.is_a?(Hash)

  @config = conf.get('node_data')
  @test_data = single_test_data
  @local_port = local_port
  @node_name = @test_data[:node_name] || random_node_name
  @image_name = conf.has?('image_name_builder') ? image_name_builder(conf, single_test_data) : @test_data[:image_name]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/cem_acpt/platform/base.rb', line 13

def config
  @config
end

#image_nameObject (readonly)

Returns the value of attribute image_name.



13
14
15
# File 'lib/cem_acpt/platform/base.rb', line 13

def image_name
  @image_name
end

#local_portObject (readonly)

Returns the value of attribute local_port.



13
14
15
# File 'lib/cem_acpt/platform/base.rb', line 13

def local_port
  @local_port
end

#node_nameObject (readonly)

Returns the value of attribute node_name.



13
14
15
# File 'lib/cem_acpt/platform/base.rb', line 13

def node_name
  @node_name
end

#test_dataObject (readonly)

Returns the value of attribute test_data.



13
14
15
# File 'lib/cem_acpt/platform/base.rb', line 13

def test_data
  @test_data
end

Class Method Details

.apply_manifest(_instance_name, _manifest, _opts = {}) ⇒ Object

Applies a Puppet manifest on the given node.

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/cem_acpt/platform/base.rb', line 69

def self.apply_manifest(_instance_name, _manifest, _opts = {})
  raise NotImplementedError, '#apply_manifest must be implemented by subclass'
end

.command_providerObject

Returns a command provider specified by the Platform module of the specific platform.

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/cem_acpt/platform/base.rb', line 64

def self.command_provider
  raise NotImplementedError, '#command_provider must be implemented by subclass'
end

.run_shell(_instance_name, _cmd, _opts = {}) ⇒ Object

Runs a shell command on the given node.

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/cem_acpt/platform/base.rb', line 74

def self.run_shell(_instance_name, _cmd, _opts = {})
  raise NotImplementedError, '#run_shell must be implemented by subclass'
end

Instance Method Details

#destroyObject

Destroy a node. Will be called asynchronously.

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/cem_acpt/platform/base.rb', line 39

def destroy
  raise NotImplementedError, '#destroy must be implemented by subclass'
end

#image_name_builder(conf, tdata) ⇒ Object

Builds an image name if the config specifies to use the image name builder.



59
60
61
# File 'lib/cem_acpt/platform/base.rb', line 59

def image_name_builder(conf, tdata)
  @image_name_builder ||= CemAcpt::ImageNameBuilder.new(conf).build(tdata)
end

#install_puppet_module_package(_module_pkg_path, _remote_path) ⇒ Object

Upload and install a Puppet module package on the node. Blocking call.

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/cem_acpt/platform/base.rb', line 49

def install_puppet_module_package(_module_pkg_path, _remote_path)
  raise NotImplementedError, '#install_puppet_module_package must be implemented by subclass'
end

#nodeObject

Node should return a hash of all data about a created node.

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/cem_acpt/platform/base.rb', line 29

def node
  raise NotImplementedError, '#node must be implemented by subclass'
end

#provisionObject

Provision a node. Will be called asynchronously.

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/cem_acpt/platform/base.rb', line 34

def provision
  raise NotImplementedError, '#provision must be implemented by subclass'
end

#random_node_nameObject

Generates a random node name.



54
55
56
# File 'lib/cem_acpt/platform/base.rb', line 54

def random_node_name
  "acpt-test-#{SecureRandom.hex(10)}"
end

#ready?Boolean

Tests to see if a node is ready to accept connections from the test suite.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/cem_acpt/platform/base.rb', line 44

def ready?
  raise NotImplementedError, '#ready? must be implemented by subclass'
end