Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVCPLAN-5555: Add support for SUSE #27

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require:
- rubocop-performance
- rubocop-rspec
AllCops:
NewCops: enable
DisplayCopNames: true
TargetRubyVersion: '2.6'
Include:
Expand Down Expand Up @@ -527,6 +528,8 @@ Lint/DuplicateBranch:
Enabled: false
Lint/DuplicateMagicComment:
Enabled: false
Lint/DuplicateMatchPattern:
Enabled: false
Lint/DuplicateRegexpCharacterClassElement:
Enabled: false
Lint/EmptyBlock:
Expand Down Expand Up @@ -643,6 +646,8 @@ Style/ComparableClamp:
Enabled: false
Style/ConcatArrayLiterals:
Enabled: false
Style/DataInheritance:
Enabled: false
Style/DirEmpty:
Enabled: false
Style/DocumentDynamicEvalDefinition:
Expand Down Expand Up @@ -711,6 +716,8 @@ Style/RedundantHeredocDelimiterQuotes:
Enabled: false
Style/RedundantInitialize:
Enabled: false
Style/RedundantLineContinuation:
Enabled: false
Style/RedundantSelfAssignmentBranch:
Enabled: false
Style/RedundantStringEscape:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"puppet.puppet-vscode",
"rebornix.Ruby"
"Shopify.ruby-lsp"
]
}
25 changes: 12 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,29 @@ group :development do
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "deep_merge", '~> 1.0', require: false
gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false
gem "facterdb", '~> 1.18', require: false
gem "metadata-json-lint", '~> 3.0', require: false
gem "puppetlabs_spec_helper", '~> 6.0', require: false
gem "rspec-puppet-facts", '~> 2.0', require: false
gem "codecov", '~> 0.2', require: false
gem "metadata-json-lint", '~> 4.0', require: false
gem "rspec-puppet-facts", '~> 3.0', require: false
gem "dependency_checker", '~> 1.0.0', require: false
gem "parallel_tests", '= 3.12.1', require: false
gem "pry", '~> 0.10', require: false
gem "simplecov-console", '~> 0.5', require: false
gem "simplecov-console", '~> 0.9', require: false
gem "puppet-debugger", '~> 1.0', require: false
gem "rubocop", '= 1.48.1', require: false
gem "rubocop", '~> 1.50.0', require: false
gem "rubocop-performance", '= 1.16.0', require: false
gem "rubocop-rspec", '= 2.19.0', require: false
gem "puppet-strings", '~> 4.0', require: false
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
end
group :system_tests do
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
gem "serverspec", '~> 2.41', require: false
end
group :release_prep do
group :development, :release_prep do
gem "puppet-strings", '~> 4.0', require: false
gem "puppetlabs_spec_helper", '~> 6.0', require: false
gem "puppetlabs_spec_helper", '~> 7.0', require: false
end
group :system_tests do
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "serverspec", '~> 2.41', require: false
end

puppet_version = ENV['PUPPET_GEM_VERSION']
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ See: [REFERENCE.md](REFERENCE.md)

## Limitations

n/a
This module supports both RedHat & Suse OS families.

## Development

Expand Down
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ If not defined cron runs every week

### <a name="profile_update_os--yum_upgrade"></a>`profile_update_os::yum_upgrade`

Apply yum updates via cron
While the class name refers to 'yum', this class also supports 'zypper' in SUSE.

#### Examples

Expand Down
79 changes: 0 additions & 79 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,6 @@ require 'bundler'
require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-syntax/tasks/puppet-syntax'
require 'github_changelog_generator/task' if Gem.loaded_specs.key? 'github_changelog_generator'
require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings'

def changelog_user
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = nil || JSON.load(File.read('metadata.json'))['author']
raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator user:#{returnVal}"
returnVal
end

def changelog_project
return unless Rake.application.top_level_tasks.include? "changelog"

returnVal = nil
returnVal ||= begin
metadata_source = JSON.load(File.read('metadata.json'))['source']
metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})

metadata_source_match && metadata_source_match[1]
end

raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?

puts "GitHubChangelogGenerator project:#{returnVal}"
returnVal
end

def changelog_future_release
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version']
raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator future_release:#{returnVal}"
returnVal
end

PuppetLint.configuration.send('disable_relative')


if Gem.loaded_specs.key? 'github_changelog_generator'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil?
config.user = "#{changelog_user}"
config.project = "#{changelog_project}"
config.future_release = "#{changelog_future_release}"
config.exclude_labels = ['maintenance']
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)."
config.add_pr_wo_labels = true
config.issues = false
config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB"
config.configure_sections = {
"Changed" => {
"prefix" => "### Changed",
"labels" => ["backwards-incompatible"],
},
"Added" => {
"prefix" => "### Added",
"labels" => ["enhancement", "feature"],
},
"Fixed" => {
"prefix" => "### Fixed",
"labels" => ["bug", "documentation", "bugfix"],
},
}
end
else
desc 'Generate a Changelog from GitHub'
task :changelog do
raise <<EOM
The changelog tasks depends on recent features of the github_changelog_generator gem.
Please manually add it to your .sync.yml for now, and run `pdk update`:
---
Gemfile:
optional:
':development':
- gem: 'github_changelog_generator'
version: '~> 1.15'
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')"
EOM
end
end

