Debian Codegraph @

spec/acceptance/suites/default/redis_multi_instances_one_host_spec.rb

raw
1 # frozen_string_literal: true
2
3 require 'spec_helper_acceptance'
4
5 describe 'redis::instance example' do
6 # TODO: SELinux
7 # semanage port --add --type redis_port_t --proto tcp 6380-6382
8 # Label /run/redis-server-\d+(/.+)? as redis_var_run_t
9
10 instances = [6379, 6380, 6381, 6382]
11
12 config_path = case fact('os.family')
13 when 'Debian'
14 '/etc/redis'
15 when 'RedHat'
16 if fact('os.release.major').to_i >= 9
17 '/etc/redis'
18 else
19 '/etc'
20 end
21 else
22 '/etc'
23 end
24
25 redis_name = case fact('os.family')
26 when 'Debian'
27 'redis-server'
28 else
29 'redis'
30 end
31
32 include_examples 'an idempotent resource' do
33 let(:manifest) do
34 <<~PUPPET
35 $listening_ports = #{instances}
36
37 class { 'redis':
38 default_install => false,
39 service_enable => false,
40 service_ensure => 'stopped',
41 protected_mode => false,
42 bind => [],
43 }
44
45 $listening_ports.each |$port| {
46 $port_string = sprintf('%d',$port)
47 redis::instance { $port_string:
48 service_enable => true,
49 service_ensure => 'running',
50 port => $port,
51 bind => $facts['networking']['ip'],
52 dbfilename => "${port}-dump.rdb",
53 appendfilename => "${port}-appendonly.aof",
54 appendfsync => 'always',
55 require => Class['Redis'],
56 }
57 }
58 PUPPET
59 end
60 end
61
62 specify { expect(package(redis_name)).to be_installed }
63
64 specify do
65 expect(service(redis_name)).not_to be_enabled
66 expect(service(redis_name)).not_to be_running
67 end
68
69 instances.each do |instance|
70 specify do
71 expect(file("/etc/systemd/system/redis-server-#{instance}.service")).
72 to be_file.
73 and have_attributes(content: include("redis-server-#{instance}.conf"))
74 end
75
76 specify { expect(service("redis-server-#{instance}")).to be_enabled.and be_running }
77
78 specify do
79 expect(file("#{config_path}/redis-server-#{instance}.conf")).
80 to be_file.
81 and have_attributes(content: include("port #{instance}"))
82 end
83
84 specify "redis instance #{instance} should respond to ping command" do
85 expect(command("redis-cli -h #{fact('networking.ip')} -p #{instance} ping")).
86 to have_attributes(stdout: %r{PONG})
87 end
88 end
89 end