From 0d101271d37dcc6f5908471400bd4f5a6b74f8ad Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Thu, 4 Jun 2015 16:47:18 +0200 Subject: [PATCH] Cassandra: Initial commit Allow puppet-openstack-cloud to deploy Cassandra nodes and hence cluster. Change-Id: I5c9b64def9406357a817d48a415e986401b90fa9 (cherry picked from commit 1159275582a8c4d9539e6e3a416fb83dd8cb1f43) --- Puppetfile | 3 + manifests/database/nosql/cassandra.pp | 40 ++++++++++ .../cloud_database_nosql_cassandra_spec.rb | 79 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 manifests/database/nosql/cassandra.pp create mode 100644 spec/classes/cloud_database_nosql_cassandra_spec.rb diff --git a/Puppetfile b/Puppetfile index 1aacad81..8e1ccb38 100644 --- a/Puppetfile +++ b/Puppetfile @@ -74,6 +74,9 @@ mod 'cloud', mod 'common', :git => 'git://github.com/enovance/puppet-module-common.git', :ref => '2d0606fce1078222dd483e731ec32807f5b4ca53' +mod 'cassandra', + :git => 'git://github.com/enovance/cassandra.git', + :ref => '124f472128d178f52e2233d6aa8a0f1285f73c49' mod 'concat', :git => 'git://github.com/enovance/puppet-concat.git', :ref => 'ab06c2b8c09d9da82b53a62a5389427720519cd5' diff --git a/manifests/database/nosql/cassandra.pp b/manifests/database/nosql/cassandra.pp new file mode 100644 index 00000000..abcacd38 --- /dev/null +++ b/manifests/database/nosql/cassandra.pp @@ -0,0 +1,40 @@ +# +# Copyright (C) 2015 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: cloud::database::nosql::cassandra +# +# Install a Cassandra node +# +# === Parameters: +# +# [*firewall_settings*] +# (optional) Allow to add custom parameters to firewall rules +# Should be an hash. +# Default to {} +# +class cloud::database::nosql::cassandra ( + $firewall_settings = {}, +){ + + include ::cassandra + + if $::cloud::manage_firewall { + cloud::firewall::rule{ '100 allow cassandra access': + port => '7000', + extras => $firewall_settings, + } + } + +} diff --git a/spec/classes/cloud_database_nosql_cassandra_spec.rb b/spec/classes/cloud_database_nosql_cassandra_spec.rb new file mode 100644 index 00000000..1445eccd --- /dev/null +++ b/spec/classes/cloud_database_nosql_cassandra_spec.rb @@ -0,0 +1,79 @@ +# +# Copyright (C) 2015 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for cloud::cache::cassandra +# + +require 'spec_helper' + +describe 'cloud::database::nosql::cassandra' do + + shared_examples_for 'cassandra server' do + + let :params do + { } + end + + it 'configure cassandra with some params' do + is_expected.to contain_class('cassandra') + end + + context 'with default firewall enabled' do + let :pre_condition do + "class { 'cloud': manage_firewall => true }" + end + it 'configure cassandra firewall rules' do + is_expected.to contain_firewall('100 allow cassandra access').with( + :port => '7000', + :proto => 'tcp', + :action => 'accept', + ) + end + end + + context 'with custom firewall enabled' do + let :pre_condition do + "class { 'cloud': manage_firewall => true }" + end + before :each do + params.merge!(:firewall_settings => { 'limit' => '50/sec' } ) + end + it 'configure cassandra firewall rules with custom parameter' do + is_expected.to contain_firewall('100 allow cassandra access').with( + :port => '7000', + :proto => 'tcp', + :action => 'accept', + :limit => '50/sec', + ) + end + end + + end + + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian' } + end + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat' } + end + + it_configures 'cassandra server' + end + +end