Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial creation of class firewall for issue #10984 #34

Merged
merged 1 commit into from Jan 13, 2012
Merged

Initial creation of class firewall for issue #10984 #34

merged 1 commit into from Jan 13, 2012

Conversation

mrwacky42
Copy link

  • Add Exec[firewall-persist] to save rules. This allows the host to
    have iptables rules on reboot, before puppet runs.
  • Add brains to the iptables/ip6tables providers to work around issues with old iptales not autoloading the kernel
    modules.
  • Debian Lenny and older hates you. Add iptables init scripts for loading iptables at
    boot on Debian.

@@ -0,0 +1,3 @@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file probably can be removed IMHO. It's not that useful from a unit test perspective. Better to use rspec-puppet for testing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I added it because puppet-module would create it. However, it seems I did it wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I'm not a fan of the scaffold we use for puppet-module. Its not bad for most things, but there are parts I don't agree with. I probably should help fix that instead of whinging about it right? :-).

@kbarber
Copy link
Contributor

kbarber commented Nov 24, 2011

So generally:

  • Debian Squeeze and higher have 'iptables-persistent' which deals with all the persistent stuff. So the way you deal with squeeze and lenny (or pre lenny) may actually be quite different
  • I would like to see the use of 'rspec-puppet' to test this puppet class, I can see this is going to be something people poke with forever (since people are more likely to raise patches on puppet code versus ruby code) - and without unit tests we may find ourselves regressing.

@mrwacky42
Copy link
Author

I'm working on future-proofing against Squeeze and Wheezy.

Meanwhile, are there any working examples of rspec-puppet that I can reference? I'm very much a ruby neophyte.

@kbarber
Copy link
Contributor

kbarber commented Dec 1, 2011

Sure. Well rpec-puppet isn't the easiest of things but I believe rodjek's project has some sweet docs these days.

https://github.com/rodjek/rspec-puppet

You'll need the rspec and mocha gems for any testing - plus the rspec-puppet gem of course (I just use 'gem' & 'rvm' on my mac).

So the idea is ... if you want to test that on debian for example a file gets created, you mock those facts:

let(:facts) { {:operatingsystem => 'Debian', :kernel => 'Linux', } }

Then using this kind of describe you declare that you are analyzing a class context:

describe 'myclass', :type => :class do
  ...
end

And inside you want an example that makes sure in the context the correct file is installed.

Putting it all together in say spec/classes/firewall_spec.rb (the path is magic and implies the firewall class in this case):

describe "debian tests" do
  let(:facts) { {:operatingsystem => 'Debian', :kernel => 'Linux', } }

  it { should contain_file('/etc/iptables/rules.v4').with_ensure("present") }
end

You can then see if it works with:

rspec spec/classes/firewall_spec.rb

Other examples:

debian "ipv6 tests" do
  let(:facts) { {:operatingsystem => 'Debian', :kernel => 'Linux', ip6tables_version => '1.4.1.1' } }
  it { should contain_file('/etc/iptables/rules.v6').with_ensure("present") }
end

You starting to get the idea?

Even if you do the most basic of tests, its going to:

  • Do the most basic of validation (which is more or less the original aim of the test/firewall_class.pp file you created)
  • At least test some of your assertions - and ensure no one messes up the logic in later patches
  • Once you get the basic tests in there, people can add to them - and we can suggest additions to help stop regressions.
  • The tests get into our CI which is tested on lots of platforms and rubies: https://jenkins.puppetlabs.com/view/Puppet%20Modules/job/Puppet%20Module%20-%20firewall/

So yeah - I'm happy to help if you need it ... I don't want make this feel overwhelming so if you want to pair up on this patch or you want me to help just let me know.

}
it { should contain_service('iptables-persistent') }
end
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work yet.

Failures:

  1. firewall Debian Lenny tests
    Failure/Error: it { should contain_service('iptables-persistent') }
    Puppet::Error:
    Could not find class firewall for testhost at line 2 on node testhost

    ./spec/classes/firewall_spec.rb:14:in `block (3 levels) in <top (required)>'

Definitely seeking insight here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ... you need to do this:

--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -8,6 +8,7 @@ require 'puppet'
 require 'mocha'
 gem 'rspec', '>=2.0.0'
 require 'rspec/expectations'
+require 'rspec-puppet'

 # So everyone else doesn't have to include this base constant.
 module PuppetSpec
@@ -31,6 +32,8 @@ end
 RSpec.configure do |config|
   include PuppetSpec::Fixtures

+  config.module_path = File.join(File.dirname(__FILE__), '../../')
+
   config.mock_with :mocha

   config.before :each do
@@ -47,7 +50,7 @@ RSpec.configure do |config|

     # Set the confdir and vardir to gibberish so that tests
     # have to be correctly mocked.
-    Puppet[:confdir] = "/dev/null"
     Puppet[:vardir] = "/dev/null"

     # Avoid opening ports to the outside world
@@ -79,4 +82,5 @@ RSpec.configure do |config|

     GC.enable
   end

And the directory needs to be 'firewall' for the autoloader to do the right thing. I'd love a workaround for that though ... I guess there might be a way to do an explicit 'import' somehow before the tests run.

@mrwacky42
Copy link
Author

Ok, tests implemented!

This is ready for final review.

}
exec { 'set-ipv6-iptables-policy':
command => '/sbin/service ip6tables restart',
subscribe => File[$ip6tables_config],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does ip6tables_config come from? I can't see it defined elsewhere in the code.

* Add Exec[firewall-persist] to save rules.  This allows the host to
  have iptables rules on reboot, before puppet runs.
* Debian hates you.  Add iptables init scripts for loading iptables at
  boot on releases of Debian that do not have them already.
* Add brains to the iptables/ip6tables providers to ensure kernel modules
  are loaded.
saysjonathan added a commit that referenced this pull request Jan 13, 2012
Initial creation of class firewall for issue #10984
@saysjonathan saysjonathan merged commit bfbf01b into puppetlabs:master Jan 13, 2012
kbarber added a commit to kbarber/puppetlabs-firewall that referenced this pull request Jan 13, 2012
…all"

This reverts commit bfbf01b, reversing
changes made to 0b55830.

This patch breaks the build, and wasn't ready for merge. The rspec test
scaffolding wasn't prepared and hasn't been tested with this module properly.
@mrwacky42
Copy link
Author

Is there a way to reopen this pull request so it gets merged ?

@geoffdavis
Copy link

I'd love to see this merged as well. As it stands, I backported this into a site-specific class on my local configuration.

Can pull requests be re-opened, or do you have to file another one?

cegeka-jenkins pushed a commit to cegeka/puppet-firewall that referenced this pull request Oct 23, 2017
Initial creation of class firewall for issue #10984
cegeka-jenkins pushed a commit to cegeka/puppet-firewall that referenced this pull request Oct 23, 2017
…all"

This reverts commit bfbf01b, reversing
changes made to 0b55830.

This patch breaks the build, and wasn't ready for merge. The rspec test
scaffolding wasn't prepared and hasn't been tested with this module properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants