diff --git a/.gitignore b/.gitignore index 7d10b86..3f158d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,11 @@ pkg .vagrant .gitreview - Gemfile.lock + +kitchenci/.tmp/ +kitchenci/modules/ +kitchenci/*.lock +kitchenci/.ruby* +kitchenci/.kitchen +kitchenci/.librarian diff --git a/kitchenci/.kitchen.yml b/kitchenci/.kitchen.yml new file mode 100644 index 0000000..49987c4 --- /dev/null +++ b/kitchenci/.kitchen.yml @@ -0,0 +1,24 @@ +--- +driver: + name: vagrant + +provisioner: + name: puppet_apply + puppet_version: {puppet_version} + mainfests_path: manifests + modules_path: modules + hiera_config_path: hiera.yaml + hiera_data_path: hieradata + +platforms: + {platforms} + driver: + customize: + memory: 4096 + +suites: + - name: default + manifest: site.pp + provisioner: + custom_facts: + processorcount: 2 diff --git a/kitchenci/Gemfile b/kitchenci/Gemfile new file mode 100644 index 0000000..a2e07b1 --- /dev/null +++ b/kitchenci/Gemfile @@ -0,0 +1,8 @@ +# A sample Gemfile +source "https://rubygems.org" + +gem "test-kitchen" +gem "kitchen-puppet" +gem "kitchen-docker" +gem "kitchen-vagrant" +gem "librarian-puppet" diff --git a/kitchenci/Puppetfile b/kitchenci/Puppetfile new file mode 100644 index 0000000..4f6deae --- /dev/null +++ b/kitchenci/Puppetfile @@ -0,0 +1,8 @@ +# Role specific modules + +forge "https://forgeapi.puppetlabs.com" + +mod "cakesolutions/cassandra", + :git => "git@github.com:cakesolutions/puppet-cassandra.git" + +mod "puppetlabs/stdlib", "4.6.0" diff --git a/kitchenci/hiera.yaml b/kitchenci/hiera.yaml new file mode 100644 index 0000000..c258cff --- /dev/null +++ b/kitchenci/hiera.yaml @@ -0,0 +1,7 @@ +--- +:backends: + - yaml +:yaml: + :datadir: /tmp/kitchen/hiera +:hierarchy: + - common diff --git a/kitchenci/hieradata/common.yaml b/kitchenci/hieradata/common.yaml new file mode 100644 index 0000000..2baff6a --- /dev/null +++ b/kitchenci/hieradata/common.yaml @@ -0,0 +1,34 @@ +--- +cassandra::version: "4.7.0-1" +cassandra::opscenter_version: "5.1.3-1" +cassandra::using_dse: true +cassandra::config_path: /etc/dse/cassandra +cassandra_home: /var/lib/cassandra +cassandra_home_mode: 755 +cassandra::service_name: "dse" +cassandra::package_name: "dse-full" +cassandra::repo_baseurl: "http://auto_cakesolutions.net:T4MAbMsNBvtlSKu@rpm.datastax.com/enterprise" +cassandra::seeds: [ "%{::ipaddress_eth0}" ] +cassandra::listen_address: "%{::ipaddress_eth0}" +cassandra::broadcast_address: "%{hiera('cassandra::listen_address')}" +cassandra::rpc_address: '0.0.0.0' +cassandra::broadcast_rpc_address: "%{hiera('cassandra::broadcast_address')}" +cassandra::cluster_name: 'testCassandra' +cassandra::endpoint_snitch: "SimpleSnitch" +cassandra::dse_audit_logging_enabled: true +cassandra::dse_audit_logger: "SLF4JAuditWriter" +cassandra::dse_audit_included_categories: "ADMIN, AUTH, QUERY" +cassandra::service_enable: "true" +cassandra::service_ensure: "running" +cassandra::opscenter_service_enable: "true" +cassandra::opscenter_service_ensure: "running" +cassandra::cassandra_seed_hosts: "%{::seed_a_eni_ip},%{::seed_b_eni_ip},%{::seed_c_eni_ip}" +cassandra::datastax_agent_stomp_interface: "%{::ipaddress}" +cassandra::datastax_agent_additional_jvm_opts: + - "-Dorg.xerial.snappy.tempdir=/var/lib/datastax-agent/" + - "-Djava.io.tmpdir=/var/lib/datastax-agent/" +cassandra::additional_jvm_opts: + - "-Dorg.xerial.snappy.tempdir=/var/lib/cassandra/" + - "-Dcom.sun.management.jmxremote.rmi.port=48888" + - "-Djava.io.tmpdir=/var/lib/cassandra/" + - "-Dconsistent.rangemovement=false" diff --git a/kitchenci/manifests/site.pp b/kitchenci/manifests/site.pp new file mode 100644 index 0000000..e5bd0d6 --- /dev/null +++ b/kitchenci/manifests/site.pp @@ -0,0 +1 @@ +include cassandra diff --git a/kitchenci/test/integration/default/serverspec/conf_spec.rb b/kitchenci/test/integration/default/serverspec/conf_spec.rb new file mode 100644 index 0000000..8bf5c64 --- /dev/null +++ b/kitchenci/test/integration/default/serverspec/conf_spec.rb @@ -0,0 +1,119 @@ +require 'serverspec' + +set :backend, :exec + +## checking successfull puppet run +describe command('grep fail /var/lib/puppet/state/last_run_summary.yaml |grep -v "fail.*:\ 0”') do + its(:exit_status) { should eq 1 } +end + +describe user('cassandra') do + it { should exist } +end + +describe group('cassandra') do + it { should exist } +end + +describe file('/var/lib/cassandra/data') do + it { should be_directory } + it { should be_mode 644 } + it { should be_owned_by 'cassandra' } + it { should be_grouped_into 'cassandra' } +end + +describe file('/etc/dse/cassandra/cassandra-env.sh') do + it { should be_file } + it { should be_mode 644 } + it { should be_owned_by 'cassandra' } + it { should be_grouped_into 'cassandra' } + its(:content) { should match /JVM_OPTS=\"\$JVM_OPTS -Dorg.xerial.snappy.tempdir=\/var\/lib\/cassandra\/\"/ } + its(:content) { should match /JVM_OPTS=\"\$JVM_OPTS -Dcom.sun.management.jmxremote.rmi.port=48888\"/ } + its(:content) { should match /JVM_OPTS=\"\$JVM_OPTS -Djava.io.tmpdir=\/var\/lib\/cassandra\/\"/ } + its(:content) { should match /JVM_OPTS=\"\$JVM_OPTS -Dconsistent.rangemovement=false/ } + its(:content) { should match /JMX_PORT=\"7199\"/ } +end + +describe file('/etc/dse/cassandra/cassandra.yaml') do + it { should be_file } + it { should be_mode 644 } + it { should be_owned_by 'cassandra' } + it { should be_grouped_into 'cassandra' } + its(:content) { should match /cluster_name: 'testCassandra'/} + its(:content) { should match /num_tokens: 256/} + its(:content) { should match /initial_token: /} + its(:content) { should match /authenticator: AllowAllAuthenticator/} + its(:content) { should match /authorizer: AllowAllAuthorizer/} + its(:content) { should match /partitioner: org.apache.cassandra.dht.Murmur3Partitioner/} + its(:content) { should match /- \/var\/lib\/cassandra\/data/} + its(:content) { should match /commitlog_directory: \/var\/lib\/cassandra\/commitlog/} + its(:content) { should match /disk_failure_policy: stop/} + its(:content) { should match /saved_caches_directory: \/var\/lib\/cassandra\/saved_caches/} + its(:content) { should match /seeds: 10.0.2.15/} #::ipaddress_eth0 + its(:content) { should match /concurrent_reads: 16/} # $::processorcount * 8 ==> 16 + its(:content) { should match /concurrent_writes: 16/} # $::processorcount * 8 ==> 16 + its(:content) { should match /storage_port: 7000/} + its(:content) { should match /listen_address: 10.0.2.15/} #::ipaddress_eth0 + its(:content) { should match /broadcast_address: 10.0.2.15/} #::ipaddress_eth0 + its(:content) { should match /start_native_transport: true/} + its(:content) { should match /native_transport_port: 9042/} + its(:content) { should match /start_rpc: true/} + its(:content) { should match /rpc_port: 9160/} + its(:content) { should match /broadcast_rpc_address: 10.0.2.15/} #::ipaddress_eth0 + its(:content) { should match /rpc_server_type: hsha/} + its(:content) { should match /rpc_min_threads: 0/} + its(:content) { should match /rpc_max_threads: 2048/} + its(:content) { should match /incremental_backups: false/} + its(:content) { should match /snapshot_before_compaction: false/} + its(:content) { should match /auto_snapshot: true/} + its(:content) { should match /endpoint_snitch: SimpleSnitch/} +### server_encryption_options: + its(:content) { should match /internode_encryption: none/} + its(:content) { should match /keystore: /} + its(:content) { should match /keystore_password: /} + its(:content) { should match /require_client_auth: false/} + its(:content) { should match /truststore: /} + its(:content) { should match /truststore_password: /} + its(:content) { should match /protocol: TLS/} + its(:content) { should match /algorithm: SunX509/} + its(:content) { should match /store_type: JKS/} +###client_encryption_options: + its(:content) { should match /enabled: false/} + its(:content) { should match /keystore: /} + its(:content) { should match /keystore_password: /} + its(:content) { should match /require_client_auth: false/} + its(:content) { should match /protocol: TLS/} + its(:content) { should match /algorithm: SunX509/} + its(:content) { should match /store_type: JKS/} +end + +describe file('/etc/dse/dse.yaml') do + it { should be_file } + it { should be_mode 644 } + it { should be_owned_by 'cassandra' } + it { should be_grouped_into 'cassandra' } +### Audit logging options + its(:content) { should match /enabled: true/} + its(:content) { should match /logger: SLF4JAuditWriter/} + its(:content) { should match /included_categories: ADMIN, AUTH, QUERY/} + its(:content) { should match /# excluded_categories:/} + its(:content) { should match /# included_keyspaces:/} + its(:content) { should match /# excluded_keyspaces:/} +end + +describe file('/etc/datastax-agent/datastax-agent-env.sh') do + it { should be_file } + it { should be_mode 644 } + it { should be_owned_by 'cassandra' } + it { should be_grouped_into 'cassandra' } + its(:content) { should match /JVM_OPTS=\"\$JVM_OPTS -Dorg.xerial.snappy.tempdir=\/var\/lib\/datastax-agent\/\"/ } + its(:content) { should match /JVM_OPTS=\"\$JVM_OPTS -Djava.io.tmpdir=\/var\/lib\/datastax-agent\/\"/} +end + +describe file('/var/lib/datastax-agent/conf/address.yaml') do + it { should be_file } + it { should be_mode 644 } + it { should be_owned_by 'cassandra' } + it { should be_grouped_into 'cassandra' } + its(:content) { should match /stomp_interface: 10.0.2.15/} #::ipaddress_eth0 +end diff --git a/kitchenci/test/integration/default/serverspec/install_spec.rb b/kitchenci/test/integration/default/serverspec/install_spec.rb new file mode 100644 index 0000000..c51a0ef --- /dev/null +++ b/kitchenci/test/integration/default/serverspec/install_spec.rb @@ -0,0 +1,22 @@ +require 'serverspec' + +set :backend, :exec + +## checking successfull puppet run +describe command('grep fail /var/lib/puppet/state/last_run_summary.yaml |grep -v "fail.*:\ 0”') do + its(:exit_status) { should eq 1 } +end + +## java_package is defined twice in params.pp of puppet-cassandra module with two different values, +## seems like java-1.7.0-openjdk is the correct default value not openjdk-7-jre +describe package('java-1.7.0-openjdk') do + it { should be_installed.by('rpm') } +end + +describe package('dse-full') do + it { should be_installed.by('rpm').with_version('4.7.0-1') } +end + +describe package('python26-cql') do + it { should be_installed.by('rpm') } +end diff --git a/kitchenci/test/integration/default/serverspec/repo_spec.rb b/kitchenci/test/integration/default/serverspec/repo_spec.rb new file mode 100644 index 0000000..1624efd --- /dev/null +++ b/kitchenci/test/integration/default/serverspec/repo_spec.rb @@ -0,0 +1,21 @@ +require 'serverspec' + +set :backend, :exec + +## checking successfull puppet run +describe command('grep fail /var/lib/puppet/state/last_run_summary.yaml |grep -v "fail.*:\ 0”') do + its(:exit_status) { should eq 1 } +end + +## check Cassandra repo +describe yumrepo('datastax') do + it { should exist } + it { should be_enabled } +end + +#TODO: add matches for the rest of repo file content +describe file('/etc/yum.repos.d/datastax.repo') do + it { should be_file } + its(:content) { should match /baseurl=http:\/\/auto_cakesolutions.net:T4MAbMsNBvtlSKu@rpm.datastax.com\/enterprise/ } + its(:content) { should match /gpgcheck=0/ } +end \ No newline at end of file diff --git a/kitchenci/test/integration/default/serverspec/service_spec.rb b/kitchenci/test/integration/default/serverspec/service_spec.rb new file mode 100644 index 0000000..3a7411f --- /dev/null +++ b/kitchenci/test/integration/default/serverspec/service_spec.rb @@ -0,0 +1,18 @@ +require 'serverspec' + +set :backend, :exec + +## checking successfull puppet run +describe command('grep fail /var/lib/puppet/state/last_run_summary.yaml |grep -v "fail.*:\ 0”') do + its(:exit_status) { should eq 1 } +end + +describe service('dse') do + it { should be_enabled } + it { should be_running } +end + +describe service('datastax-agent') do + it { should be_enabled } + it { should be_running } +end \ No newline at end of file diff --git a/manifests/config.pp b/manifests/config.pp index 032631e..5287444 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -168,20 +168,20 @@ content => template("${module_name}/dse.yaml.erb"), } - file { "/etc/datastax-agent/datastax-agent-env.sh": + file { '/etc/datastax-agent/datastax-agent-env.sh': ensure => file, content => template("${module_name}/datastax-agent-env.sh.erb"), notify => Service['datastax-agent'], } - file { "/var/lib/datastax-agent/conf/address.yaml": + file { '/var/lib/datastax-agent/conf/address.yaml': ensure => file, content => template("${module_name}/address.yaml.erb"), notify => Service['datastax-agent'], } } - if(($dse_audit_logging_enabled) and ($dse_audit_logger=="Log4JAuditWriter")) { + if(($dse_audit_logging_enabled) and ($dse_audit_logger=='Log4JAuditWriter')) { file { "${dse_config_path}/cassandra/log4j-server.properties": ensure => file, content => template("${module_name}/log4j-server.properties.erb"), @@ -189,17 +189,17 @@ } if($using_opscenter) { - file { "/etc/opscenter/opscenterd.conf": + file { '/etc/opscenter/opscenterd.conf': ensure => file, owner => opscenter, group => opscenter, content => template("${module_name}/opscenterd.conf.erb"), } - file { "/etc/opscenter/clusters": + file { '/etc/opscenter/clusters': ensure => directory, - owner => opscenter, - group => opscenter, + owner => opscenter, + group => opscenter, } file { "/etc/opscenter/clusters/${cluster_name}.conf": diff --git a/manifests/init.pp b/manifests/init.pp index 2ccc27a..5c2f81e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -167,12 +167,12 @@ validate_re($snapshot_before_compaction, '^(true|false)$') validate_re($auto_snapshot, '^(true|false)$') validate_re($multithreaded_compaction, '^(true|false)$') - validate_re("${concurrent_reads}", '^[0-9]+$') - validate_re("${concurrent_writes}", '^[0-9]+$') - validate_re("${num_tokens}", '^[0-9]+$') + validate_re($concurrent_reads, '^[0-9]+$') + validate_re($concurrent_writes, '^[0-9]+$') + validate_re($num_tokens, '^[0-9]+$') validate_re($internode_compression, '^(all|dc|none)$') validate_re($disk_failure_policy, '^(stop|best_effort|ignore)$') - validate_re("${thread_stack_size}", '^[0-9]+$') + validate_re($thread_stack_size, '^[0-9]+$') validate_re($service_enable, '^(true|false)$') validate_re($service_ensure, '^(running|stopped)$') @@ -237,7 +237,7 @@ if(!is_integer($datastax_agent_use_ssl)) { fail('datastax_agent_use_ssl must be a nuber between 0 and 1') } - validate_re("$datastax_agent_use_ssl", '^[0-1]$') + validate_re($datastax_agent_use_ssl, '^[0-1]$') validate_string($datastax_agent_ssl_keystore) validate_string($datastax_agent_ssl_keystore_password) validate_string($datastax_agent_ssl_ca_certs) @@ -296,7 +296,7 @@ validate_string($dse_audit_included_categories) validate_string($dse_audit_excluded_categories) validate_string($dse_audit_included_keyspaces) - validate_string($dse_audit_excluded_keyspaces) + validate_string($dse_audit_excluded_keyspaces) } diff --git a/manifests/install.pp b/manifests/install.pp index 434e711..22f2789 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -2,8 +2,8 @@ if !defined (Package['java']) { package { 'java': - ensure => installed, - name => "$java_package" + ensure => installed, + name => $java_package } } diff --git a/manifests/params.pp b/manifests/params.pp index d6480a5..7589bb8 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -431,22 +431,22 @@ } $incremental_backups = $::cassandra_incremental_backups ? { - undef => 'false', + undef => false, default => $::cassandra_incremental_backups, } $snapshot_before_compaction = $::cassandra_snapshot_before_compaction ? { - undef => 'false', + undef => false, default => $::cassandra_snapshot_before_compaction, } $auto_snapshot = $::cassandra_auto_snapshot ? { - undef => 'true', + undef => true, default => $::cassandra_auto_snapshot, } $multithreaded_compaction = $::cassandra_multithreaded_compaction ? { - undef => 'false', + undef => false, default => $::cassandra_multithreaded_compaction, } @@ -466,7 +466,7 @@ } $start_native_transport = $::cassandra_start_native_transport ? { - undef => 'true', + undef => true, default => $::cassandra_start_native_transport, } @@ -476,7 +476,7 @@ } $start_rpc = $::cassandra_start_rpc ? { - undef => 'true', + undef => true, default => $::cassandra_start_rpc, } @@ -491,7 +491,7 @@ } $service_enable = $::cassandra_service_enable ? { - undef => 'true', + undef => true, default => $::cassandra_service_enable, } @@ -501,7 +501,7 @@ } $opscenter_service_enable = $::cassandra_opscenter_service_enable ? { - undef => 'true', + undef => true, default => $::cassandra_opscenter_service_enable, } diff --git a/manifests/repo.pp b/manifests/repo.pp index 7e8ba06..99037b2 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -12,15 +12,15 @@ case $::osfamily { 'Debian': { class { 'cassandra::repo::debian': - repo_name => $repo_name, - location => $baseurl, - repos => $repos, - release => $release, - key => $key_id, - key_source => $gpgkey, - pin => $pin, - before => Anchor['cassandra::repo::end'], - require => Anchor['cassandra::repo::begin'], + repo_name => $repo_name, + location => $baseurl, + repos => $repos, + release => $release, + key => $key_id, + key_source => $gpgkey, + pin => $pin, + before => Anchor['cassandra::repo::end'], + require => Anchor['cassandra::repo::begin'], } } 'RedHat': { diff --git a/manifests/repo/debian.pp b/manifests/repo/debian.pp index 2732d65..25da397 100644 --- a/manifests/repo/debian.pp +++ b/manifests/repo/debian.pp @@ -25,7 +25,7 @@ notice("cassandra will be pinned to ${version_pin}") apt::pin { "hold_cassandra_at_${version_pin}": - packages => "cassandra", + packages => 'cassandra', version => $version_pin, priority => 1001, }