Skip to content

Commit

Permalink
Refs #37130 - Set the mode on the generated bootstrap RPM
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Mar 13, 2024
1 parent 1c0d8a8 commit 5197ba7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
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,12 +102,19 @@ def build_rpm

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

def copy_srpm
FileUtils.copy(built_srpm, resource[:dest])
end

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

def rpm_changed?
changed = true
return changed unless latest_rpm
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 }

Check failure on line 39 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm" is expected to be file Failure/Error: it { should be_file } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm".file?` to be truthy, got false

Check failure on line 39 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm" is expected to be file Failure/Error: it { should be_file } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm".file?` to be truthy, got false

Check failure on line 39 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm" is expected to be file Failure/Error: it { should be_file } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm".file?` to be truthy, got false

Check failure on line 39 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm" is expected to be file Failure/Error: it { should be_file } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm".file?` to be truthy, got false
it { should be_mode 644 }

Check failure on line 40 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm" is expected to be mode 644 Failure/Error: it { should be_mode 644 } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm".mode?(644)` to be truthy, got false

Check failure on line 40 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm" is expected to be mode 644 Failure/Error: it { should be_mode 644 } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm".mode?(644)` to be truthy, got false

Check failure on line 40 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm" is expected to be mode 644 Failure/Error: it { should be_mode 644 } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm".mode?(644)` to be truthy, got false

Check failure on line 40 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm" is expected to be mode 644 Failure/Error: it { should be_mode 644 } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm".mode?(644)` to be truthy, got false
it { should be_owned_by 'root' }

Check failure on line 41 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm" is expected to be owned by "root" Failure/Error: it { should be_owned_by 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm".owned_by?("root")` to be truthy, got false

Check failure on line 41 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm" is expected to be owned by "root" Failure/Error: it { should be_owned_by 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm".owned_by?("root")` to be truthy, got false

Check failure on line 41 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm" is expected to be owned by "root" Failure/Error: it { should be_owned_by 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm".owned_by?("root")` to be truthy, got false

Check failure on line 41 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm" is expected to be owned by "root" Failure/Error: it { should be_owned_by 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm".owned_by?("root")` to be truthy, got false
it { should be_grouped_into 'root' }

Check failure on line 42 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm" is expected to be grouped into "root" Failure/Error: it { should be_grouped_into 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet8.example.com-1.0-1.src.rpm".grouped_into?("root")` to be truthy, got false

Check failure on line 42 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 8

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm" is expected to be grouped into "root" Failure/Error: it { should be_grouped_into 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos8-64-puppet7.example.com-1.0-1.src.rpm".grouped_into?("root")` to be truthy, got false

Check failure on line 42 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm" is expected to be grouped into "root" Failure/Error: it { should be_grouped_into 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet8.example.com-1.0-1.src.rpm".grouped_into?("root")` to be truthy, got false

Check failure on line 42 in spec/acceptance/bootstrap_rpm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9

bootstrap_rpm with default params File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm" is expected to be grouped into "root" Failure/Error: it { should be_grouped_into 'root' } expected `File "/var/www/html/pub/katello-ca-consumer-centos9-64-puppet7.example.com-1.0-1.src.rpm".grouped_into?("root")` to be truthy, got false
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

0 comments on commit 5197ba7

Please sign in to comment.