Module: ForemanMaintain

Extended by:
Concerns::OsFacts, Concerns::PrimaryChecks
Defined in:
lib/foreman_maintain.rb,
lib/foreman_maintain/cli.rb,
lib/foreman_maintain/check.rb,
lib/foreman_maintain/error.rb,
lib/foreman_maintain/param.rb,
lib/foreman_maintain/config.rb,
lib/foreman_maintain/report.rb,
lib/foreman_maintain/runner.rb,
lib/foreman_maintain/context.rb,
lib/foreman_maintain/feature.rb,
lib/foreman_maintain/version.rb,
lib/foreman_maintain/cli/base.rb,
lib/foreman_maintain/core_ext.rb,
lib/foreman_maintain/detector.rb,
lib/foreman_maintain/reporter.rb,
lib/foreman_maintain/scenario.rb,
lib/foreman_maintain/procedure.rb,
lib/foreman_maintain/csv_parser.rb,
lib/foreman_maintain/executable.rb,
lib/foreman_maintain/utils/bash.rb,
lib/foreman_maintain/utils/backup.rb,
lib/foreman_maintain/yaml_storage.rb,
lib/foreman_maintain/update_runner.rb,
lib/foreman_maintain/upgrade_runner.rb,
lib/foreman_maintain/utils/response.rb,
lib/foreman_maintain/concerns/hammer.rb,
lib/foreman_maintain/concerns/logger.rb,
lib/foreman_maintain/package_manager.rb,
lib/foreman_maintain/concerns/finders.rb,
lib/foreman_maintain/dependency_graph.rb,
lib/foreman_maintain/runner/execution.rb,
lib/foreman_maintain/utils/disk/stats.rb,
lib/foreman_maintain/concerns/metadata.rb,
lib/foreman_maintain/concerns/os_facts.rb,
lib/foreman_maintain/concerns/reporter.rb,
lib/foreman_maintain/concerns/upstream.rb,
lib/foreman_maintain/concerns/versions.rb,
lib/foreman_maintain/utils/disk/device.rb,
lib/foreman_maintain/cli/backup_command.rb,
lib/foreman_maintain/cli/health_command.rb,
lib/foreman_maintain/cli/plugin_command.rb,
lib/foreman_maintain/cli/report_command.rb,
lib/foreman_maintain/cli/update_command.rb,
lib/foreman_maintain/repository_manager.rb,
lib/foreman_maintain/cli/restore_command.rb,
lib/foreman_maintain/cli/service_command.rb,
lib/foreman_maintain/cli/upgrade_command.rb,
lib/foreman_maintain/concerns/downstream.rb,
lib/foreman_maintain/utils/curl_response.rb,
lib/foreman_maintain/cli/advanced_command.rb,
lib/foreman_maintain/cli/packages_command.rb,
lib/foreman_maintain/concerns/pulp_common.rb,
lib/foreman_maintain/utils/command_runner.rb,
lib/foreman_maintain/utils/disk/io_device.rb,
lib/foreman_maintain/utils/system_helpers.rb,
lib/foreman_maintain/reporter/cli_reporter.rb,
lib/foreman_maintain/utils/disk/nil_device.rb,
lib/foreman_maintain/concerns/base_database.rb,
lib/foreman_maintain/concerns/primary_checks.rb,
lib/foreman_maintain/concerns/system_helpers.rb,
lib/foreman_maintain/concerns/system_service.rb,
lib/foreman_maintain/runner/stored_execution.rb,
lib/foreman_maintain/cli/self_upgrade_command.rb,
lib/foreman_maintain/concerns/directory_marker.rb,
lib/foreman_maintain/concerns/scenario_metadata.rb,
lib/foreman_maintain/cli/transform_clamp_options.rb,
lib/foreman_maintain/cli/maintenance_mode_command.rb,
lib/foreman_maintain/cli/advanced/procedure_command.rb,
lib/foreman_maintain/cli/advanced/procedure/run_command.rb,
lib/foreman_maintain/concerns/firewall/maintenance_mode.rb,
lib/foreman_maintain/cli/advanced/prebuild_bash_completion.rb,
lib/foreman_maintain/cli/advanced/procedure/by_tag_command.rb,
lib/foreman_maintain/concerns/foreman_and_katello_version_map.rb,
lib/foreman_maintain/concerns/firewall/iptables_maintenance_mode.rb,
lib/foreman_maintain/concerns/firewall/nftables_maintenance_mode.rb,
lib/foreman_maintain/cli/advanced/procedure/abstract_by_tag_command.rb,
lib/foreman_maintain/cli/advanced/procedure/abstract_procedure_command.rb

