modulesync 2017-02-07

This commit is contained in:
Zach Leslie 2017-02-07 21:30:33 -08:00
parent da52e85d3e
commit 4632063f89
16 changed files with 810 additions and 187 deletions

19
.gitignore vendored
View File

@ -1,3 +1,18 @@
Gemfile.lock
.bundle
pkg/
Gemfile.lock
Gemfile.local
vendor/
.vendor/
spec/fixtures/manifests/
spec/fixtures/modules/
.vagrant/
.bundle/
coverage/
log/
.idea/
.dependencies/
.librarian/
Puppetfile.lock
*.iml
.*.sw?
.yardoc/

1
.msync.yml Normal file
View File

@ -0,0 +1 @@
modulesync_config_version: '0.19.3'

1
.pmtignore Normal file
View File

@ -0,0 +1 @@
docs/

528
.rubocop.yml Normal file
View File

@ -0,0 +1,528 @@
require: rubocop-rspec
AllCops:
TargetRubyVersion: 1.9
Include:
- ./**/*.rb
Exclude:
- files/**/*
- vendor/**/*
- .vendor/**/*
- pkg/**/*
- spec/fixtures/**/*
Lint/ConditionPosition:
Enabled: True
Lint/ElseLayout:
Enabled: True
Lint/UnreachableCode:
Enabled: True
Lint/UselessComparison:
Enabled: True
Lint/EnsureReturn:
Enabled: True
Lint/HandleExceptions:
Enabled: True
Lint/LiteralInCondition:
Enabled: True
Lint/ShadowingOuterLocalVariable:
Enabled: True
Lint/LiteralInInterpolation:
Enabled: True
Style/HashSyntax:
Enabled: True
Style/RedundantReturn:
Enabled: True
Lint/AmbiguousOperator:
Enabled: True
Lint/AssignmentInCondition:
Enabled: True
Style/SpaceBeforeComment:
Enabled: True
Style/AndOr:
Enabled: True
Style/RedundantSelf:
Enabled: True
Metrics/BlockLength:
Enabled: False
# Method length is not necessarily an indicator of code quality
Metrics/MethodLength:
Enabled: False
# Module length is not necessarily an indicator of code quality
Metrics/ModuleLength:
Enabled: False
Style/WhileUntilModifier:
Enabled: True
Lint/AmbiguousRegexpLiteral:
Enabled: True
Security/Eval:
Enabled: True
Lint/BlockAlignment:
Enabled: True
Lint/DefEndAlignment:
Enabled: True
Lint/EndAlignment:
Enabled: True
Lint/DeprecatedClassMethods:
Enabled: True
Lint/Loop:
Enabled: True
Lint/ParenthesesAsGroupedExpression:
Enabled: True
Lint/RescueException:
Enabled: True
Lint/StringConversionInInterpolation:
Enabled: True
Lint/UnusedBlockArgument:
Enabled: True
Lint/UnusedMethodArgument:
Enabled: True
Lint/UselessAccessModifier:
Enabled: True
Lint/UselessAssignment:
Enabled: True
Lint/Void:
Enabled: True
Style/AccessModifierIndentation:
Enabled: True
Style/AccessorMethodName:
Enabled: True
Style/Alias:
Enabled: True
Style/AlignArray:
Enabled: True
Style/AlignHash:
Enabled: True
Style/AlignParameters:
Enabled: True
Metrics/BlockNesting:
Enabled: True
Style/AsciiComments:
Enabled: True
Style/Attr:
Enabled: True
Style/BracesAroundHashParameters:
Enabled: True
Style/CaseEquality:
Enabled: True
Style/CaseIndentation:
Enabled: True
Style/CharacterLiteral:
Enabled: True
Style/ClassAndModuleCamelCase:
Enabled: True
Style/ClassAndModuleChildren:
Enabled: False
Style/ClassCheck:
Enabled: True
# Class length is not necessarily an indicator of code quality
Metrics/ClassLength:
Enabled: False
Style/ClassMethods:
Enabled: True
Style/ClassVars:
Enabled: True
Style/WhenThen:
Enabled: True
Style/WordArray:
Enabled: True
Style/UnneededPercentQ:
Enabled: True
Style/Tab:
Enabled: True
Style/SpaceBeforeSemicolon:
Enabled: True
Style/TrailingBlankLines:
Enabled: True
Style/SpaceInsideBlockBraces:
Enabled: True
Style/SpaceInsideBrackets:
Enabled: True
Style/SpaceInsideHashLiteralBraces:
Enabled: True
Style/SpaceInsideParens:
Enabled: True
Style/LeadingCommentSpace:
Enabled: True
Style/SpaceBeforeFirstArg:
Enabled: True
Style/SpaceAfterColon:
Enabled: True
Style/SpaceAfterComma:
Enabled: True
Style/SpaceAfterMethodName:
Enabled: True
Style/SpaceAfterNot:
Enabled: True
Style/SpaceAfterSemicolon:
Enabled: True
Style/SpaceAroundEqualsInParameterDefault:
Enabled: True
Style/SpaceAroundOperators:
Enabled: True
Style/SpaceBeforeBlockBraces:
Enabled: True
Style/SpaceBeforeComma:
Enabled: True
Style/CollectionMethods:
Enabled: True
Style/CommentIndentation:
Enabled: True
Style/ColonMethodCall:
Enabled: True
Style/CommentAnnotation:
Enabled: True
# 'Complexity' is very relative
Metrics/CyclomaticComplexity:
Enabled: False
Style/ConstantName:
Enabled: True
Style/Documentation:
Enabled: False
Style/DefWithParentheses:
Enabled: True
Style/PreferredHashMethods:
Enabled: True
Style/DotPosition:
EnforcedStyle: trailing
Style/DoubleNegation:
Enabled: True
Style/EachWithObject:
Enabled: True
Style/EmptyLineBetweenDefs:
Enabled: True
Style/IndentArray:
Enabled: True
Style/IndentHash:
Enabled: True
Style/IndentationConsistency:
Enabled: True
Style/IndentationWidth:
Enabled: True
Style/EmptyLines:
Enabled: True
Style/EmptyLinesAroundAccessModifier:
Enabled: True
Style/EmptyLiteral:
Enabled: True
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Enabled: False
Style/MethodCallWithoutArgsParentheses:
Enabled: True
Style/MethodDefParentheses:
Enabled: True
Style/LineEndConcatenation:
Enabled: True
Style/TrailingWhitespace:
Enabled: True
Style/StringLiterals:
Enabled: True
Style/TrailingCommaInArguments:
Enabled: True
Style/TrailingCommaInLiteral:
Enabled: True
Style/GlobalVars:
Enabled: True
Style/GuardClause:
Enabled: True
Style/IfUnlessModifier:
Enabled: True
Style/MultilineIfThen:
Enabled: True
Style/NegatedIf:
Enabled: True
Style/NegatedWhile:
Enabled: True
Style/Next:
Enabled: True
Style/SingleLineBlockParams:
Enabled: True
Style/SingleLineMethods:
Enabled: True
Style/SpecialGlobalVars:
Enabled: True
Style/TrivialAccessors:
Enabled: True
Style/UnlessElse:
Enabled: True
Style/VariableInterpolation:
Enabled: True
Style/VariableName:
Enabled: True
Style/WhileUntilDo:
Enabled: True
Style/EvenOdd:
Enabled: True
Style/FileName:
Enabled: True
Style/For:
Enabled: True
Style/Lambda:
Enabled: True
Style/MethodName:
Enabled: True
Style/MultilineTernaryOperator:
Enabled: True
Style/NestedTernaryOperator:
Enabled: True
Style/NilComparison:
Enabled: True
Style/FormatString:
Enabled: True
Style/MultilineBlockChain:
Enabled: True
Style/Semicolon:
Enabled: True
Style/SignalException:
Enabled: True
Style/NonNilCheck:
Enabled: True
Style/Not:
Enabled: True
Style/NumericLiterals:
Enabled: True
Style/OneLineConditional:
Enabled: True
Style/OpMethod:
Enabled: True
Style/ParenthesesAroundCondition:
Enabled: True
Style/PercentLiteralDelimiters:
Enabled: True
Style/PerlBackrefs:
Enabled: True
Style/PredicateName:
Enabled: True
Style/RedundantException:
Enabled: True
Style/SelfAssignment:
Enabled: True
Style/Proc:
Enabled: True
Style/RaiseArgs:
Enabled: True
Style/RedundantBegin:
Enabled: True
Style/RescueModifier:
Enabled: True
# based on https://github.com/voxpupuli/modulesync_config/issues/168
Style/RegexpLiteral:
EnforcedStyle: percent_r
Enabled: True
Lint/UnderscorePrefixedVariableName:
Enabled: True
Metrics/ParameterLists:
Enabled: False
Lint/RequireParentheses:
Enabled: True
Style/SpaceBeforeFirstArg:
Enabled: True
Style/ModuleFunction:
Enabled: True
Lint/Debugger:
Enabled: True
Style/IfWithSemicolon:
Enabled: True
Style/Encoding:
Enabled: True
Style/BlockDelimiters:
Enabled: True
Style/MultilineBlockLayout:
Enabled: True
# 'Complexity' is very relative
Metrics/AbcSize:
Enabled: False
# 'Complexity' is very relative
Metrics/PerceivedComplexity:
Enabled: False
Lint/UselessAssignment:
Enabled: True
Style/ClosingParenthesisIndentation:
Enabled: True
# RSpec
# We don't use rspec in this way
RSpec/DescribeClass:
Enabled: False
# Example length is not necessarily an indicator of code quality
RSpec/ExampleLength:
Enabled: False
RSpec/NamedSubject:
Enabled: False
# disabled for now since they cause a lot of issues
# these issues aren't easy to fix
RSpec/RepeatedDescription:
Enabled: False
# disabled for simpler testing on multiple platforms in case statement
RSpec/RepeatedExample:
Enabled: False
RSpec/NestedGroups:
Enabled: False
# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs
Security/YAMLLoad:
Enabled: false

