diff options
-rw-r--r-- | lib/puppet/parser/functions/write_package_names.rb | 22 | ||||
-rw-r--r-- | lib/puppet/provider/package_manifest/flat_file.rb | 39 | ||||
-rw-r--r-- | lib/puppet/type/package_manifest.rb | 8 | ||||
-rw-r--r-- | manifests/loadbalancer.pp | 63 | ||||
-rw-r--r-- | spec/unit/type/package_manifest_spec.rb | 37 |
5 files changed, 94 insertions, 75 deletions
diff --git a/lib/puppet/parser/functions/write_package_names.rb b/lib/puppet/parser/functions/write_package_names.rb deleted file mode 100644 index 8f99674..0000000 --- a/lib/puppet/parser/functions/write_package_names.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'fileutils' - -module Puppet::Parser::Functions - newfunction(:write_package_names, :doc => "Write package names which are managed via this puppet run to a file.") do |arg| - if arg[0].class == String - begin - output_file = arg[0] - packages = catalog.resources.collect { |r| r.title if r.type == 'Package' }.compact - FileUtils.mkdir_p(File.dirname(output_file)) - File.open(output_file, 'w') do |f| - packages.each do |pkg_name| - f.write(pkg_name + "\n") - end - end - rescue JSON::ParserError - raise Puppet::ParseError, "Syntax error: #{arg[0]} is invalid" - end - else - raise Puppet::ParseError, "Syntax error: #{arg[0]} is not a String" - end - end -end diff --git a/lib/puppet/provider/package_manifest/flat_file.rb b/lib/puppet/provider/package_manifest/flat_file.rb new file mode 100644 index 0000000..96e033b --- /dev/null +++ b/lib/puppet/provider/package_manifest/flat_file.rb @@ -0,0 +1,39 @@ + +require 'set' + + +Puppet::Type.type(:package_manifest).provide(:flat_file) do + + desc "Write package manifest to a flat file" + + def exists? + # exists? is always run before create, so we can create package list here + @packages = resource.catalog.resources.collect { |r| + r.name if r.type == :package + }.compact.sort + + exists = File.exist?(resource[:path]) + if exists + new_content = Set.new @packages + old_content = Set.new( + File.open(resource[:path], 'r').each_line.collect{ |pkg| pkg.strip() } + ) + exists = new_content == old_content + end + exists + end + + def create + FileUtils.mkdir_p(File.dirname(resource[:path])) + File.open(resource[:path], 'w') do |f| + @packages.each do |pkg_name| + f.puts(pkg_name) + end + end + end + + def destroy + File.delete(resource[:path]) + end + +end diff --git a/lib/puppet/type/package_manifest.rb b/lib/puppet/type/package_manifest.rb new file mode 100644 index 0000000..9ee3270 --- /dev/null +++ b/lib/puppet/type/package_manifest.rb @@ -0,0 +1,8 @@ +Puppet::Type.newtype(:package_manifest) do + + ensurable + newparam(:path, :namevar => true) do + newvalues(/\S+\/\S+/) + end + +end diff --git a/manifests/loadbalancer.pp b/manifests/loadbalancer.pp index 6797d9e..e30d76e 100644 --- a/manifests/loadbalancer.pp +++ b/manifests/loadbalancer.pp @@ -573,7 +573,6 @@ class tripleo::loadbalancer ( "${public_virtual_ip}:13004" => ['ssl', 'crt', $heat_bind_certificate], } $heat_options = { - 'option' => [ 'httpchk GET /' ], 'rsprep' => "^Location:\\ http://${public_virtual_ip}(.*) Location:\\ https://${public_virtual_ip}\\1", } $heat_cw_bind_opts = { @@ -589,9 +588,7 @@ class tripleo::loadbalancer ( "${heat_api_vip}:8004" => [], "${public_virtual_ip}:8004" => [], } - $heat_options = { - 'option' => [ 'httpchk GET /' ], - } + $heat_options = {} $heat_cw_bind_opts = { "${heat_api_vip}:8003" => [], "${public_virtual_ip}:8003" => [], @@ -644,12 +641,17 @@ class tripleo::loadbalancer ( 'mode' => 'tcp', 'log' => 'global', 'retries' => '3', - 'option' => [ 'tcpka', 'tcplog' ], 'timeout' => [ 'http-request 10s', 'queue 1m', 'connect 10s', 'client 1m', 'server 1m', 'check 10s' ], 'maxconn' => $haproxy_default_maxconn, }, } + Haproxy::Listen { + options => { + 'option' => [], + } + } + haproxy::listen { 'haproxy.stats': ipaddress => $controller_virtual_ip, ports => '1993', @@ -663,9 +665,6 @@ class tripleo::loadbalancer ( if $keystone_admin { haproxy::listen { 'keystone_admin': bind => $keystone_admin_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'keystone_admin': @@ -680,9 +679,6 @@ class tripleo::loadbalancer ( if $keystone_public { haproxy::listen { 'keystone_public': bind => $keystone_public_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'keystone_public': @@ -697,9 +693,6 @@ class tripleo::loadbalancer ( if $neutron { haproxy::listen { 'neutron': bind => $neutron_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'neutron': @@ -714,9 +707,6 @@ class tripleo::loadbalancer ( if $cinder { haproxy::listen { 'cinder': bind => $cinder_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'cinder': @@ -731,9 +721,6 @@ class tripleo::loadbalancer ( if manila { haproxy::listen { 'manila': bind => $manila_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'manila': @@ -748,9 +735,6 @@ class tripleo::loadbalancer ( if $glance_api { haproxy::listen { 'glance_api': bind => $glance_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'glance_api': @@ -765,9 +749,6 @@ class tripleo::loadbalancer ( if $glance_registry { haproxy::listen { 'glance_registry': ipaddress => hiera('glance_registry_vip', $controller_virtual_ip), - options => { - 'option' => [ ], - }, ports => 9191, collect_exported => false, } @@ -783,9 +764,6 @@ class tripleo::loadbalancer ( if $nova_ec2 { haproxy::listen { 'nova_ec2': bind => $nova_ec2_bind_opts, - options => { - 'option' => [ ], - }, collect_exported => false, } haproxy::balancermember { 'nova_ec2': @@ -800,9 +778,6 @@ class tripleo::loadbalancer ( if $nova_osapi { haproxy::listen { 'nova_osapi': bind => $nova_osapi_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'nova_osapi': @@ -818,9 +793,6 @@ class tripleo::loadbalancer ( haproxy::listen { 'nova_metadata': ipaddress => hiera('nova_metadata_vip', $controller_virtual_ip), ports => 8775, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'nova_metadata': @@ -836,7 +808,7 @@ class tripleo::loadbalancer ( haproxy::listen { 'nova_novncproxy': bind => $nova_novnc_bind_opts, options => { - 'option' => [ 'httpchk GET /' ], + 'balance' => 'source', }, collect_exported => false, } @@ -852,9 +824,6 @@ class tripleo::loadbalancer ( if $ceilometer { haproxy::listen { 'ceilometer': bind => $ceilometer_bind_opts, - options => { - 'option' => [ ], - }, collect_exported => false, } haproxy::balancermember { 'ceilometer': @@ -869,9 +838,6 @@ class tripleo::loadbalancer ( if $swift_proxy_server { haproxy::listen { 'swift_proxy_server': bind => $swift_bind_opts, - options => { - 'option' => [ 'httpchk GET /info' ], - }, collect_exported => false, } haproxy::balancermember { 'swift_proxy_server': @@ -902,9 +868,6 @@ class tripleo::loadbalancer ( if $heat_cloudwatch { haproxy::listen { 'heat_cloudwatch': bind => $heat_cw_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'heat_cloudwatch': @@ -919,9 +882,6 @@ class tripleo::loadbalancer ( if $heat_cfn { haproxy::listen { 'heat_cfn': bind => $heat_cfn_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'heat_cfn': @@ -937,7 +897,6 @@ class tripleo::loadbalancer ( haproxy::listen { 'horizon': bind => $horizon_bind_opts, options => { - 'option' => [ 'httpchk GET /' ], 'cookie' => 'SERVERID insert indirect nocache', }, collect_exported => false, @@ -953,7 +912,7 @@ class tripleo::loadbalancer ( if $mysql_clustercheck { $mysql_listen_options = { - 'option' => [ 'httpchk' ], + 'option' => [ 'tcpka', 'httpchk' ], 'timeout' => [ 'client 0', 'server 0' ], 'stick-table' => 'type ip size 1000', 'stick' => 'on dst', @@ -969,9 +928,6 @@ class tripleo::loadbalancer ( if $ironic { haproxy::listen { 'ironic': bind => $ironic_bind_opts, - options => { - 'option' => [ 'httpchk GET /' ], - }, collect_exported => false, } haproxy::balancermember { 'ironic': @@ -1004,6 +960,7 @@ class tripleo::loadbalancer ( ipaddress => [hiera('rabbitmq_vip', $controller_virtual_ip)], ports => 5672, options => { + 'option' => [ 'tcpka' ], 'timeout' => [ 'client 0', 'server 0' ], }, collect_exported => false, diff --git a/spec/unit/type/package_manifest_spec.rb b/spec/unit/type/package_manifest_spec.rb new file mode 100644 index 0000000..096564c --- /dev/null +++ b/spec/unit/type/package_manifest_spec.rb @@ -0,0 +1,37 @@ + +require 'puppet' +require 'puppet/type/package_manifest' + +describe 'Puppet::Type.type(:package_manifest)' do + before :each do + @manifest = Puppet::Type.type(:package_manifest).new( + :path => '/tmp/test_package_manifest.txt', :ensure => 'present' + ) + end + + it 'should require a path' do + expect { + Puppet::Type.type(:package_manifest).new({}) + }.to raise_error Puppet::Error + end + + it 'should not require a value when ensure is absent' do + Puppet::Type.type(:package_manifest).new( + :path => '/tmp/test_package_manifest.txt', :ensure => :absent + ) + end + + it 'should accept valid ensure values' do + @manifest[:ensure] = :present + expect(@manifest[:ensure]).to eq(:present) + @manifest[:ensure] = :absent + expect(@manifest[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @manifest[:ensure] = :latest + }.to raise_error(Puppet::Error, /Invalid value/) + end + +end |