From 7351a4f57005a49c50b5a2de9613c46c57db8f68 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Fri, 5 Aug 2022 15:03:53 +0200 Subject: [PATCH 1/5] format class according to pdk linter --- manifests/init.pp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index d7764db..023046f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -139,8 +139,7 @@ Optional[String[1]] $restart_service, Boolean $dns_notify_daemon = true, Optional[Hash] $connection_dnsoptions = undef, -){ - +) { unless $facts['networkmanager_nmcli_path'] { fail("Did not found NetworkManager command line tool 'nmcli'.") } @@ -160,12 +159,12 @@ ensure => file, mode => '0644', content => template("${module_name}/dns.erb"), - notify => Class['networkmanager::service'] + notify => Class['networkmanager::service'], } } else { file { $global_conffile: ensure => absent, - notify => Class['networkmanager::service'] + notify => Class['networkmanager::service'], } } @@ -176,10 +175,10 @@ if $primary_connection { networkmanager::dns { $primary_connection: - nameservers => $nameservers, - searchdomains => $dns_searchdomains, - dns_options => $dns_options, - notify_daemon => $dns_notify_daemon, + nameservers => $nameservers, + searchdomains => $dns_searchdomains, + dns_options => $dns_options, + notify_daemon => $dns_notify_daemon, } } else { notify { 'Did not found a primary NetworkManager connection.': loglevel => warning } From 3130e028a30b544878a860bfef657d639c3ad3e9 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Mon, 8 Aug 2022 09:20:26 +0200 Subject: [PATCH 2/5] update readme - fix linitings --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3d5c584..257a3e0 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,18 @@ ## Table of Contents -1. [Description](#description) -1. [Setup - The basics of getting started with networkmanager](#setup) - * [Setup requirements](#setup-requirements) -1. [Usage - Configuration options and additional functionality](#usage) -1. [Limitations - OS compatibility, etc.](#limitations) -1. [Development - Guide for contributing to the module](#development) +- [networkmanager](#networkmanager) + - [Table of Contents](#table-of-contents) + - [Description](#description) + - [Setup](#setup) + - [Setup Requirements](#setup-requirements) + - [Usage](#usage) + - [Simple Including the module](#simple-including-the-module) + - [Instantiation as a class](#instantiation-as-a-class) + - [Setup of hieradata](#setup-of-hieradata) + - [Parameters](#parameters) + - [Limitations](#limitations) + - [Development](#development) ## Description @@ -26,7 +32,7 @@ of the NetworkManager: ## Setup -### Setup Requirements +### Setup Requirements This module requires following: @@ -51,7 +57,7 @@ configuration must be done via hieradata. include networkmanager ``` -or +or ```puppet contain networkmanager From 9e1d4ce357dd946cdc907067f0fde47aad0981e4 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Mon, 8 Aug 2022 09:25:22 +0200 Subject: [PATCH 3/5] fix rubocop - rename nm-witch to nm_witch to comply with naming --- lib/facter/networkmanager_nmcli_path.rb | 2 +- lib/puppet_x/pixelpark/{nm-which.rb => nm_which.rb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/puppet_x/pixelpark/{nm-which.rb => nm_which.rb} (100%) diff --git a/lib/facter/networkmanager_nmcli_path.rb b/lib/facter/networkmanager_nmcli_path.rb index e7a3208..25cfebc 100644 --- a/lib/facter/networkmanager_nmcli_path.rb +++ b/lib/facter/networkmanager_nmcli_path.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../puppet_x/pixelpark/nm-which' +require_relative '../puppet_x/pixelpark/nm_which' Facter.add(:networkmanager_nmcli_path) do setcode do diff --git a/lib/puppet_x/pixelpark/nm-which.rb b/lib/puppet_x/pixelpark/nm_which.rb similarity index 100% rename from lib/puppet_x/pixelpark/nm-which.rb rename to lib/puppet_x/pixelpark/nm_which.rb From 25a2995ad8b0de704bf1865bc1724dc99b3c2e79 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Mon, 8 Aug 2022 13:40:43 +0200 Subject: [PATCH 4/5] update tests - try to fix test - fix style --- .fixtures.yml | 2 +- manifests/dns.pp | 12 +++++++----- spec/defines/dns_spec.rb | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 4d1fe61..6470f44 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,4 +3,4 @@ --- fixtures: forge_modules: - stdlib: "puppetlabs/stdlib" + stdlib: "puppetlabs/stdlib" diff --git a/manifests/dns.pp b/manifests/dns.pp index d99193a..4091529 100644 --- a/manifests/dns.pp +++ b/manifests/dns.pp @@ -39,19 +39,21 @@ Optional[String[1]] $connection = undef, Boolean $notify_daemon = true, ) { + assert_private() + unless $facts['networkmanager_nmcli_path'] { fail("Did not found NetworkManager command line tool 'nmcli'.") } $nmcli = $facts['networkmanager_nmcli_path'] - if $connection { - $_connection = $connection - } else { + if empty($connection) { $_connection = $name + } else { + $_connection = $connection } - if $nameservers.length() == 1 { + if $nameservers.length == 1 { notify { "Only one nameserver was given for NetworkManager connection ${_connection}.": loglevel => warning } } @@ -69,7 +71,7 @@ } $used_searchdomains = $searchdomains.join(',') - $has_searchdomains = $facts['networkmanager_dns'][$_connection]['search'].join(',') + $has_searchdomains = $facts['networkmanager_dns'][$_connection]['search'].join(',') unless $used_searchdomains == $has_searchdomains { exec { "update searchdomains nmcli connection ${_connection}": diff --git a/spec/defines/dns_spec.rb b/spec/defines/dns_spec.rb index 6e018d3..c7b6a69 100644 --- a/spec/defines/dns_spec.rb +++ b/spec/defines/dns_spec.rb @@ -11,7 +11,7 @@ dns_options: '', } end - let(:pre_condition) { 'include networkmanager::service' } + let(:pre_condition) { 'include networkmanager' } on_supported_os.each do |os, os_facts| context "on #{os}" do From 38bec4905c15339ec44ab4a34d32aebe616a375f Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Mon, 8 Aug 2022 14:33:49 +0200 Subject: [PATCH 5/5] fix tests - add dummy data for service class - remove wrong assert_private from define --- data/common.yaml | 2 -- manifests/dns.pp | 2 -- spec/classes/networkmanager_service_spec.rb | 9 +++++++++ spec/defines/dns_spec.rb | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index 5ba9031..8b0a5b0 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,5 +1,4 @@ --- - # Defaults for Global DNS options networkmanager::enable_global_dns: false networkmanagerservers: [] @@ -19,4 +18,3 @@ networkmanager::ensure_service: 'running' networkmanager::service_name: 'NetworkManager' networkmanager::enable_service: true networkmanager::restart_service: ~ - diff --git a/manifests/dns.pp b/manifests/dns.pp index 4091529..cfa6c84 100644 --- a/manifests/dns.pp +++ b/manifests/dns.pp @@ -39,8 +39,6 @@ Optional[String[1]] $connection = undef, Boolean $notify_daemon = true, ) { - assert_private() - unless $facts['networkmanager_nmcli_path'] { fail("Did not found NetworkManager command line tool 'nmcli'.") } diff --git a/spec/classes/networkmanager_service_spec.rb b/spec/classes/networkmanager_service_spec.rb index ea764da..023b4e4 100644 --- a/spec/classes/networkmanager_service_spec.rb +++ b/spec/classes/networkmanager_service_spec.rb @@ -6,6 +6,15 @@ on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } + let(:params) do + { + service_name: 'foobar', + enable: true, + ensure: 'running', + manage: true, + restart: nil, + } + end it { is_expected.to compile } end diff --git a/spec/defines/dns_spec.rb b/spec/defines/dns_spec.rb index c7b6a69..56dac9d 100644 --- a/spec/defines/dns_spec.rb +++ b/spec/defines/dns_spec.rb @@ -11,7 +11,7 @@ dns_options: '', } end - let(:pre_condition) { 'include networkmanager' } + let(:pre_condition) { 'class { "networkmanager::service": service_name => "foobar", enable => true, ensure => "running", manage => true, restart => "/bin/foo",}' } on_supported_os.each do |os, os_facts| context "on #{os}" do