Skip to content

Commit 2218071

Browse files
committed
Use modern facts
1 parent eea6c8c commit 2218071

File tree

9 files changed

+39
-33
lines changed

9 files changed

+39
-33
lines changed

manifests/init.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
if $use_exported_resources {
7070
# first we export this server's instance
71-
@@gluster::peer { $::fqdn:
71+
@@gluster::peer { $facts['networking']['fqdn']:
7272
pool => $pool,
7373
}
7474

manifests/params.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
# Set distro/release specific names, repo versions, repo gpg keys, package versions, etc
1919
# if the user didn't specify a version, just use "installed" for package version.
2020
# if they did specify a version, assume they provided a valid one
21-
case $::osfamily {
21+
case $facts['os']['family'] {
2222
'RedHat': {
2323
$repo = true
2424
$repo_gpg_key_source = 'https://raw.githubusercontent.com/CentOS-Storage-SIG/centos-release-storage-common/master/RPM-GPG-KEY-CentOS-SIG-Storage'
2525

26-
$server_package = $::operatingsystemmajrelease ? {
26+
$server_package = $facts['os']['release']['major'] ? {
2727
# RHEL 6 and 7 provide Gluster packages natively
2828
/(6|7)/ => 'glusterfs-server',
2929
default => false
3030
}
31-
$client_package = $::operatingsystemmajrelease ? {
31+
$client_package = $facts['os']['release']['major'] ? {
3232
/(6|7)/ => 'glusterfs-fuse',
3333
default => false,
3434
}

manifests/peer.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#
3737
define gluster::peer (
3838
$pool = 'default',
39-
$fqdn = $::fqdn,
39+
$fqdn = $facts['networking']['fqdn'],
4040
) {
4141

4242
# we can't do much without the Gluster binary
@@ -45,7 +45,7 @@
4545
if getvar('::gluster_binary') {
4646
# we can't join to ourselves, so it only makes sense to operate
4747
# on other gluster servers in the same pool
48-
if $fqdn != $::fqdn {
48+
if $fqdn != $facts['networking']['fqdn'] {
4949

5050
# and we don't want to attach a server that is already a member
5151
# of the current pool

manifests/repo.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$release = $gluster::params::release,
2020
$version = $gluster::params::version,
2121
) inherits gluster::params {
22-
case $::osfamily {
22+
case $facts['os']['family'] {
2323
'RedHat': {
2424
class { 'gluster::repo::yum':
2525
release => $release,
@@ -30,6 +30,6 @@
3030
version => $version,
3131
}
3232
}
33-
default: { fail("${::osfamily} not yet supported!") }
33+
default: { fail("${facts['os']['family']} not yet supported!") }
3434
}
3535
}

manifests/repo/apt.pp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,30 @@
5151
} elsif $version =~ /^(\d)\.(\d+)\.(\d+).*$/ {
5252
$repo_ver = "${1}.${2}/${1}.${2}.${3}"
5353
} else {
54-
fail("${version} doesn't make sense for ${::operatingsystem}!")
54+
fail("${version} doesn't make sense for ${facts['os']['name']}!")
5555
}
5656

5757
# the Gluster repo only supports x86_64 (amd64) and arm64. The Ubuntu PPA also supports armhf and arm64.
58-
case $::operatingsystem {
58+
case $facts['os']['name'] {
5959
'Debian': {
60-
case $::lsbdistcodename {
60+
case $facts['os']['distro']['codename'] {
6161
'jessie', 'stretch': {
62-
$arch = $::architecture ? {
62+
$arch = $facts['os']['architecture'] ? {
6363
'amd64' => 'amd64',
6464
'arm64' => 'arm64',
6565
default => false,
6666
}
6767

6868
$_repo_base = 'https://download.gluster.org/pub/gluster/glusterfs'
6969
$repo_url = if versioncmp($release, '4.1') < 0 {
70-
"${_repo_base}/01.old-releases/${release}/LATEST/Debian/${::lsbdistcodename}/${arch}/apt/"
70+
"${_repo_base}/01.old-releases/${release}/LATEST/Debian/${facts['os']['distro']['codename']}/${arch}/apt/"
7171
} else {
7272
$_release = if $release == '4.1' {
7373
$release
7474
} else {
7575
$release[0]
7676
}
77-
"${_repo_base}/${_release}/LATEST/Debian/${::lsbdistcodename}/${arch}/apt/"
77+
"${_repo_base}/${_release}/LATEST/Debian/${facts['os']['distro']['codename']}/${arch}/apt/"
7878
}
7979
}
8080
default: {
@@ -88,14 +88,14 @@
8888
}
8989

9090
unless $arch {
91-
fail("Architecture ${::architecture} not yet supported for ${::operatingsystem}.")
91+
fail("Architecture ${facts['os']['architecture']} not yet supported for ${facts['os']['name']}.")
9292
}
9393

9494
$repo = {
9595
"glusterfs-${version}" => {
9696
ensure => present,
9797
location => $repo_url,
98-
release => $::lsbdistcodename,
98+
release => $facts['os']['distro']['codename'],
9999
repos => 'main',
100100
key => {
101101
id => $repo_key_name,

manifests/repo/yum.pp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
) inherits gluster::params {
2222

2323
# CentOS Gluster repo only supports x86_64
24-
if $::architecture != 'x86_64' {
25-
fail("Architecture ${::architecture} not yet supported for ${::operatingsystem}.")
24+
if $facts['os']['architecture'] != 'x86_64' {
25+
fail("Architecture ${facts['os']['architecture']} not yet supported for ${facts['os']['name']}.")
2626
}
2727

2828
if $priority {
2929
if ! defined( Package['yum-plugin-priorities'] ) {
3030
package { 'yum-plugin-priorities':
3131
ensure => installed,
32-
before => Yumrepo["glusterfs-${::architecture}"],
32+
before => Yumrepo["glusterfs-${facts['os']['architecture']}"],
3333
}
3434
}
3535
}
@@ -40,15 +40,15 @@
4040
$release[0]
4141
}
4242

43-
yumrepo { "glusterfs-${::architecture}":
43+
yumrepo { "glusterfs-${facts['os']['architecture']}":
4444
enabled => 1,
45-
baseurl => "http://mirror.centos.org/centos/${::operatingsystemmajrelease}/storage/${::architecture}/gluster-${_release}/",
46-
descr => "CentOS-${::operatingsystemmajrelease} - Gluster ${_release}",
45+
baseurl => "http://mirror.centos.org/centos/${facts['os']['release']['major']}/storage/${facts['os']['architecture']}/gluster-${_release}/",
46+
descr => "CentOS-${facts['os']['release']['major']} - Gluster ${_release}",
4747
gpgcheck => 1,
4848
gpgkey => $repo_key_source,
4949
priority => $priority,
5050
}
5151

52-
Yumrepo["glusterfs-${::architecture}"] -> Package<| tag == 'gluster-packages' |>
52+
Yumrepo["glusterfs-${facts['os']['architecture']}"] -> Package<| tag == 'gluster-packages' |>
5353

5454
}

spec/classes/install_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@
5656
end
5757
context 'installing on an unsupported architecture' do
5858
let :facts do
59-
super().merge(
60-
architecture: 'zLinux'
61-
)
59+
# deep_merge modifies facts in place
60+
facts = super().dup
61+
facts[:os] = facts[:os].merge(architecture: 'zLinux')
62+
facts
6263
end
6364

6465
case facts[:osfamily]
6566
when 'Archlinux', 'Suse'
6667
it { is_expected.not_to create_class('gluster::repo') }
6768
else
68-
it { is_expected.to raise_error(Puppet::Error, %r{not yet supported}) }
69+
it { is_expected.to compile.and_raise_error(%r{not yet supported}) }
6970
end
7071
end
7172
end

spec/classes/repo_apt_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe 'gluster::repo::apt', type: :class do
44
on_supported_os.each do |os, os_facts|
5-
context "on #{os}", if: os_facts[:osfamily] == 'Debian' do
5+
context "on #{os}", if: os_facts[:os]['family'] == 'Debian' do
66
let(:facts) { os_facts }
77
let(:pre_condition) { 'require gluster::params' }
88

@@ -17,17 +17,20 @@
1717
)
1818
end
1919
end
20+
2021
context 'unsupported architecture' do
21-
let :facts do
22-
super().merge(
23-
architecture: 'zLinux'
24-
)
22+
let(:facts) do
23+
# deep_merge modifies the facts in place
24+
facts = super().dup
25+
facts[:os] = facts[:os].merge(architecture: 'zLinux')
26+
facts
2527
end
2628

2729
it 'does not install' do
2830
is_expected.to compile.and_raise_error(%r{Architecture zLinux not yet supported})
2931
end
3032
end
33+
3134
context 'latest Gluster with priority' do
3235
let :params do
3336
{

spec/defines/peer_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@
9999
gluster_binary: '/usr/sbin/gluster',
100100
gluster_peer_count: 0,
101101
gluster_peer_list: '',
102-
fqdn: 'peer1.example.com'
102+
networking: {
103+
fqdn: 'peer1.example.com'
104+
}
103105
}
104106
end
105107

0 commit comments

Comments
 (0)