6
.sync.yml Normal file
View File

@ -0,0 +1,6 @@
Gemfile:
optional:
':testextra':
- gem: 'rspec-mocks'
- gem: 'rspec-expectations'
mock_with: ':rspec'

View File

@ -1,19 +1,36 @@
---
sudo: false
dist: trusty
language: ruby
bundler_args: --without development
cache: bundler
bundler_args: --without system_tests development
before_install:
- bundle -v
- rm Gemfile.lock || true
- gem update --system
- gem update bundler
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2
script: bundle exec rake test
env:
- PUPPET_VERSION="~> 4.2.0" STRICT_VARIABLES=yes
- PUPPET_VERSION="~> 4.3.0" STRICT_VARIABLES=yes
- PUPPET_VERSION="~> 4.4.0" STRICT_VARIABLES=yes
- PUPPET_VERSION="~> 4.5.0" STRICT_VARIABLES=yes
- PUPPET_VERSION="~> 4.6.1" STRICT_VARIABLES=yes
- gem --version
- bundle -v
script:
- 'bundle exec rake $CHECK'
matrix:
fast_finish: true
include:
- rvm: 2.1.9
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.2.6
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.3.3
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.4.0
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.4.0
env: PUPPET_VERSION="~> 4.0" CHECK=rubocop
- rvm: 2.4.0
env: PUPPET_VERSION="~> 4.0" CHECK=build
branches:
only:
- master
- /^v\d/
notifications:
email: false

