| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
require 'spec_helper_acceptance' |
| 4 |
|
| 5 |
if hosts.length >= 3 |
| 6 |
describe 'configuring master and slave redis hosts' do |
| 7 |
let(:master_ip_address) do |
| 8 |
# hosts_as('master').inject({}) do |memo,host| |
| 9 |
# memo[host] = fact_on host, "ipaddress_enp0s8" |
| 10 |
# end |
| 11 |
'10.255.33.129' # hardcoding as vagrant ip for now |
| 12 |
end |
| 13 |
|
| 14 |
hosts_as('master').each do |host| |
| 15 |
context "should be able to configure a host as master on #{host}" do |
| 16 |
it 'works idempotently with no errors' do |
| 17 |
pp = <<-EOS |
| 18 |
# Stop firewall so we can easily connect |
| 19 |
service {'firewalld': |
| 20 |
ensure => 'stopped', |
| 21 |
} |
| 22 |
|
| 23 |
class { 'redis': |
| 24 |
bind => '#{master_ip_address}', |
| 25 |
requirepass => 'foobared', |
| 26 |
} |
| 27 |
EOS |
| 28 |
apply_manifest_on(host, pp, catch_failures: true) |
| 29 |
|
| 30 |
command_to_check = "redis-cli -h #{master_ip_address} -a foobared info replication" |
| 31 |
|
| 32 |
on host, command_to_check do |
| 33 |
expect(stdout).to match(%r{^role:master}) |
| 34 |
end |
| 35 |
end |
| 36 |
end |
| 37 |
end |
| 38 |
|
| 39 |
hosts_as('slave').each do |host| |
| 40 |
context "should be able to configure a host as master on #{host}" do |
| 41 |
it 'works idempotently with no errors' do |
| 42 |
pp = <<-EOS |
| 43 |
class { 'redis': |
| 44 |
bind => '127.0.0.1', |
| 45 |
masterauth => 'foobared', |
| 46 |
slaveof => '#{master_ip_address} 6379' |
| 47 |
} |
| 48 |
|
| 49 |
EOS |
| 50 |
apply_manifest_on(host, pp, catch_failures: true) |
| 51 |
|
| 52 |
on host, 'redis-cli -h $(facter ipaddress_enp0s8) info replication' do |
| 53 |
expect(stdout).to match(%r{^role:slave}) |
| 54 |
end |
| 55 |
end |
| 56 |
end |
| 57 |
end |
| 58 |
|
| 59 |
hosts_as('master').each do |host| |
| 60 |
context "should be able to configure a host as master on #{host}" do |
| 61 |
it 'works idempotently with no errors' do |
| 62 |
command_to_check = "redis-cli -h #{master_ip_address} -a foobared info replication" |
| 63 |
|
| 64 |
sleep(5) |
| 65 |
|
| 66 |
on host, command_to_check do |
| 67 |
expect(stdout).to match(%r{^connected_slaves:2}) |
| 68 |
end |
| 69 |
end |
| 70 |
end |
| 71 |
end |
| 72 |
end |
| 73 |
end |