Skip to content

Commit

Permalink
Fix ordering issue with conf_file and ports_file
Browse files Browse the repository at this point in the history
The httpd.conf.erb template explicitly includes the $ports_file, but the resource that uses that
template doesn't have a dependency on $ports_file. This means it's possible for a declaration of the
apache::custom_config resource to get run between when $conf_file is written and $ports_file is
written. This will cause syntax verification via "apachectl -t" to always fail, causing the
custom_config to be removed if the $verify_config flag is set to "true". Example:

    ==> ops: Notice: /Stage[main]/Jci_nagios::Server/Apache::Custom_config[cgid]/Exec[service notify for cgid]/returns: httpd: Syntax error on line 37 of /etc/httpd/conf/httpd.conf: Could not open configuration file /etc/httpd/conf/ports.conf: No such file or directory
    ==> ops: Error: /Stage[main]/Jci_nagios::Server/Apache::Custom_config[cgid]/Exec[service notify for cgid]: Failed to call refresh: /usr/sbin/apachectl -t returned 1 instead of one of [0]
    ==> ops: Error: /Stage[main]/Jci_nagios::Server/Apache::Custom_config[cgid]/Exec[service notify for cgid]: /usr/sbin/apachectl -t returned 1 instead of one of [0]
    ==> ops: Notice: /Stage[main]/Jci_nagios::Server/Apache::Custom_config[cgid]/Exec[remove cgid if invalid]: Triggered 'refresh' from 1 events

I wrote a test that reproduces this behavior by using ordering arrows to force apache::custom_config
to run before $ports_file is written. This is rather artificial, but I wasn't able to get this is
happen "naturally" in the test environment. Take my word for it that it's possible.
  • Loading branch information
MasonM committed Oct 21, 2015
1 parent f515778 commit e226ba8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
ensure => file,
content => template($conf_template),
notify => Class['Apache::Service'],
require => Package['httpd'],
require => [Package['httpd'], File[$ports_file]],
}

# preserve back-wards compatibility to the times when default_mods was
Expand Down
21 changes: 21 additions & 0 deletions spec/acceptance/custom_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,25 @@ class { 'apache': }
it { is_expected.to be_file }
end
end

describe 'custom_config only applied after configs are written' do
it 'applies in the right order' do
pp = <<-EOS
class { 'apache': }
apache::custom_config { 'ordering_test':
content => '# just a comment',
}
# Try to wedge the apache::custom_config call between when httpd.conf is written and
# ports.conf is written. This should trigger a dependency cycle
File["#{$conf_file}"] -> Apache::Custom_config['ordering_test'] -> File["#{$ports_file}"]
EOS
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Failed to apply catalog: Found 1 dependency cycle/i)
end

describe file("#{$confd_dir}/25-ordering_test.conf") do
it { is_expected.not_to be_file }
end
end
end
2 changes: 1 addition & 1 deletion spec/classes/apache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
it { is_expected.to contain_file("/opt/rh/root/etc/httpd/conf/httpd.conf").with(
'ensure' => 'file',
'notify' => 'Class[Apache::Service]',
'require' => 'Package[httpd]'
'require' => ['Package[httpd]', 'File[/etc/httpd/conf/ports.conf]'],
) }
end

Expand Down

0 comments on commit e226ba8

Please sign in to comment.