2
.yardopts Normal file
View File

@ -0,0 +1,2 @@
--markup markdown
--output-dir docs/

71
Gemfile
View File

@ -1,25 +1,62 @@
source "https://rubygems.org"
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
def location_for(place, fake_version = nil)
if place =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
elsif place =~ /^file:\/\/(.*)/
['>= 0', { :path => File.expand_path($1), :require => false }]
else
[place, { :require => false }]
end
end
group :test do
gem "rake"
gem "puppet", ENV['PUPPET_VERSION'] || '~> 4.6.1'
gem "rspec"
gem "rspec-core"
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
gem "puppetlabs_spec_helper"
gem "metadata-json-lint"
gem "rspec-puppet-facts"
gem 'json_pure', '<=2.0.1', :require => false if RUBY_VERSION =~ /^1\./
gem 'puppetlabs_spec_helper', '~> 1.2.2', :require => false
gem 'rspec-puppet', '~> 2.5', :require => false
gem 'rspec-puppet-facts', :require => false
gem 'rspec-puppet-utils', :require => false
gem 'puppet-lint-absolute_classname-check', :require => false
gem 'puppet-lint-leading_zero-check', :require => false
gem 'puppet-lint-trailing_comma-check', :require => false
gem 'puppet-lint-version_comparison-check', :require => false
gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false
gem 'puppet-lint-unquoted_string-check', :require => false
gem 'puppet-lint-variable_contains_upcase', :require => false
gem 'metadata-json-lint', :require => false
gem 'puppet-blacksmith', :require => false
gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem.git'
gem 'puppet-strings', '~> 1.0.0', :require => false
gem 'redcarpet', :require => false
gem 'rubocop', '~> 0.47.0', :require => false if RUBY_VERSION >= '2.3.0'
gem 'rubocop-rspec', '~> 1.10.0', :require => false if RUBY_VERSION >= '2.3.0'
gem 'mocha', '>= 1.2.1', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
gem 'github_changelog_generator', '~> 1.13.0', :require => false if RUBY_VERSION < '2.2.2'
gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2'
gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
end
group :development do
gem "travis"
gem "travis-lint"
gem "vagrant-wrapper"
gem "puppet-blacksmith"
gem 'travis', :require => false
gem 'travis-lint', :require => false
gem 'guard-rake', :require => false
end
group :system_tests do
gem "beaker"
gem "beaker-rspec"
group :testextra do
gem 'rspec-mocks'
gem 'rspec-expectations'
end
if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion.to_s, :require => false, :groups => [:test]
else
gem 'facter', :require => false, :groups => [:test]
end
ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 4.0' : puppetversion = ENV['PUPPET_VERSION'].to_s
gem 'puppet', puppetversion, :require => false, :groups => [:test]
# vim: syntax=ruby

