diff --git a/Puppetfile b/Puppetfile index 4726c3dcb..6c6cddeff 100644 --- a/Puppetfile +++ b/Puppetfile @@ -1,5 +1,5 @@ mod 'apache', - :commit => 'bf061e66d10ff595799e13945832948e0a538cea', + :commit => '84219d81079b901a1400660757e399c365dacbda', :git => 'https://github.com/puppetlabs/puppetlabs-apache.git' mod 'aviator', @@ -7,7 +7,7 @@ mod 'aviator', :git => 'https://github.com/aimonb/puppet_aviator.git' mod 'ceilometer', - :commit => '264ea1b19155bb2f34a95858b18442c14504ddf2', + :commit => '2bb88c9e504df19d61c6d272e3658cc47532e686', :git => 'https://github.com/stackforge/puppet-ceilometer.git' mod 'ceph', @@ -19,7 +19,7 @@ mod 'certmonger', :git => 'https://github.com/rcritten/puppet-certmonger.git' mod 'cinder', - :commit => '4785c1c739f19c4874d0ba24f14e34b6f0d06375', + :commit => 'cddc87e4012c7b8851dc274e28c7a32422c47720', :git => 'https://github.com/stackforge/puppet-cinder.git' mod 'common', @@ -35,7 +35,7 @@ mod 'corosync', :git => 'https://github.com/puppetlabs/puppetlabs-corosync.git' mod 'firewall', - :commit => 'cbfca920444c5da5bddd3990f89ca61e5bcc0006', + :commit => '1ceff193347867be5b5d3a0f1757e929173d394c', :git => 'https://github.com/puppetlabs/puppetlabs-firewall.git' mod 'galera', @@ -43,7 +43,7 @@ mod 'galera', :git => 'https://github.com/redhat-openstack/puppet-galera.git' mod 'glance', - :commit => '88b74f869aed0c3fd2fb4b27e0f3956991399414', + :commit => '7fc2ba21a7ee8cc81826f2bcc74f0a7fa5b6687e', :git => 'https://github.com/stackforge/puppet-glance.git' mod 'gluster', @@ -51,23 +51,23 @@ mod 'gluster', :git => 'https://github.com/purpleidea/puppet-gluster.git' mod 'gnocchi', - :commit => '4ebe8a6b83a5c3a55f7ea9f61991917054c6b013', + :commit => '8bb2319e56cab193b43ac0f93e0b76d8c4826d8c', :git => 'https://github.com/stackforge/puppet-gnocchi.git' mod 'haproxy', - :commit => '3007560fc47da48d576890b1823e0ccfac3d9207', + :commit => '6bca1f0bc31bfeb397635c9867d51a847caddbcd', :git => 'https://github.com/puppetlabs/puppetlabs-haproxy.git' mod 'heat', - :commit => '01004884a1a4d3e2e5fac779975ddc18fec034cd', + :commit => '1e77c010b95bd8f27d6547dfaf7f5748f80519bc', :git => 'https://github.com/stackforge/puppet-heat.git' mod 'horizon', - :commit => 'b975b22d97f5b794160bfdd5c4190990e8496331', + :commit => 'd45c1e69b83dd082e9b969787f3af461f9b32193', :git => 'https://github.com/stackforge/puppet-horizon.git' mod 'inifile', - :commit => 'c72bfbb9b1df49ec66a4899e84ea869a1c18426c', + :commit => 'e132445690c21cef314d926bbc5975843c14951e', :git => 'https://github.com/puppetlabs/puppetlabs-inifile.git' mod 'ipa', @@ -75,7 +75,7 @@ mod 'ipa', :git => 'https://github.com/xbezdick/puppet-ipa-1.git' mod 'ironic', - :commit => '78e0dc117ee77275f40dcda8dd060f1d6ca06499', + :commit => '1e4c59f22a423aabb5608e18ba9cf3299c07a46f', :git => 'https://github.com/stackforge/puppet-ironic.git' mod 'keepalived', @@ -83,15 +83,15 @@ mod 'keepalived', :git => 'https://github.com/Unyonsys/puppet-module-keepalived.git' mod 'keystone', - :commit => 'eb240c5aa120d428567fb7c239167def96b6b75f', + :commit => '380d9addc3ad7552aa1c21002de12a7b349a0675', :git => 'https://github.com/stackforge/puppet-keystone.git' mod 'manila', - :commit => 'ce1fa24cfdbb1073a1fedbb373b690b92b35c43f', + :commit => '04c9643e0e7bf7659ae063977788b4ca4504b861', :git => 'https://github.com/stackforge/puppet-manila.git' mod 'memcached', - :commit => 'f6dd071b94a934fcb66d06228ca234502f4ebb8f', + :commit => '8e6fdfda7400c40176baa5063e05ff716cc5fd73', :git => 'https://github.com/saz/puppet-memcached.git' mod 'module-collectd', @@ -103,15 +103,15 @@ mod 'module-data', :git => 'https://github.com/ripienaar/puppet-module-data.git' mod 'mongodb', - :commit => '14117ae3391862021555df8139c66fd04c13c0c3', + :commit => '030100a176a72a32e265b77790d8d15407a13729', :git => 'https://github.com/puppetlabs/puppetlabs-mongodb.git' mod 'mysql', - :commit => '5f76233b7f44bb5d11521d78e60f0545da19e60e', + :commit => '2a9ff96e023e306e026455fa87ee5c415b74426e', :git => 'https://github.com/puppetlabs/puppetlabs-mysql.git' mod 'n1k_vsm', - :commit => '2a42723f5a9d7dbfa00edf944ac5dec2bff6d9ea', + :commit => 'ed391d3d9bdcccef3e2de3b0da98e654237d99a5', :git => 'https://github.com/stackforge/puppet-n1k-vsm.git' mod 'nagios', @@ -119,11 +119,11 @@ mod 'nagios', :git => 'https://github.com/gildub/puppet-nagios-openstack.git' mod 'neutron', - :commit => 'dea7f4719fea5529d916ef4cae56020e8ee4efea', + :commit => '910afc6d768a32f36462c3cdc77fe8cd43166b81', :git => 'https://github.com/stackforge/puppet-neutron.git' mod 'nova', - :commit => 'f4330488dd503562ba936c2f14d23e6af3ee9fca', + :commit => '273728b88d8dd17cbb42485ec6fe06ce3d854fc8', :git => 'https://github.com/stackforge/puppet-nova.git' mod 'nssdb', @@ -131,19 +131,19 @@ mod 'nssdb', :git => 'https://github.com/rcritten/puppet-nssdb.git' mod 'ntp', - :commit => 'c0613256dfcec3fb0ec20ef42c9d9e47f0412648', + :commit => '413a705d3b61eda9fb3651affb8cf79251c11d98', :git => 'https://github.com/puppetlabs/puppetlabs-ntp' mod 'openstack_extras', - :commit => '610313ca08ffc50c44b6d41000d25bd0274d57f0', + :commit => '7ab1f4544ac71d2158459a85438eddc35e6fd0d6', :git => 'https://github.com/stackforge/puppet-openstack_extras.git' mod 'openstacklib', - :commit => 'd0de990f92a9a9cb7f705ecd39dd8aa02d02bf48', + :commit => '15f9db96c2f77a5e78a8fc098c07a72f66bdde4e', :git => 'https://github.com/stackforge/puppet-openstacklib.git' mod 'pacemaker', - :commit => '47c85172fedcf452acd004cc880a565e4a326c73', + :commit => '337f9c139b705135b4f65e72748b4c706323b695', :git => 'https://github.com/redhat-openstack/puppet-pacemaker.git' mod 'puppet', @@ -155,11 +155,11 @@ mod 'qpid', :git => 'https://github.com/dprince/puppet-qpid' mod 'rabbitmq', - :commit => 'd3c6971a3e97b7079a6076a43a8891000757797b', + :commit => '3acf530fe70b9d4bf15fe048643a635977a68d13', :git => 'https://github.com/puppetlabs/puppetlabs-rabbitmq.git' mod 'redis', - :commit => 'aa13ac935693204972b7255233f13402634f256e', + :commit => '439fb695ed582b99430352cd7b15fefa6bb56989', :git => 'https://github.com/arioch/puppet-redis.git' mod 'remote', @@ -171,7 +171,7 @@ mod 'rsync', :git => 'https://github.com/puppetlabs/puppetlabs-rsync.git' mod 'sahara', - :commit => '326860e6244927474f458e5df220abcb59049576', + :commit => 'aca5d45cfc8cbc0ec961a2aad7cc06d0e23144e5', :git => 'https://github.com/stackforge/puppet-sahara.git' mod 'snmp', @@ -179,7 +179,7 @@ mod 'snmp', :git => 'https://github.com/razorsedge/puppet-snmp.git' mod 'ssh', - :commit => '5afa7d6cc30c129af66612928f3ab51f89ad7a26', + :commit => '3216cd87ae97ee74f06edd0e4868cedbc90e86d9', :git => 'https://github.com/saz/puppet-ssh.git' mod 'staging', @@ -187,11 +187,11 @@ mod 'staging', :git => 'https://github.com/nanliu/puppet-staging.git' mod 'stdlib', - :commit => '4a8c0a57f2c4df4e2e3fa37466f02a7f6fccd517', + :commit => '8267dbc149584afa4824dde7a3b95380556e2cea', :git => 'https://github.com/puppetlabs/puppetlabs-stdlib.git' mod 'swift', - :commit => 'ef9f9a4194237b3cd00446f42d1b407d203cbfd5', + :commit => '1c655eb5bdeb90f97cd157b846a7202f79216e15', :git => 'https://github.com/stackforge/puppet-swift.git' mod 'sysctl', @@ -199,7 +199,7 @@ mod 'sysctl', :git => 'https://github.com/puppetlabs/puppetlabs-sysctl.git' mod 'tempest', - :commit => 'd46a0c403ee9adcdc2a694c609d9bb6fe3b5a05f', + :commit => '21ccff381996a39cec387d6020aeb015c6e3e244', :git => 'https://github.com/stackforge/puppet-tempest.git' mod 'timezone', @@ -207,11 +207,11 @@ mod 'timezone', :git => 'https://github.com/saz/puppet-timezone.git' mod 'tripleo', - :commit => '98cbe976ff26ad0db7d9ad6d4766c1d0114fed5b', + :commit => '8bfbcb1074caf16e44e79b68d385a19d7cac4537', :git => 'https://github.com/stackforge/puppet-tripleo.git' mod 'trove', - :commit => '16e82e68ea62efec3ec7e11d7b9887e16b773372', + :commit => 'ec563fbaf5545939efe8376c3382912562eca1df', :git => 'https://github.com/stackforge/puppet-trove' mod 'tuskar', @@ -219,7 +219,7 @@ mod 'tuskar', :git => 'https://github.com/stackforge/puppet-tuskar.git' mod 'vcsrepo', - :commit => '18b91b2f51a1cd8cd6911bd981e4629dd0d407e8', + :commit => '69c9fc6c5c794f829b9c68b546277ae0081c8329', :git => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git' mod 'vlan', @@ -227,7 +227,7 @@ mod 'vlan', :git => 'https://github.com/derekhiggins/puppet-vlan.git' mod 'vswitch', - :commit => '8bdf36261b7f25ac0f0af84804d102db0ba51007', + :commit => '70239fb8414f4322b22bdc9fb36accfeacf49795', :git => 'https://github.com/stackforge/puppet-vswitch.git' mod 'xinetd', diff --git a/apache/.travis.yml b/apache/.travis.yml index 742380f6b..16d694bb6 100644 --- a/apache/.travis.yml +++ b/apache/.travis.yml @@ -16,8 +16,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - rvm: 2.1.6 env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/apache/CHANGELOG.md b/apache/CHANGELOG.md index 44ca14c39..6e0b1ee87 100644 --- a/apache/CHANGELOG.md +++ b/apache/CHANGELOG.md @@ -1,3 +1,35 @@ +##2015-06-16 - Supported Release 1.5.0 +### Summary +This release primarily adds Suse compatibility. It also adds a handful of other +parameters for greater configuration control. + +### Features +- Now compatible with concat 1.x and 2.x +- Add `apache::lib_path` parameter +- Add `apache::service_restart` parameter +- Add `apache::vhost::geoip_enable` parameter +- Add `apache::mod::geoip` class +- Add `apache::mod::remoteip` class +- Add parameters to `apache::mod::expires` class +- Add `index_style_sheet` handling to `apache::vhost::directories` +- Add some compatibility for SLES 11 +- Add `apache::mod::ssl::ssl_sessioncachetimeout` parameter +- Add `apache::mod::ssl::ssl_cryptodevice` parameter +- Add `apache::mod::ssl::ssl_honorcipherorder` parameter +- Add `apache::mod::userdir::options` parameter + +### Bugfixes +- Document `apache::user` parameter +- Document `apache::group` parameter +- Fix apache::dev on FreeBSD +- Fix proxy\_connect on apache >= 2.2 +- Validate log levels better +- Fix `apache::apache_name` for package and vhost +- Fix Debian Jessie mod\_prefork package name +- Fix alias module being declared even when vhost is absent +- Fix proxy\_pass\_match handling in vhost's proxy template +- Fix userdir access permissions + ##2015-04-28 - Supported Release 1.4.1 This release corrects a metadata issue that has been present since release 1.2.0. The refactoring of `apache::vhost` to use `puppetlabs-concat` requires a version of concat newer than the version required in PE. If you are using PE 3.3.0 or earlier you will need to use version 1.1.1 or earlier of the `puppetlabs-apache` module. diff --git a/apache/metadata.json b/apache/metadata.json index e860ca407..71bad1d35 100644 --- a/apache/metadata.json +++ b/apache/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-apache", - "version": "1.4.1", + "version": "1.5.0", "author": "puppetlabs", "summary": "Installs, configures, and manages Apache virtual hosts, web services, and modules.", "license": "Apache-2.0", @@ -46,6 +46,12 @@ "7" ] }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11 SP1" + ] + }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ diff --git a/apache/spec/spec_helper_acceptance.rb b/apache/spec/spec_helper_acceptance.rb index 1091edcaf..66d1d7c43 100644 --- a/apache/spec/spec_helper_acceptance.rb +++ b/apache/spec/spec_helper_acceptance.rb @@ -5,7 +5,10 @@ unless ENV['RS_PROVISION'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = { :default_action => 'gem_install' } + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), + } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end diff --git a/ceilometer/.gitreview b/ceilometer/.gitreview index 721c4d8a5..18185b186 100644 --- a/ceilometer/.gitreview +++ b/ceilometer/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-ceilometer.git +project=openstack/puppet-ceilometer.git diff --git a/ceilometer/Gemfile b/ceilometer/Gemfile index 4c65317ac..3c0b87530 100644 --- a/ceilometer/Gemfile +++ b/ceilometer/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -17,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/ceilometer/manifests/init.pp b/ceilometer/manifests/init.pp index 124eaa10e..577e3533f 100644 --- a/ceilometer/manifests/init.pp +++ b/ceilometer/manifests/init.pp @@ -167,64 +167,64 @@ if $rpc_backend == 'ceilometer.openstack.common.rpc.impl_kombu' { if $rabbit_hosts { - ceilometer_config { 'DEFAULT/rabbit_host': ensure => absent } - ceilometer_config { 'DEFAULT/rabbit_port': ensure => absent } - ceilometer_config { 'DEFAULT/rabbit_hosts': + ceilometer_config { 'oslo_messaging_rabbit/rabbit_host': ensure => absent } + ceilometer_config { 'oslo_messaging_rabbit/rabbit_port': ensure => absent } + ceilometer_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } } else { - ceilometer_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - ceilometer_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - ceilometer_config { 'DEFAULT/rabbit_hosts': + ceilometer_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + ceilometer_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + ceilometer_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } } if size($rabbit_hosts) > 1 { - ceilometer_config { 'DEFAULT/rabbit_ha_queues': value => true } + ceilometer_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { - ceilometer_config { 'DEFAULT/rabbit_ha_queues': value => false } + ceilometer_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } ceilometer_config { - 'DEFAULT/rabbit_userid' : value => $rabbit_userid; - 'DEFAULT/rabbit_password' : value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_virtual_host' : value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl' : value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_userid' : value => $rabbit_userid; + 'oslo_messaging_rabbit/rabbit_password' : value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_virtual_host' : value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl' : value => $rabbit_use_ssl; } if $rabbit_use_ssl { if $kombu_ssl_ca_certs { - ceilometer_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } + ceilometer_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } } else { - ceilometer_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; } + ceilometer_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; } } if $kombu_ssl_certfile or $kombu_ssl_keyfile { ceilometer_config { - 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; + 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; } } else { ceilometer_config { - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } if $kombu_ssl_version { - ceilometer_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version; } + ceilometer_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version; } } else { - ceilometer_config { 'DEFAULT/kombu_ssl_version': ensure => absent; } + ceilometer_config { 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } else { ceilometer_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } diff --git a/ceilometer/spec/acceptance/nodesets/nodepool-centos7.yml b/ceilometer/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/ceilometer/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/ceilometer/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/ceilometer/spec/acceptance/nodesets/nodepool-trusty.yml b/ceilometer/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/ceilometer/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/ceilometer/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/ceilometer/spec/classes/ceilometer_init_spec.rb b/ceilometer/spec/classes/ceilometer_init_spec.rb index f65edc1d6..536a30614 100644 --- a/ceilometer/spec/classes/ceilometer_init_spec.rb +++ b/ceilometer/spec/classes/ceilometer_init_spec.rb @@ -174,58 +174,58 @@ shared_examples_for 'rabbit without HA support (with backward compatibility)' do it 'configures rabbit' do - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ).with_secret(true) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ).with_secret(true) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) end - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_host').with_value( params[:rabbit_host] ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_port').with_value( params[:rabbit_port] ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_hosts').with_value( "#{params[:rabbit_host]}:#{params[:rabbit_port]}" ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_ha_queues').with_value('false') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_host').with_value( params[:rabbit_host] ) } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_port').with_value( params[:rabbit_port] ) } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_hosts').with_value( "#{params[:rabbit_host]}:#{params[:rabbit_port]}" ) } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') } end shared_examples_for 'rabbit without HA support (without backward compatibility)' do it 'configures rabbit' do - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ).with_secret(true) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ).with_secret(true) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) end - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_host').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_port').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_ha_queues').with_value('false') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_host').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_port').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') } end shared_examples_for 'rabbit with HA support' do it 'configures rabbit' do - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ).with_secret(true) - is_expected.to contain_ceilometer_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ).with_secret(true) + is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) end - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_host').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_port').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_ha_queues').with_value('true') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_host').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_port').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } end shared_examples_for 'rabbit with SSL support' do context "with default parameters" do - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_use_ssl').with_value('false') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_version').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') } end context "with SSL enabled with kombu" do @@ -237,11 +237,11 @@ :kombu_ssl_version => 'TLSv1' ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_use_ssl').with_value('true') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ca.crt') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/cert.crt') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/cert.key') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ca.crt') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/cert.crt') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/cert.key') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } end context "with SSL enabled without kombu" do @@ -249,11 +249,11 @@ :rabbit_use_ssl => 'true' ) } - it { is_expected.to contain_ceilometer_config('DEFAULT/rabbit_use_ssl').with_value('true') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') } - it { is_expected.to contain_ceilometer_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') } + it { is_expected.to contain_ceilometer_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } end context "with SSL wrongly configured" do diff --git a/cinder/.gitreview b/cinder/.gitreview index 8afd6562d..86c09bfea 100644 --- a/cinder/.gitreview +++ b/cinder/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-cinder.git +project=openstack/puppet-cinder.git diff --git a/cinder/Gemfile b/cinder/Gemfile index 091cb6268..f1393a84b 100644 --- a/cinder/Gemfile +++ b/cinder/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'puppet-lint', '~> 1.1' gem 'puppet-lint-param-docs', '1.1.0' @@ -16,7 +15,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/cinder/manifests/backend/netapp.pp b/cinder/manifests/backend/netapp.pp index d14f03d3d..47d3150ff 100644 --- a/cinder/manifests/backend/netapp.pp +++ b/cinder/manifests/backend/netapp.pp @@ -214,44 +214,44 @@ if $nfs_mount_options { cinder_config { - "${volume_backend_name}/nfs_mount_options": value => $nfs_mount_options; + "${name}/nfs_mount_options": value => $nfs_mount_options; } } else { cinder_config { - "${volume_backend_name}/nfs_mount_options": ensure => absent; + "${name}/nfs_mount_options": ensure => absent; } } cinder_config { - "${volume_backend_name}/volume_backend_name": value => $volume_backend_name; - "${volume_backend_name}/volume_driver": value => 'cinder.volume.drivers.netapp.common.NetAppDriver'; - "${volume_backend_name}/netapp_login": value => $netapp_login; - "${volume_backend_name}/netapp_password": value => $netapp_password, secret => true; - "${volume_backend_name}/netapp_server_hostname": value => $netapp_server_hostname; - "${volume_backend_name}/netapp_server_port": value => $netapp_server_port; - "${volume_backend_name}/netapp_size_multiplier": value => $netapp_size_multiplier; - "${volume_backend_name}/netapp_storage_family": value => $netapp_storage_family; - "${volume_backend_name}/netapp_storage_protocol": value => $netapp_storage_protocol; - "${volume_backend_name}/netapp_transport_type": value => $netapp_transport_type; - "${volume_backend_name}/netapp_vfiler": value => $netapp_vfiler; - "${volume_backend_name}/netapp_volume_list": value => $netapp_volume_list; - "${volume_backend_name}/netapp_vserver": value => $netapp_vserver; - "${volume_backend_name}/netapp_partner_backend_name": value => $netapp_partner_backend_name; - "${volume_backend_name}/expiry_thres_minutes": value => $expiry_thres_minutes; - "${volume_backend_name}/thres_avl_size_perc_start": value => $thres_avl_size_perc_start; - "${volume_backend_name}/thres_avl_size_perc_stop": value => $thres_avl_size_perc_stop; - "${volume_backend_name}/nfs_shares_config": value => $nfs_shares_config; - "${volume_backend_name}/netapp_copyoffload_tool_path": value => $netapp_copyoffload_tool_path; - "${volume_backend_name}/netapp_controller_ips": value => $netapp_controller_ips; - "${volume_backend_name}/netapp_sa_password": value => $netapp_sa_password, secret => true; - "${volume_backend_name}/netapp_storage_pools": value => $netapp_storage_pools; - "${volume_backend_name}/netapp_eseries_host_type": value => $netapp_eseries_host_type; - "${volume_backend_name}/netapp_webservice_path": value => $netapp_webservice_path; + "${name}/volume_backend_name": value => $volume_backend_name; + "${name}/volume_driver": value => 'cinder.volume.drivers.netapp.common.NetAppDriver'; + "${name}/netapp_login": value => $netapp_login; + "${name}/netapp_password": value => $netapp_password, secret => true; + "${name}/netapp_server_hostname": value => $netapp_server_hostname; + "${name}/netapp_server_port": value => $netapp_server_port; + "${name}/netapp_size_multiplier": value => $netapp_size_multiplier; + "${name}/netapp_storage_family": value => $netapp_storage_family; + "${name}/netapp_storage_protocol": value => $netapp_storage_protocol; + "${name}/netapp_transport_type": value => $netapp_transport_type; + "${name}/netapp_vfiler": value => $netapp_vfiler; + "${name}/netapp_volume_list": value => $netapp_volume_list; + "${name}/netapp_vserver": value => $netapp_vserver; + "${name}/netapp_partner_backend_name": value => $netapp_partner_backend_name; + "${name}/expiry_thres_minutes": value => $expiry_thres_minutes; + "${name}/thres_avl_size_perc_start": value => $thres_avl_size_perc_start; + "${name}/thres_avl_size_perc_stop": value => $thres_avl_size_perc_stop; + "${name}/nfs_shares_config": value => $nfs_shares_config; + "${name}/netapp_copyoffload_tool_path": value => $netapp_copyoffload_tool_path; + "${name}/netapp_controller_ips": value => $netapp_controller_ips; + "${name}/netapp_sa_password": value => $netapp_sa_password, secret => true; + "${name}/netapp_storage_pools": value => $netapp_storage_pools; + "${name}/netapp_eseries_host_type": value => $netapp_eseries_host_type; + "${name}/netapp_webservice_path": value => $netapp_webservice_path; } if $netapp_storage_family == 'eseries' { cinder_config { - "${volume_backend_name}/use_multipath_for_image_xfer": value => true; + "${name}/use_multipath_for_image_xfer": value => true; } } diff --git a/cinder/manifests/init.pp b/cinder/manifests/init.pp index 7a5556590..1fba82f4c 100644 --- a/cinder/manifests/init.pp +++ b/cinder/manifests/init.pp @@ -317,52 +317,52 @@ } cinder_config { - 'DEFAULT/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_userid': value => $rabbit_userid; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_userid; + 'oslo_messaging_rabbit/rabbit_virtual_host': value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl': value => $rabbit_use_ssl; 'DEFAULT/control_exchange': value => $control_exchange; 'DEFAULT/amqp_durable_queues': value => $amqp_durable_queues; } if $rabbit_hosts { - cinder_config { 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ',') } - cinder_config { 'DEFAULT/rabbit_ha_queues': value => true } - cinder_config { 'DEFAULT/rabbit_host': ensure => absent } - cinder_config { 'DEFAULT/rabbit_port': ensure => absent } + cinder_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } + cinder_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } + cinder_config { 'oslo_messaging_rabbit/rabbit_host': ensure => absent } + cinder_config { 'oslo_messaging_rabbit/rabbit_port': ensure => absent } } else { - cinder_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - cinder_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - cinder_config { 'DEFAULT/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } - cinder_config { 'DEFAULT/rabbit_ha_queues': value => false } + cinder_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + cinder_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + cinder_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } + cinder_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } if $rabbit_use_ssl { - cinder_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version } + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version } if $kombu_ssl_ca_certs { - cinder_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs } + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs } } else { - cinder_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent} + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent} } if $kombu_ssl_certfile { - cinder_config { 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile } + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile } } else { - cinder_config { 'DEFAULT/kombu_ssl_certfile': ensure => absent} + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent} } if $kombu_ssl_keyfile { - cinder_config { 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile } + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile } } else { - cinder_config { 'DEFAULT/kombu_ssl_keyfile': ensure => absent} + cinder_config { 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent} } } else { cinder_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } diff --git a/cinder/spec/acceptance/nodesets/nodepool-centos7.yml b/cinder/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/cinder/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/cinder/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/cinder/spec/acceptance/nodesets/nodepool-trusty.yml b/cinder/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/cinder/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/cinder/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/cinder/spec/classes/cinder_spec.rb b/cinder/spec/classes/cinder_spec.rb index b80466cb4..b28d5a263 100644 --- a/cinder/spec/classes/cinder_spec.rb +++ b/cinder/spec/classes/cinder_spec.rb @@ -19,13 +19,13 @@ it 'should contain default config' do is_expected.to contain_cinder_config('DEFAULT/rpc_backend').with(:value => 'cinder.openstack.common.rpc.impl_kombu') is_expected.to contain_cinder_config('DEFAULT/control_exchange').with(:value => 'openstack') - is_expected.to contain_cinder_config('DEFAULT/rabbit_password').with(:value => 'guest', :secret => true) - is_expected.to contain_cinder_config('DEFAULT/rabbit_host').with(:value => '127.0.0.1') - is_expected.to contain_cinder_config('DEFAULT/rabbit_port').with(:value => '5672') - is_expected.to contain_cinder_config('DEFAULT/rabbit_hosts').with(:value => '127.0.0.1:5672') - is_expected.to contain_cinder_config('DEFAULT/rabbit_ha_queues').with(:value => false) - is_expected.to contain_cinder_config('DEFAULT/rabbit_virtual_host').with(:value => '/') - is_expected.to contain_cinder_config('DEFAULT/rabbit_userid').with(:value => 'guest') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_password').with(:value => 'guest', :secret => true) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_host').with(:value => '127.0.0.1') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_port').with(:value => '5672') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => '127.0.0.1:5672') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => false) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_virtual_host').with(:value => '/') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_userid').with(:value => 'guest') is_expected.to contain_cinder_config('database/connection').with(:value => 'mysql://user:password@host/database', :secret => true) is_expected.to contain_cinder_config('database/idle_timeout').with(:value => '3600') is_expected.to contain_cinder_config('database/min_pool_size').with(:value => '1') @@ -62,10 +62,10 @@ end it 'should contain many' do - is_expected.to contain_cinder_config('DEFAULT/rabbit_host').with(:value => nil) - is_expected.to contain_cinder_config('DEFAULT/rabbit_port').with(:value => nil) - is_expected.to contain_cinder_config('DEFAULT/rabbit_hosts').with(:value => 'rabbit1:5672,rabbit2:5672') - is_expected.to contain_cinder_config('DEFAULT/rabbit_ha_queues').with(:value => true) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_host').with(:value => nil) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_port').with(:value => nil) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => 'rabbit1:5672,rabbit2:5672') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => true) end end @@ -75,10 +75,10 @@ end it 'should contain many' do - is_expected.to contain_cinder_config('DEFAULT/rabbit_host').with(:value => nil) - is_expected.to contain_cinder_config('DEFAULT/rabbit_port').with(:value => nil) - is_expected.to contain_cinder_config('DEFAULT/rabbit_hosts').with(:value => 'rabbit1:5672') - is_expected.to contain_cinder_config('DEFAULT/rabbit_ha_queues').with(:value => true) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_host').with(:value => nil) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_port').with(:value => nil) + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => 'rabbit1:5672') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => true) end end @@ -159,11 +159,11 @@ end it do - is_expected.to contain_cinder_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -175,11 +175,11 @@ end it do - is_expected.to contain_cinder_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -195,11 +195,11 @@ end it do - is_expected.to contain_cinder_config('DEFAULT/rabbit_use_ssl').with_value('false') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_cinder_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_cinder_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end diff --git a/cinder/spec/defines/cinder_backend_netapp_spec.rb b/cinder/spec/defines/cinder_backend_netapp_spec.rb index 04900002f..4dcb7e4b0 100644 --- a/cinder/spec/defines/cinder_backend_netapp_spec.rb +++ b/cinder/spec/defines/cinder_backend_netapp_spec.rb @@ -2,7 +2,7 @@ describe 'cinder::backend::netapp' do - let(:title) {'hippo'} + let(:title) {'netapp'} let :params do { @@ -44,23 +44,22 @@ end it 'configures netapp volume driver' do - is_expected.to contain_cinder_config("#{params_hash[:volume_backend_name]}/volume_driver").with_value( + is_expected.to contain_cinder_config('netapp/volume_driver').with_value( 'cinder.volume.drivers.netapp.common.NetAppDriver') params_hash.each_pair do |config,value| - is_expected.to contain_cinder_config("#{params_hash[:volume_backend_name]}/#{config}").with_value( value ) + is_expected.to contain_cinder_config("netapp/#{config}").with_value( value ) end end it 'marks netapp_password as secret' do - is_expected.to contain_cinder_config("#{params_hash[:volume_backend_name]}/netapp_password").with_secret( true ) + is_expected.to contain_cinder_config('netapp/netapp_password').with_secret( true ) end it 'marks netapp_sa_password as secret' do - is_expected.to contain_cinder_config("#{params_hash[:volume_backend_name]}/netapp_sa_password").with_secret( true ) + is_expected.to contain_cinder_config('netapp/netapp_sa_password').with_secret( true ) end end - context 'with default parameters' do before do params = {} @@ -74,28 +73,36 @@ end context 'with netapp_storage_family eseries' do - let (:req_params) { params.merge!({ - :netapp_storage_family => 'eseries', - }) } + before do + params.merge!(:netapp_storage_family => 'eseries') + end - it { is_expected.to contain_cinder_config("#{req_params[:volume_backend_name]}/use_multipath_for_image_xfer").with_value('true') } + it 'sets use_multipath_for_image_xfer to true' do + should contain_cinder_config('netapp/use_multipath_for_image_xfer').with({ + :value => 'true' + }) + end end - context 'with NFS mount options' do - let (:req_params) { params.merge!({ - :nfs_mount_options => 'rw,proto=tcp,sec=sys', - }) } + context 'with nfs_mount_options' do + before do + params.merge!(:nfs_mount_options => 'rw,proto=tcp,sec=sys') + end - it { is_expected.to contain_cinder_config("#{req_params[:volume_backend_name]}/nfs_mount_options").with_value('rw,proto=tcp,sec=sys') } + it 'sets the nfs mount options' do + should contain_cinder_config('netapp/nfs_mount_options').with({ + :value => 'rw,proto=tcp,sec=sys' + }) + end end context 'netapp backend with additional configuration' do before do - params.merge!({:extra_options => {'hippo/param1' => { 'value' => 'value1' }}}) + params.merge!({:extra_options => {'netapp/param1' => { 'value' => 'value1' }}}) end it 'configure netapp backend with additional configuration' do - should contain_cinder_config('hippo/param1').with({ + should contain_cinder_config('netapp/param1').with({ :value => 'value1' }) end diff --git a/firewall/.travis.yml b/firewall/.travis.yml index cbf6f11df..7e8ed57bb 100644 --- a/firewall/.travis.yml +++ b/firewall/.travis.yml @@ -20,8 +20,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - rvm: 1.8.7 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/firewall/README.markdown b/firewall/README.markdown index cbcee2eeb..98d642e65 100644 --- a/firewall/README.markdown +++ b/firewall/README.markdown @@ -78,24 +78,24 @@ The rules in the `pre` and `post` classes are fairly general. These two classes # Default firewall rules firewall { '000 accept all icmp': - proto => 'icmp', - action => 'accept', + proto => 'icmp', + action => 'accept', }-> firewall { '001 accept all to lo interface': proto => 'all', iniface => 'lo', action => 'accept', }-> - firewall { "002 reject local traffic not on loopback interface": + firewall { '002 reject local traffic not on loopback interface': iniface => '! lo', proto => 'all', destination => '127.0.0.1/8', action => 'reject', }-> firewall { '003 accept related established rules': - proto => 'all', - state => ['RELATED', 'ESTABLISHED'], - action => 'accept', + proto => 'all', + state => ['RELATED', 'ESTABLISHED'], + action => 'accept', } } ~~~ @@ -107,9 +107,9 @@ The rules in the `pre` and `post` classes are fairly general. These two classes ~~~puppet class my_fw::post { firewall { '999 drop all': - proto => 'all', - action => 'drop', - before => undef, + proto => 'all', + action => 'drop', + before => undef, } } ~~~ diff --git a/firewall/spec/spec_helper.rb b/firewall/spec/spec_helper.rb index dc8bc39cb..bcd31596d 100644 --- a/firewall/spec/spec_helper.rb +++ b/firewall/spec/spec_helper.rb @@ -26,4 +26,5 @@ end config.module_path = File.join(fixture_path, 'modules') config.manifest_dir = File.join(fixture_path, 'manifests') + config.environmentpath = File.expand_path(File.join(Dir.pwd, 'spec')) end diff --git a/firewall/spec/spec_helper_acceptance.rb b/firewall/spec/spec_helper_acceptance.rb index 28910a286..56f896143 100644 --- a/firewall/spec/spec_helper_acceptance.rb +++ b/firewall/spec/spec_helper_acceptance.rb @@ -30,7 +30,10 @@ def is_rhel7(osfamily, operatingsystem, operatingsystemrelease) unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = { :default_action => 'gem_install' } + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), + } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end diff --git a/firewall/spec/unit/classes/firewall_linux_spec.rb b/firewall/spec/unit/classes/firewall_linux_spec.rb index e43c1e9f8..52ca5f8d9 100644 --- a/firewall/spec/unit/classes/firewall_linux_spec.rb +++ b/firewall/spec/unit/classes/firewall_linux_spec.rb @@ -22,8 +22,11 @@ context 'Debian like' do %w{Debian Ubuntu}.each do |os| context "operatingsystem => #{os}" do - let(:facts) { facts_default.merge({ :operatingsystem => os }) } - it { should contain_class('firewall::linux::debian').with_require('Package[iptables]') } + releases = (os == 'Debian' ? ['6','7','8'] : ['10.04','12.04','14.04']) + releases.each do |osrel| + let(:facts) { facts_default.merge({ :operatingsystem => os, :operatingsystemrelease => osrel}) } + it { should contain_class('firewall::linux::debian').with_require('Package[iptables]') } + end end end end diff --git a/glance/.gitreview b/glance/.gitreview index 074651a11..b2ae1d3b9 100644 --- a/glance/.gitreview +++ b/glance/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-glance.git +project=openstack/puppet-glance.git diff --git a/gnocchi/.gitreview b/gnocchi/.gitreview index ad856333a..40f91b618 100644 --- a/gnocchi/.gitreview +++ b/gnocchi/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-gnocchi.git +project=openstack/puppet-gnocchi.git diff --git a/haproxy/.fixtures.yml b/haproxy/.fixtures.yml index c682e73b6..ecfef31df 100644 --- a/haproxy/.fixtures.yml +++ b/haproxy/.fixtures.yml @@ -2,7 +2,7 @@ fixtures: repositories: concat: repo: "git://github.com/puppetlabs/puppetlabs-concat.git" - ref: '1.0.0' + ref: '1.2.3' stdlib: repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git" ref: '2.4.0' diff --git a/haproxy/.gitignore b/haproxy/.gitignore index b5db85e05..874db461f 100644 --- a/haproxy/.gitignore +++ b/haproxy/.gitignore @@ -7,3 +7,4 @@ spec/fixtures/ coverage/ .idea/ *.iml +log/ diff --git a/haproxy/.travis.yml b/haproxy/.travis.yml index cbf6f11df..7e8ed57bb 100644 --- a/haproxy/.travis.yml +++ b/haproxy/.travis.yml @@ -20,8 +20,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - rvm: 1.8.7 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/haproxy/metadata.json b/haproxy/metadata.json index b5e04722b..29d362e11 100644 --- a/haproxy/metadata.json +++ b/haproxy/metadata.json @@ -68,6 +68,6 @@ ], "dependencies": [ {"name":"puppetlabs/stdlib","version_requirement":">= 2.4.0 < 5.0.0"}, - {"name":"puppetlabs/concat","version_requirement":">= 1.1.0 < 2.0.0"} + {"name":"puppetlabs/concat","version_requirement":">= 1.2.3 < 2.0.0"} ] } diff --git a/haproxy/spec/defines/peer_spec.rb b/haproxy/spec/defines/peer_spec.rb index 32ccbf82a..677e0b56c 100644 --- a/haproxy/spec/defines/peer_spec.rb +++ b/haproxy/spec/defines/peer_spec.rb @@ -4,8 +4,9 @@ let(:title) { 'dero' } let(:facts) do { - :ipaddress => '1.1.1.1', - :hostname => 'dero', + :ipaddress => '1.1.1.1', + :hostname => 'dero', + :concat_basedir => '/foo', } end diff --git a/haproxy/spec/defines/peers_spec.rb b/haproxy/spec/defines/peers_spec.rb index d80120ce4..95b768a68 100644 --- a/haproxy/spec/defines/peers_spec.rb +++ b/haproxy/spec/defines/peers_spec.rb @@ -1,7 +1,10 @@ require 'spec_helper' describe 'haproxy::peers' do - let(:facts) {{ :ipaddress => '1.1.1.1' }} + let(:facts) {{ + :ipaddress => '1.1.1.1', + :concat_basedir => '/foo', + }} context "when no options are passed" do let(:title) { 'bar' } diff --git a/haproxy/spec/spec_helper_acceptance.rb b/haproxy/spec/spec_helper_acceptance.rb index 4639ece26..4e2c457fb 100644 --- a/haproxy/spec/spec_helper_acceptance.rb +++ b/haproxy/spec/spec_helper_acceptance.rb @@ -5,7 +5,10 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = { :default_action => 'gem_install' } + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), + } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end diff --git a/haproxy/spec/unit/facter/haproxy_version_spec.rb b/haproxy/spec/unit/facter/haproxy_version_spec.rb index fbd68e6a9..75289fd69 100644 --- a/haproxy/spec/unit/facter/haproxy_version_spec.rb +++ b/haproxy/spec/unit/facter/haproxy_version_spec.rb @@ -11,8 +11,8 @@ HA-Proxy version 1.5.3 2014/07/25 Copyright 2000-2014 Willy Tarreau EOS - Facter::Util::Resolution.expects(:which).with("haproxy").returns(true) - Facter::Util::Resolution.expects(:exec).with("haproxy -v 2>&1").returns(haproxy_version_output) + Facter::Util::Resolution.expects(:which).at_least(1).with("haproxy").returns(true) + Facter::Util::Resolution.expects(:exec).at_least(1).with("haproxy -v 2>&1").returns(haproxy_version_output) Facter.fact(:haproxy_version).value.should == "1.5.3" end end @@ -20,8 +20,8 @@ context "haproxy not present" do it do Facter::Util::Resolution.stubs(:exec) - Facter::Util::Resolution.expects(:which).with("haproxy").returns(false) + Facter::Util::Resolution.expects(:which).at_least(1).with("haproxy").returns(false) Facter.fact(:haproxy_version).should be_nil end end -end \ No newline at end of file +end diff --git a/heat/.gitreview b/heat/.gitreview index 37bb1b287..3818248b0 100644 --- a/heat/.gitreview +++ b/heat/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-heat.git +project=openstack/puppet-heat.git diff --git a/heat/Gemfile b/heat/Gemfile index 4c65317ac..3c0b87530 100644 --- a/heat/Gemfile +++ b/heat/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -17,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/heat/manifests/engine.pp b/heat/manifests/engine.pp index 34778f606..d702992f0 100644 --- a/heat/manifests/engine.pp +++ b/heat/manifests/engine.pp @@ -45,6 +45,28 @@ # Can be "password" or "trusts". # Defaults to 'trusts' # +# [*default_software_config_transport*] +# (optional) Template default for how the server should receive the metadata +# required for software configuration. POLL_SERVER_CFN will allow calls to the +# cfn API action DescribeStackResource authenticated with the provided keypair +# (requires enabled heat-api-cfn). POLL_SERVER_HEAT will allow calls to the +# Heat API resource-show using the provided keystone credentials (requires +# keystone v3 API, and configured stack_user_* config options). POLL_TEMP_URL +# will create and populate a Swift TempURL with metadata for polling (requires +# object-store endpoint which supports TempURL). (string value) +# Allowed values: POLL_SERVER_CFN, POLL_SERVER_HEAT, POLL_TEMP_URL +# Defaults to 'POLL_SERVER_CFN' +# +# [*default_deployment_signal_transport*] +# (optional) Template default for how the server should signal to heat with +# the deployment output values. CFN_SIGNAL will allow an HTTP POST to a CFN +# keypair signed URL (requires enabled heat-api-cfn). TEMP_URL_SIGNAL will +# create a Swift TempURL to be signaled via HTTP PUT (requires object-store +# TempURL). HEAT_SIGNAL will allow calls to the Heat API resource-signal using +# endpoint which supports the provided keystone credentials (string value) +# Allowed values: CFN_SIGNAL, TEMP_URL_SIGNAL, HEAT_SIGNAL +# Defaults to 'CFN_SIGNAL' + # [*trusts_delegated_roles*] # (optional) Array of trustor roles to be delegated to heat. # This value is also used by heat::keystone::auth if it is set to @@ -60,17 +82,19 @@ # class heat::engine ( $auth_encryption_key, - $package_ensure = 'present', - $manage_service = true, - $enabled = true, - $heat_stack_user_role = 'heat_stack_user', - $heat_metadata_server_url = 'http://127.0.0.1:8000', - $heat_waitcondition_server_url = 'http://127.0.0.1:8000/v1/waitcondition', - $heat_watch_server_url = 'http://127.0.0.1:8003', - $engine_life_check_timeout = '2', - $deferred_auth_method = 'trusts', - $trusts_delegated_roles = ['heat_stack_owner'], #DEPRECATED - $configure_delegated_roles = true, #DEPRECATED + $package_ensure = 'present', + $manage_service = true, + $enabled = true, + $heat_stack_user_role = 'heat_stack_user', + $heat_metadata_server_url = 'http://127.0.0.1:8000', + $heat_waitcondition_server_url = 'http://127.0.0.1:8000/v1/waitcondition', + $heat_watch_server_url = 'http://127.0.0.1:8003', + $engine_life_check_timeout = '2', + $deferred_auth_method = 'trusts', + $default_software_config_transport = 'POLL_SERVER_CFN', + $default_deployment_signal_transport = 'CFN_SIGNAL', + $trusts_delegated_roles = ['heat_stack_owner'], #DEPRECATED + $configure_delegated_roles = true, #DEPRECATED ) { # Validate Heat Engine AES key @@ -124,13 +148,15 @@ } heat_config { - 'DEFAULT/auth_encryption_key' : value => $auth_encryption_key; - 'DEFAULT/heat_stack_user_role' : value => $heat_stack_user_role; - 'DEFAULT/heat_metadata_server_url' : value => $heat_metadata_server_url; - 'DEFAULT/heat_waitcondition_server_url': value => $heat_waitcondition_server_url; - 'DEFAULT/heat_watch_server_url' : value => $heat_watch_server_url; - 'DEFAULT/engine_life_check_timeout' : value => $engine_life_check_timeout; - 'DEFAULT/trusts_delegated_roles' : value => $trusts_delegated_roles; - 'DEFAULT/deferred_auth_method' : value => $deferred_auth_method; + 'DEFAULT/auth_encryption_key' : value => $auth_encryption_key; + 'DEFAULT/heat_stack_user_role' : value => $heat_stack_user_role; + 'DEFAULT/heat_metadata_server_url' : value => $heat_metadata_server_url; + 'DEFAULT/heat_waitcondition_server_url' : value => $heat_waitcondition_server_url; + 'DEFAULT/heat_watch_server_url' : value => $heat_watch_server_url; + 'DEFAULT/engine_life_check_timeout' : value => $engine_life_check_timeout; + 'DEFAULT/default_software_config_transport' : value => $default_software_config_transport; + 'DEFAULT/default_deployment_signal_transport' : value => $default_deployment_signal_transport; + 'DEFAULT/trusts_delegated_roles' : value => $trusts_delegated_roles; + 'DEFAULT/deferred_auth_method' : value => $deferred_auth_method; } } diff --git a/heat/manifests/init.pp b/heat/manifests/init.pp index c20b3c8c7..b6a7327df 100644 --- a/heat/manifests/init.pp +++ b/heat/manifests/init.pp @@ -302,65 +302,65 @@ if $rpc_backend == 'heat.openstack.common.rpc.impl_kombu' { if $rabbit_hosts { - heat_config { 'DEFAULT/rabbit_host': ensure => absent } - heat_config { 'DEFAULT/rabbit_port': ensure => absent } - heat_config { 'DEFAULT/rabbit_hosts': + heat_config { 'oslo_messaging_rabbit/rabbit_host': ensure => absent } + heat_config { 'oslo_messaging_rabbit/rabbit_port': ensure => absent } + heat_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } } else { - heat_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - heat_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - heat_config { 'DEFAULT/rabbit_hosts': + heat_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + heat_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + heat_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } } if size($rabbit_hosts) > 1 { - heat_config { 'DEFAULT/rabbit_ha_queues': value => true } + heat_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { - heat_config { 'DEFAULT/rabbit_ha_queues': value => false } + heat_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } heat_config { - 'DEFAULT/rabbit_userid' : value => $rabbit_userid; - 'DEFAULT/rabbit_password' : value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_virtual_host' : value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl' : value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_userid' : value => $rabbit_userid; + 'oslo_messaging_rabbit/rabbit_password' : value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_virtual_host' : value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl' : value => $rabbit_use_ssl; 'DEFAULT/amqp_durable_queues' : value => $amqp_durable_queues; } if $rabbit_use_ssl { if $kombu_ssl_ca_certs { - heat_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } + heat_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } } else { - heat_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; } + heat_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; } } if $kombu_ssl_certfile or $kombu_ssl_keyfile { heat_config { - 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; + 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; } } else { heat_config { - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } if $kombu_ssl_version { - heat_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version; } + heat_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version; } } else { - heat_config { 'DEFAULT/kombu_ssl_version': ensure => absent; } + heat_config { 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } else { heat_config { - 'DEFAULT/kombu_ssl_version': ensure => absent; - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } @@ -521,6 +521,7 @@ user => 'heat', refreshonly => true, logoutput => on_failure, + subscribe => Package['heat-common'], } } } diff --git a/heat/spec/acceptance/nodesets/nodepool-centos7.yml b/heat/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/heat/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/heat/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/heat/spec/acceptance/nodesets/nodepool-trusty.yml b/heat/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/heat/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/heat/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/heat/spec/classes/heat_engine_spec.rb b/heat/spec/classes/heat_engine_spec.rb index 57d2c30bf..7549d06ab 100644 --- a/heat/spec/classes/heat_engine_spec.rb +++ b/heat/spec/classes/heat_engine_spec.rb @@ -13,6 +13,8 @@ :trusts_delegated_roles => ['heat_stack_owner'], :deferred_auth_method => 'trusts', :configure_delegated_roles => true, + :default_software_config_transport => 'POLL_SERVER_CFN', + :default_deployment_signal_transport => 'CFN_SIGNAL', } end @@ -30,6 +32,8 @@ :trusts_delegated_roles => ['role1', 'role2'], :deferred_auth_method => 'trusts', :configure_delegated_roles => true, + :default_software_config_transport => 'POLL_SERVER_CFN', + :default_deployment_signal_transport => 'CFN_SIGNAL', } ].each do |new_params| describe 'when #{param_set == {} ? "using default" : "specifying"} parameters' @@ -69,6 +73,8 @@ it { is_expected.to contain_heat_config('DEFAULT/engine_life_check_timeout').with_value( expected_params[:engine_life_check_timeout] ) } it { is_expected.to contain_heat_config('DEFAULT/trusts_delegated_roles').with_value( expected_params[:trusts_delegated_roles] ) } it { is_expected.to contain_heat_config('DEFAULT/deferred_auth_method').with_value( expected_params[:deferred_auth_method] ) } + it { is_expected.to contain_heat_config('DEFAULT/default_software_config_transport').with_value( expected_params[:default_software_config_transport] ) } + it { is_expected.to contain_heat_config('DEFAULT/default_deployment_signal_transport').with_value( expected_params[:default_deployment_signal_transport] ) } it 'configures delegated roles' do is_expected.to contain_keystone_role("role1").with( diff --git a/heat/spec/classes/heat_init_spec.rb b/heat/spec/classes/heat_init_spec.rb index 52f203494..83f330783 100644 --- a/heat/spec/classes/heat_init_spec.rb +++ b/heat/spec/classes/heat_init_spec.rb @@ -122,6 +122,11 @@ ) end + it 'has db_sync enabled' do + is_expected.to contain_exec('heat-dbsync').with( + :subscribe => 'Package[heat-common]', + ) + end it 'configures debug and verbose' do is_expected.to contain_heat_config('DEFAULT/debug').with_value( params[:debug] ) @@ -175,58 +180,58 @@ shared_examples_for 'rabbit without HA support (with backward compatibility)' do it 'configures rabbit' do - is_expected.to contain_heat_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_password').with_secret( true ) - is_expected.to contain_heat_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_use_ssl').with_value(false) - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_version').with_ensure('absent') - end - it { is_expected.to contain_heat_config('DEFAULT/rabbit_host').with_value( params[:rabbit_host] ) } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_port').with_value( params[:rabbit_port] ) } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_hosts').with_value( "#{params[:rabbit_host]}:#{params[:rabbit_port]}" ) } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_ha_queues').with_value('false') } + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') + end + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_host').with_value( params[:rabbit_host] ) } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_port').with_value( params[:rabbit_port] ) } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_hosts').with_value( "#{params[:rabbit_host]}:#{params[:rabbit_port]}" ) } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') } it { is_expected.to contain_heat_config('DEFAULT/amqp_durable_queues').with_value(false) } end shared_examples_for 'rabbit without HA support (without backward compatibility)' do it 'configures rabbit' do - is_expected.to contain_heat_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_password').with_secret( true ) - is_expected.to contain_heat_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_use_ssl').with_value(false) - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_version').with_ensure('absent') - end - it { is_expected.to contain_heat_config('DEFAULT/rabbit_host').with_ensure('absent') } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_port').with_ensure('absent') } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_ha_queues').with_value('false') } + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') + end + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_host').with_ensure('absent') } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_port').with_ensure('absent') } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') } it { is_expected.to contain_heat_config('DEFAULT/amqp_durable_queues').with_value(false) } end shared_examples_for 'rabbit with HA support' do it 'configures rabbit' do - is_expected.to contain_heat_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_password').with_secret( true ) - is_expected.to contain_heat_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) - is_expected.to contain_heat_config('DEFAULT/rabbit_use_ssl').with_value(false) - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_version').with_ensure('absent') - end - it { is_expected.to contain_heat_config('DEFAULT/rabbit_host').with_ensure('absent') } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_port').with_ensure('absent') } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } - it { is_expected.to contain_heat_config('DEFAULT/rabbit_ha_queues').with_value('true') } + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') + end + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_host').with_ensure('absent') } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_port').with_ensure('absent') } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } + it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } it { is_expected.to contain_heat_config('DEFAULT/amqp_durable_queues').with_value(true) } end @@ -272,11 +277,11 @@ end it do - is_expected.to contain_heat_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -288,11 +293,11 @@ end it do - is_expected.to contain_heat_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -305,11 +310,11 @@ end it do - is_expected.to contain_heat_config('DEFAULT/rabbit_use_ssl').with_value('false') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_heat_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end diff --git a/horizon/.gitreview b/horizon/.gitreview index 14c44d48d..765382400 100644 --- a/horizon/.gitreview +++ b/horizon/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-horizon.git +project=openstack/puppet-horizon.git diff --git a/horizon/Gemfile b/horizon/Gemfile index 0014b44f8..c22078253 100644 --- a/horizon/Gemfile +++ b/horizon/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'puppet-lint', '~> 1.1.0' gem 'metadata-json-lint' @@ -18,7 +17,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/horizon/manifests/wsgi/apache.pp b/horizon/manifests/wsgi/apache.pp index 797fe9147..1333420ba 100644 --- a/horizon/manifests/wsgi/apache.pp +++ b/horizon/manifests/wsgi/apache.pp @@ -101,7 +101,7 @@ # - ${priority}-${vhost_conf_name}.conf # - ${priority}-${vhost_ssl_conf_name}.conf #", - require => Package[$::horizon::params::package_name], + require => Package['horizon'], } diff --git a/horizon/spec/acceptance/nodesets/nodepool-centos7.yml b/horizon/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/horizon/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/horizon/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/horizon/spec/acceptance/nodesets/nodepool-trusty.yml b/horizon/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/horizon/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/horizon/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/inifile/CHANGELOG.md b/inifile/CHANGELOG.md index ab0263868..375e910f0 100644 --- a/inifile/CHANGELOG.md +++ b/inifile/CHANGELOG.md @@ -1,3 +1,20 @@ +##2015-06-09 - Supported Releases 1.3.0 +###Summary + +This is primarily a feature release, but also includes test fixes, documentation updates and synchronization of files with modulesync. + +####Features +- Synchronized files using modulesync +- Improved documentation +- Allow changing key value separator beyond indentation +- Adding the ability to change regex match for $section in inifile + +####Bugfixes +- pin beaker-rspec for windows testing +- pin rspec gems for testing +- Adds default values for section +- Fixed names containing spaces + ##2014-11-11 - Supported Releases 1.2.0 ###Summary diff --git a/inifile/CONTRIBUTING.md b/inifile/CONTRIBUTING.md index f1cbde4bb..bfeaa701c 100644 --- a/inifile/CONTRIBUTING.md +++ b/inifile/CONTRIBUTING.md @@ -159,7 +159,7 @@ If you already have those gems installed, make sure they are up-to-date: With all dependencies in place and up-to-date we can now run the tests: ```shell -% rake spec +% bundle exec rake spec ``` This will execute all the [rspec tests](http://rspec-puppet.com/) tests @@ -178,8 +178,8 @@ installed on your system. You can run them by issuing the following command ```shell -% rake spec_clean -% rspec spec/acceptance +% bundle exec rake spec_clean +% bundle exec rspec spec/acceptance ``` This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml), diff --git a/inifile/Gemfile b/inifile/Gemfile index 2b1b7cd8d..04f8667df 100644 --- a/inifile/Gemfile +++ b/inifile/Gemfile @@ -27,7 +27,8 @@ group :system_tests do else gem 'beaker-rspec', :require => false end - gem 'serverspec', :require => false + gem 'serverspec', :require => false + gem 'beaker-puppet_install_helper', :require => false end diff --git a/inifile/metadata.json b/inifile/metadata.json index 9f96ceb01..b4bff409c 100644 --- a/inifile/metadata.json +++ b/inifile/metadata.json @@ -1,12 +1,15 @@ { "name": "puppetlabs-inifile", - "version": "1.2.0", + "version": "1.3.0", "author": "Puppet Labs", "summary": "Resource types for managing settings in INI files", "license": "Apache-2.0", "source": "https://github.com/puppetlabs/puppetlabs-inifile", "project_page": "https://github.com/puppetlabs/puppetlabs-inifile", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", + "dependencies": [ + + ], "operatingsystem_support": [ { "operatingsystem": "RedHat", @@ -97,8 +100,5 @@ "name": "puppet", "version_requirement": "3.x" } - ], - "dependencies": [ - ] } diff --git a/inifile/spec/spec_helper_acceptance.rb b/inifile/spec/spec_helper_acceptance.rb index 80a6b6257..dd1f1f0f5 100644 --- a/inifile/spec/spec_helper_acceptance.rb +++ b/inifile/spec/spec_helper_acceptance.rb @@ -1,24 +1,8 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' +require 'beaker/puppet_install_helper' -unless ENV['RS_PROVISION'] == 'no' - # This will install the latest available package on el and deb based - # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = {:default_action => 'gem_install'} - - if default.is_pe?; then - install_pe; - else - install_puppet(foss_opts); - end - - hosts.each do |host| - if host['platform'] =~ /debian/ - on host, 'echo \'export PATH=/var/lib/gems/1.8/bin/:${PATH}\' >> ~/.bashrc' - on host, "mkdir -p #{host['distmoduledir']}" - end - end -end +run_puppet_install_helper RSpec.configure do |c| # Project root diff --git a/ironic/.fixtures.yml b/ironic/.fixtures.yml index ef880bc26..718df5723 100644 --- a/ironic/.fixtures.yml +++ b/ironic/.fixtures.yml @@ -1,9 +1,13 @@ fixtures: repositories: 'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile' + 'concat': + 'repo': 'git://github.com/puppetlabs/puppetlabs-concat.git' + 'ref': '1.2.1' 'keystone': 'git://github.com/stackforge/puppet-keystone.git' 'mysql': 'git://github.com/puppetlabs/puppetlabs-mysql.git' 'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git' + 'postgresql': 'git://github.com/puppetlabs/puppet-postgresql.git' 'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git' symlinks: 'ironic': "#{source_dir}" diff --git a/ironic/.gitreview b/ironic/.gitreview index 1ac7755c5..98fe90f15 100644 --- a/ironic/.gitreview +++ b/ironic/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-ironic.git +project=openstack/puppet-ironic.git diff --git a/ironic/Gemfile b/ironic/Gemfile index 5f76c2d3e..212eec887 100644 --- a/ironic/Gemfile +++ b/ironic/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-absolute_classname-check' @@ -16,7 +15,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/ironic/manifests/db/postgresql.pp b/ironic/manifests/db/postgresql.pp new file mode 100644 index 000000000..7fe7bb255 --- /dev/null +++ b/ironic/manifests/db/postgresql.pp @@ -0,0 +1,47 @@ +# == Class: ironic::db::postgresql +# +# Class that configures postgresql for ironic +# Requires the Puppetlabs postgresql module. +# +# === Parameters +# +# [*password*] +# (Required) Password to connect to the database. +# +# [*dbname*] +# (Optional) Name of the database. +# Defaults to 'ironic'. +# +# [*user*] +# (Optional) User to connect to the database. +# Defaults to 'ironic'. +# +# [*encoding*] +# (Optional) The charset to use for the database. +# Default to undef. +# +# [*privileges*] +# (Optional) Privileges given to the database user. +# Default to 'ALL' +# +class ironic::db::postgresql( + $password, + $dbname = 'ironic', + $user = 'ironic', + $encoding = undef, + $privileges = 'ALL', +) { + + Class['ironic::db::postgresql'] -> Service<| title == 'ironic' |> + + ::openstacklib::db::postgresql { 'ironic': + password_hash => postgresql_password($user, $password), + dbname => $dbname, + user => $user, + encoding => $encoding, + privileges => $privileges, + } + + ::Openstacklib::Db::Postgresql['ironic'] ~> Exec<| title == 'ironic-dbsync' |> + +} diff --git a/ironic/manifests/init.pp b/ironic/manifests/init.pp index bd48bc226..749a6a870 100644 --- a/ironic/manifests/init.pp +++ b/ironic/manifests/init.pp @@ -325,52 +325,52 @@ } ironic_config { - 'DEFAULT/rabbit_userid': value => $rabbit_user_real; - 'DEFAULT/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_user_real; + 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_virtual_host': value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl': value => $rabbit_use_ssl; 'DEFAULT/control_exchange': value => $control_exchange; 'DEFAULT/amqp_durable_queues': value => $amqp_durable_queues; } if $rabbit_hosts { - ironic_config { 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ',') } - ironic_config { 'DEFAULT/rabbit_ha_queues': value => true } - ironic_config { 'DEFAULT/rabbit_host': ensure => absent } - ironic_config { 'DEFAULT/rabbit_port': ensure => absent } + ironic_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } + ironic_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } + ironic_config { 'oslo_messaging_rabbit/rabbit_host': ensure => absent } + ironic_config { 'oslo_messaging_rabbit/rabbit_port': ensure => absent } } else { - ironic_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - ironic_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - ironic_config { 'DEFAULT/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } - ironic_config { 'DEFAULT/rabbit_ha_queues': value => false } + ironic_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + ironic_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + ironic_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } + ironic_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } if $rabbit_use_ssl { - ironic_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version } + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version } if $kombu_ssl_ca_certs { - ironic_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs } + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs } } else { - ironic_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent} + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent} } if $kombu_ssl_certfile { - ironic_config { 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile } + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile } } else { - ironic_config { 'DEFAULT/kombu_ssl_certfile': ensure => absent} + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent} } if $kombu_ssl_keyfile { - ironic_config { 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile } + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile } } else { - ironic_config { 'DEFAULT/kombu_ssl_keyfile': ensure => absent} + ironic_config { 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent} } } else { ironic_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } diff --git a/ironic/spec/acceptance/nodesets/nodepool-centos7.yml b/ironic/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/ironic/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/ironic/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/ironic/spec/acceptance/nodesets/nodepool-trusty.yml b/ironic/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/ironic/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/ironic/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/ironic/spec/classes/ironic_db_postgresql_spec.rb b/ironic/spec/classes/ironic_db_postgresql_spec.rb new file mode 100644 index 000000000..91874f083 --- /dev/null +++ b/ironic/spec/classes/ironic_db_postgresql_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'ironic::db::postgresql' do + + let :req_params do + { :password => 'pw' } + end + + let :pre_condition do + 'include postgresql::server' + end + + context 'on a RedHat osfamily' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + :concat_basedir => '/var/lib/puppet/concat' + } + end + + context 'with only required parameters' do + let :params do + req_params + end + + it { is_expected.to contain_postgresql__server__db('ironic').with( + :user => 'ironic', + :password => 'md554bdb85e136b50c40104fd9f73e1294d' + )} + end + + end + + context 'on a Debian osfamily' do + let :facts do + { + :operatingsystemrelease => '7.8', + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :concat_basedir => '/var/lib/puppet/concat' + } + end + + context 'with only required parameters' do + let :params do + req_params + end + + it { is_expected.to contain_postgresql__server__db('ironic').with( + :user => 'ironic', + :password => 'md554bdb85e136b50c40104fd9f73e1294d' + )} + end + + end + +end diff --git a/ironic/spec/classes/ironic_init_spec.rb b/ironic/spec/classes/ironic_init_spec.rb index fb3f0ca80..1f5a037ad 100644 --- a/ironic/spec/classes/ironic_init_spec.rb +++ b/ironic/spec/classes/ironic_init_spec.rb @@ -128,10 +128,10 @@ end it 'configures credentials for rabbit' do - is_expected.to contain_ironic_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_userid] ) - is_expected.to contain_ironic_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_ironic_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) - is_expected.to contain_ironic_config('DEFAULT/rabbit_password').with_secret( true ) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) end it 'should perform default database configuration' do @@ -155,19 +155,19 @@ shared_examples_for 'rabbit HA with a single virtual host' do it 'in ironic.conf' do - is_expected.to contain_ironic_config('DEFAULT/rabbit_host').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/rabbit_port').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts] ) - is_expected.to contain_ironic_config('DEFAULT/rabbit_ha_queues').with_value(true) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_host').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_port').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts] ) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) end end shared_examples_for 'rabbit HA with multiple hosts' do it 'in ironic.conf' do - is_expected.to contain_ironic_config('DEFAULT/rabbit_host').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/rabbit_port').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) - is_expected.to contain_ironic_config('DEFAULT/rabbit_ha_queues').with_value(true) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_host').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_port').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) end end @@ -183,11 +183,11 @@ end it do - is_expected.to contain_ironic_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -199,11 +199,11 @@ end it do - is_expected.to contain_ironic_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -219,11 +219,11 @@ end it do - is_expected.to contain_ironic_config('DEFAULT/rabbit_use_ssl').with_value('false') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_ironic_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_ironic_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end diff --git a/keystone/.gitreview b/keystone/.gitreview index 23429b728..03e6182a3 100644 --- a/keystone/.gitreview +++ b/keystone/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-keystone.git +project=openstack/puppet-keystone.git diff --git a/keystone/Gemfile b/keystone/Gemfile index e8271383f..4d9cab8af 100644 --- a/keystone/Gemfile +++ b/keystone/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -19,7 +18,7 @@ group :development, :test do gem 'json' gem 'webmock' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/keystone/lib/puppet/provider/keystone.rb b/keystone/lib/puppet/provider/keystone.rb index b5112290c..4e7815abf 100644 --- a/keystone/lib/puppet/provider/keystone.rb +++ b/keystone/lib/puppet/provider/keystone.rb @@ -1,36 +1,33 @@ require 'puppet/util/inifile' require 'puppet/provider/openstack' +require 'puppet/provider/openstack/auth' +require 'puppet/provider/openstack/credentials' + class Puppet::Provider::Keystone < Puppet::Provider::Openstack - def request(service, action, object, credentials, *properties) - begin - super - rescue Puppet::Error::OpenstackAuthInputError => error - keystone_request(service, action, object, credentials, error, *properties) - end - end + extend Puppet::Provider::Openstack::Auth - def self.request(service, action, object, credentials, *properties) - begin - super - rescue Puppet::Error::OpenstackAuthInputError => error - keystone_request(service, action, object, credentials, error, *properties) - end - end + INI_FILENAME = '/etc/keystone/keystone.conf' - def keystone_request(service, action, object, credentials, error, *properties) - self.class.keystone_request(service, action, object, credentials, error, *properties) + def self.get_endpoint + endpoint = nil + if ENV['OS_AUTH_URL'] + endpoint = ENV['OS_AUTH_URL'] + else + endpoint = get_os_vars_from_rcfile(rc_filename)['OS_AUTH_URL'] + unless endpoint + # This is from legacy but seems wrong, we want auth_url not url! + endpoint = get_admin_endpoint + end + end + unless endpoint + raise(Puppet::Error::OpenstackAuthInputError, 'Could not find auth url to check user password.') + end + endpoint end - def self.keystone_request(service, action, object, credentials, error, *properties) - credentials = { - 'token' => get_admin_token, - 'url' => get_admin_endpoint, - } - raise error unless (credentials['token'] && credentials['url']) - auth_args = token_auth_args(credentials) - args = [object, properties, auth_args].flatten.compact - authenticate_request(service, action, args) + def self.admin_endpoint + @admin_endpoint ||= get_admin_endpoint end def self.admin_token @@ -45,21 +42,12 @@ def self.get_admin_token end end - def self.admin_endpoint - @admin_endpoint ||= get_admin_endpoint - end - - def get_admin_token - self.class.get_admin_token - end - - def self.get_admin_endpoint if keystone_file if keystone_file['DEFAULT'] if keystone_file['DEFAULT']['admin_endpoint'] auth_url = keystone_file['DEFAULT']['admin_endpoint'].strip.chomp('/') - return "#{auth_url}/v2.0/" + return "#{auth_url}/v#{@credentials.version}/" end if keystone_file['DEFAULT']['admin_port'] @@ -87,22 +75,34 @@ def self.get_admin_endpoint end end - "#{protocol}://#{host}:#{admin_port}/v2.0/" + "#{protocol}://#{host}:#{admin_port}/v#{@credentials.version}/" end - def get_admin_endpoint - self.class.get_admin_endpoint + def self.request(service, action, properties=nil) + super + rescue Puppet::Error::OpenstackAuthInputError => error + request_by_service_token(service, action, error, properties) end - def self.keystone_file - return @keystone_file if @keystone_file - @keystone_file = Puppet::Util::IniConfig::File.new - @keystone_file.read('/etc/keystone/keystone.conf') - @keystone_file + def self.request_by_service_token(service, action, error, properties=nil) + properties ||= [] + @credentials.token = get_admin_token + @credentials.url = get_admin_endpoint + raise error unless @credentials.service_token_set? + Puppet::Provider::Openstack.request(service, action, properties, @credentials) end - def keystone_file - self.class.keystone_file + def self.ini_filename + INI_FILENAME + end + + def self.keystone_file + return @keystone_file if @keystone_file + if File.exists?(ini_filename) + @keystone_file = Puppet::Util::IniConfig::File.new + @keystone_file.read(ini_filename) + @keystone_file + end end # Helper functions to use on the pre-validated enabled field @@ -113,5 +113,4 @@ def bool_to_sym(bool) def sym_to_bool(sym) sym == :true ? true : false end - end diff --git a/keystone/lib/puppet/provider/keystone_endpoint/openstack.rb b/keystone/lib/puppet/provider/keystone_endpoint/openstack.rb index ac7780d48..97de693d8 100644 --- a/keystone/lib/puppet/provider/keystone_endpoint/openstack.rb +++ b/keystone/lib/puppet/provider/keystone_endpoint/openstack.rb @@ -7,6 +7,8 @@ desc "Provider to manage keystone endpoints." + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + def initialize(value={}) super(value) @property_flush = {} @@ -16,6 +18,7 @@ def create properties = [] # The region property is just ignored. We should fix this in kilo. region, name = resource[:name].split('/') + properties << name properties << '--region' properties << region if resource[:public_url] @@ -30,56 +33,53 @@ def create properties << '--adminurl' properties << resource[:admin_url] end - @instance = request('endpoint', 'create', name, resource[:auth], properties) - end - - def exists? - ! instance(resource[:name]).empty? + self.class.request('endpoint', 'create', properties) + @property_hash[:ensure] = :present end def destroy - id = instance(resource[:name])[:id] - request('endpoint', 'delete', id, resource[:auth]) + self.class.request('endpoint', 'delete', @property_hash[:id]) + @property_hash.clear end + def exists? + @property_hash[:ensure] == :present + end def region - instance(resource[:name])[:region] + @property_hash[:region] end - def public_url=(value) @property_flush[:public_url] = value end def public_url - instance(resource[:name])[:public_url] + @property_hash[:public_url] end - def internal_url=(value) @property_flush[:internal_url] = value end def internal_url - instance(resource[:name])[:internal_url] + @property_hash[:internal_url] end - def admin_url=(value) @property_flush[:admin_url] = value end def admin_url - instance(resource[:name])[:admin_url] + @property_hash[:admin_url] end def id - instance(resource[:name])[:id] + @property_hash[:id] end def self.instances - list = request('endpoint', 'list', nil, nil, '--long') + list = request('endpoint', 'list', '--long') list.collect do |endpoint| new( :name => "#{endpoint[:region]}/#{endpoint[:service_name]}", @@ -93,30 +93,20 @@ def self.instances end end - def instances - instances = request('endpoint', 'list', nil, resource[:auth], '--long') - instances.collect do |endpoint| - { - :name => "#{endpoint[:region]}/#{endpoint[:service_name]}", - :id => endpoint[:id], - :region => endpoint[:region], - :public_url => endpoint[:publicurl], - :internal_url => endpoint[:internalurl], - :admin_url => endpoint[:adminurl] - } + def self.prefetch(resources) + endpoints = instances + resources.keys.each do |name| + if provider = endpoints.find{ |endpoint| endpoint.name == name } + resources[name].provider = provider + end end end - def instance(name) - @instance ||= instances.select { |instance| instance[:name] == name }.first || {} - end - def flush - if ! @property_flush.empty? + if ! @property_flush.empty? destroy create @property_flush.clear end end - end diff --git a/keystone/lib/puppet/provider/keystone_role/openstack.rb b/keystone/lib/puppet/provider/keystone_role/openstack.rb index b3bd85621..b15462047 100644 --- a/keystone/lib/puppet/provider/keystone_role/openstack.rb +++ b/keystone/lib/puppet/provider/keystone_role/openstack.rb @@ -7,25 +7,33 @@ desc 'Provider for keystone roles.' - def create - properties = [] - @instance = request('role', 'create', resource[:name], resource[:auth], properties) + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + + def initialize(value={}) + super(value) + @property_flush = {} end - def exists? - ! instance(resource[:name]).empty? + def create + self.class.request('role', 'create', name) + @property_hash[:ensure] = :present end def destroy - request('role', 'delete', resource[:name], resource[:auth]) + self.class.request('role', 'delete', @property_hash[:id]) + @property_hash.clear + end + + def exists? + @property_hash[:ensure] == :present end def id - instance(resource[:name])[:id] + @property_hash[:id] end def self.instances - list = request('role', 'list', nil, nil) + list = request('role', 'list') list.collect do |role| new( :name => role[:name], @@ -35,18 +43,12 @@ def self.instances end end - def instances - instances = request('role', 'list', nil, resource[:auth]) - instances.collect do |role| - { - :name => role[:name], - :id => role[:id] - } + def self.prefetch(resources) + roles = instances + resources.keys.each do |name| + if provider = roles.find{ |role| role.name == name } + resources[name].provider = provider + end end end - - def instance(name) - @instance ||= instances.select { |instance| instance[:name] == name }.first || {} - end - end diff --git a/keystone/lib/puppet/provider/keystone_service/openstack.rb b/keystone/lib/puppet/provider/keystone_service/openstack.rb index 54e75f596..4853b7d27 100644 --- a/keystone/lib/puppet/provider/keystone_service/openstack.rb +++ b/keystone/lib/puppet/provider/keystone_service/openstack.rb @@ -7,57 +7,57 @@ desc "Provider to manage keystone services." + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + def initialize(value={}) super(value) @property_flush = {} end def create - properties = [] + properties = ['--name'] + properties << resource[:name] if resource[:description] properties << '--description' properties << resource[:description] end - if resource[:type] - properties << '--type' - properties << resource[:type] - end - @instance = request('service', 'create', resource[:name], resource[:auth], properties) + raise(Puppet::Error, 'The service type is mandatory') unless resource[:type] + properties << resource[:type] + self.class.request('service', 'create', properties) + @property_hash[:ensure] = :present end def exists? - ! instance(resource[:name]).empty? + @property_hash[:ensure] == :present end def destroy - request('service', 'delete', resource[:name], resource[:auth]) + self.class.request('service', 'delete', @property_hash[:id]) + @property_hash.clear end - def description=(value) - raise(Puppet::Error, "Updating the service is not currently supported.") + @property_flush[:description] = value end def description - instance(resource[:name])[:description] + @property_hash[:description] end - def type=(value) - raise(Puppet::Error, "Updating the service is not currently supported.") + @property_flush[:type] = value end def type - instance(resource[:name])[:type] + @property_hash[:type] end - def id - instance(resource[:name])[:id] + @property_hash[:id] end def self.instances - list = request('service', 'list', nil, nil, '--long') + list = request('service', 'list', '--long') list.collect do |service| new( :name => service[:name], @@ -69,30 +69,20 @@ def self.instances end end - def instances - instances = request('service', 'list', nil, resource[:auth], '--long') - instances.collect do |service| - { - :name => service[:name], - :type => service[:type], - :description => service[:description], - :id => service[:id] - } + def self.prefetch(resources) + services = instances + resources.keys.each do |name| + if provider = services.find{ |service| service.name == name } + resources[name].provider = provider + end end end - def instance(name) - @instance ||= instances.select { |instance| instance[:name] == name }.first || {} - end - def flush - options = [] - if @property_flush - # There is a --description flag for the set command, but it does not work if the value is empty - (options << '--property' << "type=#{resource[:type]}") if @property_flush[:type] - (options << '--property' << "description=#{resource[:description]}") if @property_flush[:description] - request('project', 'set', resource[:name], resource[:auth], options) unless options.empty? + if ! @property_flush.empty? + destroy + create + @property_flush.clear end end - end diff --git a/keystone/lib/puppet/provider/keystone_tenant/openstack.rb b/keystone/lib/puppet/provider/keystone_tenant/openstack.rb index 7d19fcef0..198798477 100644 --- a/keystone/lib/puppet/provider/keystone_tenant/openstack.rb +++ b/keystone/lib/puppet/provider/keystone_tenant/openstack.rb @@ -7,13 +7,15 @@ desc "Provider to manage keystone tenants/projects." + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + def initialize(value={}) super(value) @property_flush = {} end def create - properties = [] + properties = [resource[:name]] if resource[:enabled] == :true properties << '--enable' elsif resource[:enabled] == :false @@ -23,42 +25,41 @@ def create properties << '--description' properties << resource[:description] end - @instance = request('project', 'create', resource[:name], resource[:auth], properties) + self.class.request('project', 'create', properties) + @property_hash[:ensure] = :present end def exists? - ! instance(resource[:name]).empty? + @property_hash[:ensure] == :present end def destroy - request('project', 'delete', resource[:name], resource[:auth]) + self.class.request('project', 'delete', @property_hash[:id]) + @property_hash.clear end - def enabled=(value) @property_flush[:enabled] = value end def enabled - bool_to_sym(instance(resource[:name])[:enabled]) + bool_to_sym(@property_hash[:enabled]) end - def description=(value) @property_flush[:description] = value end def description - instance(resource[:name])[:description] + @property_hash[:description] end - def id - instance(resource[:name])[:id] + @property_hash[:id] end def self.instances - list = request('project', 'list', nil, nil, '--long') + list = request('project', 'list', '--long') list.collect do |project| new( :name => project[:name], @@ -70,30 +71,28 @@ def self.instances end end - def instances - instances = request('project', 'list', nil, resource[:auth], '--long') - instances.collect do |project| - { - :name => project[:name], - :enabled => project[:enabled].downcase.chomp == 'true' ? true : false, - :description => project[:description], - :id => project[:id] - } + def self.prefetch(resources) + tenants = instances + resources.keys.each do |name| + if provider = tenants.find{ |tenant| tenant.name == name } + resources[name].provider = provider + end end end - def instance(name) - @instance ||= instances.select { |instance| instance[:name] == name }.first || {} - end - def flush options = [] - if @property_flush - (options << '--enable') if @property_flush[:enabled] == :true - (options << '--disable') if @property_flush[:enabled] == :false - # There is a --description flag for the set command, but it does not work if the value is empty - (options << '--property' << "description=#{resource[:description]}") if @property_flush[:description] - request('project', 'set', resource[:name], resource[:auth], options) unless options.empty? + if @property_flush && !@property_flush.empty? + case @property_flush[:enabled] + when :true + options << '--enable' + when :false + options << '--disable' + end + (options << "--description=#{resource[:description]}") if @property_flush[:description] + options << @property_hash[:id] + self.class.request('project', 'set', options) unless options.empty? + @property_flush.clear end end diff --git a/keystone/lib/puppet/provider/keystone_user/openstack.rb b/keystone/lib/puppet/provider/keystone_user/openstack.rb index 6c8d04aa2..05dd1a2c0 100644 --- a/keystone/lib/puppet/provider/keystone_user/openstack.rb +++ b/keystone/lib/puppet/provider/keystone_user/openstack.rb @@ -1,6 +1,5 @@ -require 'net/http' -require 'json' require 'puppet/provider/keystone' + Puppet::Type.type(:keystone_user).provide( :openstack, :parent => Puppet::Provider::Keystone @@ -8,137 +7,115 @@ desc "Provider to manage keystone users." + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + def initialize(value={}) super(value) @property_flush = {} end def create - properties = [] + properties = [resource[:name]] if resource[:enabled] == :true properties << '--enable' elsif resource[:enabled] == :false properties << '--disable' end if resource[:password] - properties << '--password' - properties << resource[:password] + properties << '--password' << resource[:password] end if resource[:tenant] - properties << '--project' - properties << resource[:tenant] + properties << '--project' << resource[:tenant] end if resource[:email] - properties << '--email' - properties << resource[:email] + properties << '--email' << resource[:email] end - @instance = request('user', 'create', resource[:name], resource[:auth], properties) + self.class.request('user', 'create', properties) + @property_hash[:ensure] = :present end - def exists? - ! instance(resource[:name]).empty? + def destroy + self.class.request('user', 'delete', @property_hash[:id]) + @property_hash.clear end - def destroy - request('user', 'delete', resource[:name], resource[:auth]) + def flush + options = [] + if @property_flush && !@property_flush.empty? + options << '--enable' if @property_flush[:enabled] == :true + options << '--disable' if @property_flush[:enabled] == :false + # There is a --description flag for the set command, but it does not work if the value is empty + options << '--password' << resource[:password] if @property_flush[:password] + options << '--email' << resource[:email] if @property_flush[:email] + # project handled in tenant= separately + unless options.empty? + options << @property_hash[:id] + self.class.request('user', 'set', options) + end + @property_flush.clear + end end + def exists? + @property_hash[:ensure] == :present + end + + # Types properties + def enabled + bool_to_sym(@property_hash[:enabled]) + end def enabled=(value) @property_flush[:enabled] = value end - def enabled - bool_to_sym(instance(resource[:name])[:enabled]) + def email + @property_hash[:email] end + def email=(value) + @property_flush[:email] = value + end - def password=(value) - @property_flush[:password] = value + def id + @property_hash[:id] end def password - # if we don't know a password we can't test it - return nil if resource[:password] == nil - # if the user is disabled then the password can't be changed - return resource[:password] if resource[:enabled] == :false - # if replacing password is disabled, then don't change it - return resource[:password] if resource[:replace_password] == :false - # we can't get the value of the password but we can test to see if the one we know - # about works, if it doesn't then return nil, causing it to be reset - endpoint = nil - if password_credentials_set?(resource[:auth]) || service_credentials_set?(resource[:auth]) - endpoint = (resource[:auth])['auth_url'] - elsif openrc_set?(resource[:auth]) - endpoint = get_credentials_from_openrc(resource[:auth])['auth_url'] - elsif env_vars_set? - endpoint = ENV['OS_AUTH_URL'] - else - # try to get endpoint from keystone.conf - endpoint = get_admin_endpoint - end - if endpoint == nil - raise(Puppet::Error::OpenstackAuthInputError, 'Could not find auth url to check user password.') + res = nil + return res if resource[:password] == nil + if resource[:enabled] == :false || resource[:replace_password] == :false + # Unchanged password + res = resource[:password] else - auth_params = { - 'username' => resource[:name], - 'password' => resource[:password], - 'tenant_name' => resource[:tenant], - 'auth_url' => endpoint, - } - # LP#1408754 - # Ideally this would be checked with the `openstack token issue` command, - # but that command is not available with version 0.3.0 of openstackclient - # which is what ships on Ubuntu during Juno. - # Instead we'll check whether the user can authenticate with curl. - creds_hash = { - :auth => { - :passwordCredentials => { - :username => auth_params['username'], - :password => auth_params['password'], - } - } - } - url = URI.parse(endpoint) - # There is issue with ipv6 where address has to be in brackets, this causes the - # underlying ruby TCPSocket to fail. Net::HTTP.new will fail without brackets on - # joining the ipv6 address with :port or passing brackets to TCPSocket. It was - # found that if we use Net::HTTP.start with url.hostname the incriminated code - # won't be hit. - use_ssl = url.scheme == "https" ? true : false - http = Net::HTTP.start(url.hostname, url.port, {:use_ssl => use_ssl}) - request = Net::HTTP::Post.new('/v2.0/tokens') - request.body = creds_hash.to_json - request.content_type = 'application/json' - response = http.request(request) - if response.code.to_i == 401 || response.code.to_i == 403 # 401 => unauthorized, 403 => userDisabled - return nil - elsif ! (response.code == 200 || response.code == 203) - return resource[:password] - else - raise(Puppet::Error, "Received bad response while trying to authenticate user: #{response.body}") - end + # Password validation + credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + credentials.auth_url = self.class.get_endpoint + credentials.password = resource[:password] + credentials.project_name = resource[:tenant] + credentials.username = resource[:name] + token = Puppet::Provider::Openstack.request('token', 'issue', ['--format', 'value'], credentials) + res = resource[:password] unless token.empty? end + return res end - def tenant=(value) - begin - request('user', 'set', resource[:name], resource[:auth], '--project', value) - rescue Puppet::ExecutionFailure => e - if e.message =~ /You are not authorized to perform the requested action: LDAP user update/ - # read-only LDAP identity backend - just fall through - else - raise e - end - # note: read-write ldap will silently fail, not raise an exception - end - set_project(value) + def password=(value) + @property_flush[:password] = value + end + + def replace_password + @property_hash[:replace_password] + end + + def replace_password=(value) + @property_flush[:replace_password] = value end def tenant return resource[:tenant] if sym_to_bool(resource[:ignore_default_tenant]) # use the one returned from instances - tenant_name = instance(resource[:name])[:project] + tenant_name = @property_hash[:project] if tenant_name.nil? or tenant_name.empty? # if none (i.e. ldap backend) use the given one tenant_name = resource[:tenant] @@ -151,7 +128,7 @@ def tenant # If the user list command doesn't report the project, it might still be there # We don't need to know exactly what it is, we just need to know whether it's # the one we're trying to set. - roles = request('user role', 'list', resource[:name], resource[:auth], ['--project', tenant_name]) + roles = self.class.request('user role', 'list', [resource[:name], '--project', tenant_name]) if roles.empty? return nil else @@ -159,64 +136,48 @@ def tenant end end - def replace_password - instance(resource[:name])[:replace_password] - end - - def replace_password=(value) - @property_flush[:replace_password] = value - end - - def email=(value) - @property_flush[:email] = value - end - - def email - instance(resource[:name])[:email] - end - - def id - instance(resource[:name])[:id] + def tenant=(value) + self.class.request('user', 'set', [resource[:name], '--project', value]) + rescue Puppet::ExecutionFailure => e + if e.message =~ /You are not authorized to perform the requested action: LDAP user update/ + # read-only LDAP identity backend - just fall through + else + raise e + end + # note: read-write ldap will silently fail, not raise an exception + else + @property_hash[:tenant] = self.class.set_project(value, resource[:name]) end def self.instances - list = request('user', 'list', nil, nil, '--long') + list = request('user', 'list', '--long') list.collect do |user| new( :name => user[:name], :ensure => :present, :enabled => user[:enabled].downcase.chomp == 'true' ? true : false, :password => user[:password], - :tenant => user[:project], + :project => user[:project], :email => user[:email], :id => user[:id] ) end end - def instances - instances = request('user', 'list', nil, resource[:auth], '--long') - instances.collect do |user| - { - :name => user[:name], - :enabled => user[:enabled].downcase.chomp == 'true' ? true : false, - :password => user[:password], - :project => user[:project], - :email => user[:email], - :id => user[:id] - } + def self.prefetch(resources) + users = instances + resources.keys.each do |name| + if provider = users.find{ |user| user.name == name } + resources[name].provider = provider + end end end - def instance(name) - @instance ||= instances.select { |instance| instance[:name] == name }.first || {} - end - - def set_project(newproject) + def self.set_project(newproject, name) # some backends do not store the project/tenant in the user object, so we have to # to modify the project/tenant instead # First, see if the project actually needs to change - roles = request('user role', 'list', resource[:name], resource[:auth], ['--project', newproject]) + roles = request('user role', 'list', [name, '--project', newproject]) unless roles.empty? return # if already set, just skip end @@ -228,26 +189,11 @@ def set_project(newproject) # ok for a user to have the _member_ role and another role. default_role = "_member_" begin - request('role', 'show', default_role, resource[:auth]) + request('role', 'show', [default_role]) rescue debug("Keystone role #{default_role} does not exist - creating") - request('role', 'create', default_role, resource[:auth]) + request('role', 'create', [default_role]) end - request('role', 'add', default_role, resource[:auth], - '--project', newproject, '--user', resource[:name]) + request('role', 'add', [default_role, '--project', newproject, '--user', name]) end - - def flush - options = [] - if @property_flush - (options << '--enable') if @property_flush[:enabled] == :true - (options << '--disable') if @property_flush[:enabled] == :false - # There is a --description flag for the set command, but it does not work if the value is empty - (options << '--password' << resource[:password]) if @property_flush[:password] - (options << '--email' << resource[:email]) if @property_flush[:email] - # project handled in tenant= separately - request('user', 'set', resource[:name], resource[:auth], options) unless options.empty? - end - end - end diff --git a/keystone/lib/puppet/provider/keystone_user_role/openstack.rb b/keystone/lib/puppet/provider/keystone_user_role/openstack.rb index 5b9a1b587..da2b87044 100644 --- a/keystone/lib/puppet/provider/keystone_user_role/openstack.rb +++ b/keystone/lib/puppet/provider/keystone_user_role/openstack.rb @@ -7,26 +7,41 @@ desc "Provider to manage keystone role assignments to users." + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + + def initialize(value={}) + super(value) + @property_flush = {} + end + def create properties = [] properties << '--project' << get_project properties << '--user' << get_user if resource[:roles] resource[:roles].each do |role| - request('role', 'add', role, resource[:auth], properties) + self.class.request('role', 'add', [role] + properties) + end + end + end + + def destroy + properties = [] + properties << '--project' << get_project + properties << '--user' << get_user + if @property_hash[:roles] + @property_hash[:roles].each do |role| + self.class.request('role', 'remove', [role] + properties) end end + @property_hash[:ensure] = :absent end def exists? - # If we just ran self.instances, no need to make the request again - # instance() will find it cached in @user_role_hash - if self.class.user_role_hash - return ! instance(resource[:name]).empty? - # If we don't have the hash ready, we don't need to rebuild the - # whole thing just to check on one particular user/role + if @user_role_hash + return ! @property_hash[:name].empty? else - roles = request('user role', 'list', nil, resource[:auth], ['--project', get_project, get_user]) + roles = self.class.request('user role', 'list', [get_user, '--project', get_project]) # Since requesting every combination of users, roles, and # projects is so expensive, construct the property hash here # instead of in self.instances so it can be used in the role @@ -44,19 +59,6 @@ def exists? end end - def destroy - properties = [] - properties << '--project' << get_project - properties << '--user' << get_user - if @property_hash[:roles] - @property_hash[:roles].each do |role| - request('role', 'remove', role, resource[:auth], properties) - end - end - @property_hash[:ensure] = :absent - end - - def roles @property_hash[:roles] end @@ -69,14 +71,13 @@ def roles=(value) user = get_user project = get_project add.each do |role_name| - request('role', 'add', role_name, resource[:auth], ['--project', project, '--user', user]) + self.class.request('role', 'add', [role_name, '--project', project, '--user', user]) end remove.each do |role_name| - request('role', 'remove', role_name, resource[:auth], ['--project', project, '--user', user]) + self.class.request('role', 'remove', [role_name, '--project', project, '--user', user]) end end - def self.instances instances = build_user_role_hash instances.collect do |title, roles| @@ -88,10 +89,6 @@ def self.instances end end - def instance(name) - self.class.user_role_hash.select { |role_name, roles| role_name == name } || {} - end - private def get_user @@ -102,50 +99,26 @@ def get_project resource[:name].rpartition('@').last end - # We split get_projects into class and instance methods - # so that the appropriate request method gets called - def get_projects - request('project', 'list', nil, resource[:auth]).collect do |project| - project[:name] - end - end - def self.get_projects - request('project', 'list', nil, nil).collect do |project| - project[:name] - end - end - - def get_users(project) - request('user', 'list', nil, resource[:auth], ['--project', project]).collect do |user| - user[:name] - end + request('project', 'list').collect { |project| project[:name] } end def self.get_users(project) - request('user', 'list', nil, nil, ['--project', project]).collect do |user| - user[:name] - end + request('user', 'list', ['--project', project]).collect { |user| user[:name] } end - # Class methods for caching user_role_hash so both class and instance - # methods can access the value def self.set_user_role_hash(user_role_hash) @user_role_hash = user_role_hash end - def self.user_role_hash - @user_role_hash - end - def self.build_user_role_hash - hash = user_role_hash || {} + hash = @user_role_hash || {} return hash unless hash.empty? projects = get_projects projects.each do |project| users = get_users(project) users.each do |user| - user_roles = request('user role', 'list', nil, nil, ['--project', project, user]) + user_roles = request('user role', 'list', [user, '--project', project]) hash["#{user}@#{project}"] = [] user_roles.each do |role| hash["#{user}@#{project}"] << role[:name] @@ -155,5 +128,4 @@ def self.build_user_role_hash set_user_role_hash(hash) hash end - end diff --git a/keystone/lib/puppet/type/keystone_endpoint.rb b/keystone/lib/puppet/type/keystone_endpoint.rb index 02ef2ed07..43c5eb2ea 100644 --- a/keystone/lib/puppet/type/keystone_endpoint.rb +++ b/keystone/lib/puppet/type/keystone_endpoint.rb @@ -1,7 +1,7 @@ # LP#1408531 File.expand_path('../..', File.dirname(__FILE__)).tap { |dir| $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) } File.expand_path('../../../../openstacklib/lib', File.dirname(__FILE__)).tap { |dir| $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) } -require 'puppet/util/openstack' + Puppet::Type.newtype(:keystone_endpoint) do desc 'Type for managing keystone endpoints.' @@ -39,10 +39,4 @@ (region, service_name) = self[:name].split('/') [service_name] end - - auth_param_doc=< true) do - newvalues(/^\S+@\S+$/) end newproperty(:roles, :array_matching => :all) do @@ -43,10 +42,4 @@ def insync?(is) autorequire(:service) do ['keystone'] end - - auth_param_doc=< 0. +# Defaults to undef +# # == Dependencies # None # @@ -448,6 +464,9 @@ $admin_workers = max($::processorcount, 2), $public_workers = max($::processorcount, 2), $sync_db = true, + $enable_fernet_setup = false, + $fernet_key_repository = '/etc/keystone/fernet-keys', + $fernet_max_active_keys = undef, # DEPRECATED PARAMETERS $mysql_module = undef, $compute_port = undef, @@ -484,6 +503,8 @@ File['/etc/keystone/keystone.conf'] -> Keystone_config<||> ~> Service[$service_name] Keystone_config<||> ~> Exec<| title == 'keystone-manage db_sync'|> Keystone_config<||> ~> Exec<| title == 'keystone-manage pki_setup'|> + Keystone_config<||> ~> Exec<| title == 'keystone-manage fernet_setup'|> + include ::keystone::params package { 'keystone': @@ -872,4 +893,38 @@ } } + # Fernet tokens support + if $enable_fernet_setup { + validate_string($fernet_key_repository) + + exec { 'keystone-manage fernet_setup': + path => '/usr/bin', + user => 'keystone', + refreshonly => true, + creates => "${fernet_key_repository}/0", + notify => Service[$service_name], + subscribe => [Package['keystone'], Keystone_config['fernet_tokens/key_repository']], + } + } + + if $fernet_key_repository { + keystone_config { + 'fernet_tokens/key_repository': value => $fernet_key_repository; + } + } else { + keystone_config { + 'fernet_tokens/key_repository': ensure => absent; + } + } + + if $fernet_max_active_keys { + keystone_config { + 'fernet_tokens/max_active_keys': value => $fernet_max_active_keys; + } + } else { + keystone_config { + 'fernet_tokens/max_active_keys': ensure => absent; + } + } + } diff --git a/keystone/spec/acceptance/basic_keystone_spec.rb b/keystone/spec/acceptance/basic_keystone_spec.rb index 203bf5607..93a81cc26 100644 --- a/keystone/spec/acceptance/basic_keystone_spec.rb +++ b/keystone/spec/acceptance/basic_keystone_spec.rb @@ -63,6 +63,7 @@ class { '::keystone::endpoint': service_type => 'beaker', service_description => 'beaker service', service_name => 'beaker', + password => 'secret', public_url => 'http://127.0.0.1:1234', admin_url => 'http://127.0.0.1:1234', internal_url => 'http://127.0.0.1:1234', diff --git a/keystone/spec/acceptance/nodesets/nodepool-centos7.yml b/keystone/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/keystone/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/keystone/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/keystone/spec/acceptance/nodesets/nodepool-trusty.yml b/keystone/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/keystone/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/keystone/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/keystone/spec/classes/keystone_spec.rb b/keystone/spec/classes/keystone_spec.rb index ba54c40cc..89c4fc55e 100644 --- a/keystone/spec/classes/keystone_spec.rb +++ b/keystone/spec/classes/keystone_spec.rb @@ -778,6 +778,35 @@ end end + describe 'when using fernet tokens' do + describe 'when enabling fernet_setup' do + let :params do + default_params.merge({ + 'enable_fernet_setup' => true, + 'fernet_max_active_keys' => 5, + }) + end + + it { is_expected.to contain_exec('keystone-manage fernet_setup').with( + :creates => '/etc/keystone/fernet-keys/0' + ) } + it { is_expected.to contain_keystone_config('fernet_tokens/max_active_keys').with_value(5)} + end + + describe 'when overriding the fernet key directory' do + let :params do + default_params.merge({ + 'enable_fernet_setup' => true, + 'fernet_key_repository' => '/var/lib/fernet-keys', + }) + end + it { is_expected.to contain_exec('keystone-manage fernet_setup').with( + :creates => '/var/lib/fernet-keys/0' + ) } + + end + end + describe 'when configuring paste_deploy' do describe 'with default paste config on Debian' do let :params do diff --git a/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb b/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb index d88f246ea..9ca5b436f 100644 --- a/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb +++ b/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb @@ -6,7 +6,14 @@ describe provider_class do - describe 'when updating an endpoint' do + shared_examples 'authenticated with environment variables' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v2.0' + end + + describe 'when managing an endpoint' do let(:endpoint_attrs) do { @@ -15,12 +22,6 @@ :public_url => 'http://127.0.0.1:5000/v2.0', :internal_url => 'http://127.0.0.1:5001/v2.0', :admin_url => 'http://127.0.0.1:5002/v2.0', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } } end @@ -32,16 +33,17 @@ provider_class.new(resource) end - describe '#create' do - it 'creates an endpoint' do - provider.class.stubs(:openstack) - .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL" + it_behaves_like 'authenticated with environment variables' do + describe '#create' do + it 'creates an endpoint' do + provider.class.stubs(:openstack) + .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL" "1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0" ') - provider.class.stubs(:openstack) - .with('endpoint', 'create', '--format', 'shell', [['bar', '--region', 'foo', '--publicurl', 'http://127.0.0.1:5000/v2.0', '--internalurl', 'http://127.0.0.1:5001/v2.0', '--adminurl', 'http://127.0.0.1:5002/v2.0', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('adminurl="http://127.0.0.1:5002/v2.0" + provider.class.stubs(:openstack) + .with('endpoint', 'create', '--format', 'shell', ['bar', '--region', 'foo', '--publicurl', 'http://127.0.0.1:5000/v2.0', '--internalurl', 'http://127.0.0.1:5001/v2.0', '--adminurl', 'http://127.0.0.1:5002/v2.0']) + .returns('adminurl="http://127.0.0.1:5002/v2.0" id="3a5c4378981e4112a0d44902a43e16ef" internalurl="http://127.0.0.1:5001/v2.0" publicurl="http://127.0.0.1:5000/v2.0" @@ -50,64 +52,49 @@ service_name="bar" service_type="test" ') - provider.create - expect(provider.exists?).to be_truthy - end - end - - describe '#destroy' do - it 'destroys an endpoint' do - provider.class.stubs(:openstack) - .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL" -"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0" -') - provider.class.stubs(:openstack) - .with('endpoint', 'delete', [['1cb05cfed7c24279be884ba4f6520262', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - expect(provider.destroy).to be_nil # We don't really care that it's nil, only that it runs successfully + provider.create + expect(provider.exists?).to be_truthy + end end - end - - describe '#exists' do - context 'when endpoint exists' do - - subject(:response) do + describe '#destroy' do + it 'destroys an endpoint' do provider.class.stubs(:openstack) - .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) + .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long') .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL" -"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0" +"1cb05cfed7c24279be884ba4f6520262","foo","bar","test","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0" ') - response = provider.exists? + provider.class.stubs(:openstack) + .with('endpoint', 'delete', []) + provider.destroy + expect(provider.exists?).to be_falsey end - - it { is_expected.to be_truthy } end - context 'when tenant does not exist' do + describe '#exists' do + context 'when tenant does not exist' do + subject(:response) do + provider.class.stubs(:openstack) + .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"') + response = provider.exists? + end - subject(:response) do - provider.class.stubs(:openstack) - .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"') - response = provider.exists? + it { is_expected.to be_falsey } end - - it { is_expected.to be_falsey } end - end - describe '#instances' do - it 'finds every tenant' do - provider.class.stubs(:openstack) - .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL" -"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0" + describe '#instances' do + it 'finds every tenant' do + provider.class.stubs(:openstack) + .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL" +"3a5c4378981e4112a0d44902a43e16ef","foo","bar","test","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0" ') - instances = provider.instances - expect(instances.count).to eq(1) + instances = Puppet::Type::Keystone_endpoint::ProviderOpenstack.instances + expect(instances.count).to eq(1) + end end end - end end diff --git a/keystone/spec/unit/provider/keystone_role/openstack_spec.rb b/keystone/spec/unit/provider/keystone_role/openstack_spec.rb index 13f877b97..09e229b82 100644 --- a/keystone/spec/unit/provider/keystone_role/openstack_spec.rb +++ b/keystone/spec/unit/provider/keystone_role/openstack_spec.rb @@ -6,96 +6,81 @@ describe provider_class do - describe 'when creating a role' do + shared_examples 'authenticated with environment variables' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:5000' + end - let(:role_attrs) do - { - :name => 'foo', - :ensure => 'present', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', + describe 'when creating a role' do + it_behaves_like 'authenticated with environment variables' do + let(:role_attrs) do + { + :name => 'foo', + :ensure => 'present', } - } - end - - let(:resource) do - Puppet::Type::Keystone_role.new(role_attrs) - end - - let(:provider) do - provider_class.new(resource) - end - - describe '#create' do - it 'creates a role' do - provider.class.stubs(:openstack) - .with('role', 'list', '--quiet', '--format', 'csv', [['--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name" -"1cb05cfed7c24279be884ba4f6520262","foo" -') - provider.class.stubs(:openstack) - .with('role', 'create', '--format', 'shell', [['foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('name="foo"') - provider.create - expect(provider.exists?).to be_truthy end - end - describe '#destroy' do - it 'destroys a role' do - provider.class.stubs(:openstack) - .with('role', 'list', '--quiet', '--format', 'csv', [['--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name"') - provider.class.stubs(:openstack) - .with('role', 'delete', [['foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.destroy - expect(provider.exists?).to be_falsey + let(:resource) do + Puppet::Type::Keystone_role.new(role_attrs) end - end - - describe '#exists' do - context 'when role exists' do + let(:provider) do + provider_class.new(resource) + end - subject(:response) do + describe '#create' do + it 'creates a role' do provider.class.stubs(:openstack) - .with('role', 'list', '--quiet', '--format', 'csv', [['--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) + .with('role', 'list', '--quiet', '--format', 'csv', []) .returns('"ID","Name" "1cb05cfed7c24279be884ba4f6520262","foo" ') - response = provider.exists? + provider.class.stubs(:openstack) + .with('role', 'create', '--format', 'shell', 'foo') + .returns('name="foo"') + provider.create + expect(provider.exists?).to be_truthy end - - it { is_expected.to be_truthy } end - context 'when role does not exist' do - - subject(:response) do + describe '#destroy' do + it 'destroys a role' do provider.class.stubs(:openstack) - .with('role', 'list', '--quiet', '--format', 'csv', [['--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name"') - response = provider.exists? + .with('role', 'list', '--quiet', '--format', 'csv', []) + .returns('"ID","Name"') + provider.class.stubs(:openstack) + .with('role', 'delete', []) + provider.destroy + expect(provider.exists?).to be_falsey end - it { is_expected.to be_falsey } end - end - describe '#instances' do - it 'finds every role' do - provider.class.stubs(:openstack) - .with('role', 'list', '--quiet', '--format', 'csv', [['--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name" + describe '#exists' do + context 'when role does not exist' do + subject(:response) do + provider.class.stubs(:openstack) + .with('role', 'list', '--quiet', '--format', 'csv', []) + .returns('"ID","Name"') + response = provider.exists? + end + it { is_expected.to be_falsey } + end + end + + describe '#instances' do + it 'finds every role' do + provider.class.stubs(:openstack) + .with('role', 'list', '--quiet', '--format', 'csv', []) + .returns('"ID","Name" "1cb05cfed7c24279be884ba4f6520262","foo" ') - instances = provider.instances - expect(instances.count).to eq(1) + instances = Puppet::Type::Keystone_role::ProviderOpenstack.instances + expect(instances.count).to eq(1) + end end end - end end diff --git a/keystone/spec/unit/provider/keystone_service/openstack_spec.rb b/keystone/spec/unit/provider/keystone_service/openstack_spec.rb index 622d000d8..b627ec1fa 100644 --- a/keystone/spec/unit/provider/keystone_service/openstack_spec.rb +++ b/keystone/spec/unit/provider/keystone_service/openstack_spec.rb @@ -6,7 +6,14 @@ describe provider_class do - describe 'when creating a service' do + shared_examples 'authenticated with environment variables' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v2.0' + end + + describe 'when managing a service' do let(:service_attrs) do { @@ -14,12 +21,6 @@ :description => 'foo', :ensure => 'present', :type => 'foo', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } } end @@ -31,78 +32,62 @@ provider_class.new(resource) end - describe '#create' do - it 'creates a service' do - provider.class.stubs(:openstack) - .with('service', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Type","Description" + it_behaves_like 'authenticated with environment variables' do + describe '#create' do + it 'creates a service' do + provider.class.stubs(:openstack) + .with('service', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Type","Description" "1cb05cfed7c24279be884ba4f6520262","foo","foo","foo" ') - provider.class.stubs(:openstack) - .with('service', 'create', '--format', 'shell', [['foo', '--description', 'foo', '--type', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('description="foo" + provider.class.stubs(:openstack) + .with('service', 'create', '--format', 'shell', ['--name', 'foo', '--description', 'foo', 'foo']) + .returns('description="foo" enabled="True" id="8f0dd4c0abc44240998fbb3f5089ecbf" name="foo" type="foo" ') - provider.create - expect(provider.exists?).to be_truthy - end - end - - describe '#destroy' do - it 'destroys a service' do - provider.class.stubs(:openstack) - .with('service', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Type","Description"') - provider.class.stubs(:openstack) - .with('service', 'delete', [['foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.destroy - expect(provider.exists?).to be_falsey + provider.create + expect(provider.exists?).to be_truthy + end end - end - - describe '#exists' do - context 'when service exists' do - - subject(:response) do + describe '#destroy' do + it 'destroys a service' do provider.class.stubs(:openstack) - .with('service', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) + .with('service', 'list', '--quiet', '--format', 'csv', '--long') .returns('"ID","Name","Type","Description" "1cb05cfed7c24279be884ba4f6520262","foo","foo","foo" ') - response = provider.exists? - end - - it { is_expected.to be_truthy } - end - - context 'when service does not exist' do - - subject(:response) do provider.class.stubs(:openstack) - .with('service', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Type","Description"') - response = provider.exists? + .with('service', 'delete', []) + provider.destroy + expect(provider.exists?).to be_falsey end - it { is_expected.to be_falsey } + context 'when service does not exist' do + subject(:response) do + provider.class.stubs(:openstack) + .with('service', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Type","Description"') + response = provider.exists? + end + it { is_expected.to be_falsey } + end end - end - describe '#instances' do - it 'finds every service' do - provider.class.stubs(:openstack) - .with('service', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Type","Description" -"1cb05cfed7c24279be884ba4f6520262","foo","foo","foo" + describe '#instances' do + it 'finds every service' do + provider.class.stubs(:openstack) + .with('service', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Type","Description" +"8f0dd4c0abc44240998fbb3f5089ecbf","foo","foo","foo" ') - instances = provider.instances - expect(instances.count).to eq(1) + instances = Puppet::Type::Keystone_service::ProviderOpenstack.instances + expect(instances.count).to eq(1) + end end end - end end diff --git a/keystone/spec/unit/provider/keystone_spec.rb b/keystone/spec/unit/provider/keystone_spec.rb index 6a40dacf4..4981f1e5c 100644 --- a/keystone/spec/unit/provider/keystone_spec.rb +++ b/keystone/spec/unit/provider/keystone_spec.rb @@ -3,10 +3,11 @@ require 'puppet/provider/keystone' require 'tempfile' - klass = Puppet::Provider::Keystone class Puppet::Provider::Keystone + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + def self.reset @admin_endpoint = nil @tenant_hash = nil @@ -21,20 +22,15 @@ def self.reset klass.reset end - describe 'when retrieving the security token' do - it 'should return nothing if there is no keystone config file' do - ini_file = Puppet::Util::IniConfig::File.new - t = Tempfile.new('foo') - path = t.path - t.unlink - ini_file.read(path) + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(false) expect(klass.get_admin_token).to be_nil end it 'should return nothing if the keystone config file does not have a DEFAULT section' do mock = {} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_token).to be_nil @@ -42,6 +38,7 @@ def self.reset it 'should fail if the keystone config file does not contain an admin token' do mock = {'DEFAULT' => {'not_a_token' => 'foo'}} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_token).to be_nil @@ -49,6 +46,7 @@ def self.reset it 'should parse the admin token if it is in the config file' do mock = {'DEFAULT' => {'admin_token' => 'foo'}} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_token).to eq('foo') @@ -56,6 +54,7 @@ def self.reset it 'should use the specified bind_host in the admin endpoint' do mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/') @@ -63,6 +62,7 @@ def self.reset it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do mock = {'DEFAULT' => { 'admin_bind_host' => '0.0.0.0', 'admin_port' => '35357' }} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/') @@ -70,6 +70,7 @@ def self.reset it 'should use [::1] in the admin endpoint if bind_host is ::0' do mock = {'DEFAULT' => { 'admin_bind_host' => '::0', 'admin_port' => '35357' }} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('http://[::1]:35357/v2.0/') @@ -77,6 +78,7 @@ def self.reset it 'should use localhost in the admin endpoint if bind_host is unspecified' do mock = {'DEFAULT' => { 'admin_port' => '35357' }} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/') @@ -84,6 +86,7 @@ def self.reset it 'should use https if ssl is enabled' do mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'True'}} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('https://192.168.56.210:35357/v2.0/') @@ -91,6 +94,7 @@ def self.reset it 'should use http if ssl is disabled' do mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'False'}} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/') @@ -98,6 +102,7 @@ def self.reset it 'should use the defined admin_endpoint if available' do mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/') @@ -105,6 +110,7 @@ def self.reset it 'should handle an admin_endpoint with a trailing slash' do mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}} + File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true) Puppet::Util::IniConfig::File.expects(:new).returns(mock) mock.expects(:read).with('/etc/keystone/keystone.conf') expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/') diff --git a/keystone/spec/unit/provider/keystone_tenant/openstack_spec.rb b/keystone/spec/unit/provider/keystone_tenant/openstack_spec.rb index fe7d73b26..1dec49e06 100644 --- a/keystone/spec/unit/provider/keystone_tenant/openstack_spec.rb +++ b/keystone/spec/unit/provider/keystone_tenant/openstack_spec.rb @@ -6,7 +6,14 @@ describe provider_class do - describe 'when updating a tenant' do + shared_examples 'authenticated with environment variables' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v2.0' + end + + describe 'when managing a tenant' do let(:tenant_attrs) do { @@ -14,12 +21,6 @@ :description => 'foo', :ensure => 'present', :enabled => 'True', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } } end @@ -31,76 +32,59 @@ provider_class.new(resource) end - describe '#create' do - it 'creates a tenant' do - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled" + it_behaves_like 'authenticated with environment variables' do + describe '#create' do + it 'creates a tenant' do + provider.class.stubs(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Description","Enabled" "1cb05cfed7c24279be884ba4f6520262","foo","foo",True ') - provider.class.stubs(:openstack) - .with('project', 'create', '--format', 'shell', [['foo', '--enable', '--description', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('description="foo" + provider.class.stubs(:openstack) + .with('project', 'create', '--format', 'shell', ['foo', '--enable', '--description', 'foo']) + .returns('description="foo" enabled="True" name="foo" ') - provider.create - expect(provider.exists?).to be_truthy - end - end - - describe '#destroy' do - it 'destroys a tenant' do - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled"') - provider.class.stubs(:openstack) - .with('project', 'delete', [['foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.destroy - expect(provider.exists?).to be_falsey + provider.create + expect(provider.exists?).to be_truthy + end end - end - - describe '#exists' do - context 'when tenant exists' do - - subject(:response) do + describe '#destroy' do + it 'destroys a tenant' do provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","foo","foo",True -') - response = provider.exists? + .with('project', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Description","Enabled"') + provider.class.stubs(:openstack) + .with('project', 'delete', []) + provider.destroy + expect(provider.exists?).to be_falsey end - - it { is_expected.to be_truthy } end context 'when tenant does not exist' do - subject(:response) do provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled"') + .with('project', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Description","Enabled"') response = provider.exists? end it { is_expected.to be_falsey } end - end - describe '#instances' do - it 'finds every tenant' do - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled" + describe '#instances' do + it 'finds every tenant' do + provider.class.stubs(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Description","Enabled" "1cb05cfed7c24279be884ba4f6520262","foo","foo",True ') - instances = provider.instances - expect(instances.count).to eq(1) + instances = Puppet::Type::Keystone_tenant::ProviderOpenstack.instances + expect(instances.count).to eq(1) + end end end - end end diff --git a/keystone/spec/unit/provider/keystone_user/openstack_spec.rb b/keystone/spec/unit/provider/keystone_user/openstack_spec.rb index 51d1dfce2..03fc8213a 100644 --- a/keystone/spec/unit/provider/keystone_user/openstack_spec.rb +++ b/keystone/spec/unit/provider/keystone_user/openstack_spec.rb @@ -6,20 +6,21 @@ describe provider_class do + shared_examples 'authenticated with environment variables' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:5000' + end + let(:user_attrs) do { :name => 'foo', - :ensure => 'present', + :ensure => :present, :enabled => 'True', :password => 'foo', :tenant => 'foo', :email => 'foo@example.com', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } } end @@ -31,175 +32,180 @@ provider_class.new(resource) end - describe 'when updating a user' do - - describe '#create' do - it 'creates a user' do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled" + describe 'when managing a user' do + it_behaves_like 'authenticated with environment variables' do + describe '#create' do + it 'creates a user' do + provider.class.stubs(:openstack) + .with('user', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Project","Email","Enabled" "1cb05cfed7c24279be884ba4f6520262","foo","foo","foo@example.com",True ') - provider.class.stubs(:openstack) - .with('user', 'create', '--format', 'shell', [['foo', '--enable', '--password', 'foo', '--project', 'foo', '--email', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('email="foo@example.com" + provider.class.stubs(:openstack) + .with('user', 'create', '--format', 'shell', ['foo', '--enable', '--password', 'foo', '--project', 'foo', '--email', 'foo@example.com']) + .returns('email="foo@example.com" enabled="True" id="12b23f07d4a3448d8189521ab09610b0" name="foo" project_id="5e2001b2248540f191ff22627dc0c2d7" username="foo" ') - provider.create - expect(provider.exists?).to be_truthy - end - end - - describe '#destroy' do - it 'destroys a user' do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled"') - provider.class.stubs(:openstack) - .with('user', 'delete', [['foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.destroy - expect(provider.exists?).to be_falsey + provider.create + expect(provider.exists?).to be_truthy + end end - end - - describe '#exists' do - context 'when user exists' do - - subject(:response) do + describe '#destroy' do + it 'destroys a user' do provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled" -"1cb05cfed7c24279be884ba4f6520262","foo","foo","foo@example.com",True -') - response = provider.exists? + .with('user', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Project","Email","Enabled"') + provider.class.stubs(:openstack) + .with('user', 'delete', []) + provider.destroy + expect(provider.exists?).to be_falsey end - it { is_expected.to be_truthy } end - context 'when user does not exist' do + describe '#exists' do + context 'when user does not exist' do + subject(:response) do + provider.class.stubs(:openstack) + .with('user', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Project","Email","Enabled"') + response = provider.exists? + end - subject(:response) do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled"') - response = provider.exists? + it { is_expected.to be_falsey } end - - it { is_expected.to be_falsey } end - end - describe '#instances' do - it 'finds every user' do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled" + describe '#instances' do + it 'finds every user' do + provider.class.stubs(:openstack) + .with('user', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Project","Email","Enabled" "1cb05cfed7c24279be884ba4f6520262","foo","foo","foo@example.com",True ') - instances = provider.instances - expect(instances.count).to eq(1) + instances = Puppet::Type::Keystone_user::ProviderOpenstack.instances + expect(instances.count).to eq(1) + end end - end - describe '#tenant' do - it 'gets the tenant with default backend' do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled" + describe '#tenant' do + it 'gets the tenant with default backend' do + provider.class.stubs(:openstack) + .with('user', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Project","Email","Enabled" "1cb05cfed7c24279be884ba4f6520262","foo","foo","foo@example.com",True ') - tenant = provider.tenant - expect(tenant).to eq('foo') - end - it 'gets the tenant with LDAP backend' do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","Email","Enabled" -"1cb05cfed7c24279be884ba4f6520262","foo","","foo@example.com",True + provider.class.stubs(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'foo']) + .returns('"ID","Name","Project","User" +"9fe2ff9ee4384b1894a90878d3e92bab","_member_","foo","foo" ') - provider.class.expects(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['foo', '--project', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","User" -"1cb05cfed7c24279be884ba4f6520262","foo","foo","foo" + tenant = provider.tenant + expect(tenant).to eq('foo') + end + + it 'gets the tenant with LDAP backend' do + provider.class.stubs(:openstack) + .with('user', 'list', '--quiet', '--format', 'csv', '--long') + .returns('"ID","Name","Project","Email","Enabled" +"1cb05cfed7c24279be884ba4f6520262","foo","","foo@example.com",True ') - tenant = provider.tenant - expect(tenant).to eq('foo') - end - end - describe '#tenant=' do - context 'when using default backend' do - it 'sets the tenant' do provider.class.expects(:openstack) - .with('user', 'set', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.class.expects(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","User" + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'foo']) + .returns('"ID","Name","Project","User" "1cb05cfed7c24279be884ba4f6520262","foo","foo","foo" ') - provider.tenant=('bar') + tenant = provider.tenant + expect(tenant).to eq('foo') end end - context 'when using LDAP read-write backend' do - it 'sets the tenant when _member_ role exists' do - provider.class.expects(:openstack) - .with('user', 'set', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.class.expects(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('') - provider.class.expects(:openstack) - .with('role', 'show', '--format', 'shell', [['_member_', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('name="_member_"') - provider.class.expects(:openstack) - .with('role', 'add', [['_member_', '--project', 'bar', '--user', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.tenant=('bar') - end - it 'sets the tenant when _member_ role does not exist' do - provider.class.expects(:openstack) - .with('user', 'set', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.class.expects(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('') - provider.class.expects(:openstack) - .with('role', 'show', '--format', 'shell', [['_member_', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .raises(Puppet::ExecutionFailure, 'no such role _member_') - provider.class.expects(:openstack) - .with('role', 'create', '--format', 'shell', [['_member_', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('name="_member_"') - provider.class.expects(:openstack) - .with('role', 'add', [['_member_', '--project', 'bar', '--user', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.tenant=('bar') + + describe '#tenant=' do + context 'when using default backend' do + it 'sets the tenant' do + provider.class.expects(:openstack) + .with('user', 'set', ['foo', '--project', 'bar']) + provider.class.expects(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'bar']) + .returns('"ID","Name","Project","User" +"9fe2ff9ee4384b1894a90878d3e92bab","_member_","bar","foo" +') + provider.tenant=('bar') + end end - end - context 'when using LDAP read-only backend' do - it 'sets the tenant when _member_ role exists' do - provider.class.expects(:openstack) - .with('user', 'set', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .raises(Puppet::ExecutionFailure, 'You are not authorized to perform the requested action: LDAP user update') - provider.class.expects(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('') - provider.class.expects(:openstack) - .with('role', 'show', '--format', 'shell', [['_member_', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('name="_member_"') - provider.class.expects(:openstack) - .with('role', 'add', [['_member_', '--project', 'bar', '--user', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.tenant=('bar') + + context 'when using LDAP read-write backend' do + it 'sets the tenant when _member_ role exists' do + provider.class.expects(:openstack) + .with('user', 'set', ['foo', '--project', 'bar']) + provider.class.expects(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'bar']) + .returns('') + provider.class.expects(:openstack) + .with('role', 'show', '--format', 'shell', ['_member_']) + .returns('id="9fe2ff9ee4384b1894a90878d3e92bab" +name="_member_" +') + provider.class.expects(:openstack) + .with('role', 'add', ['_member_', '--project', 'bar', '--user', 'foo']) + provider.tenant=('bar') + end + it 'sets the tenant when _member_ role does not exist' do + provider.class.expects(:openstack) + .with('user', 'set', ['foo', '--project', 'bar']) + provider.class.expects(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'bar']) + .returns('') + provider.class.expects(:openstack) + .with('role', 'show', '--format', 'shell', ['_member_']) + .raises(Puppet::ExecutionFailure, 'no such role _member_') + provider.class.expects(:openstack) + .with('role', 'create', '--format', 'shell', ['_member_']) + .returns('name="_member_"') + provider.class.expects(:openstack) + .with('role', 'add', ['_member_', '--project', 'bar', '--user', 'foo']) + .returns('id="8wr2ff9ee4384b1894a90878d3e92bab" +name="_member_" +') + provider.tenant=('bar') + end end - it 'sets the tenant and gets an unexpected exception message' do - provider.class.expects(:openstack) - .with('user', 'set', [['foo', '--project', 'bar', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .raises(Puppet::ExecutionFailure, 'unknown error message') - expect{ provider.tenant=('bar') }.to raise_error(Puppet::ExecutionFailure, /unknown error message/) + +# This doesn't make sense, need to clarify what's happening with LDAP mock +=begin + context 'when using LDAP read-only backend' do + it 'sets the tenant when _member_ role exists' do + provider.class.expects(:openstack) + .with('user', 'set', [['foo', '--project', 'bar']]) + .raises(Puppet::ExecutionFailure, 'You are not authorized to perform the requested action: LDAP user update') + provider.class.expects(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', [['foo', '--project', 'bar']]) + .returns('') + provider.class.expects(:openstack) + .with('role', 'show', '--format', 'shell', [['_member_']]) + .returns('id="9fe2ff9ee4384b1894a90878d3e92bab" +name="_member_" +') + provider.class.expects(:openstack) + .with('role', 'add', [['_member_', '--project', 'bar', '--user', 'foo']]) + provider.tenant=('bar') + end + + it 'sets the tenant and gets an unexpected exception message' do + provider.class.expects(:openstack) + .with('user', 'set', [['foo', '--project', 'bar']]) + .raises(Puppet::ExecutionFailure, 'unknown error message') + expect{ provider.tenant=('bar') }.to raise_error(Puppet::ExecutionFailure, /unknown error message/) + end end +=end end end - end describe "#password" do @@ -211,44 +217,41 @@ :password => 'foo', :tenant => 'foo', :email => 'foo@example.com', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'https://127.0.0.1:5000/v2.0', - } } end - it 'checks the password with HTTPS' do - httpobj = mock('Net::HTTP') - httpobj.stubs(:use_ssl=).with(true) - httpobj.stubs(:verify_mode=) - Net::HTTP.stubs(:start).returns(httpobj) - reqobj = mock('Net::HTTP::Post') - reqobj.stubs(:body=) - reqobj.stubs(:content_type=) - Net::HTTP::Post.stubs(:start).returns(reqobj) - respobj = mock('Net::HTTPResponse') - respobj.stubs(:code).returns('200') - httpobj.stubs(:request).returns(respobj) - password = provider.password - expect(password).to eq('foo') + let(:resource) do + Puppet::Type::Keystone_user.new(user_attrs) end - it 'fails the password check with HTTPS' do - httpobj = mock('Net::HTTP') - httpobj.stubs(:use_ssl=).with(true) - httpobj.stubs(:verify_mode=) - Net::HTTP.stubs(:start).returns(httpobj) - reqobj = mock('Net::HTTP::Post') - reqobj.stubs(:body=) - reqobj.stubs(:content_type=) - Net::HTTP::Post.stubs(:start).returns(reqobj) - respobj = mock('Net::HTTPResponse') - respobj.stubs(:code).returns('401') - httpobj.stubs(:request).returns(respobj) - password = provider.password - expect(password).to eq(nil) + + let :provider do + provider_class.new(resource) + end + + shared_examples 'with auth-url environment variable' do + ENV['OS_AUTH_URL'] = 'http://localhost:5000' + end + + it_behaves_like 'with auth-url environment variable' do + it 'checks the password' do + Puppet::Provider::Openstack.stubs(:openstack) + .with('token', 'issue', ['--format', 'value']) + .returns('2015-05-14T04:06:05Z +e664a386befa4a30878dcef20e79f167 +8dce2ae9ecd34c199d2877bf319a3d06 +ac43ec53d5a74a0b9f51523ae41a29f0 +') + password = provider.password + expect(password).to eq('foo') + end + + it 'fails the password check' do + Puppet::Provider::Openstack.stubs(:openstack) + .with('token', 'issue', ['--format', 'value']) + .returns('') + password = provider.password + expect(password).to eq(nil) + end end describe 'when updating a user with unmanaged password' do @@ -262,23 +265,9 @@ :replace_password => 'False', :tenant => 'foo', :email => 'foo@example.com', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'tenant_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } } end - let(:resource) do - Puppet::Type::Keystone_user.new(user_attrs) - end - - let :provider do - provider_class.new(resource) - end - it 'should not try to check password' do expect(provider.password).to eq('foo') end diff --git a/keystone/spec/unit/provider/keystone_user_role/openstack_spec.rb b/keystone/spec/unit/provider/keystone_user_role/openstack_spec.rb index 1be2bd64f..2490adc52 100644 --- a/keystone/spec/unit/provider/keystone_user_role/openstack_spec.rb +++ b/keystone/spec/unit/provider/keystone_user_role/openstack_spec.rb @@ -6,89 +6,84 @@ describe provider_class do - describe 'when updating a user\'s role' do + shared_examples 'authenticated with environment variables' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:5000' + end - let(:user_role_attrs) do - { - :name => 'foo@example.com@foo', - :ensure => 'present', - :roles => ['foo', 'bar'], - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'foo', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', + describe 'when updating a user\'s role' do + it_behaves_like 'authenticated with environment variables' do + let(:user_role_attrs) do + { + :name => 'foo@foo', + :ensure => 'present', + :roles => ['foo', 'bar'], } - } - end - - let(:resource) do - Puppet::Type::Keystone_user_role.new(user_role_attrs) - end + end - let(:provider) do - provider_class.new(resource) - end + let(:resource) do + Puppet::Type::Keystone_user_role.new(user_role_attrs) + end - before(:each) do - provider.class.stubs(:openstack) - .with('user', 'list', '--quiet', '--format', 'csv', [['--project', 'foo', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name" -"1cb05cfed7c24279be884ba4f6520262","foo@example.com" -') - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name" -"1cb05cfed7c24279be884ba4f6520262","foo" -') - end + let(:provider) do + provider_class.new(resource) + end - describe '#create' do - it 'adds all the roles to the user' do + before(:each) do provider.class.stubs(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['--project', 'foo', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) + .with('user', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'foo']) .returns('"ID","Name","Project","User" -"1cb05cfed7c24279be884ba4f6520262","foo","foo","foo@example.com" -"1cb05cfed7c24279be884ba4f6520263","bar","foo","foo@example.com" +"1cb05cfed7c24279be884ba4f6520262","foo","foo","foo" ') - provider.class.stubs(:openstack) - .with('role', 'add', [['foo', '--project', 'foo', '--user', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.class.stubs(:openstack) - .with('role', 'add', [['bar', '--project', 'foo', '--user', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.create - expect(provider.exists?).to be_truthy end - end - describe '#destroy' do - it 'removes all the roles from a user' do - provider.class.stubs(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['--project', 'foo', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","User"') - provider.class.stubs(:openstack) - .with('role', 'remove', [['foo', '--project', 'foo', '--user', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.class.stubs(:openstack) - .with('role', 'remove', [['bar', '--project', 'foo', '--user', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - provider.destroy - expect(provider.exists?).to be_falsey + describe '#create' do + it 'adds all the roles to the user' do + provider.class.stubs(:openstack) + .with('role', 'add', ['foo', '--project', 'foo', '--user', 'foo']) + provider.class.stubs(:openstack) + .with('role', 'add', ['bar', '--project', 'foo', '--user', 'foo']) + provider.class.stubs(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'foo']) + .returns('"ID","Name","Project","User" +"1cb05ed7c24279be884ba4f6520262","foo","foo","foo" +"2cb05ed7c24279be884ba4f6520262","bar","foo","foo" +') + provider.create + expect(provider.exists?).to be_truthy + end end - end + describe '#destroy' do + it 'removes all the roles from a user' do + provider.class.stubs(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'foo']) + .returns('"ID","Name","Project","User"') + provider.class.stubs(:openstack) + .with('role', 'remove', ['foo', '--project', 'foo', '--user', 'foo']) + provider.class.stubs(:openstack) + .with('role', 'remove', ['bar', '--project', 'foo', '--user', 'foo']) + provider.destroy + expect(provider.exists?).to be_falsey + end - describe '#exists' do - subject(:response) do - provider.class.stubs(:openstack) - .with('user role', 'list', '--quiet', '--format', 'csv', [['--project', 'foo', 'foo@example.com', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Project","User" -"1cb05ed7c24279be884ba4f6520262","foo","foo","foo@example.com" -"1cb05ed7c24279be884ba4f6520262","bar","foo","foo@example.com" -') - response = provider.exists? end - it { is_expected.to be_truthy } + describe '#exists' do + subject(:response) do + provider.class.stubs(:openstack) + .with('user role', 'list', '--quiet', '--format', 'csv', ['foo', '--project', 'foo']) + .returns('"ID","Name","Project","User" +"1cb05ed7c24279be884ba4f6520262","foo","foo","foo" +') + response = provider.exists? + end - end + it { is_expected.to be_truthy } + end + end end end diff --git a/manila/.gitreview b/manila/.gitreview index bfcdf9a01..b0a267847 100644 --- a/manila/.gitreview +++ b/manila/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-manila.git +project=openstack/puppet-manila.git diff --git a/manila/Gemfile b/manila/Gemfile index 37e3eb3d4..d6d9f8473 100644 --- a/manila/Gemfile +++ b/manila/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'puppet-lint', '~> 1.1' gem 'metadata-json-lint' @@ -18,7 +17,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/manila/manifests/init.pp b/manila/manifests/init.pp index 6b9572597..c25715fbf 100644 --- a/manila/manifests/init.pp +++ b/manila/manifests/init.pp @@ -11,6 +11,10 @@ # Timeout when db connections should be reaped. # (Optional) Defaults to 3600. # +# [*state_path*] +# (optional) Directory for storing state. +# Defaults to '/var/lib/manila' +# # [*control_exchange*] # (Optional) The default exchange under which topics are scope. # Defaults to 'openstack'. @@ -23,6 +27,10 @@ # (Optional) Ensure state for package. # Defaults to 'present' # +# [*notification_driver*] +# (optional) Driver or drivers to handle sending notifications. +# Defaults to 'messaging' +# # [*rabbit_host*] # (Optional) IP or hostname of the rabbit server. # Defaults to '127.0.0.1' @@ -163,6 +171,7 @@ $sql_idle_timeout = '3600', $rpc_backend = 'manila.openstack.common.rpc.impl_kombu', $control_exchange = 'openstack', + $notification_driver = 'messaging', $rabbit_host = '127.0.0.1', $rabbit_port = 5672, $rabbit_hosts = false, @@ -202,6 +211,7 @@ $debug = false, $storage_availability_zone = 'nova', $rootwrap_config = '/etc/manila/rootwrap.conf', + $state_path = '/var/lib/manila', $lock_path = '/tmp/manila/manila_locks', ) { @@ -265,56 +275,56 @@ } manila_config { - 'DEFAULT/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_userid': value => $rabbit_userid; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_userid; + 'oslo_messaging_rabbit/rabbit_virtual_host': value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl': value => $rabbit_use_ssl; 'DEFAULT/control_exchange': value => $control_exchange; 'DEFAULT/amqp_durable_queues': value => $amqp_durable_queues; } if $rabbit_hosts { - manila_config { 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ',') } - manila_config { 'DEFAULT/rabbit_ha_queues': value => true } + manila_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } + manila_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { - manila_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - manila_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - manila_config { 'DEFAULT/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } - manila_config { 'DEFAULT/rabbit_ha_queues': value => false } + manila_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + manila_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + manila_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } + manila_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } if $rabbit_use_ssl { if $kombu_ssl_ca_certs { - manila_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } + manila_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } } else { - manila_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; } + manila_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; } } if $kombu_ssl_certfile or $kombu_ssl_keyfile { manila_config { - 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; + 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; } } else { manila_config { - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } if $kombu_ssl_version { - manila_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version; } + manila_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version; } } else { - manila_config { 'DEFAULT/kombu_ssl_version': ensure => absent; } + manila_config { 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } else { manila_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } @@ -367,6 +377,8 @@ 'DEFAULT/rpc_backend': value => $rpc_backend; 'DEFAULT/storage_availability_zone': value => $storage_availability_zone; 'DEFAULT/rootwrap_config': value => $rootwrap_config; + 'DEFAULT/notification_driver': value => $notification_driver; + 'DEFAULT/state_path': value => $state_path; 'DEFAULT/lock_path': value => $lock_path; } diff --git a/manila/spec/acceptance/nodesets/nodepool-centos7.yml b/manila/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/manila/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/manila/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/manila/spec/acceptance/nodesets/nodepool-trusty.yml b/manila/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/manila/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/manila/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/manila/spec/classes/manila_spec.rb b/manila/spec/classes/manila_spec.rb index 2b17c0f93..eaecd64d9 100644 --- a/manila/spec/classes/manila_spec.rb +++ b/manila/spec/classes/manila_spec.rb @@ -23,29 +23,32 @@ is_expected.to contain_manila_config('DEFAULT/rpc_backend').with( :value => 'manila.openstack.common.rpc.impl_kombu' ) + is_expected.to contain_manila_config('DEFAULT/notification_driver').with( + :value => 'messaging' + ) is_expected.to contain_manila_config('DEFAULT/control_exchange').with( :value => 'openstack' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_password').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_password').with( :value => 'guest', :secret => true ) - is_expected.to contain_manila_config('DEFAULT/rabbit_host').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_host').with( :value => '127.0.0.1' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_port').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_port').with( :value => '5672' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_hosts').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_hosts').with( :value => '127.0.0.1:5672' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_ha_queues').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_ha_queues').with( :value => false ) - is_expected.to contain_manila_config('DEFAULT/rabbit_virtual_host').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_virtual_host').with( :value => '/' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_userid').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_userid').with( :value => 'guest' ) is_expected.to contain_manila_config('DEFAULT/sql_connection').with( @@ -67,6 +70,9 @@ is_expected.to contain_manila_config('DEFAULT/rootwrap_config').with( :value => '/etc/manila/rootwrap.conf' ) + is_expected.to contain_manila_config('DEFAULT/state_path').with( + :value => '/var/lib/manila' + ) is_expected.to contain_manila_config('DEFAULT/lock_path').with( :value => '/tmp/manila/manila_locks' ) @@ -94,12 +100,12 @@ end it 'should contain many' do - is_expected.to_not contain_manila_config('DEFAULT/rabbit_host') - is_expected.to_not contain_manila_config('DEFAULT/rabbit_port') - is_expected.to contain_manila_config('DEFAULT/rabbit_hosts').with( + is_expected.to_not contain_manila_config('oslo_messaging_rabbit/rabbit_host') + is_expected.to_not contain_manila_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_hosts').with( :value => 'rabbit1:5672,rabbit2:5672' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_ha_queues').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_ha_queues').with( :value => true ) end @@ -111,12 +117,12 @@ end it 'should contain many' do - is_expected.to_not contain_manila_config('DEFAULT/rabbit_host') - is_expected.to_not contain_manila_config('DEFAULT/rabbit_port') - is_expected.to contain_manila_config('DEFAULT/rabbit_hosts').with( + is_expected.to_not contain_manila_config('oslo_messaging_rabbit/rabbit_host') + is_expected.to_not contain_manila_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_hosts').with( :value => 'rabbit1:5672' ) - is_expected.to contain_manila_config('DEFAULT/rabbit_ha_queues').with( + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_ha_queues').with( :value => true ) end @@ -199,11 +205,11 @@ end it do - is_expected.to contain_manila_config('DEFAULT/rabbit_use_ssl').with_value(true) - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -215,11 +221,11 @@ end it do - is_expected.to contain_manila_config('DEFAULT/rabbit_use_ssl').with_value(true) - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -232,11 +238,11 @@ end it do - is_expected.to contain_manila_config('DEFAULT/rabbit_use_ssl').with_value(false) - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_manila_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_manila_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end diff --git a/memcached/.gitignore b/memcached/.gitignore index f90090294..43d6b1e08 100644 --- a/memcached/.gitignore +++ b/memcached/.gitignore @@ -2,3 +2,4 @@ pkg/ *.swp .forge-releng/ Gemfile.lock +vendor/ diff --git a/memcached/metadata.json b/memcached/metadata.json index 5c86811d1..4fe51f780 100644 --- a/memcached/metadata.json +++ b/memcached/metadata.json @@ -33,9 +33,9 @@ } ], "name": "saz-memcached", - "version": "2.8.0", + "version": "2.8.1", "author": "saz", - "summary": "UNKNOWN", + "summary": "Manage memcached via Puppet", "license": "Apache License, Version 2.0", "source": "git://github.com/saz/puppet-memcached.git", "project_page": "https://github.com/saz/puppet-memcached", diff --git a/mongodb/.travis.yml b/mongodb/.travis.yml index cbf6f11df..7e8ed57bb 100644 --- a/mongodb/.travis.yml +++ b/mongodb/.travis.yml @@ -20,8 +20,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - rvm: 1.8.7 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/mongodb/README.md b/mongodb/README.md index 226b2e73b..06bc21a7d 100644 --- a/mongodb/README.md +++ b/mongodb/README.md @@ -430,11 +430,13 @@ Default: <> #####`ssl_ca` Default: <> - #####`service_manage` Whether or not the MongoDB service resource should be part of the catalog. Default: true +#####`restart` +Specifies whether the service should be restarted on config changes. Default: 'true' + ####Class: mongodb::mongos class. This class should only be used if you want to implement sharding within your mongodb deployment. @@ -486,6 +488,9 @@ This setting can be used to specify if puppet should install the package or not This setting can be used to specify the name of the package that should be installed. If not specified, the module will use whatever service name is the default for your OS distro. +#####`restart` +Specifies whether the service should be restarted on config changes. Default: 'true' + ### Definitions #### Definition: mongodb:db diff --git a/mongodb/manifests/mongos.pp b/mongodb/manifests/mongos.pp index a2d3c7f7e..d5aa62da9 100644 --- a/mongodb/manifests/mongos.pp +++ b/mongodb/manifests/mongos.pp @@ -18,14 +18,25 @@ $fork = $mongodb::params::mongos_fork, $bind_ip = undef, $port = undef, + $restart = $mongodb::params::mongos_restart, ) inherits mongodb::params { if ($ensure == 'present' or $ensure == true) { - anchor { 'mongodb::mongos::start': }-> - class { '::mongodb::mongos::install': }-> - class { '::mongodb::mongos::config': }-> - class { '::mongodb::mongos::service': }-> - anchor { 'mongodb::mongos::end': } + if $restart { + anchor { 'mongodb::mongos::start': }-> + class { 'mongodb::mongos::install': }-> + # If $restart is true, notify the service on config changes (~>) + class { 'mongodb::mongos::config': }~> + class { 'mongodb::mongos::service': }-> + anchor { 'mongodb::mongos::end': } + } else { + anchor { 'mongodb::mongos::start': }-> + class { 'mongodb::mongos::install': }-> + # If $restart is false, config changes won't restart the service (->) + class { 'mongodb::mongos::config': }-> + class { 'mongodb::mongos::service': }-> + anchor { 'mongodb::mongos::end': } + } } else { anchor { 'mongodb::mongos::start': }-> class { '::mongodb::mongos::service': }-> diff --git a/mongodb/manifests/mongos/config.pp b/mongodb/manifests/mongos/config.pp index fc7154762..1b9bc2341 100644 --- a/mongodb/manifests/mongos/config.pp +++ b/mongodb/manifests/mongos/config.pp @@ -20,7 +20,6 @@ owner => 'root', group => 'root', mode => '0644', - notify => Class['mongodb::mongos::service'] } } diff --git a/mongodb/manifests/params.pp b/mongodb/manifests/params.pp index fb2bec3e0..d4e0ad00b 100644 --- a/mongodb/manifests/params.pp +++ b/mongodb/manifests/params.pp @@ -7,12 +7,14 @@ $service_enable = pick($mongodb::globals::service_enable, true) $service_ensure = pick($mongodb::globals::service_ensure, 'running') $service_status = $mongodb::globals::service_status + $restart = true $mongos_service_manage = pick($mongodb::globals::mongos_service_manage, true) $mongos_service_enable = pick($mongodb::globals::mongos_service_enable, true) $mongos_service_ensure = pick($mongodb::globals::mongos_service_ensure, 'running') $mongos_service_status = $mongodb::globals::mongos_service_status $mongos_configdb = '127.0.0.1:27019' + $mongos_restart = true # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'. case $::osfamily { diff --git a/mongodb/manifests/server.pp b/mongodb/manifests/server.pp index d5226c6af..a5affa792 100644 --- a/mongodb/manifests/server.pp +++ b/mongodb/manifests/server.pp @@ -64,6 +64,7 @@ $ssl = undef, $ssl_key = undef, $ssl_ca = undef, + $restart = $mongodb::params::restart, # Deprecated parameters $master = undef, @@ -78,11 +79,21 @@ } if ($ensure == 'present' or $ensure == true) { - anchor { 'mongodb::server::start': }-> - class { '::mongodb::server::install': }-> - class { '::mongodb::server::config': }-> - class { '::mongodb::server::service': }-> - anchor { 'mongodb::server::end': } + if $restart { + anchor { 'mongodb::server::start': }-> + class { 'mongodb::server::install': }-> + # If $restart is true, notify the service on config changes (~>) + class { 'mongodb::server::config': }~> + class { 'mongodb::server::service': }-> + anchor { 'mongodb::server::end': } + } else { + anchor { 'mongodb::server::start': }-> + class { 'mongodb::server::install': }-> + # If $restart is false, config changes won't restart the service (->) + class { 'mongodb::server::config': }-> + class { 'mongodb::server::service': }-> + anchor { 'mongodb::server::end': } + } } else { anchor { 'mongodb::server::start': }-> class { '::mongodb::server::service': }-> diff --git a/mongodb/manifests/server/config.pp b/mongodb/manifests/server/config.pp index 058c00a24..c93427e05 100644 --- a/mongodb/manifests/server/config.pp +++ b/mongodb/manifests/server/config.pp @@ -97,7 +97,6 @@ owner => 'root', group => 'root', mode => '0644', - notify => Class['mongodb::server::service'] } file { $dbpath: diff --git a/mysql/spec/spec_helper_acceptance.rb b/mysql/spec/spec_helper_acceptance.rb index f87c6ed6e..5f8a6e905 100644 --- a/mysql/spec/spec_helper_acceptance.rb +++ b/mysql/spec/spec_helper_acceptance.rb @@ -5,7 +5,10 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = { :default_action => 'gem_install' } + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), + } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end diff --git a/n1k_vsm/manifests/pkgprep_ovscfg.pp b/n1k_vsm/manifests/pkgprep_ovscfg.pp index 96253e0f4..577cd9fb4 100644 --- a/n1k_vsm/manifests/pkgprep_ovscfg.pp +++ b/n1k_vsm/manifests/pkgprep_ovscfg.pp @@ -53,13 +53,13 @@ unless => '/usr/bin/virsh net-info default | /bin/grep -c \'Autostart: .* no\'', } - package { 'Package_openvswitch': + package { 'Package_ovs': ensure => installed, name => 'openvswitch', } # bring up OVS and perform interface configuration - service { 'Service_openvswitch': + service { 'Service_ovs': ensure => running, name => 'openvswitch', enable => true, diff --git a/n1k_vsm/templates/vsm_vm.xml.erb b/n1k_vsm/templates/vsm_vm.xml.erb index 9d6c50026..82a2a013e 100644 --- a/n1k_vsm/templates/vsm_vm.xml.erb +++ b/n1k_vsm/templates/vsm_vm.xml.erb @@ -4,7 +4,7 @@ <%= scope.lookupvar('n1k_vsm::vcpu') %> - hvm + hvm diff --git a/neutron/.gitreview b/neutron/.gitreview index 3d91c1d15..31ff42142 100644 --- a/neutron/.gitreview +++ b/neutron/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-neutron.git +project=openstack/puppet-neutron.git diff --git a/neutron/Gemfile b/neutron/Gemfile index 0d86f5b55..212eec887 100644 --- a/neutron/Gemfile +++ b/neutron/Gemfile @@ -15,7 +15,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/neutron/lib/puppet/provider/neutron.rb b/neutron/lib/puppet/provider/neutron.rb index 4313e2f06..ef946ea97 100644 --- a/neutron/lib/puppet/provider/neutron.rb +++ b/neutron/lib/puppet/provider/neutron.rb @@ -26,13 +26,21 @@ def self.neutron_credentials end def self.get_neutron_credentials - auth_keys = ['auth_host', 'auth_port', 'auth_protocol', - 'admin_tenant_name', 'admin_user', 'admin_password'] + auth_keys = ['admin_tenant_name', 'admin_user', 'admin_password'] + deprecated_auth_url = ['auth_host', 'auth_port', 'auth_protocol'] conf = neutron_conf if conf and conf['keystone_authtoken'] and - auth_keys.all?{|k| !conf['keystone_authtoken'][k].nil?} + auth_keys.all?{|k| !conf['keystone_authtoken'][k].nil?} and + ( deprecated_auth_url.all?{|k| !conf['keystone_authtoken'][k].nil?} or + !conf['keystone_authtoken']['auth_uri'].nil? ) creds = Hash[ auth_keys.map \ { |k| [k, conf['keystone_authtoken'][k].strip] } ] + if !conf['keystone_authtoken']['auth_uri'].nil? + creds['auth_uri'] = conf['keystone_authtoken']['auth_uri'] + else + q = conf['keystone_authtoken'] + creds['auth_uri'] = "#{q['auth_protocol']}://#{q['auth_host']}:#{q['auth_port']}/v2.0/" + end if conf['DEFAULT'] and !conf['DEFAULT']['nova_region_name'].nil? creds['nova_region_name'] = conf['DEFAULT']['nova_region_name'] end @@ -54,7 +62,11 @@ def self.auth_endpoint def self.get_auth_endpoint q = neutron_credentials - "#{q['auth_protocol']}://#{q['auth_host']}:#{q['auth_port']}/v2.0/" + if q['auth_uri'].nil? + return "#{q['auth_protocol']}://#{q['auth_host']}:#{q['auth_port']}/v2.0/" + else + return "#{q['auth_uri']}".strip + end end def self.neutron_conf diff --git a/neutron/manifests/agents/lbaas.pp b/neutron/manifests/agents/lbaas.pp index a6ae3ac8a..f73c39468 100644 --- a/neutron/manifests/agents/lbaas.pp +++ b/neutron/manifests/agents/lbaas.pp @@ -21,7 +21,7 @@ # (optional) Defaults to 'neutron.agent.linux.interface.OVSInterfaceDriver'. # # [*device_driver*] -# (optional) Defaults to 'neutron.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver'. +# (optional) Defaults to 'neutron_lbaas.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver'. # # [*use_namespaces*] # (optional) Allow overlapping IP (Must have kernel build with @@ -43,7 +43,7 @@ $manage_service = true, $debug = false, $interface_driver = 'neutron.agent.linux.interface.OVSInterfaceDriver', - $device_driver = 'neutron.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver', + $device_driver = 'neutron_lbaas.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver', $use_namespaces = true, $user_group = $::neutron::params::nobody_user_group, $manage_haproxy_package = true, diff --git a/neutron/manifests/agents/metadata.pp b/neutron/manifests/agents/metadata.pp index 874c809a6..32fd64a38 100644 --- a/neutron/manifests/agents/metadata.pp +++ b/neutron/manifests/agents/metadata.pp @@ -40,7 +40,7 @@ # CA cert to check against with for ssl keystone. (Defaults to undef) # # [*auth_region*] -# The authentication region. Defaults to 'RegionOne'. +# The authentication region. (Defaults to undef) # # [*metadata_ip*] # The IP address of the metadata service. Defaults to '127.0.0.1'. @@ -83,7 +83,7 @@ $auth_url = 'http://localhost:35357/v2.0', $auth_insecure = false, $auth_ca_cert = undef, - $auth_region = 'RegionOne', + $auth_region = undef, $metadata_ip = '127.0.0.1', $metadata_port = '8775', $metadata_protocol = 'http', @@ -102,7 +102,6 @@ 'DEFAULT/debug': value => $debug; 'DEFAULT/auth_url': value => $auth_url; 'DEFAULT/auth_insecure': value => $auth_insecure; - 'DEFAULT/auth_region': value => $auth_region; 'DEFAULT/admin_tenant_name': value => $auth_tenant; 'DEFAULT/admin_user': value => $auth_user; 'DEFAULT/admin_password': value => $auth_password, secret => true; @@ -114,23 +113,33 @@ 'DEFAULT/metadata_backlog': value => $metadata_backlog; } + if $auth_region { + neutron_metadata_agent_config { + 'DEFAULT/auth_region': value => $auth_region; + } + } else { + neutron_metadata_agent_config { + 'DEFAULT/auth_region': ensure => absent; + } + } + if $metadata_memory_cache_ttl { neutron_metadata_agent_config { - 'DEFAULT/cache_url': value => "memory://?default_ttl=${metadata_memory_cache_ttl}"; + 'DEFAULT/cache_url': value => "memory://?default_ttl=${metadata_memory_cache_ttl}"; } } else { neutron_metadata_agent_config { - 'DEFAULT/cache_url': ensure => absent; + 'DEFAULT/cache_url': ensure => absent; } } if $auth_ca_cert { neutron_metadata_agent_config { - 'DEFAULT/auth_ca_cert': value => $auth_ca_cert; + 'DEFAULT/auth_ca_cert': value => $auth_ca_cert; } } else { neutron_metadata_agent_config { - 'DEFAULT/auth_ca_cert': ensure => absent; + 'DEFAULT/auth_ca_cert': ensure => absent; } } diff --git a/neutron/manifests/init.pp b/neutron/manifests/init.pp index 7a58f3271..3db024682 100644 --- a/neutron/manifests/init.pp +++ b/neutron/manifests/init.pp @@ -403,55 +403,55 @@ fail('When rpc_backend is rabbitmq, you must set rabbit password') } if $rabbit_hosts { - neutron_config { 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ',') } - neutron_config { 'DEFAULT/rabbit_ha_queues': value => true } + neutron_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } + neutron_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { - neutron_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - neutron_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - neutron_config { 'DEFAULT/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } - neutron_config { 'DEFAULT/rabbit_ha_queues': value => false } + neutron_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + neutron_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + neutron_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } + neutron_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } neutron_config { - 'DEFAULT/rabbit_userid': value => $rabbit_user; - 'DEFAULT/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; - 'DEFAULT/kombu_reconnect_delay': value => $kombu_reconnect_delay; + 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_user; + 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_virtual_host': value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl': value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/kombu_reconnect_delay': value => $kombu_reconnect_delay; } if $rabbit_use_ssl { if $kombu_ssl_ca_certs { - neutron_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } + neutron_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } } else { - neutron_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; } + neutron_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; } } if $kombu_ssl_certfile or $kombu_ssl_keyfile { neutron_config { - 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; + 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; } } else { neutron_config { - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } if $kombu_ssl_version { - neutron_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version; } + neutron_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version; } } else { - neutron_config { 'DEFAULT/kombu_ssl_version': ensure => absent; } + neutron_config { 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } else { neutron_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } diff --git a/neutron/manifests/params.pp b/neutron/manifests/params.pp index 08179434e..14b76292a 100644 --- a/neutron/manifests/params.pp +++ b/neutron/manifests/params.pp @@ -142,7 +142,7 @@ $l3_agent_package = 'neutron-l3-agent' $l3_agent_service = 'neutron-l3-agent' - $fwaas_package = 'neutron-fwaas' + $fwaas_package = 'python-neutron-fwaas' $cliff_package = 'python-cliff' $kernel_headers = "linux-headers-${::kernelrelease}" diff --git a/neutron/manifests/server/notifications.pp b/neutron/manifests/server/notifications.pp index 8cfb6d7fe..4a6f7db8e 100644 --- a/neutron/manifests/server/notifications.pp +++ b/neutron/manifests/server/notifications.pp @@ -57,7 +57,7 @@ # [*nova_region_name*] # (optional) Name of nova region to use. Useful if keystone manages more than # one region. -# Defaults to 'RegionOne' +# Defaults to undef # class neutron::server::notifications ( @@ -70,7 +70,7 @@ $nova_admin_tenant_name = 'services', $nova_admin_tenant_id = undef, $nova_admin_password = false, - $nova_region_name = 'RegionOne', + $nova_region_name = undef, ) { # Depend on the specified keystone_user resource, if it exists. @@ -92,7 +92,16 @@ 'DEFAULT/nova_admin_auth_url': value => $nova_admin_auth_url; 'DEFAULT/nova_admin_username': value => $nova_admin_username; 'DEFAULT/nova_admin_password': value => $nova_admin_password, secret => true; - 'DEFAULT/nova_region_name': value => $nova_region_name; + } + + if $nova_region_name { + neutron_config { + 'DEFAULT/nova_region_name': value => $nova_region_name; + } + } else { + neutron_config { + 'DEFAULT/nova_region_name': ensure => absent; + } } if $nova_admin_tenant_id { diff --git a/neutron/spec/acceptance/basic_neutron_spec.rb b/neutron/spec/acceptance/basic_neutron_spec.rb index a3938c3d9..d4809881f 100644 --- a/neutron/spec/acceptance/basic_neutron_spec.rb +++ b/neutron/spec/acceptance/basic_neutron_spec.rb @@ -8,10 +8,34 @@ pp= <<-EOS Exec { logoutput => 'on_failure' } - include ::apt - class { '::openstack_extras::repo::debian::ubuntu': - release => 'kilo', - package_require => true, + # Common resources + case $::osfamily { + 'Debian': { + include ::apt + class { '::openstack_extras::repo::debian::ubuntu': + release => 'kilo', + package_require => true, + } + $package_provider = 'apt' + } + 'RedHat': { + class { '::openstack_extras::repo::redhat::redhat': + # Kilo is not GA yet, so let's use the testing repo + manage_rdo => false, + repo_hash => { + 'rdo-kilo-testing' => { + 'baseurl' => 'https://repos.fedorapeople.org/repos/openstack/openstack-kilo/testing/el7/', + # packages are not GA so not signed + 'gpgcheck' => '0', + 'priority' => 97, + }, + }, + } + $package_provider = 'yum' + } + default: { + fail("Unsupported osfamily (${::osfamily})") + } } class { '::mysql::server': } @@ -19,6 +43,7 @@ class { '::mysql::server': } class { '::rabbitmq': delete_guest_user => true, erlang_cookie => 'secrete', + package_provider => $package_provider, } rabbitmq_vhost { '/': @@ -67,7 +92,12 @@ class { '::neutron': rabbit_password => 'an_even_bigger_secret', rabbit_host => '127.0.0.1', allow_overlapping_ips => true, - core_plugin => 'neutron.plugins.ml2.plugin.Ml2Plugin', + core_plugin => 'ml2', + service_plugins => [ + 'neutron.services.l3_router.l3_router_plugin.L3RouterPlugin', + 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', + 'neutron.services.metering.metering_plugin.MeteringPlugin', + ], } class { '::neutron::db::mysql': password => 'a_big_secret', @@ -79,18 +109,26 @@ class { '::neutron::server': database_connection => 'mysql://neutron:a_big_secret@127.0.0.1/neutron?charset=utf8', auth_password => 'a_big_secret', identity_uri => 'http://127.0.0.1:35357/', + sync_db => true, } class { '::neutron::client': } class { '::neutron::quota': } class { '::neutron::agents::dhcp': } class { '::neutron::agents::l3': } - class { '::neutron::agents::lbaas': } + class { '::neutron::agents::lbaas': + device_driver => 'neutron_lbaas.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver', + } class { '::neutron::agents::metering': } class { '::neutron::agents::ml2::ovs': enable_tunneling => true, local_ip => '127.0.0.1', + tunnel_types => ['vxlan'], + } + class { '::neutron::plugins::ml2': + type_drivers => ['vxlan'], + tenant_network_types => ['vxlan'], + mechanism_drivers => ['openvswitch'] } - class { '::neutron::plugins::ml2': } EOS diff --git a/neutron/spec/acceptance/nodesets/nodepool-centos7.yml b/neutron/spec/acceptance/nodesets/nodepool-centos7.yml new file mode 100644 index 000000000..575ae6732 --- /dev/null +++ b/neutron/spec/acceptance/nodesets/nodepool-centos7.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-70-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor : none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/neutron/spec/acceptance/nodesets/nodepool.yml b/neutron/spec/acceptance/nodesets/nodepool-trusty.yml similarity index 89% rename from neutron/spec/acceptance/nodesets/nodepool.yml rename to neutron/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/neutron/spec/acceptance/nodesets/nodepool.yml +++ b/neutron/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/neutron/spec/classes/neutron_agents_lbaas_spec.rb b/neutron/spec/classes/neutron_agents_lbaas_spec.rb index db1c64695..08f08fba8 100644 --- a/neutron/spec/classes/neutron_agents_lbaas_spec.rb +++ b/neutron/spec/classes/neutron_agents_lbaas_spec.rb @@ -15,7 +15,7 @@ :enabled => true, :debug => false, :interface_driver => 'neutron.agent.linux.interface.OVSInterfaceDriver', - :device_driver => 'neutron.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver', + :device_driver => 'neutron_lbaas.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver', :use_namespaces => true, :manage_haproxy_package => true } diff --git a/neutron/spec/classes/neutron_init_spec.rb b/neutron/spec/classes/neutron_init_spec.rb index 575625101..0c150c38e 100644 --- a/neutron/spec/classes/neutron_init_spec.rb +++ b/neutron/spec/classes/neutron_init_spec.rb @@ -99,11 +99,11 @@ end it 'configures credentials for rabbit' do - is_expected.to contain_neutron_config('DEFAULT/rabbit_userid').with_value( params[:rabbit_user] ) - is_expected.to contain_neutron_config('DEFAULT/rabbit_password').with_value( params[:rabbit_password] ) - is_expected.to contain_neutron_config('DEFAULT/rabbit_password').with_secret( true ) - is_expected.to contain_neutron_config('DEFAULT/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) - is_expected.to contain_neutron_config('DEFAULT/kombu_reconnect_delay').with_value( params[:kombu_reconnect_delay] ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_user] ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value( params[:kombu_reconnect_delay] ) end it 'configures neutron.conf' do @@ -133,19 +133,19 @@ shared_examples_for 'rabbit HA with a single virtual host' do it 'in neutron.conf' do - is_expected.not_to contain_neutron_config('DEFAULT/rabbit_host') - is_expected.not_to contain_neutron_config('DEFAULT/rabbit_port') - is_expected.to contain_neutron_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts] ) - is_expected.to contain_neutron_config('DEFAULT/rabbit_ha_queues').with_value(true) + is_expected.not_to contain_neutron_config('oslo_messaging_rabbit/rabbit_host') + is_expected.not_to contain_neutron_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts] ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) end end shared_examples_for 'rabbit HA with multiple hosts' do it 'in neutron.conf' do - is_expected.not_to contain_neutron_config('DEFAULT/rabbit_host') - is_expected.not_to contain_neutron_config('DEFAULT/rabbit_port') - is_expected.to contain_neutron_config('DEFAULT/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) - is_expected.to contain_neutron_config('DEFAULT/rabbit_ha_queues').with_value(true) + is_expected.not_to contain_neutron_config('oslo_messaging_rabbit/rabbit_host') + is_expected.not_to contain_neutron_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) end end @@ -235,11 +235,11 @@ end it do - is_expected.to contain_neutron_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -251,11 +251,11 @@ end it do - is_expected.to contain_neutron_config('DEFAULT/rabbit_use_ssl').with_value('true') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -268,11 +268,11 @@ end it do - is_expected.to contain_neutron_config('DEFAULT/rabbit_use_ssl').with_value('false') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_neutron_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_neutron_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end diff --git a/neutron/spec/classes/neutron_server_notifications_spec.rb b/neutron/spec/classes/neutron_server_notifications_spec.rb index 9a7820e78..07e806f36 100644 --- a/neutron/spec/classes/neutron_server_notifications_spec.rb +++ b/neutron/spec/classes/neutron_server_notifications_spec.rb @@ -29,7 +29,7 @@ :nova_admin_auth_url => 'http://127.0.0.1:35357/v2.0', :nova_admin_username => 'nova', :nova_admin_tenant_name => 'services', - :nova_region_name => 'RegionOne' + :nova_region_name => nil, } end @@ -54,8 +54,8 @@ is_expected.to contain_neutron_config('DEFAULT/nova_admin_username').with_value('nova') is_expected.to contain_neutron_config('DEFAULT/nova_admin_password').with_value('secrete') is_expected.to contain_neutron_config('DEFAULT/nova_admin_password').with_secret( true ) - is_expected.to contain_neutron_config('DEFAULT/nova_region_name').with_value('RegionOne') is_expected.to contain_neutron_config('DEFAULT/nova_admin_tenant_id').with_value('UUID') + is_expected.to contain_neutron_config('DEFAULT/nova_region_name').with_ensure('absent') end context 'when overriding parameters' do diff --git a/neutron/spec/classes/neutron_services_fwaas_spec.rb b/neutron/spec/classes/neutron_services_fwaas_spec.rb index 0a3803890..e236f4189 100644 --- a/neutron/spec/classes/neutron_services_fwaas_spec.rb +++ b/neutron/spec/classes/neutron_services_fwaas_spec.rb @@ -55,7 +55,7 @@ it_configures 'neutron fwaas service plugin' it 'installs neutron fwaas package' do - is_expected.to contain_package('neutron-fwaas').with( + is_expected.to contain_package('python-neutron-fwaas').with( :ensure => 'present', :tag => 'openstack' ) @@ -71,7 +71,7 @@ it_configures 'neutron fwaas service plugin' it 'installs neutron fwaas package' do - is_expected.to contain_package('neutron-fwaas').with( + is_expected.to contain_package('python-neutron-fwaas').with( :ensure => 'present', :tag => 'openstack' ) diff --git a/neutron/spec/spec_helper_acceptance.rb b/neutron/spec/spec_helper_acceptance.rb index c110059a9..7fd3b0eaa 100644 --- a/neutron/spec/spec_helper_acceptance.rb +++ b/neutron/spec/spec_helper_acceptance.rb @@ -29,15 +29,19 @@ on host, puppet('module','install','puppetlabs-mysql'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','dprince/qpid'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','duritong/sysctl'), { :acceptable_exit_codes => 0 } + # pin apt module until openstack_extras use >= 2.0.0 version + on host, puppet('module','install','puppetlabs-apt','--version','1.8.0'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','puppetlabs-inifile'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','stahnma-epel'), { :acceptable_exit_codes => 0 } - on host, puppet('module','install','puppetlabs-rabbitmq'), { :acceptable_exit_codes => 0 } # install puppet modules from git, use master shell('git clone https://git.openstack.org/stackforge/puppet-openstacklib /etc/puppet/modules/openstacklib') shell('git clone https://git.openstack.org/stackforge/puppet-vswitch /etc/puppet/modules/vswitch') shell('git clone https://git.openstack.org/stackforge/puppet-keystone /etc/puppet/modules/keystone') shell('git clone https://git.openstack.org/stackforge/puppet-openstack_extras /etc/puppet/modules/openstack_extras') + # TODO(EmilienM) Cloning RabbitMQ module for now because we wait for a release including + # https://github.com/enovance/puppetlabs-rabbitmq/commit/0227f762070ffbbea3c28d6a60174de98fa4cc1c + shell('git clone https://github.com/puppetlabs/puppetlabs-rabbitmq/ /etc/puppet/modules/rabbitmq') # Install the module being tested puppet_module_install(:source => proj_root, :module_name => 'neutron') diff --git a/nova/.gitreview b/nova/.gitreview index 3e4002cd4..cd6f9d1e7 100644 --- a/nova/.gitreview +++ b/nova/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-nova.git +project=openstack/puppet-nova.git diff --git a/nova/Gemfile b/nova/Gemfile index 4c65317ac..3c0b87530 100644 --- a/nova/Gemfile +++ b/nova/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -17,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/nova/manifests/api.pp b/nova/manifests/api.pp index 21c7af155..a21eaf817 100644 --- a/nova/manifests/api.pp +++ b/nova/manifests/api.pp @@ -346,7 +346,9 @@ # Added arg and if statement prevents this from being run # where db is not active i.e. the compute if $sync_db { - Package<| title == 'nova-api' |> -> Exec['nova-db-sync'] + Package<| title == $::nova::params::api_package_name |> ~> Exec['nova-db-sync'] + Package<| title == $::nova::params::common_package_name |> ~> Exec['nova-db-sync'] + exec { 'nova-db-sync': command => '/usr/bin/nova-manage db sync', refreshonly => true, diff --git a/nova/manifests/init.pp b/nova/manifests/init.pp index 634f06ab2..8b91bb7b2 100644 --- a/nova/manifests/init.pp +++ b/nova/manifests/init.pp @@ -168,10 +168,6 @@ # (optional) Path to the rootwrap configuration file to use for running commands as root # Defaults to '/etc/nova/rootwrap.conf' # -# [*monitoring_notifications*] -# (optional) Whether or not to send system usage data notifications out on the message queue. Only valid for stable/essex. -# Defaults to false -# # [*use_syslog*] # (optional) Use syslog for logging # Defaults to false @@ -354,13 +350,13 @@ } if $nova_public_key { - if ! $nova_public_key[key] or ! $nova_public_key['type'] { + if ! $nova_public_key['key'] or ! $nova_public_key['type'] { fail('You must provide both a key type and key data.') } ssh_authorized_key { 'nova-migration-public-key': ensure => present, - key => $nova_public_key[key], + key => $nova_public_key['key'], type => $nova_public_key['type'], user => 'nova', require => File['/var/lib/nova/.ssh'], @@ -463,63 +459,63 @@ if $rpc_backend == 'nova.openstack.common.rpc.impl_kombu' or $rpc_backend == 'rabbit' { # I may want to support exporting and collecting these nova_config { - 'DEFAULT/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_userid': value => $rabbit_userid; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; + 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_userid; + 'oslo_messaging_rabbit/rabbit_virtual_host': value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_use_ssl': value => $rabbit_use_ssl; 'DEFAULT/amqp_durable_queues': value => $amqp_durable_queues; } if $rabbit_use_ssl { if $kombu_ssl_ca_certs { - nova_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } + nova_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } } else { - nova_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; } + nova_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; } } if $kombu_ssl_certfile or $kombu_ssl_keyfile { nova_config { - 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; + 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; } } else { nova_config { - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } if $kombu_ssl_version { - nova_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version; } + nova_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version; } } else { - nova_config { 'DEFAULT/kombu_ssl_version': ensure => absent; } + nova_config { 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } else { nova_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } if $rabbit_hosts { - nova_config { 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ',') } + nova_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ',') } } else { - nova_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - nova_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - nova_config { 'DEFAULT/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } + nova_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } + nova_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } + nova_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } } if $rabbit_ha_queues == undef { if $rabbit_hosts { - nova_config { 'DEFAULT/rabbit_ha_queues': value => true } + nova_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { - nova_config { 'DEFAULT/rabbit_ha_queues': value => false } + nova_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } } } else { - nova_config { 'DEFAULT/rabbit_ha_queues': value => $rabbit_ha_queues } + nova_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => $rabbit_ha_queues } } } diff --git a/nova/spec/acceptance/nodesets/nodepool-centos7.yml b/nova/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/nova/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/nova/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/nova/spec/acceptance/nodesets/nodepool-trusty.yml b/nova/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/nova/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/nova/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/nova/spec/classes/nova_api_spec.rb b/nova/spec/classes/nova_api_spec.rb index 030e015ed..6fe090a8d 100644 --- a/nova/spec/classes/nova_api_spec.rb +++ b/nova/spec/classes/nova_api_spec.rb @@ -28,9 +28,9 @@ is_expected.to contain_package('nova-api').with( :name => platform_params[:nova_api_package], :ensure => 'present', - :notify => 'Service[nova-api]', :tag => ['openstack'] ) + is_expected.to contain_package('nova-api').that_notifies('Service[nova-api]') is_expected.to_not contain_exec('validate_nova_api') end diff --git a/nova/spec/classes/nova_compute_libvirt_spec.rb b/nova/spec/classes/nova_compute_libvirt_spec.rb index a2795f3d2..7bf5d4c80 100644 --- a/nova/spec/classes/nova_compute_libvirt_spec.rb +++ b/nova/spec/classes/nova_compute_libvirt_spec.rb @@ -31,7 +31,7 @@ :ensure => 'running', :provider => 'upstart', :require => 'Package[libvirt]', - :before => 'Service[nova-compute]' + :before => ['Service[nova-compute]'] )} it { is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.LibvirtDriver')} @@ -75,7 +75,7 @@ :enable => true, :ensure => 'running', :require => 'Package[libvirt]', - :before => 'Service[nova-compute]' + :before => ['Service[nova-compute]'] )} end @@ -148,12 +148,12 @@ :ensure => 'running', :provider => 'init', :require => 'Package[libvirt]', - :before => 'Service[nova-compute]' + :before => ['Service[nova-compute]'] )} it { is_expected.to contain_service('messagebus').with( :ensure => 'running', :enable => true, - :before => 'Service[libvirt]', + :before => ['Service[libvirt]'], :provider => 'init', :name => 'messagebus' ) } @@ -246,7 +246,7 @@ :ensure => 'running', :provider => nil, :require => 'Package[libvirt]', - :before => 'Service[nova-compute]' + :before => ['Service[nova-compute]'] )} it { is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.LibvirtDriver')} diff --git a/nova/spec/classes/nova_init_spec.rb b/nova/spec/classes/nova_init_spec.rb index aacf4a4e6..368cb6a12 100644 --- a/nova/spec/classes/nova_init_spec.rb +++ b/nova/spec/classes/nova_init_spec.rb @@ -57,11 +57,11 @@ it 'configures rabbit' do is_expected.to contain_nova_config('DEFAULT/rpc_backend').with_value('rabbit') - is_expected.to contain_nova_config('DEFAULT/rabbit_host').with_value('localhost') - is_expected.to contain_nova_config('DEFAULT/rabbit_password').with_value('guest').with_secret(true) - is_expected.to contain_nova_config('DEFAULT/rabbit_port').with_value('5672') - is_expected.to contain_nova_config('DEFAULT/rabbit_userid').with_value('guest') - is_expected.to contain_nova_config('DEFAULT/rabbit_virtual_host').with_value('/') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_password').with_value('guest').with_secret(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_port').with_value('5672') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value('/') end it 'configures various things' do @@ -128,11 +128,11 @@ it 'configures rabbit' do is_expected.to contain_nova_config('DEFAULT/rpc_backend').with_value('rabbit') - is_expected.to contain_nova_config('DEFAULT/rabbit_host').with_value('rabbit') - is_expected.to contain_nova_config('DEFAULT/rabbit_password').with_value('password').with_secret(true) - is_expected.to contain_nova_config('DEFAULT/rabbit_port').with_value('5673') - is_expected.to contain_nova_config('DEFAULT/rabbit_userid').with_value('rabbit_user') - is_expected.to contain_nova_config('DEFAULT/rabbit_virtual_host').with_value('/') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_host').with_value('rabbit') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_password').with_value('password').with_secret(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_userid').with_value('rabbit_user') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value('/') end it 'configures memcached_servers' do @@ -221,16 +221,16 @@ end it 'configures rabbit' do - is_expected.to_not contain_nova_config('DEFAULT/rabbit_host') - is_expected.to_not contain_nova_config('DEFAULT/rabbit_port') - is_expected.to contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673,rabbit2:5674') - is_expected.to contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true) - is_expected.to contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false) + is_expected.to_not contain_nova_config('oslo_messaging_rabbit/rabbit_host') + is_expected.to_not contain_nova_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_hosts').with_value('rabbit:5673,rabbit2:5674') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) is_expected.to contain_nova_config('DEFAULT/amqp_durable_queues').with_value(false) - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end @@ -240,11 +240,11 @@ end it 'configures rabbit' do - is_expected.to_not contain_nova_config('DEFAULT/rabbit_host') - is_expected.to_not contain_nova_config('DEFAULT/rabbit_port') - is_expected.to contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673') - is_expected.to contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true) - is_expected.to contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false) + is_expected.to_not contain_nova_config('oslo_messaging_rabbit/rabbit_host') + is_expected.to_not contain_nova_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_hosts').with_value('rabbit:5673') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) is_expected.to contain_nova_config('DEFAULT/amqp_durable_queues').with_value(false) end end @@ -255,7 +255,7 @@ end it 'configures rabbit' do - is_expected.to contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) end end @@ -266,16 +266,16 @@ end it 'configures rabbit' do - is_expected.to_not contain_nova_config('DEFAULT/rabbit_host') - is_expected.to_not contain_nova_config('DEFAULT/rabbit_port') - is_expected.to contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673') - is_expected.to contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true) - is_expected.to contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false) + is_expected.to_not contain_nova_config('oslo_messaging_rabbit/rabbit_host') + is_expected.to_not contain_nova_config('oslo_messaging_rabbit/rabbit_port') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_hosts').with_value('rabbit:5673') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) is_expected.to contain_nova_config('DEFAULT/amqp_durable_queues').with_value(true) - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end @@ -290,11 +290,11 @@ end it 'configures rabbit' do - is_expected.to contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(true) - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_value('/etc/ca.cert') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_certfile').with_value('/etc/certfile') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_value('/etc/key') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/etc/ca.cert') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/etc/certfile') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/etc/key') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -305,11 +305,11 @@ end it 'configures rabbit' do - is_expected.to contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(true) - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end @@ -323,11 +323,11 @@ end it 'configures rabbit' do - is_expected.to contain_nova_config('DEFAULT/rabbit_use_ssl').with_value('false') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') - is_expected.to contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') + is_expected.to contain_nova_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') end end @@ -413,8 +413,7 @@ context 'with ssh public key missing key type' do let :params do { - :nova_public_key => {'type' => '', - 'key' => 'keydata'} + :nova_public_key => {'key' => 'keydata'} } end @@ -422,8 +421,7 @@ expect { is_expected.to contain_ssh_authorized_key('nova-migration-public-key').with( :ensure => 'present', - :key => 'keydata', - :type => '' + :key => 'keydata' ) }.to raise_error Puppet::Error, /You must provide both a key type and key data./ end @@ -432,8 +430,7 @@ context 'with ssh public key missing key data' do let :params do { - :nova_public_key => {'type' => 'ssh-rsa', - 'key' => ''} + :nova_public_key => {'type' => 'ssh-rsa'} } end @@ -441,8 +438,7 @@ expect { is_expected.to contain_ssh_authorized_key('nova-migration-public-key').with( :ensure => 'present', - :key => 'keydata', - :type => '' + :key => 'keydata' ) }.to raise_error Puppet::Error, /You must provide both a key type and key data./ end @@ -466,8 +462,7 @@ context 'with ssh private key missing key type' do let :params do { - :nova_private_key => {'type' => '', - 'key' => 'keydata'} + :nova_private_key => {'key' => 'keydata'} } end @@ -500,8 +495,7 @@ context 'with ssh private key missing key data' do let :params do { - :nova_private_key => {'type' => 'ssh-rsa', - 'key' => ''} + :nova_private_key => {'type' => 'ssh-rsa'} } end diff --git a/nova/spec/classes/nova_keystone_endpoint_spec.rb b/nova/spec/classes/nova_keystone_endpoint_spec.rb index 038001b5a..907440ec1 100644 --- a/nova/spec/classes/nova_keystone_endpoint_spec.rb +++ b/nova/spec/classes/nova_keystone_endpoint_spec.rb @@ -15,7 +15,7 @@ it { is_expected.to contain_keystone_user_role('nova@services').with( :ensure => 'present', - :roles => 'admin' + :roles => ['admin'] )} it { is_expected.to contain_keystone_service('nova').with( @@ -71,7 +71,7 @@ it { is_expected.to contain_keystone_user_role('foo@services').with( :ensure => 'present', - :roles => 'admin' + :roles => ['admin'] )} it { is_expected.to contain_keystone_service('foo').with( @@ -234,7 +234,7 @@ } end - it { is_expected.to contain_keystone_endpoint('RegionOne/nova').with_notify('Service[nova-api]') } + it { is_expected.to contain_keystone_endpoint('RegionOne/nova').with_notify(['Service[nova-api]']) } end describe 'when overriding service names' do diff --git a/nova/spec/type/nova_aggregate_spec.rb b/nova/spec/type/nova_aggregate_spec.rb index dc5db974a..e3bcb0340 100644 --- a/nova/spec/type/nova_aggregate_spec.rb +++ b/nova/spec/type/nova_aggregate_spec.rb @@ -20,25 +20,25 @@ def self.instances; []; end end it "should be able to create an more complex instance" do - described_class.new(:name => 'agg0', + expect(described_class.new(:name => 'agg0', :availability_zone => 'myzone', :metadata => "a=b, c=d", - :hosts => "host1").should_not be_nil + :hosts => "host1")).to_not be_nil end it "should be able to create an more complex instance with multiple hosts" do - described_class.new(:name => 'agg0', + expect(described_class.new(:name => 'agg0', :availability_zone => 'myzone', :metadata => "a=b, c=d", - :hosts => "host1, host2").should_not be_nil + :hosts => "host1, host2")).to_not be_nil end it "should be able to create a instance and have the default values" do c = described_class.new(:name => 'agg0') - c[:name].should == "agg0" - c[:availability_zone].should == nil - c[:metadata].should == nil - c[:hosts].should == nil + expect(c[:name]).to eq("agg0") + expect(c[:availability_zone]).to eq( nil) + expect(c[:metadata]).to eq(nil) + expect(c[:hosts]).to eq(nil) end it "should return the given values" do @@ -46,10 +46,10 @@ def self.instances; []; end :availability_zone => 'myzone', :metadata => " a = b , c= d ", :hosts => " host1, host2 ") - c[:name].should == "agg0" - c[:availability_zone].should == "myzone" - c[:metadata].should == {"a" => "b", "c" => "d"} - c[:hosts].should == ["host1" , "host2"] + expect(c[:name]).to eq("agg0") + expect(c[:availability_zone]).to eq("myzone") + expect(c[:metadata]).to eq({"a" => "b", "c" => "d"}) + expect(c[:hosts]).to eq(["host1" , "host2"]) end it "should return the given values" do @@ -57,10 +57,10 @@ def self.instances; []; end :availability_zone => "", :metadata => "", :hosts => "") - c[:name].should == "agg0" - c[:availability_zone].should == "" - c[:metadata].should == {} - c[:hosts].should == [] + expect(c[:name]).to eq("agg0") + expect(c[:availability_zone]).to eq("") + expect(c[:metadata]).to eq({}) + expect(c[:hosts]).to eq([]) end end diff --git a/nova/spec/unit/provider/nova_config/ini_setting_spec.rb b/nova/spec/unit/provider/nova_config/ini_setting_spec.rb index 0f58316d3..2a226d4d0 100644 --- a/nova/spec/unit/provider/nova_config/ini_setting_spec.rb +++ b/nova/spec/unit/provider/nova_config/ini_setting_spec.rb @@ -23,8 +23,8 @@ {:name => 'DEFAULT/foo', :value => 'bar'} ) provider = provider_class.new(resource) - provider.section.should == 'DEFAULT' - provider.setting.should == 'foo' + expect(provider.section).to eq('DEFAULT') + expect(provider.setting).to eq('foo') end it 'should allow setting to be set explicitly' do @@ -32,7 +32,7 @@ {:name => 'dude/foo', :value => 'bar'} ) provider = provider_class.new(resource) - provider.section.should == 'dude' - provider.setting.should == 'foo' + expect(provider.section).to eq('dude') + expect(provider.setting).to eq('foo') end end diff --git a/nova/spec/unit/provider/nova_spec.rb b/nova/spec/unit/provider/nova_spec.rb index 6f757e746..64bfc3fde 100644 --- a/nova/spec/unit/provider/nova_spec.rb +++ b/nova/spec/unit/provider/nova_spec.rb @@ -61,7 +61,7 @@ def klass it 'should use specified host/port/protocol in the auth endpoint' do conf = {'keystone_authtoken' => credential_hash} klass.expects(:nova_conf).returns(conf) - klass.get_auth_endpoint.should == auth_endpoint + expect(klass.get_auth_endpoint).to eq(auth_endpoint) end end @@ -96,53 +96,53 @@ def klass describe 'when parse a string line' do it 'should return the same string' do res = klass.str2hash("zone1") - res.should == "zone1" + expect(res).to eq("zone1") end it 'should return the string without quotes' do res = klass.str2hash("'zone1'") - res.should == "zone1" + expect(res).to eq("zone1") end it 'should return the same string' do res = klass.str2hash("z o n e1") - res.should == "z o n e1" + expect(res).to eq("z o n e1") end it 'should return a hash' do res = klass.str2hash("a=b") - res.should == {"a"=>"b"} + expect(res).to eq({"a"=>"b"}) end it 'should return a hash with containing spaces' do res = klass.str2hash("a b = c d") - res.should == {"a b "=>" c d"} + expect(res).to eq({"a b "=>" c d"}) end it 'should return the same string' do res = klass.str2list("zone1") - res.should == "zone1" + expect(res).to eq("zone1") end it 'should return a list of strings' do res = klass.str2list("zone1, zone2") - res.should == ["zone1", "zone2"] + expect(res).to eq(["zone1", "zone2"]) end it 'should return a list of strings' do res = klass.str2list("zo n e1, zone2 ") - res.should == ["zo n e1", "zone2"] + expect(res).to eq(["zo n e1", "zone2"]) end it 'should return a hash with multiple keys' do res = klass.str2list("a=b, c=d") - res.should == {"a"=>"b", "c"=>"d"} + expect(res).to eq({"a"=>"b", "c"=>"d"}) end it 'should return a single hash' do res = klass.str2list("a=b") - res.should == {"a"=>"b"} + expect(res).to eq({"a"=>"b"}) end end @@ -158,8 +158,8 @@ def klass +----+-------+-------------------+ EOT res = klass.cliout2list(output) - res.should == [{"Id"=>"1", "Name"=>"haha", "Availability Zone"=>"haha2"}, - {"Id"=>"2", "Name"=>"haha2", "Availability Zone"=>""}] + expect(res).to eq([{"Id"=>"1", "Name"=>"haha", "Availability Zone"=>"haha2"}, + {"Id"=>"2", "Name"=>"haha2", "Availability Zone"=>""}]) end it 'should return a list with hashes' do @@ -171,7 +171,7 @@ def klass +----+-------+-------------------+-------+--------------------------------------------------+ EOT res = klass.cliout2list(output) - res.should == [{"Id"=>"16", + expect(res).to eq([{"Id"=>"16", "Name"=>"agg94", "Availability Zone"=>"my_-zone1", "Hosts"=>"", @@ -180,7 +180,7 @@ def klass "availability_zone"=>" my_-zone1", "x_q-r"=>"y" } - }] + }]) end it 'should return a empty list' do @@ -191,14 +191,14 @@ def klass +----+------+-------------------+ EOT res = klass.cliout2list(output) - res.should == [] + expect(res).to eq([]) end it 'should return a empty list because no input available' do output = <<-EOT EOT res = klass.cliout2list(output) - res.should == [] + expect(res).to eq([]) end it 'should return a list with hashes' do @@ -211,8 +211,8 @@ def klass +----+----------------+-------------------+ EOT res = klass.cliout2list(output) - res.should == [{"Id"=>"6", "Name"=>"my", "Availability Zone"=>"zone1"}, - {"Id"=>"8", "Name"=>"my2", "Availability Zone"=>""}] + expect(res).to eq([{"Id"=>"6", "Name"=>"my", "Availability Zone"=>"zone1"}, + {"Id"=>"8", "Name"=>"my2", "Availability Zone"=>""}]) end end @@ -228,7 +228,7 @@ def klass EOT klass.expects(:auth_nova).returns(output) res = klass.nova_aggregate_resources_get_name_by_id("haha2") - res.should eql(2) + expect(res).to eql(2) end it 'should return nil because given name is not available' do @@ -242,7 +242,7 @@ def klass EOT klass.expects(:auth_nova).returns(output) res = klass.nova_aggregate_resources_get_name_by_id("notavailable") - res.should eql(nil) + expect(res).to eql(nil) end end @@ -257,7 +257,7 @@ def klass EOT klass.expects(:auth_nova).returns(output) res = klass.nova_aggregate_resources_attr(16) - res.should == { + expect(res).to eq({ "Id"=>"16", "Name"=>"agg94", "Availability Zone"=>"my_-zone1", @@ -267,7 +267,7 @@ def klass "availability_zone"=>" my_-zone1", "x_q-r"=>"y" } - } + }) end end diff --git a/nova/spec/unit/type/nova_config_spec.rb b/nova/spec/unit/type/nova_config_spec.rb index 353fff087..0d09e826a 100644 --- a/nova/spec/unit/type/nova_config_spec.rb +++ b/nova/spec/unit/type/nova_config_spec.rb @@ -29,19 +29,19 @@ it 'should accept a valid value' do @nova_config[:value] = 'bar' - @nova_config[:value].should == 'bar' + expect(@nova_config[:value]).to eq('bar') end it 'should not accept a value with whitespace' do @nova_config[:value] = 'b ar' - @nova_config[:value].should == 'b ar' + expect(@nova_config[:value]).to eq('b ar') end it 'should accept valid ensure values' do @nova_config[:ensure] = :present - @nova_config[:ensure].should == :present + expect(@nova_config[:ensure]).to eq(:present) @nova_config[:ensure] = :absent - @nova_config[:ensure].should == :absent + expect(@nova_config[:ensure]).to eq(:absent) end it 'should not accept invalid ensure values' do diff --git a/ntp/.travis.yml b/ntp/.travis.yml index cbf6f11df..7e8ed57bb 100644 --- a/ntp/.travis.yml +++ b/ntp/.travis.yml @@ -20,8 +20,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - rvm: 1.8.7 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/ntp/manifests/params.pp b/ntp/manifests/params.pp index cf9c01180..7a6d79c66 100644 --- a/ntp/manifests/params.pp +++ b/ntp/manifests/params.pp @@ -72,7 +72,7 @@ $driftfile = $default_driftfile $package_name = $default_package_name $restrict = [ - '-4 kod nomodify notrap nopeer noquery', + '-4 default kod nomodify notrap nopeer noquery', '-6 default kod nomodify notrap nopeer noquery', '127.0.0.1', '::1', diff --git a/ntp/spec/spec_helper_acceptance.rb b/ntp/spec/spec_helper_acceptance.rb index ac8a59cfd..643fadf80 100644 --- a/ntp/spec/spec_helper_acceptance.rb +++ b/ntp/spec/spec_helper_acceptance.rb @@ -5,7 +5,10 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = {:default_action => 'gem_install'} + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), + } if default.is_pe?; then install_pe; diff --git a/openstack_extras/.gitreview b/openstack_extras/.gitreview index 441ad434f..14d9f666e 100644 --- a/openstack_extras/.gitreview +++ b/openstack_extras/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-openstack_extras.git +project=openstack/puppet-openstack_extras.git diff --git a/openstack_extras/metadata.json b/openstack_extras/metadata.json index 4c36ba5b4..f87026ad6 100644 --- a/openstack_extras/metadata.json +++ b/openstack_extras/metadata.json @@ -31,6 +31,8 @@ ], "description": "Puppet module to add useful utilities for OpenStack deployments", "dependencies": [ - { "name": "puppetlabs/corosync", "version_requirement": ">=0.1.0" } + { "name": "puppetlabs/apt", "version_requirement": ">=1.8.0 <2.0.0" }, + { "name": "puppetlabs/corosync", "version_requirement": ">=0.1.0 <1.0.0" }, + { "name": "puppetlabs/stdlib", "version_requirement": ">=4.0.0 <5.0.0" } ] } diff --git a/openstacklib/.gitreview b/openstacklib/.gitreview index e248d7d95..aa396d062 100644 --- a/openstacklib/.gitreview +++ b/openstacklib/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-openstacklib.git +project=openstack/puppet-openstacklib.git diff --git a/openstacklib/Gemfile b/openstacklib/Gemfile index c160caceb..1fce4aa9f 100644 --- a/openstacklib/Gemfile +++ b/openstacklib/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'puppet-lint', '~> 1.1.0' gem 'metadata-json-lint' @@ -18,7 +17,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'mocha' gem 'json' end diff --git a/openstacklib/lib/puppet/provider/openstack.rb b/openstacklib/lib/puppet/provider/openstack.rb index 3dccba1a2..155e5b919 100644 --- a/openstacklib/lib/puppet/provider/openstack.rb +++ b/openstacklib/lib/puppet/provider/openstack.rb @@ -12,185 +12,73 @@ class Puppet::Provider::Openstack < Puppet::Provider initvars # so commands will work commands :openstack => 'openstack' - def request(service, action, object, credentials, *properties) - if password_credentials_set?(credentials) - auth_args = password_auth_args(credentials) - elsif openrc_set?(credentials) - credentials = get_credentials_from_openrc(credentials['openrc']) - auth_args = password_auth_args(credentials) - elsif service_credentials_set?(credentials) - auth_args = token_auth_args(credentials) - elsif env_vars_set? - # noop; auth needs no extra arguments - auth_args = nil - else # All authentication efforts failed - raise(Puppet::Error::OpenstackAuthInputError, 'No credentials provided.') - end - args = [object, properties, auth_args].flatten.compact - authenticate_request(service, action, args) - end - - def self.request(service, action, object, *properties) - if env_vars_set? - # noop; auth needs no extra arguments - auth_args = nil - else # All authentication efforts failed - raise(Puppet::Error::OpenstackAuthInputError, 'No credentials provided.') - end - args = [object, properties, auth_args].flatten.compact - authenticate_request(service, action, args) - end - # Returns an array of hashes, where the keys are the downcased CSV headers # with underscores instead of spaces - def self.authenticate_request(service, action, *args) - rv = nil - timeout = 10 - end_time = Time.now.to_i + timeout - loop do - begin - if(action == 'list') - response = openstack(service, action, '--quiet', '--format', 'csv', args) - response = parse_csv(response) - keys = response.delete_at(0) # ID,Name,Description,Enabled - rv = response.collect do |line| - hash = {} - keys.each_index do |index| - key = keys[index].downcase.gsub(/ /, '_').to_sym - hash[key] = line[index] + def self.request(service, action, properties, credentials=nil) + env = credentials ? credentials.to_env : {} + Puppet::Util.withenv(env) do + rv = nil + timeout = 10 + end_time = Time.now.to_i + timeout + loop do + begin + if(action == 'list') + response = openstack(service, action, '--quiet', '--format', 'csv', properties) + response = parse_csv(response) + keys = response.delete_at(0) # ID,Name,Description,Enabled + rv = response.collect do |line| + hash = {} + keys.each_index do |index| + key = keys[index].downcase.gsub(/ /, '_').to_sym + hash[key] = line[index] + end + hash + end + elsif(action == 'show' || action == 'create') + rv = {} + # shell output is name="value"\nid="value2"\ndescription="value3" etc. + openstack(service, action, '--format', 'shell', properties).split("\n").each do |line| + # key is everything before the first "=" + key, val = line.split("=", 2) + next unless val # Ignore warnings + # value is everything after the first "=", with leading and trailing double quotes stripped + val = val.gsub(/\A"|"\Z/, '') + rv[key.downcase.to_sym] = val end - hash - end - elsif(action == 'show' || action == 'create') - rv = {} - # shell output is name="value"\nid="value2"\ndescription="value3" etc. - openstack(service, action, '--format', 'shell', args).split("\n").each do |line| - # key is everything before the first "=" - key, val = line.split("=", 2) - next unless val # Ignore warnings - # value is everything after the first "=", with leading and trailing double quotes stripped - val = val.gsub(/\A"|"\Z/, '') - rv[key.downcase.to_sym] = val - end - else - rv = openstack(service, action, args) - end - break - rescue Puppet::ExecutionFailure => e - if e.message =~ /HTTP 401/ - raise(Puppet::Error::OpenstackUnauthorizedError, 'Could not authenticate.') - elsif e.message =~ /Unable to establish connection/ - current_time = Time.now.to_i - if current_time > end_time - break else - wait = end_time - current_time - Puppet::debug("Non-fatal error: \"#{e.message}\"; retrying for #{wait} more seconds.") - if wait > timeout - 2 # Only notice the first time - notice("#{service} service is unavailable. Will retry for up to #{wait} seconds.") + rv = openstack(service, action, properties) + end + break + rescue Puppet::ExecutionFailure => e + if e.message =~ /HTTP 401/ + raise(Puppet::Error::OpenstackUnauthorizedError, 'Could not authenticate.') + elsif e.message =~ /Unable to establish connection/ + current_time = Time.now.to_i + if current_time > end_time + break + else + wait = end_time - current_time + Puppet::debug("Non-fatal error: \"#{e.message}\"; retrying for #{wait} more seconds.") + if wait > timeout - 2 # Only notice the first time + notice("#{service} service is unavailable. Will retry for up to #{wait} seconds.") + end end + sleep(2) + else + raise e end - sleep(2) - else - raise e end end + return rv end - return rv - end - - def authenticate_request(service, action, *args) - self.class.authenticate_request(service, action, *args) end private - def password_credentials_set?(auth_params) - auth_params && auth_params['username'] && auth_params['password'] && auth_params['project_name'] && auth_params['auth_url'] - end - - def openrc_set?(auth_params) - auth_params && auth_params['openrc'] - end - - def service_credentials_set?(auth_params) - auth_params && auth_params['token'] && auth_params['url'] - end - - def self.env_vars_set? - ENV['OS_USERNAME'] && ENV['OS_PASSWORD'] && ENV['OS_PROJECT_NAME'] && ENV['OS_AUTH_URL'] - end - - def env_vars_set? - self.class.env_vars_set? - end - - def self.password_auth_args(credentials) - creds = [ '--os-username', credentials['username'], - '--os-password', credentials['password'], - '--os-project-name', credentials['project_name'], - '--os-auth-url', credentials['auth_url'] ] - - if credentials.include?('project_domain_name') - creds << '--os-project-domain-name' - creds << credentials['project_domain_name'] - end - - if credentials.include?('user_domain_name') - creds << '--os-user-domain-name' - creds << credentials['user_domain_name'] - end - - creds - end - - def password_auth_args(credentials) - self.class.password_auth_args(credentials) - end - - def self.token_auth_args(credentials) - args = [ '--os-token', credentials['token'], - '--os-url', credentials['url'] ] - # Add the api version only if requested by the caller - if credentials['version'] - args << [ '--os-identity-api-version', credentials['version'] ] - end - args - end - - def token_auth_args(credentials) - self.class.token_auth_args(credentials) - end - - def get_credentials_from_openrc(file) - creds = {} - File.open(file).readlines.delete_if{|l| l=~ /^#/}.each do |line| - key, value = line.split('=') - key = key.split(' ').last.downcase.sub(/^os_/, '') - value = value.chomp.gsub(/'/, '') - creds[key] = value - end - return creds - end - - def self.get_credentials_from_env - env = ENV.to_hash.dup.delete_if { |key, _| ! (key =~ /^OS_/) } - credentials = {} - env.each do |name, value| - credentials[name.downcase.sub(/^os_/, '')] = value - end - credentials - end - - def get_credentials_from_env - self.class.get_credentials_from_env - end - def self.parse_csv(text) # Ignore warnings - assume legitimate output starts with a double quoted # string. Errors will be caught and raised prior to this text = text.split("\n").drop_while { |line| line !~ /^\".*\"/ }.join("\n") return CSV.parse(text + "\n") end - end diff --git a/openstacklib/lib/puppet/provider/openstack/auth.rb b/openstacklib/lib/puppet/provider/openstack/auth.rb new file mode 100644 index 000000000..93a054ee0 --- /dev/null +++ b/openstacklib/lib/puppet/provider/openstack/auth.rb @@ -0,0 +1,49 @@ +require 'puppet/provider/openstack/credentials' + +module Puppet::Provider::Openstack::Auth + + RCFILENAME = "#{ENV['HOME']}/openrc" + + def get_os_vars_from_env + env = {} + ENV.each { |k,v| env.merge!(k => v) if k =~ /^OS_/ } + return env + end + + def get_os_vars_from_rcfile(filename) + env = {} + if File.exists?(filename) + File.open(filename).readlines.delete_if{|l| l=~ /^#|^$/ }.each do |line| + key, value = line.split('=') + key = key.split(' ').last + value = value.chomp.gsub(/'/, '') + env.merge!(key => value) if key =~ /OS_/ + end + end + return env + end + + def rc_filename + RCFILENAME + end + + def request(service, action, properties=nil) + properties ||= [] + set_credentials(@credentials, get_os_vars_from_env) + unless @credentials.set? + @credentials.unset + set_credentials(@credentials, get_os_vars_from_rcfile(rc_filename)) + end + unless @credentials.set? + raise(Puppet::Error::OpenstackAuthInputError, 'Insufficient credentials to authenticate') + end + super(service, action, properties, @credentials) + end + + def set_credentials(creds, env) + env.each do |key, val| + var = key.sub(/^OS_/,'').downcase + creds.set(var, val) + end + end +end diff --git a/openstacklib/lib/puppet/provider/openstack/credentials.rb b/openstacklib/lib/puppet/provider/openstack/credentials.rb new file mode 100644 index 000000000..5337671e1 --- /dev/null +++ b/openstacklib/lib/puppet/provider/openstack/credentials.rb @@ -0,0 +1,89 @@ +require 'puppet' +require 'puppet/provider/openstack' + +class Puppet::Provider::Openstack::Credentials + + KEYS = [ + :auth_url, :password, :project_name, :username, + :token, :url, + :identity_api_version + ] + + KEYS.each { |var| attr_accessor var } + + def self.defined?(name) + KEYS.include?(name.to_sym) + end + + def set(key, val) + if self.class.defined?(key.to_sym) + self.instance_variable_set("@#{key}".to_sym, val) + end + end + + def set? + return true if user_password_set? || service_token_set? + end + + def service_token_set? + return true if @token && @url + end + + def to_env + env = {} + self.instance_variables.each do |var| + name = var.to_s.sub(/^@/,'OS_').upcase + env.merge!(name => self.instance_variable_get(var)) + end + env + end + + def user_password_set? + return true if @username && @password && @project_name && @auth_url + end + + def unset + list = KEYS.delete_if { |key, val| key == :identity_api_version } + list.each { |key, val| self.set(key, '') if self.class.defined?("@#{key}".to_sym) } + end + + def version + self.class.to_s.sub(/.*V/,'').sub('_','.') + end +end + +class Puppet::Provider::Openstack::CredentialsV2_0 < Puppet::Provider::Openstack::Credentials +end + +class Puppet::Provider::Openstack::CredentialsV3 < Puppet::Provider::Openstack::Credentials + + KEYS = [ + :cacert, + :cert, + :default_domain, + :domain_id, + :domain_name, + :key, + :project_domain_id, + :project_domain_name, + :project_id, + :trust_id, + :user_domain_id, + :user_domain_name, + :user_id + ] + + KEYS.each { |var| attr_accessor var } + + def self.defined?(name) + KEYS.include?(name.to_sym) || super + end + + def user_password_set? + return true if (@username || @user_id) && @password && (@project_name || @project_id) && @auth_url + end + + def initialize + set(:identity_api_version, version) + end +end diff --git a/openstacklib/lib/puppet/util/openstack.rb b/openstacklib/lib/puppet/util/openstack.rb deleted file mode 100644 index 916aa8e16..000000000 --- a/openstacklib/lib/puppet/util/openstack.rb +++ /dev/null @@ -1,66 +0,0 @@ -# Add the auth parameter to whatever type is given -module Puppet::Util::Openstack - def self.add_openstack_type_methods(type, comment) - - type.newparam(:auth) do - - desc < { - 'username' => 'test', - 'password' => 'changeme', - 'project_name' => 'test', - 'auth_url' => 'http://localhost:35357/v2.0' -} - -or altenatively for Keystone API V3: -auth => { - 'username' => 'test', - 'password' => 'changeme', - 'project_name' => 'test', - 'project_domain_name' => 'domain1', - 'user_domain_name' => 'domain1', - 'auth_url' => 'http://localhost:35357/v3' -} - -2. Using a path to an openrc file containing these credentials - -auth => { - 'openrc' => '/root/openrc' -} - -3. Using a service token - -For Keystone API V2: -auth => { - 'token' => 'example', - 'url' => 'http://localhost:35357/v2.0' -} - -Alternatively for Keystone API V3: -auth => { - 'token' => 'example', - 'url' => 'http://localhost:35357/v3.0' -} - -If not present, the provider will look for environment variables for -password credentials. - -#{comment} -EOT - - validate do |value| - raise(Puppet::Error, 'This property must be a hash') unless value.is_a?(Hash) - end - end - - type.autorequire(:package) do - 'python-openstackclient' - end - - end -end diff --git a/openstacklib/spec/acceptance/mysql_spec.rb b/openstacklib/spec/acceptance/mysql_spec.rb index 590a17a64..00889718f 100644 --- a/openstacklib/spec/acceptance/mysql_spec.rb +++ b/openstacklib/spec/acceptance/mysql_spec.rb @@ -25,8 +25,10 @@ class { '::mysql::server': } it { is_expected.to be_listening.with('tcp') } end - describe command("mysql -e 'show databases;' | grep -q beaker") do - it { should return_exit_status 0 } + describe 'test database listing' do + it 'should list beaker database' do + expect(shell("mysql -e 'show databases;'|grep -q beaker").exit_code).to be_zero + end end end diff --git a/openstacklib/spec/acceptance/nodesets/nodepool-centos7.yml b/openstacklib/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/openstacklib/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/openstacklib/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/openstacklib/spec/acceptance/nodesets/nodepool-trusty.yml b/openstacklib/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/openstacklib/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/openstacklib/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/openstacklib/spec/acceptance/rabbitmq_spec.rb b/openstacklib/spec/acceptance/rabbitmq_spec.rb index 4b82b8222..7f7277103 100644 --- a/openstacklib/spec/acceptance/rabbitmq_spec.rb +++ b/openstacklib/spec/acceptance/rabbitmq_spec.rb @@ -47,13 +47,19 @@ class { '::rabbitmq': apply_manifest(pp, :catch_changes => true) end - describe command("rabbitmqctl list_users") do - it { should return_stdout /^beaker/ } - it { should_not return_stdout /^guest/ } - end + describe 'test rabbitmq resources' do + it 'should list rabbitmq beaker resources' do + shell('rabbitmqctl list_users') do |r| + expect(r.stdout).to match(/^beaker/) + expect(r.stdout).not_to match(/^guest/) + expect(r.exit_code).to eq(0) + end - describe command('rabbitmqctl list_permissions') do - it { should return_stdout /^beaker\t\.\*\t\.\*\t\.\*$/ } + shell('rabbitmqctl list_permissions') do |r| + expect(r.stdout).to match(/^beaker\t\.\*\t\.\*\t\.\*$/) + expect(r.exit_code).to eq(0) + end + end end end diff --git a/openstacklib/spec/unit/provider/openstack/auth_spec.rb b/openstacklib/spec/unit/provider/openstack/auth_spec.rb new file mode 100644 index 000000000..77a8f2764 --- /dev/null +++ b/openstacklib/spec/unit/provider/openstack/auth_spec.rb @@ -0,0 +1,181 @@ +require 'puppet' +require 'spec_helper' +require 'puppet/provider/openstack' +require 'puppet/provider/openstack/auth' +require 'tempfile' + +class Puppet::Provider::Openstack::AuthTester < Puppet::Provider::Openstack + extend Puppet::Provider::Openstack::Auth +end + +klass = Puppet::Provider::Openstack::AuthTester + +describe Puppet::Provider::Openstack::Auth do + + let(:type) do + Puppet::Type.newtype(:test_resource) do + newparam(:name, :namevar => true) + newparam(:log_file) + end + end + + let(:resource_attrs) do + { + :name => 'stubresource' + } + end + + let(:provider) do + klass.new(type.new(resource_attrs)) + end + + before(:each) do + ENV['OS_USERNAME'] = nil + ENV['OS_PASSWORD'] = nil + ENV['OS_PROJECT_NAME'] = nil + ENV['OS_AUTH_URL'] = nil + ENV['OS_TOKEN'] = nil + ENV['OS_URL'] = nil + end + + describe '#set_credentials' do + it 'adds keys to the object' do + credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + set = { 'OS_USERNAME' => 'user', 'OS_PASSWORD' => 'secret', + 'OS_PROJECT_NAME' => 'tenant', + 'OS_AUTH_URL' => 'http://127.0.0.1:5000', + 'OS_TOKEN' => 'token', + 'OS_URL' => 'http://127.0.0.1:35357', + 'OS_IDENTITY_API_VERSION' => '2.0' + } + klass.set_credentials(credentials, set) + expect(credentials.to_env).to eq("OS_AUTH_URL" => "http://127.0.0.1:5000", + "OS_IDENTITY_API_VERSION" => '2.0', + "OS_PASSWORD" => "secret", + "OS_PROJECT_NAME" => "tenant", + "OS_TOKEN" => "token", + "OS_URL" => "http://127.0.0.1:35357", + "OS_USERNAME" => "user") + end + end + + describe '#rc_filename' do + it 'returns RCFILENAME' do + expect(klass.rc_filename).to eq("#{ENV['HOME']}/openrc") + end + end + + describe '#get_os_from_env' do + context 'with Openstack environment variables set' do + it 'provides a hash' do + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:5000' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_USERNAME'] = 'test' + response = klass.get_os_vars_from_env + expect(response).to eq({"OS_AUTH_URL" => "http://127.0.0.1:5000","OS_PASSWORD" => "abc123","OS_PROJECT_NAME" => "test","OS_USERNAME" => "test"}) + end + end + end + + describe '#get_os_vars_from_rcfile' do + context 'with a valid RC file' do + it 'provides a hash' do + mock = "export OS_USERNAME='test'\nexport OS_PASSWORD='abc123'\nexport OS_PROJECT_NAME='test'\nexport OS_AUTH_URL='http://127.0.0.1:5000'" + filename = 'file' + File.expects(:exists?).with('file').returns(true) + File.expects(:open).with('file').returns(StringIO.new(mock)) + + response = klass.get_os_vars_from_rcfile(filename) + expect(response).to eq({"OS_AUTH_URL" => "http://127.0.0.1:5000","OS_PASSWORD" => "abc123","OS_PROJECT_NAME" => "test","OS_USERNAME" => "test"}) + end + end + + context 'with an empty file' do + it 'provides an empty hash' do + filename = 'file' + File.expects(:exists?).with(filename).returns(true) + File.expects(:open).with(filename).returns(StringIO.new("")) + + response = klass.get_os_vars_from_rcfile(filename) + expect(response).to eq({}) + end + end + end + + before(:each) do + class Puppet::Provider::Openstack::AuthTester + @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + end + end + + describe '#request' do + context 'with no valid credentials' do + it 'fails to authenticate' do + expect { klass.request('project', 'list', ['--long']) }.to raise_error(Puppet::Error::OpenstackAuthInputError, "Insufficient credentials to authenticate") + end + end + + context 'with user credentials in env' do + it 'is successful' do + klass.expects(:get_os_vars_from_env) + .returns({ 'OS_USERNAME' => 'test', + 'OS_PASSWORD' => 'abc123', + 'OS_PROJECT_NAME' => 'test', + 'OS_AUTH_URL' => 'http://127.0.0.1:5000' }) + klass.expects(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', ['--long']) + .returns('"ID","Name","Description","Enabled" +"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True +') + response = klass.request('project', 'list', ['--long']) + expect(response.first[:description]).to eq("Test tenant") + end + end + + context 'with service token credentials in env' do + it 'is successful' do + klass.expects(:get_os_vars_from_env) + .returns({ 'OS_TOKEN' => 'test', + 'OS_URL' => 'http://127.0.0.1:5000' }) + klass.expects(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', ['--long']) + .returns('"ID","Name","Description","Enabled" +"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True +') + response = klass.request('project', 'list', ['--long']) + expect(response.first[:description]).to eq("Test tenant") + end + end + + context 'with a RC file containing user credentials' do + it 'is successful' do + mock = "export OS_USERNAME='test'\nexport OS_PASSWORD='abc123'\nexport OS_PROJECT_NAME='test'\nexport OS_AUTH_URL='http://127.0.0.1:5000'" + File.expects(:exists?).with("#{ENV['HOME']}/openrc").returns(true) + File.expects(:open).with("#{ENV['HOME']}/openrc").returns(StringIO.new(mock)) + klass.expects(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', ['--long']) + .returns('"ID","Name","Description","Enabled" +"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True +') + response = provider.class.request('project', 'list', ['--long']) + expect(response.first[:description]).to eq("Test tenant") + end + end + + context 'with a RC file containing service token credentials' do + it 'is successful' do + mock = "export OS_TOKEN='test'\nexport OS_URL='abc123'\n" + File.expects(:exists?).with("#{ENV['HOME']}/openrc").returns(true) + File.expects(:open).with("#{ENV['HOME']}/openrc").returns(StringIO.new(mock)) + klass.expects(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', ['--long']) + .returns('"ID","Name","Description","Enabled" +"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True +') + response = klass.request('project', 'list', ['--long']) + expect(response.first[:description]).to eq("Test tenant") + end + end + end +end diff --git a/openstacklib/spec/unit/provider/openstack/credentials_spec.rb b/openstacklib/spec/unit/provider/openstack/credentials_spec.rb new file mode 100644 index 000000000..2437f6656 --- /dev/null +++ b/openstacklib/spec/unit/provider/openstack/credentials_spec.rb @@ -0,0 +1,92 @@ +require 'puppet' +require 'spec_helper' +require 'puppet/provider/openstack' +require 'puppet/provider/openstack/credentials' + + +describe Puppet::Provider::Openstack::Credentials do + + let(:creds) do + creds = Puppet::Provider::Openstack::CredentialsV2_0.new + end + + describe '#service_token_set?' do + context "with service credentials" do + it 'is successful' do + creds.token = 'token' + creds.url = 'url' + expect(creds.service_token_set?).to be_truthy + end + end + end + + describe '#password_set?' do + context "with user credentials" do + it 'is successful' do + creds.auth_url = 'auth_url' + creds.password = 'password' + creds.project_name = 'project_name' + creds.username = 'username' + expect(creds.user_password_set?).to be_truthy + end + end + end + + describe '#set?' do + context "without any credential" do + it 'fails' do + expect(creds.set?).to be_falsey + end + end + end + + describe '#to_env' do + context "with an exhaustive data set" do + it 'successfully returns content' do + creds.auth_url = 'auth_url' + creds.password = 'password' + creds.project_name = 'project_name' + creds.username = 'username' + creds.token = 'token' + creds.url = 'url' + creds.identity_api_version = 'identity_api_version' + expect(creds.auth_url).to eq("auth_url") + expect(creds.password).to eq("password") + expect(creds.project_name).to eq("project_name") + expect(creds.username).to eq("username") + expect(creds.token).to eq('token') + expect(creds.url).to eq('url') + expect(creds.identity_api_version).to eq('identity_api_version') + end + end + end + + describe 'using v3' do + let(:creds) do + creds = Puppet::Provider::Openstack::CredentialsV3.new + end + describe 'with v3' do + it 'uses v3 identity api' do + creds.identity_api_version == '3' + end + end + describe '#password_set? with username and project_name' do + it 'is successful' do + creds.auth_url = 'auth_url' + creds.password = 'password' + creds.project_name = 'project_name' + creds.username = 'username' + expect(creds.user_password_set?).to be_truthy + end + end + describe '#password_set? with user_id and project_id' do + it 'is successful' do + creds.auth_url = 'auth_url' + creds.password = 'password' + creds.project_id = 'projid' + creds.user_id = 'userid' + expect(creds.user_password_set?).to be_truthy + end + end + end +end diff --git a/openstacklib/spec/unit/provider/openstack_spec.rb b/openstacklib/spec/unit/provider/openstack_spec.rb index 5ae7dafde..c9c22eed5 100644 --- a/openstacklib/spec/unit/provider/openstack_spec.rb +++ b/openstacklib/spec/unit/provider/openstack_spec.rb @@ -1,12 +1,8 @@ -# Load libraries from aviator here to simulate how they live together in a real puppet run -$LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'modules', 'aviator', 'lib')) require 'puppet' require 'spec_helper' require 'puppet/provider/openstack' - describe Puppet::Provider::Openstack do - before(:each) do ENV['OS_USERNAME'] = nil ENV['OS_PASSWORD'] = nil @@ -17,237 +13,46 @@ let(:type) do Puppet::Type.newtype(:test_resource) do newparam(:name, :namevar => true) - newparam(:auth) newparam(:log_file) end end - shared_examples 'authenticating with environment variables using API v2' do - it 'makes a successful request' do - ENV['OS_USERNAME'] = 'test' - ENV['OS_PASSWORD'] = 'abc123' - ENV['OS_PROJECT_NAME'] = 'test' - ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v2.0' - if provider.class == Class - provider.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [[ '--long' ]]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True -') - else - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [[ '--long' ]]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True -') - end - response = provider.request('project', 'list', nil, nil, '--long' ) - expect(response.first[:description]).to match /Test tenant/ - end - end - - shared_examples 'authenticating with environment variables using API v3' do - it 'makes a successful request' do - ENV['OS_USERNAME'] = 'test' - ENV['OS_PASSWORD'] = 'abc123' - ENV['OS_PROJECT_NAME'] = 'test' - ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v3' - if provider.class == Class - provider.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [[ '--long' ]]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True -') - else - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [[ '--long' ]]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True -') - end - response = provider.request('project', 'list', nil, nil, '--long' ) - expect(response.first[:description]).to match /Test tenant/ - end - end - - shared_examples 'it has no credentials' do - it 'fails to authenticate' do - expect{ provider.request('project', 'list', nil, nil, '--long') }.to raise_error(Puppet::Error::OpenstackAuthInputError, /No credentials provided/) - end - end - describe '#request' do - - context 'with valid password credentials in parameters' do - let(:resource_attrs) do - { - :name => 'stubresource', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'test', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } - } - end - let(:provider) do - Puppet::Provider::Openstack.new(type.new(resource_attrs)) - end - - it 'makes a successful request' do - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'test', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True -') - response = provider.request('project', 'list', nil, resource_attrs[:auth], '--long') - expect(response.first[:description]).to match /Test tenant/ - end + let(:resource_attrs) do + { + :name => 'stubresource', + } end - context 'with valid openrc file in parameters' do - mock = "export OS_USERNAME='test'\nexport OS_PASSWORD='abc123'\nexport OS_PROJECT_NAME='test'\nexport OS_AUTH_URL='http://127.0.0.1:5000/v2.0'" - let(:resource_attrs) do - { - :name => 'stubresource', - :auth => { - 'openrc' => '/root/openrc' - } - } - end - let(:provider) do - Puppet::Provider::Openstack.new(type.new(resource_attrs)) - end - - it 'makes a successful request' do - File.expects(:open).with('/root/openrc').returns(StringIO.new(mock)) - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'test', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) - .returns('"ID","Name","Description","Enabled" -"1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True -') - response = provider.request('project', 'list', nil, resource_attrs[:auth], '--long') - expect(response.first[:description]).to match /Test tenant/ - end + let(:provider) do + Puppet::Provider::Openstack.new(type.new(resource_attrs)) end - context 'with valid service token in parameters' do - let(:resource_attrs) do - { - :name => 'stubresource', - :auth => { - 'token' => 'secrettoken', - 'url' => 'http://127.0.0.1:5000/v3', - 'version' => '3' - } - } - end - let(:provider) do - Puppet::Provider::Openstack.new(type.new(resource_attrs)) - end - - it 'makes a successful request' do - provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-token', 'secrettoken', '--os-url', 'http://127.0.0.1:5000/v3', '--os-identity-api-version', '3']]) - .returns('"ID","Name","Description","Enabled" + it 'makes a successful request' do + provider.class.stubs(:openstack) + .with('project', 'list', '--quiet', '--format', 'csv', ['--long']) + .returns('"ID","Name","Description","Enabled" "1cb05cfed7c24279be884ba4f6520262","test","Test tenant",True ') - response = provider.request('project', 'list', nil, resource_attrs[:auth], '--long') - expect(response.first[:description]).to match /Test tenant/ - end - - it 'makes a successful show request' do - provider.class.stubs(:openstack) - .with('project', 'show', '--format', 'shell', [['test', '--os-token', 'secrettoken', '--os-url', 'http://127.0.0.1:5000/v3', '--os-identity-api-version', '3']]) - .returns('ID="1cb05cfed7c24279be884ba4f6520262" -Name="test" -Description="Test Tenant" -Enabled="True" -') - response = provider.request('project', 'show', 'test', resource_attrs[:auth]) - expect(response[:description]).to match /Test Tenant/ - expect(response[:id]).to match /1cb05cfed7c24279be884ba4f6520262/ - expect(response[:name]).to match /test/ - expect(response[:enabled]).to match /True/ - end - - end - - context 'with valid password credentials in environment variables' do - it_behaves_like 'authenticating with environment variables using API v2' do - let(:resource_attrs) do - { - :name => 'stubresource', - } - end - let(:provider) do - Puppet::Provider::Openstack.new(type.new(resource_attrs)) - end - end - end - - context 'with no valid credentials' do - it_behaves_like 'it has no credentials' do - let(:resource_attrs) do - { - :name => 'stubresource', - } - end - let(:provider) do - Puppet::Provider::Openstack.new(type.new(resource_attrs)) - end - end + response = Puppet::Provider::Openstack.request('project', 'list', ['--long']) + expect(response.first[:description]).to eq("Test tenant") end - context 'it retries on connection errors' do - let(:resource_attrs) do - { - :name => 'stubresource', - :auth => { - 'username' => 'test', - 'password' => 'abc123', - 'project_name' => 'test', - 'auth_url' => 'http://127.0.0.1:5000/v2.0', - } - } - end - let(:provider) do - Puppet::Provider::Openstack.new(type.new(resource_attrs)) - end + context 'on connection errors' do it 'retries' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:5000' provider.class.stubs(:openstack) - .with('project', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-project-name', 'test', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']]) + .with('project', 'list', '--quiet', '--format', 'csv', ['--long']) .raises(Puppet::ExecutionFailure, 'Unable to establish connection') .then .returns('') provider.class.expects(:sleep).with(2).returns(nil) - provider.request('project', 'list', nil, resource_attrs[:auth], '--long') - end - end - end - - - describe '::request' do - - context 'with valid password credentials in environment variables' do - it_behaves_like 'authenticating with environment variables using API v2' do - let(:resource_attrs) do - { - :name => 'stubresource', - } - end - let(:provider) do - Puppet::Provider::Openstack.dup - end + Puppet::Provider::Openstack.request('project', 'list', ['--long']) end end - - context 'with no valid credentials' do - it_behaves_like 'it has no credentials' do - let(:provider) { Puppet::Provider::Openstack.dup } - end - end - end describe 'parse_csv' do @@ -281,5 +86,4 @@ end end end - end diff --git a/pacemaker/agent_generator/agent_generator.rb b/pacemaker/agent_generator/agent_generator.rb index 96196263f..f3c5b536b 100755 --- a/pacemaker/agent_generator/agent_generator.rb +++ b/pacemaker/agent_generator/agent_generator.rb @@ -56,35 +56,39 @@ def generate puts <<-eos # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::#{@parser.getAgentName} ( +define pacemaker::stonith::#{@parser.getAgentName} ( #{getManifestParameters} ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" +#{getVariableValues} + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::#{@parser.getAgentName}": - command => "/usr/sbin/pcs stonith delete stonith-#{@parser.getAgentName}-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-#{@parser.getAgentName}-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-#{@parser.getAgentName}-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-#{@parser.getAgentName}-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-#{@parser.getAgentName}-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - #{getVariableValues} - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "#{@parser.getPackageName}": ensure => installed, - } -> exec { - "Creating stonith::#{@parser.getAgentName}": - command => "/usr/sbin/pcs stonith create stonith-#{@parser.getAgentName}-${real_address} #{@parser.getAgentName} pcmk_host_list=\\"${pcmk_host_value_chunk}\\" #{getChunks} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-#{@parser.getAgentName}-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-#{@parser.getAgentName}-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-#{@parser.getAgentName}-${safe_title} #{@parser.getAgentName} pcmk_host_list=\\"${pcmk_host_value_chunk}\\" #{getChunks} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-#{@parser.getAgentName}-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::#{@parser.getAgentName} ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-#{@parser.getAgentName}-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-#{@parser.getAgentName}-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-#{@parser.getAgentName}-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } @@ -94,13 +98,16 @@ class pacemaker::stonith::#{@parser.getAgentName} ( def getManifestParameters text = "" @parser.getParameters.each { |p| - text += "\t$#{p['name']} = undef,\n" + text += " $#{p['name']} = undef,\n" } text += "\n" - text += "\t$interval = \"60s\",\n" - text += "\t$ensure = present,\n" - text += "\t$pcmk_host_value = undef,\n" + text += " $interval = \"60s\",\n" + text += " $ensure = present,\n" + text += " $pcmk_host_list = undef,\n" + text += "\n" + text += " $tries = undef,\n" + text += " $try_sleep = undef," return text end @@ -108,10 +115,10 @@ def getManifestParameters def getVariableValues text = "" @parser.getParameters.each { |p| - text += "\t$#{p['name']}_chunk = $#{p['name']} ? {\n" - text += "\t\tundef => \"\",\n" - text += "\t\tdefault => \"#{p['name']}=\\\"${#{p['name']}}\\\"\",\n" - text += "\t}\n" + text += " $#{p['name']}_chunk = $#{p['name']} ? {\n" + text += " undef => \"\",\n" + text += " default => \"#{p['name']}=\\\"${#{p['name']}}\\\"\",\n" + text += " }\n" } return text diff --git a/pacemaker/agent_generator/src_xml/fence_xvm.xml b/pacemaker/agent_generator/src_xml/fence_xvm.xml new file mode 100644 index 000000000..15d00e607 --- /dev/null +++ b/pacemaker/agent_generator/src_xml/fence_xvm.xml @@ -0,0 +1,86 @@ + + +fence_xvm is an I/O Fencing agent which can be used withvirtual machines. + + + + + Specify (stdin) or increment (command line) debug level + + + + + IP Family ([auto], ipv4, ipv6) + + + + + Multicast address (default=225.0.0.12 / ff05::3:1) + + + + + TCP, Multicast, or VMChannel IP port (default=1229) + + + + + Multicast retransmit time (in 1/10sec; default=20) + + + + + Authentication (none, sha1, [sha256], sha512) + + + + + Packet hash strength (none, sha1, [sha256], sha512) + + + + + Shared key file (default=/etc/cluster/fence_xvm.key) + + + + + Virtual Machine (domain name) to fence + + + + + Treat [domain] as UUID instead of domain name. This is provided for compatibility with older fence_xvmd installations. + + + + + Fencing action (null, off, on, [reboot], status, list, monitor, metadata) + + + + + Fencing timeout (in seconds; default=30) + + + + + Fencing delay (in seconds; default=0) + + + + + Virtual Machine (domain name) to fence (deprecated; use port) + + + + + + + + + + + + + diff --git a/pacemaker/agent_generator/variables.sh b/pacemaker/agent_generator/variables.sh index a6e38a029..247e941ed 100644 --- a/pacemaker/agent_generator/variables.sh +++ b/pacemaker/agent_generator/variables.sh @@ -30,6 +30,7 @@ cmd_pkg_map=( "fence_virt:fence-virt" "fence_vmware_soap:fence-agents-vmware-soap" "fence_wti:fence-agents-wti" - # not generating fence_xvm for now, it would overwrite the existing one + + # These have manual changes and need to be updated manually: # "fence_xvm:fence-virt" ) diff --git a/pacemaker/manifests/stonith/fence_apc.pp b/pacemaker/manifests/stonith/fence_apc.pp index 13f6b6663..8229e6931 100644 --- a/pacemaker/manifests/stonith/fence_apc.pp +++ b/pacemaker/manifests/stonith/fence_apc.pp @@ -1,148 +1,154 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_apc ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $cmd_prompt = undef, - $secure = undef, - $port = undef, - $switch = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_apc ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $cmd_prompt = undef, + $secure = undef, + $port = undef, + $switch = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $switch_chunk = $switch ? { + undef => "", + default => "switch=\"${switch}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_apc": - command => "/usr/sbin/pcs stonith delete stonith-fence_apc-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_apc-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_apc-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_apc-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_apc-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $switch_chunk = $switch ? { - undef => "", - default => "switch=\"${switch}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-apc": ensure => installed, - } -> exec { - "Creating stonith::fence_apc": - command => "/usr/sbin/pcs stonith create stonith-fence_apc-${real_address} fence_apc pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${switch_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_apc-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_apc-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_apc-${safe_title} fence_apc pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${switch_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_apc-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_apc ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_apc-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_apc-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_apc-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_apc_snmp.pp b/pacemaker/manifests/stonith/fence_apc_snmp.pp index fd1a508b1..959519e1e 100644 --- a/pacemaker/manifests/stonith/fence_apc_snmp.pp +++ b/pacemaker/manifests/stonith/fence_apc_snmp.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_apc_snmp ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_apc_snmp ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_apc_snmp": - command => "/usr/sbin/pcs stonith delete stonith-fence_apc_snmp-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_apc_snmp-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_apc_snmp-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_apc_snmp-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_apc_snmp-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-apc-snmp": ensure => installed, - } -> exec { - "Creating stonith::fence_apc_snmp": - command => "/usr/sbin/pcs stonith create stonith-fence_apc_snmp-${real_address} fence_apc_snmp pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_apc_snmp-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_apc_snmp-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_apc_snmp-${safe_title} fence_apc_snmp pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_apc_snmp-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_apc_snmp ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_apc_snmp-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_apc_snmp-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_apc_snmp-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_bladecenter.pp b/pacemaker/manifests/stonith/fence_bladecenter.pp index 175e25dfc..415b5cc54 100644 --- a/pacemaker/manifests/stonith/fence_bladecenter.pp +++ b/pacemaker/manifests/stonith/fence_bladecenter.pp @@ -1,148 +1,154 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_bladecenter ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $cmd_prompt = undef, - $secure = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $missing_as_off = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_bladecenter ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $cmd_prompt = undef, + $secure = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $missing_as_off = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $missing_as_off_chunk = $missing_as_off ? { + undef => "", + default => "missing_as_off=\"${missing_as_off}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_bladecenter": - command => "/usr/sbin/pcs stonith delete stonith-fence_bladecenter-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_bladecenter-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_bladecenter-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_bladecenter-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_bladecenter-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $missing_as_off_chunk = $missing_as_off ? { - undef => "", - default => "missing_as_off=\"${missing_as_off}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-bladecenter": ensure => installed, - } -> exec { - "Creating stonith::fence_bladecenter": - command => "/usr/sbin/pcs stonith create stonith-fence_bladecenter-${real_address} fence_bladecenter pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${missing_as_off_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_bladecenter-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_bladecenter-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_bladecenter-${safe_title} fence_bladecenter pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${missing_as_off_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_bladecenter-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_bladecenter ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_bladecenter-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_bladecenter-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_bladecenter-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_brocade.pp b/pacemaker/manifests/stonith/fence_brocade.pp index d06dc8712..b30b70b58 100644 --- a/pacemaker/manifests/stonith/fence_brocade.pp +++ b/pacemaker/manifests/stonith/fence_brocade.pp @@ -1,143 +1,149 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_brocade ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $cmd_prompt = undef, - $secure = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_brocade ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $cmd_prompt = undef, + $secure = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_brocade": - command => "/usr/sbin/pcs stonith delete stonith-fence_brocade-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_brocade-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_brocade-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_brocade-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_brocade-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-brocade": ensure => installed, - } -> exec { - "Creating stonith::fence_brocade": - command => "/usr/sbin/pcs stonith create stonith-fence_brocade-${real_address} fence_brocade pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_brocade-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_brocade-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_brocade-${safe_title} fence_brocade pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_brocade-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_brocade ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_brocade-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_brocade-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_brocade-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_cisco_mds.pp b/pacemaker/manifests/stonith/fence_cisco_mds.pp index eab35940f..a914bbd6b 100644 --- a/pacemaker/manifests/stonith/fence_cisco_mds.pp +++ b/pacemaker/manifests/stonith/fence_cisco_mds.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_cisco_mds ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_cisco_mds ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_cisco_mds": - command => "/usr/sbin/pcs stonith delete stonith-fence_cisco_mds-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_cisco_mds-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_cisco_mds-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_cisco_mds-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_cisco_mds-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-cisco-mds": ensure => installed, - } -> exec { - "Creating stonith::fence_cisco_mds": - command => "/usr/sbin/pcs stonith create stonith-fence_cisco_mds-${real_address} fence_cisco_mds pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_cisco_mds-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_cisco_mds-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_cisco_mds-${safe_title} fence_cisco_mds pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_cisco_mds-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_cisco_mds ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_cisco_mds-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_cisco_mds-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_cisco_mds-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_cisco_ucs.pp b/pacemaker/manifests/stonith/fence_cisco_ucs.pp index 0acb7a49e..cff71744d 100644 --- a/pacemaker/manifests/stonith/fence_cisco_ucs.pp +++ b/pacemaker/manifests/stonith/fence_cisco_ucs.pp @@ -1,148 +1,154 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_cisco_ucs ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $ssl = undef, - $notls = undef, - $port = undef, - $suborg = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $ssl_secure = undef, - $ssl_insecure = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_cisco_ucs ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $ssl = undef, + $notls = undef, + $port = undef, + $suborg = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $ssl_secure = undef, + $ssl_insecure = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $ssl_chunk = $ssl ? { + undef => "", + default => "ssl=\"${ssl}\"", + } + $notls_chunk = $notls ? { + undef => "", + default => "notls=\"${notls}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $suborg_chunk = $suborg ? { + undef => "", + default => "suborg=\"${suborg}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $ssl_secure_chunk = $ssl_secure ? { + undef => "", + default => "ssl_secure=\"${ssl_secure}\"", + } + $ssl_insecure_chunk = $ssl_insecure ? { + undef => "", + default => "ssl_insecure=\"${ssl_insecure}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_cisco_ucs": - command => "/usr/sbin/pcs stonith delete stonith-fence_cisco_ucs-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_cisco_ucs-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_cisco_ucs-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_cisco_ucs-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_cisco_ucs-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $ssl_chunk = $ssl ? { - undef => "", - default => "ssl=\"${ssl}\"", - } - $notls_chunk = $notls ? { - undef => "", - default => "notls=\"${notls}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $suborg_chunk = $suborg ? { - undef => "", - default => "suborg=\"${suborg}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $ssl_secure_chunk = $ssl_secure ? { - undef => "", - default => "ssl_secure=\"${ssl_secure}\"", - } - $ssl_insecure_chunk = $ssl_insecure ? { - undef => "", - default => "ssl_insecure=\"${ssl_insecure}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-cisco-ucs": ensure => installed, - } -> exec { - "Creating stonith::fence_cisco_ucs": - command => "/usr/sbin/pcs stonith create stonith-fence_cisco_ucs-${real_address} fence_cisco_ucs pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${port_chunk} ${suborg_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_cisco_ucs-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_cisco_ucs-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_cisco_ucs-${safe_title} fence_cisco_ucs pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${port_chunk} ${suborg_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_cisco_ucs-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_cisco_ucs ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_cisco_ucs-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_cisco_ucs-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_cisco_ucs-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_drac5.pp b/pacemaker/manifests/stonith/fence_drac5.pp index 6e3f54d63..8fdf9e7f1 100644 --- a/pacemaker/manifests/stonith/fence_drac5.pp +++ b/pacemaker/manifests/stonith/fence_drac5.pp @@ -1,148 +1,154 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_drac5 ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $cmd_prompt = undef, - $secure = undef, - $drac_version = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_drac5 ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $cmd_prompt = undef, + $secure = undef, + $drac_version = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $drac_version_chunk = $drac_version ? { + undef => "", + default => "drac_version=\"${drac_version}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_drac5": - command => "/usr/sbin/pcs stonith delete stonith-fence_drac5-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_drac5-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_drac5-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_drac5-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_drac5-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $drac_version_chunk = $drac_version ? { - undef => "", - default => "drac_version=\"${drac_version}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-drac5": ensure => installed, - } -> exec { - "Creating stonith::fence_drac5": - command => "/usr/sbin/pcs stonith create stonith-fence_drac5-${real_address} fence_drac5 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${drac_version_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_drac5-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_drac5-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_drac5-${safe_title} fence_drac5 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${drac_version_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_drac5-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_drac5 ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_drac5-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_drac5-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_drac5-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_eaton_snmp.pp b/pacemaker/manifests/stonith/fence_eaton_snmp.pp index 826d2e357..036e97558 100644 --- a/pacemaker/manifests/stonith/fence_eaton_snmp.pp +++ b/pacemaker/manifests/stonith/fence_eaton_snmp.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_eaton_snmp ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_eaton_snmp ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_eaton_snmp": - command => "/usr/sbin/pcs stonith delete stonith-fence_eaton_snmp-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_eaton_snmp-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_eaton_snmp-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_eaton_snmp-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_eaton_snmp-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-eaton-snmp": ensure => installed, - } -> exec { - "Creating stonith::fence_eaton_snmp": - command => "/usr/sbin/pcs stonith create stonith-fence_eaton_snmp-${real_address} fence_eaton_snmp pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_eaton_snmp-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_eaton_snmp-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_eaton_snmp-${safe_title} fence_eaton_snmp pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_eaton_snmp-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_eaton_snmp ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_eaton_snmp-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_eaton_snmp-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_eaton_snmp-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_eps.pp b/pacemaker/manifests/stonith/fence_eps.pp index f25d9b298..aea36acc9 100644 --- a/pacemaker/manifests/stonith/fence_eps.pp +++ b/pacemaker/manifests/stonith/fence_eps.pp @@ -1,128 +1,134 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_eps ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $hidden_page = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_eps ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $hidden_page = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $hidden_page_chunk = $hidden_page ? { + undef => "", + default => "hidden_page=\"${hidden_page}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_eps": - command => "/usr/sbin/pcs stonith delete stonith-fence_eps-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_eps-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_eps-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_eps-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_eps-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $hidden_page_chunk = $hidden_page ? { - undef => "", - default => "hidden_page=\"${hidden_page}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-eps": ensure => installed, - } -> exec { - "Creating stonith::fence_eps": - command => "/usr/sbin/pcs stonith create stonith-fence_eps-${real_address} fence_eps pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${hidden_page_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_eps-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_eps-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_eps-${safe_title} fence_eps pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${hidden_page_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_eps-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_eps ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_eps-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_eps-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_eps-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_hpblade.pp b/pacemaker/manifests/stonith/fence_hpblade.pp index de9f42bf8..4eef367d7 100644 --- a/pacemaker/manifests/stonith/fence_hpblade.pp +++ b/pacemaker/manifests/stonith/fence_hpblade.pp @@ -1,148 +1,154 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_hpblade ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $cmd_prompt = undef, - $secure = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $missing_as_off = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_hpblade ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $cmd_prompt = undef, + $secure = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $missing_as_off = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $missing_as_off_chunk = $missing_as_off ? { + undef => "", + default => "missing_as_off=\"${missing_as_off}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_hpblade": - command => "/usr/sbin/pcs stonith delete stonith-fence_hpblade-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_hpblade-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_hpblade-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_hpblade-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_hpblade-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $missing_as_off_chunk = $missing_as_off ? { - undef => "", - default => "missing_as_off=\"${missing_as_off}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-hpblade": ensure => installed, - } -> exec { - "Creating stonith::fence_hpblade": - command => "/usr/sbin/pcs stonith create stonith-fence_hpblade-${real_address} fence_hpblade pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${missing_as_off_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_hpblade-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_hpblade-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_hpblade-${safe_title} fence_hpblade pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${missing_as_off_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_hpblade-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_hpblade ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_hpblade-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_hpblade-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_hpblade-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ibmblade.pp b/pacemaker/manifests/stonith/fence_ibmblade.pp index f72cedc36..13dfe31de 100644 --- a/pacemaker/manifests/stonith/fence_ibmblade.pp +++ b/pacemaker/manifests/stonith/fence_ibmblade.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ibmblade ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_ibmblade ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ibmblade": - command => "/usr/sbin/pcs stonith delete stonith-fence_ibmblade-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ibmblade-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ibmblade-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ibmblade-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ibmblade-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ibmblade": ensure => installed, - } -> exec { - "Creating stonith::fence_ibmblade": - command => "/usr/sbin/pcs stonith create stonith-fence_ibmblade-${real_address} fence_ibmblade pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ibmblade-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ibmblade-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ibmblade-${safe_title} fence_ibmblade pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ibmblade-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ibmblade ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ibmblade-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ibmblade-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ibmblade-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_idrac.pp b/pacemaker/manifests/stonith/fence_idrac.pp index dce567db2..438c8a84f 100644 --- a/pacemaker/manifests/stonith/fence_idrac.pp +++ b/pacemaker/manifests/stonith/fence_idrac.pp @@ -1,103 +1,109 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_idrac ( - $auth = undef, - $ipaddr = undef, - $passwd = undef, - $passwd_script = undef, - $lanplus = undef, - $login = undef, - $timeout = undef, - $cipher = undef, - $method = undef, - $power_wait = undef, - $delay = undef, - $privlvl = undef, - $verbose = undef, +define pacemaker::stonith::fence_idrac ( + $auth = undef, + $ipaddr = undef, + $passwd = undef, + $passwd_script = undef, + $lanplus = undef, + $login = undef, + $timeout = undef, + $cipher = undef, + $method = undef, + $power_wait = undef, + $delay = undef, + $privlvl = undef, + $verbose = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $auth_chunk = $auth ? { + undef => "", + default => "auth=\"${auth}\"", + } + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $lanplus_chunk = $lanplus ? { + undef => "", + default => "lanplus=\"${lanplus}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $cipher_chunk = $cipher ? { + undef => "", + default => "cipher=\"${cipher}\"", + } + $method_chunk = $method ? { + undef => "", + default => "method=\"${method}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $privlvl_chunk = $privlvl ? { + undef => "", + default => "privlvl=\"${privlvl}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_idrac": - command => "/usr/sbin/pcs stonith delete stonith-fence_idrac-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_idrac-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_idrac-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_idrac-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_idrac-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $auth_chunk = $auth ? { - undef => "", - default => "auth=\"${auth}\"", - } - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $lanplus_chunk = $lanplus ? { - undef => "", - default => "lanplus=\"${lanplus}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $cipher_chunk = $cipher ? { - undef => "", - default => "cipher=\"${cipher}\"", - } - $method_chunk = $method ? { - undef => "", - default => "method=\"${method}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $privlvl_chunk = $privlvl ? { - undef => "", - default => "privlvl=\"${privlvl}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ipmilan": ensure => installed, - } -> exec { - "Creating stonith::fence_idrac": - command => "/usr/sbin/pcs stonith create stonith-fence_idrac-${real_address} fence_idrac pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_idrac-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_idrac-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_idrac-${safe_title} fence_idrac pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_idrac-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_idrac ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_idrac-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_idrac-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_idrac-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ifmib.pp b/pacemaker/manifests/stonith/fence_ifmib.pp index 2d33d98c5..a2185bc2b 100644 --- a/pacemaker/manifests/stonith/fence_ifmib.pp +++ b/pacemaker/manifests/stonith/fence_ifmib.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ifmib ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_ifmib ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ifmib": - command => "/usr/sbin/pcs stonith delete stonith-fence_ifmib-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ifmib-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ifmib-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ifmib-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ifmib-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ifmib": ensure => installed, - } -> exec { - "Creating stonith::fence_ifmib": - command => "/usr/sbin/pcs stonith create stonith-fence_ifmib-${real_address} fence_ifmib pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ifmib-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ifmib-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ifmib-${safe_title} fence_ifmib pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ifmib-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ifmib ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ifmib-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ifmib-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ifmib-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ilo.pp b/pacemaker/manifests/stonith/fence_ilo.pp index fe4297310..db495c175 100644 --- a/pacemaker/manifests/stonith/fence_ilo.pp +++ b/pacemaker/manifests/stonith/fence_ilo.pp @@ -1,138 +1,144 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ilo ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $ssl = undef, - $notls = undef, - $ribcl = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $ssl_secure = undef, - $ssl_insecure = undef, - $verbose = undef, - $debug = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_ilo ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $ssl = undef, + $notls = undef, + $ribcl = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $ssl_secure = undef, + $ssl_insecure = undef, + $verbose = undef, + $debug = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $ssl_chunk = $ssl ? { + undef => "", + default => "ssl=\"${ssl}\"", + } + $notls_chunk = $notls ? { + undef => "", + default => "notls=\"${notls}\"", + } + $ribcl_chunk = $ribcl ? { + undef => "", + default => "ribcl=\"${ribcl}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $ssl_secure_chunk = $ssl_secure ? { + undef => "", + default => "ssl_secure=\"${ssl_secure}\"", + } + $ssl_insecure_chunk = $ssl_insecure ? { + undef => "", + default => "ssl_insecure=\"${ssl_insecure}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ilo": - command => "/usr/sbin/pcs stonith delete stonith-fence_ilo-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ilo-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ilo-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $ssl_chunk = $ssl ? { - undef => "", - default => "ssl=\"${ssl}\"", - } - $notls_chunk = $notls ? { - undef => "", - default => "notls=\"${notls}\"", - } - $ribcl_chunk = $ribcl ? { - undef => "", - default => "ribcl=\"${ribcl}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $ssl_secure_chunk = $ssl_secure ? { - undef => "", - default => "ssl_secure=\"${ssl_secure}\"", - } - $ssl_insecure_chunk = $ssl_insecure ? { - undef => "", - default => "ssl_insecure=\"${ssl_insecure}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ilo2": ensure => installed, - } -> exec { - "Creating stonith::fence_ilo": - command => "/usr/sbin/pcs stonith create stonith-fence_ilo-${real_address} fence_ilo pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${ribcl_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ilo-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ilo-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ilo-${safe_title} fence_ilo pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${ribcl_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ilo-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ilo ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ilo-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ilo-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ilo-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ilo2.pp b/pacemaker/manifests/stonith/fence_ilo2.pp index 4799dc73d..644bd077f 100644 --- a/pacemaker/manifests/stonith/fence_ilo2.pp +++ b/pacemaker/manifests/stonith/fence_ilo2.pp @@ -1,138 +1,144 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ilo2 ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $ssl = undef, - $notls = undef, - $ribcl = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $ssl_secure = undef, - $ssl_insecure = undef, - $verbose = undef, - $debug = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_ilo2 ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $ssl = undef, + $notls = undef, + $ribcl = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $ssl_secure = undef, + $ssl_insecure = undef, + $verbose = undef, + $debug = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $ssl_chunk = $ssl ? { + undef => "", + default => "ssl=\"${ssl}\"", + } + $notls_chunk = $notls ? { + undef => "", + default => "notls=\"${notls}\"", + } + $ribcl_chunk = $ribcl ? { + undef => "", + default => "ribcl=\"${ribcl}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $ssl_secure_chunk = $ssl_secure ? { + undef => "", + default => "ssl_secure=\"${ssl_secure}\"", + } + $ssl_insecure_chunk = $ssl_insecure ? { + undef => "", + default => "ssl_insecure=\"${ssl_insecure}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ilo2": - command => "/usr/sbin/pcs stonith delete stonith-fence_ilo2-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo2-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ilo2-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ilo2-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo2-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $ssl_chunk = $ssl ? { - undef => "", - default => "ssl=\"${ssl}\"", - } - $notls_chunk = $notls ? { - undef => "", - default => "notls=\"${notls}\"", - } - $ribcl_chunk = $ribcl ? { - undef => "", - default => "ribcl=\"${ribcl}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $ssl_secure_chunk = $ssl_secure ? { - undef => "", - default => "ssl_secure=\"${ssl_secure}\"", - } - $ssl_insecure_chunk = $ssl_insecure ? { - undef => "", - default => "ssl_insecure=\"${ssl_insecure}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ilo2": ensure => installed, - } -> exec { - "Creating stonith::fence_ilo2": - command => "/usr/sbin/pcs stonith create stonith-fence_ilo2-${real_address} fence_ilo2 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${ribcl_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ilo2-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ilo2-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ilo2-${safe_title} fence_ilo2 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${ribcl_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ilo2-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ilo2 ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ilo2-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ilo2-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ilo2-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ilo3.pp b/pacemaker/manifests/stonith/fence_ilo3.pp index b7777cb39..b6da79e38 100644 --- a/pacemaker/manifests/stonith/fence_ilo3.pp +++ b/pacemaker/manifests/stonith/fence_ilo3.pp @@ -1,103 +1,109 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ilo3 ( - $auth = undef, - $ipaddr = undef, - $passwd = undef, - $passwd_script = undef, - $lanplus = undef, - $login = undef, - $timeout = undef, - $cipher = undef, - $method = undef, - $power_wait = undef, - $delay = undef, - $privlvl = undef, - $verbose = undef, +define pacemaker::stonith::fence_ilo3 ( + $auth = undef, + $ipaddr = undef, + $passwd = undef, + $passwd_script = undef, + $lanplus = undef, + $login = undef, + $timeout = undef, + $cipher = undef, + $method = undef, + $power_wait = undef, + $delay = undef, + $privlvl = undef, + $verbose = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $auth_chunk = $auth ? { + undef => "", + default => "auth=\"${auth}\"", + } + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $lanplus_chunk = $lanplus ? { + undef => "", + default => "lanplus=\"${lanplus}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $cipher_chunk = $cipher ? { + undef => "", + default => "cipher=\"${cipher}\"", + } + $method_chunk = $method ? { + undef => "", + default => "method=\"${method}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $privlvl_chunk = $privlvl ? { + undef => "", + default => "privlvl=\"${privlvl}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ilo3": - command => "/usr/sbin/pcs stonith delete stonith-fence_ilo3-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo3-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ilo3-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ilo3-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo3-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $auth_chunk = $auth ? { - undef => "", - default => "auth=\"${auth}\"", - } - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $lanplus_chunk = $lanplus ? { - undef => "", - default => "lanplus=\"${lanplus}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $cipher_chunk = $cipher ? { - undef => "", - default => "cipher=\"${cipher}\"", - } - $method_chunk = $method ? { - undef => "", - default => "method=\"${method}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $privlvl_chunk = $privlvl ? { - undef => "", - default => "privlvl=\"${privlvl}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ipmilan": ensure => installed, - } -> exec { - "Creating stonith::fence_ilo3": - command => "/usr/sbin/pcs stonith create stonith-fence_ilo3-${real_address} fence_ilo3 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ilo3-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ilo3-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ilo3-${safe_title} fence_ilo3 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ilo3-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ilo3 ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ilo3-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ilo3-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ilo3-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ilo4.pp b/pacemaker/manifests/stonith/fence_ilo4.pp index 3b1da970e..714b3cf10 100644 --- a/pacemaker/manifests/stonith/fence_ilo4.pp +++ b/pacemaker/manifests/stonith/fence_ilo4.pp @@ -1,103 +1,109 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ilo4 ( - $auth = undef, - $ipaddr = undef, - $passwd = undef, - $passwd_script = undef, - $lanplus = undef, - $login = undef, - $timeout = undef, - $cipher = undef, - $method = undef, - $power_wait = undef, - $delay = undef, - $privlvl = undef, - $verbose = undef, +define pacemaker::stonith::fence_ilo4 ( + $auth = undef, + $ipaddr = undef, + $passwd = undef, + $passwd_script = undef, + $lanplus = undef, + $login = undef, + $timeout = undef, + $cipher = undef, + $method = undef, + $power_wait = undef, + $delay = undef, + $privlvl = undef, + $verbose = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $auth_chunk = $auth ? { + undef => "", + default => "auth=\"${auth}\"", + } + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $lanplus_chunk = $lanplus ? { + undef => "", + default => "lanplus=\"${lanplus}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $cipher_chunk = $cipher ? { + undef => "", + default => "cipher=\"${cipher}\"", + } + $method_chunk = $method ? { + undef => "", + default => "method=\"${method}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $privlvl_chunk = $privlvl ? { + undef => "", + default => "privlvl=\"${privlvl}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ilo4": - command => "/usr/sbin/pcs stonith delete stonith-fence_ilo4-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo4-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ilo4-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ilo4-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo4-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $auth_chunk = $auth ? { - undef => "", - default => "auth=\"${auth}\"", - } - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $lanplus_chunk = $lanplus ? { - undef => "", - default => "lanplus=\"${lanplus}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $cipher_chunk = $cipher ? { - undef => "", - default => "cipher=\"${cipher}\"", - } - $method_chunk = $method ? { - undef => "", - default => "method=\"${method}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $privlvl_chunk = $privlvl ? { - undef => "", - default => "privlvl=\"${privlvl}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ipmilan": ensure => installed, - } -> exec { - "Creating stonith::fence_ilo4": - command => "/usr/sbin/pcs stonith create stonith-fence_ilo4-${real_address} fence_ilo4 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ilo4-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ilo4-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ilo4-${safe_title} fence_ilo4 pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ilo4-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ilo4 ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ilo4-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ilo4-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ilo4-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ilo_mp.pp b/pacemaker/manifests/stonith/fence_ilo_mp.pp index 661a70e85..6b8e30d1c 100644 --- a/pacemaker/manifests/stonith/fence_ilo_mp.pp +++ b/pacemaker/manifests/stonith/fence_ilo_mp.pp @@ -1,133 +1,139 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ilo_mp ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $secure = undef, - $cmd_prompt = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_ilo_mp ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $secure = undef, + $cmd_prompt = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ilo_mp": - command => "/usr/sbin/pcs stonith delete stonith-fence_ilo_mp-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo_mp-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ilo_mp-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ilo_mp-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ilo_mp-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ilo-mp": ensure => installed, - } -> exec { - "Creating stonith::fence_ilo_mp": - command => "/usr/sbin/pcs stonith create stonith-fence_ilo_mp-${real_address} fence_ilo_mp pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${secure_chunk} ${cmd_prompt_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ilo_mp-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ilo_mp-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ilo_mp-${safe_title} fence_ilo_mp pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${secure_chunk} ${cmd_prompt_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ilo_mp-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ilo_mp ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ilo_mp-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ilo_mp-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ilo_mp-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_imm.pp b/pacemaker/manifests/stonith/fence_imm.pp index 993556c5a..d4534b4e9 100644 --- a/pacemaker/manifests/stonith/fence_imm.pp +++ b/pacemaker/manifests/stonith/fence_imm.pp @@ -1,103 +1,109 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_imm ( - $auth = undef, - $ipaddr = undef, - $passwd = undef, - $passwd_script = undef, - $lanplus = undef, - $login = undef, - $timeout = undef, - $cipher = undef, - $method = undef, - $power_wait = undef, - $delay = undef, - $privlvl = undef, - $verbose = undef, +define pacemaker::stonith::fence_imm ( + $auth = undef, + $ipaddr = undef, + $passwd = undef, + $passwd_script = undef, + $lanplus = undef, + $login = undef, + $timeout = undef, + $cipher = undef, + $method = undef, + $power_wait = undef, + $delay = undef, + $privlvl = undef, + $verbose = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $auth_chunk = $auth ? { + undef => "", + default => "auth=\"${auth}\"", + } + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $lanplus_chunk = $lanplus ? { + undef => "", + default => "lanplus=\"${lanplus}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $cipher_chunk = $cipher ? { + undef => "", + default => "cipher=\"${cipher}\"", + } + $method_chunk = $method ? { + undef => "", + default => "method=\"${method}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $privlvl_chunk = $privlvl ? { + undef => "", + default => "privlvl=\"${privlvl}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_imm": - command => "/usr/sbin/pcs stonith delete stonith-fence_imm-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_imm-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_imm-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_imm-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_imm-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $auth_chunk = $auth ? { - undef => "", - default => "auth=\"${auth}\"", - } - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $lanplus_chunk = $lanplus ? { - undef => "", - default => "lanplus=\"${lanplus}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $cipher_chunk = $cipher ? { - undef => "", - default => "cipher=\"${cipher}\"", - } - $method_chunk = $method ? { - undef => "", - default => "method=\"${method}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $privlvl_chunk = $privlvl ? { - undef => "", - default => "privlvl=\"${privlvl}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ipmilan": ensure => installed, - } -> exec { - "Creating stonith::fence_imm": - command => "/usr/sbin/pcs stonith create stonith-fence_imm-${real_address} fence_imm pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_imm-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_imm-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_imm-${safe_title} fence_imm pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_imm-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_imm ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_imm-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_imm-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_imm-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_intelmodular.pp b/pacemaker/manifests/stonith/fence_intelmodular.pp index bde84bafd..b93a5f40d 100644 --- a/pacemaker/manifests/stonith/fence_intelmodular.pp +++ b/pacemaker/manifests/stonith/fence_intelmodular.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_intelmodular ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_intelmodular ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_intelmodular": - command => "/usr/sbin/pcs stonith delete stonith-fence_intelmodular-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_intelmodular-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_intelmodular-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_intelmodular-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_intelmodular-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-intelmodular": ensure => installed, - } -> exec { - "Creating stonith::fence_intelmodular": - command => "/usr/sbin/pcs stonith create stonith-fence_intelmodular-${real_address} fence_intelmodular pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_intelmodular-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_intelmodular-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_intelmodular-${safe_title} fence_intelmodular pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_intelmodular-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_intelmodular ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_intelmodular-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_intelmodular-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_intelmodular-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ipdu.pp b/pacemaker/manifests/stonith/fence_ipdu.pp index 7dbd3a598..53aa32a8b 100644 --- a/pacemaker/manifests/stonith/fence_ipdu.pp +++ b/pacemaker/manifests/stonith/fence_ipdu.pp @@ -1,158 +1,164 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ipdu ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $port = undef, - $snmp_version = undef, - $community = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $snmp_auth_prot = undef, - $snmp_sec_level = undef, - $snmp_priv_prot = undef, - $snmp_priv_passwd = undef, - $snmp_priv_passwd_script = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_ipdu ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $port = undef, + $snmp_version = undef, + $community = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $snmp_auth_prot = undef, + $snmp_sec_level = undef, + $snmp_priv_prot = undef, + $snmp_priv_passwd = undef, + $snmp_priv_passwd_script = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $snmp_version_chunk = $snmp_version ? { + undef => "", + default => "snmp_version=\"${snmp_version}\"", + } + $community_chunk = $community ? { + undef => "", + default => "community=\"${community}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $snmp_auth_prot_chunk = $snmp_auth_prot ? { + undef => "", + default => "snmp_auth_prot=\"${snmp_auth_prot}\"", + } + $snmp_sec_level_chunk = $snmp_sec_level ? { + undef => "", + default => "snmp_sec_level=\"${snmp_sec_level}\"", + } + $snmp_priv_prot_chunk = $snmp_priv_prot ? { + undef => "", + default => "snmp_priv_prot=\"${snmp_priv_prot}\"", + } + $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { + undef => "", + default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", + } + $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { + undef => "", + default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ipdu": - command => "/usr/sbin/pcs stonith delete stonith-fence_ipdu-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ipdu-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ipdu-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ipdu-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ipdu-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $snmp_version_chunk = $snmp_version ? { - undef => "", - default => "snmp_version=\"${snmp_version}\"", - } - $community_chunk = $community ? { - undef => "", - default => "community=\"${community}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $snmp_auth_prot_chunk = $snmp_auth_prot ? { - undef => "", - default => "snmp_auth_prot=\"${snmp_auth_prot}\"", - } - $snmp_sec_level_chunk = $snmp_sec_level ? { - undef => "", - default => "snmp_sec_level=\"${snmp_sec_level}\"", - } - $snmp_priv_prot_chunk = $snmp_priv_prot ? { - undef => "", - default => "snmp_priv_prot=\"${snmp_priv_prot}\"", - } - $snmp_priv_passwd_chunk = $snmp_priv_passwd ? { - undef => "", - default => "snmp_priv_passwd=\"${snmp_priv_passwd}\"", - } - $snmp_priv_passwd_script_chunk = $snmp_priv_passwd_script ? { - undef => "", - default => "snmp_priv_passwd_script=\"${snmp_priv_passwd_script}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ipdu": ensure => installed, - } -> exec { - "Creating stonith::fence_ipdu": - command => "/usr/sbin/pcs stonith create stonith-fence_ipdu-${real_address} fence_ipdu pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ipdu-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ipdu-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ipdu-${safe_title} fence_ipdu pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${port_chunk} ${snmp_version_chunk} ${community_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${snmp_auth_prot_chunk} ${snmp_sec_level_chunk} ${snmp_priv_prot_chunk} ${snmp_priv_passwd_chunk} ${snmp_priv_passwd_script_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ipdu-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ipdu ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ipdu-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ipdu-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ipdu-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_ipmilan.pp b/pacemaker/manifests/stonith/fence_ipmilan.pp index c143d5820..6183519df 100644 --- a/pacemaker/manifests/stonith/fence_ipmilan.pp +++ b/pacemaker/manifests/stonith/fence_ipmilan.pp @@ -1,103 +1,109 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_ipmilan ( - $auth = undef, - $ipaddr = undef, - $passwd = undef, - $passwd_script = undef, - $lanplus = undef, - $login = undef, - $timeout = undef, - $cipher = undef, - $method = undef, - $power_wait = undef, - $delay = undef, - $privlvl = undef, - $verbose = undef, +define pacemaker::stonith::fence_ipmilan ( + $auth = undef, + $ipaddr = undef, + $passwd = undef, + $passwd_script = undef, + $lanplus = undef, + $login = undef, + $timeout = undef, + $cipher = undef, + $method = undef, + $power_wait = undef, + $delay = undef, + $privlvl = undef, + $verbose = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $auth_chunk = $auth ? { + undef => "", + default => "auth=\"${auth}\"", + } + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $lanplus_chunk = $lanplus ? { + undef => "", + default => "lanplus=\"${lanplus}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $cipher_chunk = $cipher ? { + undef => "", + default => "cipher=\"${cipher}\"", + } + $method_chunk = $method ? { + undef => "", + default => "method=\"${method}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $privlvl_chunk = $privlvl ? { + undef => "", + default => "privlvl=\"${privlvl}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_ipmilan": - command => "/usr/sbin/pcs stonith delete stonith-fence_ipmilan-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_ipmilan-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_ipmilan-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_ipmilan-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_ipmilan-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $auth_chunk = $auth ? { - undef => "", - default => "auth=\"${auth}\"", - } - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $lanplus_chunk = $lanplus ? { - undef => "", - default => "lanplus=\"${lanplus}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $cipher_chunk = $cipher ? { - undef => "", - default => "cipher=\"${cipher}\"", - } - $method_chunk = $method ? { - undef => "", - default => "method=\"${method}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $privlvl_chunk = $privlvl ? { - undef => "", - default => "privlvl=\"${privlvl}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-ipmilan": ensure => installed, - } -> exec { - "Creating stonith::fence_ipmilan": - command => "/usr/sbin/pcs stonith create stonith-fence_ipmilan-${real_address} fence_ipmilan pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_ipmilan-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_ipmilan-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_ipmilan-${safe_title} fence_ipmilan pcmk_host_list=\"${pcmk_host_value_chunk}\" ${auth_chunk} ${ipaddr_chunk} ${passwd_chunk} ${passwd_script_chunk} ${lanplus_chunk} ${login_chunk} ${timeout_chunk} ${cipher_chunk} ${method_chunk} ${power_wait_chunk} ${delay_chunk} ${privlvl_chunk} ${verbose_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_ipmilan-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_ipmilan ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_ipmilan-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_ipmilan-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_ipmilan-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_kdump.pp b/pacemaker/manifests/stonith/fence_kdump.pp index dda1a83f8..4d8936427 100644 --- a/pacemaker/manifests/stonith/fence_kdump.pp +++ b/pacemaker/manifests/stonith/fence_kdump.pp @@ -1,68 +1,74 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_kdump ( - $nodename = undef, - $ipport = undef, - $family = undef, - $timeout = undef, - $verbose = undef, - $usage = undef, +define pacemaker::stonith::fence_kdump ( + $nodename = undef, + $ipport = undef, + $family = undef, + $timeout = undef, + $verbose = undef, + $usage = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $nodename_chunk = $nodename ? { + undef => "", + default => "nodename=\"${nodename}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $family_chunk = $family ? { + undef => "", + default => "family=\"${family}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $usage_chunk = $usage ? { + undef => "", + default => "usage=\"${usage}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_kdump": - command => "/usr/sbin/pcs stonith delete stonith-fence_kdump-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_kdump-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_kdump-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_kdump-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_kdump-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $nodename_chunk = $nodename ? { - undef => "", - default => "nodename=\"${nodename}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $family_chunk = $family ? { - undef => "", - default => "family=\"${family}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $usage_chunk = $usage ? { - undef => "", - default => "usage=\"${usage}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-kdump": ensure => installed, - } -> exec { - "Creating stonith::fence_kdump": - command => "/usr/sbin/pcs stonith create stonith-fence_kdump-${real_address} fence_kdump pcmk_host_list=\"${pcmk_host_value_chunk}\" ${nodename_chunk} ${ipport_chunk} ${family_chunk} ${timeout_chunk} ${verbose_chunk} ${usage_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_kdump-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_kdump-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_kdump-${safe_title} fence_kdump pcmk_host_list=\"${pcmk_host_value_chunk}\" ${nodename_chunk} ${ipport_chunk} ${family_chunk} ${timeout_chunk} ${verbose_chunk} ${usage_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_kdump-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_kdump ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_kdump-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_kdump-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_kdump-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_rhevm.pp b/pacemaker/manifests/stonith/fence_rhevm.pp index 9b31530c0..669fa1db8 100644 --- a/pacemaker/manifests/stonith/fence_rhevm.pp +++ b/pacemaker/manifests/stonith/fence_rhevm.pp @@ -1,143 +1,149 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_rhevm ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $ssl = undef, - $notls = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $ssl_secure = undef, - $ssl_insecure = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_rhevm ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $ssl = undef, + $notls = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $ssl_secure = undef, + $ssl_insecure = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $ssl_chunk = $ssl ? { + undef => "", + default => "ssl=\"${ssl}\"", + } + $notls_chunk = $notls ? { + undef => "", + default => "notls=\"${notls}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $ssl_secure_chunk = $ssl_secure ? { + undef => "", + default => "ssl_secure=\"${ssl_secure}\"", + } + $ssl_insecure_chunk = $ssl_insecure ? { + undef => "", + default => "ssl_insecure=\"${ssl_insecure}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_rhevm": - command => "/usr/sbin/pcs stonith delete stonith-fence_rhevm-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_rhevm-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_rhevm-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_rhevm-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_rhevm-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $ssl_chunk = $ssl ? { - undef => "", - default => "ssl=\"${ssl}\"", - } - $notls_chunk = $notls ? { - undef => "", - default => "notls=\"${notls}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $ssl_secure_chunk = $ssl_secure ? { - undef => "", - default => "ssl_secure=\"${ssl_secure}\"", - } - $ssl_insecure_chunk = $ssl_insecure ? { - undef => "", - default => "ssl_insecure=\"${ssl_insecure}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-rhevm": ensure => installed, - } -> exec { - "Creating stonith::fence_rhevm": - command => "/usr/sbin/pcs stonith create stonith-fence_rhevm-${real_address} fence_rhevm pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_rhevm-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_rhevm-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_rhevm-${safe_title} fence_rhevm pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_rhevm-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_rhevm ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_rhevm-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_rhevm-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_rhevm-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_rsb.pp b/pacemaker/manifests/stonith/fence_rsb.pp index 879799a52..0ff8475a3 100644 --- a/pacemaker/manifests/stonith/fence_rsb.pp +++ b/pacemaker/manifests/stonith/fence_rsb.pp @@ -1,133 +1,139 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_rsb ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $secure = undef, - $cmd_prompt = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_rsb ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $secure = undef, + $cmd_prompt = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_rsb": - command => "/usr/sbin/pcs stonith delete stonith-fence_rsb-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_rsb-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_rsb-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_rsb-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_rsb-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-rsb": ensure => installed, - } -> exec { - "Creating stonith::fence_rsb": - command => "/usr/sbin/pcs stonith create stonith-fence_rsb-${real_address} fence_rsb pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${secure_chunk} ${cmd_prompt_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_rsb-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_rsb-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_rsb-${safe_title} fence_rsb pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${secure_chunk} ${cmd_prompt_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_rsb-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_rsb ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_rsb-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_rsb-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_rsb-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_scsi.pp b/pacemaker/manifests/stonith/fence_scsi.pp index 52032dde2..3031da94f 100644 --- a/pacemaker/manifests/stonith/fence_scsi.pp +++ b/pacemaker/manifests/stonith/fence_scsi.pp @@ -1,68 +1,74 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_scsi ( - $aptpl = undef, - $devices = undef, - $logfile = undef, - $delay = undef, - $key = undef, - $nodename = undef, +define pacemaker::stonith::fence_scsi ( + $aptpl = undef, + $devices = undef, + $logfile = undef, + $delay = undef, + $key = undef, + $nodename = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $aptpl_chunk = $aptpl ? { + undef => "", + default => "aptpl=\"${aptpl}\"", + } + $devices_chunk = $devices ? { + undef => "", + default => "devices=\"${devices}\"", + } + $logfile_chunk = $logfile ? { + undef => "", + default => "logfile=\"${logfile}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $key_chunk = $key ? { + undef => "", + default => "key=\"${key}\"", + } + $nodename_chunk = $nodename ? { + undef => "", + default => "nodename=\"${nodename}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_scsi": - command => "/usr/sbin/pcs stonith delete stonith-fence_scsi-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_scsi-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_scsi-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_scsi-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_scsi-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $aptpl_chunk = $aptpl ? { - undef => "", - default => "aptpl=\"${aptpl}\"", - } - $devices_chunk = $devices ? { - undef => "", - default => "devices=\"${devices}\"", - } - $logfile_chunk = $logfile ? { - undef => "", - default => "logfile=\"${logfile}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $key_chunk = $key ? { - undef => "", - default => "key=\"${key}\"", - } - $nodename_chunk = $nodename ? { - undef => "", - default => "nodename=\"${nodename}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-scsi": ensure => installed, - } -> exec { - "Creating stonith::fence_scsi": - command => "/usr/sbin/pcs stonith create stonith-fence_scsi-${real_address} fence_scsi pcmk_host_list=\"${pcmk_host_value_chunk}\" ${aptpl_chunk} ${devices_chunk} ${logfile_chunk} ${delay_chunk} ${key_chunk} ${nodename_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_scsi-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_scsi-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_scsi-${safe_title} fence_scsi pcmk_host_list=\"${pcmk_host_value_chunk}\" ${aptpl_chunk} ${devices_chunk} ${logfile_chunk} ${delay_chunk} ${key_chunk} ${nodename_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_scsi-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_scsi ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_scsi-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_scsi-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_scsi-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_virt.pp b/pacemaker/manifests/stonith/fence_virt.pp index d948a58a1..ef9c3b2fb 100644 --- a/pacemaker/manifests/stonith/fence_virt.pp +++ b/pacemaker/manifests/stonith/fence_virt.pp @@ -1,83 +1,89 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_virt ( - $debug = undef, - $serial_device = undef, - $serial_params = undef, - $channel_address = undef, - $ipport = undef, - $port = undef, - $timeout = undef, - $delay = undef, - $domain = undef, +define pacemaker::stonith::fence_virt ( + $debug = undef, + $serial_device = undef, + $serial_params = undef, + $channel_address = undef, + $ipport = undef, + $port = undef, + $timeout = undef, + $delay = undef, + $domain = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $serial_device_chunk = $serial_device ? { + undef => "", + default => "serial_device=\"${serial_device}\"", + } + $serial_params_chunk = $serial_params ? { + undef => "", + default => "serial_params=\"${serial_params}\"", + } + $channel_address_chunk = $channel_address ? { + undef => "", + default => "channel_address=\"${channel_address}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $domain_chunk = $domain ? { + undef => "", + default => "domain=\"${domain}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_virt": - command => "/usr/sbin/pcs stonith delete stonith-fence_virt-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_virt-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_virt-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_virt-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_virt-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $serial_device_chunk = $serial_device ? { - undef => "", - default => "serial_device=\"${serial_device}\"", - } - $serial_params_chunk = $serial_params ? { - undef => "", - default => "serial_params=\"${serial_params}\"", - } - $channel_address_chunk = $channel_address ? { - undef => "", - default => "channel_address=\"${channel_address}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $timeout_chunk = $timeout ? { - undef => "", - default => "timeout=\"${timeout}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $domain_chunk = $domain ? { - undef => "", - default => "domain=\"${domain}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-virt": ensure => installed, - } -> exec { - "Creating stonith::fence_virt": - command => "/usr/sbin/pcs stonith create stonith-fence_virt-${real_address} fence_virt pcmk_host_list=\"${pcmk_host_value_chunk}\" ${debug_chunk} ${serial_device_chunk} ${serial_params_chunk} ${channel_address_chunk} ${ipport_chunk} ${port_chunk} ${timeout_chunk} ${delay_chunk} ${domain_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_virt-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_virt-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_virt-${safe_title} fence_virt pcmk_host_list=\"${pcmk_host_value_chunk}\" ${debug_chunk} ${serial_device_chunk} ${serial_params_chunk} ${channel_address_chunk} ${ipport_chunk} ${port_chunk} ${timeout_chunk} ${delay_chunk} ${domain_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_virt-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_virt ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_virt-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_virt-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_virt-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_vmware_soap.pp b/pacemaker/manifests/stonith/fence_vmware_soap.pp index 47c6cedc8..e5021169e 100644 --- a/pacemaker/manifests/stonith/fence_vmware_soap.pp +++ b/pacemaker/manifests/stonith/fence_vmware_soap.pp @@ -1,143 +1,149 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_vmware_soap ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $ssl = undef, - $notls = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $ssl_secure = undef, - $ssl_insecure = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_vmware_soap ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $ssl = undef, + $notls = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $ssl_secure = undef, + $ssl_insecure = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $ssl_chunk = $ssl ? { + undef => "", + default => "ssl=\"${ssl}\"", + } + $notls_chunk = $notls ? { + undef => "", + default => "notls=\"${notls}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $ssl_secure_chunk = $ssl_secure ? { + undef => "", + default => "ssl_secure=\"${ssl_secure}\"", + } + $ssl_insecure_chunk = $ssl_insecure ? { + undef => "", + default => "ssl_insecure=\"${ssl_insecure}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_vmware_soap": - command => "/usr/sbin/pcs stonith delete stonith-fence_vmware_soap-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_vmware_soap-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_vmware_soap-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_vmware_soap-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_vmware_soap-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $ssl_chunk = $ssl ? { - undef => "", - default => "ssl=\"${ssl}\"", - } - $notls_chunk = $notls ? { - undef => "", - default => "notls=\"${notls}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $ssl_secure_chunk = $ssl_secure ? { - undef => "", - default => "ssl_secure=\"${ssl_secure}\"", - } - $ssl_insecure_chunk = $ssl_insecure ? { - undef => "", - default => "ssl_insecure=\"${ssl_insecure}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-vmware-soap": ensure => installed, - } -> exec { - "Creating stonith::fence_vmware_soap": - command => "/usr/sbin/pcs stonith create stonith-fence_vmware_soap-${real_address} fence_vmware_soap pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_vmware_soap-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_vmware_soap-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_vmware_soap-${safe_title} fence_vmware_soap pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${ssl_chunk} ${notls_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${ssl_secure_chunk} ${ssl_insecure_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_vmware_soap-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_vmware_soap ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_vmware_soap-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_vmware_soap-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_vmware_soap-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_wti.pp b/pacemaker/manifests/stonith/fence_wti.pp index 14b346fbd..1cfb21752 100644 --- a/pacemaker/manifests/stonith/fence_wti.pp +++ b/pacemaker/manifests/stonith/fence_wti.pp @@ -1,143 +1,149 @@ # generated by agent_generator.rb, manual changes will be lost -class pacemaker::stonith::fence_wti ( - $ipaddr = undef, - $login = undef, - $passwd = undef, - $cmd_prompt = undef, - $secure = undef, - $port = undef, - $ipport = undef, - $inet4_only = undef, - $inet6_only = undef, - $passwd_script = undef, - $identity_file = undef, - $ssh_options = undef, - $verbose = undef, - $debug = undef, - $separator = undef, - $power_timeout = undef, - $shell_timeout = undef, - $login_timeout = undef, - $power_wait = undef, - $delay = undef, - $retry_on = undef, +define pacemaker::stonith::fence_wti ( + $ipaddr = undef, + $login = undef, + $passwd = undef, + $cmd_prompt = undef, + $secure = undef, + $port = undef, + $ipport = undef, + $inet4_only = undef, + $inet6_only = undef, + $passwd_script = undef, + $identity_file = undef, + $ssh_options = undef, + $verbose = undef, + $debug = undef, + $separator = undef, + $power_timeout = undef, + $shell_timeout = undef, + $login_timeout = undef, + $power_wait = undef, + $delay = undef, + $retry_on = undef, - $interval = "60s", - $ensure = present, - $pcmk_host_value = undef, + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, + $tries = undef, + $try_sleep = undef, ) { - $real_address = "$(corosync-cfgtool -a $(crm_node -n))" + $ipaddr_chunk = $ipaddr ? { + undef => "", + default => "ipaddr=\"${ipaddr}\"", + } + $login_chunk = $login ? { + undef => "", + default => "login=\"${login}\"", + } + $passwd_chunk = $passwd ? { + undef => "", + default => "passwd=\"${passwd}\"", + } + $cmd_prompt_chunk = $cmd_prompt ? { + undef => "", + default => "cmd_prompt=\"${cmd_prompt}\"", + } + $secure_chunk = $secure ? { + undef => "", + default => "secure=\"${secure}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $inet4_only_chunk = $inet4_only ? { + undef => "", + default => "inet4_only=\"${inet4_only}\"", + } + $inet6_only_chunk = $inet6_only ? { + undef => "", + default => "inet6_only=\"${inet6_only}\"", + } + $passwd_script_chunk = $passwd_script ? { + undef => "", + default => "passwd_script=\"${passwd_script}\"", + } + $identity_file_chunk = $identity_file ? { + undef => "", + default => "identity_file=\"${identity_file}\"", + } + $ssh_options_chunk = $ssh_options ? { + undef => "", + default => "ssh_options=\"${ssh_options}\"", + } + $verbose_chunk = $verbose ? { + undef => "", + default => "verbose=\"${verbose}\"", + } + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $separator_chunk = $separator ? { + undef => "", + default => "separator=\"${separator}\"", + } + $power_timeout_chunk = $power_timeout ? { + undef => "", + default => "power_timeout=\"${power_timeout}\"", + } + $shell_timeout_chunk = $shell_timeout ? { + undef => "", + default => "shell_timeout=\"${shell_timeout}\"", + } + $login_timeout_chunk = $login_timeout ? { + undef => "", + default => "login_timeout=\"${login_timeout}\"", + } + $power_wait_chunk = $power_wait ? { + undef => "", + default => "power_wait=\"${power_wait}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $retry_on_chunk = $retry_on ? { + undef => "", + default => "retry_on=\"${retry_on}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { - "Removing stonith::fence_wti": - command => "/usr/sbin/pcs stonith delete stonith-fence_wti-${real_address}", - onlyif => "/usr/sbin/pcs stonith show stonith-fence_wti-${real_address} > /dev/null 2>&1", + exec { "Delete stonith-fence_wti-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_wti-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_wti-${safe_title} > /dev/null 2>&1", require => Class["pacemaker::corosync"], } } else { - $ipaddr_chunk = $ipaddr ? { - undef => "", - default => "ipaddr=\"${ipaddr}\"", - } - $login_chunk = $login ? { - undef => "", - default => "login=\"${login}\"", - } - $passwd_chunk = $passwd ? { - undef => "", - default => "passwd=\"${passwd}\"", - } - $cmd_prompt_chunk = $cmd_prompt ? { - undef => "", - default => "cmd_prompt=\"${cmd_prompt}\"", - } - $secure_chunk = $secure ? { - undef => "", - default => "secure=\"${secure}\"", - } - $port_chunk = $port ? { - undef => "", - default => "port=\"${port}\"", - } - $ipport_chunk = $ipport ? { - undef => "", - default => "ipport=\"${ipport}\"", - } - $inet4_only_chunk = $inet4_only ? { - undef => "", - default => "inet4_only=\"${inet4_only}\"", - } - $inet6_only_chunk = $inet6_only ? { - undef => "", - default => "inet6_only=\"${inet6_only}\"", - } - $passwd_script_chunk = $passwd_script ? { - undef => "", - default => "passwd_script=\"${passwd_script}\"", - } - $identity_file_chunk = $identity_file ? { - undef => "", - default => "identity_file=\"${identity_file}\"", - } - $ssh_options_chunk = $ssh_options ? { - undef => "", - default => "ssh_options=\"${ssh_options}\"", - } - $verbose_chunk = $verbose ? { - undef => "", - default => "verbose=\"${verbose}\"", - } - $debug_chunk = $debug ? { - undef => "", - default => "debug=\"${debug}\"", - } - $separator_chunk = $separator ? { - undef => "", - default => "separator=\"${separator}\"", - } - $power_timeout_chunk = $power_timeout ? { - undef => "", - default => "power_timeout=\"${power_timeout}\"", - } - $shell_timeout_chunk = $shell_timeout ? { - undef => "", - default => "shell_timeout=\"${shell_timeout}\"", - } - $login_timeout_chunk = $login_timeout ? { - undef => "", - default => "login_timeout=\"${login_timeout}\"", - } - $power_wait_chunk = $power_wait ? { - undef => "", - default => "power_wait=\"${power_wait}\"", - } - $delay_chunk = $delay ? { - undef => "", - default => "delay=\"${delay}\"", - } - $retry_on_chunk = $retry_on ? { - undef => "", - default => "retry_on=\"${retry_on}\"", - } - - $pcmk_host_value_chunk = $pcmk_host_list ? { - '' => '$(/usr/sbin/crm_node -n)', - default => "${pcmk_host_list}", - } - package { "fence-agents-wti": ensure => installed, - } -> exec { - "Creating stonith::fence_wti": - command => "/usr/sbin/pcs stonith create stonith-fence_wti-${real_address} fence_wti pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show stonith-fence_wti-${real_address} > /dev/null 2>&1", + } -> + exec { "Create stonith-fence_wti-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_wti-${safe_title} fence_wti pcmk_host_list=\"${pcmk_host_value_chunk}\" ${ipaddr_chunk} ${login_chunk} ${passwd_chunk} ${cmd_prompt_chunk} ${secure_chunk} ${port_chunk} ${ipport_chunk} ${inet4_only_chunk} ${inet6_only_chunk} ${passwd_script_chunk} ${identity_file_chunk} ${ssh_options_chunk} ${verbose_chunk} ${debug_chunk} ${separator_chunk} ${power_timeout_chunk} ${shell_timeout_chunk} ${login_timeout_chunk} ${power_wait_chunk} ${delay_chunk} ${retry_on_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_wti-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, require => Class["pacemaker::corosync"], - } -> exec { - "Adding non-local constraint stonith::fence_wti ${real_address}": - command => "/usr/sbin/pcs constraint location stonith-fence_wti-${real_address} avoids ${pcmk_host_value_chunk}" + } -> + exec { "Add non-local constraint for stonith-fence_wti-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_wti-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/pacemaker/manifests/stonith/fence_xvm.pp b/pacemaker/manifests/stonith/fence_xvm.pp index d0bdb9d8a..cba974c7b 100644 --- a/pacemaker/manifests/stonith/fence_xvm.pp +++ b/pacemaker/manifests/stonith/fence_xvm.pp @@ -1,42 +1,104 @@ -# DEPRECATED: use pacemaker::stonith::xvm instead +define pacemaker::stonith::fence_xvm ( + $debug = undef, + $ip_family = undef, + $multicast_address = undef, + $ipport = undef, + $retrans = undef, + $auth = undef, + $hash = undef, + $key_file = undef, + $port = undef, + $use_uuid = undef, + $timeout = undef, + $delay = undef, + $domain = undef, -# To use this class ensure that fence_virtd is properly configured and running on the hypervisor + $interval = "60s", + $ensure = present, + $pcmk_host_list = undef, -class pacemaker::stonith::fence_xvm( - $name, - $manage_key_file=false, - $key_file="/etc/cluster/fence_xvm.key", - $key_file_password="123456", - $interval="30s", - $ensure=present, - $port=undef, # the name of the vm - $pcmk_host=undef, # the hostname or IP that pacemaker uses + $manage_key_file = false, + $key_file = "/etc/cluster/fence_xvm.key", + $key_file_password = "123456", $manage_fw = true, - ) { - warning('pacemaker::stonith::fence_xvm is deprecated, use pacemaker::stonith::xvm instead') + $tries = undef, + $try_sleep = undef, +) { + $debug_chunk = $debug ? { + undef => "", + default => "debug=\"${debug}\"", + } + $ip_family_chunk = $ip_family ? { + undef => "", + default => "ip_family=\"${ip_family}\"", + } + $multicast_address_chunk = $multicast_address ? { + undef => "", + default => "multicast_address=\"${multicast_address}\"", + } + $ipport_chunk = $ipport ? { + undef => "", + default => "ipport=\"${ipport}\"", + } + $retrans_chunk = $retrans ? { + undef => "", + default => "retrans=\"${retrans}\"", + } + $auth_chunk = $auth ? { + undef => "", + default => "auth=\"${auth}\"", + } + $hash_chunk = $hash ? { + undef => "", + default => "hash=\"${hash}\"", + } + $key_file_chunk = $key_file ? { + undef => "", + default => "key_file=\"${key_file}\"", + } + $port_chunk = $port ? { + undef => "", + default => "port=\"${port}\"", + } + $use_uuid_chunk = $use_uuid ? { + undef => "", + default => "use_uuid=\"${use_uuid}\"", + } + $timeout_chunk = $timeout ? { + undef => "", + default => "timeout=\"${timeout}\"", + } + $delay_chunk = $delay ? { + undef => "", + default => "delay=\"${delay}\"", + } + $domain_chunk = $domain ? { + undef => "", + default => "domain=\"${domain}\"", + } + + $pcmk_host_value_chunk = $pcmk_host_list ? { + undef => '$(/usr/sbin/crm_node -n)', + default => "${pcmk_host_list}", + } + + # $title can be a mac address, remove the colons for pcmk resource name + $safe_title = regsubst($title, ':', '', 'G') if($ensure == absent) { - exec { "Removing stonith::fence_xvm ${name}": - command => "/usr/sbin/pcs stonith delete fence_xvm-${name }", - onlyif => "/usr/sbin/pcs stonith show fence_xvm-${name} > /dev/null 2>&1", - require => Class['pacemaker::corosync'], + exec { "Delete stonith-fence_xvm-${safe_title}": + command => "/usr/sbin/pcs stonith delete stonith-fence_xvm-${safe_title}", + onlyif => "/usr/sbin/pcs stonith show stonith-fence_xvm-${safe_title} > /dev/null 2>&1", + require => Class["pacemaker::corosync"], } } else { - $port_chunk = $port ? { - '' => '', - default => "port=${port}", - } - $pcmk_host_list_chunk = $pcmk_host ? { - '' => 'pcmk_host_list=$(/usr/sbin/crm_node -n)', - default => "pcmk_host_list=${pcmk_host}", - } - if $manage_key_file { + if str2bool($manage_key_file) { file { "$key_file": content => "$key_file_password", } } - if $manage_fw { + if str2bool($manage_fw) { firewall { "003 fence_xvm": proto => 'igmp', action => 'accept', @@ -53,10 +115,20 @@ } } - exec { "Creating stonith::fence_xvm ${name}": - command => "/usr/sbin/pcs stonith create fence_xvm-${name} fence_xvm ${port_chunk} ${pcmk_host_list_chunk} op monitor interval=${interval}", - unless => "/usr/sbin/pcs stonith show fence_xvm-${name} > /dev/null 2>&1", - require => Class['pacemaker::corosync'], + package { + "fence-virt": ensure => installed, + } -> + exec { "Create stonith-fence_xvm-${safe_title}": + command => "/usr/sbin/pcs stonith create stonith-fence_xvm-${safe_title} fence_xvm pcmk_host_list=\"${pcmk_host_value_chunk}\" ${debug_chunk} ${ip_family_chunk} ${multicast_address_chunk} ${ipport_chunk} ${retrans_chunk} ${auth_chunk} ${hash_chunk} ${key_file_chunk} ${port_chunk} ${use_uuid_chunk} ${timeout_chunk} ${delay_chunk} ${domain_chunk} op monitor interval=${interval}", + unless => "/usr/sbin/pcs stonith show stonith-fence_xvm-${safe_title} > /dev/null 2>&1", + tries => $tries, + try_sleep => $try_sleep, + require => Class["pacemaker::corosync"], + } -> + exec { "Add non-local constraint for stonith-fence_xvm-${safe_title}": + command => "/usr/sbin/pcs constraint location stonith-fence_xvm-${safe_title} avoids ${pcmk_host_value_chunk}", + tries => $tries, + try_sleep => $try_sleep, } } } diff --git a/rabbitmq/.travis.yml b/rabbitmq/.travis.yml index 742380f6b..16d694bb6 100644 --- a/rabbitmq/.travis.yml +++ b/rabbitmq/.travis.yml @@ -16,8 +16,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - rvm: 2.1.6 env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/rabbitmq/CHANGELOG.md b/rabbitmq/CHANGELOG.md index 9800626d7..c0f8d8c20 100644 --- a/rabbitmq/CHANGELOG.md +++ b/rabbitmq/CHANGELOG.md @@ -1,3 +1,12 @@ +## 2015-06-09 - Version 5.2.2 +### Summary +This is a bugfix to allow the rabbitmq\_exchange type's internal/durable/auto\_delete attributes work when they are not explicitly passed. + +### Bugfixes +- Fix rabbitmq\_exchange create when internal/durable/auto\_delete are not specified +- Start unit testing on puppet 4 +- Add default value to tcp\_listen\_options + ## 2015-05-26 - Version 5.2.1 ###Summary This release includes a fix for idempotency between puppet runs, as well as Readme updates diff --git a/rabbitmq/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb b/rabbitmq/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb index c1cff0957..583b7bc60 100644 --- a/rabbitmq/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb +++ b/rabbitmq/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb @@ -98,7 +98,12 @@ def create if arguments.nil? arguments = {} end - rabbitmqadmin('declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}", "internal=#{resource[:internal]}", "durable=#{resource[:durable]}", "auto_delete=#{resource[:auto_delete]}", "arguments=#{arguments.to_json}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf') + cmd = ['declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}",] + cmd << "internal=#{resource[:internal]}" if resource[:internal] + cmd << "durable=#{resource[:durable]}" if resource[:durable] + cmd << "auto_delete=#{resource[:auto_delete]}" if resource[:auto_delete] + cmd += ["arguments=#{arguments.to_json}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf'] + rabbitmqadmin(*cmd) @property_hash[:ensure] = :present end diff --git a/rabbitmq/lib/puppet/type/rabbitmq_exchange.rb b/rabbitmq/lib/puppet/type/rabbitmq_exchange.rb index b2e88a8de..7dd0a1ff9 100644 --- a/rabbitmq/lib/puppet/type/rabbitmq_exchange.rb +++ b/rabbitmq/lib/puppet/type/rabbitmq_exchange.rb @@ -24,16 +24,19 @@ newparam(:durable) do desc 'Exchange durability to be set *on creation*' newvalues(/^\S+$/) + defaultto 'false' end newparam(:auto_delete) do desc 'Exchange auto delete option to be set *on creation*' newvalues(/^\S+$/) + defaultto 'false' end newparam(:internal) do desc 'Exchange internal option to be set *on creation*' newvalues(/^\S+$/) + defaultto 'false' end newparam(:arguments) do diff --git a/rabbitmq/metadata.json b/rabbitmq/metadata.json index 945a26f47..9f7104fff 100644 --- a/rabbitmq/metadata.json +++ b/rabbitmq/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-rabbitmq", - "version": "5.2.1", + "version": "5.2.2", "author": "puppetlabs", "summary": "Installs, configures, and manages RabbitMQ.", "license": "Apache-2.0", diff --git a/rabbitmq/spec/acceptance/rabbitmqadmin_spec.rb b/rabbitmq/spec/acceptance/rabbitmqadmin_spec.rb index e9d619cd4..dcf62402d 100644 --- a/rabbitmq/spec/acceptance/rabbitmqadmin_spec.rb +++ b/rabbitmq/spec/acceptance/rabbitmqadmin_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper_acceptance' describe 'rabbitmq::install::rabbitmqadmin class' do - context 'does nothing if service is unmanaged' do + context 'downloads the cli tools' do it 'should run successfully' do pp = <<-EOS class { 'rabbitmq': admin_enable => true, - service_manage => false, + service_manage => true, } if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true} @@ -14,21 +14,20 @@ class { 'erlang': epel_enable => true} } EOS - shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') apply_manifest(pp, :catch_failures => true) end describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should_not be_file } + it { should be_file } end end - context 'downloads the cli tools' do + context 'does nothing if service is unmanaged' do it 'should run successfully' do pp = <<-EOS class { 'rabbitmq': admin_enable => true, - service_manage => true, + service_manage => false, } if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true} @@ -36,11 +35,12 @@ class { 'erlang': epel_enable => true} } EOS + shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') apply_manifest(pp, :catch_failures => true) end describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should be_file } + it { should_not be_file } end end diff --git a/rabbitmq/spec/acceptance/zz281_spec.rb b/rabbitmq/spec/acceptance/zz281_spec.rb index 05e5ef40c..75637485b 100644 --- a/rabbitmq/spec/acceptance/zz281_spec.rb +++ b/rabbitmq/spec/acceptance/zz281_spec.rb @@ -3,209 +3,193 @@ # beacuse of some serious issues with upgrading and downgrading rabbitmq on RedHat, # we need to run all of the 2.8.1 tests last. # -# NOTE that this is only tested on RedHat and probably only works there. But I can't seem -# to get 'confine' to work... +# These tests only apply to RedHat because 2.8.1 is not available in either the +# distro or upstream repos for Debian/Ubuntu. # - describe 'rabbitmq class with 2.8.1:' do - case fact('osfamily') - when 'RedHat' - package_name = 'rabbitmq-server' - service_name = 'rabbitmq-server' - package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.1/rabbitmq-server-2.8.1-1.noarch.rpm" - package_ensure = '2.8.1-1' - when 'SUSE' - package_name = 'rabbitmq-server' - service_name = 'rabbitmq-server' - package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.1/rabbitmq-server-2.8.1-1.noarch.rpm" - package_ensure = '2.8.1-1' - when 'Debian' - package_name = 'rabbitmq-server' - service_name = 'rabbitmq-server' - package_source = '' - package_ensure = '2.8.1' - when 'Archlinux' - package_name = 'rabbitmq' - service_name = 'rabbitmq' - package_source = '' - package_ensure = '2.8.1' - end - - context "default class inclusion" do - it 'should run successfully' do - pp = <<-EOS - class { 'rabbitmq': - version => '2.8.1-1', - package_source => '#{package_source}', - package_ensure => '#{package_ensure}', - package_provider => 'rpm', - management_port => '55672', - } - if $::osfamily == 'RedHat' { - class { 'erlang': epel_enable => true} - Class['erlang'] -> Class['rabbitmq'] - } - EOS - - # clean up previous 3.x install - can't be ungraded cleanly via RPM - shell('service rabbitmq-server stop') - shell('yum -y erase rabbitmq-server') - shell('rm -Rf /var/lib/rabbitmq/mnesia /etc/rabbitmq /var/lib/rabbitmq/rabbitmqadmin') - # Apply twice to ensure no errors the second time. - apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero - # DEBUG - shell('netstat -lntp') - end - - describe command('rabbitmqctl status') do - its(:stdout) { should match /{rabbit,"RabbitMQ","2.8.1"}/ } - end - - describe package(package_name) do - it { should be_installed } + if fact('osfamily') == 'RedHat' + package_name = 'rabbitmq-server' + service_name = 'rabbitmq-server' + package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.1/rabbitmq-server-2.8.1-1.noarch.rpm" + package_ensure = '2.8.1-1' + + context "default class inclusion" do + it 'should run successfully' do + pp = <<-EOS + class { 'rabbitmq': + version => '2.8.1-1', + package_source => '#{package_source}', + package_ensure => '#{package_ensure}', + package_provider => 'rpm', + management_port => '55672', + } + if $::osfamily == 'RedHat' { + class { 'erlang': epel_enable => true} + Class['erlang'] -> Class['rabbitmq'] + } + EOS + + # clean up previous 3.x install - can't be ungraded cleanly via RPM + shell('service rabbitmq-server stop') + shell('yum -y erase rabbitmq-server') + shell('rm -Rf /var/lib/rabbitmq/mnesia /etc/rabbitmq /var/lib/rabbitmq/rabbitmqadmin') + # Apply twice to ensure no errors the second time. + apply_manifest(pp, :catch_failures => true) + expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero + # DEBUG + shell('netstat -lntp') + end + + describe command('rabbitmqctl status') do + its(:stdout) { should match /{rabbit,"RabbitMQ","2.8.1"}/ } + end + + describe package(package_name) do + it { should be_installed } + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end end - describe service(service_name) do - it { should be_enabled } - it { should be_running } + context "disable and stop service" do + it 'should run successfully' do + pp = <<-EOS + class { 'rabbitmq': + version => '2.8.1-1', + package_source => '#{package_source}', + package_ensure => '#{package_ensure}', + package_provider => 'rpm', + management_port => '55672', + service_ensure => 'stopped', + admin_enable => false, + } + if $::osfamily == 'RedHat' { + class { 'erlang': epel_enable => true} + Class['erlang'] -> Class['rabbitmq'] + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + + describe service(service_name) do + it { should_not be_enabled } + it { should_not be_running } + end end - end - context "disable and stop service" do - it 'should run successfully' do - pp = <<-EOS - class { 'rabbitmq': - version => '2.8.1-1', - package_source => '#{package_source}', - package_ensure => '#{package_ensure}', - package_provider => 'rpm', - management_port => '55672', - service_ensure => 'stopped', - admin_enable => false, - } - if $::osfamily == 'RedHat' { - class { 'erlang': epel_enable => true} - Class['erlang'] -> Class['rabbitmq'] - } - EOS - - apply_manifest(pp, :catch_failures => true) + context "service is unmanaged" do + it 'should run successfully' do + pp_pre = <<-EOS + class { 'rabbitmq': + version => '2.8.1-1', + package_source => '#{package_source}', + package_ensure => '#{package_ensure}', + package_provider => 'rpm', + management_port => '55672', + } + if $::osfamily == 'RedHat' { + class { 'erlang': epel_enable => true} + Class['erlang'] -> Class['rabbitmq'] + } + EOS + + pp = <<-EOS + class { 'rabbitmq': + service_manage => false, + service_ensure => 'stopped', + } + if $::osfamily == 'RedHat' { + class { 'erlang': epel_enable => true} + Class['erlang'] -> Class['rabbitmq'] + } + EOS + + apply_manifest(pp_pre, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end end - describe service(service_name) do - it { should_not be_enabled } - it { should_not be_running } - end - end + context 'rabbitmqadmin' do + #confine :to, :platform => 'el-6-x86' + + it 'should run successfully' do + pp = <<-EOS + class { 'rabbitmq': + admin_enable => true, + service_manage => true, + version => '2.8.1-1', + package_source => '#{package_source}', + package_ensure => '#{package_ensure}', + package_provider => 'rpm', + management_port => '55672', + } + if $::osfamily == 'RedHat' { + class { 'erlang': epel_enable => true} + Class['erlang'] -> Class['rabbitmq'] + } + EOS + + shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') + apply_manifest(pp, :catch_failures => true) + end + + # since serverspec (used by beaker-rspec) can only tell present/absent for packages + describe file('/var/lib/rabbitmq/rabbitmqadmin') do + it { should be_file } + end + + describe command('/usr/local/bin/rabbitmqadmin --help') do + its(:exit_status) { should eq 0 } + end - context "service is unmanaged" do - it 'should run successfully' do - pp_pre = <<-EOS - class { 'rabbitmq': - version => '2.8.1-1', - package_source => '#{package_source}', - package_ensure => '#{package_ensure}', - package_provider => 'rpm', - management_port => '55672', - } - if $::osfamily == 'RedHat' { - class { 'erlang': epel_enable => true} - Class['erlang'] -> Class['rabbitmq'] - } - EOS - - pp = <<-EOS - class { 'rabbitmq': - service_manage => false, - service_ensure => 'stopped', - } - if $::osfamily == 'RedHat' { - class { 'erlang': epel_enable => true} - Class['erlang'] -> Class['rabbitmq'] - } - EOS - - apply_manifest(pp_pre, :catch_failures => true) - apply_manifest(pp, :catch_failures => true) end - describe service(service_name) do - it { should be_enabled } - it { should be_running } - end - end - - context 'rabbitmqadmin' do - #confine :to, :platform => 'el-6-x86' - - it 'should run successfully' do - pp = <<-EOS - class { 'rabbitmq': - admin_enable => true, - service_manage => true, - version => '2.8.1-1', - package_source => '#{package_source}', - package_ensure => '#{package_ensure}', - package_provider => 'rpm', - management_port => '55672', - } - if $::osfamily == 'RedHat' { - class { 'erlang': epel_enable => true} - Class['erlang'] -> Class['rabbitmq'] - } - EOS - - shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') - apply_manifest(pp, :catch_failures => true) - end - - # since serverspec (used by beaker-rspec) can only tell present/absent for packages - describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should be_file } - end - - describe command('/usr/local/bin/rabbitmqadmin --help') do - its(:exit_status) { should eq 0 } - end - - end - - context 'rabbitmqadmin with specified default credentials' do - - it 'should run successfully' do - # make sure credential change takes effect before admin_enable - pp = <<-EOS - class { 'rabbitmq': - admin_enable => true, - service_manage => true, - version => '2.8.1-1', - package_source => '#{package_source}', - package_ensure => '#{package_ensure}', - package_provider => 'rpm', - management_port => '55672', - default_user => 'foobar', - default_pass => 'bazblam', - } - if $::osfamily == 'RedHat' { - class { 'erlang': epel_enable => true} - Class['erlang'] -> Class['rabbitmq'] - } - EOS - - # next 3 lines - see MODULES-1085 - shell('service rabbitmq-server stop') - shell('rm -Rf /var/lib/rabbitmq/mnesia /var/lib/rabbitmq/rabbitmqadmin') - apply_manifest(pp, :catch_failures => true) - end - - # since serverspec (used by beaker-rspec) can only tell present/absent for packages - describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should be_file } - end + context 'rabbitmqadmin with specified default credentials' do + + it 'should run successfully' do + # make sure credential change takes effect before admin_enable + pp = <<-EOS + class { 'rabbitmq': + admin_enable => true, + service_manage => true, + version => '2.8.1-1', + package_source => '#{package_source}', + package_ensure => '#{package_ensure}', + package_provider => 'rpm', + management_port => '55672', + default_user => 'foobar', + default_pass => 'bazblam', + } + if $::osfamily == 'RedHat' { + class { 'erlang': epel_enable => true} + Class['erlang'] -> Class['rabbitmq'] + } + EOS + + # next 3 lines - see MODULES-1085 + shell('service rabbitmq-server stop') + shell('rm -Rf /var/lib/rabbitmq/mnesia /var/lib/rabbitmq/rabbitmqadmin') + apply_manifest(pp, :catch_failures => true) + end + + # since serverspec (used by beaker-rspec) can only tell present/absent for packages + describe file('/var/lib/rabbitmq/rabbitmqadmin') do + it { should be_file } + end + + describe command('/usr/local/bin/rabbitmqadmin --help') do + its(:exit_status) { should eq 0 } + end - describe command('/usr/local/bin/rabbitmqadmin --help') do - its(:exit_status) { should eq 0 } end end diff --git a/rabbitmq/spec/classes/rabbitmq_spec.rb b/rabbitmq/spec/classes/rabbitmq_spec.rb index 675a8759e..534ba4f1f 100644 --- a/rabbitmq/spec/classes/rabbitmq_spec.rb +++ b/rabbitmq/spec/classes/rabbitmq_spec.rb @@ -923,14 +923,14 @@ let(:params) {{ :tcp_keepalive => true }} it 'should set tcp_listen_options keepalive true' do should contain_file('rabbitmq.config') \ - .with_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/) + .with_content(/\{keepalive, true\}/) end end describe 'tcp_keepalive disabled (default)' do it 'should not set tcp_listen_options' do should contain_file('rabbitmq.config') \ - .without_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/) + .without_content(/\{keepalive, true\}/) end end diff --git a/rabbitmq/templates/rabbitmq.config.erb b/rabbitmq/templates/rabbitmq.config.erb index 4e2154e55..71b777621 100644 --- a/rabbitmq/templates/rabbitmq.config.erb +++ b/rabbitmq/templates/rabbitmq.config.erb @@ -12,9 +12,17 @@ {cluster_nodes, {[<%= @cluster_nodes.map { |n| "\'rabbit@#{n}\'" }.join(', ') %>], <%= @cluster_node_type %>}}, {cluster_partition_handling, <%= @cluster_partition_handling %>}, <% end -%> -<%- if @tcp_keepalive -%> - {tcp_listen_options, [{keepalive, true}]}, -<%- end -%> + {tcp_listen_options, + [binary, + <%- if @tcp_keepalive -%> + {keepalive, true}, + <%- end -%> + {packet, raw}, + {reuseaddr, true}, + {backlog, 128}, + {nodelay, true}, + {exit_on_close, false}] + }, <%- if @ssl_only -%> {tcp_listeners, []}, <%- elsif @interface != 'UNSET' -%> diff --git a/redis/manifests/install.pp b/redis/manifests/install.pp index bfa7d0746..22c4abee5 100644 --- a/redis/manifests/install.pp +++ b/redis/manifests/install.pp @@ -3,8 +3,10 @@ # This class installs the application. # class redis::install { - ensure_resource('package', $::redis::package_name, { - 'ensure' => $::redis::package_ensure - }) + unless defined(Package["$::redis::package_name"]) { + ensure_resource('package', $::redis::package_name, { + 'ensure' => $::redis::package_ensure + }) + } } diff --git a/redis/manifests/params.pp b/redis/manifests/params.pp index 2a2cbaa1a..42a750f73 100644 --- a/redis/manifests/params.pp +++ b/redis/manifests/params.pp @@ -76,7 +76,7 @@ $config_file = '/etc/redis/redis.conf' $config_file_mode = '0644' $config_group = 'root' - $config_owner = 'root' + $config_owner = 'redis' $daemonize = true $log_dir_mode = '0755' $package_ensure = 'present' @@ -103,7 +103,7 @@ $config_file = '/etc/redis.conf' $config_file_mode = '0644' $config_group = 'root' - $config_owner = 'root' + $config_owner = 'redis' $daemonize = false $log_dir_mode = '0755' $package_ensure = 'present' @@ -121,6 +121,7 @@ $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' + $ppa_repo = undef } 'FreeBSD': { @@ -129,7 +130,7 @@ $config_file = '/usr/local/etc/redis.conf' $config_file_mode = '0644' $config_group = 'wheel' - $config_owner = 'root' + $config_owner = 'redis' $daemonize = true $log_dir_mode = '0755' $package_ensure = 'present' @@ -147,6 +148,7 @@ $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' + $ppa_repo = undef } 'Suse': { @@ -173,6 +175,7 @@ $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' + $ppa_repo = undef } default: { diff --git a/redis/manifests/sentinel.pp b/redis/manifests/sentinel.pp index 6bb9243aa..24d4ff138 100644 --- a/redis/manifests/sentinel.pp +++ b/redis/manifests/sentinel.pp @@ -170,10 +170,11 @@ $notification_script = $::redis::params::sentinel_notification_script, ) inherits redis::params { - - ensure_resource('package', $package_name, { - 'ensure' => $package_ensure - }) + unless defined(Package["$package_name"]) { + ensure_resource('package', $package_name, { + 'ensure' => $package_ensure + }) + } file { $config_file_orig: diff --git a/redis/metadata.json b/redis/metadata.json index 29f615df2..6fa158cd1 100644 --- a/redis/metadata.json +++ b/redis/metadata.json @@ -1,6 +1,6 @@ { "name": "arioch-redis", - "version": "1.0.6", + "version": "1.0.7", "author": "Tom De Vylder", "summary": "Redis module", "license": "Apache License, Version 2.0", diff --git a/sahara/.gitreview b/sahara/.gitreview index c9b04466b..7420f8c93 100644 --- a/sahara/.gitreview +++ b/sahara/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-sahara.git +project=openstack/puppet-sahara.git diff --git a/sahara/Gemfile b/sahara/Gemfile index f36bf808f..248993a69 100644 --- a/sahara/Gemfile +++ b/sahara/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -17,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/sahara/manifests/notify/rabbitmq.pp b/sahara/manifests/notify/rabbitmq.pp index 1cb2a7cd0..cf0ce4e1c 100644 --- a/sahara/manifests/notify/rabbitmq.pp +++ b/sahara/manifests/notify/rabbitmq.pp @@ -107,68 +107,68 @@ if $rabbit_use_ssl { if $kombu_ssl_ca_certs { - sahara_config { 'DEFAULT/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } + sahara_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': value => $kombu_ssl_ca_certs; } } else { - sahara_config { 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; } + sahara_config { 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; } } if $kombu_ssl_certfile or $kombu_ssl_keyfile { sahara_config { - 'DEFAULT/kombu_ssl_certfile': value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; + 'oslo_messaging_rabbit/kombu_ssl_certfile': value => $kombu_ssl_certfile; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': value => $kombu_ssl_keyfile; } } else { sahara_config { - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; } } if $kombu_ssl_version { - sahara_config { 'DEFAULT/kombu_ssl_version': value => $kombu_ssl_version; } + sahara_config { 'oslo_messaging_rabbit/kombu_ssl_version': value => $kombu_ssl_version; } } else { - sahara_config { 'DEFAULT/kombu_ssl_version': ensure => absent; } + sahara_config { 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } } else { sahara_config { - 'DEFAULT/kombu_ssl_ca_certs': ensure => absent; - 'DEFAULT/kombu_ssl_certfile': ensure => absent; - 'DEFAULT/kombu_ssl_keyfile': ensure => absent; - 'DEFAULT/kombu_ssl_version': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_ca_certs': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_certfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_keyfile': ensure => absent; + 'oslo_messaging_rabbit/kombu_ssl_version': ensure => absent; } } if $rabbit_hosts { sahara_config { - 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ','); - 'DEFAULT/rabbit_ha_queues': value => true + 'oslo_messaging_rabbit/rabbit_hosts': value => join($rabbit_hosts, ','); + 'oslo_messaging_rabbit/rabbit_ha_queues': value => true; } } else { sahara_config { - 'DEFAULT/rabbit_host': value => $rabbit_host; - 'DEFAULT/rabbit_port': value => $rabbit_port; - 'DEFAULT/rabbit_ha_queues': value => false; + 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host; + 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port; + 'oslo_messaging_rabbit/rabbit_ha_queues': value => false; # single-quotes to get literal dollar signs - 'DEFAULT/rabbit_hosts': value => '$rabbit_host:$rabbit_port'; + 'oslo_messaging_rabbit/rabbit_hosts': value => '$rabbit_host:$rabbit_port'; } } sahara_config { - 'DEFAULT/rpc_backend': value => 'rabbit'; + 'oslo_messaging_rabbit/rpc_backend': value => 'rabbit'; 'DEFAULT/amqp_durable_queues': value => $durable_queues; - 'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; - 'DEFAULT/rabbit_userid': value => $rabbit_userid; - 'DEFAULT/rabbit_password': + 'oslo_messaging_rabbit/rabbit_use_ssl': value => $rabbit_use_ssl; + 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_userid; + 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_login_method': value => $rabbit_login_method; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/rabbit_retry_interval': value => $rabbit_retry_interval; - 'DEFAULT/rabbit_retry_backoff': value => $rabbit_retry_backoff; - 'DEFAULT/rabbit_max_retries': value => $rabbit_max_retries; + 'oslo_messaging_rabbit/rabbit_login_method': value => $rabbit_login_method; + 'oslo_messaging_rabbit/rabbit_virtual_host': value => $rabbit_virtual_host; + 'oslo_messaging_rabbit/rabbit_retry_interval': value => $rabbit_retry_interval; + 'oslo_messaging_rabbit/rabbit_retry_backoff': value => $rabbit_retry_backoff; + 'oslo_messaging_rabbit/rabbit_max_retries': value => $rabbit_max_retries; 'DEFAULT/notification_topics': value => $notification_topics; 'DEFAULT/control_exchange': value => $control_exchange; - 'DEFAULT/kombu_reconnect_delay': value => $kombu_reconnect_delay; + 'oslo_messaging_rabbit/kombu_reconnect_delay': value => $kombu_reconnect_delay; } } diff --git a/sahara/spec/acceptance/nodesets/nodepool-centos7.yml b/sahara/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/sahara/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/sahara/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/sahara/spec/acceptance/nodesets/nodepool-trusty.yml b/sahara/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/sahara/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/sahara/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/sahara/spec/classes/sahara_notify_rabbitmq_spec.rb b/sahara/spec/classes/sahara_notify_rabbitmq_spec.rb index 40cdc67f6..12ff938d9 100644 --- a/sahara/spec/classes/sahara_notify_rabbitmq_spec.rb +++ b/sahara/spec/classes/sahara_notify_rabbitmq_spec.rb @@ -10,15 +10,15 @@ let :params do {:rabbit_password => 'pass'} end - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_password').with_value('pass') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_password').with_value(params[:rabbit_password]).with_secret(true) } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_userid').with_value('guest') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_host').with_value('localhost') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_port').with_value('5672') } - xit { is_expected.to contain_sahara_config('DEFAULT/rabbit_hosts').with_value('localhost:5672') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_ha_queues').with_value('false') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_password').with_value('pass') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_password').with_value(params[:rabbit_password]).with_secret(true) } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('5672') } + xit { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value('localhost:5672') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') } it { is_expected.to contain_sahara_config('DEFAULT/amqp_durable_queues').with_value('false') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_virtual_host').with_value('/') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value('/') } it { is_expected.to contain_sahara_config('DEFAULT/control_exchange').with_value('openstack') } it { is_expected.to contain_sahara_config('DEFAULT/notification_topics').with_value('notifications') } end @@ -32,10 +32,10 @@ :rabbit_port => '5673', :durable_queues => true, } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_userid').with_value('guest2') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_host').with_value('localhost2') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_port').with_value('5673') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_durable_queues').with_value('true') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_durable_queues').with_value('true') } end end @@ -50,11 +50,11 @@ } end - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_use_ssl').with_value('true') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_ca_certs').with_value('/etc/ca.cert') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_certfile').with_value('/etc/certfile') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_keyfile').with_value('/etc/key') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/etc/ca.cert') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/etc/certfile') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/etc/key') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } end describe 'with rabbit ssl cert parameters' do @@ -65,8 +65,8 @@ } end - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_use_ssl').with_value('true') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_version').with_value('TLSv1') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } end describe 'with rabbit ssl disabled' do @@ -80,11 +80,11 @@ } end - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_use_ssl').with_value('false') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent') } - it { is_expected.to contain_sahara_config('DEFAULT/kombu_ssl_version').with_ensure('absent') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_ensure('absent') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_ensure('absent') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_ensure('absent') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_version').with_ensure('absent') } end describe 'when passing params for single rabbit host' do @@ -97,10 +97,10 @@ :durable_queues => true, } end - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_userid').with_value('guest2') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_host').with_value('localhost2') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_port').with_value('5673') } - xit { is_expected.to contain_sahara_config('DEFAULT/rabbit_hosts').with_value('localhost2:5673') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } + xit { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value('localhost2:5673') } it { is_expected.to contain_sahara_config('DEFAULT/amqp_durable_queues').with_value('true') } end @@ -112,12 +112,12 @@ :rabbit_hosts => ['nonlocalhost3:5673', 'nonlocalhost4:5673'] } end - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_userid').with_value('guest3') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_hosts').with_value( + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest3') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value( 'nonlocalhost3:5673,nonlocalhost4:5673') } - it { is_expected.to contain_sahara_config('DEFAULT/rabbit_ha_queues').with_value('true') } - it { is_expected.to_not contain_sahara_config('DEFAULT/rabbit_port') } - it { is_expected.to_not contain_sahara_config('DEFAULT/rabbit_host') } + it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } + it { is_expected.to_not contain_sahara_config('oslo_messaging_rabbit/rabbit_port') } + it { is_expected.to_not contain_sahara_config('oslo_messaging_rabbit/rabbit_host') } end describe 'when using deprecated params' do diff --git a/ssh/.gitignore b/ssh/.gitignore index f83f4b238..a2197b247 100644 --- a/ssh/.gitignore +++ b/ssh/.gitignore @@ -1,3 +1,5 @@ pkg/ *.swp .DS_Store +Gemfile.lock +vendor/ diff --git a/ssh/README.markdown b/ssh/README.markdown index 665c5a549..0298992ad 100644 --- a/ssh/README.markdown +++ b/ssh/README.markdown @@ -27,7 +27,7 @@ port 22 and 2222) should be passed as an array. This is working for both, client and server. -### Both client and server +### Both client, server and per user client configuration Host keys will be collected and distributed unless `storeconfigs_enabled` is `false`. @@ -55,6 +55,15 @@ or 'User' => 'ec2-user', }, }, + users_client_options => { + 'bob' => { + options => { + 'Host *.alice.fr' => { + 'User' => 'alice', + }, + }, + }, + }, } ``` @@ -77,6 +86,13 @@ ssh::client_options: SendEnv: 'LANG LC_*' ForwardX11Trusted: 'yes' ServerAliveInterval: '10' + +ssh::users_client_options: + 'bob': + 'options': + 'Host *.alice.fr': + 'User': 'alice' + 'PasswordAuthentication': 'no' ``` ### Client only @@ -105,6 +121,63 @@ or } ``` +### Per user client configuration + +**User's home is expected to be /home/bob** + +SSH configuration file will be `/home/bob/.ssh/config`. + +```puppet +::ssh::client::config::user { 'bob': + ensure => present, + options => { + 'HashKnownHosts' => 'yes' + } +} +``` + +**User's home is passed to define type** + +SSH configuration file will be `/var/lib/bob/.ssh/config` and puppet will +manage directory `/var/lib/bob/.ssh`. + +```puppet +::ssh::client::config::user { 'bob': + ensure => present, + user_home_dir => '/var/lib/bob', + options => { + 'HashKnownHosts' => 'yes' + } +} +``` + +**User's ssh directory should not be managed by the define type** + +SSH configuration file will be `/var/lib/bob/.ssh/config`. + +```puppet +::ssh::client::config::user { 'bob': + ensure => present, + user_home_dir => '/var/lib/bob', + manage_user_ssh_dir => false, + options => { + 'HashKnownHosts' => 'yes' + } +} +``` + +**User's ssh config is specified with an absolute path** + +```puppet +::ssh::client::config::user { 'bob': + ensure => present, + target => '/var/lib/bob/.ssh/ssh_config', + options => { + 'HashKnownHosts' => 'yes' + } +} +``` + ### Server only Host keys will be collected for client distribution unless `storeconfigs_enabled` is `false` diff --git a/ssh/manifests/client/config.pp b/ssh/manifests/client/config.pp index 3e4c7afcd..2f8a5d8e0 100644 --- a/ssh/manifests/client/config.pp +++ b/ssh/manifests/client/config.pp @@ -1,4 +1,7 @@ -class ssh::client::config { +class ssh::client::config +{ + $options = $::ssh::client::merged_options + file { $ssh::params::ssh_config: ensure => present, owner => '0', diff --git a/ssh/manifests/client/config/user.pp b/ssh/manifests/client/config/user.pp new file mode 100644 index 000000000..a9d2ef246 --- /dev/null +++ b/ssh/manifests/client/config/user.pp @@ -0,0 +1,56 @@ +# +# Copyright (c) IN2P3 Computing Centre, IN2P3, CNRS +# Contributor: Remi Ferrand (2015) +# +define ssh::client::config::user( + $ensure = present, + $target = undef, + $user_home_dir = undef, + $manage_user_ssh_dir = true, + $options = {} +) +{ + validate_re($ensure, '^(present|absent)$') + validate_hash($options) + validate_bool($manage_user_ssh_dir) + + include ::ssh::params + + $_files_ensure = $ensure ? { 'present' => 'file', 'absent' => 'absent' } + + # If a specific target file was specified, + # it must have higher priority than any + # other parameter. + if ($target != undef) { + validate_absolute_path($target) + $_target = $target + } + else { + if ($user_home_dir == undef) { + $_user_home_dir = "/home/${name}" + } + else { + validate_absolute_path($user_home_dir) + $_user_home_dir = $user_home_dir + } + + $user_ssh_dir = "${_user_home_dir}/.ssh" + $_target = "${user_ssh_dir}/config" + + if ($manage_user_ssh_dir == true) { + file { $user_ssh_dir: + ensure => directory, + owner => $name, + mode => $::ssh::params::user_ssh_directory_default_mode, + before => File[$_target] + } + } + } + + file { $_target: + ensure => $_files_ensure, + owner => $name, + mode => $::ssh::params::user_ssh_config_default_mode, + content => template("${module_name}/ssh_config.erb") + } +} diff --git a/ssh/manifests/init.pp b/ssh/manifests/init.pp index 3906b295b..8f89ce5f1 100644 --- a/ssh/manifests/init.pp +++ b/ssh/manifests/init.pp @@ -1,13 +1,20 @@ class ssh ( $server_options = {}, $client_options = {}, + $users_client_options = {}, $version = 'present', $storeconfigs_enabled = true ) inherits ssh::params { + validate_hash($server_options) + validate_hash($client_options) + validate_hash($users_client_options) + validate_bool($storeconfigs_enabled) + # Merge hashes from multiple layer of hierarchy in hiera $hiera_server_options = hiera_hash("${module_name}::server_options", undef) $hiera_client_options = hiera_hash("${module_name}::client_options", undef) + $hiera_users_client_options = hiera_hash("${module_name}::users_client_options", undef) $fin_server_options = $hiera_server_options ? { undef => $server_options, @@ -15,19 +22,26 @@ } $fin_client_options = $hiera_client_options ? { - undef => $server_options, + undef => $client_options, default => $hiera_client_options, } + $fin_users_client_options = $hiera_users_client_options ? { + undef => $users_client_options, + default => $hiera_users_client_options, + } + class { 'ssh::server': + ensure => $version, storeconfigs_enabled => $storeconfigs_enabled, options => $fin_server_options, - ensure => $version, } class { 'ssh::client': + ensure => $version, storeconfigs_enabled => $storeconfigs_enabled, options => $fin_client_options, - ensure => $version, } + + create_resources('::ssh::client::config::user', $fin_users_client_options) } diff --git a/ssh/manifests/params.pp b/ssh/manifests/params.pp index 787d192ff..f93f1bbe5 100644 --- a/ssh/manifests/params.pp +++ b/ssh/manifests/params.pp @@ -131,4 +131,7 @@ 'HashKnownHosts' => 'yes', }, } + + $user_ssh_directory_default_mode = '0700' + $user_ssh_config_default_mode = '0600' } diff --git a/ssh/manifests/server.pp b/ssh/manifests/server.pp index a07240eec..14e40ac0b 100644 --- a/ssh/manifests/server.pp +++ b/ssh/manifests/server.pp @@ -9,6 +9,7 @@ $fin_options = $hiera_options ? { undef => $options, + '' => $options, default => $hiera_options, } @@ -18,8 +19,6 @@ include ssh::server::config include ssh::server::service - File[$ssh::params::sshd_config] ~> Service[$ssh::params::service_name] - anchor { 'ssh::server::start': } anchor { 'ssh::server::end': } diff --git a/ssh/manifests/server/config.pp b/ssh/manifests/server/config.pp index c71a17c6b..8bb961bd9 100644 --- a/ssh/manifests/server/config.pp +++ b/ssh/manifests/server/config.pp @@ -1,11 +1,11 @@ class ssh::server::config { - File[$ssh::params::sshd_config] ~> Service[$ssh::params::service_name] concat { $ssh::params::sshd_config: ensure => present, owner => '0', group => '0', mode => '0600', + notify => Service[$ssh::params::service_name] } concat::fragment { 'global config': diff --git a/ssh/manifests/server/match_block.pp b/ssh/manifests/server/match_block.pp index ddb06ff30..1ff975ff4 100644 --- a/ssh/manifests/server/match_block.pp +++ b/ssh/manifests/server/match_block.pp @@ -1,4 +1,4 @@ -define ssh::server::match_block ($type = 'user', $order = 50, $options,) { +define ssh::server::match_block ($options, $type = 'user', $order = 50,) { concat::fragment { "match_block ${name}": target => $ssh::params::sshd_config, content => template("${module_name}/sshd_match_block.erb"), diff --git a/ssh/metadata.json b/ssh/metadata.json index f7efdfce1..582f856a3 100644 --- a/ssh/metadata.json +++ b/ssh/metadata.json @@ -42,11 +42,11 @@ } ], "name": "saz-ssh", - "version": "2.6.0", + "version": "2.8.1", "source": "git://github.com/saz/puppet-ssh.git", "author": "saz", "license": "Apache License, Version 2.0", - "summary": "UNKNOWN", + "summary": "Manage SSH client and server via Puppet.", "description": "Manage SSH client and server via puppet", "project_page": "https://github.com/saz/puppet-ssh", "dependencies": [ diff --git a/ssh/spec/defines/client/config/user_spec.rb b/ssh/spec/defines/client/config/user_spec.rb new file mode 100644 index 000000000..7d3479c81 --- /dev/null +++ b/ssh/spec/defines/client/config/user_spec.rb @@ -0,0 +1,167 @@ +require 'spec_helper' + +describe 'ssh::client::config::user', :type => :define do + + let :title do + 'riton' + end + + let :ssh_options do { + 'HashKnownHosts' => 'yes', + 'Host *.in2p3.fr' => { + 'User' => 'riton', + 'GSSAPIAuthentication' => 'no' + } + } end + + let :facts do { + :osfamily => 'RedHat', + :concat_basedir => '/tmp' + } end + + + describe 'with invalid parameters' do + + params = { + :ensure => [ 'somestate', 'does not' ], + :target => [ './somedir', 'is not an absolute path' ], + :user_home_dir => [ './somedir', 'is not an absolute path' ], + :manage_user_ssh_dir => [ 'maybe', 'is not a boolean' ], + :options => [ 'the_options', 'is not a Hash' ] + } + + params.each do |param, value| + + context "with invalid value for #{param.to_s}" do + let :params do { + param => value[0] + } end + + it 'should fail' do + expect { + should compile + }.to raise_error(/#{value[1]}/) + end + end + + end # params.each + end # describe 'with invalid parameters' + + describe 'with correct values' do + + describe 'with a user provided target' do + + let :target do + '/root/.ssh/config' + end + + let :params do { + :target => target + } end + + it do + should contain_file(target).with({ + :ensure => 'file', + :owner => title, + :mode => '0600' + }) + end + + end # describe 'with a user provided target' + + describe 'user_home_dir behavior' do + + context 'with a user provided user_home_dir' do + + let :user_home_dir do + '/path/to/home' + end + + context 'with manage_user_ssh_dir default value' do + + let :params do { + :user_home_dir => user_home_dir + } end + + it 'should contain ssh directory and ssh config' do + + should contain_file("#{user_home_dir}/.ssh").with({ + :ensure => 'directory', + :owner => title, + :mode => '0700' + }).that_comes_before("File[#{user_home_dir}/.ssh/config]") + + should contain_file("#{user_home_dir}/.ssh/config").with({ + :ensure => 'file', + :owner => title, + :mode => '0600' + }) + end + + end # context 'with manage_user_ssh_dir default value' + + context 'with manage_user_ssh_dir set to false' do + + let :params do { + :user_home_dir => user_home_dir, + :manage_user_ssh_dir => false + } end + + it do + should_not contain_file("#{user_home_dir}/.ssh") + end + + end # context 'with manage_user_ssh_dir set to false' + + end # context 'with a user provided user_home_dir' + + context 'with no user provided user_home_dir' do + it 'with manage_user_ssh_dir default value' do + should contain_file("/home/#{title}/.ssh").that_comes_before("File[/home/#{title}/.ssh/config]") + should contain_file("/home/#{title}/.ssh/config") + end + + context 'with manage_user_ssh_dir set to false' do + let :params do { + :manage_user_ssh_dir => false + } end + + it do + should_not contain_file("/home/#{title}/.ssh") + end + + it do + should contain_file("/home/#{title}/.ssh/config") + end + + end # context 'with manage_user_ssh_dir set to false' + + end # context 'with no user provided user_home_dir' + + end # describe 'user_home_dir behavior' + + describe 'ssh configuration content' do + + let :params do { + :options => ssh_options + } end + + it 'should have single value' do + should contain_file("/home/#{title}/.ssh/config").with({ + :content => /HashKnownHosts\s+yes/ + }) + end + + it 'should have Hash value' do + should contain_file("/home/#{title}/.ssh/config").with({ + :content => /Host \*\.in2p3\.fr\s*\n\s+GSSAPIAuthentication\s+no\s*\n\s+User\s+riton/ + }) + end + + end + + end # describe 'with correct values' + +end + +# vim: tabstop=2 shiftwidth=2 softtabstop=2 diff --git a/ssh/templates/ssh_config.erb b/ssh/templates/ssh_config.erb index 70580e6fa..c8061c0f0 100644 --- a/ssh/templates/ssh_config.erb +++ b/ssh/templates/ssh_config.erb @@ -11,7 +11,8 @@ end end -%> -<%- scope.lookupvar('ssh::client::merged_options').sort.each do |k, v| -%> + +<%- @options.sort.each do |k, v| -%> <%- if v.is_a?(Hash) -%> <%= k %> <%- v.sort.each do |key, value| -%> diff --git a/ssh/templates/sshd_config.erb b/ssh/templates/sshd_config.erb index 7e27f0e03..bd594a673 100644 --- a/ssh/templates/sshd_config.erb +++ b/ssh/templates/sshd_config.erb @@ -17,10 +17,10 @@ AddressFamily <%= addressfamily %> <%- end -%> <%- if port = options.delete('Port') -%> <%- if port.is_a?(Array) -%> -<%- port.reject{ |x| x.strip.empty? }.each do |p| -%> +<%- port.reject{ |x| x.to_s.strip.empty? }.each do |p| -%> Port <%= p %> <%- end -%> -<%- elsif not port.strip.empty? -%> +<%- elsif not port.to_s.strip.empty? -%> Port <%= port %> <%- end -%> <%- end -%> diff --git a/stdlib/.gitignore b/stdlib/.gitignore index b5db85e05..37c4f5968 100644 --- a/stdlib/.gitignore +++ b/stdlib/.gitignore @@ -1,9 +1,12 @@ -pkg/ -Gemfile.lock -vendor/ -spec/fixtures/ -.vagrant/ -.bundle/ -coverage/ -.idea/ +/pkg/ +/Gemfile.lock +/vendor/ +/spec/fixtures/manifests/* +/spec/fixtures/modules/* +!/spec/fixtures/modules/stdlib +!/spec/fixtures/modules/stdlib/* +/.vagrant/ +/.bundle/ +/coverage/ +/.idea/ *.iml diff --git a/stdlib/.travis.yml b/stdlib/.travis.yml index 371586b97..6fad7a4ad 100644 --- a/stdlib/.travis.yml +++ b/stdlib/.travis.yml @@ -1,6 +1,7 @@ --- sudo: false language: ruby +cache: bundler bundler_args: --without system_tests script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'" matrix: @@ -16,8 +17,5 @@ matrix: env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - rvm: 2.1.6 env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" - allow_failures: - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/stdlib/CHANGELOG.md b/stdlib/CHANGELOG.md index eef04737b..7c3331460 100644 --- a/stdlib/CHANGELOG.md +++ b/stdlib/CHANGELOG.md @@ -90,7 +90,7 @@ backwards-compatible with the stdlib 3 series. It adds two new functions, one bu #### Features - New `bool2str()` function -- New `camalcase()` function +- New `camelcase()` function #### Bugfixes - Fix `has_interface_with()` when interfaces fact is nil diff --git a/stdlib/Gemfile b/stdlib/Gemfile index 82a520427..64c906632 100644 --- a/stdlib/Gemfile +++ b/stdlib/Gemfile @@ -13,10 +13,12 @@ end group :development, :unit_tests do gem 'rake', '~> 10.1.0', :require => false gem 'rspec', '~> 3.1.0', :require => false - gem 'rspec-puppet', :require => false + gem 'rspec-puppet', '~> 2.2', :require => false gem 'mocha', :require => false + # keep for its rake task for now gem 'puppetlabs_spec_helper', :require => false gem 'puppet-lint', :require => false + gem 'metadata-json-lint', :require => false gem 'pry', :require => false gem 'simplecov', :require => false end diff --git a/stdlib/README.markdown b/stdlib/README.markdown index c140af447..8ed3d9b24 100644 --- a/stdlib/README.markdown +++ b/stdlib/README.markdown @@ -259,7 +259,20 @@ fqdn_rand_string(10, '', 'custom seed') #### `fqdn_rotate` -Rotates an array a random number of times, based on a node's fqdn. *Type*: rvalue. +Rotates an array or string a random number of times, combining the `$fqdn` fact and an optional seed for repeatable randomness. + +*Usage:* +~~~ +fqdn_rotate(VALUE, [SEED]) +~~~ +*Examples:* +~~~ +fqdn_rotate(['a', 'b', 'c', 'd']) +fqdn_rotate('abcd') +fqdn_rotate([1, 2, 3], 'custom seed') +~~~ + +*Type*: rvalue. #### `get_module_path` diff --git a/stdlib/Rakefile b/stdlib/Rakefile index 4ed1327a3..e136b8e41 100644 --- a/stdlib/Rakefile +++ b/stdlib/Rakefile @@ -1,18 +1,7 @@ require 'rubygems' +# keep for compatibility for now require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] -desc "Validate manifests, templates, and ruby files in lib." -task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" - end - Dir['lib/**/*.rb'].each do |lib_file| - sh "ruby -c #{lib_file}" - end - Dir['templates/**/*.erb'].each do |template| - sh "erb -P -x -T '-' #{template} | ruby -c" - end -end diff --git a/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb b/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb index d9741a02f..b66431d1e 100644 --- a/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb +++ b/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb @@ -2,16 +2,23 @@ # fqdn_rotate.rb # -module Puppet::Parser::Functions - newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS -Rotates an array a random number of times based on a nodes fqdn. - EOS - ) do |arguments| +Puppet::Parser::Functions.newfunction( + :fqdn_rotate, + :type => :rvalue, + :doc => "Usage: `fqdn_rotate(VALUE, [SEED])`. VALUE is required and + must be an array or a string. SEED is optional and may be any number + or string. + + Rotates VALUE a random number of times, combining the `$fqdn` fact and + the value of SEED for repeatable randomness. (That is, each node will + get a different random rotation from this function, but a given node's + result will be the same every time unless its hostname changes.) Adding + a SEED can be useful if you need more than one unrelated rotation.") do |args| raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 + "given (#{args.size} for 1)") if args.size < 1 - value = arguments[0] + value = args.shift require 'digest/md5' unless value.is_a?(Array) || value.is_a?(String) @@ -31,7 +38,7 @@ module Puppet::Parser::Functions elements = result.size - seed = Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex + seed = Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex # deterministic_rand() was added in Puppet 3.2.0; reimplement if necessary if Puppet::Util.respond_to?(:deterministic_rand) offset = Puppet::Util.deterministic_rand(seed, elements).to_i @@ -51,7 +58,6 @@ module Puppet::Parser::Functions result = string ? result.join : result return result - end end # vim: set ts=2 sw=2 et : diff --git a/stdlib/lib/puppet/parser/functions/getvar.rb b/stdlib/lib/puppet/parser/functions/getvar.rb index fb336b6ac..ae9c869d1 100644 --- a/stdlib/lib/puppet/parser/functions/getvar.rb +++ b/stdlib/lib/puppet/parser/functions/getvar.rb @@ -20,7 +20,9 @@ module Puppet::Parser::Functions end begin - self.lookupvar("#{args[0]}") + catch(:undefined_variable) do + self.lookupvar("#{args[0]}") + end rescue Puppet::ParseError # Eat the exception if strict_variables = true is set end diff --git a/stdlib/lib/puppet/parser/functions/is_mac_address.rb b/stdlib/lib/puppet/parser/functions/is_mac_address.rb index 1b3088a26..2619d44a3 100644 --- a/stdlib/lib/puppet/parser/functions/is_mac_address.rb +++ b/stdlib/lib/puppet/parser/functions/is_mac_address.rb @@ -15,7 +15,7 @@ module Puppet::Parser::Functions mac = arguments[0] - if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then + if /^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$/i.match(mac) then return true else return false diff --git a/stdlib/lib/puppet/parser/functions/member.rb b/stdlib/lib/puppet/parser/functions/member.rb index 88609ce5f..1e5b3def9 100644 --- a/stdlib/lib/puppet/parser/functions/member.rb +++ b/stdlib/lib/puppet/parser/functions/member.rb @@ -44,7 +44,7 @@ module Puppet::Parser::Functions end if arguments[1].is_a? String or arguments[1].is_a? Fixnum - item = Array(arguments[1]) + item = [arguments[1]] else item = arguments[1] end diff --git a/stdlib/lib/puppet/parser/functions/time.rb b/stdlib/lib/puppet/parser/functions/time.rb index 0cddaf86b..c5747474f 100644 --- a/stdlib/lib/puppet/parser/functions/time.rb +++ b/stdlib/lib/puppet/parser/functions/time.rb @@ -33,13 +33,14 @@ module Puppet::Parser::Functions ENV['TZ'] = time_zone - time = local_time.localtime + result = local_time.localtime.strftime('%s') ENV['TZ'] = original_zone + else + result = time.localtime.strftime('%s') end # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor. - result = time.strftime('%s') result = result.to_i return result diff --git a/stdlib/spec/acceptance/anchor_spec.rb b/stdlib/spec/acceptance/anchor_spec.rb new file mode 100755 index 000000000..5bc2bbb3b --- /dev/null +++ b/stdlib/spec/acceptance/anchor_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_acceptance' + +describe 'anchor type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'should effect proper chaining of resources' do + pp = <<-EOS + class anchored { + anchor { 'anchored::begin': } + ~> anchor { 'anchored::end': } + } + + class anchorrefresh { + notify { 'first': } + ~> class { 'anchored': } + ~> anchor { 'final': } + } + + include anchorrefresh + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Anchor\[final\]: Triggered 'refresh'/) + end + end + end +end diff --git a/stdlib/spec/acceptance/fqdn_rand_string_spec.rb b/stdlib/spec/acceptance/fqdn_rand_string_spec.rb index 8fe1a6955..881cff37e 100644 --- a/stdlib/spec/acceptance/fqdn_rand_string_spec.rb +++ b/stdlib/spec/acceptance/fqdn_rand_string_spec.rb @@ -39,6 +39,19 @@ expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/) end end + it 'generates random alphanumeric strings with custom charsets' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-eos + $l = 10 + $c = '0123456789' + $o = fqdn_rand_string($l, $c) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/) + end + end it 'generates random alphanumeric strings with custom seeds' do shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") pp = <<-eos @@ -52,6 +65,20 @@ expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/) end end + it 'generates random alphanumeric strings with custom charsets and seeds' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-eos + $l = 10 + $c = '0123456789' + $s = 'seed' + $o = fqdn_rand_string($l, $c, $s) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/) + end + end end describe 'failure' do it 'handles improper argument counts' diff --git a/stdlib/spec/acceptance/fqdn_rotate_spec.rb b/stdlib/spec/acceptance/fqdn_rotate_spec.rb index 753068bfe..f1a15d34e 100755 --- a/stdlib/spec/acceptance/fqdn_rotate_spec.rb +++ b/stdlib/spec/acceptance/fqdn_rotate_spec.rb @@ -27,7 +27,7 @@ shell("mkdir -p '#{facts_d}'") end end - it 'fqdn_rotates floats' do + it 'rotates arrays' do shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") pp = <<-EOS $a = ['a','b','c','d'] @@ -35,13 +35,51 @@ notice(inline_template('fqdn_rotate is <%= @o.inspect %>')) EOS + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rotate is \["d", "a", "b", "c"\]/) + end + end + it 'rotates arrays with custom seeds' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-EOS + $a = ['a','b','c','d'] + $s = 'seed' + $o = fqdn_rotate($a, $s) + notice(inline_template('fqdn_rotate is <%= @o.inspect %>')) + EOS + apply_manifest(pp, :catch_failures => true) do |r| expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/) end end + it 'rotates strings' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-EOS + $a = 'abcd' + $o = fqdn_rotate($a) + notice(inline_template('fqdn_rotate is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rotate is "dabc"/) + end + end + it 'rotates strings with custom seeds' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-EOS + $a = 'abcd' + $s = 'seed' + $o = fqdn_rotate($a, $s) + notice(inline_template('fqdn_rotate is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rotate is "cdab"/) + end + end end describe 'failure' do it 'handles improper argument counts' - it 'handles non-numbers' + it 'handles invalid arguments' end end diff --git a/stdlib/spec/classes/anchor_spec.rb b/stdlib/spec/classes/anchor_spec.rb deleted file mode 100755 index 2d4455e41..000000000 --- a/stdlib/spec/classes/anchor_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' -require 'puppet_spec/compiler' - -describe "anchorrefresh" do - include PuppetSpec::Compiler - - let :transaction do - apply_compiled_manifest(<<-ANCHORCLASS) - class anchored { - anchor { 'anchored::begin': } - ~> anchor { 'anchored::end': } - } - - class anchorrefresh { - notify { 'first': } - ~> class { 'anchored': } - ~> anchor { 'final': } - } - - include anchorrefresh - ANCHORCLASS - end - - it 'propagates events through the anchored class' do - resource = transaction.resource_status('Anchor[final]') - - expect(resource.restarted).to eq(true) - end -end diff --git a/stdlib/spec/fixtures/modules/stdlib/lib b/stdlib/spec/fixtures/modules/stdlib/lib new file mode 120000 index 000000000..b6ce6cc06 --- /dev/null +++ b/stdlib/spec/fixtures/modules/stdlib/lib @@ -0,0 +1 @@ +../../../../lib/ \ No newline at end of file diff --git a/stdlib/spec/fixtures/modules/stdlib/manifests b/stdlib/spec/fixtures/modules/stdlib/manifests new file mode 120000 index 000000000..cdcdae07c --- /dev/null +++ b/stdlib/spec/fixtures/modules/stdlib/manifests @@ -0,0 +1 @@ +../../../../manifests/ \ No newline at end of file diff --git a/stdlib/spec/functions/abs_spec.rb b/stdlib/spec/functions/abs_spec.rb index 3c25ce28f..7d2257b02 100755 --- a/stdlib/spec/functions/abs_spec.rb +++ b/stdlib/spec/functions/abs_spec.rb @@ -1,25 +1,30 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the abs function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("abs")).to eq("function_abs") - end +describe 'abs' do + it { is_expected.not_to eq(nil) } - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_abs([]) }.to( raise_error(Puppet::ParseError)) + describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } end - it "should convert a negative number into a positive" do - result = scope.function_abs(["-34"]) - expect(result).to(eq(34)) + describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do + it { pending "the puppet 4 implementation"; is_expected.to run.with_params().and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params([]).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params({}).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(true).and_raise_error(ArgumentError) } end - it "should do nothing with a positive number" do - result = scope.function_abs(["5678"]) - expect(result).to(eq(5678)) - end + it { is_expected.to run.with_params(-34).and_return(34) } + it { is_expected.to run.with_params("-34").and_return(34) } + it { is_expected.to run.with_params(34).and_return(34) } + it { is_expected.to run.with_params("34").and_return(34) } + it { is_expected.to run.with_params(-34.5).and_return(34.5) } + it { is_expected.to run.with_params("-34.5").and_return(34.5) } + it { is_expected.to run.with_params(34.5).and_return(34.5) } + it { is_expected.to run.with_params("34.5").and_return(34.5) } end diff --git a/stdlib/spec/functions/any2array_spec.rb b/stdlib/spec/functions/any2array_spec.rb index 87cd04b5e..70121f1e3 100755 --- a/stdlib/spec/functions/any2array_spec.rb +++ b/stdlib/spec/functions/any2array_spec.rb @@ -1,55 +1,15 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the any2array function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("any2array")).to eq("function_any2array") - end - - it "should return an empty array if there is less than 1 argument" do - result = scope.function_any2array([]) - expect(result).to(eq([])) - end - - it "should convert boolean true to [ true ] " do - result = scope.function_any2array([true]) - expect(result).to(eq([true])) - end - - it "should convert one object to [object]" do - result = scope.function_any2array(['one']) - expect(result).to(eq(['one'])) - end - - it "should convert multiple objects to [objects]" do - result = scope.function_any2array(['one', 'two']) - expect(result).to(eq(['one', 'two'])) - end - - it "should return empty array it was called with" do - result = scope.function_any2array([[]]) - expect(result).to(eq([])) - end - - it "should return one-member array it was called with" do - result = scope.function_any2array([['string']]) - expect(result).to(eq(['string'])) - end - - it "should return multi-member array it was called with" do - result = scope.function_any2array([['one', 'two']]) - expect(result).to(eq(['one', 'two'])) - end - - it "should return members of a hash it was called with" do - result = scope.function_any2array([{ 'key' => 'value' }]) - expect(result).to(eq(['key', 'value'])) - end - - it "should return an empty array if it was called with an empty hash" do - result = scope.function_any2array([{ }]) - expect(result).to(eq([])) - end +describe "any2array" do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_return([]) } + it { is_expected.to run.with_params(true).and_return([true]) } + it { is_expected.to run.with_params('one').and_return(['one']) } + it { is_expected.to run.with_params('one', 'two').and_return(['one', 'two']) } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['one']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two']).and_return(['one', 'two']) } + it { is_expected.to run.with_params({}).and_return([]) } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) } end diff --git a/stdlib/spec/functions/assert_private_spec.rb b/stdlib/spec/functions/assert_private_spec.rb index a009d28dc..98f2598ea 100755 --- a/stdlib/spec/functions/assert_private_spec.rb +++ b/stdlib/spec/functions/assert_private_spec.rb @@ -1,15 +1,7 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:assert_private) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - subject do - function_name = Puppet::Parser::Functions.function(:assert_private) - scope.method(function_name) - end - - context "when called from inside module" do +describe 'assert_private' do + context 'when called from inside module' do it "should not fail" do scope.expects(:lookupvar).with('module_name').returns('foo') scope.expects(:lookupvar).with('caller_module_name').returns('foo') diff --git a/stdlib/spec/functions/base64_spec.rb b/stdlib/spec/functions/base64_spec.rb index e93fafcd0..42512b3e9 100755 --- a/stdlib/spec/functions/base64_spec.rb +++ b/stdlib/spec/functions/base64_spec.rb @@ -1,34 +1,15 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the base64 function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64") - end - - it "should raise a ParseError if there are other than 2 arguments" do - expect { scope.function_base64([]) }.to(raise_error(Puppet::ParseError)) - expect { scope.function_base64(["asdf"]) }.to(raise_error(Puppet::ParseError)) - expect { scope.function_base64(["asdf","moo","cow"]) }.to(raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if argument 1 isn't 'encode' or 'decode'" do - expect { scope.function_base64(["bees","astring"]) }.to(raise_error(Puppet::ParseError, /first argument must be one of/)) - end - - it "should raise a ParseError if argument 2 isn't a string" do - expect { scope.function_base64(["encode",["2"]]) }.to(raise_error(Puppet::ParseError, /second argument must be a string/)) - end - - it "should encode a encoded string" do - result = scope.function_base64(["encode",'thestring']) - expect(result).to match(/\AdGhlc3RyaW5n\n\Z/) - end - it "should decode a base64 encoded string" do - result = scope.function_base64(["decode",'dGhlc3RyaW5n']) - expect(result).to eq('thestring') - end +describe 'base64' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("one").and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("one", "two", "three").and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("one", "two").and_raise_error(Puppet::ParseError, /first argument must be one of/) } + it { is_expected.to run.with_params("encode", ["two"]).and_raise_error(Puppet::ParseError, /second argument must be a string/) } + it { is_expected.to run.with_params("encode", 2).and_raise_error(Puppet::ParseError, /second argument must be a string/) } + + it { is_expected.to run.with_params("encode", "thestring").and_return("dGhlc3RyaW5n\n") } + it { is_expected.to run.with_params("decode", "dGhlc3RyaW5n").and_return("thestring") } + it { is_expected.to run.with_params("decode", "dGhlc3RyaW5n\n").and_return("thestring") } end diff --git a/stdlib/spec/functions/basename_spec.rb b/stdlib/spec/functions/basename_spec.rb index 8a2d0dc3d..0ea30e7a7 100755 --- a/stdlib/spec/functions/basename_spec.rb +++ b/stdlib/spec/functions/basename_spec.rb @@ -1,46 +1,13 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the basename function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("basename").should == "function_basename" - end - - it "should raise a ParseError if there is less than 1 argument" do - lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are more than 2 arguments" do - lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError)) - end - - it "should return basename for an absolute path" do - result = scope.function_basename(['/path/to/a/file.ext']) - result.should(eq('file.ext')) - end - - it "should return basename for a relative path" do - result = scope.function_basename(['path/to/a/file.ext']) - result.should(eq('file.ext')) - end - - it "should strip extention when extension specified (absolute path)" do - result = scope.function_basename(['/path/to/a/file.ext', '.ext']) - result.should(eq('file')) - end - - it "should strip extention when extension specified (relative path)" do - result = scope.function_basename(['path/to/a/file.ext', '.ext']) - result.should(eq('file')) - end - - it "should complain about non-string first argument" do - lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError)) - end - - it "should complain about non-string second argument" do - lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError)) - end +describe 'basename' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('file.ext') } + it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('file.ext') } + it { is_expected.to run.with_params('/path/to/a/file.ext', '.ext').and_return('file') } + it { is_expected.to run.with_params('relative_path/to/a/file.ext', '.ext').and_return('file') } end diff --git a/stdlib/spec/functions/bool2num_spec.rb b/stdlib/spec/functions/bool2num_spec.rb index 3904d7e40..e5068594b 100755 --- a/stdlib/spec/functions/bool2num_spec.rb +++ b/stdlib/spec/functions/bool2num_spec.rb @@ -1,38 +1,14 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the bool2num function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'bool2num' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } - it "should exist" do - expect(Puppet::Parser::Functions.function("bool2num")).to eq("function_bool2num") + [ true, 'true', AlsoString.new('true') ].each do |truthy| + it { is_expected.to run.with_params(truthy).and_return(1) } end - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert true to 1" do - result = scope.function_bool2num([true]) - expect(result).to(eq(1)) - end - - it "should convert 'true' to 1" do - result = scope.function_bool2num(['true']) - result.should(eq(1)) - end - - it "should convert 'false' to 0" do - result = scope.function_bool2num(['false']) - expect(result).to(eq(0)) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new('true') - result = scope.function_bool2num([value]) - result.should(eq(1)) + [ false, 'false', AlsoString.new('false') ].each do |falsey| + it { is_expected.to run.with_params(falsey).and_return(0) } end end diff --git a/stdlib/spec/functions/bool2str_spec.rb b/stdlib/spec/functions/bool2str_spec.rb index b87889180..8d35598e8 100755 --- a/stdlib/spec/functions/bool2str_spec.rb +++ b/stdlib/spec/functions/bool2str_spec.rb @@ -1,46 +1,11 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the bool2str function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert true to 'true'" do - result = scope.function_bool2str([true]) - expect(result).to(eq('true')) - end - - it "should convert true to a string" do - result = scope.function_bool2str([true]) - expect(result.class).to(eq(String)) - end - - it "should convert false to 'false'" do - result = scope.function_bool2str([false]) - expect(result).to(eq('false')) - end - - it "should convert false to a string" do - result = scope.function_bool2str([false]) - expect(result.class).to(eq(String)) - end - - it "should not accept a string" do - expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError)) - end - - it "should not accept a nil value" do - expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError)) - end - - it "should not accept an undef" do - expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError)) +describe 'bool2str' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + [ 'true', 'false', nil, :undef, ''].each do |invalid| + it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError) } end + it { is_expected.to run.with_params(true).and_return("true") } + it { is_expected.to run.with_params(false).and_return("false") } end diff --git a/stdlib/spec/functions/camelcase_spec.rb b/stdlib/spec/functions/camelcase_spec.rb index 70382adb1..c78aa62ff 100755 --- a/stdlib/spec/functions/camelcase_spec.rb +++ b/stdlib/spec/functions/camelcase_spec.rb @@ -1,24 +1,17 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the camelcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("camelcase")).to eq("function_camelcase") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_camelcase([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should capitalize the beginning of a normal string" do - result = scope.function_camelcase(["abc"]) - expect(result).to(eq("Abc")) - end - - it "should camelcase an underscore-delimited string" do - result = scope.function_camelcase(["aa_bb_cc"]) - expect(result).to(eq("AaBbCc")) - end +describe 'camelcase' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("abc").and_return("Abc") } + it { is_expected.to run.with_params("aa_bb_cc").and_return("AaBbCc") } + it { is_expected.to run.with_params("_aa__bb__cc_").and_return("AaBbCc") } + it { is_expected.to run.with_params("100").and_return("100") } + it { is_expected.to run.with_params("1_00").and_return("100") } + it { is_expected.to run.with_params("_").and_return("") } + it { is_expected.to run.with_params("").and_return("") } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(["abc", "aa_bb_cc"]).and_return(["Abc", "AaBbCc"]) } + it { is_expected.to run.with_params(["abc", 1, "aa_bb_cc"]).and_return(["Abc", 1, "AaBbCc"]) } end diff --git a/stdlib/spec/functions/capitalize_spec.rb b/stdlib/spec/functions/capitalize_spec.rb index fd0e92ba2..7ce2e1630 100755 --- a/stdlib/spec/functions/capitalize_spec.rb +++ b/stdlib/spec/functions/capitalize_spec.rb @@ -1,28 +1,15 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the capitalize function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("capitalize")).to eq("function_capitalize") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_capitalize([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should capitalize the beginning of a string" do - result = scope.function_capitalize(["abc"]) - expect(result).to(eq("Abc")) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new('abc') - result = scope.function_capitalize([value]) - result.should(eq('Abc')) - end +describe 'capitalize' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("one").and_return("One") } + it { is_expected.to run.with_params("one two").and_return("One two") } + it { is_expected.to run.with_params("ONE TWO").and_return("One two") } + + it { is_expected.to run.with_params(AlsoString.new("one")).and_return("One") } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(["one", "two"]).and_return(["One", "Two"]) } + it { is_expected.to run.with_params(["one", 1, "two"]).and_return(["One", 1, "Two"]) } end diff --git a/stdlib/spec/functions/ceiling_spec.rb b/stdlib/spec/functions/ceiling_spec.rb index 814aa7c01..567426fd3 100755 --- a/stdlib/spec/functions/ceiling_spec.rb +++ b/stdlib/spec/functions/ceiling_spec.rb @@ -1,39 +1,13 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the ceiling function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("ceiling")).to eq("function_ceiling") - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_ceiling([]) }.to( raise_error(Puppet::ParseError, /Wrong number of arguments/)) - end - - it "should should raise a ParseError if input isn't numeric (eg. String)" do - expect { scope.function_ceiling(["foo"]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/)) - end - - it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do - expect { scope.function_ceiling([true]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/)) - end - - it "should return an integer when a numeric type is passed" do - result = scope.function_ceiling([12.4]) - expect(result.is_a?(Integer)).to(eq(true)) - end - - it "should return the input when an integer is passed" do - result = scope.function_ceiling([7]) - expect(result).to(eq(7)) - end - - it "should return the smallest integer greater than or equal to the input" do - result = scope.function_ceiling([3.8]) - expect(result).to(eq(4)) - end +describe 'ceiling' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("foo").and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(34).and_return(34) } + it { is_expected.to run.with_params(-34).and_return(-34) } + it { is_expected.to run.with_params(33.1).and_return(34) } + it { is_expected.to run.with_params(-33.1).and_return(-33) } end diff --git a/stdlib/spec/functions/chomp_spec.rb b/stdlib/spec/functions/chomp_spec.rb index b1e1e60f3..687874292 100755 --- a/stdlib/spec/functions/chomp_spec.rb +++ b/stdlib/spec/functions/chomp_spec.rb @@ -1,28 +1,20 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the chomp function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'chomp' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params("a", "b").and_raise_error(Puppet::ParseError) + } + it { is_expected.to run.with_params("one").and_return("one") } + it { is_expected.to run.with_params("one\n").and_return("one") } + it { is_expected.to run.with_params("one\n\n").and_return("one\n") } + it { is_expected.to run.with_params(["one\n", "two", "three\n"]).and_return(["one", "two", "three"]) } - it "should exist" do - expect(Puppet::Parser::Functions.function("chomp")).to eq("function_chomp") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_chomp([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should chomp the end of a string" do - result = scope.function_chomp(["abc\n"]) - expect(result).to(eq("abc")) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new("abc\n") - result = scope.function_chomp([value]) - result.should(eq("abc")) - end + it { is_expected.to run.with_params(AlsoString.new("one")).and_return("one") } + it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return("one") } + it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") } + it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new("two"), "three\n"]).and_return(["one", "two", "three"]) } end diff --git a/stdlib/spec/functions/chop_spec.rb b/stdlib/spec/functions/chop_spec.rb index c8a19519a..db7d18b8c 100755 --- a/stdlib/spec/functions/chop_spec.rb +++ b/stdlib/spec/functions/chop_spec.rb @@ -1,28 +1,20 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the chop function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'chop' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params("a", "b").and_raise_error(Puppet::ParseError) + } + it { is_expected.to run.with_params("one").and_return("on") } + it { is_expected.to run.with_params("one\n").and_return("one") } + it { is_expected.to run.with_params("one\n\n").and_return("one\n") } + it { is_expected.to run.with_params(["one\n", "two", "three\n"]).and_return(["one", "tw", "three"]) } - it "should exist" do - expect(Puppet::Parser::Functions.function("chop")).to eq("function_chop") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_chop([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should chop the end of a string" do - result = scope.function_chop(["asdf\n"]) - expect(result).to(eq("asdf")) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new("abc\n") - result = scope.function_chop([value]) - result.should(eq('abc')) - end + it { is_expected.to run.with_params(AlsoString.new("one")).and_return("on") } + it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return("one") } + it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") } + it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new("two"), "three\n"]).and_return(["one", "tw", "three"]) } end diff --git a/stdlib/spec/functions/concat_spec.rb b/stdlib/spec/functions/concat_spec.rb index 49fa6bb36..1694d5ee5 100755 --- a/stdlib/spec/functions/concat_spec.rb +++ b/stdlib/spec/functions/concat_spec.rb @@ -1,50 +1,24 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the concat function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should raise a ParseError if the client does not provide at least two arguments" do - expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError)) - expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the first parameter is not an array" do - expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError)) - end - - it "should not raise a ParseError if the client provides more than two arguments" do - expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error - end - - it "should be able to concat an array" do - result = scope.function_concat([['1','2','3'],['4','5','6']]) - expect(result).to(eq(['1','2','3','4','5','6'])) - end - - it "should be able to concat a primitive to an array" do - result = scope.function_concat([['1','2','3'],'4']) - expect(result).to(eq(['1','2','3','4'])) - end - - it "should not accidentally flatten nested arrays" do - result = scope.function_concat([['1','2','3'],[['4','5'],'6']]) - expect(result).to(eq(['1','2','3',['4','5'],'6'])) - end +describe 'concat' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([1]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1, [2]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([1], [2], [3]).and_return([1, 2, 3]) } + it { is_expected.to run.with_params(['1','2','3'],['4','5','6']).and_return(['1','2','3','4','5','6']) } + it { is_expected.to run.with_params(['1','2','3'],'4').and_return(['1','2','3','4']) } + it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) } + it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) } + it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) } it "should leave the original array intact" do - array_original = ['1','2','3'] - result = scope.function_concat([array_original,['4','5','6']]) - array_original.should(eq(['1','2','3'])) - end - - it "should be able to concat multiple arrays" do - result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']]) - expect(result).to(eq(['1','2','3','4','5','6','7','8','9'])) - end - - it "should be able to concat mix of primitives and arrays to a final array" do - result = scope.function_concat([['1','2','3'],'4',['5','6','7']]) - expect(result).to(eq(['1','2','3','4','5','6','7'])) + argument1 = ['1','2','3'] + original1 = argument1.dup + argument2 = ['4','5','6'] + original2 = argument2.dup + result = subject.call([argument1,argument2]) + expect(argument1).to eq(original1) + expect(argument2).to eq(original2) end end diff --git a/stdlib/spec/functions/count_spec.rb b/stdlib/spec/functions/count_spec.rb index f8f1d4842..c8d19601c 100755 --- a/stdlib/spec/functions/count_spec.rb +++ b/stdlib/spec/functions/count_spec.rb @@ -1,31 +1,18 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the count function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("count")).to eq("function_count") - end - - it "should raise a ArgumentError if there is more than 2 arguments" do - expect { scope.function_count(['foo', 'bar', 'baz']) }.to( raise_error(ArgumentError)) - end - - it "should be able to count arrays" do - expect(scope.function_count([["1","2","3"]])).to(eq(3)) - end - - it "should be able to count matching elements in arrays" do - expect(scope.function_count([["1", "2", "2"], "2"])).to(eq(2)) - end - - it "should not count nil or empty strings" do - expect(scope.function_count([["foo","bar",nil,""]])).to(eq(2)) - end - - it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do - expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) - end +describe 'count' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError) } + it { is_expected.to run.with_params("one").and_raise_error(ArgumentError) } + it { is_expected.to run.with_params("one", "two").and_return(1) } + it { + pending("should actually be like this, and not like above") + is_expected.to run.with_params("one", "two").and_raise_error(ArgumentError) + } + it { is_expected.to run.with_params("one", "two", "three").and_raise_error(ArgumentError) } + it { is_expected.to run.with_params(["one", "two", "three"]).and_return(3) } + it { is_expected.to run.with_params(["one", "two", "two"], "two").and_return(2) } + it { is_expected.to run.with_params(["one", nil, "two"]).and_return(2) } + it { is_expected.to run.with_params(["one", "", "two"]).and_return(2) } + it { is_expected.to run.with_params(["one", :undef, "two"]).and_return(2) } end diff --git a/stdlib/spec/functions/deep_merge_spec.rb b/stdlib/spec/functions/deep_merge_spec.rb index 7087904a8..397e048ce 100755 --- a/stdlib/spec/functions/deep_merge_spec.rb +++ b/stdlib/spec/functions/deep_merge_spec.rb @@ -1,105 +1,55 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:deep_merge) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling deep_merge from puppet' do - it "should not compile when no arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$x = deep_merge()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when 1 argument is passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$my_hash={'one' => 1}\n$x = deep_merge($my_hash)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end +describe 'deep_merge' do + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, /unexpected argument type String/) } + it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) } + it { is_expected.to run.with_params({}, '').and_return({}) } + it { is_expected.to run.with_params({}, {}).and_return({}) } + it { is_expected.to run.with_params({}, {}, {}).and_return({}) } + it { is_expected.to run.with_params({}, {}, {}, {}).and_return({}) } + it { is_expected.to run.with_params({'key' => 'value'}, '').and_return({'key' => 'value'}) } + it { is_expected.to run.with_params({'key1' => 'value1'}, {'key2' => 'value2' }).and_return({'key1' => 'value1', 'key2' => 'value2'}) } + + describe 'when arguments have key collisions' do + it 'should prefer values from the last hash' do + is_expected.to run \ + .with_params( + {'key1' => 'value1', 'key2' => 'value2' }, + {'key2' => 'replacement_value', 'key3' => 'value3'}) \ + .and_return( + {'key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3'}) + end + it { is_expected.to run \ + .with_params({'key1' => 'value1'}, {'key1' => 'value2'}, {'key1' => 'value3'}) \ + .and_return({'key1' => 'value3' }) + } end - describe 'when calling deep_merge on the scope instance' do - it 'should require all parameters are hashes' do - expect { new_hash = scope.function_deep_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) - expect { new_hash = scope.function_deep_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) - end - - it 'should accept empty strings as puppet undef' do - expect { new_hash = scope.function_deep_merge([{}, ''])}.not_to raise_error - end - - it 'should be able to deep_merge two hashes' do - new_hash = scope.function_deep_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) - expect(new_hash['one']).to eq('1') - expect(new_hash['two']).to eq('2') - expect(new_hash['three']).to eq('2') - end - - it 'should deep_merge multiple hashes' do - hash = scope.function_deep_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - expect(hash['one']).to eq('3') - end - - it 'should accept empty hashes' do - expect(scope.function_deep_merge([{},{},{}])).to eq({}) - end - - it 'should deep_merge subhashes' do - hash = scope.function_deep_merge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }]) - expect(hash['one']).to eq(1) - expect(hash['two']).to eq(2) - expect(hash['three']).to eq({ 'four' => 4 }) - end - - it 'should append to subhashes' do - hash = scope.function_deep_merge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }]) - expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 }) - end - - it 'should append to subhashes 2' do - hash = scope.function_deep_merge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }]) - expect(hash['one']).to eq(1) - expect(hash['two']).to eq('dos') - expect(hash['three']).to eq({ 'four' => 4, 'five' => 5 }) - end - - it 'should append to subhashes 3' do - hash = scope.function_deep_merge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) - expect(hash['key1']).to eq({ 'a' => 1, 'b' => 99 }) - expect(hash['key2']).to eq({ 'c' => 3 }) - end - - it 'should not change the original hashes' do - hash1 = {'one' => { 'two' => 2 } } - hash2 = { 'one' => { 'three' => 3 } } - hash = scope.function_deep_merge([hash1, hash2]) - expect(hash1).to eq({'one' => { 'two' => 2 } }) - expect(hash2).to eq({ 'one' => { 'three' => 3 } }) - expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 }) - end + describe 'when arguments have subhashes' do + it { is_expected.to run \ + .with_params({'key1' => 'value1'}, {'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}}) \ + .and_return( {'key1' => 'value1', 'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}}) + } + it { is_expected.to run \ + .with_params({'key1' => {'subkey1' => 'value1'}}, {'key1' => {'subkey2' => 'value2'}}) \ + .and_return( {'key1' => {'subkey1' => 'value1', 'subkey2' => 'value2'}}) + } + it { is_expected.to run \ + .with_params({'key1' => {'subkey1' => {'subsubkey1' => 'value1'}}}, {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}}) \ + .and_return( {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}}) + } + end - it 'should not change the original hashes 2' do - hash1 = {'one' => { 'two' => [1,2] } } - hash2 = { 'one' => { 'three' => 3 } } - hash = scope.function_deep_merge([hash1, hash2]) - expect(hash1).to eq({'one' => { 'two' => [1,2] } }) - expect(hash2).to eq({ 'one' => { 'three' => 3 } }) - expect(hash['one']).to eq({ 'two' => [1,2], 'three' => 3 }) - end + it 'should not change the original hashes' do + argument1 = { 'key1' => 'value1' } + original1 = argument1.dup + argument2 = { 'key2' => 'value2' } + original2 = argument2.dup - it 'should not change the original hashes 3' do - hash1 = {'one' => { 'two' => [1,2, {'two' => 2} ] } } - hash2 = { 'one' => { 'three' => 3 } } - hash = scope.function_deep_merge([hash1, hash2]) - expect(hash1).to eq({'one' => { 'two' => [1,2, {'two' => 2}] } }) - expect(hash2).to eq({ 'one' => { 'three' => 3 } }) - expect(hash['one']).to eq({ 'two' => [1,2, {'two' => 2} ], 'three' => 3 }) - expect(hash['one']['two']).to eq([1,2, {'two' => 2}]) - end + subject.call([argument1, argument2]) + expect(argument1).to eq(original1) + expect(argument2).to eq(original2) end end diff --git a/stdlib/spec/functions/defined_with_params_spec.rb b/stdlib/spec/functions/defined_with_params_spec.rb index 359030474..516d986db 100755 --- a/stdlib/spec/functions/defined_with_params_spec.rb +++ b/stdlib/spec/functions/defined_with_params_spec.rb @@ -1,37 +1,26 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -require 'rspec-puppet' describe 'defined_with_params' do - describe 'when a resource is not specified' do + describe 'when no resource is specified' do it { is_expected.to run.with_params().and_raise_error(ArgumentError) } end describe 'when compared against a resource with no attributes' do let :pre_condition do 'user { "dan": }' end - it do - is_expected.to run.with_params('User[dan]', {}).and_return(true) - is_expected.to run.with_params('User[bob]', {}).and_return(false) - is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) - end + it { is_expected.to run.with_params('User[dan]', {}).and_return(true) } + it { is_expected.to run.with_params('User[bob]', {}).and_return(false) } + it { is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) } end describe 'when compared against a resource with attributes' do let :pre_condition do 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' end - it do - is_expected.to run.with_params('User[dan]', {}).and_return(true) - is_expected.to run.with_params('User[dan]', '').and_return(true) - is_expected.to run.with_params('User[dan]', {'ensure' => 'present'} - ).and_return(true) - is_expected.to run.with_params('User[dan]', - {'ensure' => 'present', 'managehome' => false} - ).and_return(true) - is_expected.to run.with_params('User[dan]', - {'ensure' => 'absent', 'managehome' => false} - ).and_return(false) - end + it { is_expected.to run.with_params('User[dan]', {}).and_return(true) } + it { is_expected.to run.with_params('User[dan]', '').and_return(true) } + it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present'}).and_return(true) } + it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true) } + it { is_expected.to run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false) } end end diff --git a/stdlib/spec/functions/delete_at_spec.rb b/stdlib/spec/functions/delete_at_spec.rb index 7c20aec42..0e19472ef 100755 --- a/stdlib/spec/functions/delete_at_spec.rb +++ b/stdlib/spec/functions/delete_at_spec.rb @@ -1,25 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the delete_at function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'delete_at' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(['one'], 'two').and_raise_error(Puppet::ParseError) } + it { + pending("Current implementation ignores parameters after the first two.") + is_expected.to run.with_params(['one'], 0, 1).and_raise_error(Puppet::ParseError) + } - it "should exist" do - expect(Puppet::Parser::Functions.function("delete_at")).to eq("function_delete_at") + describe 'argument validation' do + it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError) } end - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_delete_at([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should delete an item at specified location from an array" do - result = scope.function_delete_at([['a','b','c'],1]) - expect(result).to(eq(['a','c'])) - end + it { is_expected.to run.with_params([0, 1, 2], 1).and_return([0, 2]) } + it { is_expected.to run.with_params([0, 1, 2], -1).and_return([0, 1]) } + it { is_expected.to run.with_params([0, 1, 2], -4).and_return([0, 1, 2]) } - it "should not change origin array passed as argument" do - origin_array = ['a','b','c','d'] - result = scope.function_delete_at([origin_array, 1]) - expect(origin_array).to(eq(['a','b','c','d'])) + it "should leave the original array intact" do + argument = [1, 2, 3] + original = argument.dup + result = subject.call([argument,2]) + expect(argument).to eq(original) end end diff --git a/stdlib/spec/functions/delete_spec.rb b/stdlib/spec/functions/delete_spec.rb index c8edd78e2..6c4747bbd 100755 --- a/stdlib/spec/functions/delete_spec.rb +++ b/stdlib/spec/functions/delete_spec.rb @@ -1,61 +1,67 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the delete function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'delete' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) } - it "should exist" do - expect(Puppet::Parser::Functions.function("delete")).to eq("function_delete") + describe 'deleting from an array' do + it { is_expected.to run.with_params([], '').and_return([]) } + it { is_expected.to run.with_params([], 'two').and_return([]) } + it { is_expected.to run.with_params(['two'], 'two').and_return([]) } + it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) } + it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) } end - it "should raise a ParseError if there are fewer than 2 arguments" do - expect { scope.function_delete([]) }.to(raise_error(Puppet::ParseError)) + describe 'deleting from a string' do + it { is_expected.to run.with_params('', '').and_return('') } + it { is_expected.to run.with_params('bar', '').and_return('bar') } + it { is_expected.to run.with_params('', 'bar').and_return('') } + it { is_expected.to run.with_params('bar', 'bar').and_return('') } + it { is_expected.to run.with_params('barbar', 'bar').and_return('') } + it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') } + it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') } + it { is_expected.to run.with_params('foobarbabarz', ['foo', 'bar']).and_return('baz') } + # this is so sick + it { is_expected.to run.with_params('barfoobar', ['barbar', 'foo']).and_return('barbar') } + it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') } end - it "should raise a ParseError if there are greater than 2 arguments" do - expect { scope.function_delete([[], 'foo', 'bar']) }.to(raise_error(Puppet::ParseError)) + describe 'deleting from an array' do + it { is_expected.to run.with_params({}, '').and_return({}) } + it { is_expected.to run.with_params({}, 'key').and_return({}) } + it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) } + it { is_expected.to run \ + .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, 'key2') \ + .and_return( {'key1' => 'value1', 'key3' => 'value3'}) + } + it { is_expected.to run \ + .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \ + .and_return( {'key3' => 'value3'}) + } end - it "should raise a TypeError if a number is passed as the first argument" do - expect { scope.function_delete([1, 'bar']) }.to(raise_error(TypeError)) + it "should leave the original array intact" do + argument1 = ['one','two','three'] + original1 = argument1.dup + result = subject.call([argument1,'two']) + expect(argument1).to eq(original1) end - - it "should delete all instances of an element from an array" do - result = scope.function_delete([['a', 'b', 'c', 'b'], 'b']) - expect(result).to(eq(['a', 'c'])) - end - - it "should delete all instances of a substring from a string" do - result = scope.function_delete(['foobarbabarz', 'bar']) - expect(result).to(eq('foobaz')) + it "should leave the original string intact" do + argument1 = 'onetwothree' + original1 = argument1.dup + result = subject.call([argument1,'two']) + expect(argument1).to eq(original1) end - - it "should delete a key from a hash" do - result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, 'b']) - expect(result).to(eq({'a' => 1, 'c' => 3})) + it "should leave the original hash intact" do + argument1 = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'} + original1 = argument1.dup + result = subject.call([argument1,'key2']) + expect(argument1).to eq(original1) end - - it 'should accept an array of items to delete' do - result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, ['b', 'c']]) - expect(result).to(eq({'a' => 1})) - end - - it "should not change origin array passed as argument" do - origin_array = ['a', 'b', 'c', 'd'] - result = scope.function_delete([origin_array, 'b']) - expect(origin_array).to(eq(['a', 'b', 'c', 'd'])) - end - - it "should not change the origin string passed as argument" do - origin_string = 'foobarbabarz' - result = scope.function_delete([origin_string, 'bar']) - expect(origin_string).to(eq('foobarbabarz')) - end - - it "should not change origin hash passed as argument" do - origin_hash = {'a' => 1, 'b' => 2, 'c' => 3} - result = scope.function_delete([origin_hash, 'b']) - expect(origin_hash).to(eq({'a' => 1, 'b' => 2, 'c' => 3})) - end - end diff --git a/stdlib/spec/functions/delete_undef_values_spec.rb b/stdlib/spec/functions/delete_undef_values_spec.rb index dc679535f..ec9fb9c23 100755 --- a/stdlib/spec/functions/delete_undef_values_spec.rb +++ b/stdlib/spec/functions/delete_undef_values_spec.rb @@ -1,41 +1,56 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the delete_undef_values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("delete_undef_values")).to eq("function_delete_undef_values") - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_delete_undef_values([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the argument is not Array nor Hash" do - expect { scope.function_delete_undef_values(['']) }.to( raise_error(Puppet::ParseError)) - expect { scope.function_delete_undef_values([nil]) }.to( raise_error(Puppet::ParseError)) - end - - it "should delete all undef items from Array and only these" do - result = scope.function_delete_undef_values([['a',:undef,'c','undef']]) - expect(result).to(eq(['a','c','undef'])) - end - - it "should delete all undef items from Hash and only these" do - result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}]) - expect(result).to(eq({'a'=>'A','c'=>'C','d'=>'undef'})) - end - - it "should not change origin array passed as argument" do - origin_array = ['a',:undef,'c','undef'] - result = scope.function_delete_undef_values([origin_array]) - expect(origin_array).to(eq(['a',:undef,'c','undef'])) +describe 'delete_undef_values' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) } + + describe 'when deleting from an array' do + [ :undef, '', nil ].each do |undef_value| + describe "when undef is represented by #{undef_value.inspect}" do + before do + pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == '' + pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == nil + end + it { is_expected.to run.with_params([undef_value]).and_return([]) } + it { is_expected.to run.with_params(['one',undef_value,'two','three']).and_return(['one','two','three']) } + end + + it "should leave the original argument intact" do + argument = ['one',undef_value,'two'] + original = argument.dup + result = subject.call([argument,2]) + expect(argument).to eq(original) + end + end + + it { is_expected.to run.with_params(['undef']).and_return(['undef']) } end - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' } - result = scope.function_delete_undef_values([origin_hash]) - expect(origin_hash).to(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' })) + describe 'when deleting from a hash' do + [ :undef, '', nil ].each do |undef_value| + describe "when undef is represented by #{undef_value.inspect}" do + before do + pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == '' + pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == nil + end + it { is_expected.to run.with_params({'key' => undef_value}).and_return({}) } + it { is_expected.to run \ + .with_params({'key1' => 'value1', 'undef_key' => undef_value, 'key2' => 'value2'}) \ + .and_return({'key1' => 'value1', 'key2' => 'value2'}) + } + end + + it "should leave the original argument intact" do + argument = { 'key1' => 'value1', 'key2' => undef_value } + original = argument.dup + result = subject.call([argument,2]) + expect(argument).to eq(original) + end + end + + it { is_expected.to run.with_params({'key' => 'undef'}).and_return({'key' => 'undef'}) } end end diff --git a/stdlib/spec/functions/delete_values_spec.rb b/stdlib/spec/functions/delete_values_spec.rb index 4f4d411b8..12907d4b7 100755 --- a/stdlib/spec/functions/delete_values_spec.rb +++ b/stdlib/spec/functions/delete_values_spec.rb @@ -1,36 +1,37 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the delete_values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("delete_values")).to eq("function_delete_values") - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - expect { scope.function_delete_values([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are greater than 2 arguments" do - expect { scope.function_delete_values([[], 'foo', 'bar']) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a TypeError if the argument is not a hash" do - expect { scope.function_delete_values([1,'bar']) }.to( raise_error(TypeError)) - expect { scope.function_delete_values(['foo','bar']) }.to( raise_error(TypeError)) - expect { scope.function_delete_values([[],'bar']) }.to( raise_error(TypeError)) +describe 'delete_values' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) } + describe 'when the first argument is not a hash' do + it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(TypeError) } + it { is_expected.to run.with_params([], 'two').and_raise_error(TypeError) } end - it "should delete all instances of a value from a hash" do - result = scope.function_delete_values([{ 'a'=>'A', 'b'=>'B', 'B'=>'C', 'd'=>'B' },'B']) - expect(result).to(eq({ 'a'=>'A', 'B'=>'C' })) + describe 'when deleting from a hash' do + it { is_expected.to run.with_params({}, 'value').and_return({}) } + it { is_expected.to run \ + .with_params({'key1' => 'value1'}, 'non-existing value') \ + .and_return({'key1' => 'value1'}) + } + it { is_expected.to run \ + .with_params({'key1' => 'value1', 'key2' => 'value to delete'}, 'value to delete') \ + .and_return({'key1' => 'value1'}) + } + it { is_expected.to run \ + .with_params({'key1' => 'value1', 'key2' => 'value to delete', 'key3' => 'value to delete'}, 'value to delete') \ + .and_return({'key1' => 'value1'}) + } end - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } - result = scope.function_delete_values([origin_hash, 2]) - expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) + it "should leave the original argument intact" do + argument = { 'key1' => 'value1', 'key2' => 'value2' } + original = argument.dup + result = subject.call([argument, 'value2']) + expect(argument).to eq(original) end - end diff --git a/stdlib/spec/functions/difference_spec.rb b/stdlib/spec/functions/difference_spec.rb index 24b2b1bc6..d5e983d8f 100755 --- a/stdlib/spec/functions/difference_spec.rb +++ b/stdlib/spec/functions/difference_spec.rb @@ -1,19 +1,21 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the difference function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("difference")).to eq("function_difference") - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - expect { scope.function_difference([]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should return the difference between two arrays" do - result = scope.function_difference([["a","b","c"],["b","c","d"]]) - expect(result).to(eq(["a"])) - end +describe 'difference' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], []).and_return([]) } + it { is_expected.to run.with_params([], ['one']).and_return([]) } + it { is_expected.to run.with_params(['one'], ['one']).and_return([]) } + it { is_expected.to run.with_params(['one'], []).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three', 'four']).and_return(['one']) } + it 'should not confuse types' do is_expected.to run.with_params(['1', '2', '3'], [1, 2]).and_return(['1', '2', '3']) end end diff --git a/stdlib/spec/functions/dirname_spec.rb b/stdlib/spec/functions/dirname_spec.rb index 4261144ec..46c4c35c7 100755 --- a/stdlib/spec/functions/dirname_spec.rb +++ b/stdlib/spec/functions/dirname_spec.rb @@ -1,38 +1,13 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the dirname function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("dirname")).to eq("function_dirname") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_dirname([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there is more than 1 argument" do - expect { scope.function_dirname(['a', 'b']) }.to( raise_error(Puppet::ParseError)) - end - - it "should return dirname for an absolute path" do - result = scope.function_dirname(['/path/to/a/file.ext']) - expect(result).to(eq('/path/to/a')) - end - - it "should return dirname for a relative path" do - result = scope.function_dirname(['path/to/a/file.ext']) - expect(result).to(eq('path/to/a')) - end - - it "should complain about hash argument" do - expect { scope.function_dirname([{}]) }.to( raise_error(Puppet::ParseError)) - end - it "should complain about list argument" do - expect { scope.function_dirname([[]]) }.to( raise_error(Puppet::ParseError)) - end - it "should complain about numeric argument" do - expect { scope.function_dirname([2112]) }.to( raise_error(Puppet::ParseError)) - end +describe 'dirname' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('/path/to/a') } + it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('relative_path/to/a') } end diff --git a/stdlib/spec/functions/downcase_spec.rb b/stdlib/spec/functions/downcase_spec.rb index edebc44f1..c594560a0 100755 --- a/stdlib/spec/functions/downcase_spec.rb +++ b/stdlib/spec/functions/downcase_spec.rb @@ -1,33 +1,15 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the downcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("downcase")).to eq("function_downcase") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_downcase([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should downcase a string" do - result = scope.function_downcase(["ASFD"]) - expect(result).to(eq("asfd")) - end - - it "should do nothing to a string that is already downcase" do - result = scope.function_downcase(["asdf asdf"]) - expect(result).to(eq("asdf asdf")) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new("ASFD") - result = scope.function_downcase([value]) - result.should(eq('asfd')) - end +describe 'downcase' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("abc").and_return("abc") } + it { is_expected.to run.with_params("Abc").and_return("abc") } + it { is_expected.to run.with_params("ABC").and_return("abc") } + + it { is_expected.to run.with_params(AlsoString.new("ABC")).and_return("abc") } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(["ONE", "TWO"]).and_return(["one", "two"]) } + it { is_expected.to run.with_params(["One", 1, "Two"]).and_return(["one", 1, "two"]) } end diff --git a/stdlib/spec/functions/empty_spec.rb b/stdlib/spec/functions/empty_spec.rb index 6a97c4cd3..94b1c6856 100755 --- a/stdlib/spec/functions/empty_spec.rb +++ b/stdlib/spec/functions/empty_spec.rb @@ -1,32 +1,22 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the empty function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - expect(Puppet::Parser::Functions.function("empty")).to eq("function_empty") - end +describe 'empty' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) + } + it { is_expected.to run.with_params('').and_return(true) } + it { is_expected.to run.with_params('one').and_return(false) } - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_empty([]) }.to( raise_error(Puppet::ParseError)) - end + it { is_expected.to run.with_params(AlsoString.new('')).and_return(true) } + it { is_expected.to run.with_params(AlsoString.new('one')).and_return(false) } - it "should return a true for an empty string" do - result = scope.function_empty(['']) - expect(result).to(eq(true)) - end + it { is_expected.to run.with_params([]).and_return(true) } + it { is_expected.to run.with_params(['one']).and_return(false) } - it "should return a false for a non-empty string" do - result = scope.function_empty(['asdf']) - expect(result).to(eq(false)) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new() - result = scope.function_empty([value]) - result.should(eq(true)) - end + it { is_expected.to run.with_params({}).and_return(true) } + it { is_expected.to run.with_params({'key' => 'value'}).and_return(false) } end diff --git a/stdlib/spec/functions/ensure_packages_spec.rb b/stdlib/spec/functions/ensure_packages_spec.rb index 436be10bc..c82473299 100755 --- a/stdlib/spec/functions/ensure_packages_spec.rb +++ b/stdlib/spec/functions/ensure_packages_spec.rb @@ -1,81 +1,36 @@ -#! /usr/bin/env ruby - require 'spec_helper' -require 'rspec-puppet' -require 'puppet_spec/compiler' describe 'ensure_packages' do - include PuppetSpec::Compiler - - before :each do - Puppet::Parser::Functions.autoloader.loadall - Puppet::Parser::Functions.function(:ensure_packages) - Puppet::Parser::Functions.function(:ensure_resource) - Puppet::Parser::Functions.function(:defined_with_params) - Puppet::Parser::Functions.function(:create_resources) - end - - let :node do Puppet::Node.new('localhost') end - let :compiler do Puppet::Parser::Compiler.new(node) end - let :scope do - if Puppet.version.to_f >= 3.0 - Puppet::Parser::Scope.new(compiler) - else - newscope = Puppet::Parser::Scope.new - newscope.compiler = compiler - newscope.source = Puppet::Resource::Type.new(:node, :localhost) - newscope - end - end - - describe 'argument handling' do - it 'fails with no arguments' do - expect { - scope.function_ensure_packages([]) - }.to raise_error(Puppet::ParseError, /0 for 1 or 2/) - end - - it 'accepts an array of values' do - scope.function_ensure_packages([['foo']]) - end - - it 'accepts a single package name as a string' do - scope.function_ensure_packages(['foo']) - end - end - - context 'given a catalog with puppet package => absent' do - let :catalog do - compile_to_catalog(<<-EOS - ensure_packages(['facter']) - package { puppet: ensure => absent } - EOS - ) - end - - it 'has no effect on Package[puppet]' do - expect(catalog.resource(:package, 'puppet')['ensure']).to eq('absent') - end - end - - context 'given a clean catalog' do - let :catalog do - compile_to_catalog('ensure_packages(["facter"])') - end - - it 'declares package resources with ensure => present' do - expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') - end - end - - context 'given a clean catalog and specified defaults' do - let :catalog do - compile_to_catalog('ensure_packages(["facter"], {"provider" => "gem"})') - end - - it 'declares package resources with ensure => present' do - expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') - expect(catalog.resource(:package, 'facter')['provider']).to eq('gem') + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { + pending("should not accept numbers as arguments") + is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) + } + it { + pending("should not accept numbers as arguments") + is_expected.to run.with_params(["packagename", 1]).and_raise_error(Puppet::ParseError) + } + it { is_expected.to run.with_params("packagename") } + it { is_expected.to run.with_params(["packagename1", "packagename2"]) } + + context 'given a catalog with "package { puppet: ensure => absent }"' do + let(:pre_condition) { 'package { puppet: ensure => absent }' } + + describe 'after running ensure_package("facter")' do + before { subject.call(['facter']) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_package('puppet').with_ensure('absent') } + it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present') } + end + + describe 'after running ensure_package("facter", { "provider" => "gem" })' do + before { subject.call(['facter', { "provider" => "gem" }]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_package('puppet').with_ensure('absent').without_provider() } + it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present').with_provider("gem") } end end end diff --git a/stdlib/spec/functions/ensure_resource_spec.rb b/stdlib/spec/functions/ensure_resource_spec.rb index 33bcac0d1..c4f2cbd0e 100755 --- a/stdlib/spec/functions/ensure_resource_spec.rb +++ b/stdlib/spec/functions/ensure_resource_spec.rb @@ -1,113 +1,55 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -require 'rspec-puppet' -require 'puppet_spec/compiler' describe 'ensure_resource' do - include PuppetSpec::Compiler + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) } + it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) } + it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) } + it { + pending("should not accept numbers as arguments") + is_expected.to run.with_params(1,2,3).and_raise_error(Puppet::ParseError) + } - before :all do - Puppet::Parser::Functions.autoloader.loadall - Puppet::Parser::Functions.function(:ensure_packages) - end - - let :node do Puppet::Node.new('localhost') end - let :compiler do Puppet::Parser::Compiler.new(node) end - let :scope do Puppet::Parser::Scope.new(compiler) end + context 'given a catalog with "user { username1: ensure => present }"' do + let(:pre_condition) { 'user { username1: ensure => present }' } - describe 'when a type or title is not specified' do - it { expect { scope.function_ensure_resource([]) }.to raise_error } - it { expect { scope.function_ensure_resource(['type']) }.to raise_error } - end - - describe 'when compared against a resource with no attributes' do - let :catalog do - compile_to_catalog(<<-EOS - user { "dan": } - ensure_resource('user', 'dan', {}) - EOS - ) - end + describe 'after running ensure_resource("user", "username1", {})' do + before { subject.call(['User', 'username1', {}]) } - it 'should contain the the ensured resources' do - expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]') + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } end - end - describe 'works when compared against a resource with non-conflicting attributes' do - [ - "ensure_resource('User', 'dan', {})", - "ensure_resource('User', 'dan', '')", - "ensure_resource('User', 'dan', {'ensure' => 'present'})", - "ensure_resource('User', 'dan', {'ensure' => 'present', 'managehome' => false})" - ].each do |ensure_resource| - pp = <<-EOS - user { "dan": ensure => present, shell => "/bin/csh", managehome => false} - #{ensure_resource} - EOS + describe 'after running ensure_resource("user", "username2", {})' do + before { subject.call(['User', 'username2', {}]) } - it { expect { compile_to_catalog(pp) }.to_not raise_error } + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(lambda { catalogue }).to contain_user('username2').without_ensure } end - end - - describe 'fails when compared against a resource with conflicting attributes' do - pp = <<-EOS - user { "dan": ensure => present, shell => "/bin/csh", managehome => false} - ensure_resource('User', 'dan', {'ensure' => 'absent', 'managehome' => false}) - EOS - - it { expect { compile_to_catalog(pp) }.to raise_error } - end - describe 'when an array of new resources are passed in' do - let :catalog do - compile_to_catalog("ensure_resource('User', ['dan', 'alex'], {})") - end + describe 'after running ensure_resource("user", ["username1", "username2"], {})' do + before { subject.call(['User', ['username1', 'username2'], {}]) } - it 'should contain the ensured resources' do - expect(catalog.resource('User[dan]').to_s).to eq('User[dan]') - expect(catalog.resource('User[alex]').to_s).to eq('User[alex]') + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } + it { expect(lambda { catalogue }).to contain_user('username2').without_ensure } end - end - describe 'when an array of existing resources is compared against existing resources' do - pp = <<-EOS - user { 'dan': ensure => present; 'alex': ensure => present } - ensure_resource('User', ['dan', 'alex'], {}) - EOS + describe 'when providing already set params' do + let(:params) { { 'ensure' => 'present' } } + before { subject.call(['User', ['username2', 'username3'], params]) } - let :catalog do - compile_to_catalog(pp) + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('username1').with(params) } + it { expect(lambda { catalogue }).to contain_user('username2').with(params) } end - it 'should return the existing resources' do - expect(catalog.resource('User[dan]').to_s).to eq('User[dan]') - expect(catalog.resource('User[alex]').to_s).to eq('User[alex]') - end - end - - describe 'works when compared against existing resources with attributes' do - [ - "ensure_resource('User', ['dan', 'alex'], {})", - "ensure_resource('User', ['dan', 'alex'], '')", - "ensure_resource('User', ['dan', 'alex'], {'ensure' => 'present'})", - ].each do |ensure_resource| - pp = <<-EOS - user { 'dan': ensure => present; 'alex': ensure => present } - #{ensure_resource} - EOS - - it { expect { compile_to_catalog(pp) }.to_not raise_error } + context 'when trying to add params' do + it { is_expected.to run \ + .with_params('User', 'username1', { 'ensure' => 'present', 'shell' => true }) \ + .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, /User\[username1\] is already declared/) + } end end - - describe 'fails when compared against existing resources with conflicting attributes' do - pp = <<-EOS - user { 'dan': ensure => present; 'alex': ensure => present } - ensure_resource('User', ['dan', 'alex'], {'ensure' => 'absent'}) - EOS - - it { expect { compile_to_catalog(pp) }.to raise_error } - end - end diff --git a/stdlib/spec/functions/flatten_spec.rb b/stdlib/spec/functions/flatten_spec.rb index de8c66d66..a4338be4d 100755 --- a/stdlib/spec/functions/flatten_spec.rb +++ b/stdlib/spec/functions/flatten_spec.rb @@ -1,27 +1,14 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the flatten function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - expect(Puppet::Parser::Functions.function("flatten")).to eq("function_flatten") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_flatten([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there is more than 1 argument" do - expect { scope.function_flatten([[], []]) }.to( raise_error(Puppet::ParseError)) - end - - it "should flatten a complex data structure" do - result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) - expect(result).to(eq(["a","b","c","d","e","f","g"])) - end - - it "should do nothing to a structure that is already flat" do - result = scope.function_flatten([["a","b","c","d"]]) - expect(result).to(eq(["a","b","c","d"])) - end +describe 'flatten' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['one']).and_return(['one']) } + it { is_expected.to run.with_params([['one']]).and_return(['one']) } + it { is_expected.to run.with_params(["a","b","c","d","e","f","g"]).and_return(["a","b","c","d","e","f","g"]) } + it { is_expected.to run.with_params([["a","b",["c",["d","e"],"f","g"]]]).and_return(["a","b","c","d","e","f","g"]) } end diff --git a/stdlib/spec/functions/floor_spec.rb b/stdlib/spec/functions/floor_spec.rb index 12a691798..608c602fa 100755 --- a/stdlib/spec/functions/floor_spec.rb +++ b/stdlib/spec/functions/floor_spec.rb @@ -1,39 +1,12 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the floor function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("floor")).to eq("function_floor") - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_floor([]) }.to( raise_error(Puppet::ParseError, /Wrong number of arguments/)) - end - - it "should should raise a ParseError if input isn't numeric (eg. String)" do - expect { scope.function_floor(["foo"]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/)) - end - - it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do - expect { scope.function_floor([true]) }.to( raise_error(Puppet::ParseError, /Wrong argument type/)) - end - - it "should return an integer when a numeric type is passed" do - result = scope.function_floor([12.4]) - expect(result.is_a?(Integer)).to(eq(true)) - end - - it "should return the input when an integer is passed" do - result = scope.function_floor([7]) - expect(result).to(eq(7)) - end - - it "should return the largest integer less than or equal to the input" do - result = scope.function_floor([3.8]) - expect(result).to(eq(3)) - end +describe 'floor' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params("foo").and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(34).and_return(34) } + it { is_expected.to run.with_params(-34).and_return(-34) } + it { is_expected.to run.with_params(33.1).and_return(33) } + it { is_expected.to run.with_params(-33.1).and_return(-34) } end - diff --git a/stdlib/spec/functions/fqdn_rand_string_spec.rb b/stdlib/spec/functions/fqdn_rand_string_spec.rb index 949d930c7..e4070846b 100644 --- a/stdlib/spec/functions/fqdn_rand_string_spec.rb +++ b/stdlib/spec/functions/fqdn_rand_string_spec.rb @@ -1,51 +1,25 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the fqdn_rand_string function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("fqdn_rand_string")).to eq("function_fqdn_rand_string") - end - - it "should raise an ArgumentError if there is less than 1 argument" do - expect { fqdn_rand_string() }.to( raise_error(ArgumentError, /wrong number of arguments/)) - end - - it "should raise an ArgumentError if argument 1 isn't a positive integer" do - expect { fqdn_rand_string(0) }.to( raise_error(ArgumentError, /first argument must be a positive integer/)) - expect { fqdn_rand_string(-1) }.to( raise_error(ArgumentError, /first argument must be a positive integer/)) - expect { fqdn_rand_string(0.5) }.to( raise_error(ArgumentError, /first argument must be a positive integer/)) - end - - it "provides a valid alphanumeric string when no character set is provided" do - length = 100 - string = %r{\A[a-zA-Z0-9]{#{length}}\z} - expect(fqdn_rand_string(length).match(string)).not_to eq(nil) - end - - it "provides a valid alphanumeric string when an undef character set is provided" do - length = 100 - string = %r{\A[a-zA-Z0-9]{#{length}}\z} - expect(fqdn_rand_string(length, :charset => nil).match(string)).not_to eq(nil) - end - - it "provides a valid alphanumeric string when an empty character set is provided" do - length = 100 - string = %r{\A[a-zA-Z0-9]{#{length}}\z} - expect(fqdn_rand_string(length, :charset => '').match(string)).not_to eq(nil) - end - - it "uses a provided character set" do - length = 100 - charset = '!@#$%^&*()-_=+' - string = %r{\A[#{charset}]{#{length}}\z} - expect(fqdn_rand_string(length, :charset => charset).match(string)).not_to eq(nil) - end - - it "provides a random string exactly as long as the given length" do - expect(fqdn_rand_string(10).size).to eql(10) - end +describe 'fqdn_rand_string' do + let(:default_charset) { %r{\A[a-zA-Z0-9]{100}\z} } + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(0).and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params(1.5).and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params(-10).and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params("-10").and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params("string").and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params([]).and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params({}).and_raise_error(ArgumentError, /first argument must be a positive integer/) } + it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, /second argument must be undef or a string/) } + it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, /second argument must be undef or a string/) } + it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, /second argument must be undef or a string/) } + it { is_expected.to run.with_params(100).and_return(default_charset) } + it { is_expected.to run.with_params("100").and_return(default_charset) } + it { is_expected.to run.with_params(100, nil).and_return(default_charset) } + it { is_expected.to run.with_params(100, '').and_return(default_charset) } + it { is_expected.to run.with_params(100, 'a').and_return(/\Aa{100}\z/) } + it { is_expected.to run.with_params(100, 'ab').and_return(/\A[ab]{100}\z/) } it "provides the same 'random' value on subsequent calls for the same host" do expect(fqdn_rand_string(10)).to eql(fqdn_rand_string(10)) @@ -77,9 +51,9 @@ def fqdn_rand_string(max, args = {}) charset = args[:charset] extra = args[:extra_identifier] || [] - scope = PuppetlabsSpec::PuppetInternals.scope - scope.stubs(:[]).with("::fqdn").returns(host) - scope.stubs(:lookupvar).with("::fqdn").returns(host) + # workaround not being able to use let(:facts) because some tests need + # multiple different hostnames in one context + scope.stubs(:lookupvar).with("::fqdn", {}).returns(host) function_args = [max] if args.has_key?(:charset) or !extra.empty? diff --git a/stdlib/spec/functions/fqdn_rotate_spec.rb b/stdlib/spec/functions/fqdn_rotate_spec.rb index 673a8a321..db7a71732 100755 --- a/stdlib/spec/functions/fqdn_rotate_spec.rb +++ b/stdlib/spec/functions/fqdn_rotate_spec.rb @@ -1,60 +1,75 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the fqdn_rotate function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'fqdn_rotate' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } - it "should exist" do - expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("function_fqdn_rotate") + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['a']).and_return(['a']) } + + it "should rotate a string and the result should be the same size" do + expect(fqdn_rotate("asdf").size).to eq(4) end - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_fqdn_rotate([]) }.to( raise_error(Puppet::ParseError)) + it "should rotate a string to give the same results for one host" do + val1 = fqdn_rotate("abcdefg", :host => 'one') + val2 = fqdn_rotate("abcdefg", :host => 'one') + expect(val1).to eq(val2) end - it "should rotate a string and the result should be the same size" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") - result = scope.function_fqdn_rotate(["asdf"]) - expect(result.size).to(eq(4)) + it "allows extra arguments to control the random rotation on a single host" do + val1 = fqdn_rotate("abcdefg", :extra_identifier => [1, "different", "host"]) + val2 = fqdn_rotate("abcdefg", :extra_identifier => [2, "different", "host"]) + expect(val1).not_to eq(val2) end - it "should rotate a string to give the same results for one host" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice - expect(scope.function_fqdn_rotate(["abcdefg"])).to eql(scope.function_fqdn_rotate(["abcdefg"])) + it "considers the same host and same extra arguments to have the same random rotation" do + val1 = fqdn_rotate("abcdefg", :extra_identifier => [1, "same", "host"]) + val2 = fqdn_rotate("abcdefg", :extra_identifier => [1, "same", "host"]) + expect(val1).to eq(val2) end it "should rotate a string to give different values on different hosts" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") - val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2") - val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) - expect(val1).not_to eql(val2) + val1 = fqdn_rotate("abcdefg", :host => 'one') + val2 = fqdn_rotate("abcdefg", :host => 'two') + expect(val1).not_to eq(val2) end it "should accept objects which extend String" do - class AlsoString < String - end - - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") - value = AlsoString.new("asdf") - result = scope.function_fqdn_rotate([value]) - result.size.should(eq(4)) + result = fqdn_rotate(AlsoString.new('asdf')) + expect(result).to eq('dfas') end - it "should use the Puppet::Util.deterministic_rand function if available" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") + it "should use the Puppet::Util.deterministic_rand function" do if Puppet::Util.respond_to?(:deterministic_rand) - Puppet::Util.expects(:deterministic_rand).with(113646079810780526294648115052177588845,4) + Puppet::Util.expects(:deterministic_rand).with(44489829212339698569024999901561968770,4) + fqdn_rotate("asdf") + else + skip 'Puppet::Util#deterministic_rand not available' end - scope.function_fqdn_rotate(["asdf"]) end it "should not leave the global seed in a deterministic state" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice - scope.function_fqdn_rotate(["asdf"]) + fqdn_rotate("asdf") rand1 = rand() - scope.function_fqdn_rotate(["asdf"]) + fqdn_rotate("asdf") rand2 = rand() expect(rand1).not_to eql(rand2) end + + def fqdn_rotate(value, args = {}) + host = args[:host] || '127.0.0.1' + extra = args[:extra_identifier] || [] + + # workaround not being able to use let(:facts) because some tests need + # multiple different hostnames in one context + scope.stubs(:lookupvar).with("::fqdn").returns(host) + + function_args = [value] + extra + scope.function_fqdn_rotate(function_args) + end end diff --git a/stdlib/spec/functions/get_module_path_spec.rb b/stdlib/spec/functions/get_module_path_spec.rb index 38ce64597..b1f682fdb 100755 --- a/stdlib/spec/functions/get_module_path_spec.rb +++ b/stdlib/spec/functions/get_module_path_spec.rb @@ -1,8 +1,16 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:get_module_path) do - Internals = PuppetlabsSpec::PuppetInternals +describe 'get_module_path' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) } + if Puppet.version.to_f >= 4.0 + it { is_expected.to run.with_params('one').and_raise_error(Puppet::Environments::EnvironmentNotFound, /Could not find a directory environment/) } + else + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Could not find module/) } + end + class StubModule attr_reader :path def initialize(path) @@ -10,37 +18,35 @@ def initialize(path) end end - def scope(environment = "production") - Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment))) - end - - it 'should only allow one argument' do - expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) - expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) - end - it 'should raise an exception when the module cannot be found' do - expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/) - end describe 'when locating a module' do let(:modulepath) { "/tmp/does_not_exist" } let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") } before(:each) { Puppet[:modulepath] = modulepath } - it 'should be able to find module paths from the modulepath setting' do - Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) - expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path) - end - it 'should be able to find module paths when the modulepath is a list' do - Puppet[:modulepath] = modulepath + ":/tmp" - Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) - expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path) + context 'in the default environment' do + before(:each) { Puppet::Module.expects(:find).with('foo', 'rp_env').returns(path_of_module_foo) } + + it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) } + + context 'when the modulepath is a list' do + before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' } + + it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) } + end end - it 'should respect the environment' do - skip("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/ - Puppet.settings[:environment] = 'danstestenv' - Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo) - expect(scope('danstestenv').function_get_module_path(['foo'])).to eq(path_of_module_foo.path) + + context 'in a non-default default environment' do + let(:environment) { 'test' } + before(:each) { Puppet::Module.expects(:find).with('foo', 'test').returns(path_of_module_foo) } + + it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) } + + context 'when the modulepath is a list' do + before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' } + + it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) } + end end end end diff --git a/stdlib/spec/functions/getparam_spec.rb b/stdlib/spec/functions/getparam_spec.rb index 833c4d4fb..9e3d9e470 100755 --- a/stdlib/spec/functions/getparam_spec.rb +++ b/stdlib/spec/functions/getparam_spec.rb @@ -1,76 +1,30 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -require 'rspec-puppet' -require 'puppet_spec/compiler' describe 'getparam' do - include PuppetSpec::Compiler - - before :each do - Puppet::Parser::Functions.autoloader.loadall - Puppet::Parser::Functions.function(:getparam) - end - - let :node do Puppet::Node.new('localhost') end - let :compiler do Puppet::Parser::Compiler.new(node) end - if Puppet.version.to_f >= 3.0 - let :scope do Puppet::Parser::Scope.new(compiler) end - else - let :scope do - newscope = Puppet::Parser::Scope.new - newscope.compiler = compiler - newscope.source = Puppet::Resource::Type.new(:node, :localhost) - newscope - end + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a reference/) } + it { is_expected.to run.with_params('User[one]').and_raise_error(ArgumentError, /Must specify name of a parameter/) } + it { is_expected.to run.with_params('User[one]', 2).and_raise_error(ArgumentError, /Must specify name of a parameter/) } + it { is_expected.to run.with_params('User[one]', []).and_raise_error(ArgumentError, /Must specify name of a parameter/) } + it { is_expected.to run.with_params('User[one]', {}).and_raise_error(ArgumentError, /Must specify name of a parameter/) } + + describe 'when compared against a user resource with no params' do + let(:pre_condition) { 'user { "one": }' } + + it { is_expected.to run.with_params('User[one]', 'ensure').and_return('') } + it { is_expected.to run.with_params('User[two]', 'ensure').and_return('') } + it { is_expected.to run.with_params('User[one]', 'shell').and_return('') } end - it "should exist" do - expect(Puppet::Parser::Functions.function("getparam")).to eq("function_getparam") - end - - describe 'when a resource is not specified' do - it { expect { scope.function_getparam([]) }.to raise_error } - it { expect { scope.function_getparam(['User[dan]']) }.to raise_error } - it { expect { scope.function_getparam(['User[dan]']) }.to raise_error } - it { expect { scope.function_getparam(['User[dan]', {}]) }.to raise_error } - # This seems to be OK because we just check for a string. - it { expect { scope.function_getparam(['User[dan]', '']) }.to_not raise_error } - end - - describe 'when compared against a resource with no params' do - let :catalog do - compile_to_catalog(<<-EOS - user { "dan": } - EOS - ) - end - - it do - expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('') - end - end - - describe 'when compared against a resource with params' do - let :catalog do - compile_to_catalog(<<-EOS - user { 'dan': ensure => present, shell => '/bin/sh', managehome => false} - $test = getparam(User[dan], 'shell') - EOS - ) - end - - it do - resource = Puppet::Parser::Resource.new(:user, 'dan', {:scope => scope}) - resource.set_parameter('ensure', 'present') - resource.set_parameter('shell', '/bin/sh') - resource.set_parameter('managehome', false) - compiler.add_resource(scope, resource) + describe 'when compared against a user resource with params' do + let(:pre_condition) { 'user { "one": ensure => present, shell => "/bin/sh", managehome => false, }' } - expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('/bin/sh') - expect(scope.function_getparam(['User[dan]', ''])).to eq('') - expect(scope.function_getparam(['User[dan]', 'ensure'])).to eq('present') - # TODO: Expected this to be false, figure out why we're getting '' back. - expect(scope.function_getparam(['User[dan]', 'managehome'])).to eq('') - end + it { is_expected.to run.with_params('User[one]', 'ensure').and_return('present') } + it { is_expected.to run.with_params('User[two]', 'ensure').and_return('') } + it { is_expected.to run.with_params('User[one]', 'shell').and_return('/bin/sh') } + it { + pending("both rspec-puppet as well as the function do the wrong thing here.") + is_expected.to run.with_params('User[one]', 'managehome').and_return(false) + } end end diff --git a/stdlib/spec/functions/getvar_spec.rb b/stdlib/spec/functions/getvar_spec.rb index 87ab9b5ac..37125d1a4 100755 --- a/stdlib/spec/functions/getvar_spec.rb +++ b/stdlib/spec/functions/getvar_spec.rb @@ -1,37 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:getvar) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling getvar from puppet' do +describe 'getvar' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should not compile when no arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$foo = getvar()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end + context 'given variables in namespaces' do + let(:pre_condition) { + <<-'ENDofPUPPETcode' + class site::data { $foo = 'baz' } + include site::data + ENDofPUPPETcode + } - it "should not compile when too many arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$foo = getvar("foo::bar", "baz")' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + it { is_expected.to run.with_params('site::data::foo').and_return('baz') } + it { is_expected.to run.with_params('::site::data::foo').and_return('baz') } + + context 'with strict variable checking', :if => RSpec.configuration.strict_variables do + it { is_expected.to run.with_params('::site::data::bar').and_raise_error(ArgumentError, /undefined_variable/) } end - it "should lookup variables in other namespaces" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = <<-'ENDofPUPPETcode' - class site::data { $foo = 'baz' } - include site::data - $foo = getvar("site::data::foo") - if $foo != 'baz' { - fail('getvar did not return what we expect') - } - ENDofPUPPETcode - scope.compiler.compile + context 'without strict variable checking', :unless => RSpec.configuration.strict_variables do + it { is_expected.to run.with_params('::site::data::bar').and_return(nil) } end end end diff --git a/stdlib/spec/functions/grep_spec.rb b/stdlib/spec/functions/grep_spec.rb index 9c671dd86..6e0bd6eb9 100755 --- a/stdlib/spec/functions/grep_spec.rb +++ b/stdlib/spec/functions/grep_spec.rb @@ -1,19 +1,19 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the grep function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("grep")).to eq("function_grep") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_grep([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should grep contents from an array" do - result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) - expect(result).to(eq(["aaabbb","bbbccc"])) - end +describe 'grep' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("grep does not actually check this, and raises NoMethodError instead") + is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /first argument not an array/) + } + it { + pending("grep does not actually check this, and raises NoMethodError instead") + is_expected.to run.with_params(1, 'two').and_raise_error(Puppet::ParseError, /first argument not an array/) + } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([], 'two').and_return([]) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['two']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 't(wo|hree)').and_return(['two', 'three']) } end diff --git a/stdlib/spec/functions/has_interface_with_spec.rb b/stdlib/spec/functions/has_interface_with_spec.rb index 23e09a955..7334d38b9 100755 --- a/stdlib/spec/functions/has_interface_with_spec.rb +++ b/stdlib/spec/functions/has_interface_with_spec.rb @@ -1,64 +1,38 @@ -#!/usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:has_interface_with) do - - let(:scope) do - PuppetlabsSpec::PuppetInternals.scope - end - - # The subject of these examples is the method itself. - subject do - function_name = Puppet::Parser::Functions.function(:has_interface_with) - scope.method(function_name) - end +describe 'has_interface_with' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params("one", "two", "three").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } # We need to mock out the Facts so we can specify how we expect this function # to behave on different platforms. context "On Mac OS X Systems" do - before :each do - scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0') - end - it 'should have loopback (lo0)' do - expect(subject.call(['lo0'])).to be_truthy - end - it 'should not have loopback (lo)' do - expect(subject.call(['lo'])).to be_falsey - end + let(:facts) { { :interfaces => 'lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0' } } + it { is_expected.to run.with_params('lo0').and_return(true) } + it { is_expected.to run.with_params('lo').and_return(false) } end + context "On Linux Systems" do - before :each do - scope.stubs(:lookupvar).with("interfaces").returns('eth0,lo') - scope.stubs(:lookupvar).with("ipaddress").returns('10.0.0.1') - scope.stubs(:lookupvar).with("ipaddress_lo").returns('127.0.0.1') - scope.stubs(:lookupvar).with("ipaddress_eth0").returns('10.0.0.1') - scope.stubs(:lookupvar).with('muppet').returns('kermit') - scope.stubs(:lookupvar).with('muppet_lo').returns('mspiggy') - scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit') - end - it 'should have loopback (lo)' do - expect(subject.call(['lo'])).to be_truthy - end - it 'should not have loopback (lo0)' do - expect(subject.call(['lo0'])).to be_falsey - end - it 'should have ipaddress with 127.0.0.1' do - expect(subject.call(['ipaddress', '127.0.0.1'])).to be_truthy - end - it 'should have ipaddress with 10.0.0.1' do - expect(subject.call(['ipaddress', '10.0.0.1'])).to be_truthy - end - it 'should not have ipaddress with 10.0.0.2' do - expect(subject.call(['ipaddress', '10.0.0.2'])).to be_falsey - end - it 'should have muppet named kermit' do - expect(subject.call(['muppet', 'kermit'])).to be_truthy - end - it 'should have muppet named mspiggy' do - expect(subject.call(['muppet', 'mspiggy'])).to be_truthy - end - it 'should not have muppet named bigbird' do - expect(subject.call(['muppet', 'bigbird'])).to be_falsey + let(:facts) do + { + :interfaces => 'eth0,lo', + :ipaddress => '10.0.0.1', + :ipaddress_lo => '127.0.0.1', + :ipaddress_eth0 => '10.0.0.1', + :muppet => 'kermit', + :muppet_lo => 'mspiggy', + :muppet_eth0 => 'kermit', + } end + + it { is_expected.to run.with_params('lo').and_return(true) } + it { is_expected.to run.with_params('lo0').and_return(false) } + it { is_expected.to run.with_params('ipaddress', '127.0.0.1').and_return(true) } + it { is_expected.to run.with_params('ipaddress', '10.0.0.1').and_return(true) } + it { is_expected.to run.with_params('ipaddress', '8.8.8.8').and_return(false) } + it { is_expected.to run.with_params('muppet', 'kermit').and_return(true) } + it { is_expected.to run.with_params('muppet', 'mspiggy').and_return(true) } + it { is_expected.to run.with_params('muppet', 'bigbird').and_return(false) } end end diff --git a/stdlib/spec/functions/has_ip_address_spec.rb b/stdlib/spec/functions/has_ip_address_spec.rb index 0df12a7be..42a5a7926 100755 --- a/stdlib/spec/functions/has_ip_address_spec.rb +++ b/stdlib/spec/functions/has_ip_address_spec.rb @@ -1,39 +1,22 @@ -#!/usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:has_ip_address) do - - let(:scope) do - PuppetlabsSpec::PuppetInternals.scope - end - - subject do - function_name = Puppet::Parser::Functions.function(:has_ip_address) - scope.method(function_name) - end +describe 'has_ip_address' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params("one", "two").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } context "On Linux Systems" do - before :each do - scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') - scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15') - scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15') - scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1') - end - - it 'should have primary address (10.0.2.15)' do - expect(subject.call(['10.0.2.15'])).to be_truthy + let(:facts) do + { + :interfaces => 'eth0,lo', + :ipaddress => '10.0.0.1', + :ipaddress_lo => '127.0.0.1', + :ipaddress_eth0 => '10.0.0.1', + } end - it 'should have lookupback address (127.0.0.1)' do - expect(subject.call(['127.0.0.1'])).to be_truthy - end - - it 'should not have other address' do - expect(subject.call(['192.1681.1.1'])).to be_falsey - end - - it 'should not have "mspiggy" on an interface' do - expect(subject.call(['mspiggy'])).to be_falsey - end + it { is_expected.to run.with_params('127.0.0.1').and_return(true) } + it { is_expected.to run.with_params('10.0.0.1').and_return(true) } + it { is_expected.to run.with_params('8.8.8.8').and_return(false) } end end diff --git a/stdlib/spec/functions/has_ip_network_spec.rb b/stdlib/spec/functions/has_ip_network_spec.rb index 2a2578e23..7b5fe66ac 100755 --- a/stdlib/spec/functions/has_ip_network_spec.rb +++ b/stdlib/spec/functions/has_ip_network_spec.rb @@ -1,36 +1,22 @@ -#!/usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:has_ip_network) do - - let(:scope) do - PuppetlabsSpec::PuppetInternals.scope - end - - subject do - function_name = Puppet::Parser::Functions.function(:has_ip_network) - scope.method(function_name) - end +describe 'has_ip_network' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params("one", "two").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } context "On Linux Systems" do - before :each do - scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') - scope.stubs(:lookupvar).with('network').returns(:undefined) - scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0') - scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1') - end - - it 'should have primary network (10.0.2.0)' do - expect(subject.call(['10.0.2.0'])).to be_truthy - end - - it 'should have loopback network (127.0.0.0)' do - expect(subject.call(['127.0.0.1'])).to be_truthy + let(:facts) do + { + :interfaces => 'eth0,lo', + :network => :undefined, + :network_lo => '127.0.0.0', + :network_eth0 => '10.0.0.0', + } end - it 'should not have other network' do - expect(subject.call(['192.168.1.0'])).to be_falsey - end + it { is_expected.to run.with_params('127.0.0.0').and_return(true) } + it { is_expected.to run.with_params('10.0.0.0').and_return(true) } + it { is_expected.to run.with_params('8.8.8.0').and_return(false) } end end - diff --git a/stdlib/spec/functions/has_key_spec.rb b/stdlib/spec/functions/has_key_spec.rb index 6b718005a..965d5a657 100755 --- a/stdlib/spec/functions/has_key_spec.rb +++ b/stdlib/spec/functions/has_key_spec.rb @@ -1,42 +1,15 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:has_key) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling has_key from puppet' do - it "should not compile when no arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$x = has_key()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when 1 argument is passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$x = has_key('foo')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should require the first value to be a Hash" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$x = has_key('foo', 'bar')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/) - end - end - - describe 'when calling the function has_key from a scope instance' do - it 'should detect existing keys' do - expect(scope.function_has_key([{'one' => 1}, 'one'])).to be_truthy - end - - it 'should detect existing keys' do - expect(scope.function_has_key([{'one' => 1}, 'two'])).to be_falsey - end - end +describe 'has_key' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params("one").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params("one", "two", "three").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params("one", "two").and_raise_error(Puppet::ParseError, /expects the first argument to be a hash/) } + it { is_expected.to run.with_params(1, "two").and_raise_error(Puppet::ParseError, /expects the first argument to be a hash/) } + it { is_expected.to run.with_params([], "two").and_raise_error(Puppet::ParseError, /expects the first argument to be a hash/) } + + it { is_expected.to run.with_params({ 'key' => 'value' }, "key").and_return(true) } + it { is_expected.to run.with_params({}, "key").and_return(false) } + it { is_expected.to run.with_params({ 'key' => 'value'}, "not a key").and_return(false) } end diff --git a/stdlib/spec/functions/hash_spec.rb b/stdlib/spec/functions/hash_spec.rb index ec2988b02..4fe99ceeb 100755 --- a/stdlib/spec/functions/hash_spec.rb +++ b/stdlib/spec/functions/hash_spec.rb @@ -1,19 +1,14 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the hash function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("hash")).to eq("function_hash") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_hash([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert an array to a hash" do - result = scope.function_hash([['a',1,'b',2,'c',3]]) - expect(result).to(eq({'a'=>1,'b'=>2,'c'=>3})) - end +describe 'hash' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params(['one']).and_raise_error(Puppet::ParseError, /Unable to compute/) } + it { is_expected.to run.with_params([]).and_return({}) } + it { is_expected.to run.with_params(['key1', 'value1']).and_return({ 'key1' => 'value1' }) } + it { is_expected.to run.with_params(['key1', 'value1', 'key2', 'value2']).and_return({ 'key1' => 'value1', 'key2' => 'value2' }) } end diff --git a/stdlib/spec/functions/intersection_spec.rb b/stdlib/spec/functions/intersection_spec.rb index 6361304fe..c0f608690 100755 --- a/stdlib/spec/functions/intersection_spec.rb +++ b/stdlib/spec/functions/intersection_spec.rb @@ -1,19 +1,21 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the intersection function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("intersection")).to eq("function_intersection") - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - expect { scope.function_intersection([]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should return the intersection of two arrays" do - result = scope.function_intersection([["a","b","c"],["b","c","d"]]) - expect(result).to(eq(["b","c"])) - end +describe 'intersection' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], []).and_return([]) } + it { is_expected.to run.with_params([], ['one']).and_return([]) } + it { is_expected.to run.with_params(['one'], []).and_return([]) } + it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['two', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['two', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['two', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three', 'four']).and_return(['two', 'three']) } + it 'should not confuse types' do is_expected.to run.with_params(['1', '2', '3'], [1, 2]).and_return([]) end end diff --git a/stdlib/spec/functions/is_array_spec.rb b/stdlib/spec/functions/is_array_spec.rb index 94920a4cb..7dd21c23b 100755 --- a/stdlib/spec/functions/is_array_spec.rb +++ b/stdlib/spec/functions/is_array_spec.rb @@ -1,29 +1,19 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_array function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_array")).to eq("function_is_array") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_array([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if passed an array" do - result = scope.function_is_array([[1,2,3]]) - expect(result).to(eq(true)) - end - - it "should return false if passed a hash" do - result = scope.function_is_array([{'a'=>1}]) - expect(result).to(eq(false)) - end - - it "should return false if passed a string" do - result = scope.function_is_array(["asdf"]) - expect(result).to(eq(false)) - end +describe 'is_array' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params([]).and_return(true) } + it { is_expected.to run.with_params(['one']).and_return(true) } + it { is_expected.to run.with_params([1]).and_return(true) } + it { is_expected.to run.with_params([{}]).and_return(true) } + it { is_expected.to run.with_params([[]]).and_return(true) } + it { is_expected.to run.with_params('').and_return(false) } + it { is_expected.to run.with_params('one').and_return(false) } + it { is_expected.to run.with_params(1).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } end diff --git a/stdlib/spec/functions/is_bool_spec.rb b/stdlib/spec/functions/is_bool_spec.rb index 4a342ba4f..76d619b00 100755 --- a/stdlib/spec/functions/is_bool_spec.rb +++ b/stdlib/spec/functions/is_bool_spec.rb @@ -1,44 +1,15 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_bool function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_bool")).to eq("function_is_bool") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_bool([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if passed a TrueClass" do - result = scope.function_is_bool([true]) - expect(result).to(eq(true)) - end - - it "should return true if passed a FalseClass" do - result = scope.function_is_bool([false]) - expect(result).to(eq(true)) - end - - it "should return false if passed the string 'true'" do - result = scope.function_is_bool(['true']) - expect(result).to(eq(false)) - end - - it "should return false if passed the string 'false'" do - result = scope.function_is_bool(['false']) - expect(result).to(eq(false)) - end - - it "should return false if passed an array" do - result = scope.function_is_bool([["a","b"]]) - expect(result).to(eq(false)) - end - - it "should return false if passed a hash" do - result = scope.function_is_bool([{"a" => "b"}]) - expect(result).to(eq(false)) - end +describe 'is_bool' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(true).and_return(true) } + it { is_expected.to run.with_params(false).and_return(true) } + it { is_expected.to run.with_params([1]).and_return(false) } + it { is_expected.to run.with_params([{}]).and_return(false) } + it { is_expected.to run.with_params([[]]).and_return(false) } + it { is_expected.to run.with_params([true]).and_return(false) } + it { is_expected.to run.with_params('true').and_return(false) } + it { is_expected.to run.with_params('false').and_return(false) } end diff --git a/stdlib/spec/functions/is_domain_name_spec.rb b/stdlib/spec/functions/is_domain_name_spec.rb index ef880612f..c1bf0e34b 100755 --- a/stdlib/spec/functions/is_domain_name_spec.rb +++ b/stdlib/spec/functions/is_domain_name_spec.rb @@ -1,81 +1,43 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_domain_name function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("function_is_domain_name") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_domain_name([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if a valid short domain name" do - result = scope.function_is_domain_name(["x.com"]) - expect(result).to(be_truthy) - end - - it "should return true if the domain is ." do - result = scope.function_is_domain_name(["."]) - expect(result).to(be_truthy) +describe 'is_domain_name' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_return(false) } + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params('').and_return(false) } + it { is_expected.to run.with_params('.').and_return(true) } + it { is_expected.to run.with_params('com').and_return(true) } + it { is_expected.to run.with_params('com.').and_return(true) } + it { is_expected.to run.with_params('x.com').and_return(true) } + it { is_expected.to run.with_params('x.com.').and_return(true) } + it { is_expected.to run.with_params('foo.example.com').and_return(true) } + it { is_expected.to run.with_params('foo.example.com.').and_return(true) } + it { is_expected.to run.with_params('2foo.example.com').and_return(true) } + it { is_expected.to run.with_params('2foo.example.com.').and_return(true) } + it { is_expected.to run.with_params('www.2foo.example.com').and_return(true) } + it { is_expected.to run.with_params('www.2foo.example.com.').and_return(true) } + describe 'inputs with spaces' do + it { is_expected.to run.with_params('invalid domain').and_return(false) } + end + describe 'inputs with hyphens' do + it { is_expected.to run.with_params('foo-bar.example.com').and_return(true) } + it { is_expected.to run.with_params('foo-bar.example.com.').and_return(true) } + it { is_expected.to run.with_params('www.foo-bar.example.com').and_return(true) } + it { is_expected.to run.with_params('www.foo-bar.example.com.').and_return(true) } + it { is_expected.to run.with_params('-foo.example.com').and_return(false) } + it { is_expected.to run.with_params('-foo.example.com').and_return(false) } end - - it "should return true if the domain is x.com." do - result = scope.function_is_domain_name(["x.com."]) - expect(result).to(be_truthy) - end - - it "should return true if a valid domain name" do - result = scope.function_is_domain_name(["foo.bar.com"]) - expect(result).to(be_truthy) - end - - it "should allow domain parts to start with numbers" do - result = scope.function_is_domain_name(["3foo.2bar.com"]) - expect(result).to(be_truthy) - end - - it "should allow domain to end with a dot" do - result = scope.function_is_domain_name(["3foo.2bar.com."]) - expect(result).to(be_truthy) - end - - it "should allow a single part domain" do - result = scope.function_is_domain_name(["orange"]) - expect(result).to(be_truthy) - end - - it "should return false if domain parts start with hyphens" do - result = scope.function_is_domain_name(["-3foo.2bar.com"]) - expect(result).to(be_falsey) - end - - it "should return true if domain contains hyphens" do - result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"]) - expect(result).to(be_truthy) - end - - it "should return false if domain name contains spaces" do - result = scope.function_is_domain_name(["not valid"]) - expect(result).to(be_falsey) - end - # Values obtained from Facter values will be frozen strings # in newer versions of Facter: - it "should not throw an exception if passed a frozen string" do - result = scope.function_is_domain_name(["my.domain.name".freeze]) - expect(result).to(be_truthy) + it { is_expected.to run.with_params('www.example.com'.freeze).and_return(true) } + describe 'top level domain must be alphabetic if there are multiple labels' do + it { is_expected.to run.with_params('2com').and_return(true) } + it { is_expected.to run.with_params('www.example.2com').and_return(false) } end - - it "should return false if top-level domain is not entirely alphabetic" do - result = scope.function_is_domain_name(["kiwi.2bar"]) - expect(result).to(be_falsey) - end - - it "should return false if domain name has the dotted-decimal form, e.g. an IPv4 address" do - result = scope.function_is_domain_name(["192.168.1.1"]) - expect(result).to(be_falsey) + describe 'IP addresses are not domain names' do + it { is_expected.to run.with_params('192.168.1.1').and_return(false) } end end diff --git a/stdlib/spec/functions/is_float_spec.rb b/stdlib/spec/functions/is_float_spec.rb index d926634e8..ffff971a7 100755 --- a/stdlib/spec/functions/is_float_spec.rb +++ b/stdlib/spec/functions/is_float_spec.rb @@ -1,33 +1,22 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_float function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'is_float' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(0.1, 0.2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should exist" do - expect(Puppet::Parser::Functions.function("is_float")).to eq("function_is_float") + describe 'passing a string' do + it { is_expected.to run.with_params('0.1').and_return(true) } + it { is_expected.to run.with_params('1.0').and_return(true) } + it { is_expected.to run.with_params('1').and_return(false) } + it { is_expected.to run.with_params('one').and_return(false) } + it { is_expected.to run.with_params('one 1.0').and_return(false) } + it { is_expected.to run.with_params('1.0 one').and_return(false) } end - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_float([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if a float" do - result = scope.function_is_float(["0.12"]) - expect(result).to(eq(true)) - end - - it "should return false if a string" do - result = scope.function_is_float(["asdf"]) - expect(result).to(eq(false)) - end - - it "should return false if an integer" do - result = scope.function_is_float(["3"]) - expect(result).to(eq(false)) - end - it "should return true if a float is created from an arithmetical operation" do - result = scope.function_is_float([3.2*2]) - expect(result).to(eq(true)) + describe 'passing numbers' do + it { is_expected.to run.with_params(0.1).and_return(true) } + it { is_expected.to run.with_params(1.0).and_return(true) } + it { is_expected.to run.with_params(1).and_return(false) } end end diff --git a/stdlib/spec/functions/is_function_available.rb b/stdlib/spec/functions/is_function_available.rb index 3a9aa1b23..44f08c081 100755 --- a/stdlib/spec/functions/is_function_available.rb +++ b/stdlib/spec/functions/is_function_available.rb @@ -1,31 +1,9 @@ -#!/usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_function_available function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_function_available")).to eq("function_is_function_available") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { @scope.function_is_function_available([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return false if a nonexistent function is passed" do - result = @scope.function_is_function_available(['jeff_mccunes_left_sock']) - expect(result).to(eq(false)) - end - - it "should return true if an available function is passed" do - result = @scope.function_is_function_available(['require']) - expect(result).to(eq(true)) - end - +describe 'is_function_available' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('include').and_return(true) } + it { is_expected.to run.with_params('no_such_function').and_return(false) } end diff --git a/stdlib/spec/functions/is_hash_spec.rb b/stdlib/spec/functions/is_hash_spec.rb index a84941111..c2599a02a 100755 --- a/stdlib/spec/functions/is_hash_spec.rb +++ b/stdlib/spec/functions/is_hash_spec.rb @@ -1,29 +1,11 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_hash function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_hash")).to eq("function_is_hash") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_hash([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if passed a hash" do - result = scope.function_is_hash([{"a"=>1,"b"=>2}]) - expect(result).to(eq(true)) - end - - it "should return false if passed an array" do - result = scope.function_is_hash([["a","b"]]) - expect(result).to(eq(false)) - end - - it "should return false if passed a string" do - result = scope.function_is_hash(["asdf"]) - expect(result).to(eq(false)) - end +describe 'is_hash' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('').and_return(false) } + it { is_expected.to run.with_params({}).and_return(true) } + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params(1).and_return(false) } end diff --git a/stdlib/spec/functions/is_integer_spec.rb b/stdlib/spec/functions/is_integer_spec.rb index f0cbca807..67263c18f 100755 --- a/stdlib/spec/functions/is_integer_spec.rb +++ b/stdlib/spec/functions/is_integer_spec.rb @@ -1,69 +1,25 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_integer function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_integer")).to eq("function_is_integer") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_integer([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if an integer" do - result = scope.function_is_integer(["3"]) - expect(result).to(eq(true)) - end - - it "should return true if a negative integer" do - result = scope.function_is_integer(["-7"]) - expect(result).to(eq(true)) - end - - it "should return false if a float" do - result = scope.function_is_integer(["3.2"]) - expect(result).to(eq(false)) - end - - it "should return false if a string" do - result = scope.function_is_integer(["asdf"]) - expect(result).to(eq(false)) - end - - it "should return true if an integer is created from an arithmetical operation" do - result = scope.function_is_integer([3*2]) - expect(result).to(eq(true)) - end - - it "should return false if an array" do - result = scope.function_is_numeric([["asdf"]]) - expect(result).to(eq(false)) - end - - it "should return false if a hash" do - result = scope.function_is_numeric([{"asdf" => false}]) - expect(result).to(eq(false)) - end - - it "should return false if a boolean" do - result = scope.function_is_numeric([true]) - expect(result).to(eq(false)) - end - - it "should return false if a whitespace is in the string" do - result = scope.function_is_numeric([" -1324"]) - expect(result).to(eq(false)) - end - - it "should return false if it is zero prefixed" do - result = scope.function_is_numeric(["0001234"]) - expect(result).to(eq(false)) - end - - it "should return false if it is wrapped inside an array" do - result = scope.function_is_numeric([[1234]]) - expect(result).to(eq(false)) - end +describe 'is_integer' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + it { is_expected.to run.with_params(3).and_return(true) } + it { is_expected.to run.with_params('3').and_return(true) } + it { is_expected.to run.with_params(-3).and_return(true) } + it { is_expected.to run.with_params('-3').and_return(true) } + + it { is_expected.to run.with_params(3.7).and_return(false) } + it { is_expected.to run.with_params('3.7').and_return(false) } + it { is_expected.to run.with_params(-3.7).and_return(false) } + it { is_expected.to run.with_params('3.7').and_return(false) } + + it { is_expected.to run.with_params('one').and_return(false) } + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params([1]).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params(true).and_return(false) } + it { is_expected.to run.with_params(false).and_return(false) } + it { is_expected.to run.with_params('0001234').and_return(false) } end diff --git a/stdlib/spec/functions/is_ip_address_spec.rb b/stdlib/spec/functions/is_ip_address_spec.rb index c16d12b16..a7a383a1e 100755 --- a/stdlib/spec/functions/is_ip_address_spec.rb +++ b/stdlib/spec/functions/is_ip_address_spec.rb @@ -1,39 +1,23 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_ip_address function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_ip_address")).to eq("function_is_ip_address") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_ip_address([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if an IPv4 address" do - result = scope.function_is_ip_address(["1.2.3.4"]) - expect(result).to(eq(true)) - end - - it "should return true if a full IPv6 address" do - result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) - expect(result).to(eq(true)) - end - - it "should return true if a compressed IPv6 address" do - result = scope.function_is_ip_address(["fe00::1"]) - expect(result).to(eq(true)) - end - - it "should return false if not valid" do - result = scope.function_is_ip_address(["asdf"]) - expect(result).to(eq(false)) - end - - it "should return false if IP octets out of range" do - result = scope.function_is_ip_address(["1.1.1.300"]) - expect(result).to(eq(false)) - end +describe 'is_ip_address' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('1.2.3.4').and_return(true) } + it { is_expected.to run.with_params('1.2.3.255').and_return(true) } + it { is_expected.to run.with_params('1.2.3.256').and_return(false) } + it { is_expected.to run.with_params('1.2.3').and_return(false) } + it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) } + it { is_expected.to run.with_params('fe00::1').and_return(true) } + it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74').and_return(true) } + it { is_expected.to run.with_params('FE80:0000:CD12:D123:E2F8:47FF:FE09:DD74').and_return(true) } + it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:zzzz').and_return(false) } + it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09').and_return(false) } + it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74:dd74').and_return(false) } + it { is_expected.to run.with_params('').and_return(false) } + it { is_expected.to run.with_params('one').and_return(false) } + it { is_expected.to run.with_params(1).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params([]).and_return(false) } end diff --git a/stdlib/spec/functions/is_mac_address_spec.rb b/stdlib/spec/functions/is_mac_address_spec.rb index 66edd197e..5f76a91b4 100755 --- a/stdlib/spec/functions/is_mac_address_spec.rb +++ b/stdlib/spec/functions/is_mac_address_spec.rb @@ -1,29 +1,24 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_mac_address function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_mac_address")).to eq("function_is_mac_address") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_mac_address([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if a valid mac address" do - result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) - expect(result).to(eq(true)) - end - - it "should return false if octets are out of range" do - result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) - expect(result).to(eq(false)) - end - - it "should return false if not valid" do - result = scope.function_is_mac_address(["not valid"]) - expect(result).to(eq(false)) - end +describe 'is_mac_address' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('00:a0:1f:12:7f:a0').and_return(true) } + it { is_expected.to run.with_params('00:A0:1F:12:7F:A0').and_return(true) } + it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) } + it { is_expected.to run.with_params('').and_return(false) } + it { is_expected.to run.with_params('one').and_return(false) } + it { + pending "should properly typecheck its arguments" + is_expected.to run.with_params(1).and_return(false) + } + it { + pending "should properly typecheck its arguments" + is_expected.to run.with_params({}).and_return(false) + } + it { + pending "should properly typecheck its arguments" + is_expected.to run.with_params([]).and_return(false) + } end diff --git a/stdlib/spec/functions/is_numeric_spec.rb b/stdlib/spec/functions/is_numeric_spec.rb index 4176961d7..d0f5a6eb6 100755 --- a/stdlib/spec/functions/is_numeric_spec.rb +++ b/stdlib/spec/functions/is_numeric_spec.rb @@ -1,119 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_numeric function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_numeric")).to eq("function_is_numeric") - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_is_numeric([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if an integer" do - result = scope.function_is_numeric(["3"]) - expect(result).to(eq(true)) - end - - it "should return true if a float" do - result = scope.function_is_numeric(["3.2"]) - expect(result).to(eq(true)) - end - - it "should return true if an integer is created from an arithmetical operation" do - result = scope.function_is_numeric([3*2]) - expect(result).to(eq(true)) - end - - it "should return true if a float is created from an arithmetical operation" do - result = scope.function_is_numeric([3.2*2]) - expect(result).to(eq(true)) - end - - it "should return false if a string" do - result = scope.function_is_numeric(["asdf"]) - expect(result).to(eq(false)) - end - - it "should return false if an array" do - result = scope.function_is_numeric([["asdf"]]) - expect(result).to(eq(false)) - end - - it "should return false if an array of integers" do - result = scope.function_is_numeric([[1,2,3,4]]) - expect(result).to(eq(false)) - end - - it "should return false if a hash" do - result = scope.function_is_numeric([{"asdf" => false}]) - expect(result).to(eq(false)) - end - - it "should return false if a hash with numbers in it" do - result = scope.function_is_numeric([{1 => 2}]) - expect(result).to(eq(false)) - end - - it "should return false if a boolean" do - result = scope.function_is_numeric([true]) - expect(result).to(eq(false)) - end - - it "should return true if a negative float with exponent" do - result = scope.function_is_numeric(["-342.2315e-12"]) - expect(result).to(eq(true)) - end - - it "should return false if a negative integer with whitespaces before/after the dash" do - result = scope.function_is_numeric([" - 751"]) - expect(result).to(eq(false)) - end - -# it "should return true if a hexadecimal" do -# result = scope.function_is_numeric(["0x52F8c"]) -# result.should(eq(true)) -# end -# -# it "should return true if a hexadecimal with uppercase 0X prefix" do -# result = scope.function_is_numeric(["0X52F8c"]) -# result.should(eq(true)) -# end -# -# it "should return false if a hexadecimal without a prefix" do -# result = scope.function_is_numeric(["52F8c"]) -# result.should(eq(false)) -# end -# -# it "should return true if a octal" do -# result = scope.function_is_numeric(["0751"]) -# result.should(eq(true)) -# end -# -# it "should return true if a negative hexadecimal" do -# result = scope.function_is_numeric(["-0x52F8c"]) -# result.should(eq(true)) -# end -# -# it "should return true if a negative octal" do -# result = scope.function_is_numeric(["-0751"]) -# result.should(eq(true)) -# end -# -# it "should return false if a negative octal with whitespaces before/after the dash" do -# result = scope.function_is_numeric([" - 0751"]) -# result.should(eq(false)) -# end -# -# it "should return false if a bad hexadecimal" do -# result = scope.function_is_numeric(["0x23d7g"]) -# result.should(eq(false)) -# end -# -# it "should return false if a bad octal" do -# result = scope.function_is_numeric(["0287"]) -# result.should(eq(false)) -# end +describe 'is_numeric' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + it { is_expected.to run.with_params(3).and_return(true) } + it { is_expected.to run.with_params('3').and_return(true) } + it { is_expected.to run.with_params(-3).and_return(true) } + it { is_expected.to run.with_params('-3').and_return(true) } + + it { is_expected.to run.with_params(3.7).and_return(true) } + it { is_expected.to run.with_params('3.7').and_return(true) } + it { is_expected.to run.with_params(-3.7).and_return(true) } + it { is_expected.to run.with_params('3.7').and_return(true) } + + it { is_expected.to run.with_params('-342.2315e-12').and_return(true) } + + it { is_expected.to run.with_params('one').and_return(false) } + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params([1]).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params(true).and_return(false) } + it { is_expected.to run.with_params(false).and_return(false) } + it { is_expected.to run.with_params('0001234').and_return(false) } + it { is_expected.to run.with_params(' - 1234').and_return(false) } end diff --git a/stdlib/spec/functions/is_string_spec.rb b/stdlib/spec/functions/is_string_spec.rb index 6a0801ae8..8e459ccfe 100755 --- a/stdlib/spec/functions/is_string_spec.rb +++ b/stdlib/spec/functions/is_string_spec.rb @@ -1,34 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_string function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'is_string' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } - it "should exist" do - expect(Puppet::Parser::Functions.function("is_string")).to eq("function_is_string") - end + it { is_expected.to run.with_params(3).and_return(false) } + it { is_expected.to run.with_params('3').and_return(false) } + it { is_expected.to run.with_params(-3).and_return(false) } + it { is_expected.to run.with_params('-3').and_return(false) } - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_string([]) }.to( raise_error(Puppet::ParseError)) - end + it { is_expected.to run.with_params(3.7).and_return(false) } + it { is_expected.to run.with_params('3.7').and_return(false) } + it { is_expected.to run.with_params(-3.7).and_return(false) } + it { is_expected.to run.with_params('3.7').and_return(false) } - it "should return true if a string" do - result = scope.function_is_string(["asdf"]) - expect(result).to(eq(true)) - end - - it "should return false if an integer" do - result = scope.function_is_string(["3"]) - expect(result).to(eq(false)) - end - - it "should return false if a float" do - result = scope.function_is_string(["3.23"]) - expect(result).to(eq(false)) - end - - it "should return false if an array" do - result = scope.function_is_string([["a","b","c"]]) - expect(result).to(eq(false)) - end + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params([1]).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params(true).and_return(false) } + it { is_expected.to run.with_params(false).and_return(false) } + it { is_expected.to run.with_params('one').and_return(true) } + it { is_expected.to run.with_params('0001234').and_return(true) } end diff --git a/stdlib/spec/functions/join_keys_to_values_spec.rb b/stdlib/spec/functions/join_keys_to_values_spec.rb index 4a9ae87a2..6c109d1c2 100755 --- a/stdlib/spec/functions/join_keys_to_values_spec.rb +++ b/stdlib/spec/functions/join_keys_to_values_spec.rb @@ -1,40 +1,19 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the join_keys_to_values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("join_keys_to_values")).to eq("function_join_keys_to_values") - end - - it "should raise a ParseError if there are fewer than two arguments" do - expect { scope.function_join_keys_to_values([{}]) }.to raise_error Puppet::ParseError - end - - it "should raise a ParseError if there are greater than two arguments" do - expect { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.to raise_error Puppet::ParseError - end - - it "should raise a TypeError if the first argument is an array" do - expect { scope.function_join_keys_to_values([[1,2], ',']) }.to raise_error TypeError - end - - it "should raise a TypeError if the second argument is an array" do - expect { scope.function_join_keys_to_values([{}, [1,2]]) }.to raise_error TypeError - end - - it "should raise a TypeError if the second argument is a number" do - expect { scope.function_join_keys_to_values([{}, 1]) }.to raise_error TypeError - end - - it "should return an empty array given an empty hash" do - result = scope.function_join_keys_to_values([{}, ":"]) - expect(result).to eq([]) - end - - it "should join hash's keys to its values" do - result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"]) - expect(result).to match_array(['a:1','2:foo','b:']) +describe 'join_keys_to_values' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Takes exactly two arguments/) } + it { is_expected.to run.with_params({}, '', '').and_raise_error(Puppet::ParseError, /Takes exactly two arguments/) } + it { is_expected.to run.with_params('one', '').and_raise_error(TypeError, /The first argument must be a hash/) } + it { is_expected.to run.with_params({}, 2).and_raise_error(TypeError, /The second argument must be a string/) } + + it { is_expected.to run.with_params({}, '').and_return([]) } + it { is_expected.to run.with_params({}, ':').and_return([]) } + it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return(['keyvalue']) } + it { is_expected.to run.with_params({ 'key' => 'value' }, ':').and_return(['key:value']) } + it { is_expected.to run.with_params({ 'key' => nil }, ':').and_return(['key:']) } + it 'should run join_keys_to_values(, ":") and return the proper array' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }, ':']) + expect(result.sort).to eq(['key1:value1', 'key2:value2'].sort) end end diff --git a/stdlib/spec/functions/join_spec.rb b/stdlib/spec/functions/join_spec.rb index 793c36fa3..a3005714b 100755 --- a/stdlib/spec/functions/join_spec.rb +++ b/stdlib/spec/functions/join_spec.rb @@ -1,19 +1,19 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the join function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'join' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the second.") + is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Requires array to work with/) } + it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, /Requires string to work with/) } - it "should exist" do - expect(Puppet::Parser::Functions.function("join")).to eq("function_join") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_join([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should join an array into a string" do - result = scope.function_join([["a","b","c"], ":"]) - expect(result).to(eq("a:b:c")) - end + it { is_expected.to run.with_params([]).and_return('') } + it { is_expected.to run.with_params([], ':').and_return('') } + it { is_expected.to run.with_params(['one']).and_return('one') } + it { is_expected.to run.with_params(['one'], ':').and_return('one') } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return('onetwothree') } + it { is_expected.to run.with_params(['one', 'two', 'three'], ':').and_return('one:two:three') } end diff --git a/stdlib/spec/functions/keys_spec.rb b/stdlib/spec/functions/keys_spec.rb index f2e7d428e..2e009dcc8 100755 --- a/stdlib/spec/functions/keys_spec.rb +++ b/stdlib/spec/functions/keys_spec.rb @@ -1,21 +1,19 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the keys function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("keys")).to eq("function_keys") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_keys([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return an array of keys when given a hash" do - result = scope.function_keys([{'a'=>1, 'b'=>2}]) - # =~ performs 'array with same elements' (set) matching - # For more info see RSpec::Matchers::MatchArray - expect(result).to match_array(['a','b']) +describe 'keys' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /Requires hash to work with/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires hash to work with/) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /Requires hash to work with/) } + it { is_expected.to run.with_params({}).and_return([]) } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key']) } + it 'should return the array of keys' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) + expect(result).to match_array(['key1', 'key2']) end end diff --git a/stdlib/spec/functions/loadyaml_spec.rb b/stdlib/spec/functions/loadyaml_spec.rb index 4b8d40623..ffc714d11 100755 --- a/stdlib/spec/functions/loadyaml_spec.rb +++ b/stdlib/spec/functions/loadyaml_spec.rb @@ -1,31 +1,24 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the loadyaml function" do - include PuppetlabsSpec::Files - - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("loadyaml")).to eq("function_loadyaml") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_loadyaml([]) }.to raise_error(Puppet::ParseError) +describe 'loadyaml' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + context 'when a non-existing file is specified' do + let(:filename) { '/tmp/doesnotexist' } + before { + File.expects(:exists?).with(filename).returns(false).once + YAML.expects(:load_file).never + } + it { is_expected.to run.with_params(filename).and_return(nil) } end - - it "should return nil when file does not exist" do - yaml_file = tmpfilename ('yamlfile') - result = scope.function_loadyaml([yaml_file]) - expect(result).to(eq(nil)) - end - - it "should convert YAML file to a data structure" do - yaml_file = tmpfilename ('yamlfile') - File.open(yaml_file, 'w') do |fh| - fh.write("---\n aaa: 1\n bbb: 2\n ccc: 3\n ddd: 4\n") - end - result = scope.function_loadyaml([yaml_file]) - expect(result).to eq({"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 }) + context 'when an existing file is specified' do + let(:filename) { '/tmp/doesexist' } + let(:data) { { 'key' => 'value' } } + before { + File.expects(:exists?).with(filename).returns(true).once + YAML.expects(:load_file).with(filename).returns(data).once + } + it { is_expected.to run.with_params(filename).and_return(data) } end end diff --git a/stdlib/spec/functions/lstrip_spec.rb b/stdlib/spec/functions/lstrip_spec.rb index 68cca1c5d..981794edf 100755 --- a/stdlib/spec/functions/lstrip_spec.rb +++ b/stdlib/spec/functions/lstrip_spec.rb @@ -1,28 +1,34 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the lstrip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("lstrip")).to eq("function_lstrip") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_lstrip([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should lstrip a string" do - result = scope.function_lstrip([" asdf"]) - expect(result).to(eq('asdf')) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new(" asdf") - result = scope.function_lstrip([value]) - result.should(eq("asdf")) - end +describe 'lstrip' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params(' ').and_return('') } + it { is_expected.to run.with_params(' ').and_return('') } + it { is_expected.to run.with_params("\t").and_return('') } + it { is_expected.to run.with_params("\t ").and_return('') } + it { is_expected.to run.with_params('one').and_return('one') } + it { is_expected.to run.with_params(' one').and_return('one') } + it { is_expected.to run.with_params(' one').and_return('one') } + it { is_expected.to run.with_params("\tone").and_return('one') } + it { is_expected.to run.with_params("\t one").and_return('one') } + it { is_expected.to run.with_params('one ').and_return('one ') } + it { is_expected.to run.with_params(' one ').and_return('one ') } + it { is_expected.to run.with_params(' one ').and_return('one ') } + it { is_expected.to run.with_params("\tone ").and_return('one ') } + it { is_expected.to run.with_params("\t one ").and_return('one ') } + it { is_expected.to run.with_params("one \t").and_return("one \t") } + it { is_expected.to run.with_params(" one \t").and_return("one \t") } + it { is_expected.to run.with_params(" one \t").and_return("one \t") } + it { is_expected.to run.with_params("\tone \t").and_return("one \t") } + it { is_expected.to run.with_params("\t one \t").and_return("one \t") } + it { is_expected.to run.with_params(' o n e ').and_return('o n e ') } + it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return('one ') } end diff --git a/stdlib/spec/functions/max_spec.rb b/stdlib/spec/functions/max_spec.rb index c3d8a132f..66fb0c869 100755 --- a/stdlib/spec/functions/max_spec.rb +++ b/stdlib/spec/functions/max_spec.rb @@ -1,27 +1,21 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the max function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("max")).to eq("function_max") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_max([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should be able to compare strings" do - expect(scope.function_max(["albatross","dog","horse"])).to(eq("horse")) - end - - it "should be able to compare numbers" do - expect(scope.function_max([6,8,4])).to(eq(8)) - end +describe 'max' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_return(1) } + it { is_expected.to run.with_params(1, 2).and_return(2) } + it { is_expected.to run.with_params(1, 2, 3).and_return(3) } + it { is_expected.to run.with_params(3, 2, 1).and_return(3) } + it { is_expected.to run.with_params('one').and_return('one') } + it { is_expected.to run.with_params('one', 'two').and_return('two') } + it { is_expected.to run.with_params('one', 'two', 'three').and_return('two') } + it { is_expected.to run.with_params('three', 'two', 'one').and_return('two') } - it "should be able to compare a number with a stringified number" do - expect(scope.function_max([1,"2"])).to(eq("2")) + describe 'implementation artifacts' do + it { is_expected.to run.with_params(1, 'one').and_return('one') } + it { is_expected.to run.with_params('1', 'one').and_return('one') } + it { is_expected.to run.with_params('1.3e1', '1.4e0').and_return('1.4e0') } + it { is_expected.to run.with_params(1.3e1, 1.4e0).and_return(1.3e1) } end end diff --git a/stdlib/spec/functions/member_spec.rb b/stdlib/spec/functions/member_spec.rb index 1a1d7c660..527f887fa 100755 --- a/stdlib/spec/functions/member_spec.rb +++ b/stdlib/spec/functions/member_spec.rb @@ -1,34 +1,21 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the member function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("member")).to eq("function_member") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_member([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if a member is in an array" do - result = scope.function_member([["a","b","c"], "a"]) - expect(result).to(eq(true)) - end - - it "should return false if a member is not in an array" do - result = scope.function_member([["a","b","c"], "d"]) - expect(result).to(eq(false)) - end - - it "should return true if a member array is in an array" do - result = scope.function_member([["a","b","c"], ["a", "b"]]) - expect(result).to(eq(true)) - end - - it "should return false if a member array is not in an array" do - result = scope.function_member([["a","b","c"], ["d", "e"]]) - expect(result).to(eq(false)) - end +describe 'member' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], [], []).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params([], '').and_return(false) } + it { is_expected.to run.with_params([], ['']).and_return(false) } + it { is_expected.to run.with_params([''], '').and_return(true) } + it { is_expected.to run.with_params([''], ['']).and_return(true) } + it { is_expected.to run.with_params([], 'one').and_return(false) } + it { is_expected.to run.with_params([], ['one']).and_return(false) } + it { is_expected.to run.with_params(['one'], 'one').and_return(true) } + it { is_expected.to run.with_params(['one'], ['one']).and_return(true) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four'], ['four', 'two']).and_return(true) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four'], ['four', 'five']).and_return(false) } end diff --git a/stdlib/spec/functions/merge_spec.rb b/stdlib/spec/functions/merge_spec.rb index 2abf97622..7b53363ed 100755 --- a/stdlib/spec/functions/merge_spec.rb +++ b/stdlib/spec/functions/merge_spec.rb @@ -1,52 +1,25 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:merge) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling merge from puppet' do - it "should not compile when no arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$x = merge()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when 1 argument is passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - end - - describe 'when calling merge on the scope instance' do - it 'should require all parameters are hashes' do - expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) - expect { new_hash = scope.function_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) - end - - it 'should accept empty strings as puppet undef' do - expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error - end - - it 'should be able to merge two hashes' do - new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) - expect(new_hash['one']).to eq('1') - expect(new_hash['two']).to eq('2') - expect(new_hash['three']).to eq('2') - end - - it 'should merge multiple hashes' do - hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - expect(hash['one']).to eq('3') - end - - it 'should accept empty hashes' do - expect(scope.function_merge([{},{},{}])).to eq({}) - end +describe 'merge' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params({}, 'two').and_raise_error(Puppet::ParseError, /unexpected argument type String/) } + it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) } + it { + pending 'should not special case this' + is_expected.to run.with_params({}).and_return({}) + } + it { is_expected.to run.with_params({}, {}).and_return({}) } + it { is_expected.to run.with_params({}, {}, {}).and_return({}) } + describe 'should accept empty strings as puppet undef' do + it { is_expected.to run.with_params({}, '').and_return({}) } end + it { is_expected.to run.with_params({ 'key' => 'value' }, {}).and_return({ 'key' => 'value' }) } + it { is_expected.to run.with_params({}, { 'key' => 'value' }).and_return({ 'key' => 'value' }) } + it { is_expected.to run.with_params({ 'key' => 'value1' }, { 'key' => 'value2' }).and_return({ 'key' => 'value2' }) } + it { + is_expected.to run \ + .with_params({ 'key1' => 'value1' }, { 'key2' => 'value2' }, { 'key3' => 'value3' }) \ + .and_return({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }) + } end diff --git a/stdlib/spec/functions/min_spec.rb b/stdlib/spec/functions/min_spec.rb index 35a08900b..c840a72c9 100755 --- a/stdlib/spec/functions/min_spec.rb +++ b/stdlib/spec/functions/min_spec.rb @@ -1,27 +1,21 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the min function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("min")).to eq("function_min") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_min([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should be able to compare strings" do - expect(scope.function_min(["albatross","dog","horse"])).to(eq("albatross")) - end - - it "should be able to compare numbers" do - expect(scope.function_min([6,8,4])).to(eq(4)) - end +describe 'min' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_return(1) } + it { is_expected.to run.with_params(1, 2).and_return(1) } + it { is_expected.to run.with_params(1, 2, 3).and_return(1) } + it { is_expected.to run.with_params(3, 2, 1).and_return(1) } + it { is_expected.to run.with_params('one').and_return('one') } + it { is_expected.to run.with_params('one', 'two').and_return('one') } + it { is_expected.to run.with_params('one', 'two', 'three').and_return('one') } + it { is_expected.to run.with_params('three', 'two', 'one').and_return('one') } - it "should be able to compare a number with a stringified number" do - expect(scope.function_min([1,"2"])).to(eq(1)) + describe 'implementation artifacts' do + it { is_expected.to run.with_params(1, 'one').and_return(1) } + it { is_expected.to run.with_params('1', 'one').and_return('1') } + it { is_expected.to run.with_params('1.3e1', '1.4e0').and_return('1.3e1') } + it { is_expected.to run.with_params(1.3e1, 1.4e0).and_return(1.4e0) } end end diff --git a/stdlib/spec/functions/num2bool_spec.rb b/stdlib/spec/functions/num2bool_spec.rb index d0ba93548..494afff9f 100755 --- a/stdlib/spec/functions/num2bool_spec.rb +++ b/stdlib/spec/functions/num2bool_spec.rb @@ -1,67 +1,22 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the num2bool function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("num2bool")).to eq("function_num2bool") - end - - it "should raise a ParseError if there are no arguments" do - expect { scope.function_num2bool([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are more than 1 arguments" do - expect { scope.function_num2bool(["foo","bar"]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if passed something non-numeric" do - expect { scope.function_num2bool(["xyzzy"]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if passed string 1" do - result = scope.function_num2bool(["1"]) - expect(result).to(be_truthy) - end - - it "should return true if passed string 1.5" do - result = scope.function_num2bool(["1.5"]) - expect(result).to(be_truthy) - end - - it "should return true if passed number 1" do - result = scope.function_num2bool([1]) - expect(result).to(be_truthy) - end - - it "should return false if passed string 0" do - result = scope.function_num2bool(["0"]) - expect(result).to(be_falsey) - end - - it "should return false if passed number 0" do - result = scope.function_num2bool([0]) - expect(result).to(be_falsey) - end - - it "should return false if passed string -1" do - result = scope.function_num2bool(["-1"]) - expect(result).to(be_falsey) - end - - it "should return false if passed string -1.5" do - result = scope.function_num2bool(["-1.5"]) - expect(result).to(be_falsey) - end - - it "should return false if passed number -1" do - result = scope.function_num2bool([-1]) - expect(result).to(be_falsey) - end - - it "should return false if passed float -1.5" do - result = scope.function_num2bool([-1.5]) - expect(result).to(be_falsey) - end +describe 'num2bool' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('abc').and_raise_error(Puppet::ParseError, /does not look like a number/) } + it { is_expected.to run.with_params(1).and_return(true) } + it { is_expected.to run.with_params('1').and_return(true) } + it { is_expected.to run.with_params(1.5).and_return(true) } + it { is_expected.to run.with_params('1.5').and_return(true) } + it { is_expected.to run.with_params(-1).and_return(false) } + it { is_expected.to run.with_params('-1').and_return(false) } + it { is_expected.to run.with_params(-1.5).and_return(false) } + it { is_expected.to run.with_params('-1.5').and_return(false) } + it { is_expected.to run.with_params(0).and_return(false) } + it { is_expected.to run.with_params('0').and_return(false) } + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params('[]').and_raise_error(Puppet::ParseError, /does not look like a number/) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params('{}').and_raise_error(Puppet::ParseError, /does not look like a number/) } end diff --git a/stdlib/spec/functions/parsejson_spec.rb b/stdlib/spec/functions/parsejson_spec.rb index 1dd41b960..436566e79 100755 --- a/stdlib/spec/functions/parsejson_spec.rb +++ b/stdlib/spec/functions/parsejson_spec.rb @@ -1,22 +1,9 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the parsejson function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("parsejson")).to eq("function_parsejson") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_parsejson([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert JSON to a data structure" do - json = <<-EOS -["aaa","bbb","ccc"] -EOS - result = scope.function_parsejson([json]) - expect(result).to(eq(['aaa','bbb','ccc'])) - end +describe 'parsejson' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('["one"').and_raise_error(PSON::ParserError) } + it { is_expected.to run.with_params('["one", "two", "three"]').and_return(['one', 'two', 'three']) } end diff --git a/stdlib/spec/functions/parseyaml_spec.rb b/stdlib/spec/functions/parseyaml_spec.rb index e5f145ba1..fb635f8ee 100755 --- a/stdlib/spec/functions/parseyaml_spec.rb +++ b/stdlib/spec/functions/parseyaml_spec.rb @@ -1,24 +1,14 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the parseyaml function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("parseyaml")).to eq("function_parseyaml") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_parseyaml([]) }.to( raise_error(Puppet::ParseError)) +describe 'parseyaml' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('["one", "two", "three"]').and_return(['one', 'two', 'three']) } + context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do + it { is_expected.to run.with_params('["one"').and_raise_error(Psych::SyntaxError) } end - - it "should convert YAML to a data structure" do - yaml = <<-EOS -- aaa -- bbb -- ccc -EOS - result = scope.function_parseyaml([yaml]) - expect(result).to(eq(['aaa','bbb','ccc'])) + context 'when running on ruby 1.8.7, which does not have Psych', :if => RUBY_VERSION == '1.8.7' do + it { is_expected.to run.with_params('["one"').and_raise_error(ArgumentError) } end end diff --git a/stdlib/spec/functions/pick_default_spec.rb b/stdlib/spec/functions/pick_default_spec.rb index db10cc354..e2fc64a11 100755 --- a/stdlib/spec/functions/pick_default_spec.rb +++ b/stdlib/spec/functions/pick_default_spec.rb @@ -1,58 +1,24 @@ -#!/usr/bin/env ruby -S rspec require 'spec_helper' -describe "the pick_default function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("pick_default")).to eq("function_pick_default") - end - - it 'should return the correct value' do - expect(scope.function_pick_default(['first', 'second'])).to eq('first') - end - - it 'should return the correct value if the first value is empty' do - expect(scope.function_pick_default(['', 'second'])).to eq('second') - end - - it 'should skip empty string values' do - expect(scope.function_pick_default(['', 'first'])).to eq('first') - end - - it 'should skip :undef values' do - expect(scope.function_pick_default([:undef, 'first'])).to eq('first') - end - - it 'should skip :undefined values' do - expect(scope.function_pick_default([:undefined, 'first'])).to eq('first') - end - - it 'should return the empty string if it is the last possibility' do - expect(scope.function_pick_default([:undef, :undefined, ''])).to eq('') - end - - it 'should return :undef if it is the last possibility' do - expect(scope.function_pick_default(['', :undefined, :undef])).to eq(:undef) - end - - it 'should return :undefined if it is the last possibility' do - expect(scope.function_pick_default([:undef, '', :undefined])).to eq(:undefined) - end - - it 'should return the empty string if it is the only possibility' do - expect(scope.function_pick_default([''])).to eq('') - end - - it 'should return :undef if it is the only possibility' do - expect(scope.function_pick_default([:undef])).to eq(:undef) - end - - it 'should return :undefined if it is the only possibility' do - expect(scope.function_pick_default([:undefined])).to eq(:undefined) - end - - it 'should error if no values are passed' do - expect { scope.function_pick_default([]) }.to raise_error(Puppet::Error, /Must receive at least one argument./) +describe 'pick_default' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::Error, /Must receive at least one argument/) } + + it { is_expected.to run.with_params('one', 'two').and_return('one') } + it { is_expected.to run.with_params('', 'two').and_return('two') } + it { is_expected.to run.with_params(:undef, 'two').and_return('two') } + it { is_expected.to run.with_params(:undefined, 'two').and_return('two') } + it { is_expected.to run.with_params(nil, 'two').and_return('two') } + + [ '', :undef, :undefined, nil, {}, [], 1, 'default' ].each do |value| + describe "when providing #{value.inspect} as default" do + it { is_expected.to run.with_params('one', value).and_return('one') } + it { is_expected.to run.with_params([], value).and_return([]) } + it { is_expected.to run.with_params({}, value).and_return({}) } + it { is_expected.to run.with_params(value, value).and_return(value) } + it { is_expected.to run.with_params(:undef, value).and_return(value) } + it { is_expected.to run.with_params(:undefined, value).and_return(value) } + it { is_expected.to run.with_params(nil, value).and_return(value) } + end end end diff --git a/stdlib/spec/functions/pick_spec.rb b/stdlib/spec/functions/pick_spec.rb index 8be8f5875..2c7caa87e 100755 --- a/stdlib/spec/functions/pick_spec.rb +++ b/stdlib/spec/functions/pick_spec.rb @@ -1,34 +1,12 @@ -#!/usr/bin/env ruby -S rspec require 'spec_helper' -describe "the pick function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("pick")).to eq("function_pick") - end - - it 'should return the correct value' do - expect(scope.function_pick(['first', 'second'])).to eq('first') - end - - it 'should return the correct value if the first value is empty' do - expect(scope.function_pick(['', 'second'])).to eq('second') - end - - it 'should remove empty string values' do - expect(scope.function_pick(['', 'first'])).to eq('first') - end - - it 'should remove :undef values' do - expect(scope.function_pick([:undef, 'first'])).to eq('first') - end - - it 'should remove :undefined values' do - expect(scope.function_pick([:undefined, 'first'])).to eq('first') - end - - it 'should error if no values are passed' do - expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at least one non empty value")) - end +describe 'pick' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /must receive at least one non empty value/) } + it { is_expected.to run.with_params('', nil, :undef, :undefined).and_raise_error(Puppet::ParseError, /must receive at least one non empty value/) } + it { is_expected.to run.with_params('one', 'two').and_return('one') } + it { is_expected.to run.with_params('', 'two').and_return('two') } + it { is_expected.to run.with_params(:undef, 'two').and_return('two') } + it { is_expected.to run.with_params(:undefined, 'two').and_return('two') } + it { is_expected.to run.with_params(nil, 'two').and_return('two') } end diff --git a/stdlib/spec/functions/prefix_spec.rb b/stdlib/spec/functions/prefix_spec.rb index aec8a7d98..37610221a 100755 --- a/stdlib/spec/functions/prefix_spec.rb +++ b/stdlib/spec/functions/prefix_spec.rb @@ -1,33 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the prefix function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) - end - - it "raises an error if the first argument is not an array" do - expect { - scope.function_prefix([Object.new]) - }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) - end - - - it "raises an error if the second argument is not a string" do - expect { - scope.function_prefix([['first', 'second'], 42]) - }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) - end - - it "returns a prefixed array" do - result = scope.function_prefix([['a','b','c'], 'p']) - expect(result).to(eq(['pa','pb','pc'])) - end - - it "returns a prefixed hash" do - result = scope.function_prefix([{'a' => 'b','b' => 'c','c' => 'd'}, 'p']) - expect(result).to(eq({'pa'=>'b','pb'=>'c','pc'=>'d'})) - end +describe 'prefix' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the second.") + is_expected.to run.with_params([], 'a', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /expected first argument to be an Array or a Hash/) } + it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, /expected second argument to be a String/) } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['one', 2]).and_return(['one', '2']) } + it { is_expected.to run.with_params([], '').and_return([]) } + it { is_expected.to run.with_params([''], '').and_return(['']) } + it { is_expected.to run.with_params(['one'], 'pre').and_return(['preone']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'pre').and_return(['preone', 'pretwo', 'prethree']) } + it { is_expected.to run.with_params({}).and_return({}) } + it { is_expected.to run.with_params({ 'key1' => 'value1', 2 => 3}).and_return({ 'key1' => 'value1', '2' => 3 }) } + it { is_expected.to run.with_params({}, '').and_return({}) } + it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return({ 'key' => 'value' }) } + it { is_expected.to run.with_params({ 'key' => 'value' }, 'pre').and_return({ 'prekey' => 'value' }) } + it { + is_expected.to run \ + .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'pre') \ + .and_return({ 'prekey1' => 'value1', 'prekey2' => 'value2', 'prekey3' => 'value3' }) + } end diff --git a/stdlib/spec/functions/private_spec.rb b/stdlib/spec/functions/private_spec.rb index c90282ed7..a13be6439 100644 --- a/stdlib/spec/functions/private_spec.rb +++ b/stdlib/spec/functions/private_spec.rb @@ -1,17 +1,13 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:private) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - subject do - function_name = Puppet::Parser::Functions.function(:private) - scope.method(function_name) - end - +describe 'private' do it 'should issue a warning' do scope.expects(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") - subject.call [] + begin + subject.call [] + rescue + # ignore this + end end context "when called from inside module" do diff --git a/stdlib/spec/functions/pw_hash_spec.rb b/stdlib/spec/functions/pw_hash_spec.rb index 337809085..df5348c90 100644 --- a/stdlib/spec/functions/pw_hash_spec.rb +++ b/stdlib/spec/functions/pw_hash_spec.rb @@ -1,96 +1,69 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the pw_hash function" do +describe 'pw_hash' do - before :all do - @enhanced_salts_supported = RUBY_PLATFORM == 'java' - end - - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("pw_hash")).to eq("function_pw_hash") - end + it { is_expected.not_to eq(nil) } - it "should raise an ArgumentError if there are less than 3 arguments" do - expect { scope.function_pw_hash([]) }.to( raise_error(ArgumentError, /[Ww]rong number of arguments/) ) - expect { scope.function_pw_hash(['password']) }.to( raise_error(ArgumentError, /[Ww]rong number of arguments/) ) - expect { scope.function_pw_hash(['password', 'sha-512']) }.to( raise_error(ArgumentError, /[Ww]rong number of arguments/) ) + context 'when there are less than 3 arguments' do + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('password').and_raise_error(ArgumentError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('password', 'sha-256').and_raise_error(ArgumentError, /wrong number of arguments/i) } end - it "should raise an ArgumentError if there are more than 3 arguments" do - expect { scope.function_pw_hash(['password', 'sha-512', 'salt', 5]) }.to( raise_error(ArgumentError, /[Ww]rong number of arguments/) ) + context 'when there are more than 3 arguments' do + it { is_expected.to run.with_params('password', 'sha-256', 'salt', 'extra').and_raise_error(ArgumentError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('password', 'sha-256', 'salt', 'extra', 'extra').and_raise_error(ArgumentError, /wrong number of arguments/i) } end - it "should raise an ArgumentError if the first argument is not a string" do - expect { scope.function_pw_hash([['password'], 'sha-512', 'salt']) }.to( raise_error(ArgumentError, /first argument must be a string/) ) - # in Puppet 3, numbers are passed as strings, so we can't test that + context 'when the first argument is not a string' do + it { is_expected.to run.with_params([], 'sha-256', 'salt').and_raise_error(ArgumentError, /first argument must be a string/) } + it { is_expected.to run.with_params({}, 'sha-256', 'salt').and_raise_error(ArgumentError, /first argument must be a string/) } + it { is_expected.to run.with_params(1, 'sha-256', 'salt').and_raise_error(ArgumentError, /first argument must be a string/) } + it { is_expected.to run.with_params(true, 'sha-256', 'salt').and_raise_error(ArgumentError, /first argument must be a string/) } end - it "should return nil if the first argument is empty" do - expect(scope.function_pw_hash(['', 'sha-512', 'salt'])).to eq(nil) + context 'when the first argument is undefined' do + it { is_expected.to run.with_params('', 'sha-256', 'salt').and_return(nil) } + it { is_expected.to run.with_params(nil, 'sha-256', 'salt').and_return(nil) } end - it "should return nil if the first argument is undef" do - expect(scope.function_pw_hash([nil, 'sha-512', 'salt'])).to eq(nil) + context 'when the second argument is not a string' do + it { is_expected.to run.with_params('password', [], 'salt').and_raise_error(ArgumentError, /second argument must be a string/) } + it { is_expected.to run.with_params('password', {}, 'salt').and_raise_error(ArgumentError, /second argument must be a string/) } + it { is_expected.to run.with_params('password', 1, 'salt').and_raise_error(ArgumentError, /second argument must be a string/) } + it { is_expected.to run.with_params('password', true, 'salt').and_raise_error(ArgumentError, /second argument must be a string/) } end - it "should raise an ArgumentError if the second argument is an invalid hash type" do - expect { scope.function_pw_hash(['', 'invalid', 'salt']) }.to( raise_error(ArgumentError, /not a valid hash type/) ) + context 'when the second argument is not one of the supported hashing algorithms' do + it { is_expected.to run.with_params('password', 'no such algo', 'salt').and_raise_error(ArgumentError, /is not a valid hash type/) } end - it "should raise an ArgumentError if the second argument is not a string" do - expect { scope.function_pw_hash(['', [], 'salt']) }.to( raise_error(ArgumentError, /second argument must be a string/) ) + context 'when the third argument is not a string' do + it { is_expected.to run.with_params('password', 'sha-256', []).and_raise_error(ArgumentError, /third argument must be a string/) } + it { is_expected.to run.with_params('password', 'sha-256', {}).and_raise_error(ArgumentError, /third argument must be a string/) } + it { is_expected.to run.with_params('password', 'sha-256', 1).and_raise_error(ArgumentError, /third argument must be a string/) } + it { is_expected.to run.with_params('password', 'sha-256', true).and_raise_error(ArgumentError, /third argument must be a string/) } end - it "should raise an ArgumentError if the third argument is not a string" do - expect { scope.function_pw_hash(['password', 'sha-512', ['salt']]) }.to( raise_error(ArgumentError, /third argument must be a string/) ) - # in Puppet 3, numbers are passed as strings, so we can't test that + context 'when the third argument is empty' do + it { is_expected.to run.with_params('password', 'sha-512', '').and_raise_error(ArgumentError, /third argument must not be empty/) } end - it "should raise an ArgumentError if the third argument is empty" do - expect { scope.function_pw_hash(['password', 'sha-512', '']) }.to( raise_error(ArgumentError, /third argument must not be empty/) ) + context 'when the third argument contains invalid characters' do + it { is_expected.to run.with_params('password', 'sha-512', 'one%').and_raise_error(ArgumentError, /characters in salt must be in the set/) } end - it "should raise an ArgumentError if the third argument has invalid characters" do - expect { scope.function_pw_hash(['password', 'sha-512', '%']) }.to( raise_error(ArgumentError, /characters in salt must be in the set/) ) - end + context 'when running on a platform with a weak String#crypt implementation' do + before(:each) { allow_any_instance_of(String).to receive(:crypt).with('$1$1').and_return('a bad hash') } - it "should fail on platforms with weak implementations of String#crypt" do - String.any_instance.expects(:crypt).with('$1$1').returns('$1SoNol0Ye6Xk') - expect { scope.function_pw_hash(['password', 'sha-512', 'salt']) }.to( raise_error(Puppet::ParseError, /system does not support enhanced salts/) ) + it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_raise_error(Puppet::ParseError, /system does not support enhanced salts/) } end - if @enhanced_salts_supported + if RUBY_PLATFORM == 'java' or 'test'.crypt('$1$1') == '$1$1$Bp8CU9Oujr9SSEw53WV6G.' describe "on systems with enhanced salts support" do - it "should return a hashed password" do - result = scope.function_pw_hash(['password', 'sha-512', 'salt']) - expect(result).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') - end - - it "should use the specified salt" do - result = scope.function_pw_hash(['password', 'sha-512', 'salt']) - expect(result).to match('salt') - end - - it "should use the specified hash type" do - resultmd5 = scope.function_pw_hash(['password', 'md5', 'salt']) - resultsha256 = scope.function_pw_hash(['password', 'sha-256', 'salt']) - resultsha512 = scope.function_pw_hash(['password', 'sha-512', 'salt']) - - expect(resultmd5).to eql('$1$salt$qJH7.N4xYta3aEG/dfqo/0') - expect(resultsha256).to eql('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1') - expect(resultsha512).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') - end - - it "should generate a valid hash" do - password_hash = scope.function_pw_hash(['password', 'sha-512', 'salt']) - - hash_parts = password_hash.match(%r{\A\$(.*)\$([a-zA-Z0-9./]+)\$([a-zA-Z0-9./]+)\z}) - - expect(hash_parts).not_to eql(nil) - end + it { is_expected.to run.with_params('password', 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') } + it { is_expected.to run.with_params('password', 'sha-256', 'salt').and_return('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1') } + it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_return('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') } end end end diff --git a/stdlib/spec/functions/range_spec.rb b/stdlib/spec/functions/range_spec.rb index f18b89e1a..492cad40b 100755 --- a/stdlib/spec/functions/range_spec.rb +++ b/stdlib/spec/functions/range_spec.rb @@ -1,93 +1,118 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the range function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'range' do + it { is_expected.not_to eq(nil) } - it "exists" do - expect(Puppet::Parser::Functions.function("range")).to eq("function_range") + describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the third.") + is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('1..2..3').and_raise_error(Puppet::ParseError, /Unable to compute range/i) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /Unknown range format/i) } end - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_range([]) }.to raise_error Puppet::ParseError, /Wrong number of arguments.*0 for 1/ + describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do + it { pending "the puppet 4 implementation"; is_expected.to run.with_params().and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params('').and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params({}).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params([]).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(true).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(true).and_raise_error(ArgumentError) } + it { is_expected.to run.with_params(1, 2, 'foo').and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, []).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, {}).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, true).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(ArgumentError) } + it { pending "the puppet 4 implementation"; is_expected.to run.with_params('1..2..3').and_raise_error(ArgumentError) } end - describe 'with a letter range' do - it "returns a letter range" do - result = scope.function_range(["a","d"]) - expect(result).to eq ['a','b','c','d'] - end - - it "returns a letter range given a step of 1" do - result = scope.function_range(["a","d","1"]) - expect(result).to eq ['a','b','c','d'] - end - - it "returns a stepped letter range" do - result = scope.function_range(["a","d","2"]) - expect(result).to eq ['a','c'] - end - - it "returns a stepped letter range given a negative step" do - result = scope.function_range(["a","d","-2"]) - expect(result).to eq ['a','c'] - end + context 'with characters as bounds' do + it { is_expected.to run.with_params('d', 'a').and_return([]) } + it { is_expected.to run.with_params('a', 'a').and_return(['a']) } + it { is_expected.to run.with_params('a', 'b').and_return(['a', 'b']) } + it { is_expected.to run.with_params('a', 'd').and_return(['a', 'b', 'c', 'd']) } + it { is_expected.to run.with_params('a', 'd', 1).and_return(['a', 'b', 'c', 'd']) } + it { is_expected.to run.with_params('a', 'd', '1').and_return(['a', 'b', 'c', 'd']) } + it { is_expected.to run.with_params('a', 'd', 2).and_return(['a', 'c']) } + it { is_expected.to run.with_params('a', 'd', -2).and_return(['a', 'c']) } + it { is_expected.to run.with_params('a', 'd', 3).and_return(['a', 'd']) } + it { is_expected.to run.with_params('a', 'd', 4).and_return(['a']) } end - describe 'with a number range' do - it "returns a number range" do - result = scope.function_range(["1","4"]) - expect(result).to eq [1,2,3,4] - end + context 'with strings as bounds' do + it { is_expected.to run.with_params('onea', 'oned').and_return(['onea', 'oneb', 'onec', 'oned']) } + it { is_expected.to run.with_params('two', 'one').and_return([]) } + it { is_expected.to run.with_params('true', 'false').and_return([]) } + it { is_expected.to run.with_params('false', 'true').and_return(['false']) } + end - it "returns a number range given a step of 1" do - result = scope.function_range(["1","4","1"]) - expect(result).to eq [1,2,3,4] - end + context 'with integers as bounds' do + it { is_expected.to run.with_params(4, 1).and_return([]) } + it { is_expected.to run.with_params(1, 1).and_return([1]) } + it { is_expected.to run.with_params(1, 2).and_return([1, 2]) } + it { is_expected.to run.with_params(1, 4).and_return([1, 2, 3, 4]) } + it { is_expected.to run.with_params(1, 4, 1).and_return([1, 2, 3, 4]) } + it { is_expected.to run.with_params(1, 4, '1').and_return([1, 2, 3, 4]) } + it { is_expected.to run.with_params(1, 4, 2).and_return([1, 3]) } + it { is_expected.to run.with_params(1, 4, -2).and_return([1, 3]) } + it { is_expected.to run.with_params(1, 4, 3).and_return([1, 4]) } + it { is_expected.to run.with_params(1, 4, 4).and_return([1]) } + end - it "returns a stepped number range" do - result = scope.function_range(["1","4","2"]) - expect(result).to eq [1,3] - end + context 'with integers as strings as bounds' do + it { is_expected.to run.with_params('4', '1').and_return([]) } + it { is_expected.to run.with_params('1', '1').and_return([1]) } + it { is_expected.to run.with_params('1', '2').and_return([1, 2]) } + it { is_expected.to run.with_params('1', '4').and_return([1, 2, 3, 4]) } + it { is_expected.to run.with_params('1', '4', 1).and_return([1, 2, 3, 4]) } + it { is_expected.to run.with_params('1', '4', '1').and_return([1, 2, 3, 4]) } + it { is_expected.to run.with_params('1', '4', 2).and_return([1, 3]) } + it { is_expected.to run.with_params('1', '4', -2).and_return([1, 3]) } + it { is_expected.to run.with_params('1', '4', 3).and_return([1, 4]) } + it { is_expected.to run.with_params('1', '4', 4).and_return([1]) } + end - it "returns a stepped number range given a negative step" do - result = scope.function_range(["1","4","-2"]) - expect(result).to eq [1,3] - end + context 'with prefixed numbers as strings as bounds' do + it { is_expected.to run.with_params('host01', 'host04').and_return(['host01', 'host02', 'host03', 'host04']) } + it { is_expected.to run.with_params('01', '04').and_return([1, 2, 3, 4]) } end - describe 'with a numeric-like string range' do - it "works with padded hostname like strings" do - expected = ("host01".."host10").to_a - expect(scope.function_range(["host01","host10"])).to eq expected - end + context 'with dash-range syntax' do + it { is_expected.to run.with_params('4-1').and_return([]) } + it { is_expected.to run.with_params('1-1').and_return([1]) } + it { is_expected.to run.with_params('1-2').and_return([1, 2]) } + it { is_expected.to run.with_params('1-4').and_return([1, 2, 3, 4]) } + end - it "coerces zero padded digits to integers" do - expected = (0..10).to_a - expect(scope.function_range(["00", "10"])).to eq expected - end + context 'with two-dot-range syntax' do + it { is_expected.to run.with_params('4..1').and_return([]) } + it { is_expected.to run.with_params('1..1').and_return([1]) } + it { is_expected.to run.with_params('1..2').and_return([1, 2]) } + it { is_expected.to run.with_params('1..4').and_return([1, 2, 3, 4]) } end - describe 'with a ruby-like range' do - it "returns a number range" do - result = scope.function_range(["1..4"]) - expect(result).to eq [1,2,3,4] - end + context 'with three-dot-range syntax' do + it { is_expected.to run.with_params('4...1').and_return([]) } + it { is_expected.to run.with_params('1...1').and_return([]) } + it { is_expected.to run.with_params('1...2').and_return([1]) } + it { is_expected.to run.with_params('1...3').and_return([1, 2]) } + it { is_expected.to run.with_params('1...5').and_return([1, 2, 3, 4]) } end - describe 'with a numeric range' do - it "returns a range of numbers" do - expected = (1..10).to_a - expect(scope.function_range([1,10])).to eq expected - end - it "returns a range of numbers with step parameter" do - expected = (1..10).step(2).to_a - expect(scope.function_range([1,10,2])).to eq expected - end - it "works with mixed numeric like strings and numeric arguments" do - expected = (1..10).to_a - expect(scope.function_range(['1',10])).to eq expected - expect(scope.function_range([1,'10'])).to eq expected - end + describe 'when passing mixed arguments as bounds' do + it { + pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') + is_expected.to run.with_params('0', 'a').and_raise_error(Puppet::ParseError, /cannot interpolate between numeric and non-numeric bounds/) + } + it { + pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') + is_expected.to run.with_params(0, 'a').and_raise_error(Puppet::ParseError, /cannot interpolate between numeric and non-numeric bounds/) + } + it { + pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') + is_expected.to run.with_params('h0', 'ha').and_raise_error(Puppet::ParseError, /cannot interpolate between numeric and non-numeric bounds/) + } end end diff --git a/stdlib/spec/functions/reject_spec.rb b/stdlib/spec/functions/reject_spec.rb index 88a992efc..486305075 100755 --- a/stdlib/spec/functions/reject_spec.rb +++ b/stdlib/spec/functions/reject_spec.rb @@ -1,20 +1,19 @@ -#!/usr/bin/env ruby - require 'spec_helper' -describe "the reject function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("reject")).to eq("function_reject") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_reject([]) }.to( raise_error(Puppet::ParseError)) - end +describe 'reject' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([], 'pattern', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should reject contents from an array" do - result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"]) - expect(result).to(eq(["1111", "dddeee"])) - end + it { + pending("reject does not actually check this, and raises NoMethodError instead") + is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /first argument not an array/) + } + it { + pending("reject does not actually check this, and raises NoMethodError instead") + is_expected.to run.with_params(1, 'two').and_raise_error(Puppet::ParseError, /first argument not an array/) + } + it { is_expected.to run.with_params([], 'two').and_return([]) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 't(wo|hree)').and_return(['one']) } end diff --git a/stdlib/spec/functions/reverse_spec.rb b/stdlib/spec/functions/reverse_spec.rb index 1f047943f..e00dee92e 100755 --- a/stdlib/spec/functions/reverse_spec.rb +++ b/stdlib/spec/functions/reverse_spec.rb @@ -1,28 +1,31 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the reverse function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'reverse' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['a']).and_return(['a']) } + it { is_expected.to run.with_params(['one']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(['three', 'two', 'one']) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(['four', 'three', 'two', 'one']) } - it "should exist" do - expect(Puppet::Parser::Functions.function("reverse")).to eq("function_reverse") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_reverse([]) }.to( raise_error(Puppet::ParseError)) - end + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('abc').and_return('cba') } + it { is_expected.to run.with_params('abcd').and_return('dcba') } - it "should reverse a string" do - result = scope.function_reverse(["asdfghijkl"]) - expect(result).to(eq('lkjihgfdsa')) - end - - it "should accept objects which extend String" do - class AlsoString < String + context 'when using a class extending String' do + it 'should call its reverse method' do + value = AlsoString.new('asdfghjkl') + value.expects(:reverse).returns('foo') + expect(subject).to run.with_params(value).and_return('foo') end - - value = AlsoString.new('asdfghjkl') - result = scope.function_reverse([value]) - result.should(eq('lkjhgfdsa')) end end diff --git a/stdlib/spec/functions/rstrip_spec.rb b/stdlib/spec/functions/rstrip_spec.rb index f6b483896..d2efac8ea 100755 --- a/stdlib/spec/functions/rstrip_spec.rb +++ b/stdlib/spec/functions/rstrip_spec.rb @@ -1,33 +1,34 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the rstrip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("rstrip")).to eq("function_rstrip") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_rstrip([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should rstrip a string" do - result = scope.function_rstrip(["asdf "]) - expect(result).to(eq('asdf')) - end - - it "should rstrip each element in an array" do - result = scope.function_rstrip([["a ","b ", "c "]]) - expect(result).to(eq(['a','b','c'])) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new('asdf ') - result = scope.function_rstrip([value]) - result.should(eq('asdf')) - end +describe 'rstrip' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params(' ').and_return('') } + it { is_expected.to run.with_params(' ').and_return('') } + it { is_expected.to run.with_params("\t").and_return('') } + it { is_expected.to run.with_params("\t ").and_return('') } + it { is_expected.to run.with_params('one').and_return('one') } + it { is_expected.to run.with_params(' one').and_return(' one') } + it { is_expected.to run.with_params(' one').and_return(' one') } + it { is_expected.to run.with_params("\tone").and_return("\tone") } + it { is_expected.to run.with_params("\t one").and_return("\t one") } + it { is_expected.to run.with_params('one ').and_return('one') } + it { is_expected.to run.with_params(' one ').and_return(' one') } + it { is_expected.to run.with_params(' one ').and_return(' one') } + it { is_expected.to run.with_params("\tone ").and_return("\tone") } + it { is_expected.to run.with_params("\t one ").and_return("\t one") } + it { is_expected.to run.with_params("one\t").and_return('one') } + it { is_expected.to run.with_params(" one\t").and_return(' one') } + it { is_expected.to run.with_params(" one\t").and_return(' one') } + it { is_expected.to run.with_params("\tone\t").and_return("\tone") } + it { is_expected.to run.with_params("\t one\t").and_return("\t one") } + it { is_expected.to run.with_params(' o n e ').and_return(' o n e') } + it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return(' one') } end diff --git a/stdlib/spec/functions/shuffle_spec.rb b/stdlib/spec/functions/shuffle_spec.rb index a62c1fb5e..ebc3a732d 100755 --- a/stdlib/spec/functions/shuffle_spec.rb +++ b/stdlib/spec/functions/shuffle_spec.rb @@ -1,33 +1,33 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the shuffle function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'shuffle' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } - it "should exist" do - expect(Puppet::Parser::Functions.function("shuffle")).to eq("function_shuffle") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_shuffle([]) }.to( raise_error(Puppet::ParseError)) - end + context 'when running with a specific seed' do + # make tests deterministic + before(:each) { srand(2) } - it "should shuffle a string and the result should be the same size" do - result = scope.function_shuffle(["asdf"]) - expect(result.size).to(eq(4)) - end + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['a']).and_return(['a']) } + it { is_expected.to run.with_params(['one']).and_return(['one']) } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(['two', 'one', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(['four', 'three', 'two', 'one']) } - it "should shuffle a string but the sorted contents should still be the same" do - result = scope.function_shuffle(["adfs"]) - expect(result.split("").sort.join("")).to(eq("adfs")) - end + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('abc').and_return('bac') } + it { is_expected.to run.with_params('abcd').and_return('dcba') } - it "should accept objects which extend String" do - class AlsoString < String + context 'when using a class extending String' do + it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return('lkhdsfajg') } end - - value = AlsoString.new('asdf') - result = scope.function_shuffle([value]) - result.size.should(eq(4)) end end diff --git a/stdlib/spec/functions/size_spec.rb b/stdlib/spec/functions/size_spec.rb index 18eb48f96..6b6486683 100755 --- a/stdlib/spec/functions/size_spec.rb +++ b/stdlib/spec/functions/size_spec.rb @@ -1,24 +1,32 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the size function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'size' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Unknown type given/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Unknown type given/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Unknown type given/) } + it { is_expected.to run.with_params('1').and_raise_error(Puppet::ParseError, /Requires either string or array to work/) } + it { is_expected.to run.with_params('1.0').and_raise_error(Puppet::ParseError, /Requires either string or array to work/) } + it { is_expected.to run.with_params([]).and_return(0) } + it { is_expected.to run.with_params(['a']).and_return(1) } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } - it "should exist" do - expect(Puppet::Parser::Functions.function("size")).to eq("function_size") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_size([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return the size of a string" do - result = scope.function_size(["asdf"]) - expect(result).to(eq(4)) - end + it { is_expected.to run.with_params('').and_return(0) } + it { is_expected.to run.with_params('a').and_return(1) } + it { is_expected.to run.with_params('abc').and_return(3) } + it { is_expected.to run.with_params('abcd').and_return(4) } - it "should return the size of an array" do - result = scope.function_size([["a","b","c"]]) - expect(result).to(eq(3)) + context 'when using a class extending String' do + it 'should call its size method' do + value = AlsoString.new('asdfghjkl') + value.expects(:size).returns('foo') + expect(subject).to run.with_params(value).and_return('foo') + end end end diff --git a/stdlib/spec/functions/sort_spec.rb b/stdlib/spec/functions/sort_spec.rb index 4c2a66cf8..9abd039c1 100755 --- a/stdlib/spec/functions/sort_spec.rb +++ b/stdlib/spec/functions/sort_spec.rb @@ -1,24 +1,24 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the sort function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("sort")).to eq("function_sort") - end - - it "should raise a ParseError if there is not 1 arguments" do - expect { scope.function_sort(['','']) }.to( raise_error(Puppet::ParseError)) +describe 'sort' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { pending('stricter input checking'); is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /requires string or array/) } + it { pending('stricter input checking'); is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /requires string or array/) } + it { pending('stricter input checking'); is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /requires string or array/) } end - it "should sort an array" do - result = scope.function_sort([["a","c","b"]]) - expect(result).to(eq(['a','b','c'])) + context 'when called with an array' do + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['a']).and_return(['a']) } + it { is_expected.to run.with_params(['c', 'b', 'a']).and_return(['a', 'b', 'c']) } end - it "should sort a string" do - result = scope.function_sort(["acb"]) - expect(result).to(eq('abc')) + context 'when called with a string' do + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('cbda').and_return('abcd') } end end diff --git a/stdlib/spec/functions/squeeze_spec.rb b/stdlib/spec/functions/squeeze_spec.rb index cd0eb37fc..7f09c30ff 100755 --- a/stdlib/spec/functions/squeeze_spec.rb +++ b/stdlib/spec/functions/squeeze_spec.rb @@ -1,24 +1,44 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the squeeze function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'squeeze' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_raise_error(NoMethodError) } + it { is_expected.to run.with_params({}).and_raise_error(NoMethodError) } + it { is_expected.to run.with_params(true).and_raise_error(NoMethodError) } - it "should exist" do - expect(Puppet::Parser::Functions.function("squeeze")).to eq("function_squeeze") + context 'when squeezing a single string' do + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('aaaaaaaaa').and_return('a') } + it { is_expected.to run.with_params('aaaaaaaaa', 'a').and_return('a') } + it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') } end - it "should raise a ParseError if there is less than 2 arguments" do - expect { scope.function_squeeze([]) }.to( raise_error(Puppet::ParseError)) + context 'when squeezing values in an array' do + it { + is_expected.to run \ + .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc']) \ + .and_return( ['', 'a', 'a', 'abc']) + } + it { + is_expected.to run \ + .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'a') \ + .and_return( ['', 'a', 'a', 'abbbbbbbbbbcccccccccc']) + } + it { + is_expected.to run \ + .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'b-c') \ + .and_return( ['', 'a', 'aaaaaaaaa', 'aaaaaaaaabc']) + } end - it "should squeeze a string" do - result = scope.function_squeeze(["aaabbbbcccc"]) - expect(result).to(eq('abc')) - end - - it "should squeeze all elements in an array" do - result = scope.function_squeeze([["aaabbbbcccc","dddfff"]]) - expect(result).to(eq(['abc','df'])) + context 'when using a class extending String' do + it 'should call its squeeze method' do + value = AlsoString.new('aaaaaaaaa') + value.expects(:squeeze).returns('foo') + expect(subject).to run.with_params(value).and_return('foo') + end end end diff --git a/stdlib/spec/functions/str2bool_spec.rb b/stdlib/spec/functions/str2bool_spec.rb index 1d205d75d..3b439b249 100755 --- a/stdlib/spec/functions/str2bool_spec.rb +++ b/stdlib/spec/functions/str2bool_spec.rb @@ -1,31 +1,23 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the str2bool function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'str2bool' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('true', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Unknown type of boolean given/) } - it "should exist" do - expect(Puppet::Parser::Functions.function("str2bool")).to eq("function_str2bool") + describe 'when testing values that mean "true"' do + [ '1', 't', 'y', 'true', 'yes', true ].each do |value| + it { is_expected.to run.with_params(value).and_return(true) } + end end - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_str2bool([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert string 'true' to true" do - result = scope.function_str2bool(["true"]) - expect(result).to(eq(true)) - end - - it "should convert string 'undef' to false" do - result = scope.function_str2bool(["undef"]) - expect(result).to(eq(false)) - end - - it "should return the boolean it was called with" do - result = scope.function_str2bool([true]) - expect(result).to(eq(true)) - result = scope.function_str2bool([false]) - expect(result).to(eq(false)) + describe 'when testing values that mean "false"' do + [ '', '0', 'f', 'n', 'false', 'no', false, 'undef', 'undefined' ].each do |value| + it { is_expected.to run.with_params(value).and_return(false) } + end end end diff --git a/stdlib/spec/functions/str2saltedsha512_spec.rb b/stdlib/spec/functions/str2saltedsha512_spec.rb index ab7f57f11..2e1e818b5 100755 --- a/stdlib/spec/functions/str2saltedsha512_spec.rb +++ b/stdlib/spec/functions/str2saltedsha512_spec.rb @@ -1,45 +1,17 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the str2saltedsha512 function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'str2saltedsha512' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('password', 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires a String argument/) } - it "should exist" do - expect(Puppet::Parser::Functions.function("str2saltedsha512")).to eq("function_str2saltedsha512") - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_str2saltedsha512([]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should raise a ParseError if there is more than 1 argument" do - expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.to( raise_error(Puppet::ParseError) ) - end - - it "should return a salted-sha512 password hash 136 characters in length" do - result = scope.function_str2saltedsha512(["password"]) - expect(result.length).to(eq(136)) - end - - it "should raise an error if you pass a non-string password" do - expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should generate a valid password" do - # Allow the function to generate a password based on the string 'password' - password_hash = scope.function_str2saltedsha512(["password"]) - - # Separate the Salt and Password from the Password Hash - salt = password_hash[0..7] - password = password_hash[8..-1] - - # Convert the Salt and Password from Hex to Binary Data - str_salt = Array(salt.lines).pack('H*') - str_password = Array(password.lines).pack('H*') + context 'when running with a specific seed' do + # make tests deterministic + before(:each) { srand(2) } - # Combine the Binary Salt with 'password' and compare the end result - saltedpass = Digest::SHA512.digest(str_salt + 'password') - result = (str_salt + saltedpass).unpack('H*')[0] - expect(result).to eq(password_hash) + it { is_expected.to run.with_params('').and_return('0f8a612f4eeed08e47b3875d00f33c5688f7926298f2d9b5fe19d1323f910bc78b6f7b5892596d2fabaa65e7a8d99b3768c102610cf0432c4827eee01f09451e3fae4f7a') } + it { is_expected.to run.with_params('password').and_return('0f8a612f43134376566c5707718d600effcfb17581fc9d3fa64d7f447dfda317c174ffdb498d2c5bd5c2075dab41c9d7ada5afbdc6b55354980eb5ba61802371e6b64956') } + it { is_expected.to run.with_params('verylongpassword').and_return('0f8a612f7a448537540e062daa8621f9bae326ca8ccb899e1bdb10e7c218cebfceae2530b856662565fdc4d81e986fc50cfbbc46d50436610ed9429ff5e43f2c45b5d039') } end end diff --git a/stdlib/spec/functions/strftime_spec.rb b/stdlib/spec/functions/strftime_spec.rb index ebec54b80..e76774aa3 100755 --- a/stdlib/spec/functions/strftime_spec.rb +++ b/stdlib/spec/functions/strftime_spec.rb @@ -1,9 +1,6 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the strftime function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - +describe 'strftime' do it "should exist" do expect(Puppet::Parser::Functions.function("strftime")).to eq("function_strftime") end diff --git a/stdlib/spec/functions/strip_spec.rb b/stdlib/spec/functions/strip_spec.rb index 4ac8daf86..689b6dd0c 100755 --- a/stdlib/spec/functions/strip_spec.rb +++ b/stdlib/spec/functions/strip_spec.rb @@ -1,27 +1,34 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the strip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - expect(Puppet::Parser::Functions.function("strip")).to eq("function_strip") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_strip([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should strip a string" do - result = scope.function_strip([" ab cd "]) - expect(result).to(eq('ab cd')) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new(' as df ') - result = scope.function_strip([value]) - result.should(eq('as df')) - end +describe 'strip' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params(' ').and_return('') } + it { is_expected.to run.with_params(' ').and_return('') } + it { is_expected.to run.with_params("\t").and_return('') } + it { is_expected.to run.with_params("\t ").and_return('') } + it { is_expected.to run.with_params('one').and_return('one') } + it { is_expected.to run.with_params(' one').and_return('one') } + it { is_expected.to run.with_params(' one').and_return('one') } + it { is_expected.to run.with_params("\tone").and_return('one') } + it { is_expected.to run.with_params("\t one").and_return('one') } + it { is_expected.to run.with_params('one ').and_return('one') } + it { is_expected.to run.with_params(' one ').and_return('one') } + it { is_expected.to run.with_params(' one ').and_return('one') } + it { is_expected.to run.with_params("\tone ").and_return('one') } + it { is_expected.to run.with_params("\t one ").and_return('one') } + it { is_expected.to run.with_params("one \t").and_return('one') } + it { is_expected.to run.with_params(" one \t").and_return('one') } + it { is_expected.to run.with_params(" one \t").and_return('one') } + it { is_expected.to run.with_params("\tone \t").and_return('one') } + it { is_expected.to run.with_params("\t one \t").and_return('one') } + it { is_expected.to run.with_params(' o n e ').and_return('o n e') } + it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return('one') } end diff --git a/stdlib/spec/functions/suffix_spec.rb b/stdlib/spec/functions/suffix_spec.rb index c7783c64d..b48a4ebf6 100755 --- a/stdlib/spec/functions/suffix_spec.rb +++ b/stdlib/spec/functions/suffix_spec.rb @@ -1,27 +1,44 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the suffix function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_suffix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) - end - - it "raises an error if the first argument is not an array" do - expect { - scope.function_suffix([Object.new]) - }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) - end - - it "raises an error if the second argument is not a string" do - expect { - scope.function_suffix([['first', 'second'], 42]) - }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) - end - - it "returns a suffixed array" do - result = scope.function_suffix([['a','b','c'], 'p']) - expect(result).to(eq(['ap','bp','cp'])) - end +describe 'suffix' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the second.") + is_expected.to run.with_params([], 'a', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /expected first argument to be an Array/) } + it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, /expected second argument to be a String/) } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['one', 2]).and_return(['one', '2']) } + it { is_expected.to run.with_params([], '').and_return([]) } + it { is_expected.to run.with_params([''], '').and_return(['']) } + it { is_expected.to run.with_params(['one'], 'post').and_return(['onepost']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'post').and_return(['onepost', 'twopost', 'threepost']) } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({}).and_return({}) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({ 'key1' => 'value1', 2 => 3}).and_return({ 'key1' => 'value1', '2' => 3 }) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({}, '').and_return({}) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({ 'key' => 'value' }, '').and_return({ 'key' => 'value' }) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({ 'key' => 'value' }, 'post').and_return({ 'keypost' => 'value' }) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run \ + .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'pre') \ + .and_return({ 'key1post' => 'value1', 'key2post' => 'value2', 'key3post' => 'value3' }) + } end diff --git a/stdlib/spec/functions/swapcase_spec.rb b/stdlib/spec/functions/swapcase_spec.rb index 791d1dfae..c175a1588 100755 --- a/stdlib/spec/functions/swapcase_spec.rb +++ b/stdlib/spec/functions/swapcase_spec.rb @@ -1,28 +1,40 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the swapcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("swapcase")).to eq("function_swapcase") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_swapcase([]) }.to( raise_error(Puppet::ParseError)) +describe 'swapcase' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('a', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + describe 'with strings as inputs' do + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('one').and_return('ONE') } + it { is_expected.to run.with_params('ONE').and_return('one') } + it { is_expected.to run.with_params('oNe').and_return('OnE') } end - - it "should swapcase a string" do - result = scope.function_swapcase(["aaBBccDD"]) - expect(result).to(eq('AAbbCCdd')) + describe 'with arrays as inputs' do + it { is_expected.to run.with_params([]).and_return([]) } + describe 'only containing strings' do + it { is_expected.to run.with_params(['']).and_return(['']) } + it { is_expected.to run.with_params(['one']).and_return(['ONE']) } + it { is_expected.to run.with_params(['ONE']).and_return(['one']) } + it { is_expected.to run.with_params(['oNe']).and_return(['OnE']) } + it { is_expected.to run.with_params(['one', 'ONE']).and_return(['ONE', 'one']) } + it { is_expected.to run.with_params(['ONE', 'OnE']).and_return(['one', 'oNe']) } + it { is_expected.to run.with_params(['oNe', 'one']).and_return(['OnE', 'ONE']) } + end + describe 'containing mixed types' do + it { is_expected.to run.with_params(['OnE', {}]).and_return(['oNe', {}]) } + it { is_expected.to run.with_params(['OnE', 1]).and_return(['oNe', 1]) } + it { is_expected.to run.with_params(['OnE', []]).and_return(['oNe', []]) } + it { is_expected.to run.with_params(['OnE', ['two']]).and_return(['oNe', ['two']]) } + end end - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new("aaBBccDD") - result = scope.function_swapcase([value]) - result.should(eq("AAbbCCdd")) + is_expected.to run.with_params(AlsoString.new("OnE")).and_return('oNe') end end diff --git a/stdlib/spec/functions/time_spec.rb b/stdlib/spec/functions/time_spec.rb index 6e22515f1..d157939e9 100755 --- a/stdlib/spec/functions/time_spec.rb +++ b/stdlib/spec/functions/time_spec.rb @@ -1,29 +1,21 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the time function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'time' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params('a', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should exist" do - expect(Puppet::Parser::Functions.function("time")).to eq("function_time") - end - - it "should raise a ParseError if there is more than 2 arguments" do - expect { scope.function_time(['','']) }.to( raise_error(Puppet::ParseError)) - end - - it "should return a number" do - result = scope.function_time([]) - expect(result).to be_an(Integer) - end - - it "should be higher then when I wrote this test" do - result = scope.function_time([]) - expect(result).to(be > 1311953157) - end - - it "should be lower then 1.5 trillion" do - result = scope.function_time([]) - expect(result).to(be < 1500000000) + context 'when running at a specific time' do + before(:each) { + # get a value before stubbing the function + test_time = Time.utc(2006, 10, 13, 8, 15, 11) + Time.expects(:new).with().returns(test_time).once + } + it { is_expected.to run.with_params().and_return(1160727311) } + it { is_expected.to run.with_params('').and_return(1160727311) } + it { is_expected.to run.with_params([]).and_return(1160727311) } + it { is_expected.to run.with_params({}).and_return(1160727311) } + it { is_expected.to run.with_params('foo').and_return(1160727311) } + it { is_expected.to run.with_params('UTC').and_return(1160727311) } + it { is_expected.to run.with_params('America/New_York').and_return(1160727311) } end end diff --git a/stdlib/spec/functions/to_bytes_spec.rb b/stdlib/spec/functions/to_bytes_spec.rb index 0f6ade912..2be23ff2d 100755 --- a/stdlib/spec/functions/to_bytes_spec.rb +++ b/stdlib/spec/functions/to_bytes_spec.rb @@ -1,83 +1,72 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the to_bytes function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("to_bytes")).to eq("function_to_bytes") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_to_bytes([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert kB to B" do - result = scope.function_to_bytes(["4 kB"]) - expect(result).to(eq(4096)) - end - - it "should convert MB to B" do - result = scope.function_to_bytes(["4 MB"]) - expect(result).to(eq(4194304)) - end - - it "should convert GB to B" do - result = scope.function_to_bytes(["4 GB"]) - expect(result).to(eq(4294967296)) - end - - it "should convert TB to B" do - result = scope.function_to_bytes(["4 TB"]) - expect(result).to(eq(4398046511104)) - end - - it "should convert PB to B" do - result = scope.function_to_bytes(["4 PB"]) - expect(result).to(eq(4503599627370496)) - end - - it "should convert PB to B" do - result = scope.function_to_bytes(["4 EB"]) - expect(result).to(eq(4611686018427387904)) - end - - it "should work without B in unit" do - result = scope.function_to_bytes(["4 k"]) - expect(result).to(eq(4096)) - end - - it "should work without a space before unit" do - result = scope.function_to_bytes(["4k"]) - expect(result).to(eq(4096)) - end - - it "should work without a unit" do - result = scope.function_to_bytes(["5678"]) - expect(result).to(eq(5678)) - end - - it "should convert fractions" do - result = scope.function_to_bytes(["1.5 kB"]) - expect(result).to(eq(1536)) - end - - it "should convert scientific notation" do - result = scope.function_to_bytes(["1.5e2 B"]) - expect(result).to(eq(150)) - end - - it "should do nothing with a positive number" do - result = scope.function_to_bytes([5678]) - expect(result).to(eq(5678)) - end - - it "should should raise a ParseError if input isn't a number" do - expect { scope.function_to_bytes(["foo"]) }.to( raise_error(Puppet::ParseError)) - end - - it "should should raise a ParseError if prefix is unknown" do - expect { scope.function_to_bytes(["5 uB"]) }.to( raise_error(Puppet::ParseError)) +describe 'to_bytes' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('1', 'extras').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([]).and_raise_error(TypeError, /(can't convert|no implicit conversion of) Array (in)?to String/) } + it { is_expected.to run.with_params({}).and_raise_error(TypeError, /(can't convert|no implicit conversion of) Hash (in)?to String/) } + it { is_expected.to run.with_params(true).and_raise_error(TypeError, /(can't convert|no implicit conversion of) (TrueClass|true) (in)?to String/) } + + describe 'when passing numbers' do + it { is_expected.to run.with_params(0).and_return(0) } + it { is_expected.to run.with_params(1).and_return(1) } + it { is_expected.to run.with_params(-1).and_return(-1) } + it { is_expected.to run.with_params(1.1).and_return(1.1) } + it { is_expected.to run.with_params(-1.1).and_return(-1.1) } + end + + describe 'when passing numbers as strings' do + describe 'without a unit' do + it { is_expected.to run.with_params('1').and_return(1) } + it { is_expected.to run.with_params('-1').and_return(-1) } + # these are so wrong + it { is_expected.to run.with_params('1.1').and_return(1) } + it { is_expected.to run.with_params('-1.1').and_return(-1) } + end + + describe 'with a unit' do + it { is_expected.to run.with_params('1k').and_return(1024) } + it { is_expected.to run.with_params('-1kB').and_return(-1024) } + it { is_expected.to run.with_params('1k').and_return(1024) } + it { is_expected.to run.with_params('1M').and_return(1024*1024) } + it { is_expected.to run.with_params('1G').and_return(1024*1024*1024) } + it { is_expected.to run.with_params('1T').and_return(1024*1024*1024*1024) } + it { is_expected.to run.with_params('1P').and_return(1024*1024*1024*1024*1024) } + it { is_expected.to run.with_params('1E').and_return(1024*1024*1024*1024*1024*1024) } + it { is_expected.to run.with_params('1.5e3M').and_return(1572864000) } + + it { is_expected.to run.with_params('4k').and_return(4*1024) } + it { is_expected.to run.with_params('-4kB').and_return(4*-1024) } + it { is_expected.to run.with_params('4k').and_return(4*1024) } + it { is_expected.to run.with_params('4M').and_return(4*1024*1024) } + it { is_expected.to run.with_params('4G').and_return(4*1024*1024*1024) } + it { is_expected.to run.with_params('4T').and_return(4*1024*1024*1024*1024) } + it { is_expected.to run.with_params('4P').and_return(4*1024*1024*1024*1024*1024) } + it { is_expected.to run.with_params('4E').and_return(4*1024*1024*1024*1024*1024*1024) } + + # these are so wrong + it { is_expected.to run.with_params('1.0001 k').and_return(1024) } + it { is_expected.to run.with_params('-1.0001 kB').and_return(-1024) } + end + + describe 'with a unknown unit' do + it { is_expected.to run.with_params('1KB').and_raise_error(Puppet::ParseError, /Unknown prefix/) } + it { is_expected.to run.with_params('1K').and_raise_error(Puppet::ParseError, /Unknown prefix/) } + it { is_expected.to run.with_params('1mb').and_raise_error(Puppet::ParseError, /Unknown prefix/) } + it { is_expected.to run.with_params('1m').and_raise_error(Puppet::ParseError, /Unknown prefix/) } + it { is_expected.to run.with_params('1%').and_raise_error(Puppet::ParseError, /Unknown prefix/) } + it { is_expected.to run.with_params('1 p').and_raise_error(Puppet::ParseError, /Unknown prefix/) } + end + end + + # these are so wrong + describe 'when passing random stuff' do + it { is_expected.to run.with_params('-1....1').and_return(-1) } + it { is_expected.to run.with_params('-1.e.e.e.1').and_return(-1) } + it { is_expected.to run.with_params('-1+1').and_return(-1) } + it { is_expected.to run.with_params('1-1').and_return(1) } + it { is_expected.to run.with_params('1 kaboom').and_return(1024) } + it { is_expected.to run.with_params('kaboom').and_return(0) } end end diff --git a/stdlib/spec/functions/type3x_spec.rb b/stdlib/spec/functions/type3x_spec.rb index d21236a61..c3eb1deee 100644 --- a/stdlib/spec/functions/type3x_spec.rb +++ b/stdlib/spec/functions/type3x_spec.rb @@ -1,8 +1,6 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the type3x function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'type3x' do it "should exist" do expect(Puppet::Parser::Functions.function("type3x")).to eq("function_type3x") end diff --git a/stdlib/spec/functions/type_of_spec.rb b/stdlib/spec/functions/type_of_spec.rb index b8234600c..f77099031 100644 --- a/stdlib/spec/functions/type_of_spec.rb +++ b/stdlib/spec/functions/type_of_spec.rb @@ -1,13 +1,23 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe 'type_of', :if => Puppet.version.to_f >= 4.0 do - it 'gives the type of a string' do - expect(subject.call_function('type_of', 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType) +if ENV["FUTURE_PARSER"] == 'yes' + describe 'type_of' do + pending 'teach rspec-puppet to load future-only functions under 3.7.5' end +end + +if Puppet.version.to_f >= 4.0 + describe 'type_of' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError) } + it { is_expected.to run.with_params('', '').and_raise_error(ArgumentError) } + + it 'gives the type of a string' do + expect(subject.call({}, 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType) + end - it 'gives the type of an integer' do - expect(subject.call_function('type_of', 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType) + it 'gives the type of an integer' do + expect(subject.call({}, 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType) + end end end diff --git a/stdlib/spec/functions/type_spec.rb b/stdlib/spec/functions/type_spec.rb index b683fcfa4..4288df09b 100755 --- a/stdlib/spec/functions/type_spec.rb +++ b/stdlib/spec/functions/type_spec.rb @@ -1,8 +1,6 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the type function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'type' do it "should exist" do expect(Puppet::Parser::Functions.function("type")).to eq("function_type") end diff --git a/stdlib/spec/functions/union_spec.rb b/stdlib/spec/functions/union_spec.rb index 706f4cbcd..970e1fe50 100755 --- a/stdlib/spec/functions/union_spec.rb +++ b/stdlib/spec/functions/union_spec.rb @@ -1,19 +1,23 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the union function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("union")).to eq("function_union") - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - expect { scope.function_union([]) }.to( raise_error(Puppet::ParseError) ) +describe 'union' do + describe 'argument checking' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError, /Requires 2 arrays/) } + it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, /Requires 2 arrays/) } + it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, /Requires 2 arrays/) } end - it "should join two arrays together" do - result = scope.function_union([["a","b","c"],["b","c","d"]]) - expect(result).to(eq(["a","b","c","d"])) - end + it { is_expected.to run.with_params([], []).and_return([]) } + it { is_expected.to run.with_params([], ['one']).and_return(['one']) } + it { is_expected.to run.with_params(['one'], []).and_return(['one']) } + it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) } + it { is_expected.to run.with_params(['one'], ['two']).and_return(['one', 'two']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['one', 'two', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['one', 'two', 'three']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one', 'two', 'three']) } + it 'should not confuse types' do is_expected.to run.with_params(['1', '2', '3'], [1, 2]).and_return(['1', '2', '3', 1, 2]) end end diff --git a/stdlib/spec/functions/unique_spec.rb b/stdlib/spec/functions/unique_spec.rb index 7cd3a566f..24257a018 100755 --- a/stdlib/spec/functions/unique_spec.rb +++ b/stdlib/spec/functions/unique_spec.rb @@ -1,33 +1,27 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the unique function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("unique")).to eq("function_unique") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_unique([]) }.to( raise_error(Puppet::ParseError)) +describe 'unique' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } end - it "should remove duplicate elements in a string" do - result = scope.function_unique(["aabbc"]) - expect(result).to(eq('abc')) + context 'when called with an array' do + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['a']).and_return(['a']) } + it { is_expected.to run.with_params(['a', 'b', 'a']).and_return(['a', 'b']) } end - it "should remove duplicate elements in an array" do - result = scope.function_unique([["a","a","b","b","c"]]) - expect(result).to(eq(['a','b','c'])) - end - - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new('aabbc') - result = scope.function_unique([value]) - result.should(eq('abc')) + context 'when called with a string' do + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('aaba').and_return('ab') } end end diff --git a/stdlib/spec/functions/upcase_spec.rb b/stdlib/spec/functions/upcase_spec.rb index 0689099cd..3b7b02d47 100755 --- a/stdlib/spec/functions/upcase_spec.rb +++ b/stdlib/spec/functions/upcase_spec.rb @@ -1,58 +1,26 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the upcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("upcase")).to eq("function_upcase") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_upcase([]) }.to(raise_error(Puppet::ParseError)) +describe 'upcase' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires an array, hash or object that responds to upcase/) } + it { is_expected.to run.with_params([1]).and_raise_error(Puppet::ParseError, /Requires an array, hash or object that responds to upcase/) } end - it "should upcase a string" do - result = scope.function_upcase(["abc"]) - expect(result).to(eq('ABC')) + describe 'normal string handling' do + it { is_expected.to run.with_params("abc").and_return("ABC") } + it { is_expected.to run.with_params("Abc").and_return("ABC") } + it { is_expected.to run.with_params("ABC").and_return("ABC") } end - it "should do nothing if a string is already upcase" do - result = scope.function_upcase(["ABC"]) - expect(result).to(eq('ABC')) + describe 'handling classes derived from String' do + it { is_expected.to run.with_params(AlsoString.new("ABC")).and_return("ABC") } end - it "should accept objects which extend String" do - class AlsoString < String - end - - value = AlsoString.new('abc') - result = scope.function_upcase([value]) - result.should(eq('ABC')) - end - - it 'should accept hashes and return uppercase' do - expect( - scope.function_upcase([{'test' => %w(this that and other thing)}]) - ).to eq({'TEST' => %w(THIS THAT AND OTHER THING)}) - end - - if :test.respond_to?(:upcase) - it 'should accept hashes of symbols' do - expect( - scope.function_upcase([{:test => [:this, :that, :other]}]) - ).to eq({:TEST => [:THIS, :THAT, :OTHER]}) - end - it 'should return upcase symbol' do - expect( - scope.function_upcase([:test]) - ).to eq(:TEST) - end - it 'should return mixed objects in upcease' do - expect( - scope.function_upcase([[:test, 'woot']]) - ).to eq([:TEST, 'WOOT']) - - end + describe 'strings in arrays handling' do + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(["One", "twO"]).and_return(["ONE", "TWO"]) } end end diff --git a/stdlib/spec/functions/uriescape_spec.rb b/stdlib/spec/functions/uriescape_spec.rb index d0f37de1d..f05ec088c 100755 --- a/stdlib/spec/functions/uriescape_spec.rb +++ b/stdlib/spec/functions/uriescape_spec.rb @@ -1,40 +1,36 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the uriescape function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("uriescape")).to eq("function_uriescape") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_uriescape([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should uriescape a string" do - result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"]) - expect(result).to(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D')) +describe 'uriescape' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } end - it "should uriescape an array of strings, while not touching up nonstrings" do - teststring = ":/?#[]@!$&'()*+,;= \"{}" - expectstring = ':/?%23[]@!$&\'()*+,;=%20%22%7B%7D' - result = scope.function_uriescape([[teststring, teststring, 1]]) - expect(result).to(eq([expectstring, expectstring, 1])) - end - - it "should do nothing if a string is already safe" do - result = scope.function_uriescape(["ABCdef"]) - expect(result).to(eq('ABCdef')) + describe 'handling normal strings' do + it 'should call ruby\'s URI.escape function' do + URI.expects(:escape).with('uri_string').returns('escaped_uri_string').once + is_expected.to run.with_params('uri_string').and_return('escaped_uri_string') + end end - it "should accept objects which extend String" do - class AlsoString < String + describe 'handling classes derived from String' do + it 'should call ruby\'s URI.escape function' do + uri_string = AlsoString.new('uri_string') + URI.expects(:escape).with(uri_string).returns('escaped_uri_string').once + is_expected.to run.with_params(uri_string).and_return("escaped_uri_string") end + end - value = AlsoString.new('abc') - result = scope.function_uriescape([value]) - result.should(eq('abc')) + describe 'strings in arrays handling' do + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(["one}", "two"]).and_return(["one%7D", "two"]) } + it { is_expected.to run.with_params(["one}", 1, true, {}, "two"]).and_return(["one%7D", 1, true, {}, "two"]) } end end diff --git a/stdlib/spec/functions/validate_absolute_path_spec.rb b/stdlib/spec/functions/validate_absolute_path_spec.rb index 36c836bdb..4a8404d81 100755 --- a/stdlib/spec/functions/validate_absolute_path_spec.rb +++ b/stdlib/spec/functions/validate_absolute_path_spec.rb @@ -1,67 +1,32 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_absolute_path) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - # The subject of these examples is the method itself. - subject do - # This makes sure the function is loaded within each test - function_name = Puppet::Parser::Functions.function(:validate_absolute_path) - scope.method(function_name) +describe 'validate_absolute_path' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } end - describe "Valid Paths" do - def self.valid_paths - %w{ - C:/ - C:\\ - C:\\WINDOWS\\System32 - C:/windows/system32 - X:/foo/bar - X:\\foo\\bar - /var/tmp - /var/lib/puppet - /var/opt/../lib/puppet - } - end - - context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do - before :each do - # The intent here is to mock Puppet to behave like Puppet 2.6 does. - # Puppet 2.6 does not have the absolute_path? method. This is only a - # convenience test, stdlib should be run with the Puppet 2.6.x in the - # $LOAD_PATH in addition to 2.7.x and master. - Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false) - end - valid_paths.each do |path| - it "validate_absolute_path(#{path.inspect}) should not fail" do - expect { subject.call [path] }.not_to raise_error - end - end - valid_paths do - it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do - expect { subject.call [valid_paths] }.not_to raise_error - end - end - end - - context "Puppet without mocking" do - valid_paths.each do |path| - it "validate_absolute_path(#{path.inspect}) should not fail" do - expect { subject.call [path] }.not_to raise_error - end - end - valid_paths do - it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do - expect { subject.call [valid_paths] }.not_to raise_error - end - end + describe "valid paths handling" do + %w{ + C:/ + C:\\ + C:\\WINDOWS\\System32 + C:/windows/system32 + X:/foo/bar + X:\\foo\\bar + \\\\host\\windows + //host/windows + / + /var/tmp + /var/opt/../lib/puppet + }.each do |path| + it { is_expected.to run.with_params(path) } + it { is_expected.to run.with_params(['/tmp', path]) } end end - describe 'Invalid paths' do - context 'Garbage inputs' do + describe 'invalid path handling' do + context 'garbage inputs' do [ nil, [ nil ], @@ -70,33 +35,26 @@ def self.valid_paths { }, '', ].each do |path| - it "validate_absolute_path(#{path.inspect}) should fail" do - expect { subject.call [path] }.to raise_error Puppet::ParseError - end + it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, /is not an absolute path/) } + it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) } + it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) } end end - context 'Relative paths' do - def self.rel_paths - %w{ - relative1 - . - .. - ./foo - ../foo - etc/puppetlabs/puppet - opt/puppet/bin - } - end - rel_paths.each do |path| - it "validate_absolute_path(#{path.inspect}) should fail" do - expect { subject.call [path] }.to raise_error Puppet::ParseError - end - end - rel_paths do - it "validate_absolute_path(#{rel_paths.inspect}) should fail" do - expect { subject.call [rel_paths] }.to raise_error Puppet::ParseError - end + context 'relative paths' do + %w{ + relative1 + . + .. + ./foo + ../foo + etc/puppetlabs/puppet + opt/puppet/bin + relative\\windows + }.each do |path| + it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, /is not an absolute path/) } + it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) } + it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, /is not an absolute path/) } end end end diff --git a/stdlib/spec/functions/validate_array_spec.rb b/stdlib/spec/functions/validate_array_spec.rb index 4b31cfde4..4ee7754f8 100755 --- a/stdlib/spec/functions/validate_array_spec.rb +++ b/stdlib/spec/functions/validate_array_spec.rb @@ -1,38 +1,27 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_array) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling validate_array from puppet' do - - %w{ true false }.each do |the_string| - it "should not compile when #{the_string} is a string" do - Puppet[:code] = "validate_array('#{the_string}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) - end +describe 'validate_array' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should not compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_array(#{the_string})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) - end + describe 'valid inputs' do + it { is_expected.to run.with_params([]) } + it { is_expected.to run.with_params(['one']) } + it { is_expected.to run.with_params([], ['two']) } + it { is_expected.to run.with_params(['one'], ['two']) } end - it "should compile when multiple array arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = [ ] - $bar = [ 'one', 'two' ] - validate_array($foo, $bar) - ENDofPUPPETcode - scope.compiler.compile - end - - it "should not compile when an undef variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_array($foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params([], {}).and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params([], 1).and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params([], true).and_raise_error(Puppet::ParseError, /is not an Array/) } + it { is_expected.to run.with_params([], 'one').and_raise_error(Puppet::ParseError, /is not an Array/) } end end end + diff --git a/stdlib/spec/functions/validate_augeas_spec.rb b/stdlib/spec/functions/validate_augeas_spec.rb index 99523ab77..4236649d6 100755 --- a/stdlib/spec/functions/validate_augeas_spec.rb +++ b/stdlib/spec/functions/validate_augeas_spec.rb @@ -1,49 +1,29 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - # The subject of these examplres is the method itself. - subject do - # This makes sure the function is loaded within each test - function_name = Puppet::Parser::Functions.function(:validate_augeas) - scope.method(function_name) - end - - context 'Using Puppet::Parser::Scope.new' do - - describe 'Garbage inputs' do - inputs = [ - [ nil ], - [ [ nil ] ], - [ { 'foo' => 'bar' } ], - [ { } ], - [ '' ], - [ "one", "one", "MSG to User", "4th arg" ], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call [input] }.to raise_error Puppet::ParseError - end - end +describe 'validate_augeas' do + unless Puppet.features.augeas? + skip "ruby-augeas not installed" + else + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', 'one', 'MSG to User', '4th arg').and_raise_error(NoMethodError) } end - describe 'Valid inputs' do + describe 'valid inputs' do inputs = [ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ], [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'], ] inputs.each do |input| - it "validate_augeas(#{input.inspect}) should not fail" do - expect { subject.call input }.not_to raise_error - end + it { is_expected.to run.with_params(*input) } end end - describe "Valid inputs which should raise an exception without a message" do + describe 'valid inputs which fail augeas validation' do # The intent here is to make sure valid inputs raise exceptions when they # don't specify an error message to display. This is the behvior in # 2.2.x and prior. @@ -53,13 +33,11 @@ ] inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/ - end + it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /validate_augeas.*?matched less than it should/) } end end - describe "Nicer Error Messages" do + describe "when specifying nice error messages" do # The intent here is to make sure the function returns the 4th argument # in the exception thrown inputs = [ @@ -68,35 +46,29 @@ ] inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /#{input[3]}/ - end + it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /#{input[3]}/) } end end - describe "Passing simple unit tests" do + describe "matching additional tests" do inputs = [ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']], [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']], ] inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.not_to raise_error - end + it { is_expected.to run.with_params(*input) } end end - describe "Failing simple unit tests" do + describe "failing additional tests" do inputs = [ [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']], [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']], ] inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /testing path/ - end + it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /testing path/) } end end end diff --git a/stdlib/spec/functions/validate_bool_spec.rb b/stdlib/spec/functions/validate_bool_spec.rb index a352d3b55..d9cdf572e 100755 --- a/stdlib/spec/functions/validate_bool_spec.rb +++ b/stdlib/spec/functions/validate_bool_spec.rb @@ -1,51 +1,25 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_bool) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling validate_bool from puppet' do - - %w{ true false }.each do |the_string| - - it "should not compile when #{the_string} is a string" do - Puppet[:code] = "validate_bool('#{the_string}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) - end - - it "should compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_bool(#{the_string})" - scope.compiler.compile - end - - end - - it "should not compile when an arbitrary string is passed" do - Puppet[:code] = 'validate_bool("jeff and dan are awesome")' - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) - end - - it "should not compile when no arguments are passed" do - Puppet[:code] = 'validate_bool()' - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end +describe 'validate_bool' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + end - it "should compile when multiple boolean arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = true - $bar = false - validate_bool($foo, $bar, true, false) - ENDofPUPPETcode - scope.compiler.compile - end + describe 'acceptable values' do + it { is_expected.to run.with_params(true) } + it { is_expected.to run.with_params(false) } + it { is_expected.to run.with_params(true, false, false, true) } + end - it "should compile when multiple boolean arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = true - $bar = false - validate_bool($foo, $bar, true, false, 'jeff') - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) - end + describe 'validation failures' do + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params(true, 'one').and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params('one', false).and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params("true").and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params("false").and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params(true, "false").and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params("true", false).and_raise_error(Puppet::ParseError, /is not a boolean/) } + it { is_expected.to run.with_params("true", false, false, false, false, false).and_raise_error(Puppet::ParseError, /is not a boolean/) } end end diff --git a/stdlib/spec/functions/validate_cmd_spec.rb b/stdlib/spec/functions/validate_cmd_spec.rb index 7cb9782d6..ab0cbc9a7 100755 --- a/stdlib/spec/functions/validate_cmd_spec.rb +++ b/stdlib/spec/functions/validate_cmd_spec.rb @@ -1,85 +1,35 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -TESTEXE = File.exists?('/usr/bin/test') ? '/usr/bin/test' : '/bin/test' -TOUCHEXE = File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' - -describe Puppet::Parser::Functions.function(:validate_cmd) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - subject do - function_name = Puppet::Parser::Functions.function(:validate_cmd) - scope.method(function_name) +describe 'validate_cmd' do + let(:touch) { File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' } + + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending('should implement stricter type checking') + is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, /content must be a string/) + } + it { + pending('should implement stricter type checking') + is_expected.to run.with_params('', [], '').and_raise_error(Puppet::ParseError, /checkscript must be a string/) + } + it { + pending('should implement stricter type checking') + is_expected.to run.with_params('', '', []).and_raise_error(Puppet::ParseError, /custom error message must be a string/) + } end - context 'with no % placeholder' do - describe "with an explicit failure message" do - it "prints the failure message on error" do - expect { - subject.call ['', '/bin/false', 'failure message!'] - }.to raise_error Puppet::ParseError, /failure message!/ - end - end - - describe "on validation failure" do - it "includes the command error output" do - expect { - subject.call ['', "#{TOUCHEXE} /cant/touch/this"] - }.to raise_error Puppet::ParseError, /(cannot touch|o such file or)/ - end - - it "includes the command return value" do - expect { - subject.call ['', '/cant/run/this'] - }.to raise_error Puppet::ParseError, /returned 1\b/ - end - end - - describe "when performing actual validation" do - it "can positively validate file content" do - expect { subject.call ["non-empty", "#{TESTEXE} -s"] }.to_not raise_error - end - - it "can negatively validate file content" do - expect { - subject.call ["", "#{TESTEXE} -s"] - }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ - end + context 'when validation fails' do + context 'with % placeholder' do + it { is_expected.to run.with_params('', "#{touch} % /no/such/file").and_raise_error(Puppet::ParseError, /Execution of '#{touch} \S+ \/no\/such\/file' returned 1:.*(cannot touch|o such file or)/) } + it { is_expected.to run.with_params('', "#{touch} % /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, /custom error/) } end - end - - context 'with % placeholder' do - describe "with an explicit failure message" do - it "prints the failure message on error" do - expect { - subject.call ['', '/bin/false % -f', 'failure message!'] - }.to raise_error Puppet::ParseError, /failure message!/ - end - end - describe "on validation failure" do - it "includes the command error output" do - expect { - subject.call ['', "#{TOUCHEXE} /cant/touch/this"] - }.to raise_error Puppet::ParseError, /(cannot touch|o such file or)/ - end - - it "includes the command return value" do - expect { - subject.call ['', '/cant/run/this % -z'] - }.to raise_error Puppet::ParseError, /Execution of '\/cant\/run\/this .+ -z' returned 1/ - end - end - - describe "when performing actual validation" do - it "can positively validate file content" do - expect { subject.call ["non-empty", "#{TESTEXE} -s %"] }.to_not raise_error - end - - it "can negatively validate file content" do - expect { - subject.call ["", "#{TESTEXE} -s %"] - }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ - end + context 'without % placeholder' do + it { is_expected.to run.with_params('', "#{touch} /no/such/file").and_raise_error(Puppet::ParseError, /Execution of '#{touch} \/no\/such\/file \S+' returned 1:.*(cannot touch|o such file or)/) } + it { is_expected.to run.with_params('', "#{touch} /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, /custom error/) } end end end diff --git a/stdlib/spec/functions/validate_hash_spec.rb b/stdlib/spec/functions/validate_hash_spec.rb index a0c35c230..2e8e59fb8 100755 --- a/stdlib/spec/functions/validate_hash_spec.rb +++ b/stdlib/spec/functions/validate_hash_spec.rb @@ -1,43 +1,26 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_hash) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling validate_hash from puppet' do - - %w{ true false }.each do |the_string| - - it "should not compile when #{the_string} is a string" do - Puppet[:code] = "validate_hash('#{the_string}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) - end - - it "should not compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_hash(#{the_string})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) - end +describe 'validate_hash' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + describe 'valid inputs' do + it { is_expected.to run.with_params({}) } + it { is_expected.to run.with_params({'key' => 'value'}) } + it { is_expected.to run.with_params({}, {'key' => 'value'}) } + it { is_expected.to run.with_params({'key1' => 'value1'}, {'key2' => 'value2'}) } end - it "should compile when multiple hash arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = {} - $bar = { 'one' => 'two' } - validate_hash($foo, $bar) - ENDofPUPPETcode - scope.compiler.compile + describe 'invalid inputs' do + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params({}, []).and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params({}, true).and_raise_error(Puppet::ParseError, /is not a Hash/) } + it { is_expected.to run.with_params({}, 'one').and_raise_error(Puppet::ParseError, /is not a Hash/) } end - - it "should not compile when an undef variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_hash($foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) - end - end - end diff --git a/stdlib/spec/functions/validate_integer_spec.rb b/stdlib/spec/functions/validate_integer_spec.rb index e95da6a8c..4c0a9d7d4 100755 --- a/stdlib/spec/functions/validate_integer_spec.rb +++ b/stdlib/spec/functions/validate_integer_spec.rb @@ -1,224 +1,90 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_integer) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling validate_integer from puppet without any argument or to many' do - it "should not compile when no argument is passed" do - Puppet[:code] = "validate_integer()" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /Wrong number of arguments/) - end - it "should not compile when more than three arguments are passed" do - Puppet[:code] = "validate_integer(1, 1, 1, 1)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /Wrong number of arguments/) - end - end - - describe 'when calling validate_integer from puppet only with input' do - %w{ 1 -1 }.each do |the_number| - it "should compile when #{the_number} is an encapsulated integer" do - Puppet[:code] = "validate_integer('#{the_number}')" - scope.compiler.compile - end - it "should compile when #{the_number} is an bare integer" do - Puppet[:code] = "validate_integer(#{the_number})" - scope.compiler.compile - end - end - - %w{ [1,2,3,4,5] ['1','2','3','4','5'] }.each do |the_number| - it "should compile when multiple Integer arguments are passed in an Array" do - Puppet[:code] = "validate_integer(#{the_number})" - scope.compiler.compile - end - end - - %w{ true false iAmAString 1test 7.0 -7.0 }.each do |the_number| - it "should not compile when #{the_number} is in a string" do - Puppet[:code] = "validate_integer('#{the_number}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/) - end - - it "should not compile when #{the_number} is a bare word" do - Puppet[:code] = "validate_integer(#{the_number})" - expect { scope.compiler.compile }.to raise_error - end - end - - it "should not compile when an Integer is part of a larger String" do - Puppet[:code] = "validate_integer('1 test')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/) - end +describe 'validate_integer' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should not compile when an Array with a non-Integer value is passed" do - Puppet[:code] = "validate_integer([1, '-7.0'])" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /at array position 1 to be an Integer/) + [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', 7.0, -7.0, {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x'].each do |invalid| + it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, /to be an Integer/) } + it { is_expected.to run.with_params(invalid, 10).and_raise_error(Puppet::ParseError, /to be an Integer/) } + it { is_expected.to run.with_params(invalid, 10, -10).and_raise_error(Puppet::ParseError, /to be an Integer/) } + it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, /to be an Integer/) } end - it "should not compile when a Hash is passed" do - Puppet[:code] = "validate_integer({ 1 => 2 })" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer or Array/) + context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do + it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, /to be an Integer/) } end - it "should not compile when a Hash is passed as Array" do - Puppet[:code] = "validate_integer([{ 1 => 2 }])" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/) + context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do + it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([0, 1, 2, {0=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } end - it "should not compile when an explicitly undef variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_integer($foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/) - end + it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, /to be unset or an Integer/) } + it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, /to be unset or an Integer/) } + it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, /second argument to be larger than third argument/) } + end - it "should not compile when an undefined variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - validate_integer($foobarbazishouldnotexist) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/) - end + context 'with no range constraints' do + it { is_expected.to run.with_params(1) } + it { is_expected.to run.with_params(-1) } + it { is_expected.to run.with_params('1') } + it { is_expected.to run.with_params('-1') } + it { is_expected.to run.with_params([1, 2, 3, 4]) } + it { is_expected.to run.with_params([1, '2', '3', 4]) } end - describe 'when calling validate_integer from puppet with input and a maximum' do - max = 10 - %w{ 1 -1 }.each do |the_number| - it "should compile when #{the_number} is lower than a maximum of #{max}" do - Puppet[:code] = "validate_integer(#{the_number},#{max})" - scope.compiler.compile + context "with a maximum limit of 10" do + describe 'rejects numbers greater than the limit' do + it { is_expected.to run.with_params(11, 10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(100, 10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(2**65, 10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params([1,2,10,100], 10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + end + + describe 'accepts numbers less or equal to the limit' do + it { is_expected.to run.with_params(10, 10) } + it { is_expected.to run.with_params(1, 10) } + it { is_expected.to run.with_params(-1, 10) } + it { is_expected.to run.with_params('1', 10) } + it { is_expected.to run.with_params('-1', 10) } + it { is_expected.to run.with_params([1, 2, 3, 4], 10) } + it { is_expected.to run.with_params([1, '2', '3', 4], 10) } + end + + context "with a minimum limit of -10" do + describe 'rejects numbers greater than the upper limit' do + it { is_expected.to run.with_params(11, 10, -10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(100, 10, -10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(2**65, 10, -10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params([1,2,10,100], 10, -10).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } end - end - it "should compile when an Integer is equal the maximum" do - Puppet[:code] = "validate_integer(#{max},#{max})" - scope.compiler.compile - end - - it "should not compile when #{max+1} is greater than a maximum of #{max}" do - Puppet[:code] = "validate_integer(#{max+1},#{max})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be smaller or equal to/) - end - - %w{ [-10,1,2,3,4,5,10] ['-10','1','2','3','4','5','10'] }.each do |the_number| - it "should compile when each element of #{the_number} is lower than a maximum of #{max}" do - Puppet[:code] = "validate_integer(#{the_number},#{max})" - scope.compiler.compile + describe 'rejects numbers smaller than the lower limit' do + it { is_expected.to run.with_params(-11, 10, -10).and_raise_error(Puppet::ParseError, /to be greater or equal/) } + it { is_expected.to run.with_params(-100, 10, -10).and_raise_error(Puppet::ParseError, /to be greater or equal/) } + it { is_expected.to run.with_params(-2**65, 10, -10).and_raise_error(Puppet::ParseError, /to be greater or equal/) } + it { is_expected.to run.with_params([-10, 1,2,10,-100], 10, -10).and_raise_error(Puppet::ParseError, /to be greater or equal/) } end - end - - it "should not compile when an element of an Array [-10,1,2,3,4,5,#{max+1}] is greater than a maximum of #{max}" do - Puppet[:code] = "validate_integer([-10,1,2,3,4,5,#{max+1}],#{max})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be smaller or equal to/) - end - %w{ true false iAmAString 1test 7.0 -7.0 }.each do |the_max| - it "should not compile when a non-Integer maximum #{the_max}, encapsulated in a String, is passed" do - Puppet[:code] = "validate_integer(1,'#{the_max}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) + describe 'accepts numbers between and including the limits' do + it { is_expected.to run.with_params(10, 10, -10) } + it { is_expected.to run.with_params(-10, 10, -10) } + it { is_expected.to run.with_params(1, 10, -10) } + it { is_expected.to run.with_params(-1, 10, -10) } + it { is_expected.to run.with_params('1', 10, -10) } + it { is_expected.to run.with_params('-1', 10, -10) } + it { is_expected.to run.with_params([1, 2, 3, 4], 10, -10) } + it { is_expected.to run.with_params([1, '2', '3', 4], 10, -10) } end - - it "should not compile when a non-Integer maximum #{the_max} bare word is passed" do - Puppet[:code] = "validate_integer(1,#{the_max})" - expect { scope.compiler.compile }.to raise_error - end - end - - it "should not compile when an explicitly undefined variable is passed as maximum and no minimum is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_integer(10, $foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) - end - it "should not compile when an explicitly undef is passed as maximum and no minimum is passed" do - Puppet[:code] = "validate_integer(10, undef)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) - end - it "should not compile when an empty string is passed as maximum and no minimum is passed" do - Puppet[:code] = "validate_integer(10, '')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) - end - it "should not compile when an undefined variable for a maximum is passed" do - Puppet[:code] = "validate_integer(10, $foobarbazishouldnotexist)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) end end - describe 'when calling validate_integer from puppet with input, a maximum and a minimum' do - it "should not compile when a minimum larger than maximum is passed" do - Puppet[:code] = "validate_integer(1,1,2)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /second argument to be larger than third argument/) - end + it { is_expected.to run.with_params(10, 10, 10) } - max = 10 - min = -10 - %w{ 1 -1 }.each do |the_number| - it "should compile when each element of #{the_number} is within a range from #{min} to #{max}" do - Puppet[:code] = "validate_integer(#{the_number},#{max},#{min})" - scope.compiler.compile - end - end - - it "should compile when an Integer is equal the minimum" do - Puppet[:code] = "validate_integer(#{min},#{max},#{min})" - scope.compiler.compile - end - - it "should compile when an Integer is equal the minimum and maximum" do - Puppet[:code] = "validate_integer(#{max},#{max},#{max})" - scope.compiler.compile - end - - it "should compile when an empty maximum is passed and the Integer is greater than the minimum" do - Puppet[:code] = "validate_integer(#{max},'',#{min})" - scope.compiler.compile - end - it "should compile when an explicitly undefined maximum is passed and the Integer is greater than the minimum" do - Puppet[:code] = "validate_integer(#{max},undef,#{min})" - scope.compiler.compile - end - it "should compile when an explicitly undefined variable is passed for maximum and the Integer is greater than the minimum" do - Puppet[:code] = <<-"ENDofPUPPETcode" - $foo = undef - validate_integer(#{max}, $foo, #{min}) - ENDofPUPPETcode - scope.compiler.compile - end - it "should not compile when no maximum value is given and the Integer is greater than the minimum" do - Puppet[:code] = "validate_integer(#{max},,#{min})" - expect { scope.compiler.compile }.to raise_error(Puppet::Error, /Syntax error at ','/) - end - - it "should not compile when #{min-1} is lower than a minimum of #{min}" do - Puppet[:code] = "validate_integer(#{min-1},#{max},#{min})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be greater or equal to/) - end - - %w{ [-10,1,2,3,4,5,10] ['-10','1','2','3','4','5','10'] }.each do |the_number| - it "should compile when each element of #{the_number} is within a range from #{min} to #{max}" do - Puppet[:code] = "validate_integer(#{the_number},#{max},#{min})" - scope.compiler.compile - end - end - - it "should not compile when an element of an Array [#{min-1},1,2,3,4,5,10] is lower than a minimum of #{min}" do - Puppet[:code] = "validate_integer([#{min-1},1,2,3,4,5,10],#{max},#{min})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be greater or equal to/) - end - - %w{ true false iAmAString 1test 7.0 -7.0 }.each do |the_min| - it "should not compile when a non-Integer minimum #{the_min}, encapsulated in a String, is passed" do - Puppet[:code] = "validate_integer(1,#{max},'#{the_min}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) - end - - it "should not compile when a non-Integer minimum #{the_min} bare word is passed" do - Puppet[:code] = "validate_integer(1,#{max},#{the_min})" - expect { scope.compiler.compile }.to raise_error - end - end + describe 'empty upper limit is interpreted as infinity' do + it { is_expected.to run.with_params(11, '', 10) } end end diff --git a/stdlib/spec/functions/validate_ipv4_address_spec.rb b/stdlib/spec/functions/validate_ipv4_address_spec.rb index 27ea4feef..b6170d438 100755 --- a/stdlib/spec/functions/validate_ipv4_address_spec.rb +++ b/stdlib/spec/functions/validate_ipv4_address_spec.rb @@ -1,62 +1,40 @@ -#! /usr/bin/env ruby -S rspec - -require "spec_helper" - -describe Puppet::Parser::Functions.function(:validate_ipv4_address) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe "when calling validate_ipv4_address from puppet" do - describe "when given IPv4 address strings" do - it "should compile with one argument" do - Puppet[:code] = "validate_ipv4_address('1.2.3.4')" - scope.compiler.compile - end - - it "should compile with multiple arguments" do - Puppet[:code] = "validate_ipv4_address('1.2.3.4', '5.6.7.8')" - scope.compiler.compile - end - end - - describe "when given an IPv6 address" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address('3ffe:505')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv4 address/) - end - end - - describe "when given other strings" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address('hello', 'world')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv4 address/) - end - end - - describe "when given numbers" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address(1, 2)" - expect { scope.compiler.compile }.to raise_error - end - end - - describe "when given booleans" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address(true, false)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a string/) +require 'spec_helper' + +describe 'validate_ipv4_address' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + describe 'valid inputs' do + it { is_expected.to run.with_params('0.0.0.0') } + it { is_expected.to run.with_params('8.8.8.8') } + it { is_expected.to run.with_params('127.0.0.1') } + it { is_expected.to run.with_params('10.10.10.10') } + it { is_expected.to run.with_params('194.232.104.150') } + it { is_expected.to run.with_params('244.24.24.24') } + it { is_expected.to run.with_params('255.255.255.255') } + it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') } + context 'with netmasks' do + it { is_expected.to run.with_params('8.8.8.8/0') } + it { is_expected.to run.with_params('8.8.8.8/16') } + it { is_expected.to run.with_params('8.8.8.8/32') } + it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') } end end - it "should not compile when no arguments are passed" do - Puppet[:code] = "validate_ipv4_address()" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('affe::beef').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } end end end diff --git a/stdlib/spec/functions/validate_ipv6_address_spec.rb b/stdlib/spec/functions/validate_ipv6_address_spec.rb index e87b3726a..7aaf0060a 100755 --- a/stdlib/spec/functions/validate_ipv6_address_spec.rb +++ b/stdlib/spec/functions/validate_ipv6_address_spec.rb @@ -1,65 +1,32 @@ -#! /usr/bin/env ruby -S rspec - -require "spec_helper" - -describe Puppet::Parser::Functions.function(:validate_ipv6_address) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe "when calling validate_ipv6_address from puppet" do - describe "when given IPv6 address strings" do - it "should compile with one argument" do - Puppet[:code] = "validate_ipv6_address('3ffe:0505:0002::')" - scope.compiler.compile - end - - it "should compile with multiple arguments" do - Puppet[:code] = "validate_ipv6_address('3ffe:0505:0002::', '3ffe:0505:0001::')" - scope.compiler.compile - end - end - - describe "when given an ipv4 address" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address('1.2.3.4')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) - end +require 'spec_helper' + +describe 'validate_ipv6_address' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + describe 'valid inputs' do + it { is_expected.to run.with_params('3ffe:0505:0002::') } + it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } + it { is_expected.to run.with_params('::1/64') } + it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } end - describe "when given other strings" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address('hello', 'world')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) } end end - - # 1.8.7 is EOL'd and also absolutely insane about ipv6 - unless RUBY_VERSION == '1.8.7' - describe "when given numbers" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address(1, 2)" - expect { scope.compiler.compile }.to raise_error - end - end - end - - describe "when given booleans" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address(true, false)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a string/) - end - end - - it "should not compile when no arguments are passed" do - Puppet[:code] = "validate_ipv6_address()" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end end end diff --git a/stdlib/spec/functions/validate_numeric_spec.rb b/stdlib/spec/functions/validate_numeric_spec.rb index c99d879e9..9b8eb0eeb 100755 --- a/stdlib/spec/functions/validate_numeric_spec.rb +++ b/stdlib/spec/functions/validate_numeric_spec.rb @@ -1,222 +1,89 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_numeric) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling validate_numeric from puppet without any argument or to many' do - it "should not compile when no argument is passed" do - Puppet[:code] = "validate_numeric()" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /Wrong number of arguments/) - end - it "should not compile when more than three arguments are passed" do - Puppet[:code] = "validate_numeric(1, 1, 1, 1)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /Wrong number of arguments/) - end - end - - describe 'when calling validate_numeric from puppet only with input' do - %w{ 1 -1 1.0 -1.0 }.each do |the_number| - it "should compile when #{the_number} is an encapsulated numeric" do - Puppet[:code] = "validate_numeric('#{the_number}')" - scope.compiler.compile - end - it "should compile when #{the_number} is a bare numeric" do - Puppet[:code] = "validate_numeric(#{the_number})" - scope.compiler.compile - end - end - - %w{ [1,2,3,4,5] ['1','2','3','4','5'] [1.1,2.2,3.3,4.4,5.5] ['1.1','2.2','3.3','4.4','5.5'] }.each do |the_number| - it "should compile when multiple Numeric arguments are passed in an Array" do - Puppet[:code] = "validate_numeric(#{the_number})" - scope.compiler.compile - end - end - - %w{ true false iAmAString 1test }.each do |the_number| - it "should not compile when #{the_number} is in a string" do - Puppet[:code] = "validate_numeric('#{the_number}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/) - end - - it "should not compile when #{the_number} is a bare word" do - Puppet[:code] = "validate_numeric(#{the_number})" - expect { scope.compiler.compile }.to raise_error - end - end - - it "should not compile when a Numeric is part of a larger String" do - Puppet[:code] = "validate_numeric('1.0 test')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/) - end +describe 'validate_numeric' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should not compile when an Array with a non-Numeric value is passed" do - Puppet[:code] = "validate_numeric([1, 'test'])" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /at array position 1 to be a Numeric/) + [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x'].each do |invalid| + it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, /to be a Numeric/) } + it { is_expected.to run.with_params(invalid, 10.0).and_raise_error(Puppet::ParseError, /to be a Numeric/) } + it { is_expected.to run.with_params(invalid, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be a Numeric/) } end - it "should not compile when a Hash is passed" do - Puppet[:code] = "validate_numeric({ 1 => 2 })" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric or Array/) + context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do + it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, /to be a Numeric/) } end - it "should not compile when a Hash is passed in an Array" do - Puppet[:code] = "validate_numeric([{ 1 => 2 }])" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/) + context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do + it { is_expected.to run.with_params([0, 1, 2, {1=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([0, 1, 2, {0=>2}, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } end - it "should not compile when an explicitly undef variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_numeric($foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/) - end + it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, /to be unset or a Numeric/) } + it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, /to be unset or a Numeric/) } + it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, /second argument to be larger than third argument/) } + end - it "should not compile when an undefined variable is passed" do - Puppet[:code] = 'validate_numeric($foobarbazishouldnotexist)' - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/) - end + context 'with no range constraints' do + it { is_expected.to run.with_params(1) } + it { is_expected.to run.with_params(-1) } + it { is_expected.to run.with_params('1') } + it { is_expected.to run.with_params('-1') } + it { is_expected.to run.with_params([1, 2, 3, 4]) } + it { is_expected.to run.with_params([1, '2', '3', 4]) } end - describe 'when calling validate_numeric from puppet with input and a maximum' do - max = 10 - %w{ 1 -1 1.0 -1.0 }.each do |the_number| - it "should compile when #{the_number} is lower than a maximum of #{max}" do - Puppet[:code] = "validate_numeric(#{the_number},#{max})" - scope.compiler.compile + context "with a maximum limit of 10.0" do + describe 'rejects numbers greater than the limit' do + it { is_expected.to run.with_params(11, 10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(100, 10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(2**65, 10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params([1,2,10.0,100], 10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + end + + describe 'accepts numbers less or equal to the limit' do + it { is_expected.to run.with_params(10.0, 10.0) } + it { is_expected.to run.with_params(1, 10.0) } + it { is_expected.to run.with_params(-1, 10.0) } + it { is_expected.to run.with_params('1', 10.0) } + it { is_expected.to run.with_params('-1', 10.0) } + it { is_expected.to run.with_params([1, 2, 3, 4], 10.0) } + it { is_expected.to run.with_params([1, '2', '3', 4], 10.0) } + end + + context "with a minimum limit of -10.0" do + describe 'rejects numbers greater than the upper limit' do + it { is_expected.to run.with_params(11, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(100, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params(2**65, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } + it { is_expected.to run.with_params([1,2,10.0,100], 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be smaller or equal/) } end - end - it "should compile when a Numeric is equal the maximum" do - Puppet[:code] = "validate_numeric(#{max},#{max})" - scope.compiler.compile - end - - it "should not compile when #{max+1} is greater than a maximum of #{max}" do - Puppet[:code] = "validate_numeric(#{max+1},#{max})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be smaller or equal to/) - end - - %w{ [-10,1,2,3,4,5,10] ['-10','1','2','3','4','5','10'] }.each do |the_number| - it "should compile when each element of #{the_number} is lower than a maximum of #{max}" do - Puppet[:code] = "validate_numeric(#{the_number},#{max})" - scope.compiler.compile + describe 'rejects numbers smaller than the lower limit' do + it { is_expected.to run.with_params(-11, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be greater or equal/) } + it { is_expected.to run.with_params(-100, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be greater or equal/) } + it { is_expected.to run.with_params(-2**65, 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be greater or equal/) } + it { is_expected.to run.with_params([-10.0, 1,2,10.0,-100], 10.0, -10.0).and_raise_error(Puppet::ParseError, /to be greater or equal/) } end - end - - it "should not compile when an element of an Array [-10,1,2,3,4,5,#{max+1}] is greater than a maximum of #{max}" do - Puppet[:code] = "validate_numeric([-10,1,2,3,4,5,#{max+1}],#{max})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be smaller or equal to/) - end - %w{ true false iAmAString 1test }.each do |the_max| - it "should not compile when a non-Numeric maximum #{the_max}, encapsulated in a String, is passed" do - Puppet[:code] = "validate_numeric(1,'#{the_max}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) + describe 'accepts numbers between and including the limits' do + it { is_expected.to run.with_params(10.0, 10.0, -10.0) } + it { is_expected.to run.with_params(-10.0, 10.0, -10.0) } + it { is_expected.to run.with_params(1, 10.0, -10.0) } + it { is_expected.to run.with_params(-1, 10.0, -10.0) } + it { is_expected.to run.with_params('1', 10.0, -10.0) } + it { is_expected.to run.with_params('-1', 10.0, -10.0) } + it { is_expected.to run.with_params([1, 2, 3, 4], 10.0, -10.0) } + it { is_expected.to run.with_params([1, '2', '3', 4], 10.0, -10.0) } end - - it "should not compile when a non-Numeric maximum #{the_max} bare word is passed" do - Puppet[:code] = "validate_numeric(1,#{the_max})" - expect { scope.compiler.compile }.to raise_error - end - end - - it "should not compile when an explicitly undefined variable is passed as maximum and no minimum is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_numeric(10, $foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) - end - it "should not compile when an explicitly undef is passed as maximum and no minimum is passed" do - Puppet[:code] = "validate_numeric(10, undef)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) - end - it "should not compile when an empty string is passed as maximum and no minimum is passed" do - Puppet[:code] = "validate_numeric(10, '')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) - end - it "should not compile when an undefined variable for a maximum is passed" do - Puppet[:code] = "validate_numeric(10, $foobarbazishouldnotexist)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) end end - describe 'when calling validate_numeric from puppet with input, a maximum and a minimum' do - it "should not compile when a minimum larger than maximum is passed" do - Puppet[:code] = "validate_numeric(1,1,2)" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /second argument to be larger than third argument/) - end + it { is_expected.to run.with_params(10.0, 10.0, 10.0) } - max = 10 - min = -10 - %w{ 1 -1 }.each do |the_number| - it "should compile when each element of #{the_number} is within a range from #{min} to #{max}" do - Puppet[:code] = "validate_numeric(#{the_number},#{max},#{min})" - scope.compiler.compile - end - end - - it "should compile when a Numeric is equal the minimum" do - Puppet[:code] = "validate_numeric(#{min},#{max},#{min})" - scope.compiler.compile - end - - it "should compile when a Numeric is equal the minimum and maximum" do - Puppet[:code] = "validate_numeric(#{max},#{max},#{max})" - scope.compiler.compile - end - - it "should compile when an empty maximum is passed and the Numeric is greater than the minimum" do - Puppet[:code] = "validate_numeric(#{max}.1,'',#{min})" - scope.compiler.compile - end - it "should compile when an explicitly undefined maximum is passed and the Numeric is greater than the minimum" do - Puppet[:code] = "validate_numeric(#{max}.1,undef,#{min})" - scope.compiler.compile - end - it "should compile when an explicitly undefined variable is passed for maximum and the Numeric is greater than the minimum" do - Puppet[:code] = <<-"ENDofPUPPETcode" - $foo = undef - validate_numeric(#{max}.1, $foo, #{min}) - ENDofPUPPETcode - scope.compiler.compile - end - it "should not compile when no maximum value is given and the Numeric is greater than the minimum" do - Puppet[:code] = "validate_numeric(#{max}.1,,#{min})" - expect { scope.compiler.compile }.to raise_error(Puppet::Error, /Syntax error at ','/) - end - - it "should not compile when #{min-1} is lower than a minimum of #{min}" do - Puppet[:code] = "validate_numeric(#{min-1.0},#{max},#{min})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be greater or equal to/) - end - - %w{ [-10,1,2,3,4,5,10] ['-10.0','1','2','3','4','5','10.0'] }.each do |the_number| - it "should compile when each element of #{the_number} is within a range from #{min} to #{max}" do - Puppet[:code] = "validate_numeric(#{the_number},#{max},#{min})" - scope.compiler.compile - end - end - - it "should not compile when an element of an Array [#{min-1.1},1,2,3,4,5,10.0] is lower than a minimum of #{min}" do - Puppet[:code] = "validate_numeric([#{min-1},1,2,3,4,5,10],#{max},#{min})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be greater or equal to/) - end - - %w{ true false iAmAString 1test }.each do |the_min| - it "should not compile when a non-Numeric minimum #{the_min}, encapsulated in a String, is passed" do - Puppet[:code] = "validate_numeric(1,#{max},'#{the_min}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) - end - - it "should not compile when a non-Numeric minimum #{the_min} bare word is passed" do - Puppet[:code] = "validate_numeric(1,#{max},#{the_min})" - expect { scope.compiler.compile }.to raise_error - end - end + describe 'empty upper limit is interpreted as infinity' do + it { is_expected.to run.with_params(11, '', 10.0) } end end diff --git a/stdlib/spec/functions/validate_re_spec.rb b/stdlib/spec/functions/validate_re_spec.rb index d29988bf0..42b104917 100755 --- a/stdlib/spec/functions/validate_re_spec.rb +++ b/stdlib/spec/functions/validate_re_spec.rb @@ -1,77 +1,46 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_re) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - # The subject of these examplres is the method itself. - subject do - # This makes sure the function is loaded within each test - function_name = Puppet::Parser::Functions.function(:validate_re) - scope.method(function_name) - end - - context 'Using Puppet::Parser::Scope.new' do - - describe 'Garbage inputs' do - inputs = [ - [ nil ], - [ [ nil ] ], - [ { 'foo' => 'bar' } ], - [ { } ], - [ '' ], - [ "one", "one", "MSG to User", "4th arg" ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should fail" do - expect { subject.call [input] }.to raise_error Puppet::ParseError - end - end - end - - describe 'Valid inputs' do - inputs = [ - [ '/full/path/to/something', '^/full' ], - [ '/full/path/to/something', 'full' ], - [ '/full/path/to/something', ['full', 'absent'] ], - [ '/full/path/to/something', ['full', 'absent'], 'Message to the user' ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should not fail" do - expect { subject.call input }.not_to raise_error - end - end - end - describe "Valid inputs which should raise an exception without a message" do - # The intent here is to make sure valid inputs raise exceptions when they - # don't specify an error message to display. This is the behvior in - # 2.2.x and prior. - inputs = [ - [ "hello", [ "bye", "later", "adios" ] ], - [ "greetings", "salutations" ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /validate_re.*?does not match/ - end - end +describe 'validate_re' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + describe 'valid inputs' do + it { is_expected.to run.with_params('', '') } + it { is_expected.to run.with_params('', ['']) } + it { is_expected.to run.with_params('', [''], 'custom error') } + it { is_expected.to run.with_params('one', '^one') } + it { is_expected.to run.with_params('one', [ '^one', '^two' ]) } + it { is_expected.to run.with_params('one', [ '^one', '^two' ], 'custom error') } end - describe "Nicer Error Messages" do - # The intent here is to make sure the function returns the 3rd argument - # in the exception thrown - inputs = [ - [ "hello", [ "bye", "later", "adios" ], "MSG to User" ], - [ "greetings", "salutations", "Error, greetings does not match salutations" ], - ] - inputs.each do |input| - it "validate_re(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /#{input[2]}/ - end - end + describe 'invalid inputs' do + it { + pending('should implement stricter type checking') + is_expected.to run.with_params([], '').and_raise_error(Puppet::ParseError, /is not a String/) + } + it { + pending('should implement stricter type checking') + is_expected.to run.with_params('', {}).and_raise_error(Puppet::ParseError, /is not an Array/) + } + it { + pending('should implement stricter type checking') + is_expected.to run.with_params('', '', []).and_raise_error(Puppet::ParseError, /is not a String/) + } + it { + pending('should implement stricter type checking') + is_expected.to run.with_params(nil, nil).and_raise_error(Puppet::ParseError, /is not a String/) + } + it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, /does not match/) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /does not match/) } + it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, /does not match/) } + it { is_expected.to run.with_params('', ['two']).and_raise_error(Puppet::ParseError, /does not match/) } + it { is_expected.to run.with_params('', ['two'], 'custom error').and_raise_error(Puppet::ParseError, /custom error/) } + it { is_expected.to run.with_params('notone', '^one').and_raise_error(Puppet::ParseError, /does not match/) } + it { is_expected.to run.with_params('notone', [ '^one', '^two' ]).and_raise_error(Puppet::ParseError, /does not match/) } + it { is_expected.to run.with_params('notone', [ '^one', '^two' ], 'custom error').and_raise_error(Puppet::ParseError, /custom error/) } end end end diff --git a/stdlib/spec/functions/validate_slength_spec.rb b/stdlib/spec/functions/validate_slength_spec.rb index e23f61a20..391f83a2a 100755 --- a/stdlib/spec/functions/validate_slength_spec.rb +++ b/stdlib/spec/functions/validate_slength_spec.rb @@ -1,67 +1,61 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the validate_slength function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("validate_slength")).to eq("function_validate_slength") +describe 'validate_slength' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', 2, 3, 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /second argument to be a positive Numeric/) } + it { is_expected.to run.with_params('', -1).and_raise_error(Puppet::ParseError, /second argument to be a positive Numeric/) } + it { is_expected.to run.with_params('', 1, '').and_raise_error(Puppet::ParseError, /third argument to be unset or a positive Numeric/) } + it { is_expected.to run.with_params('', 1, -1).and_raise_error(Puppet::ParseError, /third argument to be unset or a positive Numeric/) } + it { is_expected.to run.with_params('', 1, 2).and_raise_error(Puppet::ParseError, /argument to be larger than third argument/) } end - describe "validating the input argument types" do - it "raises an error if there are less than two arguments" do - expect { scope.function_validate_slength([]) }.to raise_error Puppet::ParseError, /Wrong number of arguments/ - end - - it "raises an error if there are more than three arguments" do - expect { scope.function_validate_slength(['input', 1, 2, 3]) }.to raise_error Puppet::ParseError, /Wrong number of arguments/ - end - - it "raises an error if the first argument is not a string" do - expect { scope.function_validate_slength([Object.new, 2, 1]) }.to raise_error Puppet::ParseError, /Expected first argument.*got .*Object/ - end - - it "raises an error if the second argument cannot be cast to an Integer" do - expect { scope.function_validate_slength(['input', Object.new]) }.to raise_error Puppet::ParseError, /Expected second argument.*got .*Object/ - end - - it "raises an error if the third argument cannot be cast to an Integer" do - expect { scope.function_validate_slength(['input', 1, Object.new]) }.to raise_error Puppet::ParseError, /Expected third argument.*got .*Object/ + context "with a maximum length of 10" do + describe 'rejects strings longer than the limit' do + it { is_expected.to run.with_params('1234567890a', 10).and_raise_error(Puppet::ParseError, /Expected length/) } + it { is_expected.to run.with_params('1234567890abcdef', 10).and_raise_error(Puppet::ParseError, /Expected length/) } + it { is_expected.to run.with_params([ 'one', '1234567890abcdef' ], 10).and_raise_error(Puppet::ParseError, /Expected length/) } end - it "raises an error if the second argument is smaller than the third argument" do - expect { scope.function_validate_slength(['input', 1, 2]) }.to raise_error Puppet::ParseError, /Expected second argument to be larger than third argument/ + describe 'accepts strings shorter or equal to the limit' do + it { is_expected.to run.with_params('1234567890', 10) } + it { is_expected.to run.with_params('12345', 10) } + it { is_expected.to run.with_params([ 'one', 'two' ], 10) } end - end - - describe "validating the input string length" do - describe "when the input is a string" do - it "fails validation if the string is larger than the max length" do - expect { scope.function_validate_slength(['input', 1]) }.to raise_error Puppet::ParseError, /Expected length .* between 0 and 1, was 5/ - end - - it "fails validation if the string is less than the min length" do - expect { scope.function_validate_slength(['input', 10, 6]) }.to raise_error Puppet::ParseError, /Expected length .* between 6 and 10, was 5/ - end - it "doesn't raise an error if the string is under the max length" do - scope.function_validate_slength(['input', 10]) + context "with a minimum length of 5" do + describe 'rejects strings longer than the upper limit' do + it { is_expected.to run.with_params('1234567890a', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) } + it { is_expected.to run.with_params('1234567890abcdef', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) } end - it "doesn't raise an error if the string is equal to the max length" do - scope.function_validate_slength(['input', 5]) + describe 'rejects numbers shorter than the lower limit' do + it { is_expected.to run.with_params('one', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) } + it { is_expected.to run.with_params(['12345678', 'two'], 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) } end - it "doesn't raise an error if the string is equal to the min length" do - scope.function_validate_slength(['input', 10, 5]) + describe 'accepts strings of length between and including the limits' do + it { is_expected.to run.with_params('12345', 10, 5) } + it { is_expected.to run.with_params('123456', 10, 5) } + it { is_expected.to run.with_params('1234567', 10, 5) } + it { is_expected.to run.with_params('12345678', 10, 5) } + it { is_expected.to run.with_params('123456789', 10, 5) } + it { is_expected.to run.with_params('1234567890', 10, 5) } + it { is_expected.to run.with_params(['1233456', '12345678'], 10, 5) } end end + end - describe "when the input is an array" do - it "fails validation if one of the array elements is not a string" do - expect { scope.function_validate_slength([["a", "b", Object.new], 2]) }.to raise_error Puppet::ParseError, /Expected element at array position 2 .*String, got .*Object/ - end - end + describe 'corner cases' do + it { pending('this should work'); is_expected.to run.with_params('', 0, 0) } + it { is_expected.to run.with_params('1234567890', 10, 10) } + end + + describe 'empty upper limit is interpreted as infinity' do + it { pending('not implemented'); is_expected.to run.with_params('1234567890ab', '', 10) } + it { pending('not implemented'); is_expected.to run.with_params('12345678', '', 10).and_raise_error(Puppet::ParseError, /Expected length/) } end end diff --git a/stdlib/spec/functions/validate_string_spec.rb b/stdlib/spec/functions/validate_string_spec.rb index 3b4fb3e1d..f0c500eb1 100755 --- a/stdlib/spec/functions/validate_string_spec.rb +++ b/stdlib/spec/functions/validate_string_spec.rb @@ -1,60 +1,21 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe Puppet::Parser::Functions.function(:validate_string) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling validate_string from puppet' do - - %w{ foo bar baz }.each do |the_string| - - it "should compile when #{the_string} is a string" do - Puppet[:code] = "validate_string('#{the_string}')" - scope.compiler.compile - end - - it "should compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_string(#{the_string})" - scope.compiler.compile - end - - end - - %w{ true false }.each do |the_string| - it "should compile when #{the_string} is a string" do - Puppet[:code] = "validate_string('#{the_string}')" - scope.compiler.compile - end - - it "should not compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_string(#{the_string})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/) - end - end - - it "should compile when multiple string arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = '' - $bar = 'two' - validate_string($foo, $bar) - ENDofPUPPETcode - scope.compiler.compile - end +describe 'validate_string' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_string($foo) - ENDofPUPPETcode - scope.compiler.compile + describe 'valid inputs' do + it { is_expected.to run.with_params('') } + it { is_expected.to run.with_params('one') } + it { is_expected.to run.with_params('one', 'two') } end - it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do - Puppet[:code] = <<-'ENDofPUPPETcode' - validate_string($foobarbazishouldnotexist) - ENDofPUPPETcode - scope.compiler.compile + describe 'invalid inputs' do + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } end end end diff --git a/stdlib/spec/functions/values_at_spec.rb b/stdlib/spec/functions/values_at_spec.rb index 86e3c31c6..a8348f395 100755 --- a/stdlib/spec/functions/values_at_spec.rb +++ b/stdlib/spec/functions/values_at_spec.rb @@ -1,38 +1,49 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the values_at function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("values_at")).to eq("function_values_at") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_values_at([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if you try to use a range where stop is greater then start" do - expect { scope.function_values_at([['a','b'],["3-1"]]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return a value at from an array" do - result = scope.function_values_at([['a','b','c'],"1"]) - expect(result).to(eq(['b'])) - end - - it "should return a value at from an array when passed a range" do - result = scope.function_values_at([['a','b','c'],"0-1"]) - expect(result).to(eq(['a','b'])) +describe 'values_at' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first two.") + is_expected.to run.with_params([], 0, 1).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('', 1).and_raise_error(Puppet::ParseError, /Requires array/i) } + it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /Requires array/i) } + it { is_expected.to run.with_params(true, 1).and_raise_error(Puppet::ParseError, /Requires array/i) } + it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, /Requires array/i) } + it { is_expected.to run.with_params([0,1,2], 'two').and_raise_error(Puppet::ParseError, /Unknown format of given index/) } + it { is_expected.to run.with_params([0,1,2], []).and_raise_error(Puppet::ParseError, /provide at least one positive index/) } + it { is_expected.to run.with_params([0,1,2], '-1-1').and_raise_error(Puppet::ParseError, /Unknown format of given index/) } + it { is_expected.to run.with_params([0,1,2], '2-1').and_raise_error(Puppet::ParseError, /Stop index in given indices range is smaller than the start index/) } end - it "should return chosen values from an array when passed number of indexes" do - result = scope.function_values_at([['a','b','c'],["0","2"]]) - expect(result).to(eq(['a','c'])) + context 'when requesting a single item' do + it { is_expected.to run.with_params([0, 1, 2], -1).and_raise_error(Puppet::ParseError, /Unknown format of given index/) } + it { is_expected.to run.with_params([0, 1, 2], 0).and_return([0]) } + it { is_expected.to run.with_params([0, 1, 2], 1).and_return([1]) } + it { is_expected.to run.with_params([0, 1, 2], [1]).and_return([1]) } + it { is_expected.to run.with_params([0, 1, 2], '1').and_return([1]) } + it { is_expected.to run.with_params([0, 1, 2], '1-1').and_return([1]) } + it { is_expected.to run.with_params([0, 1, 2], 2).and_return([2]) } + it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError, /index exceeds array size/) } end - it "should return chosen values from an array when passed ranges and multiple indexes" do - result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]]) - expect(result).to(eq(['a','c','e','f'])) + context 'when requesting multiple items' do + it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, /Unknown format of given index/) } + it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) } + it { is_expected.to run.with_params([0, 1, 2], ['0-2', 1, 2]).and_return([0, 1, 2, 1, 2]) } + it { is_expected.to run.with_params([0, 1, 2], [3, 2]).and_raise_error(Puppet::ParseError, /index exceeds array size/) } + + describe 'different range syntaxes' do + it { is_expected.to run.with_params([0, 1, 2], '0-2').and_return([0, 1, 2]) } + it { is_expected.to run.with_params([0, 1, 2], '0..2').and_return([0, 1, 2]) } + it { is_expected.to run.with_params([0, 1, 2], '0...2').and_return([0, 1]) } + it { + pending('fix this bounds check') + is_expected.to run.with_params([0, 1, 2], '0...3').and_return([0, 1, 2]) + } + end end end diff --git a/stdlib/spec/functions/values_spec.rb b/stdlib/spec/functions/values_spec.rb index 08d21b037..4abf0bd74 100755 --- a/stdlib/spec/functions/values_spec.rb +++ b/stdlib/spec/functions/values_spec.rb @@ -1,31 +1,19 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("values")).to eq("function_values") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_values([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return values from a hash" do - result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}]) - # =~ is the RSpec::Matchers::MatchArray matcher. - # A.K.A. "array with same elements" (multiset) matching - expect(result).to match_array(%w{ 1 2 3 }) - end - - it "should return a multiset" do - result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}]) - expect(result).to match_array(%w{ 1 3 3 }) - expect(result).not_to match_array(%w{ 1 3 }) - end - - it "should raise a ParseError unless a Hash is provided" do - expect { scope.function_values([['a','b','c']]) }.to( raise_error(Puppet::ParseError)) +describe 'values' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params({}, 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /Requires hash to work with/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires hash to work with/) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /Requires hash to work with/) } + it { is_expected.to run.with_params({}).and_return([]) } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['value']) } + it 'should return the array of values' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) + expect(result).to match_array(['value1', 'value2', 'value2']) end end diff --git a/stdlib/spec/functions/zip_spec.rb b/stdlib/spec/functions/zip_spec.rb index f265fcee4..abca7ee86 100755 --- a/stdlib/spec/functions/zip_spec.rb +++ b/stdlib/spec/functions/zip_spec.rb @@ -1,31 +1,15 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the zip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_zip([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should be able to zip an array" do - result = scope.function_zip([['1','2','3'],['4','5','6']]) - expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]])) - result = scope.function_zip([['1','2','3'],['4','5','6'], false]) - result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) - end - - it "should be able to zip an array and flatten" do - result = scope.function_zip([['1','2','3'],['4','5','6'], true]) - result.should(eq(["1", "4", "2", "5", "3", "6"])) - end - - it "should accept objects which extend String for the second argument" do - class AlsoString < String - end - - value = AlsoString.new('false') - result = scope.function_zip([['1','2','3'],['4','5','6'],value]) - result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) - end +describe 'zip' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the third.") + is_expected.to run.with_params([], [], true, []).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params([], []).and_return([]) } + it { is_expected.to run.with_params([1,2,3], [4,5,6]).and_return([[1,4], [2,5], [3,6]]) } + it { is_expected.to run.with_params([1,2,3], [4,5,6], false).and_return([[1,4], [2,5], [3,6]]) } + it { is_expected.to run.with_params([1,2,3], [4,5,6], true).and_return([1, 4, 2, 5, 3, 6]) } end diff --git a/stdlib/spec/lib/puppet_spec/compiler.rb b/stdlib/spec/lib/puppet_spec/compiler.rb deleted file mode 100755 index 1f322ca63..000000000 --- a/stdlib/spec/lib/puppet_spec/compiler.rb +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env ruby -S rspec -module PuppetSpec::Compiler - def compile_to_catalog(string, node = Puppet::Node.new('foonode')) - Puppet[:code] = string - Puppet[:parser] = 'future' if ENV['FUTURE_PARSER'] == 'yes' - Puppet::Parser::Compiler.compile(node) - end - - def compile_to_ral(manifest) - catalog = compile_to_catalog(manifest) - ral = catalog.to_ral - ral.finalize - ral - end - - def compile_to_relationship_graph(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new) - ral = compile_to_ral(manifest) - graph = Puppet::Graph::RelationshipGraph.new(prioritizer) - graph.populate_from(ral) - graph - end - - if Puppet.version.to_f >= 3.3 - def apply_compiled_manifest(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new) - transaction = Puppet::Transaction.new(compile_to_ral(manifest), - Puppet::Transaction::Report.new("apply"), - prioritizer) - transaction.evaluate - transaction.report.finalize_report - - transaction - end - else - def apply_compiled_manifest(manifest) - transaction = Puppet::Transaction.new(compile_to_ral(manifest), Puppet::Transaction::Report.new("apply")) - transaction.evaluate - transaction.report.finalize_report - - transaction - end - end - - def order_resources_traversed_in(relationships) - order_seen = [] - relationships.traverse { |resource| order_seen << resource.ref } - order_seen - end -end diff --git a/stdlib/spec/lib/puppet_spec/database.rb b/stdlib/spec/lib/puppet_spec/database.rb deleted file mode 100755 index f5c234179..000000000 --- a/stdlib/spec/lib/puppet_spec/database.rb +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env ruby -S rspec -# This just makes some nice things available at global scope, and for setup of -# tests to use a real fake database, rather than a fake stubs-that-don't-work -# version of the same. Fun times. -def sqlite? - if $sqlite.nil? - begin - require 'sqlite3' - $sqlite = true - rescue LoadError - $sqlite = false - end - end - $sqlite -end - -def can_use_scratch_database? - sqlite? and Puppet.features.rails? -end - - -# This is expected to be called in your `before :each` block, and will get you -# ready to roll with a serious database and all. Cleanup is handled -# automatically for you. Nothing to do there. -def setup_scratch_database - Puppet[:dbadapter] = 'sqlite3' - Puppet[:dblocation] = ':memory:' - Puppet[:railslog] = PuppetSpec::Files.tmpfile('storeconfigs.log') - Puppet::Rails.init -end diff --git a/stdlib/spec/lib/puppet_spec/files.rb b/stdlib/spec/lib/puppet_spec/files.rb deleted file mode 100755 index 71b38ffed..000000000 --- a/stdlib/spec/lib/puppet_spec/files.rb +++ /dev/null @@ -1,61 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'fileutils' -require 'tempfile' -require 'tmpdir' -require 'pathname' - -# A support module for testing files. -module PuppetSpec::Files - def self.cleanup - $global_tempfiles ||= [] - while path = $global_tempfiles.pop do - begin - Dir.unstub(:entries) - FileUtils.rm_rf path, :secure => true - rescue Errno::ENOENT - # nothing to do - end - end - end - - def make_absolute(path) PuppetSpec::Files.make_absolute(path) end - def self.make_absolute(path) - path = File.expand_path(path) - path[0] = 'c' if Puppet.features.microsoft_windows? - path - end - - def tmpfile(name, dir = nil) PuppetSpec::Files.tmpfile(name, dir) end - def self.tmpfile(name, dir = nil) - # Generate a temporary file, just for the name... - source = dir ? Tempfile.new(name, dir) : Tempfile.new(name) - path = source.path - source.close! - - record_tmp(File.expand_path(path)) - - path - end - - def file_containing(name, contents) PuppetSpec::Files.file_containing(name, contents) end - def self.file_containing(name, contents) - file = tmpfile(name) - File.open(file, 'wb') { |f| f.write(contents) } - file - end - - def tmpdir(name) PuppetSpec::Files.tmpdir(name) end - def self.tmpdir(name) - dir = Dir.mktmpdir(name) - - record_tmp(dir) - - dir - end - - def self.record_tmp(tmp) - # ...record it for cleanup, - $global_tempfiles ||= [] - $global_tempfiles << tmp - end -end diff --git a/stdlib/spec/lib/puppet_spec/fixtures.rb b/stdlib/spec/lib/puppet_spec/fixtures.rb deleted file mode 100755 index 81e9775ff..000000000 --- a/stdlib/spec/lib/puppet_spec/fixtures.rb +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env ruby -S rspec -module PuppetSpec::Fixtures - def fixtures(*rest) - File.join(PuppetSpec::FIXTURE_DIR, *rest) - end - def my_fixture_dir - callers = caller - while line = callers.shift do - next unless found = line.match(%r{/spec/(.*)_spec\.rb:}) - return fixtures(found[1]) - end - fail "sorry, I couldn't work out your path from the caller stack!" - end - def my_fixture(name) - file = File.join(my_fixture_dir, name) - unless File.readable? file then - fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable" - end - return file - end - def my_fixtures(glob = '*', flags = 0) - files = Dir.glob(File.join(my_fixture_dir, glob), flags) - unless files.length > 0 then - fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!" - end - block_given? and files.each do |file| yield file end - files - end -end diff --git a/stdlib/spec/lib/puppet_spec/matchers.rb b/stdlib/spec/lib/puppet_spec/matchers.rb deleted file mode 100755 index 093d77c81..000000000 --- a/stdlib/spec/lib/puppet_spec/matchers.rb +++ /dev/null @@ -1,121 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'stringio' - -######################################################################## -# Backward compatibility for Jenkins outdated environment. -module RSpec - module Matchers - module BlockAliases - alias_method :to, :should unless method_defined? :to - alias_method :to_not, :should_not unless method_defined? :to_not - alias_method :not_to, :should_not unless method_defined? :not_to - end - end -end - - -######################################################################## -# Custom matchers... -RSpec::Matchers.define :have_matching_element do |expected| - match do |actual| - actual.any? { |item| item =~ expected } - end -end - - -RSpec::Matchers.define :exit_with do |expected| - actual = nil - match do |block| - begin - block.call - rescue SystemExit => e - actual = e.status - end - actual and actual == expected - end - failure_message_for_should do |block| - "expected exit with code #{expected} but " + - (actual.nil? ? " exit was not called" : "we exited with #{actual} instead") - end - failure_message_for_should_not do |block| - "expected that exit would not be called with #{expected}" - end - description do - "expect exit with #{expected}" - end -end - -class HavePrintedMatcher - attr_accessor :expected, :actual - - def initialize(expected) - case expected - when String, Regexp - @expected = expected - else - @expected = expected.to_s - end - end - - def matches?(block) - begin - $stderr = $stdout = StringIO.new - $stdout.set_encoding('UTF-8') if $stdout.respond_to?(:set_encoding) - block.call - $stdout.rewind - @actual = $stdout.read - ensure - $stdout = STDOUT - $stderr = STDERR - end - - if @actual then - case @expected - when String - @actual.include? @expected - when Regexp - @expected.match @actual - end - else - false - end - end - - def failure_message_for_should - if @actual.nil? then - "expected #{@expected.inspect}, but nothing was printed" - else - "expected #{@expected.inspect} to be printed; got:\n#{@actual}" - end - end - - def failure_message_for_should_not - "expected #{@expected.inspect} to not be printed; got:\n#{@actual}" - end - - def description - "expect #{@expected.inspect} to be printed" - end -end - -def have_printed(what) - HavePrintedMatcher.new(what) -end - -RSpec::Matchers.define :equal_attributes_of do |expected| - match do |actual| - actual.instance_variables.all? do |attr| - actual.instance_variable_get(attr) == expected.instance_variable_get(attr) - end - end -end - -RSpec::Matchers.define :be_one_of do |*expected| - match do |actual| - expected.include? actual - end - - failure_message_for_should do |actual| - "expected #{actual.inspect} to be one of #{expected.map(&:inspect).join(' or ')}" - end -end diff --git a/stdlib/spec/lib/puppet_spec/modules.rb b/stdlib/spec/lib/puppet_spec/modules.rb deleted file mode 100755 index 910c6d94e..000000000 --- a/stdlib/spec/lib/puppet_spec/modules.rb +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env ruby -S rspec -module PuppetSpec::Modules - class << self - def create(name, dir, options = {}) - module_dir = File.join(dir, name) - FileUtils.mkdir_p(module_dir) - - environment = options[:environment] - - if metadata = options[:metadata] - metadata[:source] ||= 'github' - metadata[:author] ||= 'puppetlabs' - metadata[:version] ||= '9.9.9' - metadata[:license] ||= 'to kill' - metadata[:dependencies] ||= [] - - metadata[:name] = "#{metadata[:author]}/#{name}" - - File.open(File.join(module_dir, 'metadata.json'), 'w') do |f| - f.write(metadata.to_pson) - end - end - - Puppet::Module.new(name, module_dir, environment) - end - end -end diff --git a/stdlib/spec/lib/puppet_spec/pops.rb b/stdlib/spec/lib/puppet_spec/pops.rb deleted file mode 100755 index e056a52b7..000000000 --- a/stdlib/spec/lib/puppet_spec/pops.rb +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/env ruby -S rspec -module PuppetSpec::Pops - extend RSpec::Matchers::DSL - - # Checks if an Acceptor has a specific issue in its list of diagnostics - matcher :have_issue do |expected| - match do |actual| - actual.diagnostics.index { |i| i.issue == expected } != nil - end - failure_message_for_should do |actual| - "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to contain issue #{expected.issue_code}" - end - failure_message_for_should_not do |actual| - "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to not contain issue #{expected.issue_code}" - end - end -end diff --git a/stdlib/spec/lib/puppet_spec/scope.rb b/stdlib/spec/lib/puppet_spec/scope.rb deleted file mode 100755 index 3847ede18..000000000 --- a/stdlib/spec/lib/puppet_spec/scope.rb +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -module PuppetSpec::Scope - # Initialize a new scope suitable for testing. - # - def create_test_scope_for_node(node_name) - node = Puppet::Node.new(node_name) - compiler = Puppet::Parser::Compiler.new(node) - scope = Puppet::Parser::Scope.new(compiler) - scope.source = Puppet::Resource::Type.new(:node, node_name) - scope.parent = compiler.topscope - scope - end - -end \ No newline at end of file diff --git a/stdlib/spec/lib/puppet_spec/settings.rb b/stdlib/spec/lib/puppet_spec/settings.rb deleted file mode 100755 index 8ddcb975f..000000000 --- a/stdlib/spec/lib/puppet_spec/settings.rb +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env ruby -S rspec -module PuppetSpec::Settings - - # It would probably be preferable to refactor defaults.rb such that the real definitions of - # these settings were available as a variable, which was then accessible for use during tests. - # However, I'm not doing that yet because I don't want to introduce any additional moving parts - # to this already very large changeset. - # Would be nice to clean this up later. --cprice 2012-03-20 - TEST_APP_DEFAULT_DEFINITIONS = { - :name => { :default => "test", :desc => "name" }, - :logdir => { :type => :directory, :default => "test", :desc => "logdir" }, - :confdir => { :type => :directory, :default => "test", :desc => "confdir" }, - :vardir => { :type => :directory, :default => "test", :desc => "vardir" }, - :rundir => { :type => :directory, :default => "test", :desc => "rundir" }, - } -end diff --git a/stdlib/spec/lib/puppet_spec/verbose.rb b/stdlib/spec/lib/puppet_spec/verbose.rb deleted file mode 100755 index b2683df04..000000000 --- a/stdlib/spec/lib/puppet_spec/verbose.rb +++ /dev/null @@ -1,10 +0,0 @@ -#! /usr/bin/env ruby -S rspec -# Support code for running stuff with warnings disabled. -module Kernel - def with_verbose_disabled - verbose, $VERBOSE = $VERBOSE, nil - result = yield - $VERBOSE = verbose - return result - end -end diff --git a/stdlib/spec/puppetlabs_spec_helper_clone.rb b/stdlib/spec/puppetlabs_spec_helper_clone.rb new file mode 100644 index 000000000..6a94a3b47 --- /dev/null +++ b/stdlib/spec/puppetlabs_spec_helper_clone.rb @@ -0,0 +1,34 @@ +#This file pulls in only the minimum necessary to let unmigrated specs still work + +# Define the main module namespace for use by the helper modules +module PuppetlabsSpec + # FIXTURE_DIR represents the standard locations of all fixture data. Normally + # this represents /spec/fixtures. This will be used by the fixtures + # library to find relative fixture data. + FIXTURE_DIR = File.join("spec", "fixtures") unless defined?(FIXTURE_DIR) +end + +# Require all necessary helper libraries so they can be used later +require 'puppetlabs_spec_helper/puppetlabs_spec/files' +require 'puppetlabs_spec_helper/puppetlabs_spec/fixtures' +#require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals' +require 'puppetlabs_spec_helper/puppetlabs_spec/matchers' + +RSpec.configure do |config| + # Include PuppetlabsSpec helpers so they can be called at convenience + config.extend PuppetlabsSpec::Files + config.extend PuppetlabsSpec::Fixtures + config.include PuppetlabsSpec::Fixtures + + config.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes' + config.strict_variables = true if ENV['STRICT_VARIABLES'] == 'yes' + config.stringify_facts = false if ENV['STRINGIFY_FACTS'] == 'no' + config.trusted_node_data = true if ENV['TRUSTED_NODE_DATA'] == 'yes' + config.ordering = ENV['ORDERING'] if ENV['ORDERING'] + + # This will cleanup any files that were created with tmpdir or tmpfile + config.after :each do + PuppetlabsSpec::Files.cleanup + end +end + diff --git a/stdlib/spec/spec_helper.rb b/stdlib/spec/spec_helper.rb index 896cb83ca..416036b5a 100755 --- a/stdlib/spec/spec_helper.rb +++ b/stdlib/spec/spec_helper.rb @@ -10,16 +10,23 @@ module PuppetSpec require 'puppet' require 'rspec-puppet' require 'puppetlabs_spec_helper/module_spec_helper' -require 'puppet_spec/verbose' -require 'puppet_spec/files' -require 'puppet_spec/settings' -require 'puppet_spec/fixtures' -require 'puppet_spec/matchers' -require 'puppet_spec/database' require 'monkey_patches/alias_should_to_must' require 'mocha/api' +#require 'puppetlabs_spec_helper/module_spec_helper' +require 'puppetlabs_spec_helper_clone' + +# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples +RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers) RSpec.configure do |config| + config.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules') + config.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests') + config.environmentpath = spec_path = File.expand_path(File.join(Dir.pwd, 'spec')) + + config.add_setting :puppet_future + #config.puppet_future = (ENV['FUTURE_PARSER'] == 'yes' or Puppet.version.to_f >= 4.0) + config.puppet_future = Puppet.version.to_f >= 4.0 + config.before :each do # Ensure that we don't accidentally cache facts and environment between # test cases. This requires each example group to explicitly load the @@ -28,6 +35,15 @@ module PuppetSpec Facter.clear Facter.clear_messages - Puppet[:parser] = 'future' if ENV['FUTURE_PARSER'] == 'yes' + RSpec::Mocks.setup end + + config.after :each do + RSpec::Mocks.verify + RSpec::Mocks.teardown + end +end + +# Helper class to test handling of arguments which are derived from string +class AlsoString < String end diff --git a/stdlib/spec/spec_helper_acceptance.rb b/stdlib/spec/spec_helper_acceptance.rb index 79b1390ce..3d9574b70 100755 --- a/stdlib/spec/spec_helper_acceptance.rb +++ b/stdlib/spec/spec_helper_acceptance.rb @@ -6,7 +6,7 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' foss_opts = { :default_action => 'gem_install', - :version => (ENV['PUPPET_VERSION'] ? ENV['PUPPET_VERSION'] : '3.7.2'), + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end diff --git a/stdlib/spec/unit/facter/util/puppet_settings_spec.rb b/stdlib/spec/unit/facter/util/puppet_settings_spec.rb index c06137d7e..c278b7984 100755 --- a/stdlib/spec/unit/facter/util/puppet_settings_spec.rb +++ b/stdlib/spec/unit/facter/util/puppet_settings_spec.rb @@ -25,6 +25,7 @@ module Puppet; end before :each do Puppet.expects(:[]).with(:vardir).returns vardir end + it 'should yield to the block' do subject.with_puppet { Puppet[:vardir] } end diff --git a/swift/.gitreview b/swift/.gitreview index df1b96ba7..7f8f985c2 100644 --- a/swift/.gitreview +++ b/swift/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-swift.git +project=openstack/puppet-swift.git diff --git a/swift/Gemfile b/swift/Gemfile index 4c65317ac..3c0b87530 100644 --- a/swift/Gemfile +++ b/swift/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -17,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/swift/spec/acceptance/nodesets/nodepool-centos7.yml b/swift/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/swift/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/swift/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/swift/spec/acceptance/nodesets/nodepool-trusty.yml b/swift/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/swift/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/swift/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/swift/spec/classes/swift_keystone_auth_spec.rb b/swift/spec/classes/swift_keystone_auth_spec.rb index ecdf8c1e2..5a487b8d5 100644 --- a/swift/spec/classes/swift_keystone_auth_spec.rb +++ b/swift/spec/classes/swift_keystone_auth_spec.rb @@ -93,7 +93,7 @@ it { is_expected.to contain_keystone_user_role("#{p[:auth_name]}@#{p[:tenant]}").with( :ensure => 'present', - :roles => 'admin', + :roles => ['admin'], )} it { is_expected.to contain_keystone_service(p[:auth_name]).with( diff --git a/swift/spec/classes/swift_proxy_ceilometer_spec.rb b/swift/spec/classes/swift_proxy_ceilometer_spec.rb index 22322db6e..211cc2573 100644 --- a/swift/spec/classes/swift_proxy_ceilometer_spec.rb +++ b/swift/spec/classes/swift_proxy_ceilometer_spec.rb @@ -22,7 +22,11 @@ class { "swift": it { is_expected.to contain_file(fragment_file).with_content(/[filter:ceilometer]/) } it { is_expected.to contain_file(fragment_file).with_content(/use = egg:ceilometer#swift/) } - it { is_expected.to contain_concat__fragment('swift_ceilometer').with_require('Class[::Ceilometer]') } + if Puppet.version.to_f < 4.0 + it { is_expected.to contain_concat__fragment('swift_ceilometer').with_require('Class[::Ceilometer]')} + else + it { is_expected.to contain_concat__fragment('swift_ceilometer').with_require('Class[Ceilometer]')} + end it { is_expected.to contain_user('swift').with_groups('ceilometer') } it { is_expected.to contain_file('/var/log/ceilometer/swift-proxy-server.log').with(:owner => 'swift', :group => 'swift', :mode => '0664') } diff --git a/swift/spec/classes/swift_proxy_spec.rb b/swift/spec/classes/swift_proxy_spec.rb index d120fc09e..0cc3b0356 100644 --- a/swift/spec/classes/swift_proxy_spec.rb +++ b/swift/spec/classes/swift_proxy_spec.rb @@ -125,9 +125,11 @@ class { swift: swift_hash_suffix => string }" ] ) end - it { is_expected.to contain_concat__fragment('swift_proxy').with_before( - 'Class[Swift::Proxy::Swauth]' - )} + if Puppet.version.to_f < 4.0 + it { is_expected.to contain_concat__fragment('swift_proxy').with_before('Class[Swift::Proxy::Swauth]')} + else + it { is_expected.to contain_concat__fragment('swift_proxy').with_before(['Class[Swift::Proxy::Swauth]'])} + end end describe "when log udp port is set" do context 'and log_udp_host is not set' do diff --git a/swift/spec/classes/swift_ringbuilder_spec.rb b/swift/spec/classes/swift_ringbuilder_spec.rb index 5c5b5b9ec..28a9d8f03 100644 --- a/swift/spec/classes/swift_ringbuilder_spec.rb +++ b/swift/spec/classes/swift_ringbuilder_spec.rb @@ -76,22 +76,22 @@ class { swift: swift_hash_suffix => string } it 'should set up all of the correct dependencies' do is_expected.to contain_swift__ringbuilder__create('object').with( - {:before => 'Ring_object_device[127.0.0.1:6000/1]'} + {:before => ['Ring_object_device[127.0.0.1:6000/1]']} ) is_expected.to contain_swift__ringbuilder__create('container').with( - {:before => 'Ring_container_device[127.0.0.1:6001/1]'} + {:before => ['Ring_container_device[127.0.0.1:6001/1]']} ) is_expected.to contain_swift__ringbuilder__create('account').with( - {:before => 'Ring_account_device[127.0.0.1:6002/1]'} + {:before => ['Ring_account_device[127.0.0.1:6002/1]']} ) is_expected.to contain_ring_object_device('127.0.0.1:6000/1').with( - {:notify => 'Swift::Ringbuilder::Rebalance[object]'} + {:notify => ['Swift::Ringbuilder::Rebalance[object]']} ) is_expected.to contain_ring_container_device('127.0.0.1:6001/1').with( - {:notify => 'Swift::Ringbuilder::Rebalance[container]'} + {:notify => ['Swift::Ringbuilder::Rebalance[container]']} ) is_expected.to contain_ring_account_device('127.0.0.1:6002/1').with( - {:notify => 'Swift::Ringbuilder::Rebalance[account]'} + {:notify => ['Swift::Ringbuilder::Rebalance[account]']} ) end end diff --git a/swift/spec/classes/swift_storage_all_spec.rb b/swift/spec/classes/swift_storage_all_spec.rb index ced3b2199..a952c9e7d 100644 --- a/swift/spec/classes/swift_storage_all_spec.rb +++ b/swift/spec/classes/swift_storage_all_spec.rb @@ -84,17 +84,17 @@ it { is_expected.to contain_swift__storage__server(param_hash[:account_port]).with( {:type => 'account', :config_file_path => 'account-server.conf', - :pipeline => param_hash[:account_pipeline] || 'account-server' }.merge(storage_server_defaults) + :pipeline => param_hash[:account_pipeline] || ['account-server'] }.merge(storage_server_defaults) )} it { is_expected.to contain_swift__storage__server(param_hash[:object_port]).with( {:type => 'object', :config_file_path => 'object-server.conf', - :pipeline => param_hash[:object_pipeline] || 'object-server' }.merge(storage_server_defaults) + :pipeline => param_hash[:object_pipeline] || ['object-server'] }.merge(storage_server_defaults) )} it { is_expected.to contain_swift__storage__server(param_hash[:container_port]).with( {:type => 'container', :config_file_path => 'container-server.conf', - :pipeline => param_hash[:container_pipeline] || 'container-server', + :pipeline => param_hash[:container_pipeline] || ['container-server'], :allow_versions => param_hash[:allow_versions] || false }.merge(storage_server_defaults) )} diff --git a/swift/spec/defines/swift_ringbuilder_create_spec.rb b/swift/spec/defines/swift_ringbuilder_create_spec.rb index 64f3f9d5f..d5a6d0834 100644 --- a/swift/spec/defines/swift_ringbuilder_create_spec.rb +++ b/swift/spec/defines/swift_ringbuilder_create_spec.rb @@ -31,7 +31,7 @@ it { is_expected.to contain_exec("create_#{type}").with( {:command => "swift-ring-builder /etc/swift/#{type}.builder create #{param_hash[:part_power]} #{param_hash[:replicas]} #{param_hash[:min_part_hours]}", - :path => '/usr/bin', + :path => ['/usr/bin'], :creates => "/etc/swift/#{type}.builder" } )} end diff --git a/swift/spec/defines/swift_ringbuilder_rebalance_spec.rb b/swift/spec/defines/swift_ringbuilder_rebalance_spec.rb index 09ef75f24..ed275ea71 100644 --- a/swift/spec/defines/swift_ringbuilder_rebalance_spec.rb +++ b/swift/spec/defines/swift_ringbuilder_rebalance_spec.rb @@ -8,7 +8,7 @@ end it { is_expected.to contain_exec("rebalance_#{type}").with( {:command => "swift-ring-builder /etc/swift/#{type}.builder rebalance", - :path => '/usr/bin', + :path => ['/usr/bin'], :refreshonly => true} )} end @@ -23,7 +23,7 @@ end it { is_expected.to contain_exec("rebalance_object").with( {:command => "swift-ring-builder /etc/swift/object.builder rebalance 999", - :path => '/usr/bin', + :path => ['/usr/bin'], :refreshonly => true} )} end diff --git a/swift/spec/spec_helper_acceptance.rb b/swift/spec/spec_helper_acceptance.rb index 267c66d5f..714215432 100644 --- a/swift/spec/spec_helper_acceptance.rb +++ b/swift/spec/spec_helper_acceptance.rb @@ -28,13 +28,12 @@ # install library modules from the forge on host, puppet('module','install','puppetlabs-mysql'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','puppetlabs-concat','--version','1.2.2'), { :acceptable_exit_codes => 0 } + # pin apt module until openstack_extras use >= 2.0.0 version on host, puppet('module','install','puppetlabs-apt', '--version', '1.8.0'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','puppetlabs-inifile'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','puppetlabs-rsync'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','saz-memcached'), { :acceptable_exit_codes => 0 } on host, puppet('module','install','stahnma-epel'), { :acceptable_exit_codes => 0 } - # pin apt module until openstack_extras use >= 2.0.0 version - on host, puppet('module','install','puppetlabs-apt','--version','1.8.0'), { :acceptable_exit_codes => 0 } # install puppet modules from git, use master shell('git clone https://git.openstack.org/stackforge/puppet-openstacklib /etc/puppet/modules/openstacklib') diff --git a/tempest/.gitreview b/tempest/.gitreview index c0022930f..6db1d88c6 100644 --- a/tempest/.gitreview +++ b/tempest/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-tempest.git +project=openstack/puppet-tempest.git diff --git a/tempest/Gemfile b/tempest/Gemfile index 27df905bb..212eec887 100644 --- a/tempest/Gemfile +++ b/tempest/Gemfile @@ -1,7 +1,6 @@ source 'https://rubygems.org' group :development, :test do - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false @@ -16,7 +15,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/tempest/spec/acceptance/nodesets/nodepool-centos7.yml b/tempest/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/tempest/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/tempest/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/tempest/spec/acceptance/nodesets/nodepool-trusty.yml b/tempest/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/tempest/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/tempest/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/tripleo/.gitreview b/tripleo/.gitreview index fd60bc5a1..90b3af94c 100644 --- a/tripleo/.gitreview +++ b/tripleo/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-tripleo.git +project=openstack/puppet-tripleo.git diff --git a/tripleo/lib/puppet/parser/functions/interface_for_ip.rb b/tripleo/lib/puppet/parser/functions/interface_for_ip.rb new file mode 100644 index 000000000..1c6712035 --- /dev/null +++ b/tripleo/lib/puppet/parser/functions/interface_for_ip.rb @@ -0,0 +1,33 @@ +require 'ipaddr' + +# Custom function to lookup the interface which matches the subnet +# of the provided IP address. +# The function iterates over all the interfaces and chooses the +# first locally assigned interface which matches the IP. +module Puppet::Parser::Functions + newfunction(:interface_for_ip, :type => :rvalue, :doc => "Find the bind IP address for the provided subnet.") do |arg| + if arg[0].class == String + begin + ip_to_find = arg[0] + Dir.foreach('/sys/class/net/') do |interface| + next if interface == '.' or interface == '..' + iface_no_dash = interface.gsub('-', '_') + interface_ip = lookupvar("ipaddress_#{iface_no_dash}") + netmask = lookupvar("netmask_#{iface_no_dash}") + if not interface_ip.nil? then + ip1=IPAddr.new(interface_ip) + ip2=IPAddr.new(ip_to_find) + if ip1.mask(netmask) == ip2.mask(netmask) then + return interface + end + 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 + return '' + end +end diff --git a/tripleo/manifests/loadbalancer.pp b/tripleo/manifests/loadbalancer.pp index 6ded6765c..e94f44a00 100644 --- a/tripleo/manifests/loadbalancer.pp +++ b/tripleo/manifests/loadbalancer.pp @@ -66,6 +66,72 @@ # Can be a string or an array. # Defaults to undef # +# [*internal_api_virtual_ip*] +# Virtual IP on the internal API network. +# A string. +# Defaults to false +# +# [*storage_virtual_ip*] +# Virtual IP on the storage network. +# A string. +# Defaults to false +# +# [*storage_mgmt_virtual_ip*] +# Virtual IP on the storage mgmt network. +# A string. +# Defaults to false +# +# [*service_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the public API endpoints using the specified file. +# Any service-specific certificates take precedence over this one. +# Defaults to undef +# +# [*keystone_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Keystone public API endpoint using the specified file. +# Defaults to undef +# +# [*neutron_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Neutron public API endpoint using the specified file. +# Defaults to undef +# +# [*cinder_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Cinder public API endpoint using the specified file. +# Defaults to undef +# +# [*glance_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Glance public API endpoint using the specified file. +# Defaults to undef +# +# [*nova_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Nova public API endpoint using the specified file. +# Defaults to undef +# +# [*ceilometer_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Ceilometer public API endpoint using the specified file. +# Defaults to undef +# +# [*swift_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Swift public API endpoint using the specified file. +# Defaults to undef +# +# [*heat_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Heat public API endpoint using the specified file. +# Defaults to undef +# +# [*horizon_certificate*] +# Filename of an HAProxy-compatible certificate and key file +# When set, enables SSL on the Horizon public API endpoint using the specified file. +# Defaults to undef +# # [*galera_master_hostname*] # FQDN of the Galera master node # Defaults to undef @@ -155,12 +221,25 @@ $control_virtual_interface, $public_virtual_interface, $public_virtual_ip, + $internal_api_virtual_ip = false, + $storage_virtual_ip = false, + $storage_mgmt_virtual_ip = false, $manage_vip = true, $haproxy_service_manage = true, $haproxy_global_maxconn = 10000, $controller_host = undef, $controller_hosts = undef, $controller_hosts_names = undef, + $service_certificate = undef, + $keystone_certificate = undef, + $neutron_certificate = undef, + $cinder_certificate = undef, + $glance_certificate = undef, + $nova_certificate = undef, + $ceilometer_certificate = undef, + $swift_certificate = undef, + $heat_certificate = undef, + $horizon_certificate = undef, $galera_master_hostname = undef, $galera_master_ip = undef, $keystone_admin = false, @@ -240,6 +319,248 @@ track_script => ['haproxy'], priority => 101, } + + + if $internal_api_virtual_ip and $internal_api_virtual_ip != $control_virtual_interface { + $internal_api_virtual_interface = interface_for_ip($internal_api_virtual_ip) + # KEEPALIVE INTERNAL API NETWORK + keepalived::instance { '53': + interface => $internal_api_virtual_interface, + virtual_ips => [join([$internal_api_virtual_ip, ' dev ', $internal_api_virtual_interface])], + state => 'MASTER', + track_script => ['haproxy'], + priority => 101, + } + } + + if $storage_virtual_ip and $storage_virtual_ip != $control_virtual_interface { + $storage_virtual_interface = interface_for_ip($storage_virtual_ip) + # KEEPALIVE STORAGE NETWORK + keepalived::instance { '54': + interface => $storage_virtual_interface, + virtual_ips => [join([$storage_virtual_ip, ' dev ', $storage_virtual_interface])], + state => 'MASTER', + track_script => ['haproxy'], + priority => 101, + } + } + + if $storage_mgmt_virtual_ip and $storage_mgmt_virtual_ip != $control_virtual_interface { + $storage_mgmt_virtual_interface = interface_for_ip($storage_mgmt_virtual_ip) + # KEEPALIVE STORAGE MANAGEMENT NETWORK + keepalived::instance { '55': + interface => $storage_mgmt_virtual_interface, + virtual_ips => [join([$storage_mgmt_virtual_ip, ' dev ', $storage_mgmt_virtual_interface])], + state => 'MASTER', + track_script => ['haproxy'], + priority => 101, + } + } + + } + + if $keystone_certificate { + $keystone_bind_certificate = $keystone_certificate + } else { + $keystone_bind_certificate = $service_certificate + } + if $neutron_certificate { + $neutron_bind_certificate = $neutron_certificate + } else { + $neutron_bind_certificate = $service_certificate + } + if $cinder_certificate { + $cinder_bind_certificate = $cinder_certificate + } else { + $cinder_bind_certificate = $service_certificate + } + if $glance_certificate { + $glance_bind_certificate = $glance_certificate + } else { + $glance_bind_certificate = $service_certificate + } + if $nova_certificate { + $nova_bind_certificate = $nova_certificate + } else { + $nova_bind_certificate = $service_certificate + } + if $ceilometer_certificate { + $ceilometer_bind_certificate = $ceilometer_certificate + } else { + $ceilometer_bind_certificate = $service_certificate + } + if $swift_certificate { + $swift_bind_certificate = $swift_certificate + } else { + $swift_bind_certificate = $service_certificate + } + if $heat_certificate { + $heat_bind_certificate = $heat_certificate + } else { + $heat_bind_certificate = $service_certificate + } + if $horizon_certificate { + $horizon_bind_certificate = $horizon_certificate + } else { + $horizon_bind_certificate = $service_certificate + } + + $keystone_public_api_vip = hiera('keystone_public_api_vip', $controller_virtual_ip) + $keystone_admin_api_vip = hiera('keystone_admin_api_vip', $controller_virtual_ip) + if $keystone_bind_certificate { + $keystone_public_bind_opts = { + "${keystone_public_api_vip}:5000" => [], + "${public_virtual_ip}:13000" => ['ssl', 'crt', $keystone_bind_certificate], + } + $keystone_admin_bind_opts = { + "${keystone_admin_api_vip}:35357" => [], + "${public_virtual_ip}:13357" => ['ssl', 'crt', $keystone_bind_certificate], + } + } else { + $keystone_public_bind_opts = { + "${keystone_public_api_vip}:5000" => [], + "${public_virtual_ip}:5000" => [], + } + $keystone_admin_bind_opts = { + "${keystone_admin_api_vip}:35357" => [], + "${public_virtual_ip}:35357" => [], + } + } + + $neutron_api_vip = hiera('neutron_api_vip', $controller_virtual_ip) + if $neutron_bind_certificate { + $neutron_bind_opts = { + "${neutron_api_vip}:9696" => [], + "${public_virtual_ip}:13696" => ['ssl', 'crt', $neutron_bind_certificate], + } + } else { + $neutron_bind_opts = { + "${neutron_api_vip}:9696" => [], + "${public_virtual_ip}:9696" => [], + } + } + + $cinder_api_vip = hiera('cinder_api_vip', $controller_virtual_ip) + if $cinder_bind_certificate { + $cinder_bind_opts = { + "${cinder_api_vip}:8776" => [], + "${public_virtual_ip}:13776" => ['ssl', 'crt', $cinder_bind_certificate], + } + } else { + $cinder_bind_opts = { + "${cinder_api_vip}:8776" => [], + "${public_virtual_ip}:8776" => [], + } + } + + $glance_api_vip = hiera('glance_api_vip', $controller_virtual_ip) + if $glance_bind_certificate { + $glance_bind_opts = { + "${glance_api_vip}:9292" => [], + "${public_virtual_ip}:13292" => ['ssl', 'crt', $glance_bind_certificate], + } + } else { + $glance_bind_opts = { + "${glance_api_vip}:9292" => [], + "${public_virtual_ip}:9292" => [], + } + } + + $nova_api_vip = hiera('nova_api_vip', $controller_virtual_ip) + if $nova_bind_certificate { + $nova_osapi_bind_opts = { + "${nova_api_vip}:8774" => [], + "${public_virtual_ip}:13774" => ['ssl', 'crt', $nova_bind_certificate], + } + $nova_ec2_bind_opts = { + "${nova_api_vip}:8773" => [], + "${public_virtual_ip}:13773" => ['ssl', 'crt', $nova_bind_certificate], + } + $nova_novnc_bind_opts = { + "${nova_api_vip}:6080" => [], + "${public_virtual_ip}:13080" => ['ssl', 'crt', $nova_bind_certificate], + } + } else { + $nova_osapi_bind_opts = { + "${nova_api_vip}:8774" => [], + "${public_virtual_ip}:8774" => [], + } + $nova_ec2_bind_opts = { + "${nova_api_vip}:8773" => [], + "${public_virtual_ip}:8773" => [], + } + $nova_novnc_bind_opts = { + "${nova_api_vip}:6080" => [], + "${public_virtual_ip}:6080" => [], + } + } + + $ceilometer_api_vip = hiera('ceilometer_api_vip', $controller_virtual_ip) + if $ceilometer_bind_certificate { + $ceilometer_bind_opts = { + "${ceilometer_api_vip}:8777" => [], + "${public_virtual_ip}:13777" => ['ssl', 'crt', $ceilometer_bind_certificate], + } + } else { + $ceilometer_bind_opts = { + "${ceilometer_api_vip}:8777" => [], + "${public_virtual_ip}:8777" => [], + } + } + + $swift_proxy_vip = hiera('swift_proxy_vip', $controller_virtual_ip) + if $swift_bind_certificate { + $swift_bind_opts = { + "${swift_proxy_vip}:8080" => [], + "${public_virtual_ip}:13080" => ['ssl', 'crt', $swift_bind_certificate], + } + } else { + $swift_bind_opts = { + "${swift_proxy_vip}:8080" => [], + "${public_virtual_ip}:8080" => [], + } + } + + $heat_api_vip = hiera('heat_api_vip', $controller_virtual_ip) + if $heat_bind_certificate { + $heat_bind_opts = { + "${heat_api_vip}:8004" => [], + "${public_virtual_ip}:13004" => ['ssl', 'crt', $heat_bind_certificate], + } + $heat_cw_bind_opts = { + "${heat_api_vip}:8003" => [], + "${public_virtual_ip}:13003" => ['ssl', 'crt', $heat_bind_certificate], + } + $heat_cfn_bind_opts = { + "${heat_api_vip}:8000" => [], + "${public_virtual_ip}:13000" => ['ssl', 'crt', $heat_bind_certificate], + } + } else { + $heat_bind_opts = { + "${heat_api_vip}:8004" => [], + "${public_virtual_ip}:8004" => [], + } + $heat_cw_bind_opts = { + "${heat_api_vip}:8003" => [], + "${public_virtual_ip}:8003" => [], + } + $heat_cfn_bind_opts = { + "${heat_api_vip}:8000" => [], + "${public_virtual_ip}:8000" => [], + } + } + + $horizon_vip = hiera('horizon_vip', $controller_virtual_ip) + if $horizon_bind_certificate { + $horizon_bind_opts = { + "${horizon_vip}:80" => [], + "${public_virtual_ip}:443" => ['ssl', 'crt', $horizon_bind_certificate], + } + } else { + $horizon_bind_opts = { + "${horizon_vip}:80" => [], + "${public_virtual_ip}:80" => [], + } } sysctl::value { 'net.ipv4.ip_nonlocal_bind': value => '1' } @@ -275,8 +596,7 @@ if $keystone_admin { haproxy::listen { 'keystone_admin': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 35357, + bind => $keystone_admin_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -285,7 +605,7 @@ haproxy::balancermember { 'keystone_admin': listening_service => 'keystone_admin', ports => '35357', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('keystone_admin_api_node_ips',$controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -293,8 +613,7 @@ if $keystone_public { haproxy::listen { 'keystone_public': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 5000, + bind => $keystone_public_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -303,7 +622,7 @@ haproxy::balancermember { 'keystone_public': listening_service => 'keystone_public', ports => '5000', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('keystone_public_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -311,8 +630,7 @@ if $neutron { haproxy::listen { 'neutron': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 9696, + bind => $neutron_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -321,7 +639,7 @@ haproxy::balancermember { 'neutron': listening_service => 'neutron', ports => '9696', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('neutron_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -329,8 +647,7 @@ if $cinder { haproxy::listen { 'cinder': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8776, + bind => $cinder_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -339,7 +656,7 @@ haproxy::balancermember { 'cinder': listening_service => 'cinder', ports => '8776', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('cinder_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -347,8 +664,7 @@ if $glance_api { haproxy::listen { 'glance_api': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 9292, + bind => $glance_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -357,7 +673,7 @@ haproxy::balancermember { 'glance_api': listening_service => 'glance_api', ports => '9292', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('glance_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -365,7 +681,7 @@ if $glance_registry { haproxy::listen { 'glance_registry': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], + ipaddress => hiera('glance_registry_vip', $controller_virtual_ip), ports => 9191, options => { 'option' => [ 'httpchk GET /' ], @@ -375,7 +691,7 @@ haproxy::balancermember { 'glance_registry': listening_service => 'glance_registry', ports => '9191', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('glance_registry_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -383,8 +699,7 @@ if $nova_ec2 { haproxy::listen { 'nova_ec2': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8773, + bind => $nova_ec2_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -393,7 +708,7 @@ haproxy::balancermember { 'nova_ec2': listening_service => 'nova_ec2', ports => '8773', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('nova_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -401,8 +716,7 @@ if $nova_osapi { haproxy::listen { 'nova_osapi': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8774, + bind => $nova_osapi_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -411,7 +725,7 @@ haproxy::balancermember { 'nova_osapi': listening_service => 'nova_osapi', ports => '8774', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('nova_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -419,7 +733,7 @@ if $nova_metadata { haproxy::listen { 'nova_metadata': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], + ipaddress => hiera('nova_metadata_vip', $controller_virtual_ip), ports => 8775, options => { 'option' => [ 'httpchk GET /' ], @@ -429,7 +743,7 @@ haproxy::balancermember { 'nova_metadata': listening_service => 'nova_metadata', ports => '8775', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('nova_metadata_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -437,8 +751,7 @@ if $nova_novncproxy { haproxy::listen { 'nova_novncproxy': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 6080, + bind => $nova_novnc_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -447,7 +760,7 @@ haproxy::balancermember { 'nova_novncproxy': listening_service => 'nova_novncproxy', ports => '6080', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('nova_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -455,14 +768,13 @@ if $ceilometer { haproxy::listen { 'ceilometer': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8777, + bind => $ceilometer_bind_opts, collect_exported => false, } haproxy::balancermember { 'ceilometer': listening_service => 'ceilometer', ports => '8777', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('ceilometer_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => [], } @@ -470,8 +782,7 @@ if $swift_proxy_server { haproxy::listen { 'swift_proxy_server': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8080, + bind => $swift_bind_opts, options => { 'option' => [ 'httpchk GET /info' ], }, @@ -480,7 +791,7 @@ haproxy::balancermember { 'swift_proxy_server': listening_service => 'swift_proxy_server', ports => '8080', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('swift_proxy_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -488,8 +799,7 @@ if $heat_api { haproxy::listen { 'heat_api': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8004, + bind => $heat_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -498,7 +808,7 @@ haproxy::balancermember { 'heat_api': listening_service => 'heat_api', ports => '8004', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('heat_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -506,8 +816,7 @@ if $heat_cloudwatch { haproxy::listen { 'heat_cloudwatch': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8003, + bind => $heat_cw_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -516,7 +825,7 @@ haproxy::balancermember { 'heat_cloudwatch': listening_service => 'heat_cloudwatch', ports => '8003', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('heat_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -524,8 +833,7 @@ if $heat_cfn { haproxy::listen { 'heat_cfn': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 8000, + bind => $heat_cfn_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -534,7 +842,7 @@ haproxy::balancermember { 'heat_cfn': listening_service => 'heat_cfn', ports => '8000', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('heat_api_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -542,8 +850,7 @@ if $horizon { haproxy::listen { 'horizon': - ipaddress => [$controller_virtual_ip, $public_virtual_ip], - ports => 80, + bind => $horizon_bind_opts, options => { 'option' => [ 'httpchk GET /' ], }, @@ -552,7 +859,7 @@ haproxy::balancermember { 'horizon': listening_service => 'horizon', ports => '80', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('horizon_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -560,7 +867,7 @@ if $mysql { haproxy::listen { 'mysql': - ipaddress => [$controller_virtual_ip], + ipaddress => [hiera('mysql_vip', $controller_virtual_ip)], ports => 3306, options => { 'timeout' => [ 'client 0', 'server 0' ], @@ -576,7 +883,7 @@ options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } - $controller_hosts_without_galera_master = delete($controller_hosts_real, $galera_master_ip) + $controller_hosts_without_galera_master = delete(hiera('mysql_node_ips', $controller_hosts_real), $galera_master_ip) $controller_hosts_names_without_galera_master = delete($controller_hosts_names_real, downcase($galera_master_hostname)) haproxy::balancermember { 'mysql-backup': listening_service => 'mysql', @@ -589,7 +896,7 @@ if $rabbitmq { haproxy::listen { 'rabbitmq': - ipaddress => [$controller_virtual_ip], + ipaddress => [hiera('rabbitmq_vip', $controller_virtual_ip)], ports => 5672, options => { 'timeout' => [ 'client 0', 'server 0' ], @@ -599,7 +906,7 @@ haproxy::balancermember { 'rabbitmq': listening_service => 'rabbitmq', ports => '5672', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('rabbitmq_network', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } @@ -607,7 +914,7 @@ if $redis { haproxy::listen { 'redis': - ipaddress => [$controller_virtual_ip], + ipaddress => [hiera('redis_vip', $controller_virtual_ip)], ports => 6379, options => { 'timeout' => [ 'client 0', 'server 0' ], @@ -621,7 +928,7 @@ haproxy::balancermember { 'redis': listening_service => 'redis', ports => '6379', - ipaddresses => $controller_hosts_real, + ipaddresses => hiera('redis_node_ips', $controller_hosts_real), server_names => $controller_hosts_names_real, options => ['check', 'inter 2000', 'rise 2', 'fall 5'], } diff --git a/trove/.gitreview b/trove/.gitreview index b34cb118f..1887f9883 100644 --- a/trove/.gitreview +++ b/trove/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-trove.git +project=openstack/puppet-trove.git diff --git a/trove/Gemfile b/trove/Gemfile index 4c65317ac..3c0b87530 100644 --- a/trove/Gemfile +++ b/trove/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', '~> 2.1.0', :require => false - gem 'minitest', '~> 4.7', :require => 'minitest/unit' gem 'metadata-json-lint' gem 'puppet-lint-param-docs' @@ -17,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/trove/spec/acceptance/nodesets/nodepool-centos7.yml b/trove/spec/acceptance/nodesets/nodepool-centos7.yml index aed4f0b26..575ae6732 100644 --- a/trove/spec/acceptance/nodesets/nodepool-centos7.yml +++ b/trove/spec/acceptance/nodesets/nodepool-centos7.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/trove/spec/acceptance/nodesets/nodepool-trusty.yml b/trove/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/trove/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/trove/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/vcsrepo/spec/spec_helper_acceptance.rb b/vcsrepo/spec/spec_helper_acceptance.rb index 9ef826ae7..78074f742 100644 --- a/vcsrepo/spec/spec_helper_acceptance.rb +++ b/vcsrepo/spec/spec_helper_acceptance.rb @@ -3,7 +3,10 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = { :default_action => 'gem_install' } + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] || '3.8.1'), + } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end diff --git a/vswitch/.gitreview b/vswitch/.gitreview index a6aebfa3d..cc8799c95 100644 --- a/vswitch/.gitreview +++ b/vswitch/.gitreview @@ -1,4 +1,4 @@ [gerrit] host=review.openstack.org port=29418 -project=stackforge/puppet-vswitch.git +project=openstack/puppet-vswitch.git diff --git a/vswitch/Gemfile b/vswitch/Gemfile index 571fd65dc..3c0b87530 100644 --- a/vswitch/Gemfile +++ b/vswitch/Gemfile @@ -16,7 +16,7 @@ group :development, :test do gem 'puppet-lint-variable_contains_upcase' gem 'puppet-lint-numericvariable' - gem 'beaker-rspec', '~> 2.2.4', :require => false + gem 'beaker-rspec', :require => false gem 'json' gem 'webmock' end diff --git a/vswitch/spec/acceptance/basic_vswitch_spec.rb b/vswitch/spec/acceptance/basic_vswitch_spec.rb index 21b33bcbf..1d847e621 100644 --- a/vswitch/spec/acceptance/basic_vswitch_spec.rb +++ b/vswitch/spec/acceptance/basic_vswitch_spec.rb @@ -8,6 +8,23 @@ pp= <<-EOS Exec { logoutput => 'on_failure' } + case $::osfamily { + 'RedHat': { + class { '::openstack_extras::repo::redhat::redhat': + # Kilo is not GA yet, so let's use the testing repo + manage_rdo => false, + repo_hash => { + 'rdo-kilo-testing' => { + 'baseurl' => 'https://repos.fedorapeople.org/repos/openstack/openstack-kilo/testing/el7/', + # packages are not GA so not signed + 'gpgcheck' => '0', + 'priority' => 97, + }, + }, + } + } + } + include ::vswitch::ovs vs_bridge { 'br-beaker': diff --git a/vswitch/spec/acceptance/nodesets/nodepool-centos7.yml b/vswitch/spec/acceptance/nodesets/nodepool-centos7.yml new file mode 100644 index 000000000..575ae6732 --- /dev/null +++ b/vswitch/spec/acceptance/nodesets/nodepool-centos7.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-70-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor : none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/vswitch/spec/acceptance/nodesets/nodepool.yml b/vswitch/spec/acceptance/nodesets/nodepool-trusty.yml similarity index 89% rename from vswitch/spec/acceptance/nodesets/nodepool.yml rename to vswitch/spec/acceptance/nodesets/nodepool-trusty.yml index a2c1ecc63..a95d9f38d 100644 --- a/vswitch/spec/acceptance/nodesets/nodepool.yml +++ b/vswitch/spec/acceptance/nodesets/nodepool-trusty.yml @@ -7,3 +7,4 @@ HOSTS: ip: 127.0.0.1 CONFIG: type: foss + set_env: false diff --git a/vswitch/spec/spec_helper_acceptance.rb b/vswitch/spec/spec_helper_acceptance.rb index 4e69a9542..31ef2a552 100644 --- a/vswitch/spec/spec_helper_acceptance.rb +++ b/vswitch/spec/spec_helper_acceptance.rb @@ -27,6 +27,8 @@ # install library modules from the forge on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => 0 } + on host, puppet('module','install','stahnma-epel'), { :acceptable_exit_codes => 0 } + shell('git clone https://git.openstack.org/stackforge/puppet-openstack_extras /etc/puppet/modules/openstack_extras') # Install the module being tested puppet_module_install(:source => proj_root, :module_name => 'vswitch')