Add image upload log arguments

Add image upload log directory and arguments.  This is where provider
upload logs configured in Ic80e532891f039e0f835847ddfbae38f1ce3cd8aIf
can be stored.

Note http export (which we do not enable in infra at this time) would
put logs under /upload ; it might be more logical to move the build
logs to be a sibling at /build but that would be backwards
incompatbile.

Change-Id: I0cc9b59063fb14920f0da581b8036c2664d5d5f1
This commit is contained in:
Ian Wienand 2016-11-07 17:18:11 +11:00
parent d70a85b686
commit cd086492a4
2 changed files with 62 additions and 3 deletions

View File

@ -29,6 +29,10 @@ class nodepool (
$image_log_document_root = '/var/log/nodepool/image',
$image_log_periodic_cleanup = false,
$enable_image_log_via_http = false,
$upload_log_document_root = '/var/log/nodepool/upload',
$upload_log_periodic_cleanup = false,
# note : not currently supported
$enable_upload_log_via_http = false,
$environment = {},
# enable sudo for nodepool user. Useful for using dib with nodepool
$sudo = true,
@ -342,8 +346,24 @@ class nodepool (
require => File['/etc/init.d/nodepool'],
}
if $enable_image_log_via_http == true {
# Setup apache for image log access
if $image_log_document_root == $upload_log_document_root {
# It makes no sense to ask to not export build or upload logs, but
# then have them log to the same directory that will be exported.
if (($enable_image_log_via_http and !$enable_upload_log_via_http) or
($enable_upload_log_via_http and !$enable_image_log_via_http)
) {
fail('Unexported logs in same directory as exported logs!')
}
}
# we only need to create the upload log dir if it is separate to the
# image log.
$separate_upload_log_dir =
$image_log_document_root != $upload_log_document_root
if $enable_image_log_via_http == true or
$enable_upload_log_via_http == true {
# Setup apache for log access
include ::httpd
::httpd::vhost { $vhost_name:
@ -376,6 +396,21 @@ class nodepool (
}
}
# we only need this if it is different to the image_log
if $separate_upload_log_dir
{
file { $upload_log_document_root:
ensure => directory,
mode => '0755',
owner => 'nodepool',
group => 'nodepool',
require => [
User['nodepool'],
File['/var/log/nodepool'],
],
}
}
# run a cleanup on the image log directory to cleanup logs for
# images that are no longer being built
if $image_log_periodic_cleanup == true {
@ -388,6 +423,18 @@ class nodepool (
}
}
# run a cleanup on the upload log directory to cleanup logs for
# providers that are no long uploading
if $upload_log_periodic_cleanup == true {
cron { 'upload_log_cleanup':
user => 'nodepool',
hour => '1',
minute => '0',
command => "find ${upload_log_document_root} \\( -name '*.log' -o -name '*.log.*' \\) -mtime +7 -execdir rm {} \\;",
environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin',
}
}
if $sudo == true {
$sudo_file_ensure = present
}

View File

@ -2,11 +2,23 @@
ServerName <%= scope.lookupvar("nodepool::vhost_name") %>
DocumentRoot <%= scope.lookupvar("nodepool::image_log_document_root") %>
<% if scope.lookupvar("nodepool::enable_image_log_via_http") -%>
<Directory <%= scope.lookupvar("nodepool::image_log_document_root") %>>
Options <%= scope.lookupvar("httpd::params::options") %>
AllowOverride None
Require all granted
</Directory>
</Directory>
<% end -%>
<% if scope.lookupvar("nodepool::enable_upload_log_via_http") and scope.lookupvar("nodepool::separate_upload_log_dir") -%>
Alias "/upload" <%= scope.lookupvar("nodepool::upload_log_document_root") %>
<Directory <%= scope.lookupvar("nodepool::upload_log_document_root") %> >
Options <%= scope.lookupvar("httpd::params::options") %>
AllowOverride None
Require all granted
</Directory>
<% end -%>
ErrorLog /var/log/<%= scope.lookupvar("httpd::params::apache_name") %>/nodepool_error.log
LogLevel warn