diff --git a/spec/classes/apache_repo_spec.rb b/spec/classes/apache_repo_spec.rb index c6fd301..4225b25 100644 --- a/spec/classes/apache_repo_spec.rb +++ b/spec/classes/apache_repo_spec.rb @@ -1,78 +1,69 @@ require 'spec_helper' describe 'cassandra::apache_repo' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $source) {}', - 'define apt::source ($location, $comment, $release, $include) {}' - ] - end - context 'On a RedHat OS with defaults for all parameters' do let :facts do { osfamily: 'RedHat' } 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: 'Ubuntu', lsbdistrelease: '14.04' } end it do is_expected.to have_resource_count(3) 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_repo_spec.rb b/spec/classes/datastax_repo_spec.rb index 04b1886..61581de 100644 --- a/spec/classes/datastax_repo_spec.rb +++ b/spec/classes/datastax_repo_spec.rb @@ -1,71 +1,62 @@ require 'spec_helper' describe 'cassandra::datastax_repo' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $source) {}', - 'define apt::source ($location, $comment, $release, $include) {}' - ] - end - context 'On a RedHat OS with defaults for all parameters' do let :facts do { osfamily: 'RedHat' } 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: 'Ubuntu', lsbdistrelease: '14.04' } end it do is_expected.to have_resource_count(3) 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 7f18b1f..aaba78e 100644 --- a/spec/classes/dse_spec.rb +++ b/spec/classes/dse_spec.rb @@ -1,28 +1,21 @@ require 'spec_helper' describe 'cassandra::dse' do - let(:pre_condition) do - [ - 'class stdlib () {}', - 'define file_line($line, $path, $match) {}' - ] - end - context 'with defaults for all parameters' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } end it do - is_expected.to have_resource_count(6) + 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 52680f3..3296555 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,403 +1,388 @@ require 'spec_helper' describe 'cassandra' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $source) {}', - 'define apt::source ($location, $comment, $release, $include) {}', - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'On an unknown OS with defaults for all parameters' do let :facts do { operatingsystemmajrelease: 10, osfamily: 'Darwin' } end it { is_expected.to raise_error(Puppet::Error) } end context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } 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', 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: {}, systemctl: '/usr/bin/systemctl' ) end end context 'On RedHat 7 with data directories specified.' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } 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' } 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' } 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 let :facts do { operatingsystemmajrelease: 7, osfamily: 'Debian', lsbdistid: 'Ubuntu', lsbdistrelease: '14.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' } 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' } 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' } 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' } 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' } 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' } 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 8b288da..805dfc3 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -1,161 +1,152 @@ require 'spec_helper' describe 'cassandra::java' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $server) {}', - 'define apt::source ($location, $comment, $release, $repos) {}' - ] - end - context 'On a RedHat OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } 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, + operatingsystemmajrelease: '7', osfamily: 'Debian' } 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, + operatingsystemmajrelease: '7', osfamily: 'Debian' } 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, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } 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, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } 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, + operatingsystemmajrelease: '7', osfamily: 'Debian' } 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/schema_spec.rb b/spec/classes/schema_spec.rb index bd2f509..d468623 100644 --- a/spec/classes/schema_spec.rb +++ b/spec/classes/schema_spec.rb @@ -1,142 +1,131 @@ require 'spec_helper' describe 'cassandra::schema' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Ensure that a connection test is made.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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 'Test that users can specify a credentials file.' do let :facts do { id: 'root', gid: 'root', operatingsystemmajrelease: 7, osfamily: 'Debian' } end let :params do { cqlsh_client_config: '/root/.puppetcqlshrc' } end it do is_expected.to contain_file('/root/.puppetcqlshrc').with( ensure: 'file', group: 'root', mode: '0600', owner: 'root', 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', operatingsystemmajrelease: 7, osfamily: 'Debian' } end let :params do { cqlsh_client_config: '/root/.puppetcqlshrc', cqlsh_password: 'topsecret' } end it do is_expected.to contain_file('/root/.puppetcqlshrc').with( ensure: 'file', group: 'root', mode: '0600', owner: 'root', 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' } 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 9d7b80c..14516f9 100644 --- a/spec/classes/system/sysctl_spec.rb +++ b/spec/classes/system/sysctl_spec.rb @@ -1,39 +1,28 @@ require 'spec_helper' describe 'cassandra::system::sysctl' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } 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/defines/private/firewall_ports/rule_spec.rb b/spec/defines/private/firewall_ports/rule_spec.rb index 1962c3b..a507c56 100644 --- a/spec/defines/private/firewall_ports/rule_spec.rb +++ b/spec/defines/private/firewall_ports/rule_spec.rb @@ -1,25 +1,21 @@ require 'spec_helper' describe 'cassandra::private::firewall_ports::rule' do - let(:pre_condition) do - ['define firewall ($action, $dport, $proto, $source) {}'] - end - context 'Test that rules can be set.' do let(:title) { '200_Public_0.0.0.0/0' } let :params do { ports: [8888, 22] } end it do is_expected.to contain_firewall('200 - Cassandra (Public) - 0.0.0.0/0').with( action: 'accept', dport: [8888, 22], proto: 'tcp', source: '0.0.0.0/0' ) is_expected.to have_resource_count(2) end end end diff --git a/spec/defines/schema/cql_type_spec.rb b/spec/defines/schema/cql_type_spec.rb index bfe5132..9e9b4ee 100644 --- a/spec/defines/schema/cql_type_spec.rb +++ b/spec/defines/schema/cql_type_spec.rb @@ -1,84 +1,73 @@ require 'spec_helper' describe 'cassandra::schema::cql_type' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'CQL TYPE (fullname)' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'fullname' } let(:params) do { 'keyspace' => 'Excelsior', fields: { 'firstname' => 'text', 'lastname' => 'text' } } end it do is_expected.to compile is_expected.to contain_class('cassandra::schema') is_expected.to contain_cassandra__schema__cql_type('fullname') is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE TYPE IF NOT EXISTS Excelsior.fullname (firstname text, lastname text)" localhost 9042') end end context 'Set ensure to absent' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'address' } let(:params) do { 'ensure' => 'absent', 'keyspace' => 'Excalibur' } end it do is_expected.to compile is_expected.to contain_cassandra__schema__cql_type('address') is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP type Excalibur.address" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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 7383aa8..f45d716 100644 --- a/spec/defines/schema/index_spec.rb +++ b/spec/defines/schema/index_spec.rb @@ -1,132 +1,121 @@ require 'spec_helper' describe 'cassandra::schema::index' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Create a basic index' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { keys: 'lname', keyspace: 'mykeyspace', table: 'users' } end it do is_expected.to compile is_expected.to contain_cassandra__schema__index('user_index') is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE INDEX IF NOT EXISTS user_index ON mykeyspace.users (lname)" localhost 9042') end end context 'Create a custom index.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', table: 'users' } end it do is_expected.to compile is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\'" localhost 9042') end end context 'Create a custom index with options.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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' } end it do is_expected.to compile is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\' WITH OPTIONS = {\'storage\': \'/mnt/ssd/indexes/\'}" localhost 9042') end end context 'Drop Index' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { ensure: 'absent', keys: 'lname', keyspace: 'Excelsior', table: 'users' } end it do is_expected.to compile is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP INDEX Excelsior.user_index" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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 fc62eb2..25b9213 100644 --- a/spec/defines/schema/keyspace_spec.rb +++ b/spec/defines/schema/keyspace_spec.rb @@ -1,110 +1,99 @@ require 'spec_helper' describe 'cassandra::schema::keyspace' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Set ensure to present (SimpleStrategy)' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'SimpleStrategy', 'replication_factor' => 3 } } end it do is_expected.to compile is_expected.to contain_class('cassandra::schema') is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = { \'class\' : \'SimpleStrategy\', \'replication_factor\' : 3 } AND DURABLE_WRITES = true" localhost 9042') end end context 'Set ensure to present (NetworkTopologyStrategy)' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'NetworkTopologyStrategy', 'dc1' => '3', 'dc2' => '2' } } end it do is_expected.to contain_cassandra__schema__keyspace('foobar') is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = { \'class\' : \'NetworkTopologyStrategy\', \'dc1\': 3, \'dc2\': 2 } AND DURABLE_WRITES = true" localhost 9042') end end context 'Set ensure to absent' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'absent' } end it do is_expected.to compile is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP KEYSPACE foobar" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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 80424c9..7bd53c8 100644 --- a/spec/defines/schema/permission_spec.rb +++ b/spec/defines/schema/permission_spec.rb @@ -1,185 +1,174 @@ require 'spec_helper' describe 'cassandra::schema::permission' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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' } 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' } end let(:params) do { user_name: 'spillman', permission_name: 'SELECT' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('spillman:SELECT:ALL') is_expected.to contain_exec('GRANT SELECT ON ALL KEYSPACES TO spillman') end end context 'akers:modify:field' do let(:title) { 'akers:modify:field' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'akers', keyspace_name: 'field', permission_name: 'MODIFY' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('akers:modify:field') is_expected.to contain_exec('GRANT MODIFY ON KEYSPACE field TO akers') end end context 'boone:alter:forty9ers' do let(:title) { 'boone:alter:forty9ers' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'ALTER' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('boone:alter:forty9ers') is_expected.to contain_exec('GRANT ALTER ON KEYSPACE forty9ers TO boone') end end context 'boone:ALL:ravens.plays' do let(:title) { 'boone:ALL:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'boone', keyspace_name: 'ravens', table_name: 'plays' } end it do is_expected.to have_resource_count(18) is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays') is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - ALTER').with( ensure: 'present', user_name: 'boone', keyspace_name: 'ravens', permission_name: 'ALTER', table_name: 'plays' ) is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - AUTHORIZE') is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - DROP') is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - MODIFY') is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - SELECT') is_expected.to contain_exec('GRANT ALTER ON TABLE ravens.plays TO boone') is_expected.to contain_exec('GRANT AUTHORIZE ON TABLE ravens.plays TO boone') is_expected.to contain_exec('GRANT DROP ON TABLE ravens.plays TO boone') is_expected.to contain_exec('GRANT MODIFY ON TABLE ravens.plays TO boone') is_expected.to contain_exec('GRANT SELECT ON TABLE ravens.plays TO boone') end end context 'REVOKE boone:SELECT:ravens.plays' do let(:title) { 'REVOKE boone:SELECT:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { ensure: 'absent', user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'SELECT' } end it do is_expected.to have_resource_count(9) is_expected.to contain_cassandra__schema__permission('REVOKE boone:SELECT:ravens.plays') is_expected.to contain_exec('REVOKE SELECT ON KEYSPACE forty9ers FROM boone') end end end diff --git a/spec/defines/schema/table_spec.rb b/spec/defines/schema/table_spec.rb index 5bbc73f..73d15da 100644 --- a/spec/defines/schema/table_spec.rb +++ b/spec/defines/schema/table_spec.rb @@ -1,93 +1,82 @@ require 'spec_helper' describe 'cassandra::schema::table' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Create Table' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'users' } let(:params) do { 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') is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE TABLE IF NOT EXISTS Excelsior.users (userid text, username FROZEN, emails set, top_scores list, todo map, tuple, PRIMARY KEY (userid)) WITH COMPACT STORAGE AND ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'" localhost 9042') end end context 'Drop Table' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'users' } let(:params) do { keyspace: 'Excelsior', ensure: 'absent' } end it do is_expected.to compile is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP TABLE IF EXISTS Excelsior.users" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } 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 967f47f..9c7af1b 100644 --- a/spec/defines/schema/user_spec.rb +++ b/spec/defines/schema/user_spec.rb @@ -1,211 +1,200 @@ require 'spec_helper' describe 'cassandra::schema::user' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Create a supper user on cassandrarelease undef' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: nil } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers WITH PASSWORD \'Niner2\' SUPERUSER" localhost 9042' ) end end context 'Create a supper user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '2.0.1' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers WITH PASSWORD \'Niner2\' SUPERUSER" localhost 9042' ) end end context 'Create a user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '2.0.1' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2' } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers WITH PASSWORD \'Niner2\' NOSUPERUSER" localhost 9042' ) 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' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', superuser: true } end it do is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE ROLE IF NOT EXISTS akers WITH PASSWORD = \'Niner2\' AND SUPERUSER = true AND LOGIN = true" localhost 9042' ) end end context 'Create a user without login in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '3.0.9' } end let(:title) { 'bob' } let(:params) do { password: 'kaZe89a', login: false } end it do is_expected.to contain_cassandra__schema__user('bob').with_ensure('present') is_expected.to contain_exec('Create user (bob)').with( command: '/usr/bin/cqlsh -e "CREATE ROLE IF NOT EXISTS bob WITH PASSWORD = \'kaZe89a\'" localhost 9042' ) end end context 'Drop a user in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '3.0.9' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', ensure: 'absent' } end it do is_expected.to contain_exec('Delete user (akers)').with( command: '/usr/bin/cqlsh -e "DROP ROLE akers" localhost 9042' ) end end context 'Drop a user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '2.0.2' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', ensure: 'absent' } end it do is_expected.to contain_exec('Delete user (akers)').with( command: '/usr/bin/cqlsh -e "DROP USER akers" localhost 9042' ) end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end it { is_expected.to raise_error(Puppet::Error) } end end