Skip to content

Commit

Permalink
Check for presence of Fact gluster_volume_list
Browse files Browse the repository at this point in the history
On a node with no pre-existing Gluster volume, this module will not populate the Fact 'gluster_volume_list' there for we should check if the current volume already exists ONLY if the nodes already has some volumes.

Work on conditional statement readability

Puppet DSL doesn't allow variable re-assignment

Of course!
So reformating conditional statement to make everything checked within a single 'if'.

Adding checks for setup from scratch

As discussed in voxpupuli#24 (comment) extra check added to handle creation of volumes from scratch on a Gluster pool.

Added check for undef fact

Ensure first run doesn't throw an error because Fact for gluster_peer_list may return as undef.
Related to voxpupuli#23

Handle different state/member in pool

Adding check to enable creation of pool and volume from scratch by the module.
voxpupuli#23

Removing blocking check for dry run

Fact $::gluster_volume_list presence should not be checked on L 105 as it may be undef on very first run in a pool without pre-existing volumes

Correcting typo in var ref and pattern in regsubst

Prevent error being thrown by pattern in regsubst() function.
As explained and corrected in voxpupuli#31
  • Loading branch information
Benjamin Merot authored and Benjamin Merot committed Mar 2, 2016
1 parent 6eeda3b commit c673907
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
19 changes: 15 additions & 4 deletions manifests/peer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,23 @@

# and we don't want to attach a server that is already a member
# of the current pool
$peers = split($::gluster_peer_list, ',' )
if ! member($peers, $title) {
exec { "gluster peer probe ${title}":
command => "${binary} peer probe ${title}",
if $::gluster_peer_list != undef {
$peers = split($::gluster_peer_list, ',' )
if ! member($peers, $title) {
$already_in_pool = false
} else {
$already_in_pool = true
}
} else {
$already_in_pool = false
}

if !$already_in_pool {
exec { "gluster peer probe ${title}":
command => "${binary} peer probe ${title}",
}
}

}
}
}
24 changes: 18 additions & 6 deletions manifests/volume.pp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,20 @@
$binary = $::gluster_binary
if $binary{
# we need the Gluster binary to do anything!

if $::gluster_peer_list != undef{
$minimal_requirements = true
} else {
$minimal_requirements = false
}

if $::gluster_volume_list != undef and member( split( $::gluster_volume_list, ',' ), $title ) {
$already_exists = true
} else {
$already_exists = false
}

if ! member( split( $::gluster_volume_list, ',' ), $title ) {
if $minimal_requirements and $already_exists == false {
# this volume has not yet been created

# before we can create it, we need to ensure that all the
Expand Down Expand Up @@ -139,7 +151,7 @@
# volume:option
$vol_opts = prefix( $_options, "${title}:" )
# now we make some YAML, and then parse that to get a Puppet hash
$yaml = join( regsubst( $vol_opts, ': ', ":\n value: ", G), "\n")
$yaml = join( regsubst( $vol_opts, ': ', ":\n value: ", 'G'), "\n")
$hoh = parseyaml($yaml)

# safety check
Expand All @@ -161,7 +173,7 @@
}
}

} else {
} elsif $already_exists {
# this volume exists

# our fact lists bricks comma-separated, but we need an array
Expand All @@ -179,7 +191,7 @@
# number of bricks to add is a factor of that value
if $stripe {
if ( count($new_bricks) % $stripe ) != 0 {
fail("Number of bricks to add is not a multiple of stripe count ${stipe}")
fail("Number of bricks to add is not a multiple of stripe count ${stripe}")
}
$s = "stripe ${stripe}"
} else {
Expand Down Expand Up @@ -256,7 +268,7 @@
# so build up the hash correctly
#
$remove_opts = prefix( $to_remove, "${title}:" )
$remove_yaml = join( regsubst( $remove_opts, ': .+$', ":\n ensure: absent", G ), "\n" )
$remove_yaml = join( regsubst( $remove_opts, ': .+$', ":\n ensure: absent", 'G' ), "\n" )
$remove = parseyaml($remove_yaml)
if $remove_options {
create_resources( ::gluster::volume::option, $remove )
Expand All @@ -268,7 +280,7 @@
if ! empty($to_add) {
# we have some options defined that are not active. Add them
$add_opts = prefix( $to_add, "${title}:" )
$add_yaml = join( regsubst( $add_opts, ': ', ":\n value: ", G ), "\n" )
$add_yaml = join( regsubst( $add_opts, ': ', ":\n value: ", 'G' ), "\n" )
$add = parseyaml($add_yaml)
create_resources( ::gluster::volume::option, $add )
}
Expand Down

0 comments on commit c673907

Please sign in to comment.