Skip to content

Commit

Permalink
Autodetect supported instead of using Hiera
Browse files Browse the repository at this point in the history
Previously it (ab)used Hiera to set the supported versions. This now
uses metadata.json and facts to do the same. The parameter is kept in to
override this. It is turned into undef to allow pick() and signal that
the value is determined later.
  • Loading branch information
ekohl committed Apr 22, 2021
1 parent 2903fab commit 6eff482
Show file tree
Hide file tree
Showing 38 changed files with 37 additions and 101 deletions.
3 changes: 0 additions & 3 deletions data/Debian.Debian.10.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Debian.Debian.7.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Debian.Debian.8.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Debian.Debian.9.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Debian.Ubuntu.14.04.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Debian.Ubuntu.16.04.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Debian.Ubuntu.18.04.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/FreeBSD.FreeBSD.10.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/FreeBSD.FreeBSD.11.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/FreeBSD.FreeBSD.12.yaml

This file was deleted.

1 change: 0 additions & 1 deletion data/RedHat.CentOS.6.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---

openvmtools::manage_epel: true
openvmtools::supported: true
3 changes: 0 additions & 3 deletions data/RedHat.CentOS.7.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.CentOS.8.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.19.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.20.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.21.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.22.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.23.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.24.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.Fedora.25.yaml

This file was deleted.

1 change: 0 additions & 1 deletion data/RedHat.OracleLinux.6.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---

openvmtools::manage_epel: true
openvmtools::supported: true
3 changes: 0 additions & 3 deletions data/RedHat.OracleLinux.7.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.OracleLinux.8.yaml

This file was deleted.

1 change: 0 additions & 1 deletion data/RedHat.RedHat.6.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---

openvmtools::manage_epel: true
openvmtools::supported: true
3 changes: 0 additions & 3 deletions data/RedHat.RedHat.7.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/RedHat.RedHat.8.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.OpenSUSE.11.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.OpenSUSE.12.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.OpenSUSE.13.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.OpenSUSE.15.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.OpenSUSE.42.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.SLES.12.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.SLES.13.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.SLES.14.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/Suse.SLES.15.yaml

This file was deleted.

19 changes: 19 additions & 0 deletions functions/supported.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @summary Returns whether the currently loaded OS is supported by the module
#
# This function uses the current facts to check if the current Operating System
# and its release or major release is supported.
#
# @param mod
# The module name to check.
#
# @example Using the Puppet built in global $module_name
# openvmtools::supported($module_name)
function openvmtools::supported(String[1] $mod) >> Boolean {
$metadata = load_module_metadata($mod)
unless $metadata {
fail("Unable to load metadata for mod '${mod}'")
}
$metadata['operatingsystem_support'].any |$os| {
$os['operatingsystem'] == $facts['os']['name'] and $facts['os']['release']['major'] in $os['operatingsystemrelease']
}
}
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@
Boolean $service_hasstatus = true,
Variant[String[1],Array[String[1]]] $service_name = ['vgauthd', 'vmtoolsd'],
Optional[String[1]] $service_pattern = undef,
Boolean $supported = false,
Optional[Boolean] $supported = undef,
Boolean $uninstall_vmware_tools = false,
Boolean $with_desktop = false,
) {
if $facts['virtual'] == 'vmware' {
if $supported {
if pick($supported, openvmtools::supported($module_name)) {
if $ensure == 'present' {
$package_ensure = $autoupgrade ? {
true => 'latest',
Expand Down
16 changes: 16 additions & 0 deletions spec/functions/supported_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe 'openvmtools::supported' do
context 'On Debian 10' do
let(:facts) do
{
operatingsystem: 'Debian',
operatingsystemmajrelease: '10',
}
end

it 'returns true' do
is_expected.to run.with_params('openvmtools').and_return(true)
end
end
end

0 comments on commit 6eff482

Please sign in to comment.