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

Refs #37130 - Set the mode on the generated bootstrap RPM #477

Merged
merged 1 commit into from
Mar 15, 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
15 changes: 12 additions & 3 deletions lib/puppet/provider/bootstrap_rpm/bootstrap_rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def symlink=(value)
link_rpm(value)
end

def latest_rpm
rpms = Dir.glob("#{resource[:dest]}/#{resource[:name]}*.noarch.rpm")
def latest_rpm(source: false)
extension = source ? 'src.rpm' : 'noarch.rpm'

rpms = Dir.glob("#{resource[:dest]}/#{resource[:name]}*.#{extension}")
rpms = rpms.reject { |rpm| rpm.end_with?("latest.noarch.rpm") }

return false if rpms.empty?
Expand Down Expand Up @@ -89,7 +91,7 @@ def release
end

def build_rpm
output = rpmbuild(
rpmbuild(
'-ba',
File.join(spec_dir, "#{resource[:name]}.spec"),
'--define', "_topdir #{base_dir}",
Expand All @@ -100,10 +102,17 @@ def build_rpm

def copy_rpm
FileUtils.copy(built_rpm, resource[:dest])
set_ownership(latest_rpm)
end

def copy_srpm
FileUtils.copy(built_srpm, resource[:dest])
set_ownership(latest_rpm(source: true))
end

def set_ownership(file)
File.chmod(resource[:mode].to_i(8), file)
FileUtils.chown(resource[:owner], resource[:group], file)
end

def rpm_changed?
Expand Down
23 changes: 0 additions & 23 deletions lib/puppet/type/bootstrap_rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,4 @@ def insync?(is)
def refresh
provider.create
end

def generate
file_opts = {
ensure: (self[:ensure] == :absent) ? :absent : :file,
path: "#{self[:dest]}/#{self[:name]}",
}

[:owner,
:group,
:mode].each do |param|
file_opts[param] = self[param] unless self[param].nil?
end

excluded_metaparams = [:before, :notify, :require, :subscribe, :tag]

Puppet::Type.metaparams.each do |metaparam|
unless self[metaparam].nil? || excluded_metaparams.include?(metaparam)
file_opts[metaparam] = self[metaparam]
end
end

[Puppet::Type.type(:file).new(file_opts)]
end
end
57 changes: 57 additions & 0 deletions spec/acceptance/bootstrap_rpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
it { should be_grouped_into 'root' }
end

describe file("/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-1.src.rpm") do
it { should be_file }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file("/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-2.noarch.rpm") do
it { should_not exist }
end
Expand Down Expand Up @@ -213,4 +220,54 @@ class { 'foreman_proxy_content::bootstrap_rpm':
it { should be_linked_to "/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-10.noarch.rpm" }
end
end

context 'generates bootstrapm RPM with proper mode with 0077 umask' do
before(:all) do
on hosts, 'rm -rf /var/www/html/pub/*rpm'
on hosts, "echo 'umask 0077' > /etc/profile.d/umask.sh"
end

it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
include foreman_proxy_content::bootstrap_rpm
PUPPET
end
end

describe file("/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-1.noarch.rpm") do
it { should be_file }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end

context 'correctly sets the mode on subsequent RPMs' do
it 'applies again without error' do
apply_manifest(
"class { 'foreman_proxy_content::bootstrap_rpm': rhsm_port => 8447, }",
catch_failures: true
)
end

describe file("/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-2.noarch.rpm") do
it { should be_file }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file("/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-2.src.rpm") do
it { should be_file }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/var/www/html/pub/katello-ca-consumer-latest.noarch.rpm') do
it { should be_symlink }
it { should be_linked_to "/var/www/html/pub/katello-ca-consumer-#{host_inventory['fqdn']}-1.0-2.noarch.rpm" }
end
end
end