View File

@ -1,56 +1,44 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet/version'
require 'puppet/vendor/semantic/lib/semantic' unless Puppet.version.to_f < 3.6
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet_blacksmith/rake_tasks'
require 'voxpupuli/release/rake_tasks'
require 'puppet-strings/tasks'
# These gems aren't always present, for instance
# on Travis with --without development
begin
require 'puppet_blacksmith/rake_tasks'
rescue LoadError
end
Rake::Task[:lint].clear
PuppetLint.configuration.relative = true
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}'
PuppetLint.configuration.fail_on_warnings = true
# Forsake support for Puppet 2.6.2 for the benefit of cleaner code.
# http://puppet-lint.com/checks/class_parameter_defaults/
PuppetLint.configuration.send('disable_class_parameter_defaults')
# http://puppet-lint.com/checks/class_inherits_from_params_class/
PuppetLint.configuration.send('relative')
PuppetLint.configuration.send('disable_140chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
exclude_paths = [
"bundle/**/*",
"pkg/**/*",
"vendor/**/*",
"spec/**/*",
]
exclude_paths = %w(
pkg/**/*
vendor/**/*
.vendor/**/*
spec/**/*
)
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths
desc "Run acceptance tests"
desc 'Run acceptance tests'
RSpec::Core::RakeTask.new(:acceptance) do |t|
t.pattern = 'spec/acceptance'
end
desc "Populate CONTRIBUTORS file"
task :contributors do
system("git log --format='%aN' | sort -u > CONTRIBUTORS")
end
task :metadata do
sh "metadata-json-lint metadata.json"
end
desc "Run syntax, lint, and spec tests."
task :test => [
:syntax,
:lint,
:spec,
:metadata,
desc 'Run tests metadata_lint, release_checks'
task test: [
:metadata_lint,
:release_checks,
]
begin
require 'github_changelog_generator/task'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
version = (Blacksmith::Modulefile.new).version
config.future_release = "#{version}"
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not impact the functionality of the module."
config.exclude_labels = %w{duplicate question invalid wontfix modulesync}
end
rescue LoadError
end
# vim: syntax=ruby

View File

@ -1,72 +1,69 @@
require 'tempfile'
Puppet::Type.type(:jail).provide(:iocage) do
desc 'Manage jails using iocage(8)'
confine kernel: :freebsd
defaultfor kernel: :freebsd
desc "Manage jails using iocage(8)"
confine :kernel => :freebsd
defaultfor :kernel => :freebsd
commands :iocage => '/usr/local/sbin/iocage'
commands iocage: '/usr/local/sbin/iocage'
mk_resource_methods
def self.jail_list
output = iocage(['list']).split("\n")
fields = output.shift.split().map {|i| i.downcase.to_sym }
fields = output.shift.split.map { |i| i.downcase.to_sym }
data = []
output.each {|j|
output.each do |j|
jail_data = {}
values = j.split()
values = j.split
iocage_jail_list_regex = /^(-|[0-9]+)\s+([[:xdigit:]]{8}-([[:xdigit:]]{4}-){3})[[:xdigit:]]{12}\s+(on|off)\s+(up|down)\s+.+$/
next if iocage_jail_list_regex.match(j) == nil
iocage_jail_list_regex = %r{^(-|[0-9]+)\s+([[:xdigit:]]{8}-([[:xdigit:]]{4}-){3})[[:xdigit:]]{12}\s+(on|off)\s+(up|down)\s+.+$}
next if iocage_jail_list_regex.match(j).nil?
values.each_index {|i|
values.each_index do |i|
jail_data[fields[i]] = values[i]
}
end
data << jail_data
}
end
return data
data
end
def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
if (resource = resources[prov.name])
resource.provider = prov
end
end
end
def self.instances
jail_list.collect do |j|
jail_list.map do |j|
jail_properties = {
:provider => :iocage,
:ensure => :present,
:name => j[:tag],
:state => j[:state],
:boot => j[:boot],
provider: :iocage,
ensure: :present,
name: j[:tag],
state: j[:state],
boot: j[:boot]
}
if j[:jid] != '-'
jail_properties[:jid] = j[:jid]
end
jail_properties[:jid] = j[:jid] if j[:jid] != '-'
all_properties = get_jail_properties(j[:tag])
extra_properties = [
:ip4_addr,
:ip6_addr,
:hostname,
:jail_zfs,
:jail_zfs_dataset,
:ip4_addr,
:ip6_addr,
:hostname,
:jail_zfs,
:jail_zfs_dataset
]
extra_properties.each {|p|
extra_properties.each do |p|
jail_properties[p] = all_properties[p.to_s]
}
end
debug jail_properties
@ -74,19 +71,19 @@ Puppet::Type.type(:jail).provide(:iocage) do
end
end
def initialize(value={})
def initialize(value = {})
super(value)
@property_flush = {}
end
def self.get_jail_properties(jailname)
data = {}
output = iocage(['get','all',jailname])
output.lines.each {|l|
output = iocage(['get', 'all', jailname])
output.lines.each do |l|
key, value = l.split(':', 2)
data[key] = value.chomp
}
data.reject! {|k,v| k == nil or v == nil}
end
data.reject! { |k, v| k.nil? || v.nil? }
debug data
@ -151,63 +148,57 @@ Puppet::Type.type(:jail).provide(:iocage) do
Puppet.debug "JailIocage(#flush): #{@property_flush}"
pre_start_properties = [
:boot,
:ip4_addr,
:ip6_addr,
:hostname,
:jail_zfs,
:jail_zfs_dataset,
:boot,
:ip4_addr,
:ip6_addr,
:hostname,
:jail_zfs,
:jail_zfs_dataset
]
if @property_flush[:ensure]
case resource[:ensure]
when :absent
iocage(['stop', resource[:name]])
iocage(['destroy', '-f', resource[:name]])
when :present
iocage(['create', '-c', "tag=#{resource[:name]}"])
if resource[:state] == :up
pre_start_properties.each {|p|
if resource[p]
set_property(p.to_s, resource[p])
end
}
iocage(['start', resource[:name]])
if resource[:user_data]
tmpfile = Tempfile.new('puppet-iocage')
tmpfile.write(resource[:user_data])
tmpfile.close
execute("/usr/local/sbin/iocage exec #{resource[:name]} /bin/sh",
{ :stdinfile => tmpfile.path }
)
tmpfile.delete
end
end
case resource[:ensure]
when :absent
iocage(['stop', resource[:name]])
iocage(['destroy', '-f', resource[:name]])
when :present
iocage(['create', '-c', "tag=#{resource[:name]}"])
end
if resource[:state] == :up && resource[:ensure] == :present
pre_start_properties.each do |p|
set_property(p.to_s, resource[p]) if resource[p]
end
iocage(['start', resource[:name]])
if resource[:user_data]
tmpfile = Tempfile.new('puppet-iocage')
tmpfile.write(resource[:user_data])
tmpfile.close
execute("/usr/local/sbin/iocage exec #{resource[:name]} /bin/sh",
stdinfile: tmpfile.path)
tmpfile.delete
end
end
need_restart = false
pre_start_properties.each {|p|
pre_start_properties.each do |p|
if @property_flush[p]
need_restart = true
set_property(p.to_s, @property_flush[p])
end
}
end
if @property_flush[:state]
case resource[:state]
when :up
need_restart = false
iocage(['start', resource[:name]])
when :down
need_restart = false
iocage(['stop', resource[:name]])
when :up
need_restart = false
iocage(['start', resource[:name]])
when :down
need_restart = false
iocage(['stop', resource[:name]])
end
end
if need_restart
restart
end
restart if need_restart
end
@property_hash = resource.to_hash
end

View File

@ -6,53 +6,52 @@
#
Puppet::Type.newtype(:jail) do
ensurable
newparam(:name, :namevar => true) do
desc "The name of the jail, and only the name"
newparam(:name, namevar: true) do
desc 'The name of the jail, and only the name'
end
newparam(:jid) do
desc "The jail ID for running jails"
desc 'The jail ID for running jails'
end
newparam(:user_data) do
desc "Rendered content to pipe to a jailed shell upon creation"
desc 'Rendered content to pipe to a jailed shell upon creation'
end
newproperty(:state) do
desc "Either running or stopped"
desc 'Either running or stopped'
newvalues(:up, :down)
end
newproperty(:boot) do
desc "Either on or off"
desc 'Either on or off'
newvalues(:on, :off)
end
newproperty(:ip4_addr) do
desc "Interface|Address"
desc 'Interface|Address'
end
newproperty(:ip6_addr) do
desc "Interface|Address"
desc 'Interface|Address'
end
newproperty(:hostname) do
desc "Hostname of the jail"
desc 'Hostname of the jail'
end
newproperty(:jail_zfs) do
desc "Enable the jail_zfs"
desc 'Enable the jail_zfs'
newvalues(:on, :off)
end
newproperty(:jail_zfs_dataset) do
desc "Set the jail_zfs_data set iocage parameter"
desc 'Set the jail_zfs_data set iocage parameter'
validate do |value|
unless value.is_a? String
raise ArgumentError, "jail_zfs_dataset requires string value"
raise ArgumentError, 'jail_zfs_dataset requires string value'
end
end
end
@ -61,7 +60,7 @@ Puppet::Type.newtype(:jail) do
if @parameters[:state] == :up
provider.restart
else
debug "Skipping restart: jail not running"
debug 'Skipping restart: jail not running'
end
end
end

View File

@ -0,0 +1,4 @@
require 'rspec-puppet'
at_exit { RSpec::Puppet::Coverage.report! }
# vim: syntax=ruby

14
spec/default_facts.yml Normal file
View File

@ -0,0 +1,14 @@
# This file is managed via modulesync
# https://github.com/voxpupuli/modulesync
# https://github.com/voxpupuli/modulesync_config
#
# use default_module_facts.yaml for module specific
# facts.
#
# Hint if using with rspec-puppet-facts ("on_supported_os.each"):
# if a same named fact exists in facterdb it will be overridden.
---
concat_basedir: "/tmp"
ipaddress: "172.16.254.254"
is_pe: false
macaddress: "AA:AA:AA:AA:AA:AA"

View File

@ -2,6 +2,32 @@ require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts
RSpec.configure do |config|
config.mock_with :rspec
if Dir.exist?(File.expand_path('../../lib', __FILE__))
require 'coveralls'
require 'simplecov'
require 'simplecov-console'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'
add_filter '/vendor'
add_filter '/.vendor'
end
end
RSpec.configure do |c|
default_facts = {
puppetversion: Puppet.version,
facterversion: Facter.version
}
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts
c.mock_with :rspec
end
# vim: syntax=ruby

View File

@ -4,26 +4,23 @@ require 'puppet/provider/jail/iocage'
provider_class = Puppet::Type.type(:jail).provider(:iocage)
describe provider_class do
context "#jail_list" do
it "should parse jail listing" do
context '#jail_list' do
it 'parses jail listing' do
fixture = File.read('spec/fixtures/iocage_list')
#provider_class.stub(:iocage).with(['list']) { fixture }
# provider_class.stub(:iocage).with(['list']) { fixture }
allow(provider_class).to receive(:iocage).with(['list']) { fixture }
wanted = [{:jid=>"-", :uuid=>"018e776d-4315-11e5-94bc-0025905cf7cc", :boot=>"off", :state=>"down", :tag=>"auth4"}, {:jid=>"-", :uuid=>"14b47568-448e-11e5-94bc-0025905cf7cc", :boot=>"off", :state=>"down", :tag=>"graphite2"}, {:jid=>"1", :uuid=>"19e2885e-448e-11e5-94bc-0025905cf7cc", :boot=>"on", :state=>"up", :tag=>"git2"}, {:jid=>"2", :uuid=>"64a7af2c-4909-11e5-9073-0025905cf7cc", :boot=>"on", :state=>"up", :tag=>"pm3"}, {:jid=>"-", :uuid=>"c3936d1d-46f5-11e5-9073-0025905cf7cc", :boot=>"off", :state=>"down", :tag=>"ns1"}, {:jid=>"333", :uuid=>"ca29dc76-46f6-11e5-9073-0025905cf7cc", :boot=>"on", :state=>"up", :tag=>"pdb2"}, {:jid=>"-", :uuid=>"e2f5f461-4314-11e5-94bc-0025905cf7cc", :boot=>"off", :state=>"down", :tag=>"mon1"}, {:jid=>"10", :uuid=>"e2f5f462-4314-11e5-94bc-0025905cf7cc", :boot=>"off", :state=>"down", :tag=>"mon2"}, {:jid=>"-", :uuid=>"fdd4151c-d555-11e5-b08a-0025906cac26", :boot=>"off", :state=>"down", :tag=>"741ac3b9-7c44-4400-8916-4ee6037d94bd"}]
wanted = [{ jid: '-', uuid: '018e776d-4315-11e5-94bc-0025905cf7cc', boot: 'off', state: 'down', tag: 'auth4' }, { jid: '-', uuid: '14b47568-448e-11e5-94bc-0025905cf7cc', boot: 'off', state: 'down', tag: 'graphite2' }, { jid: '1', uuid: '19e2885e-448e-11e5-94bc-0025905cf7cc', boot: 'on', state: 'up', tag: 'git2' }, { jid: '2', uuid: '64a7af2c-4909-11e5-9073-0025905cf7cc', boot: 'on', state: 'up', tag: 'pm3' }, { jid: '-', uuid: 'c3936d1d-46f5-11e5-9073-0025905cf7cc', boot: 'off', state: 'down', tag: 'ns1' }, { jid: '333', uuid: 'ca29dc76-46f6-11e5-9073-0025905cf7cc', boot: 'on', state: 'up', tag: 'pdb2' }, { jid: '-', uuid: 'e2f5f461-4314-11e5-94bc-0025905cf7cc', boot: 'off', state: 'down', tag: 'mon1' }, { jid: '10', uuid: 'e2f5f462-4314-11e5-94bc-0025905cf7cc', boot: 'off', state: 'down', tag: 'mon2' }, { jid: '-', uuid: 'fdd4151c-d555-11e5-b08a-0025906cac26', boot: 'off', state: 'down', tag: '741ac3b9-7c44-4400-8916-4ee6037d94bd' }]
expect(provider_class.jail_list).to eq(wanted)
end
end
context "#get_jail_properties" do
it "should parse jail properties" do
context '#get_jail_properties' do
it 'parses jail properties' do
list_fixture = File.read('spec/fixtures/iocage_list')
allow(provider_class).to receive(:iocage).with(['list']) { list_fixture}
allow(provider_class).to receive(:iocage).with(['list']) { list_fixture }
get_fixture = File.read('spec/fixtures/iocage_jail_get_all')
allow(provider_class).to receive(:iocage).with(["get", "all", "f9e67f5a-4bbe-11e6-a9b4-eca86bff7d21"]) { get_fixture }
allow(provider_class).to receive(:iocage).with(['get', 'all', 'f9e67f5a-4bbe-11e6-a9b4-eca86bff7d21']) { get_fixture }
results = provider_class.get_jail_properties('f9e67f5a-4bbe-11e6-a9b4-eca86bff7d21')
@ -34,6 +31,5 @@ describe provider_class do
results.should(include('ip4_addr' => 'ethernet0|10.0.0.10'))
results.should(include('ip6_addr' => 'ethernet0|2001:470:deed::100'))
end
end
end

View File

@ -4,10 +4,9 @@ require 'puppet/type/jail'
type_class = Puppet::Type.type(:jail)
describe type_class do
[:absent, :present].each do |v|
it "should support #{v} as a value to :ensure" do
j = type_class.new(:name => 'myjail', :ensure => v)
j = type_class.new(name: 'myjail', ensure: v)
expect(j.should(:ensure)).to eq(v)
end
end
@ -16,7 +15,7 @@ describe type_class do
[
:name,
:jid,
:user_data,
:user_data
]
end
@ -28,20 +27,19 @@ describe type_class do
:ip4_addr,
:ip6_addr,
:jail_zfs,
:jail_zfs_dataset,
:jail_zfs_dataset
]
end
it 'should have expected properties' do
it 'has expected properties' do
properties.each do |property|
expect(type_class.properties.map(&:name)).to be_include(property)
end
end
it 'should have expected parameters' do
it 'has expected parameters' do
params.each do |param|
expect(type_class.parameters).to be_include(param)
end
end
end