Class: CemAcpt::Provision::OsData

Inherits:
Object
  • Object
show all
Extended by:
Logging
Includes:
Logging
Defined in:
lib/cem_acpt/provision/terraform/os_data.rb

Overview

Base class for OS-specific provisioning data

Direct Known Subclasses

Linux, Windows

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

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_format, current_log_level, current_log_level, included, logger, logger, new_log_config, new_log_config, new_log_formatter, new_log_formatter, new_log_level, new_log_level, new_logger, new_logger, verbose?, verbose?

Constructor Details

#initialize(config, provision_data) ⇒ OsData

Initializes a new instance of the OsData class with the given configuration and provision data.

Parameters:

  • config (CemAcpt::Config)

    The configuration object containing settings for the provisioner.

  • provision_data (Hash)

    A hash containing all necessary information for provisioning, including node data, credentials, and module package paths.



50
51
52
53
54
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 50

def initialize(config, provision_data)
  @config = config
  @provision_data = provision_data
  @base_provision_directory = @config.get('terraform.dir')
end

Instance Attribute Details

#base_provision_directoryObject

Returns the value of attribute base_provision_directory.



44
45
46
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 44

def base_provision_directory
  @base_provision_directory
end

Class Method Details

.use_for?(test_name) ⇒ Boolean

Determines if this OsData implementation should be used for the given test name. This method extracts the OS name and version from the test name using a regular expression, and checks if they match the valid names and versions defined by the subclass. The test name is expected to be in the format ‘<prefix>_osname-version`, where osname is the name of the operating system and version is the version number. For example, a test name of test_ubuntu-20 would indicate an Ubuntu OS with version 20.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 17

def self.use_for?(test_name)
  name_ver = test_name.match(%r{^\w+_(\w+)-(\d+).*})
  return false unless name_ver && name_ver.length == 3

  if valid_versions.include?(name_ver[2]) || valid_versions.include?(name_ver[2].to_s)
    return true if valid_names.include?(name_ver[1])
  end

  false
end

.valid_namesArray<String>

Returns an array of valid OS names that this class can handle. This method should be implemented by subclasses to specify which OS names they can handle. The OS name is typically extracted from the test name and used to determine which OS-specific data class to use for provisioning.

Returns:

  • (Array<String>)

    An array of valid OS names that this class can handle.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 32

def self.valid_names
  raise NotImplementedError
end

.valid_versionsArray<String>

Returns an array of valid OS versions that this class can handle. This method should be implemented by subclasses to specify which OS versions they can handle. The OS version is typically extracted from the test name and used to determine which OS-specific data class to use for provisioning.

Returns:

  • (Array<String>)

    An array of valid OS versions that this class can handle.

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 40

def self.valid_versions
  raise NotImplementedError
end

Instance Method Details

#destination_provision_directoryString

Returns The path to the destination provision directory on the provisioned nodes. This method should be implemented by subclasses to specify the correct path for the specific OS they handle.

Returns:

  • (String)

    The path to the destination provision directory on the provisioned nodes. This method should be implemented by subclasses to specify the correct path for the specific OS they handle.

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 87

def destination_provision_directory
  raise NotImplementedError
end

#goss_filesArray<String>

Returns An array of filenames for Goss test files that should be included in the provision directory.

Returns:

  • (Array<String>)

    An array of filenames for Goss test files that should be included in the provision directory.



100
101
102
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 100

def goss_files
  Dir.glob(File.join(provision_directory, 'goss', '*.yaml')).map { |f| File.basename(f) }
end

#implementation_nameString

Returns The name of the OsData implementation, derived from the class name.

Returns:

  • (String)

    The name of the OsData implementation, derived from the class name.



75
76
77
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 75

def implementation_name
  self.class.to_s.downcase.split('::').last
end

#provision_commandsArray<String>

Returns An array of shell commands to be run on the provisioned nodes to set up the necessary environment for running the Puppet manifest. This method should be implemented by subclasses to specify the correct commands for the specific OS they handle.

Returns:

  • (Array<String>)

    An array of shell commands to be run on the provisioned nodes to set up the necessary environment for running the Puppet manifest. This method should be implemented by subclasses to specify the correct commands for the specific OS they handle.

Raises:

  • (NotImplementedError)


94
95
96
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 94

def provision_commands
  raise NotImplementedError
end

#provision_directoryString

Returns The path to the provision directory for this OsData implementation, which is a subdirectory of the base provision directory named after the implementation.

Returns:

  • (String)

    The path to the provision directory for this OsData implementation, which is a subdirectory of the base provision directory named after the implementation.



81
82
83
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 81

def provision_directory
  File.join(base_provision_directory, implementation_name)
end

#puppet_bin_pathString

Returns the path to the Puppet binary on the provisioned nodes. This method should be implemented by subclasses to specify the correct path to the Puppet binary for the specific OS they handle.

Returns:

  • (String)

    The path to the Puppet binary on the provisioned nodes.

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 59

def puppet_bin_path
  raise NotImplementedError
end

#puppet_manifest_fileString

Returns The filename of the Puppet manifest to be used for provisioning.

Returns:

  • (String)

    The filename of the Puppet manifest to be used for provisioning.



64
65
66
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 64

def puppet_manifest_file
  'manifest.pp'
end

#remote_module_package_nameString

Returns The name of the remote package file that will be created on the provisioned nodes for installing the Puppet module.

Returns:

  • (String)

    The name of the remote package file that will be created on the provisioned nodes for installing the Puppet module.



70
71
72
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 70

def remote_module_package_name
  'puppet-module.tar.gz'
end