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

untar fdi-image as proxy user/group #774

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions examples/discovery_images.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class { 'foreman_proxy':
tftp => true,
}
class { 'foreman_proxy::plugin::discovery':
install_images => true,
}
4 changes: 4 additions & 0 deletions manifests/plugin/discovery.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@
foreman_proxy::remote_file { "${tftp_root_clean}/boot/${image_name}":
remote_location => "${source_url}${image_name}",
mode => '0644',
owner => $foreman_proxy::user,
group => $foreman_proxy::group,
} ~> exec { "untar ${image_name}":
command => "tar xf ${image_name}",
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
cwd => "${tftp_root_clean}/boot",
creates => "${tftp_root_clean}/boot/fdi-image/initrd0.img",
user => $foreman_proxy::user,
group => $foreman_proxy::group,
}
}
}
4 changes: 4 additions & 0 deletions manifests/remote_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
define foreman_proxy::remote_file (
Stdlib::Filesource $remote_location,
Stdlib::Filemode $mode = '0644',
Optional[String[1]] $owner = undef,
Optional[String[1]] $group = undef,
) {
$parent = dirname($title)
File <| title == $parent |>
Expand All @@ -13,6 +15,8 @@
-> file { $title:
source => $remote_location,
mode => $mode,
owner => $owner,
group => $group,
replace => false,
}
}
42 changes: 38 additions & 4 deletions spec/acceptance/discovery_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
require 'spec_helper_acceptance'
require 'json'

shared_examples 'the discovery feature is enabled' do
describe command('curl -sk https://127.0.0.1:8443/features') do
it { expect(JSON.parse(subject.stdout)).to include('discovery', 'logs') }
its(:exit_status) { is_expected.to eq (0) }
end
end

describe 'Scenario: install foreman-proxy with discovery plugin' do
before(:context) { purge_foreman_proxy }

include_examples 'the example', 'discovery.pp'
context 'without params' do
include_examples 'the example', 'discovery.pp'

it_behaves_like 'the default foreman proxy application'
it_behaves_like 'the discovery feature is enabled'
end

context 'with install_images param' do
include_examples 'the example', 'discovery_images.pp'

it_behaves_like 'the default foreman proxy application'
it_behaves_like 'the discovery feature is enabled'

it_behaves_like 'the default foreman proxy application'
%w[
/boot/fdi-image-latest.tar
/boot/fdi-image/initrd0.img
/boot/fdi-image/vmlinuz0
].each do |f|
describe file(File.join(tftp_root, f)) do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'foreman-proxy' }
it { is_expected.to be_grouped_into 'foreman-proxy' }
it { is_expected.to be_mode '644' }
end
end

describe command('curl -sk https://127.0.0.1:8443/features | grep -q discovery') do
its(:exit_status) { should eq 0 }
describe file(File.join(tftp_root, '/boot/fdi-image')) do
it { is_expected.to be_directory }
it { is_expected.to be_owned_by 'foreman-proxy' }
it { is_expected.to be_grouped_into 'foreman-proxy' }
it { is_expected.to be_mode '755' }
end
end
end
15 changes: 1 addition & 14 deletions spec/acceptance/netboot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,7 @@

include_examples 'the example', 'tftp.pp'

root = case host_inventory['facter']['os']['name']
when 'Debian'
'/srv/tftp'
when 'Ubuntu'
if host_inventory['facter']['os']['release']['major'].to_f >= 20.04
'/srv/tftp'
else
'/var/lib/tftpboot'
end
else
'/var/lib/tftpboot'
end

describe file("#{root}/grub2/boot") do
describe file("#{tftp_root}/grub2/boot") do
it { should be_symlink }
it { should be_linked_to '../boot' }
end
Expand Down
8 changes: 6 additions & 2 deletions spec/classes/foreman_proxy__plugin__discovery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'foreman-proxy'
end
end
let(:user) { group }

describe 'without paramaters' do
it { should compile.with_all_deps }
Expand Down Expand Up @@ -62,8 +63,11 @@
it { should contain_foreman_proxy__feature('Discovery') }

it 'should download and install tarball' do
should contain_foreman_proxy__remote_file("#{tftproot}/boot/fdi-image-latest.tar").
with_remote_location('http://downloads.theforeman.org/discovery/releases/latest/fdi-image-latest.tar')
should contain_foreman_proxy__remote_file("#{tftproot}/boot/fdi-image-latest.tar").with(
remote_location: 'http://downloads.theforeman.org/discovery/releases/latest/fdi-image-latest.tar',
owner: user,
group: group,
)
end

it 'should extract the tarball' do
Expand Down
67 changes: 50 additions & 17 deletions spec/defines/foreman_proxy_remote_file_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
require 'spec_helper'

shared_examples 'remote_file' do
it { is_expected.to contain_exec('mkdir -p /tmp') }
end

describe 'foreman_proxy::remote_file' do
let(:title) { '/tmp/a' }

let(:params) do
{
remote_location: 'https://example.com/tmp/a',
mode: '0664'
}
end
context 'without owner/group params' do
let(:params) do
{
remote_location: 'https://example.com/tmp/a',
mode: '0664'
}
end

context 'default scenario' do
it { is_expected.to contain_exec('mkdir -p /tmp') }
context 'default scenario' do
include_examples 'remote_file'

it do
is_expected.to contain_file('/tmp/a')
.with_source('https://example.com/tmp/a')
.with_mode('0664')
.that_requires('Exec[mkdir -p /tmp]')
it do
is_expected.to contain_file('/tmp/a').with(
source: 'https://example.com/tmp/a',
mode: '0664',
owner: nil,
group: nil,
).without(
).that_requires('Exec[mkdir -p /tmp]')
Comment on lines +27 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
).without(
).that_requires('Exec[mkdir -p /tmp]')
).that_requires('Exec[mkdir -p /tmp]')

end
end

context 'with parent file defined' do
let :pre_condition do
"file { '/tmp': }"
end

include_examples 'remote_file'

it { is_expected.to contain_exec('mkdir -p /tmp').that_requires('File[/tmp]') }
end
end

context 'with parent file defined' do
let :pre_condition do
"file { '/tmp': }"
context 'with owner/group params' do
let(:params) do
{
remote_location: 'https://example.com/tmp/a',
mode: '0664',
owner: 'foo',
group: 'bar',
}
end

it { is_expected.to contain_exec('mkdir -p /tmp').that_requires('File[/tmp]') }
include_examples 'remote_file'

it do
is_expected.to contain_file('/tmp/a').with(
source: 'https://example.com/tmp/a',
mode: '0664',
owner: 'foo',
group: 'bar',
).that_requires('Exec[mkdir -p /tmp]')
end
end
end
8 changes: 8 additions & 0 deletions spec/support/acceptance/tftp_root.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def tftp_root
case host_inventory['facter']['os']['name']
when 'Debian', 'Ubuntu'
'/srv/tftp'
else
'/var/lib/tftpboot'
end
end