Defined Under Namespace

Modules: Cli, Concerns, CoreExt, Error, PackageManager, RepositoryManager, Utils Classes: CSVParser, Check, Config, Context, DependencyGraph, Detector, Executable, Feature, HammerConfigurationError, Param, Procedure, Report, Reporter, Runner, Scenario, UpdateRunner, UpgradeRunner, YamlStorage

Constant Summary collapse

LOGGER_LEVEL_MAPPING =
{
  'debug' => ::Logger::DEBUG,
  'info' => ::Logger::INFO,
  'warn' => ::Logger::WARN,
  'error' => ::Logger::ERROR,
  'fatal' => ::Logger::FATAL,
  'unknown' => ::Logger::UNKNOWN,
}.freeze
VERSION =
'1.10.1'.freeze

Constants included from Concerns::OsFacts

Concerns::OsFacts::FALLBACK_OS_RELEASE_FILE, Concerns::OsFacts::OS_RELEASE_FILE

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Concerns::PrimaryChecks

package_name, validate_downstream_packages

Methods included from Concerns::OsFacts

centos?, cpu_cores, deb_major_version, debian?, debian_or_ubuntu?, el8?, el?, el_major_version, el_short_name, facts, memory, os_id, os_id_like_list, os_name, os_release_file, os_version, os_version_codename, os_version_id, rhel?, ubuntu?, ubuntu_major_version

Class Attribute Details

.configObject

Returns the value of attribute config.



52
53
54
# File 'lib/foreman_maintain.rb', line 52

def config
  @config
end

.loggerObject

Returns the value of attribute logger.



52
53
54
# File 'lib/foreman_maintain.rb', line 52

def logger
  @logger
end

Class Method Details

.allowed_available_procedures(*args) ⇒ Object



143
144
145
146
# File 'lib/foreman_maintain.rb', line 143

def allowed_available_procedures(*args)
  procedures = detector.available_procedures(*args)
  procedures.select(&:advanced_run?)
end

.available_checks(*args) ⇒ Object



131
132
133
# File 'lib/foreman_maintain.rb', line 131

def available_checks(*args)
  detector.available_checks(*args)
end

.available_features(*args) ⇒ Object



123
124
125
# File 'lib/foreman_maintain.rb', line 123

def available_features(*args)
  detector.available_features(*args)
end

.available_procedures(*args) ⇒ Object



139
140
141
# File 'lib/foreman_maintain.rb', line 139

def available_procedures(*args)
  detector.available_procedures(*args)
end

.available_reports(*args) ⇒ Object



135
136
137
# File 'lib/foreman_maintain.rb', line 135

def available_reports(*args)
  detector.available_reports(*args)
end

.available_scenarios(*args) ⇒ Object



127
128
129
# File 'lib/foreman_maintain.rb', line 127

def available_scenarios(*args)
  detector.available_scenarios(*args)
end

.cacheObject



107
108
109
# File 'lib/foreman_maintain.rb', line 107

def cache
  ObjectCache.instance
end

.command_nameObject



183
184
185
# File 'lib/foreman_maintain.rb', line 183

def command_name
  pkg_and_cmd_name[1]
end

.config_fileObject



89
90
91
# File 'lib/foreman_maintain.rb', line 89

def config_file
  config.config_file
end

.configure_highlineObject



103
104
105
# File 'lib/foreman_maintain.rb', line 103

def configure_highline
  HighLine.use_color = config.use_color?
end

.detectorObject



111
112
113
# File 'lib/foreman_maintain.rb', line 111

def detector
  @detector ||= Detector.new
end

.enable_maintenance_moduleObject



207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/foreman_maintain.rb', line 207

def enable_maintenance_module
  return unless el8?

  maintenance_module = 'satellite-maintenance:el8'
  package_manager = ForemanMaintain.package_manager

  if package_manager.module_exists?(maintenance_module) &&
     !package_manager.module_enabled?(maintenance_module)
    puts "\nEnabling #{maintenance_module} module"
    package_manager.enable_module(maintenance_module)
  end
end

.init_loggerObject



148
149
150
151
152
153
154
155
156
# File 'lib/foreman_maintain.rb', line 148

def init_logger
  # convert size in KB to Bytes
  log_fsize = config.log_file_size.to_i * 1024
  @logger = Logger.new(config.log_filename, 10, log_fsize).tap do |logger|
    logger.level = LOGGER_LEVEL_MAPPING[config.log_level] || Logger::INFO
    logger.datetime_format = '%Y-%m-%d %H:%M:%S%z '
  end
  pickup_log_messages
end

.load_definitionsObject



