Skip to content

Commit 9aabe24

Browse files
authored
Merge pull request #2320 from ekohl/clean-up-selinux-in-acceptance
Clean up SELinux handling in acceptance testing.
2 parents 29faa1a + 12ab304 commit 9aabe24

File tree

4 files changed

+43
-45
lines changed

4 files changed

+43
-45
lines changed

spec/acceptance/apache_parameters_spec.rb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -428,34 +428,30 @@ class { 'apache':
428428
describe 'logging' do
429429
describe 'setup' do
430430
pp = <<-MANIFEST
431-
if $::osfamily == 'RedHat' and "$::selinux" == "true" {
432-
$semanage_package = $::operatingsystemmajrelease ? {
433-
'6' => 'policycoreutils-python',
434-
'7' => 'policycoreutils-python',
435-
default => 'policycoreutils-python-utils',
436-
}
437-
package { $semanage_package: ensure => installed }
431+
if $facts['osfamily'] == 'RedHat' and $facts['selinux'] {
438432
exec { 'set_apache_defaults':
439-
command => 'semanage fcontext -a -t httpd_log_t "/apache_spec(/.*)?"',
433+
command => 'semanage fcontext -a -t httpd_log_t "/apache_spec/logs(/.*)?"',
434+
unless => 'semanage fcontext --list | grep /apache_spec/logs | grep httpd_log_t',
440435
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
441-
require => Package[$semanage_package],
442436
}
443437
exec { 'restorecon_apache':
444-
command => 'restorecon -Rv /apache_spec',
445-
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
446-
before => Service['httpd'],
447-
require => Class['apache'],
438+
command => 'restorecon -Rv /apache_spec',
439+
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
440+
before => Service['httpd'],
441+
require => [File['/apache_spec'], Class['apache']],
442+
subscribe => Exec['set_apache_defaults'],
443+
refreshonly => true,
448444
}
449445
}
450-
file { '/apache_spec': ensure => directory, }
451-
class { 'apache': logroot => '/apache_spec' }
446+
file { ['/apache_spec', '/apache_spec/logs']: ensure => directory, }
447+
class { 'apache': logroot => '/apache_spec/logs' }
452448
MANIFEST
453449
it 'applies cleanly' do
454450
apply_manifest(pp, catch_failures: true)
455451
end
456452
end
457453

458-
describe file("/apache_spec/#{apache_hash['error_log']}") do
454+
describe file("/apache_spec/logs/#{apache_hash['error_log']}") do
459455
it { is_expected.to be_file }
460456
end
461457
end

spec/acceptance/class_spec.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,24 @@
4141
context 'custom site/mod dir parameters' do
4242
let(:pp) do
4343
<<-MANIFEST
44-
if $::osfamily == 'RedHat' and "$::selinux" == "true" {
45-
$semanage_package = $::operatingsystemmajrelease ? {
46-
'6' => 'policycoreutils-python',
47-
'7' => 'policycoreutils-python',
48-
default => 'policycoreutils-python-utils',
49-
}
50-
package { $semanage_package: ensure => installed }
44+
if $facts['osfamily'] == 'RedHat' and $facts['selinux'] {
5145
exec { 'set_apache_defaults':
52-
command => 'semanage fcontext -a -t httpd_sys_content_t "/apache_spec(/.*)?"',
53-
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
54-
subscribe => Package[$semanage_package],
55-
refreshonly => true,
46+
command => 'semanage fcontext --add -t httpd_config_t "/apache_spec/apache_custom(/.*)?"',
47+
unless => 'semanage fcontext --list | grep /apache_spec/apache_custom | grep httpd_config_t',
48+
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
5649
}
5750
exec { 'restorecon_apache':
5851
command => 'restorecon -Rv /apache_spec',
5952
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
6053
before => Service['httpd'],
61-
require => Class['apache'],
54+
require => [File['/apache_spec/apache_custom'], Class['apache']],
6255
subscribe => Exec['set_apache_defaults'],
6356
refreshonly => true,
6457
}
6558
}
66-
file { '/apache_spec': ensure => directory, }
67-
file { '/apache_spec/apache_custom': ensure => directory, }
59+
file { ['/apache_spec', '/apache_spec/apache_custom']:
60+
ensure => directory,
61+
}
6862
class { 'apache':
6963
mod_dir => '/apache_spec/apache_custom/mods',
7064
vhost_dir => '/apache_spec/apache_custom/vhosts',

spec/acceptance/vhost_spec.rb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,36 +1171,33 @@ class { 'apache::mod::wsgi': }
11711171

11721172
describe 'additional_includes' do
11731173
pp = <<-MANIFEST
1174-
if $::osfamily == 'RedHat' and "$::selinux" == "true" {
1175-
$semanage_package = $::operatingsystemmajrelease ? {
1176-
'6' => 'policycoreutils-python',
1177-
'7' => 'policycoreutils-python',
1178-
default => 'policycoreutils-python-utils',
1179-
}
1180-
package { $semanage_package: ensure => installed }
1174+
if $facts['osfamily'] == 'RedHat' and $facts['selinux'] {
11811175
exec { 'set_apache_defaults':
1182-
command => 'semanage fcontext -a -t httpd_sys_content_t "/apache_spec(/.*)?"',
1176+
command => 'semanage fcontext --add -t httpd_sys_content_t "/apache_spec/docroot(/.*)?"',
1177+
unless => 'semanage fcontext --list | grep /apache_spec/docroot | grep httpd_sys_content_t',
11831178
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
1184-
require => Package[$semanage_package],
11851179
}
11861180
exec { 'restorecon_apache':
11871181
command => 'restorecon -Rv /apache_spec',
11881182
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
1189-
before => Service['httpd'],
1190-
require => Class['apache'],
1183+
before => Service['httpd'],
1184+
require => [File['/apache_spec/include'], Class['apache']],
1185+
subscribe => Exec['set_apache_defaults'],
1186+
refreshonly => true,
11911187
}
11921188
}
11931189
class { 'apache': }
11941190
host { 'test.server': ip => '127.0.0.1' }
1195-
file { '/apache_spec': ensure => directory, }
1191+
file { ['/apache_spec', '/apache_spec/docroot']: ensure => directory, }
11961192
file { '/apache_spec/include': ensure => present, content => '#additional_includes' }
11971193
apache::vhost { 'test.server':
1198-
docroot => '/apache_spec',
1194+
docroot => '/apache_spec/docroot',
11991195
additional_includes => '/apache_spec/include',
12001196
}
12011197
MANIFEST
1202-
it 'applies cleanly' do
1203-
apply_manifest(pp, catch_failures: false)
1198+
1199+
it 'behaves idempotently' do
1200+
idempotent_apply(pp)
12041201
end
12051202

12061203
describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do

spec/setup_acceptance_node.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
}
1919
}
2020

21+
if $facts['selinux'] {
22+
$semanage_package = $facts['os']['release']['major'] ? {
23+
'6' => 'policycoreutils-python',
24+
'7' => 'policycoreutils-python',
25+
default => 'policycoreutils-python-utils',
26+
}
27+
package { $semanage_package:
28+
ensure => installed,
29+
}
30+
}
31+
2132
if versioncmp($facts['os']['release']['major'], '8') >= 0 {
2233
package { 'iproute':
2334
ensure => installed,

0 commit comments

Comments
 (0)