Skip to content

Commit

Permalink
adding tests and foodcritic
Browse files Browse the repository at this point in the history
  • Loading branch information
Bao Nguyen committed Jul 25, 2014
1 parent e222323 commit cf34be8
Show file tree
Hide file tree
Showing 25 changed files with 233 additions and 87 deletions.
23 changes: 23 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,23 @@
AllCops:
Include:
- metadata.rb
- Gemfile
- attributes/**
- recipes/**
- libraries/**
- providers/**
- resources/**
Exclude:
- example/**
- test/**
- vendor/**

Encoding:
Enabled: false

LineLength:
Enabled: false

WordArray:
MinSize: 3

9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
before_script:
- bundle exec berks install
script:
- bundle exec rake test:quick

11 changes: 10 additions & 1 deletion Gemfile
@@ -1,7 +1,16 @@
source 'https://rubygems.org'

gem 'test-kitchen', '~> 1.2.1'
gem 'kitchen-vagrant', '= 0.15.0', :group => :integration
gem 'kitchen-vagrant', '= 0.15.0', group: :integration
gem 'librarian-chef'
gem 'berkshelf'
gem 'chef-zero'

group 'develop' do
gem 'kitchen-docker-api'
gem 'rake'
gem 'foodcritic', git: 'https://github.com/mlafeldt/foodcritic.git', branch: 'improve-rake-task'
gem 'rubocop'
gem 'knife-cookbook-doc'
gem 'chefspec', '>= 3.2.0'
end
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -63,3 +63,22 @@ quagga_ospf "#{node.quagga.ospf.area}" do
networks node.quagga.networks
end
```

Author and License
===================

__Author__ Bao Nguyen <ngqbao@gmail.com>

Copyright 2014, Ooyala Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
73 changes: 73 additions & 0 deletions Rakefile
@@ -0,0 +1,73 @@
#!/usr/bin/env rake
require 'rake'
require 'rspec/core/rake_task'

task :default => 'test:quick'

namespace :test do

RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob('test/spec/**/*_spec.rb')
t.rspec_opts = "--color -f d"
end

begin
require 'kitchen/rake_tasks'
Kitchen::RakeTasks.new
rescue
puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
end

begin
require 'foodcritic/rake_task'
require 'foodcritic'
task :default => [:foodcritic]
FoodCritic::Rake::LintTask.new do |t|
t.options = {
fail_tags: %w/correctness services libraries deprecated/,
exclude_paths: ['test/**/*', 'spec/**/*', 'features/**/*', 'example/**/*']
}
end
rescue LoadError
warn "Foodcritic Is missing ZOMG"
end

begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new do |task|
task.fail_on_error = true
task.options = %w{-D -a}
end
rescue LoadError
warn "Rubocop gem not installed, now the code will look like crap!"
end


desc 'Run all of the quick tests.'
task :quick do
Rake::Task['test:rubocop'].invoke
Rake::Task['test:foodcritic'].invoke
Rake::Task['test:spec'].invoke
end


desc 'Run _all_ the tests. Go get a coffee.'
task :complete do
Rake::Task['test:quick'].invoke
Rake::Task['test:kitchen:all'].invoke
end

desc 'Run CI tests'
task :ci do
Rake::Task['test:complete'].invoke
end
end


namespace :release do
task :update_metadata do
end

task :tag_release do
end
end
4 changes: 2 additions & 2 deletions attributes/bgpd.rb
@@ -1,5 +1,5 @@
include_attribute "quagga"
include_attribute 'quagga'

default[:quagga][:bgp][:local_asn] = ""
default[:quagga][:bgp][:local_asn] = ''
default[:quagga][:bgp][:networks] = []
default[:quagga][:bgp][:peers] = {}
10 changes: 5 additions & 5 deletions attributes/default.rb
@@ -1,4 +1,4 @@
default[:quagga][:dir] = "/etc/quagga"
default[:quagga][:dir] = '/etc/quagga'

default[:quagga][:user] = 'quagga'
default[:quagga][:group] = 'quagga'
Expand All @@ -13,9 +13,9 @@
default[:quagga][:daemons][:babeld] = false

# insecured default username and password. overwrite when deploy
default[:quagga][:password] = "quagga"
default[:quagga][:enabled_password] = "quagga"
default[:quagga][:password] = 'quagga'
default[:quagga][:enabled_password] = 'quagga'

default[:quagga]["integrated-vtysh-config"] = false
default[:quagga]['integrated-vtysh-config'] = false

default[:quagga][:loopback] = "127.0.0.1"
default[:quagga][:loopback] = '127.0.0.1'
4 changes: 2 additions & 2 deletions attributes/ospfd.rb
@@ -1,6 +1,6 @@
include_attribute "quagga"
include_attribute 'quagga'

default[:quagga][:ospf][:area] = ""
default[:quagga][:ospf][:area] = ''
default[:quagga][:ospf][:networks] = []
default[:quagga][:ospf][:protocols] = []
default[:quagga][:ospf][:interfaces] = []
16 changes: 6 additions & 10 deletions metadata.rb
@@ -1,11 +1,7 @@
name "quagga"
maintainer "Bao Nguyen"
maintainer_email "ngqbao@gmail.com"
license "All rights reserved"
description "Generic Quagga cookbook"
name 'quagga'
maintainer 'Bao Nguyen'
maintainer_email 'ngqbao@gmail.com'
license 'All rights reserved'

