Alexandros Kosiaris has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351603 )

Change subject: interface: Add a new define for handling /e/n/i config
......................................................................

interface: Add a new define for handling /e/n/i config

Add the new inteface efine in order to handle /etc/network/interfaces.d
configuration. This define does NOT hold the user's hand when handling
the config but rather expects the user to pass the config as they want
it. At most, if instructed it will reload the interface in an effort to
apply the configuration. It comes with it's own RSpec tests

Change-Id: I32c2513b1ed4383e912836fac65f186972f3b8c6
---
A modules/interface/.fixtures.yml
A modules/interface/.rspec
A modules/interface/Rakefile
A modules/interface/manifests/enid.pp
A modules/interface/spec/defines/interface_enid_spec.rb
A modules/interface/spec/spec_helper.rb
6 files changed, 120 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/03/351603/1

diff --git a/modules/interface/.fixtures.yml b/modules/interface/.fixtures.yml
new file mode 100644
index 0000000..7799b36
--- /dev/null
+++ b/modules/interface/.fixtures.yml
@@ -0,0 +1,5 @@
+fixtures:
+    symlinks:
+        interface: "#{source_dir}"
+        wmflib: "../../../../wmflib"
+        stdlib: "../../../../stdlib"
diff --git a/modules/interface/.rspec b/modules/interface/.rspec
new file mode 100644
index 0000000..f449dae
--- /dev/null
+++ b/modules/interface/.rspec
@@ -0,0 +1,2 @@
+--format doc
+--color
diff --git a/modules/interface/Rakefile b/modules/interface/Rakefile
new file mode 100644
index 0000000..cd3d379
--- /dev/null
+++ b/modules/interface/Rakefile
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/modules/interface/manifests/enid.pp 
b/modules/interface/manifests/enid.pp
new file mode 100644
index 0000000..c11b25a
--- /dev/null
+++ b/modules/interface/manifests/enid.pp
@@ -0,0 +1,55 @@
+# == Definition: interface::enid
+
+# Define used to populate /etc/network/interfaces.d
+# This definition assumes that the user wants full control of the interface
+# configuration and does not try to provide abstractions around the various
+# things most other structures in the interface module do. Also by default it
+# will NOT try to also set the currently active state to the configured one,
+# that is by default it will NOT do an ifdown/ifup
+#
+# === Parameters
+#  [*content*]
+#    A string that will be /etc/network/interfaces.d/${title}'s content. It is
+#    not possible to pass both content and source.
+#  [*source*]
+#    A path to a file that will be /etc/network/interfaces.d${title}'s content.
+#    It is not possible to pass both content and source.
+#  [*ifdownup*]
+#    A boolean value whether changes in the configuration will cause a down and
+#    then an up of the interface to apply new configuration. Defaults to false.
+#    NOTE: Make sure you need this before specifying, it can have unexpected
+#    consequences
+#  [*ensure*]
+#    Defaults to present.
+define interface::enid(
+    $content = undef,
+    $source = undef,
+    $ifdownup = false,
+    $ensure = 'present',
+){
+    if !os_version('debian >= jessie') {
+        fail('interface is supported only on debian systems since jessie')
+    }
+    if $source and $content {
+        fail('interface: Defining both content and source is not allowed')
+    }
+    if !$source and !$content {
+        fail('interface: Leaving both content and source undefined is not 
allowed')
+    }
+    file { "/etc/network/interfaces.d/${title}":
+        ensure  => $ensure,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0444',
+        content => $content,
+        source  => $source,
+    }
+
+    if $ifdownup {
+        exec { "ifdownup-${title}":
+            command     => "/sbin/ifdown ${title} ; /sbin/ifup ${title}",
+            subscribe   => File["/etc/network/interfaces.d/${title}"],
+            refreshonly => true,
+        }
+    }
+}
diff --git a/modules/interface/spec/defines/interface_enid_spec.rb 
b/modules/interface/spec/defines/interface_enid_spec.rb
new file mode 100644
index 0000000..21e7eff
--- /dev/null
+++ b/modules/interface/spec/defines/interface_enid_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+describe 'interface::enid', :type => :define do
+  let(:title) { 'eth0' }
+
+  describe 'valid inputs' do
+    context 'On Debian Jessie with content only defined' do
+      let(:params) { { :content => 'a' } }
+      let(:facts) { {
+        :lsbdistrelease => 'Jessie',
+        :lsbdistid      => 'Debian',
+      } }
+      it { should compile }
+    end
+    context 'On Debian Jessie with source only defined' do
+      let(:params) { { :source => 'puppet:///a' } }
+      let(:facts) { {
+        :lsbdistrelease => 'Jessie',
+        :lsbdistid      => 'Debian',
+      } }
+      it { should compile }
+    end
+  end
+
+  describe 'invalid inputs' do
+    context 'On Debian Jessie with neither content nor source' do
+      let(:facts) { {
+        :lsbdistrelease => 'Jessie',
+        :lsbdistid      => 'Debian',
+      } }
+      it { should_not compile }
+    end
+    context 'On Debian Jessie with both content and source defined' do
+      let(:params) { { :source => 'puppet:///a', :content => 'a' } }
+      let(:facts) { {
+        :lsbdistrelease => 'Jessie',
+        :lsbdistid      => 'Debian',
+      } }
+      it { should_not compile }
+    end
+    context 'On Ubuntu Trusty' do
+      let(:facts) { {
+        :lsbdistrelease => 'Trusty',
+        :lsbdistid      => 'Ubuntu',
+      } }
+      it { should_not compile }
+    end
+  end
+end
diff --git a/modules/interface/spec/spec_helper.rb 
b/modules/interface/spec/spec_helper.rb
new file mode 100644
index 0000000..d3923f8
--- /dev/null
+++ b/modules/interface/spec/spec_helper.rb
@@ -0,0 +1,8 @@
+require 'rspec-puppet'
+
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+
+RSpec.configure do |c|
+  c.module_path = File.join(fixture_path, 'modules')
+  c.manifest_dir = File.join(fixture_path, 'manifests')
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/351603
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I32c2513b1ed4383e912836fac65f186972f3b8c6
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Alexandros Kosiaris <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to