diff --git a/.fixtures.yml b/.fixtures.yml index 0025d9a..f712123 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,12 +1,13 @@ fixtures: repositories: apt: "git://github.com/puppetlabs/puppetlabs-apt" + translate: "git://github.com/puppetlabs/puppetlabs-translate" firewall: "git://github.com/puppetlabs/puppetlabs-firewall" inifile: "git://github.com/puppetlabs/puppetlabs-inifile" stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib" yumrepo_core: repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git puppet_version: ">= 6.0.0" mount_core: repo: https://github.com/puppetlabs/puppetlabs-mount_core.git puppet_version: ">= 6.0.0" diff --git a/.sync.yml b/.sync.yml index 33e96e8..fb6de51 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,3 +1,5 @@ --- .travis.yml: secure: "I/IK9bG88UOVll0hpuxluGp6IY5gicLaDHug/jGwfuWlN4R3coPAqWO/sGOyaEMbc9V5/Fw0H0ThQdYY3eI3rW5M4a1r9TSg/Z9d46JximPat/XvcpLvUc0G+QxCVhTRmYqD7u0wuX5VSric0PQU6KSjH84ZbKgAA8l04NGObgUI6ugjaNBhkaoIP3glYcHY1fgn5vwER2T/iiXZ5q3qDtYboR2GWLUODLWSpXWZRy7oYvp/RGTSe1fKjDwkbtrZiFvRoyzQvDhEAr+0MFDxJiOLdoKJFeBs6BrF2lyUJ6udlOmEYV94DfKoxEhhlZbxkPCh4SedT79i3c3xkKlf9wfAsEyGSTfc9OtyYBfoHcE9GMRZIvLf2Jn2mpHMO2694Fil4d7JdhLYQ/9Gv9VgFrYosQdVlDh+RxE2CXzrO39LhA1GeOY/n1r+DdvuCJs1fZfBZ1ORb7eQNp1BknurJ8FoYCKlEgihS223IJEnGueDdYkchMSRjS6C3a/HIzBz0RvEDGXD3WgrY5edRIaGziSoSr5eXzumK7N1FFBlpfY/7j38zI1ibWN4PRakmZppeeWOb1xiuVS5JkngCLoYerxLJEEjt8+klXhwnqqJukFuObaVsyprSWp+aAu/UHD/4w/6/lC6Elv+VzccLpITOR5b7VdAuCttQ5PGse6fits=" +spec/spec_helper.rb: + mock_with: ':mocha' diff --git a/Gemfile b/Gemfile index 9648d7d..b871c78 100644 --- a/Gemfile +++ b/Gemfile @@ -1,83 +1,86 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" def location_for(place, fake_version = nil) if place =~ /^(git[:@][^#]*)#(.*)/ [fake_version, { :git => $1, :branch => $2, :require => false }].compact elsif place =~ /^file:\/\/(.*)/ ['>= 0', { :path => File.expand_path($1), :require => false }] else [place, { :require => false }] end end group :test do gem 'puppetlabs_spec_helper', '>= 2.11.0', :require => false gem 'rspec-puppet-facts', '>= 1.8.0', :require => false gem 'rspec-puppet-utils', :require => false gem 'puppet-lint-leading_zero-check', :require => false gem 'puppet-lint-trailing_comma-check', :require => false gem 'puppet-lint-version_comparison-check', :require => false gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false gem 'puppet-lint-unquoted_string-check', :require => false gem 'puppet-lint-variable_contains_upcase', :require => false + gem 'puppet-lint-absolute_classname-check', :require => false + gem 'puppet-lint-topscope-variable-check', :require => false + gem 'puppet-lint-legacy_facts-check', :require => false gem 'metadata-json-lint', :require => false gem 'redcarpet', :require => false gem 'rubocop', '~> 0.49.1', :require => false if RUBY_VERSION >= '2.3.0' gem 'rubocop-rspec', '~> 1.15.0', :require => false if RUBY_VERSION >= '2.3.0' gem 'mocha', '~> 1.4.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2' gem 'parallel_tests', '2.24.0', :require => false if RUBY_VERSION < '2.2.0' gem 'parallel_tests', :require => false if RUBY_VERSION >= '2.2.0' end group :development do gem 'travis', :require => false gem 'travis-lint', :require => false gem 'guard-rake', :require => false gem 'overcommit', '>= 0.39.1', :require => false end group :system_tests do gem 'winrm', :require => false if beaker_version = ENV['BEAKER_VERSION'] gem 'beaker', *location_for(beaker_version) else gem 'beaker', '>= 4.2.0', :require => false end if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] gem 'beaker-rspec', *location_for(beaker_rspec_version) else gem 'beaker-rspec', :require => false end gem 'serverspec', :require => false gem 'beaker-hostgenerator', '>= 1.1.22', :require => false gem 'beaker-docker', :require => false gem 'beaker-puppet', :require => false gem 'beaker-puppet_install_helper', :require => false gem 'beaker-module_install_helper', :require => false gem 'rbnacl', '>= 4', :require => false if RUBY_VERSION >= '2.2.6' gem 'rbnacl-libsodium', :require => false if RUBY_VERSION >= '2.2.6' gem 'bcrypt_pbkdf', :require => false end group :release do gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator' if RUBY_VERSION >= '2.2.2' gem 'puppet-blacksmith', :require => false gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem' gem 'puppet-strings', '>= 1.0', :require => false end if facterversion = ENV['FACTER_GEM_VERSION'] gem 'facter', facterversion.to_s, :require => false, :groups => [:test] else gem 'facter', :require => false, :groups => [:test] end ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 5.0' : puppetversion = ENV['PUPPET_VERSION'].to_s gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/examples/alt_storage.pp b/examples/alt_storage.pp index 3fc7953..325b082 100644 --- a/examples/alt_storage.pp +++ b/examples/alt_storage.pp @@ -1,56 +1,56 @@ ############################################################################# # Specify different storage locations ############################################################################# # Cassandra pre-requisites include cassandra::datastax_repo include cassandra::java # Specify the storage locations $commitlog_directory = '/appdata/cassandra/commitlog' $data_file_directory = '/appdata/cassandra/data' $saved_caches_directory = '/appdata/cassandra/saved_caches' file { '/appdata': ensure => directory, mode => '0755', before => File['/appdata/cassandra'], } file { '/appdata/cassandra': ensure => directory, mode => '0755', before => Class['cassandra'], } # Create a cluster called MyCassandraCluster which uses the # GossipingPropertyFileSnitch. In this very basic example # the node itself becomes a seed for the cluster. class { 'cassandra': commitlog_directory => $commitlog_directory, data_file_directories => [$data_file_directory], saved_caches_directory => $saved_caches_directory, settings => { 'authenticator' => 'PasswordAuthenticator', 'cluster_name' => 'MyCassandraCluster', 'commitlog_sync' => 'periodic', 'commitlog_sync_period_in_ms' => 10000, 'endpoint_snitch' => 'GossipingPropertyFileSnitch', - 'listen_address' => $::ipaddress, + 'listen_address' => $facts['networking']['ip'], 'partitioner' => 'org.apache.cassandra.dht.Murmur3Partitioner', 'seed_provider' => [ { 'class_name' => 'org.apache.cassandra.locator.SimpleSeedProvider', 'parameters' => [ { - 'seeds' => $::ipaddress, + 'seeds' => $facts['networking']['ip'], }, ], }, ], 'start_native_transport' => true, }, service_ensure => running, require => Class['cassandra::datastax_repo', 'cassandra::java'], } diff --git a/examples/getting_started.pp b/examples/getting_started.pp index e2698ab..e42d8f5 100644 --- a/examples/getting_started.pp +++ b/examples/getting_started.pp @@ -1,198 +1,197 @@ ############################################################################# # This is for placing in the getting started section of the README file. ############################################################################# # Install Cassandra 2.2.5 onto a system and create a basic keyspace, table # and index. The node itself becomes a seed for the cluster. # # Tested on CentOS 7 ############################################################################# # Cassandra pre-requisites require cassandra::datastax_repo require cassandra::system::sysctl require cassandra::system::transparent_hugepage require cassandra::java class { 'cassandra::system::swapoff': device => '/dev/mapper/centos-swap', before => Class['cassandra'], } # Create a cluster called MyCassandraCluster which uses the # GossipingPropertyFileSnitch. In this very basic example # the node itself becomes a seed for the cluster. class { 'cassandra': commitlog_directory => '/var/lib/cassandra/commitlog', data_file_directories => ['/var/lib/cassandra/data'], hints_directory => '/var/lib/cassandra/hints', package_name => 'cassandra30', saved_caches_directory => '/var/lib/cassandra/saved_caches', settings => { 'authenticator' => 'PasswordAuthenticator', 'authorizer' => 'CassandraAuthorizer', 'cluster_name' => 'MyCassandraCluster', 'commitlog_sync' => 'periodic', 'commitlog_sync_period_in_ms' => 10000, 'endpoint_snitch' => 'GossipingPropertyFileSnitch', - 'listen_address' => $::ipaddress, + 'listen_address' => $facts['networking']['ip'], 'partitioner' => 'org.apache.cassandra.dht.Murmur3Partitioner', 'seed_provider' => [ { 'class_name' => 'org.apache.cassandra.locator.SimpleSeedProvider', 'parameters' => [ { - 'seeds' => $::ipaddress, + 'seeds' => $facts['networking']['ip'], }, ], }, ], 'start_native_transport' => true, }, service_ensure => running, require => Class['cassandra::datastax_repo', 'cassandra::system::sysctl', 'cassandra::java'], } class { 'cassandra::datastax_agent': settings => { 'agent_alias' => { 'setting' => 'agent_alias', 'value' => 'foobar', }, 'stomp_interface' => { 'setting' => 'stomp_interface', 'value' => 'localhost', }, 'async_pool_size' => { 'ensure' => absent, }, }, require => Class['cassandra'], } class { 'cassandra::optutils': package_name => 'cassandra30-tools', require => Class['cassandra'], } class { 'cassandra::schema': cqlsh_password => 'cassandra', cqlsh_user => 'cassandra', - cqlsh_host => $::ipaddress, + cqlsh_host => $facts['networking']['ip'], indexes => { 'users_lname_idx' => { table => 'users', keys => 'lname', keyspace => 'mykeyspace', }, }, keyspaces => { 'mykeyspace' => { durable_writes => false, replication_map => { keyspace_class => 'SimpleStrategy', replication_factor => 1, }, }, }, permissions => { 'Grant select permissions to spillman to all keyspaces' => { permission_name => 'SELECT', user_name => 'spillman', }, 'Grant modify to to keyspace mykeyspace to akers' => { keyspace_name => 'mykeyspace', permission_name => 'MODIFY', user_name => 'akers', }, 'Grant alter permissions to mykeyspace to boone' => { keyspace_name => 'mykeyspace', permission_name => 'ALTER', user_name => 'boone', }, 'Grant ALL permissions to mykeyspace.users to gbennet' => { keyspace_name => 'mykeyspace', permission_name => 'ALTER', table_name => 'users', user_name => 'gbennet', }, }, tables => { 'users' => { columns => { user_id => 'int', fname => 'text', lname => 'text', 'PRIMARY KEY' => '(user_id)', }, keyspace => 'mykeyspace', }, }, users => { 'spillman' => { password => 'Niner27', }, 'akers' => { password => 'Niner2', superuser => true, }, 'boone' => { password => 'Niner75', }, 'gbennet' => { 'password' => 'foobar', }, 'lucan' => { 'ensure' => absent, }, }, } - -if $::memorysize_mb < 24576.0 { - $max_heap_size_in_mb = floor($::memorysize_mb / 2) -} elsif $::memorysize_mb < 8192.0 { - $max_heap_size_in_mb = floor($::memorysize_mb / 4) +if ($facts['memory']['system']['total_bytes'] / (1024*1024)) < 24576.0 { + $max_heap_size_in_mb = floor(($facts['memory']['system']['total_bytes'] / (1024*1024)) / 2) +} elsif ($facts['memory']['system']['total_bytes'] / (1024*1024)) < 8192.0 { + $max_heap_size_in_mb = floor(($facts['memory']['system']['total_bytes'] / (1024*1024)) / 4) } else { $max_heap_size_in_mb = 8192 } -$heap_new_size = $::processorcount * 100 +$heap_new_size = $facts['processors']['count'] * 100 cassandra::file { "Set Java/Cassandra max heap size to ${max_heap_size_in_mb}.": file => 'cassandra-env.sh', file_lines => { 'MAX_HEAP_SIZE' => { line => "MAX_HEAP_SIZE='${max_heap_size_in_mb}M'", match => '^#?MAX_HEAP_SIZE=.*', }, }, } cassandra::file { "Set Java/Cassandra heap new size to ${heap_new_size}.": file => 'cassandra-env.sh', file_lines => { 'HEAP_NEWSIZE' => { line => "HEAP_NEWSIZE='${heap_new_size}M'", match => '^#?HEAP_NEWSIZE=.*', }, }, } $tmpdir = '/var/lib/cassandra/tmp' file { $tmpdir: ensure => directory, owner => 'cassandra', group => 'cassandra', require => Package['cassandra'], } cassandra::file { 'Set java.io.tmpdir': file => 'jvm.options', file_lines => { 'java.io.tmpdir' => { line => "-Djava.io.tmpdir=${tmpdir}", }, }, require => File[$tmpdir], } diff --git a/examples/single_dc.pp b/examples/single_dc.pp index 06bec90..d0a3580 100644 --- a/examples/single_dc.pp +++ b/examples/single_dc.pp @@ -1,35 +1,35 @@ # Cassandra pre-requisites include cassandra::datastax_repo include cassandra::java class { 'cassandra': package_name => 'cassandra30', settings => { 'authenticator' => 'AllowAllAuthenticator', 'auto_bootstrap' => false, 'cluster_name' => 'MyCassandraCluster', 'commitlog_directory' => '/var/lib/cassandra/commitlog', 'commitlog_sync' => 'periodic', 'commitlog_sync_period_in_ms' => 10000, 'data_file_directories' => ['/var/lib/cassandra/data'], 'endpoint_snitch' => 'GossipingPropertyFileSnitch', 'hints_directory' => '/var/lib/cassandra/hints', 'listen_interface' => 'eth1', 'num_tokens' => 256, 'partitioner' => 'org.apache.cassandra.dht.Murmur3Partitioner', 'saved_caches_directory' => '/var/lib/cassandra/saved_caches', 'seed_provider' => [ { 'class_name' => 'org.apache.cassandra.locator.SimpleSeedProvider', 'parameters' => [ { - 'seeds' => $::ipaddress, + 'seeds' => $facts['networking']['ip'], }, ], }, ], 'start_native_transport' => true, }, service_ensure => running, require => Class['cassandra::datastax_repo', 'cassandra::java'], } diff --git a/examples/system_settings.pp b/examples/system_settings.pp index 11047c0..2cc0d32 100644 --- a/examples/system_settings.pp +++ b/examples/system_settings.pp @@ -1,26 +1,26 @@ # Cassandra pre-requisites require cassandra::datastax_repo require cassandra::system::transparent_hugepage -case "${::operatingsystem}-${operatingsystemmajrelease}" { +case "${facts['os']['name']}-${operatingsystemmajrelease}" { 'CentOS-6': { $device = '/dev/mapper/VolGroup-lv_swap' $sysctl_args = '-e -p' } 'CentOS-7': { $device = '/dev/mapper/centos-swap' } default: {} } class { 'cassandra::system::swapoff': device => $device, } if $sysctl_args { class { 'cassandra::system::sysctl': sysctl_args => $sysctl_args, } } else { require cassandra::system::sysctl } diff --git a/manifests/apache_repo.pp b/manifests/apache_repo.pp index 0f1be42..b25595c 100644 --- a/manifests/apache_repo.pp +++ b/manifests/apache_repo.pp @@ -1,85 +1,85 @@ # An optional class that will allow a suitable repository to be configured # from which packages for Apache Cassandra can be downloaded. # @param descr [string] On the Red Hat family, this is passed as the `descr` # attribute to a `yumrepo` resource. On the Debian family, it is passed as # the `comment` attribute to an `apt::source` resource. # @param key_id [string] On the Debian family, this is passed as the `id` # attribute to an `apt::key` resource. On the Red Hat family, it is # ignored. # @param key_url [string] On the Debian family, this is passed as the # `source` attribute to an `apt::key` resource. On the Red Hat family, # it is set to the `gpgkey` attribute on the `yumrepo` resource. # @param pkg_url [string] On the Red Hat family, leaving this as default will # set the `baseurl` on the `yumrepo` resource to # 'http://www.apache.org/dist/cassandra/redhat' with whatever is set in the # 'release' attribute appended. # On the Debian family, leaving this as the default # will set the `location` attribute on an `apt::source` to # 'http://www.apache.org/dist/cassandra/debian'. # @param release [string] On the Debian family, this is passed as the `release` # attribute to an `apt::source` resource. On the Red Hat family, it is the # major version number of Cassandra, without dot, and with an appended 'x' # (e.g. '311x') class cassandra::apache_repo ( $descr = 'Repo for Apache Cassandra', $key_id = 'A26E528B271F19B9E5D8E19EA278B781FE4B2BDA', $key_url = 'https://www.apache.org/dist/cassandra/KEYS', $pkg_url = undef, $release = 'main', ) { - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { if $pkg_url != undef { $baseurl = $pkg_url } else { $url = 'http://www.apache.org/dist/cassandra/redhat' $baseurl = "${url}/${release}" } yumrepo { 'cassandra_apache': ensure => present, descr => $descr, baseurl => $baseurl, enabled => 1, gpgcheck => 1, gpgkey => $key_url, } } 'Debian': { include apt include apt::update apt::key {'apache.cassandra': id => $key_id, source => $key_url, before => Apt::Source['cassandra.sources'], } if $pkg_url != undef { $location = $pkg_url } else { $location = 'http://www.apache.org/dist/cassandra/debian' } apt::source {'cassandra.sources': location => $location, comment => $descr, release => $release, include => { 'src' => false, }, notify => Exec['update-apache-cassandra-repo'], } # Required to wrap apt_update exec {'update-apache-cassandra-repo': refreshonly => true, command => '/bin/true', require => Exec['apt_update'], } } default: { - warning("OS family ${::osfamily} not supported") + warning("OS family ${facts['os']['family']} not supported") } } } diff --git a/manifests/datastax_agent.pp b/manifests/datastax_agent.pp index 8f8cd60..8343d47 100644 --- a/manifests/datastax_agent.pp +++ b/manifests/datastax_agent.pp @@ -1,120 +1,120 @@ # A class for installing the DataStax Agent and to point it at an OpsCenter # instance. # # @param address_config_file The full path to the address config file. # @param defaults_file The full path name to the file where `java_home` is set. # @param java_home If the value of this variable is left as *undef*, no # action is taken. Otherwise the value is set as JAVA_HOME in # `defaults_file`. # @param package_ensure Is passed to the package reference. Valid values are # **present** or a version number. # @param package_name Is passed to the package reference. # @param service_ensure Is passed to the service reference. # @param service_enable Is passed to the service reference. # @param service_name Is passed to the service reference. # @param service_provider The name of the provider that runs the service. # If left as *undef* then the OS family specific default will be used, # otherwise the specified value will be used instead. # @param settings A hash that is passed to # [create_ini_settings] # (https://github.com/puppetlabs/puppetlabs-inifile#function-create_ini_settings) # with the following additional defaults: # # ```puppet # { # path => $address_config_file, # key_val_separator => ': ', # require => Package[$package_name], # notify => Service['datastax-agent'], # } # ``` # # @example Set agent_alias to foobar, stomp_interface to localhost and ensure that async_pool_size is absent from the file. # class { 'cassandra::datastax_agent': # settings => { # 'agent_alias' => { # 'setting' => 'agent_alias', # 'value' => 'foobar', # }, # 'stomp_interface' => { # 'setting' => 'stomp_interface', # 'value' => 'localhost', # }, # 'async_pool_size' => { # 'ensure' => absent, # }, # }, # } class cassandra::datastax_agent ( $address_config_file = '/var/lib/datastax-agent/conf/address.yaml', $defaults_file = '/etc/default/datastax-agent', $java_home = undef, $package_ensure = 'present', $package_name = 'datastax-agent', $service_ensure = 'running', $service_enable = true, $service_name = 'datastax-agent', $service_provider = undef, $settings = {}, ) inherits cassandra::params { - require '::cassandra' + require 'cassandra' if $service_provider != undef { System { provider => $service_provider, } } package { $package_name: ensure => $package_ensure, require => Class['cassandra'], notify => Exec['datastax_agent_reload_systemctl'], } exec { 'datastax_agent_reload_systemctl': - command => "${::cassandra::params::systemctl} daemon-reload", - onlyif => "test -x ${::cassandra::params::systemctl}", + command => "${cassandra::params::systemctl} daemon-reload", + onlyif => "test -x ${cassandra::params::systemctl}", path => ['/usr/bin', '/bin'], refreshonly => true, notify => Service['datastax-agent'], } file { $address_config_file: owner => 'cassandra', group => 'cassandra', mode => '0644', require => Package[$package_name], } if $java_home != undef { ini_setting { 'java_home': ensure => present, path => $defaults_file, section => '', key_val_separator => '=', setting => 'JAVA_HOME', value => $java_home, notify => Service['datastax-agent'], } } service { 'datastax-agent': ensure => $service_ensure, enable => $service_enable, name => $service_name, } if $settings { $defaults = { path => $address_config_file, key_val_separator => ': ', require => Package[$package_name], notify => Service['datastax-agent'], } $full_settings = { '' => $settings, } create_ini_settings($full_settings, $defaults) } } diff --git a/manifests/datastax_repo.pp b/manifests/datastax_repo.pp index 56c9980..729df81 100644 --- a/manifests/datastax_repo.pp +++ b/manifests/datastax_repo.pp @@ -1,82 +1,82 @@ # An optional class that will allow a suitable repository to be configured # from which packages for DataStax Community can be downloaded. Changing # the defaults will allow any Debian Apt or Red Hat Yum repository to be # configured. # @param descr [string] On the Red Hat family, this is passed as the `descr` # attribute to a `yumrepo` resource. On the Debian family, it is passed as # the `comment` attribute to an `apt::source` resource. # @param key_id [string] On the Debian family, this is passed as the `id` # attribute to an `apt::key` resource. On the Red Hat family, it is # ignored. # @param key_url [string] On the Debian family, this is passed as the # `source` attribute to an `apt::key` resource. On the Red Hat family, # it is ignored. # @param pkg_url [string] If left as the default, this will set the `baseurl` # to 'http://rpm.datastax.com/community' on a `yumrepo` resource # on the Red Hat family. On the Debian family, leaving this as the default # will set the `location` attribute on an `apt::source` to # 'http://debian.datastax.com/community'. # @param release [string] On the Debian family, this is passed as the `release` # attribute to an `apt::source` resource. On the Red Hat family, it is # ignored. class cassandra::datastax_repo ( $descr = 'DataStax Repo for Apache Cassandra', $key_id = '7E41C00F85BFC1706C4FFFB3350200F2B999A372', $key_url = 'http://debian.datastax.com/debian/repo_key', $pkg_url = undef, $release = 'stable', ) { - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { if $pkg_url != undef { $baseurl = $pkg_url } else { $baseurl = 'http://rpm.datastax.com/community' } yumrepo { 'datastax': ensure => present, descr => $descr, baseurl => $baseurl, enabled => 1, gpgcheck => 0, } } 'Debian': { include apt include apt::update apt::key {'datastaxkey': id => $key_id, source => $key_url, before => Apt::Source['datastax'], } if $pkg_url != undef { $location = $pkg_url } else { $location = 'http://debian.datastax.com/community' } apt::source {'datastax': location => $location, comment => $descr, release => $release, include => { 'src' => false, }, notify => Exec['update-cassandra-repos'], } # Required to wrap apt_update exec {'update-cassandra-repos': refreshonly => true, command => '/bin/true', require => Exec['apt_update'], } } default: { - warning("OS family ${::osfamily} not supported") + warning("OS family ${facts['os']['family']} not supported") } } } diff --git a/manifests/file.pp b/manifests/file.pp index c35b9b3..0a6698d 100644 --- a/manifests/file.pp +++ b/manifests/file.pp @@ -1,85 +1,85 @@ # A defined type for altering files relative to the configuration directory. # @param file [string] The name of the file relative to the `config_path`. # @param config_path [string] The path to the configuration directory. # @param file_lines [string] If set, then the [create_resources] # (https://docs.puppet.com/puppet/latest/reference/function.html#createresources) # will be used to create an array of [file_line] # (https://forge.puppet.com/puppetlabs/stdlib#file_line) resources. # @param service_refresh [boolean] Is the Cassandra service is to be notified # if the environment file is changed. # @example # if $::memorysize_mb < 24576.0 { # $max_heap_size_in_mb = floor($::memorysize_mb / 2) # } elsif $::memorysize_mb < 8192.0 { # $max_heap_size_in_mb = floor($::memorysize_mb / 4) # } else { # $max_heap_size_in_mb = 8192 # } # # $heap_new_size = $::processorcount * 100 # # cassandra::file { "Set Java/Cassandra max heap size to ${max_heap_size_in_mb}.": # file => 'cassandra-env.sh', # file_lines => { # 'MAX_HEAP_SIZE' => { # line => "MAX_HEAP_SIZE='${max_heap_size_in_mb}M'", # match => '^#?MAX_HEAP_SIZE=.*', # }, # } # } # # cassandra::file { "Set Java/Cassandra heap new size to ${heap_new_size}.": # file => 'cassandra-env.sh', # file_lines => { # 'HEAP_NEWSIZE' => { # line => "HEAP_NEWSIZE='${heap_new_size}M'", # match => '^#?HEAP_NEWSIZE=.*', # } # } # } # $tmpdir = '/var/lib/cassandra/tmp' # # file { $tmpdir: # ensure => directory, # owner => 'cassandra', # group => 'cassandra', # } # # cassandra::file { 'Set java.io.tmpdir': # file => 'jvm.options', # file_lines => { # 'java.io.tmpdir' => { # line => "-Djava.io.tmpdir=${tmpdir}", # }, # }, # require => File[$tmpdir], # } define cassandra::file( $file = $title, - $config_path = $::cassandra::config_path, + $config_path = $cassandra::config_path, $file_lines = undef, $service_refresh = true, ) { include cassandra include cassandra::params include stdlib $path = "${config_path}/${file}" if $file_lines != undef { if $service_refresh { $default_file_line = { path => $path, require => Package['cassandra'], notify => Service['cassandra'], } } else { $default_file_line = { path => $path, require => Package['cassandra'], } } create_resources(file_line, $file_lines, $default_file_line) } } diff --git a/manifests/init.pp b/manifests/init.pp index 06c4b3f..820f795 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,390 +1,390 @@ # A class for installing the Cassandra package and manipulate settings in the # configuration file. # # @param baseline_settings [hash] If set, this is a baseline of settings that # are merged with the `settings` hash. The values of the `settings` # hash overriding the values in this hash. This is most useful when used # with hiera. # @param cassandra_2356_sleep_seconds [boolean] # This will provide a workaround for # [CASSANDRA-2356](https://issues.apache.org/jira/browse/CASSANDRA-2356) by # sleeping for the specifed number of seconds after an event involving the # Cassandra package. This option is silently ignored on the Red Hat family # of operating systems as this bug only affects Debian systems. # @param cassandra_9822 [boolean] If set to true, this will apply a patch to the init # file for the Cassandra service as a workaround for # [CASSANDRA-9822](https://issues.apache.org/jira/browse/CASSANDRA-9822). # This this bug only affects Debian systems. # @param cassandra_yaml_tmpl [string] The path to the Puppet template for the # Cassandra configuration file. This allows the user to supply their own # customized template.` # @param commitlog_directory [string] The path to the commitlog directory. # If set, the directory will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. # @param commitlog_directory_mode [string] The mode for the # `commitlog_directory` is ignored unless `commitlog_directory` is # specified. # @param manage_config_file [boolean] Whether or not to manage the cassandra configuration # file. # @param config_file_mode [string] The permissions mode of the cassandra configuration # file. # @param config_path [string] The path to the cassandra configuration file. # @param data_file_directories [array] The path(s) to the date directory or # directories. # If set, the directories will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. # @param data_file_directories_mode [string] The mode for the # `data_file_directories` is ignored unless `data_file_directories` is # specified. # @param dc [string] Sets the value for dc in *config_path*/*snitch_properties_file* # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. # @param dc_suffix [string] Sets the value for dc_suffix in # *config_path*/*snitch_properties_file* see # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. If the value is *undef* then no change will be made to # the snitch properties file for this setting. # @param fail_on_non_supported_os [boolean] A flag that dictates if the module should # fail if it is not RedHat or Debian. If you set this option to false then # you must also at least set the `config_path` attribute as well. # @param hints_directory [string] The path to the hints directory. # If set, the directory will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. Do not set this option in Cassandra versions before 3.0.0. # @param hints_directory_mode [string] The mode for the # `hints_directory` is ignored unless `hints_directory` is # specified. # @param package_ensure [present|latest|string] The status of the package specified in # **package_name**. Can be *present*, *latest* or a specific version # number. # @param package_name [string] The name of the Cassandra package which must be available # from a repository. # @param prefer_local [boolean] Sets the value for prefer_local in # *config_path*/*snitch_properties_file* see # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. Valid values are true, false or *undef*. If the value # is *undef* then change will be made to the snitch properties file for # this setting. # @param rack [string] Sets the value for rack in # *config_path*/*snitch_properties_file* see # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. # @param rackdc_tmpl [string] The template for creating the snitch properties file. # @param saved_caches_directory [string] The path to the saved caches directory. # If set, the directory will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. # @param saved_caches_directory_mode [string] The mode for the # `saved_caches_directory` is ignored unless `saved_caches_directory` is # specified. # @param service_enable [boolean] enable the Cassandra service to start at boot time. # @param service_ensure [string] Ensure the Cassandra service is running. Valid values # are running or stopped. # @param service_name [string] The name of the service that runs the Cassandra software. # @param service_provider [string] The name of the provider that runs the service. # If left as *undef* then the OS family specific default will # be used, otherwise the specified value will be used instead. # @param service_refresh [boolean] If set to true, changes to the Cassandra config file # or the data directories will ensure that Cassandra service is refreshed # after the changes. Setting this flag to false will disable this # behaviour, therefore allowing the changes to be made but allow the user # to control when the service is restarted. # @param settings [hash] A hash that is passed to `to_yaml` which dumps the results # to the Cassandra configuring file. The minimum required settings for # Cassandra 2.X are as follows: # # ```puppet # { # 'authenticator' => 'PasswordAuthenticator', # 'cluster_name' => 'MyCassandraCluster', # 'commitlog_directory' => '/var/lib/cassandra/commitlog', # 'commitlog_sync' => 'periodic', # 'commitlog_sync_period_in_ms' => 10000, # 'data_file_directories' => ['/var/lib/cassandra/data'], # 'endpoint_snitch' => 'GossipingPropertyFileSnitch', # 'listen_address' => $::ipaddress, # 'partitioner' => 'org.apache.cassandra.dht.Murmur3Partitioner', # 'saved_caches_directory' => '/var/lib/cassandra/saved_caches', # 'seed_provider' => [ # { # 'class_name' => 'org.apache.cassandra.locator.SimpleSeedProvider', # 'parameters' => [ # { # 'seeds' => $::ipaddress, # }, # ], # }, # ], # 'start_native_transport' => true, # } # ``` # For Cassandra 3.X you will also need to specify the `hints_directory` # attribute. # @param snitch_properties_file [string] The name of the snitch properties file. The # full path name would be *config_path*/*snitch_properties_file*. # @param systemctl [string] The full path to the systemctl command. Only # needed when the package is installed. Will silently continue if the # executable does not exist. class cassandra ( $baseline_settings = {}, $cassandra_2356_sleep_seconds = 5, $cassandra_9822 = false, $cassandra_yaml_tmpl = 'cassandra/cassandra.yaml.erb', $commitlog_directory = undef, $commitlog_directory_mode = '0750', Boolean $manage_config_file = true, $config_file_mode = '0644', - $config_path = $::cassandra::params::config_path, + $config_path = $cassandra::params::config_path, $data_file_directories = undef, $data_file_directories_mode = '0750', $dc = 'DC1', $dc_suffix = undef, $fail_on_non_supported_os = true, $hints_directory = undef, $hints_directory_mode = '0750', $package_ensure = 'present', - $package_name = $::cassandra::params::cassandra_pkg, + $package_name = $cassandra::params::cassandra_pkg, $prefer_local = undef, $rack = 'RAC1', $rackdc_tmpl = 'cassandra/cassandra-rackdc.properties.erb', $saved_caches_directory = undef, $saved_caches_directory_mode = '0750', $service_enable = true, $service_ensure = undef, $service_name = 'cassandra', $service_provider = undef, $service_refresh = true, $settings = {}, $snitch_properties_file = 'cassandra-rackdc.properties', - $systemctl = $::cassandra::params::systemctl, + $systemctl = $cassandra::params::systemctl, ) inherits cassandra::params { if $service_provider != undef { Service { provider => $service_provider, } } $config_file = "${config_path}/cassandra.yaml" $dc_rack_properties_file = "${config_path}/${snitch_properties_file}" - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { $config_file_require = Package['cassandra'] $config_file_before = [] $config_path_require = Package['cassandra'] $dc_rack_properties_file_require = Package['cassandra'] $dc_rack_properties_file_before = [] $data_dir_require = Package['cassandra'] $data_dir_before = [] - if $::operatingsystemmajrelease == '7' and $::cassandra::service_provider == 'init' { + if $facts['os']['release']['major'] == '7' and $cassandra::service_provider == 'init' { exec { "/sbin/chkconfig --add ${service_name}": unless => "/sbin/chkconfig --list ${service_name}", require => Package['cassandra'], before => Service['cassandra'], } } } 'Debian': { $config_file_require = [ User['cassandra'], File[$config_path] ] $config_file_before = Package['cassandra'] $config_path_require = [] $dc_rack_properties_file_require = [ User['cassandra'], File[$config_path] ] $dc_rack_properties_file_before = Package['cassandra'] $data_dir_require = File[$config_file] $data_dir_before = Package['cassandra'] if $cassandra_9822 { file { '/etc/init.d/cassandra': source => 'puppet:///modules/cassandra/CASSANDRA-9822/cassandra', mode => '0555', before => Package['cassandra'], } } # Sleep after package install and before service resource to prevent # possible duplicate processes arising from CASSANDRA-2356. exec { 'CASSANDRA-2356 sleep': command => "/bin/sleep ${cassandra_2356_sleep_seconds}", refreshonly => true, user => 'root', subscribe => Package['cassandra'], before => Service['cassandra'], } group { 'cassandra': ensure => present, } $user = 'cassandra' user { $user: ensure => present, comment => 'Cassandra database,,,', gid => 'cassandra', home => '/var/lib/cassandra', shell => '/bin/false', managehome => true, require => Group['cassandra'], } # End of CASSANDRA-2356 specific resources. } default: { $config_file_before = [ Package['cassandra'] ] $config_file_require = [] $config_path_require = [] $dc_rack_properties_file_require = Package['cassandra'] $dc_rack_properties_file_before = [] if $fail_on_non_supported_os { - fail("OS family ${::osfamily} not supported") + fail("OS family ${facts['os']['family']} not supported") } else { - warning("OS family ${::osfamily} not supported") + warning("OS family ${facts['os']['family']} not supported") } } } package { 'cassandra': ensure => $package_ensure, name => $package_name, notify => Exec['cassandra_reload_systemctl'], } exec { 'cassandra_reload_systemctl': command => "${systemctl} daemon-reload", onlyif => "test -x ${systemctl}", path => ['/usr/bin', '/bin'], refreshonly => true, } file { $config_path: ensure => directory, group => 'cassandra', owner => 'cassandra', mode => '0755', require => $config_path_require, } if $commitlog_directory { file { $commitlog_directory: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $commitlog_directory_mode, require => $data_dir_require, before => $data_dir_before, } $commitlog_directory_settings = merge($settings, { 'commitlog_directory' => $commitlog_directory, }) } else { $commitlog_directory_settings = $settings } if is_array($data_file_directories) { file { $data_file_directories: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $data_file_directories_mode, require => $data_dir_require, before => $data_dir_before, } $data_file_directories_settings = merge($settings, { 'data_file_directories' => $data_file_directories, }) } else { $data_file_directories_settings = $settings } if $hints_directory { file { $hints_directory: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $hints_directory_mode, require => $data_dir_require, before => $data_dir_before, } $hints_directory_settings = merge($settings, { 'hints_directory' => $hints_directory, }) } else { $hints_directory_settings = $settings } if $saved_caches_directory { file { $saved_caches_directory: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $saved_caches_directory_mode, require => $data_dir_require, before => $data_dir_before, } $saved_caches_directory_settings = merge($settings, { 'saved_caches_directory' => $saved_caches_directory, }) } else { $saved_caches_directory_settings = $settings } $merged_settings = merge($baseline_settings, $settings, $commitlog_directory_settings, $data_file_directories_settings, $hints_directory_settings, $saved_caches_directory_settings) if $manage_config_file { file { $config_file: ensure => present, owner => 'cassandra', group => 'cassandra', content => template($cassandra_yaml_tmpl), mode => $config_file_mode, require => $config_file_require, before => $config_file_before, } $service_dependencies = [ File[$config_file], File[$dc_rack_properties_file], Package['cassandra'], ] } else { $service_dependencies = [ File[$dc_rack_properties_file], Package['cassandra'], ] } file { $dc_rack_properties_file: ensure => file, content => template($rackdc_tmpl), owner => 'cassandra', group => 'cassandra', mode => '0644', require => $dc_rack_properties_file_require, before => $dc_rack_properties_file_before, } if $package_ensure != 'absent' and $package_ensure != 'purged' { if $service_refresh { service { 'cassandra': ensure => $service_ensure, name => $service_name, enable => $service_enable, subscribe => $service_dependencies, } } else { service { 'cassandra': ensure => $service_ensure, name => $service_name, enable => $service_enable, require => $service_dependencies, } } } } diff --git a/manifests/java.pp b/manifests/java.pp index 92ec02c..78fe95c 100644 --- a/manifests/java.pp +++ b/manifests/java.pp @@ -1,66 +1,67 @@ # A class to install Java and JNA packages. # @param aptkey [hash] If supplied, this should be a hash of `apt::key` # resources that will be passed to the create_resources function. # This is ignored on non-Debian systems. # @param aptsource [hash] If supplied, this should be a hash of # `apt::source` resources that will be passed to the create_resources # function. This is ignored on non-Red Hat` # @param jna_ensure [string] Is passed to the package reference for the JNA # package. Valid values are `present` or a version number. # @param jna_package_name [string] The name of the JNA package. # @param package_ensure [string] Is passed to the package reference for the JRE/JDK # package. Valid values are `present` or a version number. # @param package_name [string] The name of the Java package to be installed. # @param yumrepo [hash] If supplied, this should be a hash of *yumrepo* # resources that will be passed to the create_resources function. # This is ignored on non-Red Hat systems. class cassandra::java ( $aptkey = undef, $aptsource = undef, $jna_ensure = present, - $jna_package_name = $::cassandra::params::jna_package_name, + $jna_package_name = $cassandra::params::jna_package_name, $package_ensure = present, - $package_name = $::cassandra::params::java_package, + $package_name = $cassandra::params::java_package, $yumrepo = undef, ) inherits cassandra::params { - if $::osfamily == 'RedHat' and $yumrepo != undef { + if $facts['os']['family'] == 'RedHat' and $yumrepo != undef { $yumrepo_defaults = { 'before' => Package[$package_name], } create_resources(yumrepo, $yumrepo, $yumrepo_defaults) } - if $::osfamily == 'Debian' { + if $facts['os']['family'] == 'Debian' { if $aptkey != undef { $aptkey_defaults = { 'before' => Package[$package_name], } + include apt create_resources(apt::key, $aptkey, $aptkey_defaults) } if $aptsource != undef { exec { 'cassandra::java::apt_update': refreshonly => true, command => '/bin/true', require => Exec['apt_update'], before => Package[$package_name], } $aptsource_defaults = { 'notify' => Exec['cassandra::java::apt_update'], } create_resources(apt::source, $aptsource, $aptsource_defaults) } } package { $package_name: ensure => $package_ensure, } package { $jna_package_name: ensure => $jna_ensure, } } diff --git a/manifests/optutils.pp b/manifests/optutils.pp index 275fa8b..3895c4e 100644 --- a/manifests/optutils.pp +++ b/manifests/optutils.pp @@ -1,16 +1,16 @@ # A class to install the optional Cassandra tools package. # @param package_ensure [string] Can be `present`, `latest` or a specific # version number. # @param package_name [string] The name of the optional utilities package to # be installed. class cassandra::optutils ( $package_ensure = 'present', - $package_name = $::cassandra::params::optutils_package_name, + $package_name = $cassandra::params::optutils_package_name, ) inherits cassandra::params { - include '::cassandra' + include 'cassandra' package { $package_name: ensure => $package_ensure, require => Class['cassandra'], } } diff --git a/manifests/params.pp b/manifests/params.pp index c94f127..862b6f1 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,60 +1,60 @@ # This class is meant to be called from the locp-cassandra module. # It sets variables according to platform. class cassandra::params { - case $::osfamily { + case $facts['os']['family'] { 'Debian': { - case $::operatingsystemmajrelease { + case $facts['os']['release']['major'] { '12.04': { $net_ipv4_tcp_rmem = '4096 87380 16777216' $net_ipv4_tcp_wmem = '4096 65536 16777216' $java_package = 'openjdk-7-jre-headless' } '18.04': { $net_ipv4_tcp_rmem = '4096 87380 16777216' $net_ipv4_tcp_wmem = '4096 65536 16777216' $java_package = 'openjdk-8-jre-headless' } # non-Ubuntu Debian is just... Debian default: { $net_ipv4_tcp_rmem = '4096, 87380, 16777216' $net_ipv4_tcp_wmem = '4096, 65536, 16777216' $java_package = 'openjdk-7-jre-headless' } } $cassandra_pkg = 'cassandra' $config_path = '/etc/cassandra' $jna_package_name = 'libjna-java' $optutils_package_name = 'cassandra-tools' $sysctl_file = '/etc/sysctl.d/10-cassandra.conf' $systemctl = '/bin/systemctl' } 'RedHat': { - case $::operatingsystemmajrelease { - 6: { + case $facts['os']['release']['major'] { + '6': { $net_ipv4_tcp_rmem = '4096 87380 16777216' $net_ipv4_tcp_wmem = '4096 65536 16777216' $sysctl_file = '/etc/sysctl.conf' } - 7: { + '7': { $net_ipv4_tcp_rmem = '4096, 87380, 16777216' $net_ipv4_tcp_wmem = '4096, 65536, 16777216' $sysctl_file = '/etc/sysctl.d/10-cassandra.conf' } default: {} } $cassandra_pkg = 'cassandra22' $config_path = '/etc/cassandra/default.conf' $java_package = 'java-1.8.0-openjdk-headless' $jna_package_name = 'jna' $optutils_package_name = 'cassandra22-tools' $systemctl = '/usr/bin/systemctl' $use_scl = false $scl_name = 'nodefault' } default: { $config_path_parents = [] } } } diff --git a/manifests/schema.pp b/manifests/schema.pp index 94ee13f..8e89783 100644 --- a/manifests/schema.pp +++ b/manifests/schema.pp @@ -1,142 +1,142 @@ # A class to maintain the database schema. Please note that cqlsh expects # Python 2.7 to be installed. This may be a problem of older distributions # (CentOS 6 for example). # @param connection_tries [integer] How many times do try to connect to # Cassandra. See also `connection_try_sleep`. # @param connection_try_sleep [integer] How much time to allow between the # number of tries specified in `connection_tries`. # @param cql_types [hash] Creates new `cassandra::schema::cql_type` resources. # @param cqlsh_additional_options [string] Any additional options to be passed # to the `cqlsh` command. # @param cqlsh_client_config [string] Set this to a file name # (e.g. '/root/.puppetcqlshrc') that will then be used to contain the # the credentials for connecting to Cassandra. This is a more secure option # than having the credentials appearing on the command line. This option # is only available in Cassandra >= 2.1. # @param cqlsh_client_tmpl [string] The location of the template for configuring # the credentials for the cqlsh client. This is ignored unless # `cqlsh_client_config` is set. # @param cqlsh_command [string] The full path to the `cqlsh` command. # @param cqlsh_host [string] The host for the `cqlsh` command to connect to. # See also `cqlsh_port`. # @param cqlsh_password [string] If credentials are require for connecting, # specify the password here. See also `cqlsh_user`, `cqlsh_client_config`. # @param cqlsh_port [integer] The host for the `cqlsh` command to connect to. # See also `cqlsh_host`. # @param cqlsh_user [string] If credentials are required for connecting, # specify the password here. See also `cqlsh_password`, # `cqlsh_client_config` # @param indexes [hash] Creates new `cassandra::schema::index` resources. # @param keyspaces [hash] Creates new `cassandra::schema::keyspace` resources. # @param permissions [hash] Creates new `cassandra::schema::permission` # resources. # @param tables [hash] Creates new `cassandra::schema::table` resources. # @param users [hash] Creates new `cassandra::schema::user` resources. class cassandra::schema ( $connection_tries = 6, $connection_try_sleep = 30, $cql_types = {}, $cqlsh_additional_options = '', $cqlsh_client_config = undef, $cqlsh_client_tmpl = 'cassandra/cqlshrc.erb', $cqlsh_command = '/usr/bin/cqlsh', $cqlsh_host = 'localhost', $cqlsh_password = undef, $cqlsh_port = 9042, $cqlsh_user = 'cassandra', $indexes = {}, $keyspaces = {}, $permissions = {}, $tables = {}, $users = {}, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ) inherits cassandra::params { - require '::cassandra' + require 'cassandra' # Pass the SCL info to create_resources below as a hash $scl = { 'use_scl' => $use_scl, 'scl_name' => $scl_name, } if $cqlsh_client_config != undef { file { $cqlsh_client_config : ensure => file, - group => $::gid, + group => $facts['identity']['gid'], mode => '0600', - owner => $::id, + owner => $facts['identity']['uid'], content => template( $cqlsh_client_tmpl ), before => Exec['::cassandra::schema connection test'], } $cmdline_login = "--cqlshrc=${cqlsh_client_config}" } else { if $cqlsh_password != undef { warning('You may want to consider using the cqlsh_client_config attribute') $cmdline_login = "-u ${cqlsh_user} -p ${cqlsh_password}" } else { $cmdline_login = '' } } $cqlsh_opts = "${cqlsh_command} ${cmdline_login} ${cqlsh_additional_options}" $cqlsh_conn = "${cqlsh_host} ${cqlsh_port}" # See if we can make a connection to Cassandra. Try $connection_tries # number of times with $connection_try_sleep in seconds between each try. $connection_test_tmp = "${cqlsh_opts} -e 'DESC KEYSPACES' ${cqlsh_conn}" if $use_scl { $connection_test = "/usr/bin/scl enable ${scl_name} \"${connection_test_tmp}\"" } else { $connection_test = $connection_test_tmp } exec { '::cassandra::schema connection test': command => $connection_test, returns => 0, tries => $connection_tries, try_sleep => $connection_try_sleep, unless => $connection_test, } # manage keyspaces if present if $keyspaces { create_resources('cassandra::schema::keyspace', $keyspaces, $scl) } # manage cql_types if present if $cql_types { create_resources('cassandra::schema::cql_type', $cql_types, $scl) } # manage tables if present if $tables { create_resources('cassandra::schema::table', $tables, $scl) } # manage indexes if present if $indexes { create_resources('cassandra::schema::index', $indexes, $scl) } # manage users if present if $users { create_resources('cassandra::schema::user', $users, $scl) } # manage permissions if present if $permissions { create_resources('cassandra::schema::permission', $permissions, $scl) } # Resource Ordering Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Cql_type <| |> Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Table <| |> Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Permission <| |> Cassandra::Schema::Cql_type <| |> -> Cassandra::Schema::Table <| |> Cassandra::Schema::Table <| |> -> Cassandra::Schema::Index <| |> Cassandra::Schema::Table <| |> -> Cassandra::Schema::Permission <| |> Cassandra::Schema::Index <| |> -> Cassandra::Schema::User <| |> Cassandra::Schema::User <| |> -> Cassandra::Schema::Permission <| |> } diff --git a/manifests/schema/cql_type.pp b/manifests/schema/cql_type.pp index 043bbc1..0e8bd0a 100644 --- a/manifests/schema/cql_type.pp +++ b/manifests/schema/cql_type.pp @@ -1,67 +1,67 @@ # Create or drop user defined data types within the schema. # @param keyspace [string] The name of the keyspace that the data type is to be associated with. # @param ensure [present|absent] ensure the data type is created, or is dropped. # @param fields [hash] A hash of the fields that will be components for the data type. # @param cql_type_name [string] The name of the CQL type to be created. # @example # cassandra::schema::cql_type { 'fullname': # keyspace => 'mykeyspace', # fields => { # 'fname' => 'text', # 'lname' => 'text', # }, # } define cassandra::schema::cql_type ( $keyspace, $ensure = present, $fields = {}, $cql_type_name = $title, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ){ include 'cassandra::schema' if $use_scl { $quote = '\"' } else { $quote = '"' } $read_script = "DESC TYPE ${keyspace}.${cql_type_name}" - $read_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $read_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $read_command = "/usr/bin/scl enable ${scl_name} \"${read_command_tmp}\"" } else { $read_command = $read_command_tmp } if $ensure == present { $create_script1 = "CREATE TYPE IF NOT EXISTS ${keyspace}.${cql_type_name}" $create_script2 = join(join_keys_to_values($fields, ' '), ', ') $create_script = "${create_script1} (${create_script2})" - $create_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $create_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $create_command = "/usr/bin/scl enable ${scl_name} \"${create_command_tmp}\"" } else { $create_command = $create_command_tmp } exec { $create_command: unless => $read_command, require => Exec['::cassandra::schema connection test'], } } elsif $ensure == absent { $delete_script = "DROP type ${keyspace}.${cql_type_name}" - $delete_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $delete_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $delete_command = "/usr/bin/scl enable ${scl_name} \"${delete_command_tmp}\"" } else { $delete_command = $delete_command_tmp } exec { $delete_command: onlyif => $read_command, require => Exec['::cassandra::schema connection test'], } } else { fail("Unknown action (${ensure}) for ensure attribute.") } } diff --git a/manifests/schema/index.pp b/manifests/schema/index.pp index 897f45b..ee47cbd 100644 --- a/manifests/schema/index.pp +++ b/manifests/schema/index.pp @@ -1,90 +1,90 @@ # Create or drop indexes within the schema. # @param ensure [present|absent] Create or dro[ the index. # @param class_name [string] The name of the class to be associated with an # index when creating a custom index. # @param index [string] The name of the index. Defaults to the name of the # resource. # @param keys [string] The columns that the index is being created on. # @param keyspace [string] The name the keyspace that the index is to be associated # with. # @param options [string] Any options to be added to the index. # @param table [string] The name of the table that the index is to be associated with. define cassandra::schema::index( $keyspace, $table, $ensure = present, $class_name = undef, $index = $title, $keys = undef, $options = undef, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ) { include 'cassandra::schema' if $use_scl { $quote = '\"' } else { $quote = '"' } # Fully qualified index name. $fqin = "${keyspace}.${index}" # Fully qualified table name. $fqtn = "${keyspace}.${table}" $read_script = "DESC INDEX ${fqin}" - $read_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $read_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $read_command = "/usr/bin/scl enable ${scl_name} \"${read_command_tmp}\"" } else { $read_command = $read_command_tmp } if $ensure == present { if $class_name != undef { $create_part1 = "CREATE CUSTOM INDEX IF NOT EXISTS ${index} ON ${keyspace}.${table}" } else { $create_part1 = "CREATE INDEX IF NOT EXISTS ${index} ON ${keyspace}.${table}" } if $class_name != undef { $create_part2 = "${create_part1} (${keys}) USING '${class_name}'" } else { $create_part2 = "${create_part1} (${keys})" } if $options != undef { $create_script = "${create_part2} WITH OPTIONS = ${options}" } else { $create_script = $create_part2 } - $create_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $create_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $create_command = "/usr/bin/scl enable ${scl_name} \"${create_command_tmp}\"" } else { $create_command = $create_command_tmp } exec { $create_command: unless => $read_command, require => Exec['::cassandra::schema connection test'], } } elsif $ensure == absent { $delete_script = "DROP INDEX ${fqin}" - $delete_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $delete_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $delete_command = "/usr/bin/scl enable ${scl_name} \"${delete_command_tmp}\"" } else { $delete_command = $delete_command_tmp } exec { $delete_command: onlyif => $read_command, require => Exec['::cassandra::schema connection test'], } } else { fail("Unknown action (${ensure}) for ensure attribute.") } } diff --git a/manifests/schema/keyspace.pp b/manifests/schema/keyspace.pp index 87ec12e..8e784ee 100644 --- a/manifests/schema/keyspace.pp +++ b/manifests/schema/keyspace.pp @@ -1,98 +1,98 @@ # Create or drop keyspaces within the schema. # @param ensure [present|absent] Create or drop the keyspace. # @param durable_writes [boolean] When set to false, data written to the # keyspace bypasses the commit log. Be careful using this option # because you risk losing data. Set this attribute to false on a keyspace # using the SimpleStrategy. # @param keyspace_name [string] The name of the keyspace to be created. # @param replication_map [hash] Needed if the keyspace is to be present. # Optional if it is to be absent. # @example # $network_topology_strategy = { # keyspace_class => 'NetworkTopologyStrategy', # dc1 => 3, # dc2 => 2 # } # @example # cassandra::schema::keyspace { 'mykeyspace': # replication_map => { # keyspace_class => 'SimpleStrategy', # replication_factor => 1, # }, # durable_writes => false, # } define cassandra::schema::keyspace( $ensure = present, $durable_writes = true, $keyspace_name = $title, $replication_map = {}, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ) { include 'cassandra::schema' if $use_scl { $quote = '\"' } else { $quote = '"' } $read_script = "DESC KEYSPACE ${keyspace_name}" - $read_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $read_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $read_command = "/usr/bin/scl enable ${scl_name} \"${read_command_tmp}\"" } else { $read_command = $read_command_tmp } if $ensure == present { $keyspace_class = $replication_map[keyspace_class] case $keyspace_class { 'SimpleStrategy': { $replication_factor = $replication_map[replication_factor] $map_str = "{ 'class' : 'SimpleStrategy', 'replication_factor' : ${replication_factor} }" } 'NetworkTopologyStrategy': { $map_str1 = "{ 'class' : 'NetworkTopologyStrategy'" $new_map = prefix(delete($replication_map, 'keyspace_class'), "'") $map_str2 = join(join_keys_to_values($new_map, "': "), ', ') $map_str = "${map_str1}, ${map_str2} }" } default: { $msg_part1 = "Invalid or no class (${keyspace_class}) specified for" $msg_part2 = "keyspace ${keyspace_name}." fail("${msg_part1} ${msg_part2}") } } $create_script1 = "CREATE KEYSPACE IF NOT EXISTS ${keyspace_name}" $create_script2 = "WITH REPLICATION = ${map_str}" $create_script3 = "AND DURABLE_WRITES = ${durable_writes}" $create_script = "${create_script1} ${create_script2} ${create_script3}" - $create_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $create_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $create_command = "/usr/bin/scl enable ${scl_name} \"${create_command_tmp}\"" } else { $create_command = $create_command_tmp } exec { $create_command: unless => $read_command, require => Exec['::cassandra::schema connection test'], } } elsif $ensure == absent { $delete_script = "DROP KEYSPACE ${keyspace_name}" - $delete_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $delete_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $delete_command = "/usr/bin/scl enable ${scl_name} \"${delete_command_tmp}\"" } else { $delete_command = $delete_command_tmp } exec { $delete_command: onlyif => $read_command, require => Exec['::cassandra::schema connection test'], } } else { fail("Unknown action (${ensure}) for ensure attribute.") } } diff --git a/manifests/schema/permission.pp b/manifests/schema/permission.pp index d2415da..b98291d 100644 --- a/manifests/schema/permission.pp +++ b/manifests/schema/permission.pp @@ -1,161 +1,161 @@ # Grant or revoke permissions. # To use this class, a suitable `authenticator` (e.g. PasswordAuthenticator) # and `authorizer` (e.g. CassandraAuthorizer) must be set in the Cassandra # class. # # WARNING: Specifying keyspace 'ALL' and 'ALL' for permissions at the same # time is not currently supported by this module. # # @param user_name [string] The name of the user who is to be granted or # revoked. # @param ensure [ present | absent ] Set to present to grant a permission or # absent to revoke it. # @param keyspace_name [string] The name of the keyspace to grant/revoke the # permissions on. If set to 'ALL' then the permission will be applied to # all of the keyspaces. # @param permission_name [string] Can be one of the following: # # * 'ALTER' - ALTER KEYSPACE, ALTER TABLE, CREATE INDEX, DROP INDEX. # * 'AUTHORIZE' - GRANT, REVOKE. # * 'CREATE' - CREATE KEYSPACE, CREATE TABLE. # * 'DROP' - DROP KEYSPACE, DROP TABLE. # * 'MODIFY' - INSERT, DELETE, UPDATE, TRUNCATE. # * 'SELECT' - SELECT. # # If the permission_name is set to 'ALL', this will set all of the specific # permissions listed. # @param table_name [string] The name of a table within the specified # keyspace. If left unspecified, the procedure will be applied to all # tables within the keyspace. define cassandra::schema::permission ( $user_name, $ensure = present, $keyspace_name = 'ALL', $permission_name = 'ALL', $table_name = undef, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ){ include 'cassandra::schema' if $use_scl { $quote = '\"' } else { $quote = '"' } if upcase($keyspace_name) == 'ALL' and upcase($permission_name) == 'ALL' { fail('"ALL" keyspaces AND "ALL" permissions are mutually exclusive.') } elsif $table_name { $resource = "TABLE ${keyspace_name}.${table_name}" } elsif upcase($keyspace_name) == 'ALL' { $resource = 'ALL KEYSPACES' } else { $resource = "KEYSPACE ${keyspace_name}" } $read_script = "LIST ALL PERMISSIONS ON ${resource}" $upcase_permission_name = upcase($permission_name) $pattern = "\s${user_name} |\s*${user_name} |\s.*\s${upcase_permission_name}$" - $read_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${::cassandra::schema::cqlsh_conn} | grep '${pattern}'" + $read_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${cassandra::schema::cqlsh_conn} | grep '${pattern}'" if $use_scl { $read_command = "/usr/bin/scl enable ${scl_name} \"${read_command_tmp}\"" } else { $read_command = $read_command_tmp } if upcase($permission_name) == 'ALL' { cassandra::schema::permission { "${title} - ALTER": ensure => $ensure, user_name => $user_name, keyspace_name => $keyspace_name, permission_name => 'ALTER', table_name => $table_name, use_scl => $use_scl, scl_name => $scl_name, } cassandra::schema::permission { "${title} - AUTHORIZE": ensure => $ensure, user_name => $user_name, keyspace_name => $keyspace_name, permission_name => 'AUTHORIZE', table_name => $table_name, use_scl => $use_scl, scl_name => $scl_name, } # The CREATE permission is not relevant to tables. if !$table_name { cassandra::schema::permission { "${title} - CREATE": ensure => $ensure, user_name => $user_name, keyspace_name => $keyspace_name, permission_name => 'CREATE', table_name => $table_name, use_scl => $use_scl, scl_name => $scl_name, } } cassandra::schema::permission { "${title} - DROP": ensure => $ensure, user_name => $user_name, keyspace_name => $keyspace_name, permission_name => 'DROP', table_name => $table_name, use_scl => $use_scl, scl_name => $scl_name, } cassandra::schema::permission { "${title} - MODIFY": ensure => $ensure, user_name => $user_name, keyspace_name => $keyspace_name, permission_name => 'MODIFY', table_name => $table_name, use_scl => $use_scl, scl_name => $scl_name, } cassandra::schema::permission { "${title} - SELECT": ensure => $ensure, user_name => $user_name, keyspace_name => $keyspace_name, permission_name => 'SELECT', table_name => $table_name, use_scl => $use_scl, scl_name => $scl_name, } } elsif $ensure == present { $create_script = "GRANT ${permission_name} ON ${resource} TO ${user_name}" - $create_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $create_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $create_command = "/usr/bin/scl enable ${scl_name} \"${create_command_tmp}\"" } else { $create_command = $create_command_tmp } exec { $create_script: command => $create_command, unless => $read_command, require => Exec['::cassandra::schema connection test'], } } elsif $ensure == absent { $delete_script = "REVOKE ${permission_name} ON ${resource} FROM ${user_name}" - $delete_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $delete_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $delete_command = "/usr/bin/scl enable ${scl_name} \"${delete_command_tmp}\"" } else { $delete_command = $delete_command_tmp } exec { $delete_script: command => $delete_command, onlyif => $read_command, require => Exec['::cassandra::schema connection test'], } } else { fail("Unknown action (${ensure}) for ensure attribute.") } } diff --git a/manifests/schema/table.pp b/manifests/schema/table.pp index 279d3f5..02eb21b 100644 --- a/manifests/schema/table.pp +++ b/manifests/schema/table.pp @@ -1,81 +1,81 @@ # Create or drop tables within the schema. # @param keyspace [string] The name of the keyspace. # @param columns [hash] A hash of the columns to be placed in the table. # Optional if the table is to be absent. # @param ensure [present|absent] Ensure a keyspace is created or dropped. # @param options [array] Options to be added to the table creation. # @param table [string] The name of the table. Defaults to the name of the # resource. # @example # cassandra::schema::table { 'users': # keyspace => 'mykeyspace', # columns => { # 'userid' => 'int', # 'fname' => 'text', # 'lname' => 'text', # 'PRIMARY KEY' => '(userid)', # }, # } define cassandra::schema::table ( $keyspace, $ensure = present, $columns = {}, $options = [], $table = $title, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ){ include 'cassandra::schema' if $use_scl { $quote = '\"' } else { $quote = '"' } $read_script = "DESC TABLE ${keyspace}.${table}" - $read_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $read_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $read_command = "/usr/bin/scl enable ${scl_name} \"${read_command_tmp}\"" } else { $read_command = $read_command_tmp } if $ensure == present { $create_script1 = "CREATE TABLE IF NOT EXISTS ${keyspace}.${table}" $cols_def = join(join_keys_to_values($columns, ' '), ', ') $cols_def_rm_collection_type = delete($cols_def, 'COLLECTION-TYPE ') if count($options) > 0 { $options_def = join($options, ' AND ') $create_script = "${create_script1} (${cols_def_rm_collection_type}) WITH ${options_def}" } else { $create_script = "${create_script1} (${cols_def_rm_collection_type})" } - $create_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $create_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $create_command = "/usr/bin/scl enable ${scl_name} \"${create_command_tmp}\"" } else { $create_command = $create_command_tmp } exec { $create_command: unless => $read_command, require => Exec['::cassandra::schema connection test'], } } elsif $ensure == absent { $delete_script = "DROP TABLE IF EXISTS ${keyspace}.${table}" - $delete_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $delete_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $delete_command = "/usr/bin/scl enable ${scl_name} \"${delete_command_tmp}\"" } else { $delete_command = $delete_command_tmp } exec { $delete_command: onlyif => $read_command, require => Exec['::cassandra::schema connection test'], } } else { fail("Unknown action (${ensure}) for ensure attribute.") } } diff --git a/manifests/schema/user.pp b/manifests/schema/user.pp index a2216bc..f6e292a 100644 --- a/manifests/schema/user.pp +++ b/manifests/schema/user.pp @@ -1,137 +1,137 @@ # Create or drop users. # To use this class, a suitable `authenticator` (e.g. PasswordAuthenticator) # must be set in the Cassandra class. # @param ensure [ present | absent ] Valid values can be **present** to # ensure a user is created, or **absent** to remove the user if it exists. # @param password [string] A password for the user. # @param superuser [boolean] If the user is to be a super-user on the system. # @param login [boolean] Allows the role to log in. # @param user_name [string] The name of the user. # @example # cassandra::schema::user { 'akers': # password => 'Niner2', # superuser => true, # } # # cassandra::schema::user { 'lucan': # ensure => absent, # } define cassandra::schema::user ( $ensure = present, $login = true, $password = undef, $superuser = false, $user_name = $title, Boolean $use_scl = $cassandra::params::use_scl, String[1] $scl_name = $cassandra::params::scl_name, ){ include 'cassandra::schema' if $use_scl { $quote = '\"' } else { $quote = '"' } if $::cassandrarelease != undef { if versioncmp($::cassandrarelease, '2.2') < 0 { $operate_with_roles = false } else { $operate_with_roles = true } } else { $operate_with_roles = false } if $operate_with_roles { $read_script = 'LIST ROLES' } else { $read_script = 'LIST USERS' } $str_match = '\s' - $read_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${::cassandra::schema::cqlsh_conn} | grep '${str_match}*${user_name} |'" + $read_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${read_script}${quote} ${cassandra::schema::cqlsh_conn} | grep '${str_match}*${user_name} |'" if $use_scl { $read_command = "/usr/bin/scl enable ${scl_name} \"${read_command_tmp}\"" } else { $read_command = $read_command_tmp } if $ensure == present { if $operate_with_roles { # we are running cassandra > 2.2 $create_script1 = "CREATE ROLE IF NOT EXISTS ${user_name}" if $password != undef { $create_script2 = "${create_script1} WITH PASSWORD = '${password}'" } else { $create_script2 = $create_script1 } if $superuser { if $password != undef { $create_script3 = "${create_script2} AND SUPERUSER = true" } else { $create_script3 = "${create_script2} WITH SUPERUSER = true" } } else { $create_script3 = $create_script2 } if $login { if $superuser or $password != undef { $create_script = "${create_script3} AND LOGIN = true" } else { $create_script = "${create_script3} WITH LOGIN = true" } } else { $create_script = $create_script3 } } else { $create_script1 = "CREATE USER IF NOT EXISTS ${user_name}" if $password != undef { $create_script2 = "${create_script1} WITH PASSWORD '${password}'" } else { $create_script2 = $create_script1 } if $superuser { $create_script = "${create_script2} SUPERUSER" } else { $create_script = "${create_script2} NOSUPERUSER" } } - $create_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $create_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${create_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $create_command = "/usr/bin/scl enable ${scl_name} \"${create_command_tmp}\"" } else { $create_command = $create_command_tmp } exec { "Create user (${user_name})": command => $create_command, unless => $read_command, require => Exec['::cassandra::schema connection test'], } } elsif $ensure == absent { if $operate_with_roles { $delete_script = "DROP ROLE ${user_name}" } else { $delete_script = "DROP USER ${user_name}" } - $delete_command_tmp = "${::cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${::cassandra::schema::cqlsh_conn}" + $delete_command_tmp = "${cassandra::schema::cqlsh_opts} -e ${quote}${delete_script}${quote} ${cassandra::schema::cqlsh_conn}" if $use_scl { $delete_command = "/usr/bin/scl enable ${scl_name} \"${delete_command_tmp}\"" } else { $delete_command = $delete_command_tmp } exec { "Delete user (${user_name})": command => $delete_command, onlyif => $read_command, require => Exec['::cassandra::schema connection test'], } } else { fail("Unknown action (${ensure}) for ensure attribute.") } } diff --git a/manifests/system/sysctl.pp b/manifests/system/sysctl.pp index 425d68d..c226d8a 100644 --- a/manifests/system/sysctl.pp +++ b/manifests/system/sysctl.pp @@ -1,113 +1,113 @@ # Set Sysctl (kernel runtime parameters) as suggested in # http://docs.datastax.com/en/landing_page/doc/landing_page/recommendedSettingsLinux.html # # If any of the values is set into the target file, the sysctl command will # be called with the provided file name as an argument. # # @example Basic requirement # require cassandra::system::sysctl # # @param sysctl_args [string] Passed to the `sysctl` command # @param sysctl_file [string] Path to the file to insert the settings into. # @param net_core_optmem_max [integer] The value to set for # net.core.optmem_max # @param net_core_rmem_default [integer] The value to set for # net.core.rmem_default. # @param net_core_rmem_max [integer] The value to set for net_core_rmem_max. # @param net_core_wmem_default [integer] The value to set for # net.core.wmem_default. # @param net_core_wmem_max [integer] The value to set for net.core.wmem_max. # @param net_ipv4_tcp_rmem [string] The value to set for net.ipv4.tcp_rmem. # @param net_ipv4_tcp_wmem [string] The value to set for net.ipv4.tcp_wmem. # @param vm_max_map_count [integer] The value to set for vm.max_map_count. # @see cassandra::params class cassandra::system::sysctl( $sysctl_args = '-p', $sysctl_file = $cassandra::params::sysctl_file, $net_core_optmem_max = 40960, $net_core_rmem_default = 16777216, $net_core_rmem_max = 16777216, $net_core_wmem_default = 16777216, $net_core_wmem_max = 16777216, - $net_ipv4_tcp_rmem = $::cassandra::params::net_ipv4_tcp_rmem, - $net_ipv4_tcp_wmem = $::cassandra::params::net_ipv4_tcp_wmem, + $net_ipv4_tcp_rmem = $cassandra::params::net_ipv4_tcp_rmem, + $net_ipv4_tcp_wmem = $cassandra::params::net_ipv4_tcp_wmem, $vm_max_map_count = 1048575, ) inherits cassandra::params { ini_setting { "net.core.rmem_max = ${net_core_rmem_max}": ensure => present, path => $sysctl_file, section => '', setting => 'net.core.rmem_max', value => $net_core_rmem_max, notify => Exec['Apply sysctl changes'], } ini_setting { "net.core.wmem_max = ${net_core_wmem_max}": ensure => present, path => $sysctl_file, section => '', setting => 'net.core.wmem_max', value => $net_core_wmem_max, notify => Exec['Apply sysctl changes'], } ini_setting { "net.core.rmem_default = ${net_core_rmem_default}": ensure => present, path => $sysctl_file, section => '', setting => 'net.core.rmem_default', value => $net_core_rmem_default, notify => Exec['Apply sysctl changes'], } ini_setting { "net.core.wmem_default = ${net_core_wmem_default}": ensure => present, path => $sysctl_file, section => '', setting => 'net.core.wmem_default', value => $net_core_wmem_default, notify => Exec['Apply sysctl changes'], } ini_setting { "net.core.optmem_max = ${net_core_optmem_max}": ensure => present, path => $sysctl_file, section => '', setting => 'net.core.optmem_max', value => $net_core_optmem_max, notify => Exec['Apply sysctl changes'], } ini_setting { "net.ipv4.tcp_rmem = ${net_ipv4_tcp_rmem}": ensure => present, path => $sysctl_file, section => '', setting => 'net.ipv4.tcp_rmem', value => $net_ipv4_tcp_rmem, notify => Exec['Apply sysctl changes'], } ini_setting { "net.ipv4.tcp_wmem = ${net_ipv4_tcp_wmem}": ensure => present, path => $sysctl_file, section => '', setting => 'net.ipv4.tcp_wmem', value => $net_ipv4_tcp_wmem, notify => Exec['Apply sysctl changes'], } ini_setting { "vm.max_map_count = ${vm_max_map_count}": ensure => present, path => $sysctl_file, section => '', setting => 'vm.max_map_count', value => $vm_max_map_count, notify => Exec['Apply sysctl changes'], } exec { 'Apply sysctl changes': command => "/sbin/sysctl ${sysctl_args} ${sysctl_file}", refreshonly => true, } } diff --git a/spec/classes/apache_repo_spec.rb b/spec/classes/apache_repo_spec.rb index cdf85da..7a143c1 100644 --- a/spec/classes/apache_repo_spec.rb +++ b/spec/classes/apache_repo_spec.rb @@ -1,73 +1,85 @@ require 'spec_helper' describe 'cassandra::apache_repo' do context 'On a RedHat OS with defaults for all parameters' do let :facts do { - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { release: '311x' } end it do is_expected.to have_resource_count(1) is_expected.to contain_class('cassandra::apache_repo').only_with( 'descr' => 'Repo for Apache Cassandra', 'key_id' => 'A26E528B271F19B9E5D8E19EA278B781FE4B2BDA', 'key_url' => 'https://www.apache.org/dist/cassandra/KEYS', 'release' => '311x' ) is_expected.to contain_yumrepo('cassandra_apache').with( ensure: 'present', descr: 'Repo for Apache Cassandra', baseurl: 'http://www.apache.org/dist/cassandra/redhat/311x', enabled: 1, gpgcheck: 1, gpgkey: 'https://www.apache.org/dist/cassandra/KEYS' ) end end context 'On a Debian OS with defaults for all parameters' do let :facts do { osfamily: 'Debian', lsbdistid: 'Debian', lsbdistrelease: '9', os: { - name: 'Debian', - release: { major: '9' } + 'family' => 'Debian', + 'name' => 'Debian', + 'release' => { + 'full' => '9.9', + 'major' => '9', + 'minor' => '9' + } } } end it do - is_expected.to have_resource_count(16) is_expected.to contain_class('apt') is_expected.to contain_class('apt::update') is_expected.to contain_apt__key('apache.cassandra').with( id: 'A26E528B271F19B9E5D8E19EA278B781FE4B2BDA', source: 'https://www.apache.org/dist/cassandra/KEYS' ) is_expected.to contain_apt__source('cassandra.sources').with( location: 'http://www.apache.org/dist/cassandra/debian', comment: 'Repo for Apache Cassandra', release: 'main', include: { 'src' => false } ).that_notifies('Exec[update-apache-cassandra-repo]') is_expected.to contain_exec('update-apache-cassandra-repo').with( refreshonly: true, command: '/bin/true' ) end end end diff --git a/spec/classes/datastax_agent_spec.rb b/spec/classes/datastax_agent_spec.rb index ec0e5c3..883f7b0 100644 --- a/spec/classes/datastax_agent_spec.rb +++ b/spec/classes/datastax_agent_spec.rb @@ -1,130 +1,163 @@ require 'spec_helper' describe 'cassandra::datastax_agent' do context 'Test for cassandra::datastax_agent with defaults (RedHat).' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: '6' + operatingsystemmajrelease: '6', + os: { + 'name' => 'RedHat', + 'family' => 'RedHat', + 'release' => { + 'full' => '6.10', + 'major' => '6', + 'minor' => '10' + } + } } end it do is_expected.to compile.with_all_deps is_expected.to have_resource_count(10) is_expected.to contain_class('cassandra::datastax_agent').with( 'address_config_file' => '/var/lib/datastax-agent/conf/address.yaml', 'defaults_file' => '/etc/default/datastax-agent', 'package_ensure' => 'present', 'package_name' => 'datastax-agent', 'service_ensure' => 'running', 'service_enable' => true, 'service_name' => 'datastax-agent', 'settings' => {} ) is_expected.to contain_package('datastax-agent').with( ensure: 'present', notify: 'Exec[datastax_agent_reload_systemctl]' ).that_notifies('Exec[datastax_agent_reload_systemctl]') is_expected.to contain_exec('datastax_agent_reload_systemctl').only_with( command: '/usr/bin/systemctl daemon-reload', onlyif: 'test -x /usr/bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true, notify: 'Service[datastax-agent]' ).that_notifies('Service[datastax-agent]') is_expected.to contain_file('/var/lib/datastax-agent/conf/address.yaml'). with( owner: 'cassandra', group: 'cassandra', mode: '0644' ).that_requires('Package[datastax-agent]') is_expected.to contain_service('datastax-agent').only_with( ensure: 'running', enable: true, name: 'datastax-agent' ) end end context 'Test for cassandra::datastax_agent with defaults (Debian).' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: '6' + operatingsystemmajrelease: '7', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end it do is_expected.to contain_exec('datastax_agent_reload_systemctl').with( command: '/bin/systemctl daemon-reload', onlyif: 'test -x /bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true ).that_notifies('Service[datastax-agent]') end end context 'Test that the JAVA_HOME can be set.' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: '6' + operatingsystemmajrelease: '7', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end let :params do { java_home: '/usr/lib/jvm/java-8-oracle' } end it do is_expected.to contain_ini_setting('java_home').with( ensure: 'present', path: '/etc/default/datastax-agent', section: '', key_val_separator: '=', setting: 'JAVA_HOME', value: '/usr/lib/jvm/java-8-oracle' ).that_notifies('Service[datastax-agent]') end end context 'Test settings.' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: '6' + operatingsystemmajrelease: '7', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end let :params do { settings: { 'agent_alias' => { 'setting' => 'agent_alias', 'value' => 'foobar' }, 'stomp_interface' => { 'setting' => 'stomp_interface', 'value' => 'localhost' }, 'async_pool_size' => { 'ensure' => 'absent' } } } end it do is_expected.to have_resource_count(16) end end end diff --git a/spec/classes/datastax_repo_spec.rb b/spec/classes/datastax_repo_spec.rb index 1ddbc20..a1698d4 100644 --- a/spec/classes/datastax_repo_spec.rb +++ b/spec/classes/datastax_repo_spec.rb @@ -1,66 +1,78 @@ require 'spec_helper' describe 'cassandra::datastax_repo' do context 'On a RedHat OS with defaults for all parameters' do let :facts do { - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to have_resource_count(1) is_expected.to contain_class('cassandra::datastax_repo').only_with( 'descr' => 'DataStax Repo for Apache Cassandra', 'key_id' => '7E41C00F85BFC1706C4FFFB3350200F2B999A372', 'key_url' => 'http://debian.datastax.com/debian/repo_key', 'release' => 'stable' ) is_expected.to contain_yumrepo('datastax').with( ensure: 'present', descr: 'DataStax Repo for Apache Cassandra', baseurl: 'http://rpm.datastax.com/community', enabled: 1, gpgcheck: 0 ) end end context 'On a Debian OS with defaults for all parameters' do let :facts do { osfamily: 'Debian', lsbdistid: 'Debian', lsbdistrelease: '9', os: { - name: 'Debian', - release: { major: '9' } + 'name' => 'Debian', + 'family' => 'Debian', + 'release' => { + 'major' => '9', + 'minor' => '9', + 'full' => '9.9' + } } } end it do - is_expected.to have_resource_count(16) is_expected.to contain_class('apt') is_expected.to contain_class('apt::update') is_expected.to contain_apt__key('datastaxkey').with( id: '7E41C00F85BFC1706C4FFFB3350200F2B999A372', source: 'http://debian.datastax.com/debian/repo_key' ) is_expected.to contain_apt__source('datastax').with( location: 'http://debian.datastax.com/community', comment: 'DataStax Repo for Apache Cassandra', release: 'stable', include: { 'src' => false } ).that_notifies('Exec[update-cassandra-repos]') is_expected.to contain_exec('update-cassandra-repos').with( refreshonly: true, command: '/bin/true' ) end end end diff --git a/spec/classes/dse_spec.rb b/spec/classes/dse_spec.rb index aaba78e..2d76a6d 100644 --- a/spec/classes/dse_spec.rb +++ b/spec/classes/dse_spec.rb @@ -1,21 +1,30 @@ require 'spec_helper' describe 'cassandra::dse' do context 'with defaults for all parameters' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: 7, + os: { + 'family' => 'RedHat', + 'name' => 'Redhat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to have_resource_count(13) is_expected.to contain_class('cassandra') is_expected.to contain_class('cassandra::dse').with( config_file_mode: '0644', config_file: '/etc/dse/dse.yaml' ) end end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 82afc99..c9476b1 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,390 +1,487 @@ require 'spec_helper' describe 'cassandra' do context 'On an unknown OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: '10', - osfamily: 'Darwin' + operatingsystemmajrelease: '16', + osfamily: 'Darwin', + os: { + 'family' => 'Darwin', + 'release' => { + 'full' => '16.0.0', + 'major' => '16', + 'minor' => '0' + } + } } end it { is_expected.to raise_error(Puppet::Error) } end context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: '7' + operatingsystemmajrelease: '7', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to contain_package('cassandra').with( ensure: 'present', name: 'cassandra22' ).that_notifies('Exec[cassandra_reload_systemctl]') is_expected.to contain_exec('cassandra_reload_systemctl').only_with( command: '/usr/bin/systemctl daemon-reload', onlyif: 'test -x /usr/bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true ) is_expected.to contain_file('/etc/cassandra/default.conf').with( ensure: 'directory', group: 'cassandra', owner: 'cassandra', mode: '0755' ).that_requires('Package[cassandra]') is_expected.to contain_file('/etc/cassandra/default.conf/cassandra.yaml'). with( ensure: 'present', owner: 'cassandra', group: 'cassandra', mode: '0644' ). that_requires('Package[cassandra]') is_expected.to contain_class('cassandra').only_with( baseline_settings: {}, cassandra_2356_sleep_seconds: 5, cassandra_9822: false, cassandra_yaml_tmpl: 'cassandra/cassandra.yaml.erb', commitlog_directory_mode: '0750', manage_config_file: true, config_file_mode: '0644', config_path: '/etc/cassandra/default.conf', data_file_directories_mode: '0750', dc: 'DC1', fail_on_non_supported_os: true, hints_directory_mode: '0750', package_ensure: 'present', package_name: 'cassandra22', rack: 'RAC1', rackdc_tmpl: 'cassandra/cassandra-rackdc.properties.erb', saved_caches_directory_mode: '0750', service_enable: true, service_name: 'cassandra', service_provider: nil, service_refresh: true, settings: {}, snitch_properties_file: 'cassandra-rackdc.properties', systemctl: '/usr/bin/systemctl' ) end end context 'On RedHat 7 with data directories specified.' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: '7' + operatingsystemmajrelease: '7', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { commitlog_directory: '/var/lib/cassandra/commitlog', data_file_directories: ['/var/lib/cassandra/data'], hints_directory: '/var/lib/cassandra/hints', saved_caches_directory: '/var/lib/cassandra/saved_caches', settings: { 'cluster_name' => 'MyCassandraCluster' } } end it do is_expected.to have_resource_count(10) is_expected.to contain_file('/var/lib/cassandra/commitlog') is_expected.to contain_file('/var/lib/cassandra/data') is_expected.to contain_file('/var/lib/cassandra/hints') is_expected.to contain_file('/var/lib/cassandra/saved_caches') end end context 'On RedHat 7 with service provider set to init.' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: '7' + operatingsystemmajrelease: '7', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { service_provider: 'init' } end it do is_expected.to have_resource_count(7) is_expected.to contain_exec('/sbin/chkconfig --add cassandra').with( unless: '/sbin/chkconfig --list cassandra' ). that_requires('Package[cassandra]'). that_comes_before('Service[cassandra]') end end context 'On a Debian OS with defaults for all parameters' do let :facts do { operatingsystemmajrelease: '8', - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '8.11', + 'major' => '8', + 'minor' => '11' + } + } } end it do is_expected.to contain_class('cassandra') is_expected.to contain_group('cassandra').with_ensure('present') is_expected.to contain_package('cassandra').with( ensure: 'present', name: 'cassandra' ).that_notifies('Exec[cassandra_reload_systemctl]') is_expected.to contain_exec('cassandra_reload_systemctl').only_with( command: '/bin/systemctl daemon-reload', onlyif: 'test -x /bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true ) is_expected.to contain_service('cassandra').with( ensure: nil, name: 'cassandra', enable: 'true' ) is_expected.to contain_exec('CASSANDRA-2356 sleep'). with( command: '/bin/sleep 5', refreshonly: true, user: 'root' ). that_subscribes_to('Package[cassandra]'). that_comes_before('Service[cassandra]') is_expected.to contain_user('cassandra'). with( ensure: 'present', comment: 'Cassandra database,,,', gid: 'cassandra', home: '/var/lib/cassandra', shell: '/bin/false', managehome: true ). that_requires('Group[cassandra]') is_expected.to contain_file('/etc/cassandra').with( ensure: 'directory', group: 'cassandra', owner: 'cassandra', mode: '0755' ) is_expected.to contain_file('/etc/cassandra/cassandra.yaml'). with( ensure: 'present', owner: 'cassandra', group: 'cassandra', mode: '0644' ). that_comes_before('Package[cassandra]'). that_requires(['User[cassandra]', 'File[/etc/cassandra]']) is_expected.to contain_file('/etc/cassandra/cassandra-rackdc.properties'). with( ensure: 'file', owner: 'cassandra', group: 'cassandra', mode: '0644' ). that_requires(['File[/etc/cassandra]', 'User[cassandra]']). that_comes_before('Package[cassandra]') is_expected.to contain_service('cassandra'). that_subscribes_to( [ 'File[/etc/cassandra/cassandra.yaml]', 'File[/etc/cassandra/cassandra-rackdc.properties]', 'Package[cassandra]' ] ) end end - context 'CASSANDRA-9822 activated on Debian' do + context 'CASSANDRA-9822 activated on Ubuntu 16.04' do let :facts do { - operatingsystemmajrelease: '7', + operatingsystemmajrelease: '16.04', osfamily: 'Debian', lsbdistid: 'Ubuntu', - lsbdistrelease: '14.04' + lsbdistrelease: '16.04', + os: { + 'name' => 'Ubuntu', + 'family' => 'Debian', + 'release' => { + 'full' => '16.04', + 'major' => '16.04' + } + } } end let :params do { cassandra_9822: true } end it do is_expected.to contain_file('/etc/init.d/cassandra').with( source: 'puppet:///modules/cassandra/CASSANDRA-9822/cassandra', mode: '0555' ).that_comes_before('Package[cassandra]') end end context 'Install DSE on a Red Hat family OS.' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { package_ensure: '4.7.0-1', package_name: 'dse-full', config_path: '/etc/dse/cassandra', service_name: 'dse' } end it do is_expected.to contain_file('/etc/dse/cassandra/cassandra.yaml').that_notifies('Service[cassandra]') is_expected.to contain_file('/etc/dse/cassandra') is_expected.to contain_file('/etc/dse/cassandra/cassandra-rackdc.properties'). with( ensure: 'file', owner: 'cassandra', group: 'cassandra', mode: '0644' ). that_notifies('Service[cassandra]') is_expected.to contain_package('cassandra').with( ensure: '4.7.0-1', name: 'dse-full' ) is_expected.to contain_service('cassandra').with_name('dse') end end context 'On an unsupported OS pleading tolerance' do let :facts do { - operatingsystemmajrelease: '10', - osfamily: 'Darwin' + operatingsystemmajrelease: '16', + osfamily: 'Darwin', + os: { + 'family' => 'Darwin', + 'release' => { + 'full' => '16.0.0', + 'major' => '16', + 'minor' => '0' + } + } } end let :params do { config_file_mode: '0755', config_path: '/etc/cassandra', fail_on_non_supported_os: false, package_name: 'cassandra', service_provider: 'base', systemctl: '/bin/true' } end it do is_expected.to contain_file('/etc/cassandra/cassandra.yaml').with('mode' => '0755') is_expected.to contain_service('cassandra').with(provider: 'base') is_expected.to have_resource_count(6) end end context 'Ensure cassandra service can be stopped and disabled.' do let :facts do { operatingsystemmajrelease: '8', - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '8.11', + 'major' => '8', + 'minor' => '11' + } + } } end let :params do { service_ensure: 'stopped', service_enable: 'false' } end it do is_expected.to contain_service('cassandra'). with(ensure: 'stopped', name: 'cassandra', enable: 'false') end end context 'Test the dc and rack properties with defaults (Debian).' do let :facts do { operatingsystemmajrelease: '8', - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '8.11', + 'major' => '8', + 'minor' => '11' + } + } } end it do is_expected.to contain_file('/etc/cassandra/cassandra-rackdc.properties'). with_content(%r{^dc=DC1}). with_content(%r{^rack=RAC1$}). with_content(%r{^#dc_suffix=$}). with_content(%r{^# prefer_local=true$}) end end context 'Test the dc and rack properties with defaults (RedHat).' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to contain_file('/etc/cassandra/default.conf/cassandra-rackdc.properties'). with_content(%r{^dc=DC1}). with_content(%r{^rack=RAC1$}). with_content(%r{^#dc_suffix=$}). with_content(%r{^# prefer_local=true$}) end end context 'Test the dc and rack properties.' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { snitch_properties_file: 'cassandra-topology.properties', dc: 'NYC', rack: 'R101', dc_suffix: '_1_cassandra', prefer_local: 'true' } end it do is_expected.to contain_file('/etc/cassandra/default.conf/cassandra-topology.properties'). with_content(%r{^dc=NYC$}). with_content(%r{^rack=R101$}). with_content(%r{^dc_suffix=_1_cassandra$}). with_content(%r{^prefer_local=true$}) end end end diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index f4e18d8..144ddf5 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -1,159 +1,206 @@ require 'spec_helper' describe 'cassandra::java' do context 'On a RedHat OS with defaults for all parameters' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to contain_class('cassandra::java') is_expected.to contain_package('java-1.8.0-openjdk-headless') is_expected.to contain_package('jna') end end context 'On a Debian OS with defaults for all parameters' do let :facts do { operatingsystemmajrelease: '7', osfamily: 'Debian', - lsbdistid: 'Debian' + lsbdistid: 'Debian', + os: { + 'name' => 'Debian', + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end it do is_expected.to contain_class('cassandra::java') is_expected.to contain_package('openjdk-7-jre-headless') is_expected.to contain_package('libjna-java') is_expected.to have_resource_count(2) end end context 'On a Debian OS with package_ensure set' do let :facts do { operatingsystemmajrelease: '7', osfamily: 'Debian', - lsbdistid: 'Debian' + lsbdistid: 'Debian', + os: { + 'name' => 'Debian', + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end let :params do { package_ensure: '2.1.13' } end it do is_expected.to contain_package('openjdk-7-jre-headless').with_ensure('2.1.13') end end context 'With package names set to foobar' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { package_name: 'foobar-java', package_ensure: '42', jna_package_name: 'foobar-jna', jna_ensure: 'latest' } end it do is_expected.to contain_package('foobar-java').with(ensure: 42) is_expected.to contain_package('foobar-jna').with(ensure: 'latest') end end context 'Ensure that a YUM repo can be specified.' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { yumrepo: { 'ACME' => { 'baseurl' => 'http://yum.acme.org/repos', 'descr' => 'YUM Repository for ACME Products' } } } end it do is_expected.to contain_yumrepo('ACME').with( baseurl: 'http://yum.acme.org/repos', descr: 'YUM Repository for ACME Products' ).that_comes_before('Package[java-1.8.0-openjdk-headless]') end end context 'Ensure that Apt key and source can be specified.' do let :facts do { operatingsystemmajrelease: '7', osfamily: 'Debian', lsbdistid: 'Debian', os: { - name: 'Debian', - release: { major: '7' } + 'name' => 'Debian', + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } } } end let :params do { aptkey: { 'openjdk-r' => { 'id' => 'DA1A4A13543B466853BAF164EB9B1D8886F44E2A', 'server' => 'keyserver.ubuntu.com' } }, aptsource: { 'openjdk-r' => { 'comment' => 'OpenJDK builds (all archs)', 'location' => 'http://ppa.launchpad.net/openjdk-r/ppa/ubuntu', 'repos' => 'main', 'release' => 'trusty' } } } end it do is_expected.to contain_apt__key('openjdk-r'). with( id: 'DA1A4A13543B466853BAF164EB9B1D8886F44E2A', server: 'keyserver.ubuntu.com' ). that_comes_before('Package[openjdk-7-jre-headless]') is_expected.to contain_apt__source('openjdk-r'). with( comment: 'OpenJDK builds (all archs)', location: 'http://ppa.launchpad.net/openjdk-r/ppa/ubuntu', repos: 'main', release: 'trusty' ) is_expected.to contain_exec('cassandra::java::apt_update'). with( refreshonly: true, command: '/bin/true' ). that_comes_before('Package[openjdk-7-jre-headless]') end end end diff --git a/spec/classes/optutils_spec.rb b/spec/classes/optutils_spec.rb index 782b93f..63d3aa9 100644 --- a/spec/classes/optutils_spec.rb +++ b/spec/classes/optutils_spec.rb @@ -1,75 +1,109 @@ require 'spec_helper' describe 'cassandra::optutils' do context 'On a RedHat OS with defaults for all parameters' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to have_resource_count(7) is_expected.to contain_package('cassandra22-tools').with(ensure: 'present') is_expected.to contain_class('cassandra::optutils').with( package_ensure: 'present', package_name: 'cassandra22-tools' ) end end context 'On a Debian OS with defaults for all parameters' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'name' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end it do is_expected.to contain_package('cassandra-tools').with(ensure: 'present') is_expected.to contain_class('cassandra::optutils').with( package_ensure: 'present', package_name: 'cassandra-tools' ) end end context 'With package_name set to foobar' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end let :params do { package_name: 'foobar-java', package_ensure: '42' } end it do is_expected.to contain_package('foobar-java').with(ensure: 42) end end context 'On a Debian OS with package_ensure set' do let :facts do { operatingsystemmajrelease: '7', - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end let :params do { package_ensure: '2.1.13' } end it { is_expected.to contain_package('cassandra-tools').with_ensure('2.1.13') } end end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index f641cda..06c5387 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -1,16 +1,24 @@ require 'spec_helper' describe '::cassandra::params' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: '7' + operatingsystemmajrelease: '7', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to compile is_expected.to contain_class('cassandra::params') is_expected.to have_resource_count(0) end end diff --git a/spec/classes/schema_spec.rb b/spec/classes/schema_spec.rb index 727a48f..6f99f8c 100644 --- a/spec/classes/schema_spec.rb +++ b/spec/classes/schema_spec.rb @@ -1,172 +1,225 @@ require 'spec_helper' describe 'cassandra::schema' do context 'Ensure that a connection test is made.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to contain_class('cassandra::schema'). with(connection_tries: 6, connection_try_sleep: 30, cqlsh_additional_options: '', cqlsh_command: '/usr/bin/cqlsh', cqlsh_host: 'localhost', cqlsh_password: nil, cqlsh_port: 9042, cqlsh_user: 'cassandra') read_command = '/usr/bin/cqlsh -e \'DESC KEYSPACES\' localhost 9042' is_expected.to contain_exec('::cassandra::schema connection test'). only_with(command: read_command, returns: 0, tries: 6, try_sleep: 30, unless: read_command) end end context 'Ensure that a connection test is made with SCL.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { use_scl: true, scl_name: 'testscl' } end it do is_expected.to contain_class('cassandra::schema'). with(connection_tries: 6, connection_try_sleep: 30, cqlsh_additional_options: '', cqlsh_command: '/usr/bin/cqlsh', cqlsh_host: 'localhost', cqlsh_password: nil, cqlsh_port: 9042, cqlsh_user: 'cassandra') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \'DESC KEYSPACES\' localhost 9042"' is_expected.to contain_exec('::cassandra::schema connection test'). only_with(command: read_command, returns: 0, tries: 6, try_sleep: 30, unless: read_command) end end context 'Test that users can specify a credentials file.' do let :facts do { - id: 'root', - gid: 'root', + id: 0, + gid: 0, operatingsystemmajrelease: 7, - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'name' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + }, + identity: { + uid: 0, + gid: 0 + } } end let :params do { cqlsh_client_config: '/root/.puppetcqlshrc', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to contain_file('/root/.puppetcqlshrc').with( ensure: 'file', - group: 'root', + group: 0, mode: '0600', - owner: 'root', + owner: 0, content: %r{username = cassandra} ).that_comes_before('Exec[::cassandra::schema connection test]') read_command = "/usr/bin/cqlsh --cqlshrc=/root/.puppetcqlshrc -e 'DESC KEYSPACES' localhost 9042" is_expected.to contain_exec('::cassandra::schema connection test'). only_with(command: read_command, returns: 0, tries: 6, try_sleep: 30, unless: read_command) end end context 'Test that users can specify a credentials file and password.' do let :facts do { - id: 'root', - gid: 'root', + id: 0, + gid: 0, operatingsystemmajrelease: 7, - osfamily: 'Debian' + osfamily: 'Debian', + os: { + 'family' => 'Debian', + 'name' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + }, + identity: { + uid: 0, + gid: 0 + } } end let :params do { cqlsh_client_config: '/root/.puppetcqlshrc', cqlsh_password: 'topsecret', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to contain_file('/root/.puppetcqlshrc').with( ensure: 'file', - group: 'root', + group: 0, mode: '0600', - owner: 'root', + owner: 0, content: %r{password = topsecret} ) read_command = "/usr/bin/cqlsh --cqlshrc=/root/.puppetcqlshrc -e 'DESC KEYSPACES' localhost 9042" is_expected.to contain_exec('::cassandra::schema connection test'). only_with(command: read_command, returns: 0, tries: 6, try_sleep: 30, unless: read_command) end end context 'Test that users can specify a password.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'Redhat' + osfamily: 'Redhat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let :params do { cqlsh_password: 'topsecret' } end it do read_command = "/usr/bin/cqlsh -u cassandra -p topsecret -e 'DESC KEYSPACES' localhost 9042" is_expected.to contain_exec('::cassandra::schema connection test'). only_with(command: read_command, returns: 0, tries: 6, try_sleep: 30, unless: read_command) end end end diff --git a/spec/classes/system/sysctl_spec.rb b/spec/classes/system/sysctl_spec.rb index 14516f9..087a232 100644 --- a/spec/classes/system/sysctl_spec.rb +++ b/spec/classes/system/sysctl_spec.rb @@ -1,28 +1,36 @@ require 'spec_helper' describe 'cassandra::system::sysctl' do context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: '7', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to have_resource_count(9) is_expected.to contain_class('Cassandra::System::Sysctl') is_expected.to contain_ini_setting('net.core.optmem_max = 40960') is_expected.to contain_ini_setting('net.core.rmem_default = 16777216') is_expected.to contain_ini_setting('net.core.rmem_max = 16777216') is_expected.to contain_ini_setting('net.core.wmem_default = 16777216') is_expected.to contain_ini_setting('net.core.wmem_max = 16777216') is_expected.to contain_ini_setting('net.ipv4.tcp_rmem = 4096, 87380, 16777216') is_expected.to contain_ini_setting('net.ipv4.tcp_wmem = 4096, 65536, 16777216') is_expected.to contain_ini_setting('vm.max_map_count = 1048575') is_expected.to contain_exec('Apply sysctl changes').with( command: '/sbin/sysctl -p /etc/sysctl.d/10-cassandra.conf' ) end end end diff --git a/spec/classes/system/transparent_hugepage_spec.rb b/spec/classes/system/transparent_hugepage_spec.rb index 39ee3c1..ad8372d 100644 --- a/spec/classes/system/transparent_hugepage_spec.rb +++ b/spec/classes/system/transparent_hugepage_spec.rb @@ -1,33 +1,49 @@ require 'spec_helper' describe 'cassandra::system::transparent_hugepage' do context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: 7, + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end it do is_expected.to have_resource_count(1) is_expected.to contain_class('cassandra::system::transparent_hugepage') is_expected.to contain_exec('Disable Java Hugepages') end end context 'Test the default parameters (Debian)' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: 7, + os: { + 'family' => 'Debian', + 'release' => { + 'full' => '7.8', + 'major' => '7', + 'minor' => '8' + } + } } end it do is_expected.to have_resource_count(1) is_expected.to contain_class('cassandra::system::transparent_hugepage') is_expected.to contain_exec('Disable Java Hugepages') end end end diff --git a/spec/defines/file_spec.rb b/spec/defines/file_spec.rb index 9dab736..a333a41 100644 --- a/spec/defines/file_spec.rb +++ b/spec/defines/file_spec.rb @@ -1,39 +1,48 @@ require 'spec_helper' -describe '::cassandra::file' do +describe 'cassandra::file' do context 'On a Debian OS set the max and new heap size' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: 8 + operatingsystemmajrelease: 8, + os: { + 'family' => 'Debian', + 'name' => 'Debian', + 'release' => { + 'full' => '8.11', + 'major' => '8', + 'minor' => '11' + } + } } end let(:title) { 'cassandra-env.sh' } let :params do { config_path: '/etc/cassandra', 'file_lines' => { 'MAX_HEAP_SIZE 4GB' => { 'line' => 'MAX_HEAP_SIZE="4G"', 'match' => '^#MAX_HEAP_SIZE="4G"$' } } } end it do is_expected.to contain_class('cassandra') is_expected.to contain_class('cassandra::params') is_expected.to contain_class('stdlib') is_expected.to contain_cassandra__file('cassandra-env.sh') is_expected.to contain_file_line('MAX_HEAP_SIZE 4GB').with( path: '/etc/cassandra/cassandra-env.sh', line: 'MAX_HEAP_SIZE="4G"', match: '^#MAX_HEAP_SIZE="4G"$' ) end end end diff --git a/spec/defines/schema/cql_type_spec.rb b/spec/defines/schema/cql_type_spec.rb index 54ec3eb..5485881 100644 --- a/spec/defines/schema/cql_type_spec.rb +++ b/spec/defines/schema/cql_type_spec.rb @@ -1,151 +1,196 @@ require 'spec_helper' describe 'cassandra::schema::cql_type' do context 'CQL TYPE (fullname)' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'fullname' } let(:params) do { 'keyspace' => 'Excelsior', fields: { 'firstname' => 'text', 'lastname' => 'text' }, 'use_scl' => false, 'scl_name' => 'nodefault' } end it do is_expected.to compile is_expected.to contain_class('cassandra::schema') is_expected.to contain_cassandra__schema__cql_type('fullname') read_command = '/usr/bin/cqlsh -e "DESC TYPE Excelsior.fullname" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE TYPE IF NOT EXISTS Excelsior.fullname ' exec_command += '(firstname text, lastname text)" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'CQL TYPE (fullname) with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'fullname' } let(:params) do { 'keyspace' => 'Excelsior', fields: { 'firstname' => 'text', 'lastname' => 'text' }, 'use_scl' => true, 'scl_name' => 'testscl' } end it do is_expected.to compile is_expected.to contain_class('cassandra::schema') is_expected.to contain_cassandra__schema__cql_type('fullname') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC TYPE Excelsior.fullname\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE TYPE IF NOT EXISTS Excelsior.fullname ' exec_command += '(firstname text, lastname text)\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to absent' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'address' } let(:params) do { 'ensure' => 'absent', 'keyspace' => 'Excalibur', 'use_scl' => false, 'scl_name' => 'nodefault' } end it do is_expected.to compile is_expected.to contain_cassandra__schema__cql_type('address') read_command = '/usr/bin/cqlsh -e "DESC TYPE Excalibur.address" localhost 9042' exec_command = '/usr/bin/cqlsh -e "DROP type Excalibur.address" localhost 9042' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to absent with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'address' } let(:params) do { 'ensure' => 'absent', 'keyspace' => 'Excalibur', 'use_scl' => true, 'scl_name' => 'testscl' } end it do is_expected.to compile is_expected.to contain_cassandra__schema__cql_type('address') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC TYPE Excalibur.address\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DROP type Excalibur.address\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/index_spec.rb b/spec/defines/schema/index_spec.rb index 930e580..0f2000a 100644 --- a/spec/defines/schema/index_spec.rb +++ b/spec/defines/schema/index_spec.rb @@ -1,275 +1,356 @@ require 'spec_helper' describe 'cassandra::schema::index' do context 'Create a basic index' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { keys: 'lname', keyspace: 'mykeyspace', table: 'users', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to compile is_expected.to contain_cassandra__schema__index('user_index') read_command = '/usr/bin/cqlsh -e "DESC INDEX mykeyspace.user_index" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE INDEX IF NOT EXISTS user_index ON mykeyspace.users (lname)" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a basic index with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { keys: 'lname', keyspace: 'mykeyspace', table: 'users', use_scl: true, scl_name: 'testscl' } end it do is_expected.to compile is_expected.to contain_cassandra__schema__index('user_index') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC INDEX mykeyspace.user_index\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE INDEX IF NOT EXISTS user_index ON mykeyspace.users (lname)\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a custom index.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', table: 'users', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to compile read_command = '/usr/bin/cqlsh -e "DESC INDEX Excelsior.user_index" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\'" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a custom index with SCL.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', table: 'users', use_scl: true, scl_name: 'testscl' } end it do is_expected.to compile read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC INDEX Excelsior.user_index\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\'\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a custom index with options.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', options: "{'storage': '/mnt/ssd/indexes/'}", table: 'users', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to compile read_command = '/usr/bin/cqlsh -e "DESC INDEX Excelsior.user_index" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON ' exec_command += 'Excelsior.users (email) USING \'path.to.the.IndexClass\' WITH OPTIONS = {' exec_command += '\'storage\': \'/mnt/ssd/indexes/\'}" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a custom index with options with SCL.' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', options: "{'storage': '/mnt/ssd/indexes/'}", table: 'users', use_scl: true, scl_name: 'testscl' } end it do is_expected.to compile read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC INDEX Excelsior.user_index\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE CUSTOM INDEX IF NOT EXISTS user_index ON ' exec_command += 'Excelsior.users (email) USING \'path.to.the.IndexClass\' WITH OPTIONS = {' exec_command += '\'storage\': \'/mnt/ssd/indexes/\'}\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop Index' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { ensure: 'absent', keys: 'lname', keyspace: 'Excelsior', table: 'users', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to compile read_command = '/usr/bin/cqlsh -e "DESC INDEX Excelsior.user_index" localhost 9042' exec_command = '/usr/bin/cqlsh -e "DROP INDEX Excelsior.user_index" localhost 9042' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop Index with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'user_index' } let(:params) do { ensure: 'absent', keys: 'lname', keyspace: 'Excelsior', table: 'users', use_scl: true, scl_name: 'testscl' } end it do is_expected.to compile read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC INDEX Excelsior.user_index\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DROP INDEX Excelsior.user_index\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/keyspace_spec.rb b/spec/defines/schema/keyspace_spec.rb index 616f8c2..7dade35 100644 --- a/spec/defines/schema/keyspace_spec.rb +++ b/spec/defines/schema/keyspace_spec.rb @@ -1,219 +1,282 @@ require 'spec_helper' describe 'cassandra::schema::keyspace' do context 'Set ensure to present (SimpleStrategy)' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'SimpleStrategy', 'replication_factor' => 3 }, use_scl: false, scl_name: 'nodefault' } end it do is_expected.to compile is_expected.to contain_class('cassandra::schema') read_command = '/usr/bin/cqlsh -e "DESC KEYSPACE foobar" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = ' exec_command += '{ \'class\' : \'SimpleStrategy\', \'replication_factor\' : 3 } ' exec_command += 'AND DURABLE_WRITES = true" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to present (SimpleStrategy) with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'SimpleStrategy', 'replication_factor' => 3 }, use_scl: true, scl_name: 'testscl' } end it do is_expected.to compile read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC KEYSPACE foobar\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = ' exec_command += '{ \'class\' : \'SimpleStrategy\', \'replication_factor\' : 3 } ' exec_command += 'AND DURABLE_WRITES = true\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to present (NetworkTopologyStrategy)' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'NetworkTopologyStrategy', 'dc1' => '3', 'dc2' => '2' }, use_scl: false, scl_name: 'nodefault' } end it do is_expected.to contain_cassandra__schema__keyspace('foobar') read_command = '/usr/bin/cqlsh -e "DESC KEYSPACE foobar" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = ' exec_command += '{ \'class\' : \'NetworkTopologyStrategy\', \'dc1\': 3, \'dc2\': 2 } ' exec_command += 'AND DURABLE_WRITES = true" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to present (NetworkTopologyStrategy) with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'NetworkTopologyStrategy', 'dc1' => '3', 'dc2' => '2' }, use_scl: true, scl_name: 'testscl' } end it do is_expected.to contain_cassandra__schema__keyspace('foobar') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC KEYSPACE foobar\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = ' exec_command += '{ \'class\' : \'NetworkTopologyStrategy\', \'dc1\': 3, \'dc2\': 2 } ' exec_command += 'AND DURABLE_WRITES = true\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to absent' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'absent', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to compile read_command = '/usr/bin/cqlsh -e "DESC KEYSPACE foobar" localhost 9042' exec_command = '/usr/bin/cqlsh -e "DROP KEYSPACE foobar" localhost 9042' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to absent with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'absent', use_scl: true, scl_name: 'testscl' } end it do is_expected.to compile read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC KEYSPACE foobar\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DROP KEYSPACE foobar\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/permission_spec.rb b/spec/defines/schema/permission_spec.rb index 44cf719..0d640e4 100644 --- a/spec/defines/schema/permission_spec.rb +++ b/spec/defines/schema/permission_spec.rb @@ -1,399 +1,507 @@ require 'spec_helper' describe 'cassandra::schema::permission' do context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { user_name: 'foobar' } end it { is_expected.to raise_error(Puppet::Error) } end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end context 'spillman:SELECT:ALL' do let(:title) { 'spillman:SELECT:ALL' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'spillman', permission_name: 'SELECT', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('spillman:SELECT:ALL') read_script = '/usr/bin/cqlsh -e "LIST ALL PERMISSIONS ON ALL KEYSPACES" ' read_script += 'localhost 9042 | grep \' spillman | *spillman | .* SELECT$\'' script_command = 'GRANT SELECT ON ALL KEYSPACES TO spillman' exec_command = "/usr/bin/cqlsh -e \"#{script_command}\" localhost 9042" is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'spillman:SELECT:ALL with SCL' do let(:title) { 'spillman:SELECT:ALL' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'spillman', permission_name: 'SELECT', use_scl: true, scl_name: 'testscl' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('spillman:SELECT:ALL') read_script = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ALL PERMISSIONS ON ALL KEYSPACES\" ' read_script += 'localhost 9042 | grep \' spillman | *spillman | .* SELECT$\'"' script_command = 'GRANT SELECT ON ALL KEYSPACES TO spillman' exec_command = "/usr/bin/scl enable testscl \"/usr/bin/cqlsh -e \\\"#{script_command}\\\" localhost 9042\"" is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'akers:modify:field' do let(:title) { 'akers:modify:field' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'akers', keyspace_name: 'field', permission_name: 'MODIFY', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('akers:modify:field') read_script = '/usr/bin/cqlsh -e "LIST ALL PERMISSIONS ON KEYSPACE field" ' read_script += 'localhost 9042 | grep \' akers | *akers | .* MODIFY$\'' script_command = 'GRANT MODIFY ON KEYSPACE field TO akers' exec_command = "/usr/bin/cqlsh -e \"#{script_command}\" localhost 9042" is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'akers:modify:field with SCL' do let(:title) { 'akers:modify:field' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'akers', keyspace_name: 'field', permission_name: 'MODIFY', use_scl: true, scl_name: 'testscl' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('akers:modify:field') read_script = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ALL PERMISSIONS ON KEYSPACE field\" ' read_script += 'localhost 9042 | grep \' akers | *akers | .* MODIFY$\'"' script_command = 'GRANT MODIFY ON KEYSPACE field TO akers' exec_command = "/usr/bin/scl enable testscl \"/usr/bin/cqlsh -e \\\"#{script_command}\\\" localhost 9042\"" is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'boone:alter:forty9ers' do let(:title) { 'boone:alter:forty9ers' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'ALTER', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('boone:alter:forty9ers') read_script = '/usr/bin/cqlsh -e "LIST ALL PERMISSIONS ON KEYSPACE forty9ers" ' read_script += 'localhost 9042 | grep \' boone | *boone | .* ALTER$\'' script_command = 'GRANT ALTER ON KEYSPACE forty9ers TO boone' exec_command = "/usr/bin/cqlsh -e \"#{script_command}\" localhost 9042" is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'boone:alter:forty9ers with SCL' do let(:title) { 'boone:alter:forty9ers' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'ALTER', use_scl: true, scl_name: 'testscl' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('boone:alter:forty9ers') read_script = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ALL PERMISSIONS ON KEYSPACE forty9ers\" ' read_script += 'localhost 9042 | grep \' boone | *boone | .* ALTER$\'"' script_command = 'GRANT ALTER ON KEYSPACE forty9ers TO boone' exec_command = "/usr/bin/scl enable testscl \"/usr/bin/cqlsh -e \\\"#{script_command}\\\" localhost 9042\"" is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'boone:ALL:ravens.plays' do let(:title) { 'boone:ALL:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'boone', keyspace_name: 'ravens', table_name: 'plays', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to have_resource_count(18) is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays') end expected_values = %w[ALTER AUTHORIZE DROP MODIFY SELECT] expected_values.each do |val| it do is_expected.to contain_cassandra__schema__permission("boone:ALL:ravens.plays - #{val}").with( ensure: 'present', user_name: 'boone', keyspace_name: 'ravens', permission_name: val, table_name: 'plays' ) end read_script = '/usr/bin/cqlsh -e "LIST ALL PERMISSIONS ON TABLE ravens.plays" ' read_script += "localhost 9042 | grep ' boone | *boone | .* #{val}$'" script_command = "GRANT #{val} ON TABLE ravens.plays TO boone" exec_command = "/usr/bin/cqlsh -e \"#{script_command}\" localhost 9042" it do is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end end context 'boone:ALL:ravens.plays with SCL' do let(:title) { 'boone:ALL:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { user_name: 'boone', keyspace_name: 'ravens', table_name: 'plays', use_scl: true, scl_name: 'testscl' } end it do is_expected.to have_resource_count(18) is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays') end expected_values = %w[ALTER AUTHORIZE DROP MODIFY SELECT] expected_values.each do |val| it do is_expected.to contain_cassandra__schema__permission("boone:ALL:ravens.plays - #{val}").with( ensure: 'present', user_name: 'boone', keyspace_name: 'ravens', permission_name: val, table_name: 'plays' ) end read_script = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ALL PERMISSIONS ON TABLE ravens.plays\" ' read_script += "localhost 9042 | grep ' boone | *boone | .* #{val}$'\"" script_command = "GRANT #{val} ON TABLE ravens.plays TO boone" exec_command = "/usr/bin/scl enable testscl \"/usr/bin/cqlsh -e \\\"#{script_command}\\\" localhost 9042\"" it do is_expected.to contain_exec(script_command). only_with(command: exec_command, unless: read_script, require: 'Exec[::cassandra::schema connection test]') end end end context 'REVOKE boone:SELECT:ravens.plays' do let(:title) { 'REVOKE boone:SELECT:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { ensure: 'absent', user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'SELECT', use_scl: false, scl_name: 'nodefault' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('REVOKE boone:SELECT:ravens.plays') read_script = '/usr/bin/cqlsh -e "LIST ALL PERMISSIONS ON KEYSPACE forty9ers" ' read_script += "localhost 9042 | grep ' boone | *boone | .* SELECT$'" script_command = 'REVOKE SELECT ON KEYSPACE forty9ers FROM boone' exec_command = "/usr/bin/cqlsh -e \"#{script_command}\" localhost 9042" is_expected.to contain_exec(script_command). only_with(command: exec_command, onlyif: read_script, require: 'Exec[::cassandra::schema connection test]') end end context 'REVOKE boone:SELECT:ravens.plays with SCL' do let(:title) { 'REVOKE boone:SELECT:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:params) do { ensure: 'absent', user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'SELECT', use_scl: true, scl_name: 'testscl' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('REVOKE boone:SELECT:ravens.plays') read_script = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ALL PERMISSIONS ON KEYSPACE forty9ers\" ' read_script += "localhost 9042 | grep ' boone | *boone | .* SELECT$'\"" script_command = 'REVOKE SELECT ON KEYSPACE forty9ers FROM boone' exec_command = "/usr/bin/scl enable testscl \"/usr/bin/cqlsh -e \\\"#{script_command}\\\" localhost 9042\"" is_expected.to contain_exec(script_command). only_with(command: exec_command, onlyif: read_script, require: 'Exec[::cassandra::schema connection test]') end end end diff --git a/spec/defines/schema/table_spec.rb b/spec/defines/schema/table_spec.rb index a84e914..e802cf9 100644 --- a/spec/defines/schema/table_spec.rb +++ b/spec/defines/schema/table_spec.rb @@ -1,173 +1,217 @@ require 'spec_helper' describe 'cassandra::schema::table' do context 'Create Table' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'users' } let(:params) do { use_scl: false, scl_name: 'nodefault', keyspace: 'Excelsior', columns: { 'userid' => 'text', 'username' => 'FROZEN', 'emails' => 'set', 'top_scores' => 'list', 'todo' => 'map', 'COLLECTION-TYPE' => 'tuple', 'PRIMARY KEY' => '(userid)' }, options: [ 'COMPACT STORAGE', 'ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'' ] } end it do is_expected.to compile is_expected.to contain_cassandra__schema__table('users') read_command = '/usr/bin/cqlsh -e "DESC TABLE Excelsior.users" localhost 9042' exec_command = '/usr/bin/cqlsh -e "CREATE TABLE IF NOT EXISTS Excelsior.users ' exec_command += '(userid text, username FROZEN, emails set, top_scores list, ' exec_command += 'todo map, tuple, PRIMARY KEY (userid)) ' exec_command += 'WITH COMPACT STORAGE AND ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'" localhost 9042' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create Table with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'users' } let(:params) do { use_scl: true, scl_name: 'testscl', keyspace: 'Excelsior', columns: { 'userid' => 'text', 'username' => 'FROZEN', 'emails' => 'set', 'top_scores' => 'list', 'todo' => 'map', 'COLLECTION-TYPE' => 'tuple', 'PRIMARY KEY' => '(userid)' }, options: [ 'COMPACT STORAGE', 'ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'' ] } end it do is_expected.to compile is_expected.to contain_cassandra__schema__table('users') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC TABLE Excelsior.users\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE TABLE IF NOT EXISTS Excelsior.users ' exec_command += '(userid text, username FROZEN, emails set, top_scores list, ' exec_command += 'todo map, tuple, PRIMARY KEY (userid)) ' exec_command += 'WITH COMPACT STORAGE AND ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop Table' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'users' } let(:params) do { use_scl: false, scl_name: 'nodefault', keyspace: 'Excelsior', ensure: 'absent' } end it do is_expected.to compile read_command = '/usr/bin/cqlsh -e "DESC TABLE Excelsior.users" localhost 9042' exec_command = '/usr/bin/cqlsh -e "DROP TABLE IF EXISTS Excelsior.users" localhost 9042' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop Table with SCL' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'users' } let(:params) do { use_scl: true, scl_name: 'testscl', keyspace: 'Excelsior', ensure: 'absent' } end it do is_expected.to compile read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DESC TABLE Excelsior.users\" localhost 9042"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DROP TABLE IF EXISTS Excelsior.users\" localhost 9042"' is_expected.to contain_exec(exec_command). only_with(onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/user_spec.rb b/spec/defines/schema/user_spec.rb index d0abf60..f70c42a 100644 --- a/spec/defines/schema/user_spec.rb +++ b/spec/defines/schema/user_spec.rb @@ -1,459 +1,594 @@ require 'spec_helper' describe 'cassandra::schema::user' do context 'Create a supper user on cassandrarelease undef' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: nil + cassandrarelease: nil, + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/cqlsh -e "LIST USERS" localhost 9042 | grep \'\s*akers |\'' exec_command = '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers' exec_command += ' WITH PASSWORD \'Niner2\' SUPERUSER" localhost 9042' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a supper user on cassandrarelease undef with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: nil + cassandrarelease: nil, + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST USERS\" localhost 9042 | grep \'\s*akers |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE USER IF NOT EXISTS akers' exec_command += ' WITH PASSWORD \'Niner2\' SUPERUSER\" localhost 9042"' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a supper user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '2.0.1' + cassandrarelease: '2.0.1', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/cqlsh -e "LIST USERS" localhost 9042 | grep \'\s*akers |\'' exec_command = '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers' exec_command += ' WITH PASSWORD \'Niner2\' SUPERUSER" localhost 9042' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a supper user in cassandrarelease < 2.2 with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '2.0.1' + cassandrarelease: '2.0.1', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST USERS\" localhost 9042 | grep \'\s*akers |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE USER IF NOT EXISTS akers' exec_command += ' WITH PASSWORD \'Niner2\' SUPERUSER\" localhost 9042"' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '2.0.1' + cassandrarelease: '2.0.1', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'Niner2' } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/cqlsh -e "LIST USERS" localhost 9042 | grep \'\s*akers |\'' exec_command = '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers' exec_command += ' WITH PASSWORD \'Niner2\' NOSUPERUSER" localhost 9042' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a user in cassandrarelease < 2.2 with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '2.0.1' + cassandrarelease: '2.0.1', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'Niner2' } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST USERS\" localhost 9042 | grep \'\s*akers |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE USER IF NOT EXISTS akers' exec_command += ' WITH PASSWORD \'Niner2\' NOSUPERUSER\" localhost 9042"' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a supper user with login in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '3.0.9' + cassandrarelease: '3.0.9', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/cqlsh -e "LIST ROLES" localhost 9042 | grep \'\s*akers |\'' exec_command = '/usr/bin/cqlsh -e "CREATE ROLE IF NOT EXISTS akers' exec_command += ' WITH PASSWORD = \'Niner2\' AND SUPERUSER = true AND LOGIN = true" localhost 9042' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a supper user with login in cassandrarelease > 2.2 with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '3.0.9' + cassandrarelease: '3.0.9', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ROLES\" localhost 9042 | grep \'\s*akers |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE ROLE IF NOT EXISTS akers' exec_command += ' WITH PASSWORD = \'Niner2\' AND SUPERUSER = true AND LOGIN = true\" localhost 9042"' is_expected.to contain_exec('Create user (akers)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a user without login in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '3.0.9' + cassandrarelease: '3.0.9', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'bob' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'kaZe89a', login: false } end it do is_expected.to contain_cassandra__schema__user('bob').with_ensure('present') read_command = '/usr/bin/cqlsh -e "LIST ROLES" localhost 9042 | grep \'\s*bob |\'' exec_command = '/usr/bin/cqlsh -e "CREATE ROLE IF NOT EXISTS bob' exec_command += ' WITH PASSWORD = \'kaZe89a\'" localhost 9042' is_expected.to contain_exec('Create user (bob)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Create a user without login in cassandrarelease > 2.2 with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '3.0.9' + cassandrarelease: '3.0.9', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'bob' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'kaZe89a', login: false } end it do is_expected.to contain_cassandra__schema__user('bob').with_ensure('present') read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ROLES\" localhost 9042 | grep \'\s*bob |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"CREATE ROLE IF NOT EXISTS bob' exec_command += ' WITH PASSWORD = \'kaZe89a\'\" localhost 9042"' is_expected.to contain_exec('Create user (bob)'). only_with(command: exec_command, unless: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop a user in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '3.0.9' + cassandrarelease: '3.0.9', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'Niner2', ensure: 'absent' } end it do read_command = '/usr/bin/cqlsh -e "LIST ROLES" localhost 9042 | grep \'\s*akers |\'' exec_command = '/usr/bin/cqlsh -e "DROP ROLE akers" localhost 9042' is_expected.to contain_exec('Delete user (akers)'). only_with(command: exec_command, onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop a user in cassandrarelease > 2.2 with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '3.0.9' + cassandrarelease: '3.0.9', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'Niner2', ensure: 'absent' } end it do read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST ROLES\" localhost 9042 | grep \'\s*akers |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DROP ROLE akers\" localhost 9042"' is_expected.to contain_exec('Delete user (akers)'). only_with(command: exec_command, onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop a user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '2.0.2' + cassandrarelease: '2.0.2', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: false, scl_name: 'nodefault', password: 'Niner2', ensure: 'absent' } end it do read_command = '/usr/bin/cqlsh -e "LIST USERS" localhost 9042 | grep \'\s*akers |\'' exec_command = '/usr/bin/cqlsh -e "DROP USER akers" localhost 9042' is_expected.to contain_exec('Delete user (akers)'). only_with(command: exec_command, onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Drop a user in cassandrarelease < 2.2 with SCL' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', - cassandrarelease: '2.0.2' + cassandrarelease: '2.0.2', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'akers' } let(:params) do { use_scl: true, scl_name: 'testscl', password: 'Niner2', ensure: 'absent' } end it do read_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"LIST USERS\" localhost 9042 | grep \'\s*akers |\'"' exec_command = '/usr/bin/scl enable testscl "/usr/bin/cqlsh -e \"DROP USER akers\" localhost 9042"' is_expected.to contain_exec('Delete user (akers)'). only_with(command: exec_command, onlyif: read_command, require: 'Exec[::cassandra::schema connection test]') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, - osfamily: 'RedHat' + osfamily: 'RedHat', + os: { + 'family' => 'RedHat', + 'name' => 'RedHat', + 'release' => { + 'full' => '7.6.1810', + 'major' => '7', + 'minor' => '6' + } + } } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 88bca59..ca1028d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,34 +1,38 @@ # This file is managed via modulesync # https://github.com/voxpupuli/modulesync # https://github.com/voxpupuli/modulesync_config +RSpec.configure do |c| + c.mock_with :mocha +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' include RspecPuppetFacts if Dir.exist?(File.expand_path('../../lib', __FILE__)) require 'coveralls' require 'simplecov' require 'simplecov-console' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console ] SimpleCov.start do track_files 'lib/**/*.rb' add_filter '/spec' add_filter '/vendor' add_filter '/.vendor' end end RSpec.configure do |c| default_facts = {} default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__)) default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__)) c.default_facts = default_facts # Coverage generation c.after(:suite) do RSpec::Puppet::Coverage.report! end end diff --git a/vagrant/manifests/site.pp b/vagrant/manifests/site.pp index 50f14c4..4b0a04f 100644 --- a/vagrant/manifests/site.pp +++ b/vagrant/manifests/site.pp @@ -1,36 +1,36 @@ require cassandra::java include cassandra::optutils class { 'cassandra::apache_repo': release => '310x', before => Class['cassandra', 'cassandra::optutils'], } class { 'cassandra': commitlog_directory => '/var/lib/cassandra/commitlog', data_file_directories => ['/var/lib/cassandra/data'], hints_directory => '/var/lib/cassandra/hints', saved_caches_directory => '/var/lib/cassandra/saved_caches', settings => { 'authenticator' => 'PasswordAuthenticator', 'authorizer' => 'CassandraAuthorizer', 'cluster_name' => 'MyCassandraCluster', 'commitlog_sync' => 'periodic', 'commitlog_sync_period_in_ms' => 10000, 'endpoint_snitch' => 'GossipingPropertyFileSnitch', - 'listen_address' => $::ipaddress, + 'listen_address' => $facts['networking']['ip'], 'partitioner' => 'org.apache.cassandra.dht.Murmur3Partitioner', 'seed_provider' => [ { 'class_name' => 'org.apache.cassandra.locator.SimpleSeedProvider', 'parameters' => [ { - 'seeds' => $::ipaddress, + 'seeds' => $facts['networking']['ip'], }, ], }, ], 'start_native_transport' => true, }, service_ensure => running, }