Skip to content

Commit

Permalink
Add CentOS 8 support
Browse files Browse the repository at this point in the history
The main differences for CentOS 8 are:
* There is now a new collectd-utils package containing collectdctl
* collectd-python is now a seperate sub package
* python is python3.
* pip command is now pip3
* The rabbitmq plugin no longer works due to lack of python3 support

The python_dir fact will fall back to `/usr/libexec/platform-python`
if `python3` does not exist on the path. This is the python
that collectd is built against and significantly requires.

Note that setting `collectd::ci_package_repo` true will currently
result in yum being configured with a non existant repo since
https://pkg.ci.collectd.org/rpm/ does not exist
for 8.

collectd/collectd-ci#35
  • Loading branch information
traylenator committed Mar 9, 2020
1 parent c25073e commit 6724520
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 103 deletions.
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- set: ubuntu1604-64
- set: ubuntu1804-64
- set: centos7-64
- set: centos8-64
- set: debian8-64
secure: "FAK3Izs5bSZyblGvcFnGWm0exZV5+v9pbwfRDD2oihWxX3U3pArGW+3XcwcJfLQgrUYBsOTmHC8yPjlgTBYeIt/5pvg9X+3jwNgeto6kozpI/nvAq4NtcHhzxRejuPELhFYeXZ3hEw0w+v/ZRo2cNLwI0LLpiWEDvCMZN1CJ2RY="
spec/spec_helper.rb:
Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ matrix:
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker
services: docker
- rvm: 2.5.3
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos8-64 BEAKER_HYPERVISOR=docker CHECK=beaker
services: docker
- rvm: 2.5.3
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos8-64 BEAKER_HYPERVISOR=docker CHECK=beaker
services: docker
- rvm: 2.5.3
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian8-64 BEAKER_HYPERVISOR=docker CHECK=beaker
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,8 @@ You will need to add this to [collectd::config::typesdb](https://github.com/voxp
via hiera or in a manifest. Failure to set the types.db.custom content will
result in *no* metrics from the rabbitmq plugin.

The rabbitmq plugin has not been ported to python3 and will fail on CentOS 8 [#75](https://github.com/nytimes/collectd-rabbitmq/issues/75)

set typesdb to include the collectd-rabbitmq types.db.custom

```yaml
Expand Down
2 changes: 2 additions & 0 deletions lib/facter/python_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
else
Facter::Util::Resolution.exec('python3 -c "import site; print(site.getsitepackages()[0])"')
end
elsif File.exist?('/usr/libexec/platform-python')
Facter::Util::Resolution.exec('/usr/libexec/platform-python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"')
else
''
end
Expand Down
5 changes: 4 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@
$config_file = '/etc/collectd.conf'
$config_group = 'root'
$java_dir = '/usr/share/collectd/java'
$default_python_dir = '/usr/lib/python2.7/site-packages'
$default_python_dir = $facts['os']['release']['major'] ? {
'7' => '/usr/lib/python2.7/site-packages',
default => '/usr/lib/python3.6/site-packages',
}
$manage_repo = true
$package_configs = {
ovs_events => 'ovs-events.conf',
Expand Down
31 changes: 24 additions & 7 deletions manifests/plugin/cuda.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,45 @@
# @param provider_proxy Optional[String] Proxy for provider. Default: undef
class collectd::plugin::cuda (
Optional[String] $ensure = 'present',
Optional[Boolean] $manage_package = undef,
Optional[Boolean] $manage_package = undef,
Optional[String] $package_name = 'collectd-cuda',
Optional[String] $package_provider = 'pip',
Optional[String] $package_provider = undef,
Optional[String] $provider_proxy = undef,
) {
include collectd

$_manage_package = pick($manage_package, $collectd::manage_package)
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' {
$_python_pip_package = 'python3-pip'
if $package_provider =~ Undef {
$_package_provider = 'pip3'
}
else {
$_package_provider = $package_provider
}
} else {
$_python_pip_package = 'python-pip'
if $package_provider =~ Undef {
$_package_provider = 'pip'
}
else {
$_package_provider = $package_provider
}
}

if ($_manage_package) {
if (!defined(Package['python-pip'])) {
package { 'python-pip': ensure => 'present', }
if (!defined(Package[$_python_pip_package])) {
package { $_python_pip_package: ensure => 'present', }

Package[$package_name] {
require => Package['python-pip'],
require => Package[$_python_pip_package],
}

if $facts['os']['family'] == 'RedHat' {
# Epel is installed in install.pp if manage_repo is true
# python-pip doesn't exist in base for RedHat. Need epel installed first
if (defined(Class['::epel'])) {
Package['python-pip'] {
Package[$_python_pip_package] {
require => Class['::epel'],
}
}
Expand All @@ -49,7 +66,7 @@

package { $package_name:
ensure => $ensure,
provider => $package_provider,
provider => $_package_provider,
install_options => $install_options,
}

Expand Down
32 changes: 25 additions & 7 deletions manifests/plugin/iscdhcp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,46 @@
# @param provider_proxy Optional[String] Proxy for provider. Default: undef
class collectd::plugin::iscdhcp (
Optional[String] $ensure = 'present',
Optional[Boolean] $manage_package = undef,
Optional[Boolean] $manage_package = undef,
Optional[String] $package_name = 'collectd-iscdhcp',
Optional[String] $package_provider = 'pip',
Optional[String] $package_provider = undef,
Optional[String] $provider_proxy = undef,
) {
include collectd

$_manage_package = pick($manage_package, $collectd::manage_package)

if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' {
$_python_pip_package = 'python3-pip'
if $package_provider =~ Undef {
$_package_provider = 'pip3'
}
else {
$_package_provider = $package_provider
}
} else {
$_python_pip_package = 'python-pip'
if $package_provider =~ Undef {
$_package_provider = 'pip'
}
else {
$_package_provider = $package_provider
}
}

if ($_manage_package) {
if (!defined(Package['python-pip'])) {
package { 'python-pip': ensure => 'present', }
if (!defined(Package[$_python_pip_package])) {
package { $_python_pip_package: ensure => 'present', }

Package[$package_name] {
require => Package['python-pip'],
require => Package[$_python_pip_package],
}

if $facts['os']['family'] == 'RedHat' {
# Epel is installed in install.pp if manage_repo is true
# python-pip doesn't exist in base for RedHat. Need epel installed first
if (defined(Class['::epel'])) {
Package['python-pip'] {
Package[$_python_pip_package] {
require => Class['::epel'],
}
}
Expand All @@ -48,7 +66,7 @@

package { $package_name:
ensure => $ensure,
provider => $package_provider,
provider => $_package_provider,
install_options => $install_options,
}

Expand Down
8 changes: 7 additions & 1 deletion manifests/plugin/python.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@
$ensure_real = 'absent'
}

if $facts['os']['name'] == 'Fedora' or $facts['os']['name'] == 'Amazon' {
if $facts['os']['name'] == 'Amazon' or
($facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0) {
if $_manage_package {
package { 'collectd-python':
ensure => $ensure_real,
}
if (defined(Class['::epel'])) {
Package['collectd-python'] {
require => Class['::epel'],
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions manifests/plugin/rabbitmq.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
) {
include collectd

if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0 {
fail('https://pypi.org/project/collectd-rabbitmq/ does not support Python 3')
}

case $facts['os']['family'] {
'RedHat': {
$_custom_types_db = '/usr/share/collectd-rabbitmq/types.db.custom'
Expand Down
9 changes: 6 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"7"
"7",
"8"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"7"
"7",
"8"
]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
"7"
"7",
"8"
]
},
{
Expand Down
87 changes: 58 additions & 29 deletions spec/acceptance/class_plugin_python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
pp = <<-EOS
class{'collectd::plugin::python':
}
# Enable one write plugin to make logs quieter
class { 'collectd::plugin::csv':}
EOS
# Run 3 times since the collectd_version
# fact is impossible until collectd is
Expand All @@ -22,39 +24,48 @@
end
end

context 'trivial module' do
context 'trivial pip module connect-time' do
it 'works idempotently with no errors' do
pp = <<-EOS
if $facts['os']['family'] == 'Debian' {
if $facts['os']['family'] == 'Debian' or ( $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' ) {
# for collectdctl command
package{'collectd-utils':
ensure => present,
ensure => present,
}
}
package{'python-pip':
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' {
$_python_pip_package = 'python3-pip'
$_pip_provider = 'pip3'
} else {
$_python_pip_package = 'python-pip'
$_pip_provider = 'pip'
}
package{$_python_pip_package:
ensure => present,
}
package{['collectd-connect-time']:
ensure => 'present',
provider => 'pip',
require => Package['python-pip'],
before => Service['collectd'],
ensure => 'present',
provider => $_pip_provider,
require => Package[$_python_pip_package],
before => Service['collectd'],
}
class{'collectd::plugin::python':
logtraces => true,
interactive => false,
logtraces => true,
interactive => false,
modules => {
'collectd_connect_time' => {
config => [{'target' => 'google.de'}],
},
},
config => [{'target' => 'google.de'}],
},
},
}
class{'collectd::plugin::unixsock':
socketfile => '/var/run/collectd-sock',
socketfile => '/var/run/collectd-sock',
socketgroup => 'root',
}
EOS

# Run it twice and test for idempotency
# Run it twice or thrice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
shell('sleep 10')
Expand All @@ -75,39 +86,57 @@
if $facts['os']['family'] == 'Debian' {
# for collectdctl command
package{['collectd-utils','python-dbus']:
ensure => present,
ensure => present,
}
}
package{['git','python-pip']:
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' {
$_python_pip_package = 'python3-pip'
$_pip_provider = 'pip3'
} else {
$_python_pip_package = 'python-pip'
$_pip_provider = 'pip'
}
package{['git',$_python_pip_package]:
ensure => present,
before => Package['collectd-systemd'],
before => Package['collectd-systemd'],
}
# Dependency on dbus for collectd-systemd installed with pip.
# https://github.com/mbachry/collectd-systemd/issues/11
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' {
package{'python3-dbus':
ensure => present,
}
}
package{'collectd-systemd':
ensure => 'present',
provider => 'pip',
source => 'git+https://github.com/mbachry/collectd-systemd.git',
before => Service['collectd'],
ensure => 'present',
provider => $_pip_provider,
source => 'git+https://github.com/mbachry/collectd-systemd.git',
before => Service['collectd'],
}
class{'collectd':
typesdb => ['/usr/share/collectd/types.db'],
}
class{'collectd::plugin::python':
logtraces => true,
interactive => false,
logtraces => true,
interactive => false,
modules => {
'instanceA' => {
module => 'collectd_systemd',
config => [{'Service' => 'collectd'}],
},
module => 'collectd_systemd',
config => [{'Service' => 'collectd'}],
},
'instanceB' => {
module => 'collectd_systemd',
config => [{'Service' => 'sshd'}],
},
},
},
},
}
class{'collectd::plugin::unixsock':
socketfile => '/var/run/collectd-sock',
socketgroup => 'root',
}
class { 'collectd::plugin::csv':}
EOS

# Run it twice and test for idempotency
Expand Down
Loading

0 comments on commit 6724520

Please sign in to comment.