This comment has been minimized.

Copy link
@irabinovitch

irabinovitch Aug 15, 2014

This should be Apache shouldn't it?

description 'Generic Quagga cookbook'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.1"

%w{ }.each do |i|
depends i
end
version '0.1.2'
24 changes: 12 additions & 12 deletions providers/bgp.rb
Expand Up @@ -20,33 +20,33 @@

action :add do
bgpd_path = "#{node.quagga.dir}/bgpd.conf"
Chef::Log.info "Adding #{new_resource.name.to_s}: acl to #{bgpd_path}"
Chef::Log.info "Adding #{new_resource.name}: acl to #{bgpd_path}"

template "#{bgpd_path}" do
cookbook "quagga"
source "bgpd.conf.erb"
cookbook 'quagga'
source 'bgpd.conf.erb'
owner node.quagga.user
group node.quagga.group
mode "0644"
mode '0644'
variables(
:local_asn => new_resource.name,
:ebgp_peers => new_resource.ebgp_peers,
:networks => new_resource.networks,
:loopback => new_resource.loopback
local_asn: new_resource.name,
ebgp_peers: new_resource.ebgp_peers,
networks: new_resource.networks,
loopback: new_resource.loopback
)
notifies :reload, "service[quagga]", :delayed
notifies :reload, 'service[quagga]', :delayed
end

# configure loopback
ifconfig "#{new_resource.loopback}/32" do
device "lo:1"
device 'lo:1'
end
end

action :remove do
bgpd_path = "#{node.quagga.dir}/#{new_resource.name}"
if ::File.exists?(bgpd_path)
Chef::Log.info "Removing #{new_resource.file_type.to_s}: bgp from #{bgpd_path}"
if ::File.exist?(bgpd_path)
Chef::Log.info "Removing #{new_resource.file_type}: bgp from #{bgpd_path}"
file bgpd_path do
action :delete
end
Expand Down
28 changes: 14 additions & 14 deletions providers/ospf.rb
Expand Up @@ -20,35 +20,35 @@

action :add do
ospfd_path = "#{node.quagga.dir}/ospfd.conf"
Chef::Log.info "Adding #{new_resource.name.to_s}: ospf to #{ospfd_path}"
Chef::Log.info "Adding #{new_resource.name}: ospf to #{ospfd_path}"

template "#{ospfd_path}" do
cookbook "quagga"
source "ospfd.conf.erb"
cookbook 'quagga'
source 'ospfd.conf.erb'
owner node.quagga.user
group node.quagga.group
mode "0644"
mode '0644'
variables(
:area => new_resource.name,
:networks => new_resource.networks,
:loopback => new_resource.loopback,
:protocols => new_resource.protocols,
:interfaces => new_resource.interfaces,
:ospf_options => new_resource.ospf_options
area: new_resource.name,
networks: new_resource.networks,
loopback: new_resource.loopback,
protocols: new_resource.protocols,
interfaces: new_resource.interfaces,
ospf_options: new_resource.ospf_options
)
notifies :reload, "service[quagga]", :delayed
notifies :reload, 'service[quagga]', :delayed
end

# configure loopback
ifconfig "#{new_resource.loopback}/32" do
device "lo:1"
device 'lo:1'
end
end

action :remove do
ospfd_path = "#{node.quagga.dir}/ospfd.conf"
if ::File.exists?(ospfd_path)
Chef::Log.info "Removing #{new_resource.file_type.to_s}: ospf from #{ospfd_path}"
if ::File.exist?(ospfd_path)
Chef::Log.info "Removing #{new_resource.file_type}: ospf from #{ospfd_path}"
file ospfd_path do
action :delete
end
Expand Down
18 changes: 9 additions & 9 deletions providers/zebra.rb
Expand Up @@ -20,26 +20,26 @@

action :add do
zebra_path = "#{node.quagga.dir}/zebra.conf"
Chef::Log.info "Adding #{new_resource.name.to_s}: interface to #{zebra_path}"
Chef::Log.info "Adding #{new_resource.name}: interface to #{zebra_path}"

template "#{zebra_path}" do
cookbook "quagga"
source "zebra.conf.erb"
cookbook 'quagga'
source 'zebra.conf.erb'
owner node.quagga.user
group node.quagga.group
mode "0644"
mode '0644'
variables(
:interfaces => new_resource.interfaces,
:static_routes => new_resource.static_routes
interfaces: new_resource.interfaces,
static_routes: new_resource.static_routes
)
notifies :reload, "service[quagga]", :delayed
notifies :reload, 'service[quagga]', :delayed
end
end

action :remove do
zebra_path = "#{node.quagga.dir}/zebra.conf"
if ::File.exists?(zebra_path)
Chef::Log.info "Removing #{new_resource.file_type.to_s}: interface from #{zebra_path}"
if ::File.exist?(zebra_path)
Chef::Log.info "Removing #{new_resource.file_type}: interface from #{zebra_path}"
file zebra_path do
action :delete
end
Expand Down
2 changes: 1 addition & 1 deletion recipes/bgpd.rb
Expand Up @@ -18,6 +18,6 @@
# limitations under the License.
#

include_recipe "quagga"
include_recipe 'quagga'

node.set[:quagga][:daemons][:bgpd] = true

0 comments on commit cf34be8

Please sign in to comment.