4 changes: 0 additions & 4 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ profile_update_os::scheduled_reboot::reboot_months: []
profile_update_os::scheduled_reboot::reboot_week_of_month: "any"

profile_update_os::yum_upgrade::enabled: false
profile_update_os::yum_upgrade::excluded_packages:
- "kernel"
- "kernel-core*"
- "kernel-modules*"
profile_update_os::yum_upgrade::random_delay: 30
profile_update_os::yum_upgrade::update_day_of_week: ""
profile_update_os::yum_upgrade::update_hour: 5
Expand Down
4 changes: 4 additions & 0 deletions data/os/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
profile_update_os::yum_upgrade::command: "/usr/bin/dnf-automatic"
profile_update_os::yum_upgrade::config_file: "/etc/dnf/automatic.conf"
profile_update_os::yum_upgrade::excluded_packages:
- "kernel"
- "kernel-core*"
- "kernel-modules*"
profile_update_os::yum_upgrade::package: "dnf-automatic"
profile_update_os::yum_upgrade::service: "dnf-automatic"
profile_update_os::yum_upgrade::yum_config_file: "/etc/dnf/dnf.conf"
10 changes: 10 additions & 0 deletions data/os/Suse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
profile_update_os::yum_upgrade::command: "zypper update -y"
profile_update_os::yum_upgrade::config_file: ""
profile_update_os::yum_upgrade::excluded_packages:
- "kernel-default"
- "kernel-default-extra"
- "kernel-default-optional"
profile_update_os::yum_upgrade::package: "zypper"
profile_update_os::yum_upgrade::service: ""
profile_update_os::yum_upgrade::yum_config_file: "/etc/zypp/zypp.conf"
billglick marked this conversation as resolved.
Show resolved Hide resolved
133 changes: 133 additions & 0 deletions files/root/cron_scripts/kernel_upgrade.sh.Suse
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/bash
# KERNEL UPGRADE SCRIPT FOR SUSE

# DEFAULT VALUES
DEF_SHUTDOWN_MESSAGE="This server ($(hostname)) WILL be rebooted for a scheduled kernel upgrade. Please log out now."
DEF_NUM_UPDATES_TODAY=5
DEF_UPDATES_SINCE_REBOOT=10
DEF_PKGS_REQ_REBOOT="kernel|dkms|lustre|zfs|lib"
DEF_WAITMAX=30
DEF_WAITMIN=5

function usage()
{
echo "usage: `basename $0` [OPTION]..."
echo "Attempt to update kernel packages and optionally reboot"
echo
echo "Options:"
echo " -n, --now, --nodelay Apply with no wait delay, ignore waitmax & waitmin"
echo " --message MESSAGE Message to display to users before reboot"
echo " -r, --reboot Force reboot always"
echo " --reboot_pkgs Regular expression of update packages that should"
echo " always trigger a fresh reboot if updated"
echo " --updates_today Minimum number of packages updated today to trigger"
echo " a fresh reboot"
echo " --updates_reboot Minimum number of packages updated since reboot to"
echo " trigger a fresh reboot"
echo " --waitmax Maximum time to sleep before updating"
echo " --waitmin Minimum time to sleep before updating"
echo " -h, --help Display help"
exit 1
}

# PARSE PARAMETERS AND ASSIGN VALUES
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
--message )
shift; SHUTDOWN_MESSAGE="$1"
;;
-n | --now | --nodelay )
NODELAY=1
;;
-r | --reboot )
REBOOT=1
;;
--reboot_pkgs )
shift; PKGS_REQ_REBOOT="$1"
;;
--updates_today )
shift; NUM_PKG_UPDATES_TODAY_REBOOT=$1
;;
--updates_reboot )
shift; NUM_PKG_UPDATES_SINCE_REBOOT=$1
;;
--waitmax )
shift; WAITMAX="$1"
;;
--waitmin )
shift; WAITMIN="$1"
;;
-h | --help )
usage; exit
;;
* )
usage; exit 1
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi

