diff --git a/.fixtures.yml b/.fixtures.yml index 8bc5f6b..1bce9d0 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -6,4 +6,7 @@ fixtures: stdlib: "puppetlabs-stdlib" inifile: "puppetlabs-inifile" zookeeper: "deric-zookeeper" + cassandra: "midonet-cassandra" datacat: "richardc-datacat" + java: "puppetlabs-java" + module_data: "ripienaar-module_data" diff --git a/data/common.yaml b/data/common.yaml index bb5ecde..7c05529 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -3,3 +3,8 @@ midonet::zookeeper::servers: - id: 1 host: 'localhost' midonet::zookeeper::server_id: '1' + +# Cassandra-based attributes +midonet::cassandra::seeds: + - 'localhost' +midonet::cassandra::seed_address: 'localhost' diff --git a/data/osfamily/Debian/common.yaml b/data/osfamily/Debian/common.yaml index 8ac4462..b478954 100644 --- a/data/osfamily/Debian/common.yaml +++ b/data/osfamily/Debian/common.yaml @@ -27,3 +27,7 @@ midonet::neutron_plugin::midonet_api_ip: 'localhost' midonet::neutron_plugin::username: 'fake_user' midonet::neutron_plugin::password: 'fake_password' midonet::neutron_plugin::project_id: 'service' + +midonet::cassandra::conf_dir: '/etc/cassandra' +midonet::cassandra::pid_dir: '/var/run/cassandra' +midonet::cassandra::service_path: '/usr/sbin' diff --git a/data/osfamily/RedHat/common.yaml b/data/osfamily/RedHat/common.yaml index d1b1425..85e3f03 100644 --- a/data/osfamily/RedHat/common.yaml +++ b/data/osfamily/RedHat/common.yaml @@ -26,3 +26,7 @@ midonet::neutron_plugin::midonet_api_ip: 'localhost' midonet::neutron_plugin::username: 'fake_user' midonet::neutron_plugin::password: 'fake_password' midonet::neutron_plugin::project_id: 'service' + +midonet::cassandra::pid_dir: '/var/run/cassandra' +midonet::cassandra::conf_dir: '/etc/cassandra/default.conf' +midonet::cassandra::service_path: '/sbin' diff --git a/manifests/cassandra.pp b/manifests/cassandra.pp new file mode 100644 index 0000000..5302c54 --- /dev/null +++ b/manifests/cassandra.pp @@ -0,0 +1,130 @@ +# == Class: ::midonet::cassandra +# +# Install and run the cassandra component +# +# === Parameters +# +# [*seeds*] +# Full list of cassandra seeds that belong to a cluster. +# [*seed_address*] +# IP address to bind for this instance. (Must belong to the +# seeders list. +# [*storage_port*] +# Inter-node cluster communication port (defaulted to 7000). +# [*ssl_storage_port*] +# SSL Inter-node cluster communication port (defaulted to 7001). +# [*client_port*] +# Cassandra client port (defaulted to 9042). +# [*client_port_thrift*] +# Cassandra client port thrift (defaulted to 9160). +# +# +# === Examples +# +# * The easiest way to run the class is: +# +# include ::cassandra +# +# And a cassandra single-machine cluster will be installed, binding the +# 'localhost' address. +# +# * Run a single-machine cluster but binding a hostname or another address +# would be: +# +# class {'::midonet::cassandra': +# seeds => ['192.168.2.2'], +# seed_address => '192.168.2.2', +# storage_port => 7000, +# ssl_storage_port => 7001, +# client_port => 9042, +# client_port_thrift => 9042, +# } +# +# * All the ports must be configured the same in all the nodes in the cluster. +# +# * For cluster of nodes, use the same 'seeds' value, but change the +# seed_address of each node: +# +# - On node1 +# class {'::midonet::cassandra': +# seeds => ['node_1', 'node_2', 'node_3'], +# seed_address => 'node_1' +# storage_port => 7000, +# ssl_storage_port => 7001, +# client_port => 9042, +# client_port_thrift => 9042, +# } +# - On node2 +# class {'::midonet::cassandra': +# seeds => ['node_1', 'node_2', 'node_3'], +# seed_address => 'node_2' +# storage_port => 7000, +# ssl_storage_port => 7001, +# client_port => 9042, +# client_port_thrift => 9042, +# } +# - On node3 +# class {'::midonet::cassandra': +# seeds => ['node_1', 'node_2', 'node_3'], +# seed_address => 'node_3' +# storage_port => 7000, +# ssl_storage_port => 7001, +# client_port => 9042, +# client_port_thrift => 9042, +# } +# +# NOTE: node_X can be either hostnames or ip addresses +# You can alternatively use the Hiera.yaml style: +# +# ::midonet::cassandra::seeds: +# - node_1 +# - node_2 +# - node_3 +# ::midonet::cassandra::seed_address: 'node_1' +# +# === Authors +# +# Midonet (http://midonet.org) +# +# === Copyright +# +# Copyright (c) 2015 Midokura SARL, All Rights Reserved. +# +# 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 midonet::cassandra ( + $seeds, + $seed_address, + $storage_port = '7000', + $ssl_storage_port = '7001', + $client_port = '9042', + $client_port_thrift = '9160', + $conf_dir, + $pid_dir, + $service_path) +{ + + class {'::cassandra': + seeds => $seeds, + seed_address => $seed_address, + storage_port => $storage_port, + ssl_storage_port => $ssl_storage_port, + client_port => $client_port, + client_port_thrift => $client_port_thrift, + conf_dir => $conf_dir, + pid_dir => $pid_dir, + service_path => $service_path + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index 3cc8f51..646b13a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -46,14 +46,14 @@ class midonet { class {'::midonet::zookeeper': } # Add cassandra - class {'::cassandra': } + class {'::midonet::cassandra': } # Add midonet-agent class { 'midonet::midonet_agent': zk_servers => [{ 'ip' => $::ipaddress} ], - require => [Class['::cassandra'], Class['::zookeeper']] + require => [Class['::midonet::cassandra'], Class['::midonet::zookeeper']] } # Add midonet-api diff --git a/spec/acceptance/midonet_spec.rb b/spec/acceptance/midonet_spec.rb index aace4d6..c1042b9 100644 --- a/spec/acceptance/midonet_spec.rb +++ b/spec/acceptance/midonet_spec.rb @@ -9,8 +9,8 @@ describe 'midonet all-in-one' do EOS # Run it twice for test the idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp) + apply_manifest(pp) end end end diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml index ca062de..082ec4c 100644 --- a/spec/acceptance/nodesets/default.yml +++ b/spec/acceptance/nodesets/default.yml @@ -1,4 +1,4 @@ -HOSTS: +HOSTS: ubuntu-14-04: platform: ubuntu-14.04-x64 image: midonet/ubuntu:14.04 diff --git a/spec/classes/midonet_cassandra_spec.rb b/spec/classes/midonet_cassandra_spec.rb new file mode 100644 index 0000000..232ea21 --- /dev/null +++ b/spec/classes/midonet_cassandra_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe 'midonet::cassandra' do + + let :params do + { + :seeds => ['192.168.7.2', '192.168.7.3', '192.168.7.4'], + :seed_address => '192.168.7.2' + } + end + + shared_examples_for 'cluster cassandra' do + + + before do + params.merge!(os_params) + end + + it 'should call cassandra module properly' do + is_expected.to contain_class('cassandra').with({ + 'seeds' => params[:seeds], + 'seed_address' => params[:seed_address], + 'storage_port' => '7000', + 'ssl_storage_port' => '7001', + 'client_port' => '9042', + 'client_port_thrift' => '9160' + }) + end + end + + context 'on Debian' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Ubuntu', + :lsbdistrelease => '14.04', + :lsbdistid => 'Ubuntu', + :lsbdistcodename => 'trusty', + :ipaddress => '127.0.0.1', + :hostname => 'test.puppet' + } + end + + let :os_params do + { + :pid_dir => '/var/run/cassandra', + :conf_dir => '/etc/cassandra', + :service_path => '/usr/sbin' + } + end + + it_configures 'cluster cassandra' + end + + context 'on RedHat' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + :operatingsystemmajrelease => 7, + :ipaddress => '127.0.0.1', + :hostname => 'test.puppet' + } + end + + let :os_params do + { + :pid_dir => '/var/run/cassandra', + :conf_dir => '/etc/cassandra/default.conf', + :service_path => '/sbin' + } + end + + it_configures 'cluster cassandra' + end +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 57417dd..1dd7002 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -18,7 +18,9 @@ RSpec.configure do |c| hosts.each do |host| copy_module_to(host, :source => proj_root, :module_name => 'midonet') scp_to(host, proj_root + '/data/hiera.yaml', "#{default['puppetpath']}/hiera.yaml") - shell("/bin/touch #{default['puppetpath']}/hiera.yaml") + scp_to(host, proj_root + '/data/common.yaml', "/var/lib/hiera") + scp_to(host, proj_root + '/data/osfamily', "/var/lib/hiera") + on host, puppet('module install ripienaar-module_data'), {:acceptable_exit_codes => [0,1] } on host, puppet('module install puppetlabs-stdlib --version 4.5.0'), { :acceptable_exit_codes => [0,1] } on host, puppet('module install deric-zookeeper'), {:acceptable_exit_codes => [0,1] }