Skip to content

Commit 3959a63

Browse files
committed
Fixed code style and added tests
Fixed rubocop offenses. Added peer test for case hostname != fqdn. Added test for volume creation exec when there is only one node.
1 parent 0c68d99 commit 3959a63

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

lib/facter/gluster.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
if peer_count > 0
3131
peer_list = output.scan(%r{^Hostname: (.+)$}).flatten.join(',')
3232
other_names = output.scan(%r{^Other names:\n((.+\n)+)}).flatten.join.scan(%r{(.+)\n?}).sort.uniq.flatten.join(',')
33-
if other_names
34-
peer_list += ',' + other_names
35-
end
33+
peer_list += ',' + other_names if other_names
3634
end
3735
# note the stderr redirection here
3836
# `gluster volume list` spits to stderr :(
@@ -41,7 +39,6 @@
4139
output.split.each do |vol|
4240
# If a brick has trailing informaion such as (arbiter) remove it
4341
info = Facter::Util::Resolution.exec("#{binary} volume info #{vol} | sed 's/ (arbiter)//g'")
44-
# rubocop:disable Metrics/BlockNesting
4542
vol_status = Regexp.last_match[1] if info =~ %r{^Status: (.+)$}
4643
bricks = info.scan(%r{^Brick[^:]+: (.+)$}).flatten
4744
volume_bricks[vol] = bricks

spec/defines/peer_spec.rb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
describe 'gluster::peer', type: :define do
44
let(:title) { 'peer1.example.com' }
55

6+
let(:params) do
7+
{
8+
fqdn: 'peer1.example.com'
9+
}
10+
end
11+
612
describe 'missing gluster_binary fact' do
713
it { is_expected.to compile }
814
it { is_expected.not_to contain_exec('gluster peer probe peer1.example.com') }
@@ -51,7 +57,8 @@
5157
{
5258
gluster_binary: '/usr/sbin/gluster',
5359
gluster_peer_count: 0,
54-
gluster_peer_list: ''
60+
gluster_peer_list: '',
61+
fqdn: 'peer99.example.com'
5562
}
5663
end
5764

@@ -63,7 +70,8 @@
6370
{
6471
gluster_binary: '/usr/sbin/gluster',
6572
gluster_peer_count: 1,
66-
gluster_peer_list: 'peer2.example.com'
73+
gluster_peer_list: 'peer2.example',
74+
fqdn: 'peer99.example.com'
6775
}
6876
end
6977

@@ -75,7 +83,8 @@
7583
{
7684
gluster_binary: '/usr/sbin/gluster',
7785
gluster_peer_count: 2,
78-
gluster_peer_list: 'peer2.example.com,peer3.example.com'
86+
gluster_peer_list: 'peer2.example,peer3.example',
87+
fqdn: 'peer99.example.com'
7988
}
8089
end
8190

@@ -84,7 +93,7 @@
8493
end
8594
end
8695

87-
describe 'self joining (fqdn matches resource title)' do
96+
describe 'self joining' do
8897
let(:facts) do
8998
{
9099
gluster_binary: '/usr/sbin/gluster',
@@ -99,4 +108,19 @@
99108
is_expected.not_to contain_exec('gluster peer probe peer1.example.com')
100109
end
101110
end
111+
112+
describe 'use custom host name (not fqdn)' do
113+
let(:title) { 'peer1.example' }
114+
let(:facts) do
115+
{
116+
gluster_binary: '/usr/sbin/gluster',
117+
gluster_peer_count: 0,
118+
gluster_peer_list: '',
119+
fqdn: 'peer99.example.com'
120+
}
121+
end
122+
123+
it { is_expected.to compile }
124+
it { is_expected.to contain_exec('gluster peer probe peer1.example') }
125+
end
102126
end

spec/defines/volume_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,17 @@
9494
end
9595
end
9696
end
97+
98+
describe 'single node' do
99+
let(:facts) do
100+
{
101+
gluster_binary: '/usr/sbin/gluster',
102+
gluster_peer_count: 0,
103+
gluster_peer_list: ''
104+
}
105+
end
106+
107+
it { is_expected.to compile.with_all_deps }
108+
it { is_expected.to contain_exec("gluster create volume #{title}") }
109+
end
97110
end

0 commit comments

Comments
 (0)