# SET DEFAULTS IF NOT MANUALLY SET
SHUTDOWN_MESSAGE="${SHUTDOWN_MESSAGE:=$DEF_SHUTDOWN_MESSAGE}"
NODELAY=${NODELAY:=0}
REBOOT=${REBOOT:=0}
NUM_UPDATES_TODAY=${NUM_PKG_UPDATES_TODAY_REBOOT:=$DEF_NUM_UPDATES_TODAY}
UPDATES_SINCE_REBOOT=${NUM_PKG_UPDATES_SINCE_REBOOT:=$DEF_UPDATES_SINCE_REBOOT}
PKGS_REQ_REBOOT="${PKGS_REQ_REBOOT:=$DEF_PKGS_REQ_REBOOT}"
WAITMAX="${WAITMAX:=$DEF_WAITMAX}"
WAITMIN="${WAITMIN:=$DEF_WAITMIN}"

# CALCULATE WAIT TIME
if [[ $NODELAY -ge 1 ]]; then
WAITTIME=0
else
WAITTIME=`shuf -i $WAITMIN-$WAITMAX -n 1`
fi

# SHUTDOWN NOTICE
#echo $SHUTDOWN_MESSAGE
wall -n "$SHUTDOWN_MESSAGE"

# SLEEP 0 OR MORE MINUTES
#echo "Waiting for $WAITTIME minutes before applying updates"
sleep $((WAITTIME))m

wall -n "$SHUTDOWN_MESSAGE"
/sbin/shutdown -k now "$SHUTDOWN_MESSAGE"

# KERNEL UPDATE
mv /etc/zypp/locks /etc/zypp/locks.temp.disabled && \
/usr/bin/zypper update -y kernel 'kernel*'
mv /etc/zypp/locks.temp.disabled /etc/zypp/locks

# REBOOT IF NECESSARY
LASTREBOOTDATE=`last reboot | head -1 | awk '{ print $5 " " $6 " " $7 }'`
DATEFORMAT="%a %b %_d"
LASTBOOTDATE=`date -d "$LASTREBOOTDATE" +"${DATEFORMAT}"`
TODAYDATE=`date +"${DATEFORMAT}"`
PKG_UPDATES_REQ_REBOOT=`rpm -qa --last | grep -B1000 "$LASTBOOTDATE" | grep -v "$LASTBOOTDATE" | egrep -i "$PKGS_REQ_REBOOT" | wc -l`
PKG_UPDATES=`rpm -qa --last | grep -B1000 "$LASTBOOTDATE" | grep -v "$LASTBOOTDATE" | wc -l`
PKG_UPDATES_TODAY=`rpm -qa --last | grep -B1000 "$TODAYDATE" | wc -l`
KERNEL_UPDATES_TODAY=`rpm -qa --last | grep -B1000 "$TODAYDATE" | egrep -i 'kernel-[0-9]' | wc -l`
#echo "Last reboot: $LASTBOOTDATE"
#echo "Today's date: $TODAYDATE"
#echo "Package updates requiring reboot since last reboot: $PKG_UPDATES_REQ_REBOOT"
#echo "Package updates since last reboot: $PKG_UPDATES"
#echo "Package updates today: $PKG_UPDATES_TODAY"

if [[ $PKG_UPDATES_REQ_REBOOT -gt 0 ]] ||
[[ $((PKG_UPDATES)) -ge $((UPDATES_SINCE_REBOOT)) ]] ||
[[ $((PKG_UPDATES_TODAY)) -ge $((NUM_UPDATES_TODAY)) ]] ||
[[ $((KERNEL_UPDATES_TODAY)) -gt 1 ]] ||
[[ $((REBOOT)) -ge 1 ]] ; then
echo "REBOOTING SERVER..."
logger -s -t "puppet-debug" $SHUTDOWN_MESSAGE
# echo $SHUTDOWN_MESSAGE
wall -n "$SHUTDOWN_MESSAGE"
/sbin/shutdown -r now "$SHUTDOWN_MESSAGE"
else
echo "SKIPPING SERVER REBOOT..."
NO_SHUTDOWN_MESSAGE="No updates require reboot of this server ($(hostname -f)). Cancelling reboot."
logger -s -t "puppet-debug" "$NO_SHUTDOWN_MESSAGE"
# echo $NO_SHUTDOWN_MESSAGE
/sbin/shutdown -c
wall -n "$NO_SHUTDOWN_MESSAGE"
fi

16 changes: 10 additions & 6 deletions manifests/kernel_upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,16 @@
}

file { 'kernel_upgrade.sh':
ensure => 'file',
path => "${profile_update_os::root_cron_scripts_dir}/kernel_upgrade.sh",
source => "puppet:///modules/${module_name}/root/cron_scripts/kernel_upgrade.sh",
owner => 'root',
group => 'root',
mode => '0700',
ensure => 'file',
path => "${profile_update_os::root_cron_scripts_dir}/kernel_upgrade.sh",
source => [
"puppet:///modules/${module_name}/root/cron_scripts/kernel_upgrade.sh.${facts['os']['family']}",
"puppet:///modules/${module_name}/root/cron_scripts/kernel_upgrade.sh",
],
sourceselect => 'first',
owner => 'root',
group => 'root',
mode => '0700',
}
}
else {
Expand Down
Loading
Loading