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

Defined Under Namespace

Classes: UnknownOsFamilyError

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.



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

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.



67
68
69
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 67

def base_provision_directory
  @base_provision_directory
end

Class Method Details

.os_family_for(test_name) ⇒ Symbol

Classifies a test name as :linux or :windows using the same use_for? predicate that Provision::Terraform#new_backend consumes. Anchored on Linux.valid_names / Windows.valid_names rather than substring matching, so a test like cis_rhel-8_firewalld_windowserver_2 correctly classifies as :linux.

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 22

def self.os_family_for(test_name)
  return :windows if CemAcpt::Provision::Windows.use_for?(test_name)
  return :linux if CemAcpt::Provision::Linux.use_for?(test_name)

  raise UnknownOsFamilyError, [
    "Cannot determine OS family for test name: #{test_name}.",
    "Known OSes: linux=[#{CemAcpt::Provision::Linux.valid_names.join(', ')}], " \
      "windows=[#{CemAcpt::Provision::Windows.valid_names.join(', ')}].",
    "Known versions: linux=[#{CemAcpt::Provision::Linux.valid_versions.join(', ')}], " \
      "windows=[#{CemAcpt::Provision::Windows.valid_versions.join(', ')}].",
  ].join(' ')
end

.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.



40
41
42
43
44
45
46
47
48
49
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 40

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.

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 55

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.

Raises:

  • (NotImplementedError)


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

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.

Raises:

  • (NotImplementedError)


110
111
112
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 110

def destination_provision_directory
  raise NotImplementedError
end

#goss_filesArray<String>



123
124
125
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 123

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

#implementation_nameString



98
99
100
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 98

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.

Raises:

  • (NotImplementedError)


117
118
119
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 117

def provision_commands
  raise NotImplementedError
end

#provision_directoryString



104
105
106
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 104

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.

Raises:

  • (NotImplementedError)


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

def puppet_bin_path
  raise NotImplementedError
end

#puppet_manifest_fileString



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

def puppet_manifest_file
  'manifest.pp'
end

#remote_module_package_nameString



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

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