Class: CemAcpt::Provision::OsData
- Inherits:
-
Object
- Object
- CemAcpt::Provision::OsData
- Extended by:
- Logging
- Includes:
- Logging
- Defined in:
- lib/cem_acpt/provision/terraform/os_data.rb
Overview
Base class for OS-specific provisioning data.
Defined Under Namespace
Classes: UnknownOsFamilyError
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#base_provision_directory ⇒ Object
Returns the value of attribute base_provision_directory.
Class Method Summary collapse
-
.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.
-
.use_for?(test_name) ⇒ Boolean
Determines if this OsData implementation should be used for the given test name.
-
.valid_names ⇒ Array<String>
Returns an array of valid OS names that this class can handle.
-
.valid_versions ⇒ Array<String>
Returns an array of valid OS versions that this class can handle.
Instance Method Summary collapse
-
#destination_provision_directory ⇒ String
The path to the destination provision directory on the provisioned nodes.
-
#goss_files ⇒ Array<String>
An array of filenames for Goss test files that should be included in the provision directory.
-
#implementation_name ⇒ String
The name of the OsData implementation, derived from the class name.
-
#initialize(config, provision_data) ⇒ OsData
constructor
Initializes a new instance of the OsData class with the given configuration and provision data.
-
#provision_commands ⇒ 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.
-
#provision_directory ⇒ String
The path to the provision directory for this OsData implementation, which is a subdirectory of the base provision directory named after the implementation.
-
#puppet_bin_path ⇒ String
Returns the path to the Puppet binary on the provisioned nodes.
-
#puppet_manifest_file ⇒ String
The filename of the Puppet manifest to be used for provisioning.
-
#remote_module_package_name ⇒ String
The name of the remote package file that will be created on the provisioned nodes for installing the Puppet module.
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_directory ⇒ Object
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`.
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_names ⇒ Array<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.
55 56 57 |
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 55 def self.valid_names raise NotImplementedError end |
.valid_versions ⇒ Array<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.
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_directory ⇒ String
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.
110 111 112 |
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 110 def destination_provision_directory raise NotImplementedError end |
#goss_files ⇒ Array<String>
Returns An array of filenames for Goss test files that should be included in the provision directory.
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_name ⇒ String
Returns The name of the OsData implementation, derived from the class name.
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_commands ⇒ Array<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.
117 118 119 |
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 117 def provision_commands raise NotImplementedError end |
#provision_directory ⇒ String
Returns The path to the provision directory for this OsData implementation, which is a subdirectory of the base provision directory named after the implementation.
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_path ⇒ String
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.
82 83 84 |
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 82 def puppet_bin_path raise NotImplementedError end |
#puppet_manifest_file ⇒ String
Returns The filename of the Puppet manifest to be used for provisioning.
87 88 89 |
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 87 def puppet_manifest_file 'manifest.pp' end |
#remote_module_package_name ⇒ String
Returns The name of the remote package file that will be created on the provisioned nodes for installing the Puppet module.
93 94 95 |
# File 'lib/cem_acpt/provision/terraform/os_data.rb', line 93 def remote_module_package_name 'puppet-module.tar.gz' end |