93
94
95
96
97
98
99
100
101
# File 'lib/foreman_maintain.rb', line 93

def load_definitions
  # we need to add the load paths first, in case there is crossreferencing
  # between the definitions directories
  $LOAD_PATH.concat(config.definitions_dirs)
  config.definitions_dirs.each do |definitions_dir|
    file_paths = File.expand_path(File.join(definitions_dir, '**', '*.rb'))
    Dir.glob(file_paths).sort.each { |f| require f }
  end
end

.main_package_nameObject



220
221
222
# File 'lib/foreman_maintain.rb', line 220

def main_package_name
  el? ? 'rubygem-foreman_maintain' : 'ruby-foreman-maintain'
end

.package_managerObject



6
7
8
9
10
11
12
13
14
# File 'lib/foreman_maintain/package_manager.rb', line 6

def self.package_manager
  if el?
    ForemanMaintain::PackageManager::Dnf.new
  elsif debian_or_ubuntu?
    ForemanMaintain::PackageManager::Apt.new
  else
    raise 'No supported package manager was found'
  end
end

.perform_self_upgradeObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/foreman_maintain.rb', line 187

def perform_self_upgrade
  package_name, command = pkg_and_cmd_name
  packages_to_update = [package_name, main_package_name].uniq
  packages_to_update_str = packages_to_update.join(', ')

  puts "Checking for new version of #{packages_to_update_str}..."

  enable_maintenance_module
  package_manager = ForemanMaintain.package_manager

  if package_manager.update_available?(packages_to_update)
    puts "\nUpdating #{packages_to_update_str}."
    package_manager.update(packages_to_update, :assumeyes => true)
    puts "\nSuccessfully updated #{packages_to_update_str}."\
         "\nRe-run #{command} with required options!"
    exit 75
  end
  puts "Nothing to update, can't find new version of #{packages_to_update_str}."
end

.pickup_log_messagesObject



158
159
160
161
162
# File 'lib/foreman_maintain.rb', line 158

def pickup_log_messages
  return if config.pre_setup_log_messages.empty?
  config.pre_setup_log_messages.each { |msg| logger.info msg }
  config.pre_setup_log_messages.clear
end

.pkg_and_cmd_nameObject



174
175
176
177
178
179
180
181
# File 'lib/foreman_maintain.rb', line 174

def pkg_and_cmd_name
  instance_feature = ForemanMaintain.available_features(:label => :instance).first
  if instance_feature.downstream
    return instance_feature.downstream.fm_pkg_and_cmd_name
  end

  [main_package_name, 'foreman-maintain']
end

.refresh_featuresObject



115
116
117
# File 'lib/foreman_maintain.rb', line 115

def refresh_features
  @detector = Detector.new
end

.reporterObject



119
120
121
# File 'lib/foreman_maintain.rb', line 119

def reporter
  @reporter ||= ForemanMaintain::Reporter::CLIReporter.new
end

.repository_managerObject



5
6
7
8
9
10
11
12
13
# File 'lib/foreman_maintain/repository_manager.rb', line 5

def self.repository_manager
  @repository_manager ||= if el?
                            ForemanMaintain::RepositoryManager::El.new
                          elsif debian_or_ubuntu?
                            raise 'Not implemented!'
                          else
                            raise 'No supported repository manager was found'
                          end
end

.set_home_environmentObject



74
75
76
# File 'lib/foreman_maintain.rb', line 74

def set_home_environment
  ENV['HOME'] ||= '/root'
end

.setup(options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/foreman_maintain.rb', line 63

def setup(options = {})
  set_home_environment

  # using a queue, we can log the messages which are generated before initializing logger
  self.config = Config.new(options)
  configure_highline
  load_definitions
  init_logger
  update_path
end

.storage(label = :default) ⇒ Object



164
165
166
167
168
# File 'lib/foreman_maintain.rb', line 164

def storage(label = :default)
  ForemanMaintain::YamlStorage.load(label)
rescue StandardError => e
  logger.error "Invalid Storage label i.e #{label}. Error - #{e.message}"
end

.update_pathObject

Appending PATH with expected paths needed for commands we run



79
80
81
82
83
84
85
86
87
# File 'lib/foreman_maintain.rb', line 79

def update_path
  paths = ['/sbin']
  existing_paths = ENV['PATH'].split(':')
  paths -= existing_paths
  if paths.any?
    paths = paths.join(':').chomp(':')
    ENV['PATH'] = "#{ENV['PATH']}:#{paths}"
  end
end

.upgrade_in_progressObject



170
171
172
# File 'lib/foreman_maintain.rb', line 170

def upgrade_in_progress
  storage[:upgrade_target_version]
end