diff --git a/examples/connection.pp b/examples/connection.pp index f8214e3..265a028 100644 --- a/examples/connection.pp +++ b/examples/connection.pp @@ -1,16 +1,33 @@ -nm::connection { 'test': +nm::connection { 'test1': content => { 'connection' => { - 'id' => 'test', - 'type' => 'ethernet', - 'interface-name' => 'test', + 'id' => 'test1', + 'type' => 'dummy', + 'interface-name' => 'dummy1', }, 'ipv4' => { 'address1' => '10.10.10.10/24', 'method' => 'manual', }, 'ipv6' => { - 'method' => 'disable', + 'method' => 'ignore', + }, + }, +} + +nm::connection { 'test2': + content => { + 'connection' => { + 'id' => 'test2', + 'type' => 'dummy', + 'interface-name' => 'dummy2', + }, + 'ipv4' => { + 'address1' => '10.20.20.20/24', + 'method' => 'manual', + }, + 'ipv6' => { + 'method' => 'ignore', }, }, } diff --git a/examples/connection_absent.pp b/examples/connection_absent.pp index 97a4cce..f48978e 100644 --- a/examples/connection_absent.pp +++ b/examples/connection_absent.pp @@ -1,3 +1,7 @@ -nm::connection { 'test': +nm::connection { 'test1': + ensure => 'absent', +} + +nm::connection { 'test2': ensure => 'absent', } diff --git a/spec/acceptance/connection_spec.rb b/spec/acceptance/connection_spec.rb index ffac423..251148c 100644 --- a/spec/acceptance/connection_spec.rb +++ b/spec/acceptance/connection_spec.rb @@ -8,7 +8,7 @@ it_behaves_like 'an idempotent resource' - describe file('/etc/NetworkManager/system-connections/test.nmconnection') do + describe file('/etc/NetworkManager/system-connections/test1.nmconnection') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } @@ -19,19 +19,52 @@ # THIS FILE IS CONTROLLED BY PUPPET [connection] - id=test - type=ethernet - interface-name=test + id=test1 + type=dummy + interface-name=dummy1 [ipv4] address1=10.10.10.10/24 method=manual [ipv6] - method=disable + method=ignore CONTENT end end + + describe interface('dummy1') do + it { should have_ipv4_address('10.10.10.10/24') } + end + + describe file('/etc/NetworkManager/system-connections/test2.nmconnection') do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode '600' } # serverspec does not like a leading 0 + + its(:content) do + is_expected.to match <<~CONTENT + # THIS FILE IS CONTROLLED BY PUPPET + + [connection] + id=test2 + type=dummy + interface-name=dummy2 + + [ipv4] + address1=10.20.20.20/24 + method=manual + + [ipv6] + method=ignore + CONTENT + end + end + + describe interface('dummy2') do + it { should have_ipv4_address('10.20.20.20/24') } + end end context 'connection absent' do @@ -39,7 +72,15 @@ it_behaves_like 'an idempotent resource' - describe file('/etc/NetworkManager/system-connections/test.nmconnection') do + describe file('/etc/NetworkManager/system-connections/test1.nmconnection') do + it { is_expected.not_to exist } + end + + describe interface('dummy1') do + it { is_expected.not_to exist } + end + + describe file('/etc/NetworkManager/system-connections/test2.nmconnection') do it { is_expected.not_to exist } end end diff --git a/spec/acceptance/nm_spec.rb b/spec/acceptance/nm_spec.rb deleted file mode 100644 index f6db748..0000000 --- a/spec/acceptance/nm_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper_acceptance' - -describe 'nm class' do - context 'without any parameters' do - include_examples 'the example', 'nm.pp' - - it_behaves_like 'an idempotent resource' - - describe package('NetworkManager') do - it { is_expected.to be_installed } - end - - describe service('NetworkManager') do - it { is_expected.to be_enabled } - it { is_expected.to be_running } - end - end -end diff --git a/spec/support/acceptance/setup.rb b/spec/support/acceptance/setup.rb deleted file mode 100644 index d4aa51d..0000000 --- a/spec/support/acceptance/setup.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -script = <<~SH - ip link add name test link eth0 type dummy -SH - -script.split("\n").each do |line| - shell(line) -end