diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..5e51cee --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,472 @@ +AllCops: + Exclude: + # Ignore HTML related things + - '**/*.erb' + # Ignore vendored gems + - 'vendor/**/*' + # Ignore code from test fixtures + - '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/RedundantReturn: + Enabled: true + +Lint/AmbiguousOperator: + Enabled: true + +Lint/AssignmentInCondition: + Enabled: true + +Style/SpaceBeforeComment: + Enabled: true + +# DISABLED - not useful +Style/HashSyntax: + Enabled: false + +# USES: as shortcut for non nil&valid checking a = x() and a.empty? +# DISABLED - not useful +Style/AndOr: + Enabled: false + +# DISABLED - not useful +Style/RedundantSelf: + Enabled: false + +# DISABLED - not useful +Metrics/MethodLength: + Enabled: false + +# DISABLED - not useful +Style/WhileUntilModifier: + Enabled: false + +# DISABLED - the offender is just haskell envy +Lint/AmbiguousRegexpLiteral: + Enabled: false + +# DISABLED +Lint/Eval: + Enabled: false + +# DISABLED +Lint/BlockAlignment: + Enabled: false + +# DISABLED +Lint/DefEndAlignment: + Enabled: false + +# DISABLED +Lint/EndAlignment: + Enabled: false + +# DISABLED +Lint/DeprecatedClassMethods: + Enabled: false + +# DISABLED +Lint/Loop: + Enabled: false + +# DISABLED +Lint/ParenthesesAsGroupedExpression: + Enabled: false + +Lint/RescueException: + Enabled: false + +Lint/StringConversionInInterpolation: + Enabled: false + +Lint/UnusedBlockArgument: + Enabled: false + +Lint/UnusedMethodArgument: + Enabled: false + +Lint/UselessAccessModifier: + Enabled: true + +Lint/UselessAssignment: + Enabled: true + +Lint/Void: + Enabled: true + +Style/AccessModifierIndentation: + Enabled: false + +Style/AccessorMethodName: + Enabled: false + +Style/Alias: + Enabled: false + +Style/AlignArray: + Enabled: false + +Style/AlignHash: + Enabled: false + +Style/AlignParameters: + Enabled: false + +Metrics/BlockNesting: + Enabled: false + +Style/AsciiComments: + Enabled: false + +Style/Attr: + Enabled: false + +Style/BracesAroundHashParameters: + Enabled: false + +Style/CaseEquality: + Enabled: false + +Style/CaseIndentation: + Enabled: false + +Style/CharacterLiteral: + Enabled: false + +Style/ClassAndModuleCamelCase: + Enabled: false + +Style/ClassAndModuleChildren: + Enabled: false + +Style/ClassCheck: + Enabled: false + +Metrics/ClassLength: + Enabled: false + +Style/ClassMethods: + Enabled: false + +Style/ClassVars: + Enabled: false + +Style/WhenThen: + Enabled: false + +# DISABLED - not useful +Style/WordArray: + Enabled: false + +Style/UnneededPercentQ: + Enabled: false + +Style/Tab: + Enabled: false + +Style/SpaceBeforeSemicolon: + Enabled: false + +Style/TrailingBlankLines: + Enabled: false + +Style/SpaceInsideBlockBraces: + Enabled: false + +Style/SpaceInsideBrackets: + Enabled: false + +Style/SpaceInsideHashLiteralBraces: + Enabled: false + +Style/SpaceInsideParens: + Enabled: false + +Style/LeadingCommentSpace: + Enabled: false + +Style/SpaceAfterColon: + Enabled: false + +Style/SpaceAfterComma: + Enabled: false + +Style/SpaceAfterMethodName: + Enabled: false + +Style/SpaceAfterNot: + Enabled: false + +Style/SpaceAfterSemicolon: + Enabled: false + +Style/SpaceAroundEqualsInParameterDefault: + Enabled: false + +Style/SpaceAroundOperators: + Enabled: false + +Style/SpaceBeforeBlockBraces: + Enabled: false + +Style/SpaceBeforeComma: + Enabled: false + +Style/CollectionMethods: + Enabled: false + +Style/CommentIndentation: + Enabled: false + +Style/ColonMethodCall: + Enabled: false + +Style/CommentAnnotation: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Style/ConstantName: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/DefWithParentheses: + Enabled: false + +Style/PreferredHashMethods: + Enabled: false + +Style/DotPosition: + Enabled: false + +# DISABLED - used for converting to bool +Style/DoubleNegation: + Enabled: false + +Style/EachWithObject: + Enabled: false + +Style/EmptyLineBetweenDefs: + Enabled: false + +Style/IndentArray: + Enabled: false + +Style/IndentHash: + Enabled: false + +Style/IndentationConsistency: + Enabled: false + +Style/IndentationWidth: + Enabled: false + +Style/EmptyLines: + Enabled: false + +Style/EmptyLinesAroundAccessModifier: + Enabled: false + +Style/EmptyLiteral: + Enabled: false + +Metrics/LineLength: + Enabled: false + +Style/MethodCallWithoutArgsParentheses: + Enabled: false + +Style/MethodDefParentheses: + Enabled: false + +Style/LineEndConcatenation: + Enabled: false + +Style/TrailingWhitespace: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/GlobalVars: + Enabled: false + +Style/GuardClause: + Enabled: false + +Style/IfUnlessModifier: + Enabled: false + +Style/MultilineIfThen: + Enabled: false + +Style/NegatedIf: + Enabled: false + +Style/NegatedWhile: + Enabled: false + +Style/Next: + Enabled: false + +Style/SingleLineBlockParams: + Enabled: false + +Style/SingleLineMethods: + Enabled: false + +Style/SpecialGlobalVars: + Enabled: false + +Style/TrivialAccessors: + Enabled: false + +Style/UnlessElse: + Enabled: false + +Style/VariableInterpolation: + Enabled: false + +Style/VariableName: + Enabled: false + +Style/WhileUntilDo: + Enabled: false + +Style/EvenOdd: + Enabled: false + +Style/FileName: + Enabled: false + +Style/For: + Enabled: false + +Style/Lambda: + Enabled: false + +Style/MethodName: + Enabled: false + +Style/MultilineTernaryOperator: + Enabled: false + +Style/NestedTernaryOperator: + Enabled: false + +Style/NilComparison: + Enabled: false + +Style/FormatString: + Enabled: false + +Style/MultilineBlockChain: + Enabled: false + +Style/Semicolon: + Enabled: false + +Style/SignalException: + Enabled: false + +Style/NonNilCheck: + Enabled: false + +Style/Not: + Enabled: false + +Style/NumericLiterals: + Enabled: false + +Style/OneLineConditional: + Enabled: false + +Naming/BinaryOperatorParameterName: + Enabled: false + +Style/ParenthesesAroundCondition: + Enabled: false + +Style/PercentLiteralDelimiters: + Enabled: false + +Style/PerlBackrefs: + Enabled: false + +Style/PredicateName: + Enabled: false + +Style/RedundantException: + Enabled: false + +Style/SelfAssignment: + Enabled: false + +Style/Proc: + Enabled: false + +Style/RaiseArgs: + Enabled: false + +Style/RedundantBegin: + Enabled: false + +Style/RescueModifier: + Enabled: false + +Style/RegexpLiteral: + Enabled: false + +Lint/UnderscorePrefixedVariableName: + Enabled: false + +Metrics/ParameterLists: + Enabled: false + +Lint/RequireParentheses: + Enabled: false + +Lint/SpaceBeforeFirstArg: + Enabled: false + +Style/ModuleFunction: + Enabled: false + +Lint/Debugger: + Enabled: false + +Style/IfWithSemicolon: + Enabled: false + +Style/Encoding: + Enabled: false + diff --git a/Gemfile b/Gemfile index f3ff7ab..70b07f6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,29 +1,25 @@ source 'https://rubygems.org' group :rake do - puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.0.0','< 6.0'] + puppetversion = ENV.key?('PUPPET_VERSION') ? (ENV['PUPPET_VERSION']).to_s : ['>= 3.0.0', '< 6.0'] gem 'puppet', puppetversion gem 'puppet-lint' gem 'puppetlabs_spec_helper', '>=0.2.0' # removed method last_comment (requires rspec 3.5.0) - gem 'rake' - gem 'rspec-system-puppet', :require => false gem 'highline' - gem 'semantic_puppet' - gem 'librarian-puppet' , '>=2.0' + gem 'librarian-puppet', '>=2.0' + gem 'metadata-json-lint', require: false + gem 'nokogiri', '~> 1.8.1' + gem 'rake' gem 'rspec-core', '>= 3.5.0' gem 'rspec-puppet' - gem 'metadata-json-lint', :require => false - if RUBY_VERSION >= "2.2.0" - gem 'safe_yaml' - end - if RUBY_VERSION >= "2.3.0" - gem 'xmlrpc' - end - gem 'nokogiri', '~> 1.8.1' + gem 'rspec-system-puppet', require: false + gem 'safe_yaml' if RUBY_VERSION >= '2.2.0' + gem 'semantic_puppet' + gem 'xmlrpc' if RUBY_VERSION >= '2.3.0' end group :development do - gem 'rubocop', '>= 0.49.0' gem 'puppet-blacksmith', '< 4.0.0' -end \ No newline at end of file + gem 'rubocop', '>= 0.49.0' +end diff --git a/Rakefile b/Rakefile index a9401fc..1b9058f 100644 --- a/Rakefile +++ b/Rakefile @@ -7,18 +7,18 @@ require 'puppet-lint/tasks/puppet-lint' require 'rspec-system/rake_task' require 'puppetlabs_spec_helper/rake_tasks' # blacksmith does not support ruby 1.8.7 anymore -require 'puppet_blacksmith/rake_tasks' if ENV['RAKE_ENV'] != 'ci' && RUBY_VERSION.split('.')[0,3].join.to_i > 187 +require 'puppet_blacksmith/rake_tasks' if ENV['RAKE_ENV'] != 'ci' && RUBY_VERSION.split('.')[0, 3].join.to_i > 187 -desc "Lint metadata.json file" +desc 'Lint metadata.json file' task :meta do - sh "metadata-json-lint metadata.json" + sh 'metadata-json-lint metadata.json' end exclude_paths = [ - "bundle/**/*", - "pkg/**/*", - "vendor/**/*", - "spec/**/*", + 'bundle/**/*', + 'pkg/**/*', + 'vendor/**/*', + 'spec/**/*' ] Rake::Task[:lint].clear @@ -29,16 +29,14 @@ PuppetLint.configuration.disable_class_parameter_defaults PuppetLint.configuration.fail_on_warnings = true PuppetLint::RakeTask.new :lint do |config| - config.ignore_paths = exclude_paths + config.ignore_paths = exclude_paths end - # use librarian-puppet to manage fixtures instead of .fixtures.yml # offers more possibilities like explicit version management, forge downloads,... task :librarian_spec_prep do sh 'librarian-puppet install --path=spec/fixtures/modules/' end -task :spec_prep => :librarian_spec_prep - -task :default => [:validate, :spec, :lint] +task spec_prep: :librarian_spec_prep +task default: %i[validate spec lint] diff --git a/lib/facter/mesos_version.rb b/lib/facter/mesos_version.rb index 5a390dd..c395425 100644 --- a/lib/facter/mesos_version.rb +++ b/lib/facter/mesos_version.rb @@ -17,4 +17,4 @@ Facter::Util::Resolution.exec('mesos-master --version 2>&1').split(/ /)[1].strip end end -end \ No newline at end of file +end diff --git a/lib/puppet/parser/functions/mesos_hash_parser.rb b/lib/puppet/parser/functions/mesos_hash_parser.rb index 4ff3e61..fe59946 100644 --- a/lib/puppet/parser/functions/mesos_hash_parser.rb +++ b/lib/puppet/parser/functions/mesos_hash_parser.rb @@ -1,24 +1,23 @@ - # # mesos_hash_parser.rb # module Puppet::Parser::Functions - newfunction(:mesos_hash_parser, :type => :rvalue, :doc => <<-EOS + newfunction(:mesos_hash_parser, type: :rvalue, doc: <<-EOS This function converts simple key-value structure to a Hash that is required by create_resources function - EOS - ) do |args| + EOS +) do |args| # Arguments: hash key_prefix [file_prefix] - if args.size < 1 || args.size > 3 + if args.empty? || args.size > 3 raise(Puppet::ParseError, "mesos_hash_parser(): Wrong number of args, given #{args.size}, accepts either 1, 2 or 3") end if args[0].class != Hash - raise(Puppet::ParseError, "mesos_hash_parser(): first argument must be a Hash, you passed a " + args[0].class.to_s) + raise(Puppet::ParseError, 'mesos_hash_parser(): first argument must be a Hash, you passed a ' + args[0].class.to_s) end res = {} @@ -28,8 +27,8 @@ module Puppet::Parser::Functions file = file_prefix ? "#{file_prefix}_#{key}" : key key = "#{key_prefix}_#{key}" if key_prefix res[key] = { - "value" => val, - "file" => file, + 'value' => val, + 'file' => file } end res diff --git a/lib/puppet/parser/functions/zookeeper_servers_url.rb b/lib/puppet/parser/functions/zookeeper_servers_url.rb index 0b3a91a..9ead3b9 100644 --- a/lib/puppet/parser/functions/zookeeper_servers_url.rb +++ b/lib/puppet/parser/functions/zookeeper_servers_url.rb @@ -1,12 +1,12 @@ module Puppet::Parser::Functions - newfunction(:zookeeper_servers_url, :type => :rvalue, :doc => <<-EOS + newfunction(:zookeeper_servers_url, type: :rvalue, doc: <<-EOS This function converts an array of ZooKeeper hostnames into a combined URL for ZooKeeper HA. Optionally you can pass custom path in ZooKeeper and default ZooKeeper port (applies only for servers without specified port) Usage: zookeeper_servers_url([10.0.0.1,10.0.0.2],'mesos', 2181) -EOS - ) do |args| + EOS +) do |args| # Only 1 argument should be passed if args.size > 3 @@ -20,25 +20,24 @@ module Puppet::Parser::Functions # The argument should be an Array case args[0].class.name - when 'Array' - zookeeper_servers = args[0].clone - when 'String' - # backward compatibility, will be removed in 1.x - return args[0] - else - raise(Puppet::ParseError, 'zookeeper_servers_url() accepts an Array, you passed a ' + args[0].class.name) + when 'Array' + zookeeper_servers = args[0].clone + when 'String' + # backward compatibility, will be removed in 1.x + return args[0] + else + raise(Puppet::ParseError, 'zookeeper_servers_url() accepts an Array, you passed a ' + args[0].class.name) end uri = 'zk://' zookeeper_servers.each_with_index do |server, i| uri << ',' if i > 0 - if server.index(':') - uri << server - else - uri << "#{server}:#{zk_port}" - end + uri << if server.index(':') + server + else + "#{server}:#{zk_port}" + end end - return "#{uri}/#{zk_path}" + return "#{uri}/#{zk_path}" end end - diff --git a/spec/classes/cli_spec.rb b/spec/classes/cli_spec.rb index 7fb6787..546ddb1 100644 --- a/spec/classes/cli_spec.rb +++ b/spec/classes/cli_spec.rb @@ -1,28 +1,31 @@ require 'spec_helper' -describe 'mesos::cli', :type => :class do - +describe 'mesos::cli', type: :class do let(:owner) { 'mesos' } let(:group) { 'mesos' } - let(:params){{ - :owner => owner, - :group => group, - :manage_pip => true, - }} - - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch'}, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :puppetversion => Puppet.version, - }} + let(:params) do + { + owner: owner, + group: group, + manage_pip: true + } + end + + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + puppetversion: Puppet.version + } + end before(:each) do puppet_debug_override @@ -30,24 +33,25 @@ it { is_expected.to contain_package('python-pip') } it { is_expected.to contain_class('mesos::cli') } - it { is_expected.to contain_package('mesos.cli').with({'provider' => 'pip'}) } - it { is_expected.to contain_package('mesos.interface').with({'provider' => 'pip'}) } + it { is_expected.to contain_package('mesos.cli').with('provider' => 'pip') } + it { is_expected.to contain_package('mesos.interface').with('provider' => 'pip') } context 'set zookeeper url' do let(:params) do { - :zookeeper => 'zk://192.168.1.100:2181/mesos', - :owner => owner, - :group => group, + zookeeper: 'zk://192.168.1.100:2181/mesos', + owner: owner, + group: group } end - it do is_expected.to contain_file('/etc/.mesos.json').with({ - 'ensure' => 'present', + it do + is_expected.to contain_file('/etc/.mesos.json').with( + 'ensure' => 'present', 'owner' => owner, 'group' => group, - 'mode' => '0644', - }) + 'mode' => '0644' + ) end it do diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 32b89b0..dc67a43 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,16 +1,17 @@ require 'spec_helper' -describe 'mesos::config', :type => :class do - +describe 'mesos::config', type: :class do let(:owner) { 'mesos' } let(:group) { 'mesos' } - let(:params){{ - :conf_dir => '/etc/mesos', - :log_dir => '/var/log/mesos', - :owner => owner, - :group => group, - }} + let(:params) do + { + conf_dir: '/etc/mesos', + log_dir: '/var/log/mesos', + owner: owner, + group: group + } + end # puppet 5 compatibility: make sure all dependent classes are loaded let :pre_condition do @@ -21,13 +22,15 @@ puppet_debug_override end - it { is_expected.to contain_file('/etc/default/mesos').with({ - 'ensure' => 'present', - 'owner' => owner, - 'group' => group, - 'mode' => '0644', - 'require' => 'Package[mesos]', - }) } + it { + is_expected.to contain_file('/etc/default/mesos').with( + 'ensure' => 'present', + 'owner' => owner, + 'group' => group, + 'mode' => '0644', + 'require' => 'Package[mesos]' + ) + } it 'has default log dir' do is_expected.to contain_file( @@ -43,10 +46,12 @@ context 'conf_file' do let(:conf_file) { '/etc/sysconfig/mesos' } - let(:params){{ - :conf_file => conf_file, - :zookeeper_url => 'zk://10.0.0.1/mesos', - }} + let(:params) do + { + conf_file: conf_file, + zookeeper_url: 'zk://10.0.0.1/mesos' + } + end it do is_expected.to contain_file(conf_file) @@ -54,49 +59,63 @@ end context 'setting ulimit' do - let(:params){{ - :ulimit => 16384, - }} + let(:params) do + { + ulimit: 16_384 + } + end - it { is_expected.to contain_file( - '/etc/default/mesos' + it { + is_expected.to contain_file( + '/etc/default/mesos' ).with_content(/ULIMIT="-n 16384"/) } end context 'setting log dir' do - let(:params){{ - :log_dir => '/srv/mesos/log', - :zookeeper_url => 'zk://10.0.0.1/mesos', - }} - it { is_expected.to contain_file( - '/etc/default/mesos' + let(:params) do + { + log_dir: '/srv/mesos/log', + zookeeper_url: 'zk://10.0.0.1/mesos' + } + end + it { + is_expected.to contain_file( + '/etc/default/mesos' ).with_content(/LOGS="\/srv\/mesos\/log"/) } end context 'setting environment variables' do - let(:params){{ - :env_var => { - 'JAVA_HOME' => '/usr/bin/java', - 'MESOS_HOME' => '/var/lib/mesos', - }, - }} - - it { is_expected.to contain_file( - '/etc/default/mesos' - ).with_content(/export JAVA_HOME="\/usr\/bin\/java"/) } + let(:params) do + { + env_var: { + 'JAVA_HOME' => '/usr/bin/java', + 'MESOS_HOME' => '/var/lib/mesos' + } + } + end - it { is_expected.to contain_file( - '/etc/default/mesos' - ).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) } + it { + is_expected.to contain_file( + '/etc/default/mesos' + ).with_content(/export JAVA_HOME="\/usr\/bin\/java"/) + } + + it { + is_expected.to contain_file( + '/etc/default/mesos' + ).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) + } end context 'set LOGS variable' do let(:file) { '/etc/default/mesos' } - let(:params) {{ - :log_dir => '/var/log/mesos', - }} + let(:params) do + { + log_dir: '/var/log/mesos' + } + end it { is_expected.to contain_file(file).with_content(/LOGS="\/var\/log\/mesos"/) } end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 0d58968..a0b5432 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,66 +1,83 @@ require 'spec_helper' -describe 'mesos', :type => :class do - - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch'}, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :puppetversion => Puppet.version, - }} +describe 'mesos', type: :class do + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + puppetversion: Puppet.version + } + end context 'with ensure' do let(:version) { '0.14' } - let(:params) {{ - :ensure => version - }} + let(:params) do + { + ensure: version + } + end before(:each) do puppet_debug_override end - it { is_expected.to contain_package('mesos').with({ - 'ensure' => version - }) } + it { + is_expected.to contain_package('mesos').with( + 'ensure' => version + ) + } - it { is_expected.not_to contain_package('python').with({ - 'ensure' => 'present' - }) } + it { + is_expected.not_to contain_package('python').with( + 'ensure' => 'present' + ) + } end context 'with given version' do let(:version) { '0.20' } - let(:params) {{ - :version => version - }} + let(:params) do + { + version: version + } + end - it { is_expected.to contain_package('mesos').with({ - 'ensure' => version - }) } + it { + is_expected.to contain_package('mesos').with( + 'ensure' => version + ) + } end context 'remove mesos' do let(:version) { 'absent' } - let(:params) {{ - :ensure => version - }} + let(:params) do + { + ensure: version + } + end - it { is_expected.to contain_package('mesos').with({ - 'ensure' => version - }) } + it { + is_expected.to contain_package('mesos').with( + 'ensure' => version + ) + } end context 'specify ulimit' do - let(:ulimit) { 16384 } + let(:ulimit) { 16_384 } let(:file) { '/etc/default/mesos' } - let(:params) {{ - :ulimit => ulimit - }} + let(:params) do + { + ulimit: ulimit + } + end it { is_expected.to contain_file(file).with_content(/ULIMIT="-n #{ulimit}"/) } end @@ -75,114 +92,139 @@ context 'change pyton packge name' do let(:python) { 'python3' } - let(:params) {{ - :manage_python => true, - :python_package => python - }} - - it { is_expected.to contain_package(python).with({ - 'ensure' => 'present' - }) } + let(:params) do + { + manage_python: true, + python_package: python + } + end + + it { + is_expected.to contain_package(python).with( + 'ensure' => 'present' + ) + } end context 'set LOGS variable' do let(:file) { '/etc/default/mesos' } - let(:params) {{ - :log_dir => '/var/log/mesos' - }} + let(:params) do + { + log_dir: '/var/log/mesos' + } + end it { is_expected.to contain_file(file).with_content(/LOGS="\/var\/log\/mesos"/) } end context 'remove packaged services' do - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch'}, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :puppetversion => Puppet.version, - }} + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + puppetversion: Puppet.version + } + end context 'keeps everything' do - it { is_expected.to contain_class('mesos::install').with( + it { + is_expected.to contain_class('mesos::install').with( 'remove_package_services' => false ) } end context 'remvoes packaged upstart config' do - let(:params) {{ - :force_provider => 'none' - }} + let(:params) do + { + force_provider: 'none' + } + end it { is_expected.to contain_class('mesos::install').with('remove_package_services' => true) } end end context 'with zookeeper' do - let(:params){{ - :zookeeper => [ '192.168.1.100:2181' ], - }} - it { is_expected.to contain_file( - '/etc/mesos/zk' + let(:params) do + { + zookeeper: ['192.168.1.100:2181'] + } + end + it { + is_expected.to contain_file( + '/etc/mesos/zk' ).with( - :ensure => 'present' + ensure: 'present' ).with_content(/^zk:\/\/192.168.1.100:2181\/mesos/) } end context 'with manage_zk_file false' do - let(:params){{ - :manage_zk_file => false, - :zookeeper => [ '192.168.1.100:2181' ], - }} - it { is_expected.not_to contain_file( - '/etc/mesos/zk' + let(:params) do + { + manage_zk_file: false, + zookeeper: ['192.168.1.100:2181'] + } + end + it { + is_expected.not_to contain_file( + '/etc/mesos/zk' ) } end context 'zookeeper URL - allow passing directly ZooKeeper\'s URI (backward compatibility 0.x)' do - let(:params){{ - :zookeeper => 'zk://192.168.1.100:2181/mesos', - }} - it { is_expected.to contain_file( - '/etc/mesos/zk' + let(:params) do + { + zookeeper: 'zk://192.168.1.100:2181/mesos' + } + end + it { + is_expected.to contain_file( + '/etc/mesos/zk' ).with( - :ensure => 'present' + ensure: 'present' ).with_content(/^zk:\/\/192.168.1.100:2181\/mesos/) } end context 'allow changing zookeeper\'s namespace' do - let(:params){{ - :zookeeper => ['192.168.1.100:2181', '192.168.1.105:2181'], - :zk_path => 'my_mesos', - }} - it { is_expected.to contain_file( - '/etc/mesos/zk' + let(:params) do + { + zookeeper: ['192.168.1.100:2181', '192.168.1.105:2181'], + zk_path: 'my_mesos' + } + end + it { + is_expected.to contain_file( + '/etc/mesos/zk' ).with( - :ensure => 'present' + ensure: 'present' ).with_content(/^zk:\/\/192.168.1.100:2181,192.168.1.105:2181\/my_mesos/) } end context 'allow changing zookeeper\'s default port' do - let(:params){{ - :zookeeper => ['192.168.1.100', '192.168.1.105'], - :zk_default_port => 2828, - }} - it { is_expected.to contain_file( - '/etc/mesos/zk' + let(:params) do + { + zookeeper: ['192.168.1.100', '192.168.1.105'], + zk_default_port: 2828 + } + end + it { + is_expected.to contain_file( + '/etc/mesos/zk' ).with( - :ensure => 'present' + ensure: 'present' ).with_content(/^zk:\/\/192.168.1.100:2828,192.168.1.105:2828\/mesos/) } end - end diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index 6b5e99e..8f12cb9 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -1,33 +1,40 @@ require 'spec_helper' -describe 'mesos::install', :type => :class do - +describe 'mesos::install', type: :class do context 'with given version' do let(:version) { '0.14' } - let(:params) {{ - :ensure => version - }} + let(:params) do + { + ensure: version + } + end before(:each) do puppet_debug_override end - it { should contain_package('mesos').with({ - 'ensure' => version - }) } + it { + should contain_package('mesos').with( + 'ensure' => version + ) + } # mesos dependencies (for web GUI) - it { should_not contain_package('python').with({ - 'ensure' => 'present' - }) } + it { + should_not contain_package('python').with( + 'ensure' => 'present' + ) + } it { should contain_class('mesos::repo') } end context 'manage python installation' do - let(:params){{ - :manage_python => true, - }} + let(:params) do + { + manage_python: true + } + end it { should contain_package('python') } end @@ -38,27 +45,35 @@ end context 'keeps everything on RHEL 7' do - let(:facts) { { - :osfamily => 'redhat', - :operatingsystemmajrelease => '7', - } } - let(:params) { { - :remove_package_services => true, - } } + let(:facts) do + { + osfamily: 'redhat', + operatingsystemmajrelease: '7' + } + end + let(:params) do + { + remove_package_services: true + } + end it { should_not contain_file('/etc/init/mesos-master.conf') } it { should_not contain_file('/etc/init/mesos-slave.conf') } end context 'removes packaged upstart config on RHEL 6' do - let(:facts) { { - :osfamily => 'redhat', - :operatingsystemmajrelease => '6', - } } + let(:facts) do + { + osfamily: 'redhat', + operatingsystemmajrelease: '6' + } + end - let(:params) { { - :remove_package_services => true, - } } + let(:params) do + { + remove_package_services: true + } + end it { should contain_file('/etc/init/mesos-master.conf').with_ensure('absent') } it { should contain_file('/etc/init/mesos-slave.conf').with_ensure('absent') } diff --git a/spec/classes/master_spec.rb b/spec/classes/master_spec.rb index 4a1186e..ee1e823 100644 --- a/spec/classes/master_spec.rb +++ b/spec/classes/master_spec.rb @@ -1,48 +1,56 @@ require 'spec_helper' -describe 'mesos::master', :type => :class do +describe 'mesos::master', type: :class do let(:owner) { 'mesos' } let(:group) { 'mesos' } let(:conf) { '/etc/mesos-master' } let(:file) { '/etc/default/mesos-master' } - let(:params){{ - :conf_dir => conf, - :owner => owner, - :group => group, - }} - - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch'}, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, - }} - - before(:each) do - puppet_debug_override - end + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group + } + end + + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version + } + end + + before(:each) do + puppet_debug_override + end it { is_expected.to contain_package('mesos') } it { is_expected.to contain_class('mesos::master') } - it { is_expected.to contain_service('mesos-master').with( - :ensure => 'running', - :enable => true - ) } - - it { should contain_file(file).with({ - 'ensure' => 'present', - 'owner' => owner, - 'group' => group, - 'mode' => '0644', - }) } + it { + is_expected.to contain_service('mesos-master').with( + ensure: 'running', + enable: true + ) + } + + it { + should contain_file(file).with( + 'ensure' => 'present', + 'owner' => owner, + 'group' => group, + 'mode' => '0644' + ) + } it 'shoud not set any IP address by default' do should_not contain_file( @@ -56,126 +64,152 @@ it { should contain_file(file).with_content(/MESOS_PORT=5050/) } context 'with zookeeper' do - let(:params){{ - :zookeeper => [ '192.168.1.100:2181' ], - }} - it { should contain_file( - file).with_content(/^export MESOS_ZK="zk:\/\/192.168.1.100:2181\/mesos"/) + let(:params) do + { + zookeeper: ['192.168.1.100:2181'] + } + end + it { + should contain_file( + file + ).with_content(/^export MESOS_ZK="zk:\/\/192.168.1.100:2181\/mesos"/) } end context 'setting master port' do - let(:params){{ - :master_port => 4040, - }} + let(:params) do + { + master_port: 4040 + } + end it { should contain_file(file).with_content(/^export MESOS_PORT=4040/) } end - it { should contain_file(file).with_content(/CLUSTER="mesos"/) } context 'setting cluster name' do - let(:params){{ - :cluster => 'cluster', - }} + let(:params) do + { + cluster: 'cluster' + } + end it { should contain_file(file).with_content(/^export MESOS_CLUSTER="cluster"/) } end context 'setting environment variables' do - let(:params){{ - :env_var => { - 'JAVA_HOME' => '/usr/bin/java', - 'MESOS_HOME' => '/var/lib/mesos', - }, - }} + let(:params) do + { + env_var: { + 'JAVA_HOME' => '/usr/bin/java', + 'MESOS_HOME' => '/var/lib/mesos' + } + } + end - it { should contain_file( - file - ).with_content(/export JAVA_HOME="\/usr\/bin\/java"/) } + it { + should contain_file( + file + ).with_content(/export JAVA_HOME="\/usr\/bin\/java"/) + } - it { should contain_file( - file - ).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) } + it { + should contain_file( + file + ).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) + } end context 'disabling service' do - let(:params){{ - :enable => false, - }} + let(:params) do + { + enable: false + } + end - it { should contain_service('mesos-master').with( - :enable => false - ) } + it { + should contain_service('mesos-master').with( + enable: false + ) + } end context 'changing master config file location' do let(:master_file) { '/etc/mesos/master' } - let(:params){{ - :conf_file => master_file, - }} - - it { should contain_file(master_file).with({ - 'ensure' => 'present', - 'mode' => '0644', - }) } + let(:params) do + { + conf_file: master_file + } + end + + it { + should contain_file(master_file).with( + 'ensure' => 'present', + 'mode' => '0644' + ) + } end context 'set quorum via options' do - let(:params){{ - :conf_dir => conf, - :options => { 'quorum' => 4 }, - }} + let(:params) do + { + conf_dir: conf, + options: { 'quorum' => 4 } + } + end it 'has quorum file in master config dir' do should contain_file( "#{conf}/quorum" - ).with_content(/^4$/).with({ - 'ensure' => 'present', - }) + ).with_content(/^4$/).with( + 'ensure' => 'present' + ) end end context 'allow changing conf_dir' do - let(:my_conf_dir) { '/var/mesos-master'} - let(:params){{ - :conf_dir => my_conf_dir, - :options => { 'quorum' => 4 }, - }} + let(:my_conf_dir) { '/var/mesos-master' } + let(:params) do + { + conf_dir: my_conf_dir, + options: { 'quorum' => 4 } + } + end it 'has quorum file in master config dir' do should contain_file( "#{my_conf_dir}/quorum" - ).with_content(/^4$/).with({ - 'ensure' => 'present', - }) + ).with_content(/^4$/).with( + 'ensure' => 'present' + ) end end context 'work_dir' do let(:work_dir) { '/var/lib/mesos' } - let(:params){{ - :conf_dir => conf, - :work_dir => work_dir, - :owner => owner, - :group => group, - }} - + let(:params) do + { + conf_dir: conf, + work_dir: work_dir, + owner: owner, + group: group + } + end it do - should contain_file(work_dir).with({ - 'ensure' => 'directory', + should contain_file(work_dir).with( + 'ensure' => 'directory', 'owner' => owner, - 'group' => group, - }) + 'group' => group + ) end it do - should contain_mesos__property('master_work_dir').with({ + should contain_mesos__property('master_work_dir').with( 'owner' => owner, 'group' => group, 'dir' => conf, - 'value' => work_dir, - }) + 'value' => work_dir + ) end it do @@ -186,27 +220,31 @@ end context 'support boolean flags' do - let(:my_conf_dir) { '/var/mesos-master'} - let(:params){{ - :conf_dir => my_conf_dir, - :options => { 'authenticate' => true }, - }} + let(:my_conf_dir) { '/var/mesos-master' } + let(:params) do + { + conf_dir: my_conf_dir, + options: { 'authenticate' => true } + } + end it 'has authenticate file in config dir' do should contain_file( "#{my_conf_dir}/?authenticate" - ).with({ - 'ensure' => 'present', - }) + ).with( + 'ensure' => 'present' + ) end end context 'nofify service after removing a key' do - let(:my_conf_dir) { '/tmp/mesos-conf'} - let(:params){{ - :conf_dir => my_conf_dir, - :options => { 'quorum' => 4 }, - }} + let(:my_conf_dir) { '/tmp/mesos-conf' } + let(:params) do + { + conf_dir: my_conf_dir, + options: { 'quorum' => 4 } + } + end before(:each) do system("mkdir -p #{my_conf_dir} && touch #{my_conf_dir}/foo") @@ -217,111 +255,119 @@ end it { is_expected.to contain_service('mesos-master') } - it { is_expected.to contain_file("#{my_conf_dir}").that_notifies('Service[mesos-master]') } + it { is_expected.to contain_file(my_conf_dir.to_s).that_notifies('Service[mesos-master]') } end context 'acls' do context 'default w/o acls' do - let(:params) { { - :conf_dir => conf, - :owner => owner, - :group => group, - } } + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group + } + end it 'has no acls property' do should_not contain_mesos__property( - 'master_acls' - ) + 'master_acls' + ) end it 'has not acls file' do should contain_file( - '/etc/mesos/acls' - ) - .with({ - 'ensure' => 'absent', - }) + '/etc/mesos/acls' + ) + .with( + 'ensure' => 'absent' + ) end end context 'w/ acls' do - let(:params) { { - :conf_dir => conf, - :owner => owner, - :group => group, - :acls => {"some-key" => ["some-value", "some-other-value"]}, - } } + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group, + acls: { 'some-key' => ['some-value', 'some-other-value'] } + } + end it 'has acls property' do should contain_mesos__property( - 'master_acls' - ).with('value' => '/etc/mesos/acls') + 'master_acls' + ).with('value' => '/etc/mesos/acls') end it 'has acls file' do should contain_file( - '/etc/mesos/acls' - ).with({ - 'ensure' => 'file', - 'content' => /{"some-key":\s*\["some-value",\s*"some-other-value"\]}/, - 'owner' => owner, - 'group' => group, - 'mode' => '0444', - }) + '/etc/mesos/acls' + ).with( + 'ensure' => 'file', + 'content' => /{"some-key":\s*\["some-value",\s*"some-other-value"\]}/, + 'owner' => owner, + 'group' => group, + 'mode' => '0444' + ) end end end context 'credentials' do context 'default w/o credentials' do - let(:params) { { - :conf_dir => conf, - :owner => owner, - :group => group, - } } + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group + } + end it 'has no credentials property' do should_not contain_mesos__property( - 'master_credentials' - ) + 'master_credentials' + ) end it 'has not credentials file' do should contain_file( - '/etc/mesos/master-credentials' - ) - .with({ - 'ensure' => 'absent', - }) + '/etc/mesos/master-credentials' + ) + .with( + 'ensure' => 'absent' + ) end end context 'w/ credentials' do - let(:params) { { - :conf_dir => conf, - :owner => owner, - :group => group, - :credentials => [{'principal' => 'some-mesos-principal', 'secret' => 'a-very-secret'}], - } } + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group, + credentials: [{ 'principal' => 'some-mesos-principal', 'secret' => 'a-very-secret' }] + } + end it 'has credentials property' do should contain_mesos__property( - 'master_credentials' - ).with({ - 'value' => 'file:///etc/mesos/master-credentials', - }) + 'master_credentials' + ).with( + 'value' => 'file:///etc/mesos/master-credentials' + ) end it 'has credentials file' do should contain_file( - '/etc/mesos/master-credentials' - ).with({ - 'ensure' => 'file', - 'content' => /{"credentials":\s*\[{"principal":\s*"some-mesos-principal",\s*"secret":\s*"a-very-secret"}\]}/, - 'owner' => owner, - 'group' => group, - 'mode' => '0400', - }) + '/etc/mesos/master-credentials' + ).with( + 'ensure' => 'file', + 'content' => /{"credentials":\s*\[{"principal":\s*"some-mesos-principal",\s*"secret":\s*"a-very-secret"}\]}/, + 'owner' => owner, + 'group' => group, + 'mode' => '0400' + ) end end @@ -329,21 +375,21 @@ describe 'when syslog_logger is true' do let(:params) do { - :conf_dir => conf, - :owner => owner, - :group => group, - :syslog_logger => true + conf_dir: conf, + owner: owner, + group: group, + syslog_logger: true } end it do should contain_mesos__property('master_logger') .with( - :ensure => 'absent', - :file => 'logger', - :value => false, - :dir => conf, - :owner => owner, - :group => group + ensure: 'absent', + file: 'logger', + value: false, + dir: conf, + owner: owner, + group: group ) should contain_file("#{conf}/?no-logger").with_ensure('absent') @@ -353,21 +399,21 @@ describe 'when syslog_logger is false' do let(:params) do { - :conf_dir => conf, - :owner => owner, - :group => group, - :syslog_logger => false + conf_dir: conf, + owner: owner, + group: group, + syslog_logger: false } end it do should contain_mesos__property('master_logger') .with( - :ensure => 'present', - :file => 'logger', - :value => false, - :dir => conf, - :owner => owner, - :group => group + ensure: 'present', + file: 'logger', + value: false, + dir: conf, + owner: owner, + group: group ) should contain_file("#{conf}/?no-logger").with_ensure('present') @@ -377,78 +423,87 @@ end context 'test merging hashes from hiera' do - let(:params){{ - :use_hiera => true, - }} + let(:params) do + { + use_hiera: true + } + end # quorum defined in spec/fixtures/hiera/test.yaml it 'defines quorum' do should contain_file("#{conf}/quorum").with_ensure('present') should contain_mesos__property('master_quorum') - .with(:value => 2) + .with(value: 2) end # advertise_ip defined in spec/fixtures/hiera/default.yaml it 'with advertised IP config' do should contain_file("#{conf}/advertise_ip").with_ensure('present') should contain_mesos__property('master_advertise_ip') - .with(:value => '10.0.0.1') + .with(value: '10.0.0.1') end end context 'single role' do - it { should contain_service('mesos-master').with( - :ensure => 'running', - :enable => true - ) } + it { + should contain_service('mesos-master').with( + ensure: 'running', + enable: true + ) + } - it { should contain_service('mesos-slave').with( - :enable => false - ) } + it { + should contain_service('mesos-slave').with( + enable: false + ) + } it { - should contain_mesos__service('master').with(:enable => true) - should contain_mesos__service('slave').with(:enable => false) + should contain_mesos__service('master').with(enable: true) + should contain_mesos__service('slave').with(enable: false) } context 'disable single role' do - let(:params) {{ - :single_role => false, - }} - - it { should_not contain_service('mesos-slave').with( - :enable => false - ) } + let(:params) do + { + single_role: false + } + end + it { + should_not contain_service('mesos-slave').with( + enable: false + ) + } end end context 'custom systemd configuration' do let(:params) do { - :service_provider => 'systemd', - :manage_service_file => true, - :systemd_after => 'network-online.target openvpn-client@.service', - :systemd_wants => 'network-online.target openvpn-client@.service', + service_provider: 'systemd', + manage_service_file: true, + systemd_after: 'network-online.target openvpn-client@.service', + systemd_wants: 'network-online.target openvpn-client@.service' } end it do - is_expected.to contain_service('mesos-master').with( - :ensure => 'running', - :enable => true + is_expected.to contain_service('mesos-master').with( + ensure: 'running', + enable: true ) end it do - is_expected.to contain_mesos__service('master').with(:enable => true) + is_expected.to contain_mesos__service('master').with(enable: true) end it do is_expected.to contain_file( '/etc/systemd/system/mesos-master.service' - ).with({ - 'ensure' => 'present', - }) + ).with( + 'ensure' => 'present' + ) end it do @@ -462,8 +517,5 @@ '/etc/systemd/system/mesos-master.service' ).with_content(/After=network-online.target openvpn-client@.service/) end - end - - end diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index 294c269..e4803bf 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -1,45 +1,52 @@ require 'spec_helper' -describe 'mesos::repo', :type => :class do - - shared_examples 'debian' do |family,operatingsystem, lsbdistcodename, puppet| - let(:params) {{ - :source => 'mesosphere', - }} - - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => family, - :os => { - :family => family, - :name => operatingsystem, - :distro => { :codename => lsbdistcodename }, - :release => { :major => '8', :minor => '9', :full => '8.9' }, - }, - :puppetversion => puppet, - }} +describe 'mesos::repo', type: :class do + shared_examples 'debian' do |family, operatingsystem, lsbdistcodename, puppet| + let(:params) do + { + source: 'mesosphere' + } + end + + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: family, + os: { + family: family, + name: operatingsystem, + distro: { codename: lsbdistcodename }, + release: { major: '8', minor: '9', full: '8.9' } + }, + puppetversion: puppet + } + end before(:each) do puppet_debug_override end - it { is_expected.to contain_apt__source('mesos').with( - 'location' => "https://repos.mesosphere.io/#{family.downcase}", - 'repos' => 'main', - 'release' => "#{lsbdistcodename}", - 'key' => {'id' => '81026D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.ubuntu.com'}, - 'include' => {'src' => false} - )} + it { + is_expected.to contain_apt__source('mesos').with( + 'location' => "https://repos.mesosphere.io/#{family.downcase}", + 'repos' => 'main', + 'release' => lsbdistcodename.to_s, + 'key' => { 'id' => '81026D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.ubuntu.com' }, + 'include' => { 'src' => false } + ) + } it { is_expected.to contain_anchor('mesos::repo::begin').that_comes_before('Apt::Source[mesos]') } it { is_expected.to contain_apt__source('mesos').that_comes_before('Class[apt::update]') } it { is_expected.to contain_class('apt::update').that_comes_before('Anchor[mesos::repo::end]') } - context "undef source" do - let(:params) {{ - :source => nil, - }} + context 'undef source' do + let(:params) do + { + source: nil + } + end it { is_expected.not_to contain_apt__source('mesos') } # it { is_expected.to contain_file('/etc/apt/sources.list.d/mesos.list').with({'ensure' => 'absent'}) } end @@ -53,38 +60,47 @@ end shared_examples 'redhat' do |family, operatingsystem, majrel, minrel| - let(:params) {{ - :source => 'mesosphere', - }} - - let(:osrel) { majrel} - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => family, - :os => { - :family => family, - :name => operatingsystem, - :release => { :major => majrel, :minor => minrel, :full => "#{majrel}.#{minrel}" }, - }, - :puppetversion => Puppet.version, - }} - - it { is_expected.to contain_package('mesosphere-el-repo').with({ - 'ensure' => 'present', - 'provider' => 'rpm', - 'source' => "https://repos.mesosphere.io/el/#{majrel}/noarch/RPMS/mesosphere-el-repo-#{majrel}-#{minrel}.noarch.rpm", - })} - - it do is_expected.to contain_exec('yum-clean-expire-cache').with({ - :command => 'yum clean expire-cache', - }) + let(:params) do + { + source: 'mesosphere' + } + end + + let(:osrel) { majrel } + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: family, + os: { + family: family, + name: operatingsystem, + release: { major: majrel, minor: minrel, full: "#{majrel}.#{minrel}" } + }, + puppetversion: Puppet.version + } + end + + it { + is_expected.to contain_package('mesosphere-el-repo').with( + 'ensure' => 'present', + 'provider' => 'rpm', + 'source' => "https://repos.mesosphere.io/el/#{majrel}/noarch/RPMS/mesosphere-el-repo-#{majrel}-#{minrel}.noarch.rpm" + ) + } + + it do + is_expected.to contain_exec('yum-clean-expire-cache').with( + command: 'yum clean expire-cache' + ) end - context "undef source" do - let(:params) {{ - :source => nil, - }} + context 'undef source' do + let(:params) do + { + source: nil + } + end it { is_expected.not_to contain_package('mesosphere-el-repo') } end end @@ -99,40 +115,44 @@ let(:params) do { 'source' => { - 'location' => "http://myrepo.example.com/debian", + 'location' => 'http://myrepo.example.com/debian', 'release' => 'stretch', 'repos' => 'main', 'key' => { 'id' => '99926D0004C44CF7EF55ADF8DF7D54CBE56151BF', - 'server' => 'keyserver.ubuntu.com', - }, - 'include' => { - 'src' => false + 'server' => 'keyserver.ubuntu.com' }, + 'include' => { + 'src' => false + } } } end - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch' }, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :puppetversion => Puppet.version, - }} - - it { is_expected.to contain_apt__source('mesos').with( - 'location' => "http://myrepo.example.com/debian", - 'repos' => 'main', - 'release' => 'stretch', - 'key' => {'id' => '99926D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.ubuntu.com'}, - 'include' => {'src' => false} - )} + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + puppetversion: Puppet.version + } + end + + it { + is_expected.to contain_apt__source('mesos').with( + 'location' => 'http://myrepo.example.com/debian', + 'repos' => 'main', + 'release' => 'stretch', + 'key' => { 'id' => '99926D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.ubuntu.com' }, + 'include' => { 'src' => false } + ) + } end context 'allow passing only values different from the default' do @@ -141,63 +161,71 @@ 'source' => { 'key' => { 'id' => '00026D0004C44CF7EF55ADF8DF7D54CBE56151BF', - 'server' => 'keyserver.example.com', - }, + 'server' => 'keyserver.example.com' + } } } end - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch' }, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :puppetversion => Puppet.version, - }} - - it { is_expected.to contain_apt__source('mesos').with( - 'location' => "https://repos.mesosphere.io/debian", - 'repos' => 'main', - 'release' => 'stretch', - 'key' => {'id' => '00026D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.example.com'}, - 'include' => {'src' => false} - )} + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + puppetversion: Puppet.version + } + end + + it { + is_expected.to contain_apt__source('mesos').with( + 'location' => 'https://repos.mesosphere.io/debian', + 'repos' => 'main', + 'release' => 'stretch', + 'key' => { 'id' => '00026D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.example.com' }, + 'include' => { 'src' => false } + ) + } end context 'puppet 4.x' do - let(:params) {{ - :source => 'mesosphere', - }} - - let(:facts) {{ - # still old fact is needed due to this - # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch'}, - :release => { :major => '9', :minor => '1', :full => '9.1' }, - }, - :puppetversion => Puppet.version, - }} + let(:params) do + { + source: 'mesosphere' + } + end + + let(:facts) do + { + # still old fact is needed due to this + # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } + }, + puppetversion: Puppet.version + } + end before(:each) do puppet_debug_override end - it { is_expected.to contain_apt__source('mesos').with( - 'location' => "https://repos.mesosphere.io/debian", - 'repos' => 'main', - 'release' => 'stretch', - 'key' => {'id' => '81026D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.ubuntu.com'}, - 'include' => {'src' => false} - )} - + it { + is_expected.to contain_apt__source('mesos').with( + 'location' => 'https://repos.mesosphere.io/debian', + 'repos' => 'main', + 'release' => 'stretch', + 'key' => { 'id' => '81026D0004C44CF7EF55ADF8DF7D54CBE56151BF', 'server' => 'keyserver.ubuntu.com' }, + 'include' => { 'src' => false } + ) + } end - end diff --git a/spec/classes/slave_spec.rb b/spec/classes/slave_spec.rb index 454a5a2..f4d5baf 100644 --- a/spec/classes/slave_spec.rb +++ b/spec/classes/slave_spec.rb @@ -1,31 +1,33 @@ require 'spec_helper' -describe 'mesos::slave', :type => :class do +describe 'mesos::slave', type: :class do let(:owner) { 'mesos' } let(:group) { 'mesos' } let(:conf) { '/etc/mesos-slave' } let(:slave_file) { '/etc/default/mesos-slave' } - let(:params){{ - :conf_dir => conf, - :owner => owner, - :group => group, - }} + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group + } + end let(:facts) do { - :mesos_version => '1.2.0', + mesos_version: '1.2.0', # still old fact is needed due to this # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'stretch'}, - :release => { :major => '9', :minor => '1', :full => '9.1' }, + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'stretch' }, + release: { major: '9', minor: '1', full: '9.1' } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end @@ -34,29 +36,34 @@ end it { should contain_package('mesos') } - it { should contain_service('mesos-slave').with( - :ensure => 'running', - :enable => true - ) } - - it { should contain_file(slave_file).with({ - 'ensure' => 'present', - 'owner' => owner, - 'group' => group, - 'mode' => '0644', - }) } + it { + should contain_service('mesos-slave').with( + ensure: 'running', + enable: true + ) + } + + it { + should contain_file(slave_file).with( + 'ensure' => 'present', + 'owner' => owner, + 'group' => group, + 'mode' => '0644' + ) + } it 'does not set IP address by default' do - should_not contain_file( - slave_file - ).with_content(/^export MESOS_IP=/) + should_not contain_file( + slave_file + ).with_content(/^export MESOS_IP=/) end context 'with ip address set' do - - let(:params) {{ - :listen_address => '192.168.1.1', - }} + let(:params) do + { + listen_address: '192.168.1.1' + } + end it 'has ip address from param' do should contain_file( @@ -74,9 +81,9 @@ it 'checkpoint should be false' do should_not contain_file( "#{conf}/?checkpoint" - ).with({ - 'ensure' => 'present', - }) + ).with( + 'ensure' => 'present' + ) end it 'should have workdir in /var/lib/mesos' do @@ -86,118 +93,151 @@ end context 'one master node' do - let(:params){{ - :master => '192.168.1.100', - }} - it { should contain_file( - slave_file + let(:params) do + { + master: '192.168.1.100' + } + end + it { + should contain_file( + slave_file ).with_content(/^export MESOS_MASTER="192.168.1.100:5050"/) } - it { should contain_file( - '/etc/mesos/zk' - ).with(:ensure => 'absent') + it { + should contain_file( + '/etc/mesos/zk' + ).with(ensure: 'absent') } end context 'zookeeper should be preferred before single master' do - let(:params){{ - :master => '172.16.0.1', - :zookeeper => [ '192.168.1.100:2181' ], - }} - it { should_not contain_file( - slave_file + let(:params) do + { + master: '172.16.0.1', + zookeeper: ['192.168.1.100:2181'] + } + end + it { + should_not contain_file( + slave_file ).with_content(/^export MESOS_MASTER="172.16.0.1"/) } # this would work only if we set mesos::zookeeper through hiera - #it { should contain_file( + # it { should contain_file( # '/etc/mesos/zk' # ).with_content(/^zk:\/\/192.168.1.100:2181\/mesos/) - #} + # } end context 'disabling service' do - let(:params){{ - :enable => false, - }} + let(:params) do + { + enable: false + } + end - it { should contain_service('mesos-slave').with( - :enable => false - ) } + it { + should contain_service('mesos-slave').with( + enable: false + ) + } end context 'changing workdir' do - let(:params){{ - :work_dir => '/home/mesos', - }} + let(:params) do + { + work_dir: '/home/mesos' + } + end - it { should contain_file( - "#{conf}/work_dir" - ).with_content(/^\/home\/mesos$/) } + it { + should contain_file( + "#{conf}/work_dir" + ).with_content(/^\/home\/mesos$/) + } end context 'enabling checkpoint (enabled by default anyway)' do - let(:params){{ - :options => { - 'checkpoint' => true, + let(:params) do + { + options: { + 'checkpoint' => true + } } - }} + end - it { should contain_file( - "#{conf}/?checkpoint" - ).with({ - 'ensure' => 'present', - }) } + it { + should contain_file( + "#{conf}/?checkpoint" + ).with( + 'ensure' => 'present' + ) + } end context 'disabling checkpoint' do - let(:params){{ - :options => { - 'checkpoint' => false, + let(:params) do + { + options: { + 'checkpoint' => false + } } - }} + end - it { should contain_file( - "#{conf}/?no-checkpoint" - ).with({ - 'ensure' => 'present', - }) } + it { + should contain_file( + "#{conf}/?no-checkpoint" + ).with( + 'ensure' => 'present' + ) + } end context 'setting environment variables' do - let(:params){{ - :env_var => { - 'JAVA_HOME' => '/usr/bin/java', - 'MESOS_HOME' => '/var/lib/mesos', - }, - }} + let(:params) do + { + env_var: { + 'JAVA_HOME' => '/usr/bin/java', + 'MESOS_HOME' => '/var/lib/mesos' + } + } + end - it { should contain_file( - slave_file - ).with_content(/export JAVA_HOME="\/usr\/bin\/java"/) } + it { + should contain_file( + slave_file + ).with_content(/export JAVA_HOME="\/usr\/bin\/java"/) + } - it { should contain_file( - slave_file - ).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) } + it { + should contain_file( + slave_file + ).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) + } end it 'should not set isolation by default (value depends on mesos version)' do should_not contain_file( "#{conf}/isolation" - ).with({ - 'ensure' => 'present', - }) + ).with( + 'ensure' => 'present' + ) end context 'should set isolation to cgroups' do - let(:params){{ - :isolation => 'cgroups/cpu,cgroups/mem', - }} + let(:params) do + { + isolation: 'cgroups/cpu,cgroups/mem' + } + end - it { should contain_file( - "#{conf}/isolation" - ).with({ - 'ensure' => 'present', - }).with_content(/^cgroups\/cpu,cgroups\/mem$/) } + it { + should contain_file( + "#{conf}/isolation" + ).with( + 'ensure' => 'present' + ).with_content(/^cgroups\/cpu,cgroups\/mem$/) + } end it 'should not contain cgroups settings' do @@ -207,80 +247,104 @@ end context 'setting isolation mechanism' do - let(:params){{ - :isolation => 'cgroups/cpu,cgroups/mem', - :cgroups => { - 'hierarchy' => '/sys/fs/cgroup', - 'root' => 'mesos', - }, - :owner => owner, - :group => group, - }} + let(:params) do + { + isolation: 'cgroups/cpu,cgroups/mem', + cgroups: { + 'hierarchy' => '/sys/fs/cgroup', + 'root' => 'mesos' + }, + owner: owner, + group: group + } + end - it { should contain_file( - "#{conf}/cgroups_root" - ).with_content(/^mesos$/)} + it { + should contain_file( + "#{conf}/cgroups_root" + ).with_content(/^mesos$/) + } - it { should contain_file( - "#{conf}/cgroups_hierarchy" - ).with_content(/^\/sys\/fs\/cgroup$/)} + it { + should contain_file( + "#{conf}/cgroups_hierarchy" + ).with_content(/^\/sys\/fs\/cgroup$/) + } - it { should contain_file( - "#{conf}/isolation" - ).with({ - 'ensure' => 'present', - }).with_content(/^cgroups\/cpu,cgroups\/mem$/) } + it { + should contain_file( + "#{conf}/isolation" + ).with( + 'ensure' => 'present' + ).with_content(/^cgroups\/cpu,cgroups\/mem$/) + } - it { should contain_mesos__property('slave_hierarchy').with({ - 'owner' => owner, - 'group' => group, - 'dir' => conf, - 'value' => '/sys/fs/cgroup', - }) } + it { + should contain_mesos__property('slave_hierarchy').with( + 'owner' => owner, + 'group' => group, + 'dir' => conf, + 'value' => '/sys/fs/cgroup' + ) + } end context 'changing slave config file location' do let(:slave_file) { '/etc/mesos/slave' } - let(:params){{ - :conf_file => slave_file, - }} + let(:params) do + { + conf_file: slave_file + } + end - it { should contain_file(slave_file).with({ - 'ensure' => 'present', - 'mode' => '0644', - }) } + it { + should contain_file(slave_file).with( + 'ensure' => 'present', + 'mode' => '0644' + ) + } end context 'resources specification' do let(:resources_dir) { '/etc/mesos-slave/resources' } - let(:params){{ - :resources => { - 'cpu' => '4', - 'mem' => '2048', + let(:params) do + { + resources: { + 'cpu' => '4', + 'mem' => '2048' + } } - }} + end - it { should contain_file(resources_dir).with({ - 'ensure' => 'directory', - }) } + it { + should contain_file(resources_dir).with( + 'ensure' => 'directory' + ) + } - it { should contain_file( - "#{resources_dir}/cpu" - ).with_content(/^4$/)} + it { + should contain_file( + "#{resources_dir}/cpu" + ).with_content(/^4$/) + } - it { should contain_file( - "#{resources_dir}/mem" - ).with_content(/^2048$/)} + it { + should contain_file( + "#{resources_dir}/mem" + ).with_content(/^2048$/) + } end context 'custom listen_address value' do - let(:params){{ - :conf_dir => conf, - :owner => owner, - :group => group, - :listen_address => '192.168.1.2', - }} + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group, + listen_address: '192.168.1.2' + } + end # fact is not evaluated in test with newer puppet (or rspec) it 'has ip address from system fact' do @@ -290,11 +354,13 @@ end end - context 'set isolation via options' do - let(:params){{ - :conf_dir => conf, - :options => { 'isolation' => 'cgroups/cpu,cgroups/mem' }, - }} + context 'set isolation via options' do + let(:params) do + { + conf_dir: conf, + options: { 'isolation' => 'cgroups/cpu,cgroups/mem' } + } + end it 'contains isolation file in slave directory' do should contain_file( @@ -303,13 +369,14 @@ end end - context 'allow changing config directory' do let(:my_conf_dir) { '/var/mesos-slave' } - let(:params){{ - :conf_dir => my_conf_dir, - :options => { 'isolation' => 'cgroups/cpu,cgroups/mem' }, - }} + let(:params) do + { + conf_dir: my_conf_dir, + options: { 'isolation' => 'cgroups/cpu,cgroups/mem' } + } + end it 'contains isolation file in slave directory' do should contain_file( @@ -320,28 +387,30 @@ context 'work_dir' do let(:work_dir) { '/tmp/mesos' } - let(:params){{ - :conf_dir => conf, - :work_dir => work_dir, - :owner => owner, - :group => group, - }} + let(:params) do + { + conf_dir: conf, + work_dir: work_dir, + owner: owner, + group: group + } + end it do - should contain_file(work_dir).with({ - 'ensure' => 'directory', + should contain_file(work_dir).with( + 'ensure' => 'directory', 'owner' => owner, - 'group' => group, - }) + 'group' => group + ) end it do - should contain_mesos__property('slave_work_dir').with({ + should contain_mesos__property('slave_work_dir').with( 'owner' => owner, 'group' => group, 'dir' => conf, - 'value' => work_dir, - }) + 'value' => work_dir + ) end it do @@ -352,60 +421,70 @@ end context 'common slave config' do - let(:params){{ - :zookeeper => 'zk://192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181/mesos', - :listen_address => '192.168.1.1', - :attributes => { - 'env' => 'production', - }, - :resources => { - 'ports' => '[10000-65535]' - }, - }} + let(:params) do + { + zookeeper: 'zk://192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181/mesos', + listen_address: '192.168.1.1', + attributes: { + 'env' => 'production' + }, + resources: { + 'ports' => '[10000-65535]' + } + } + end it { should compile.with_all_deps } it { should contain_package('mesos') } - it { should contain_service('mesos-slave').with( - :ensure => 'running', - :enable => true - ) } - - it { should contain_mesos__property('resources_ports').with({ - 'dir' => '/etc/mesos-slave/resources', - 'file' => 'ports', - 'value' => '[10000-65535]', - }) } - + it { + should contain_service('mesos-slave').with( + ensure: 'running', + enable: true + ) + } - it { should contain_mesos__property('attributes_env').with({ - 'dir' => '/etc/mesos-slave/attributes', - 'file' => 'env', - 'value' => 'production', - }) } + it { + should contain_mesos__property('resources_ports').with( + 'dir' => '/etc/mesos-slave/resources', + 'file' => 'ports', + 'value' => '[10000-65535]' + ) + } + it { + should contain_mesos__property('attributes_env').with( + 'dir' => '/etc/mesos-slave/attributes', + 'file' => 'env', + 'value' => 'production' + ) + } end context 'support boolean flags' do - let(:my_conf_dir) { '/var/mesos-slave'} - let(:params){{ - :conf_dir => my_conf_dir, - :options => { 'strict' => false }, - }} + let(:my_conf_dir) { '/var/mesos-slave' } + let(:params) do + { + conf_dir: my_conf_dir, + options: { 'strict' => false } + } + end it 'has no-strict file in config dir' do should contain_file( "#{my_conf_dir}/?no-strict" - ).with({ - 'ensure' => 'present', - }) + ).with( + 'ensure' => 'present' + ) end end - context 'nofify service after removing a key' do - let(:my_conf_dir) { '/tmp/mesos-conf'} - let(:params){{ - :conf_dir => my_conf_dir, - }} + context 'nofify service after removing a key' do + let(:my_conf_dir) { '/tmp/mesos-conf' } + let(:params) do + { + conf_dir: my_conf_dir + } + end before(:each) do system("mkdir -p #{my_conf_dir} && touch #{my_conf_dir}/foo") @@ -416,14 +495,16 @@ end it { is_expected.to contain_service('mesos-slave') } - it { is_expected.to contain_file("#{my_conf_dir}").that_notifies('Service[mesos-slave]') } + it { is_expected.to contain_file(my_conf_dir.to_s).that_notifies('Service[mesos-slave]') } end context 'nofify service after removing a key' do - let(:my_conf_dir) { '/tmp/mesos-conf'} - let(:params){{ - :conf_dir => my_conf_dir, - }} + let(:my_conf_dir) { '/tmp/mesos-conf' } + let(:params) do + { + conf_dir: my_conf_dir + } + end before(:each) do system("mkdir -p #{my_conf_dir}/resources && echo 2 > #{my_conf_dir}/resources/cpus") @@ -434,60 +515,64 @@ end it { is_expected.to contain_service('mesos-slave') } - it { is_expected.to contain_file("#{my_conf_dir}").that_notifies('Service[mesos-slave]') } + it { is_expected.to contain_file(my_conf_dir.to_s).that_notifies('Service[mesos-slave]') } end context 'credentials' do context 'default w/o principal/secret' do - let(:params) { { - :conf_dir => conf, - :owner => owner, - :group => group, - } } + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group + } + end it 'has no credentials property' do should_not contain_mesos__property( - 'slave_credential' - ) + 'slave_credential' + ) end it 'has not credentials file' do should contain_file( - '/etc/mesos/slave-credentials' - ) - .with({ - 'ensure' => 'absent', - }) + '/etc/mesos/slave-credentials' + ) + .with( + 'ensure' => 'absent' + ) end end context 'w/ principal/secret' do - let(:params) { { - :conf_dir => conf, - :owner => owner, - :group => group, - :principal => 'some-mesos-principal', - :secret => 'a-very-secret', - } } + let(:params) do + { + conf_dir: conf, + owner: owner, + group: group, + principal: 'some-mesos-principal', + secret: 'a-very-secret' + } + end it 'has credentials property' do should contain_mesos__property( - 'slave_credential' - ).with({ - 'value' => '/etc/mesos/slave-credentials', - }) + 'slave_credential' + ).with( + 'value' => '/etc/mesos/slave-credentials' + ) end it 'has credentials file' do should contain_file( - '/etc/mesos/slave-credentials' - ).with({ - 'ensure' => 'file', - 'content' => '{"principal": "some-mesos-principal", "secret": "a-very-secret"}', - 'owner' => owner, - 'group' => group, - 'mode' => '0400', - }) + '/etc/mesos/slave-credentials' + ).with( + 'ensure' => 'file', + 'content' => '{"principal": "some-mesos-principal", "secret": "a-very-secret"}', + 'owner' => owner, + 'group' => group, + 'mode' => '0400' + ) end end @@ -495,21 +580,21 @@ describe 'when syslog_logger is true' do let(:params) do { - :conf_dir => conf, - :owner => owner, - :group => group, - :syslog_logger => true + conf_dir: conf, + owner: owner, + group: group, + syslog_logger: true } end it do should contain_mesos__property('slave_logger') .with( - :ensure => 'absent', - :file => 'logger', - :value => false, - :dir => conf, - :owner => owner, - :group => group + ensure: 'absent', + file: 'logger', + value: false, + dir: conf, + owner: owner, + group: group ) should contain_file("#{conf}/?no-logger").with_ensure('absent') @@ -519,21 +604,21 @@ describe 'when syslog_logger is false' do let(:params) do { - :conf_dir => conf, - :owner => owner, - :group => group, - :syslog_logger => false + conf_dir: conf, + owner: owner, + group: group, + syslog_logger: false } end it do should contain_mesos__property('slave_logger') .with( - :ensure => 'present', - :file => 'logger', - :value => false, - :dir => conf, - :owner => owner, - :group => group + ensure: 'present', + file: 'logger', + value: false, + dir: conf, + owner: owner, + group: group ) should contain_file("#{conf}/?no-logger").with_ensure('present') @@ -543,29 +628,36 @@ end context 'single role' do - it { should contain_service('mesos-slave').with( - :ensure => 'running', - :enable => true - ) } + it { + should contain_service('mesos-slave').with( + ensure: 'running', + enable: true + ) + } - it { should contain_service('mesos-master').with( - :enable => false - ) } + it { + should contain_service('mesos-master').with( + enable: false + ) + } it { - should contain_mesos__service('master').with(:enable => false) - should contain_mesos__service('slave').with(:enable => true) + should contain_mesos__service('master').with(enable: false) + should contain_mesos__service('slave').with(enable: true) } context 'disable single role' do - let(:params) {{ - :single_role => false, - }} - - it { should_not contain_service('mesos-master').with( - :enable => false - ) } + let(:params) do + { + single_role: false + } + end + it { + should_not contain_service('mesos-master').with( + enable: false + ) + } end end @@ -573,30 +665,30 @@ context 'diable systemd support where systemd is not present' do let(:facts) do { - :mesos_version => '1.2.0', + mesos_version: '1.2.0', # still old fact is needed due to this # https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3 - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'precise'}, - :release => { :major => '12', :minor => '04', :full => '12.04' }, + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'precise' }, + release: { major: '12', minor: '04', full: '12.04' } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end it do is_expected.to contain_mesos__property('slave_systemd_enable_support') .with( - :ensure => 'present', - :file => 'systemd_enable_support', - :value => false, - :dir => conf, - :owner => owner, - :group => group + ensure: 'present', + file: 'systemd_enable_support', + value: false, + dir: conf, + owner: owner, + group: group ) is_expected.to contain_file("#{conf}/?no-systemd_enable_support").with_ensure('present') @@ -606,28 +698,28 @@ context 'enable systemd support' do let(:facts) do { - :mesos_version => '1.2.0', - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'jessie'}, - :release => { :major => '8', :minor => '9', :full => '8.9' }, + mesos_version: '1.2.0', + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'jessie' }, + release: { major: '8', minor: '9', full: '8.9' } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end it do is_expected.not_to contain_mesos__property('slave_systemd_enable_support') .with( - :ensure => 'present', - :file => 'systemd_enable_support', - :value => true, - :dir => conf, - :owner => owner, - :group => group + ensure: 'present', + file: 'systemd_enable_support', + value: true, + dir: conf, + owner: owner, + group: group ) is_expected.not_to contain_file("#{conf}/?systemd_enable_support").with_ensure('present') @@ -638,28 +730,28 @@ context 'do not use systemd flag' do let(:facts) do { - :mesos_version => '1.2.0', - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'jessie'}, - :release => { :major => '8', :minor => '9', :full => '8.9' }, + mesos_version: '1.2.0', + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'jessie' }, + release: { major: '8', minor: '9', full: '8.9' } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end it do is_expected.not_to contain_mesos__property('slave_systemd_enable_support') .with( - :ensure => 'present', - :file => 'systemd_enable_support', - :value => true, - :dir => conf, - :owner => owner, - :group => group + ensure: 'present', + file: 'systemd_enable_support', + value: true, + dir: conf, + owner: owner, + group: group ) is_expected.not_to contain_file("#{conf}/?systemd_enable_support").with_ensure('present') @@ -667,108 +759,109 @@ end end - - context 'do not use systemd_enable_support flag for earlier versions than 0.28' do let(:facts) do { - :mesos_version => '0.27.0', - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'jessie'}, - :release => { :major => '8', :minor => '9', :full => '8.9' }, + mesos_version: '0.27.0', + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'jessie' }, + release: { major: '8', minor: '9', full: '8.9' } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end it do is_expected.not_to contain_mesos__property('slave_systemd_enable_support') .with( - :ensure => 'present', - :file => 'systemd_enable_support', - :value => false, - :dir => conf, - :owner => owner, - :group => group + ensure: 'present', + file: 'systemd_enable_support', + value: false, + dir: conf, + owner: owner, + group: group ) is_expected.not_to contain_file("#{conf}/?no-systemd_enable_support").with_ensure('present') is_expected.not_to contain_file("#{conf}/systemd_enable_support").with_ensure('present') end end - end context 'auto-detect service provider' do let(:facts) do { - :mesos_version => '1.2.0', - :osfamily => 'RedHat', - :os => { - :family => 'RedHat', - :name => 'CentOS', - :release => { :major => '6', :minor => '7', :full => '6.7' }, - }, + mesos_version: '1.2.0', + osfamily: 'RedHat', + os: { + family: 'RedHat', + name: 'CentOS', + release: { major: '6', minor: '7', full: '6.7' } + } } end - it { is_expected.to contain_service('mesos-slave').with( - :ensure => 'running', - :provider => 'upstart', - :enable => true - ) } + it { + is_expected.to contain_service('mesos-slave').with( + ensure: 'running', + provider: 'upstart', + enable: true + ) + } context 'on CentOS 7' do let(:facts) do { - :mesos_version => '1.2.0', - :osfamily => 'RedHat', - :os => { - :family => 'RedHat', - :name => 'CentOS', - :release => { :major => '7', :minor => '7', :full => '7.7' }, - }, + mesos_version: '1.2.0', + osfamily: 'RedHat', + os: { + family: 'RedHat', + name: 'CentOS', + release: { major: '7', minor: '7', full: '7.7' } + } } end - it { is_expected.to contain_service('mesos-slave').with( - :ensure => 'running', - :provider => 'systemd', - :enable => true - ) } + it { + is_expected.to contain_service('mesos-slave').with( + ensure: 'running', + provider: 'systemd', + enable: true + ) + } end end context 'custom systemd configuration' do let(:params) do { - :service_provider => 'systemd', - :manage_service_file => true, - :systemd_after => 'network-online.target openvpn-client@.service', - :systemd_wants => 'network-online.target openvpn-client@.service', + service_provider: 'systemd', + manage_service_file: true, + systemd_after: 'network-online.target openvpn-client@.service', + systemd_wants: 'network-online.target openvpn-client@.service' } end it do - is_expected.to contain_service('mesos-slave').with( - :ensure => 'running', - :enable => true + is_expected.to contain_service('mesos-slave').with( + ensure: 'running', + enable: true ) end it do - is_expected.to contain_mesos__service('slave').with(:enable => true) + is_expected.to contain_mesos__service('slave').with(enable: true) end it do is_expected.to contain_file( '/etc/systemd/system/mesos-slave.service' - ).with({ - 'ensure' => 'present', - }) + ).with( + 'ensure' => 'present' + ) end it do @@ -782,7 +875,5 @@ '/etc/systemd/system/mesos-slave.service' ).with_content(/After=network-online.target openvpn-client@.service/) end - end - end diff --git a/spec/defines/property_spec.rb b/spec/defines/property_spec.rb index 270c981..0cb2f6d 100644 --- a/spec/defines/property_spec.rb +++ b/spec/defines/property_spec.rb @@ -1,22 +1,21 @@ require 'spec_helper' -describe 'mesos::property', :type => :define do +describe 'mesos::property', type: :define do let(:title) { 'some-property' } let(:directory) { '/tmp/mesos-conf' } - let(:facts) do { - :mesos_version => '1.2.0', - :osfamily => 'Debian', - :os => { - :family => 'Debian', - :name => 'Debian', - :distro => { :codename => 'jessie'}, - :release => { :major => '8', :minor => '9', :full => '8.9' }, + mesos_version: '1.2.0', + osfamily: 'Debian', + os: { + family: 'Debian', + name: 'Debian', + distro: { codename: 'jessie' }, + release: { major: '8', minor: '9', full: '8.9' } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end @@ -27,8 +26,8 @@ context 'with a string value' do let(:params) do { - :value => 'foo', - :dir => directory, + value: 'foo', + dir: directory } end @@ -36,8 +35,8 @@ it do parameters = { - :ensure => 'present', - :content => "foo\n", + ensure: 'present', + content: "foo\n" } is_expected.to contain_file("#{directory}/#{title}").with(parameters) end @@ -46,8 +45,8 @@ context 'with an empty value' do let(:params) do { - :value => '', - :dir => directory, + value: '', + dir: directory } end @@ -61,8 +60,8 @@ context 'with the :undef value' do let(:params) do { - :value => :undef, - :dir => directory, + value: :undef, + dir: directory } end @@ -73,7 +72,6 @@ end end - context 'without a defined value or dir' do let(:params) do {} @@ -89,8 +87,8 @@ context 'with a boolean (true) value' do let(:params) do { - :value => true, - :dir => directory, + value: true, + dir: directory } end @@ -98,8 +96,8 @@ it 'should contain a positive "predicate" file' do parameters = { - :ensure => 'present', - :content => '', + ensure: 'present', + content: '' } is_expected.to contain_file("#{directory}/?#{title}").with(parameters) end @@ -108,8 +106,8 @@ context 'with a boolean (false) value' do let(:params) do { - :value => false, - :dir => directory, + value: false, + dir: directory } end @@ -117,8 +115,8 @@ it 'should contain a negative "predicate" file' do parameters = { - :ensure => 'present', - :content => '', + ensure: 'present', + content: '' } is_expected.to contain_file("#{directory}/?no-#{title}").with(parameters) end @@ -127,8 +125,8 @@ context 'with an integer value' do let(:params) do { - :value => 123, - :dir => directory, + value: 123, + dir: directory } end @@ -136,8 +134,8 @@ it 'should create a property file with the value' do parameters = { - :ensure => 'present', - :content => "123\n", + ensure: 'present', + content: "123\n" } is_expected.to contain_file("#{directory}/#{title}").with(parameters) end @@ -146,8 +144,8 @@ context 'with a float value' do let(:params) do { - :value => 3.14, - :dir => directory, + value: 3.14, + dir: directory } end @@ -155,8 +153,8 @@ it 'should create a property file with the value' do parameters = { - :ensure => 'present', - :content => "3.14\n", + ensure: 'present', + content: "3.14\n" } is_expected.to contain_file("#{directory}/#{title}").with(parameters) end @@ -165,9 +163,9 @@ context 'ensure is set to absent' do let(:params) do { - :ensure => 'absent', - :value => 'foo', - :dir => directory, + ensure: 'absent', + value: 'foo', + dir: directory } end @@ -181,9 +179,9 @@ describe 'when ensure is file and the value is empty' do let(:params) do { - :ensure => 'file', - :value => '', - :dir => directory, + ensure: 'file', + value: '', + dir: directory } end @@ -191,8 +189,8 @@ it 'should create the property file with an empty value' do parameters = { - :ensure => 'present', - :content => "\n", + ensure: 'present', + content: "\n" } is_expected.to contain_file("#{directory}/#{title}").with(parameters) end @@ -201,9 +199,9 @@ describe 'when ensure is directory' do let(:params) do { - :ensure => 'directory', - :value => 'test', - :dir => directory, + ensure: 'directory', + value: 'test', + dir: directory } end @@ -218,9 +216,9 @@ context 'default' do let(:params) do { - :ensure => 'present', - :value => 'test', - :dir => directory, + ensure: 'present', + value: 'test', + dir: directory } end @@ -229,9 +227,9 @@ it { is_expected.to contain_class('mesos::params') } parameters = { - :owner => 'root', - :group => 'root', - :mode => '0644', + owner: 'root', + group: 'root', + mode: '0644' } it { is_expected.to contain_file("#{directory}/#{title}").with(parameters) } @@ -242,12 +240,12 @@ context 'custom' do let(:params) do { - :ensure => 'present', - :value => 'test', - :owner => 'user', - :group => 'group', - :mode => '0640', - :dir => directory, + ensure: 'present', + value: 'test', + owner: 'user', + group: 'group', + mode: '0640', + dir: directory } end @@ -256,9 +254,9 @@ it { is_expected.to contain_class('mesos::params') } parameters = { - :owner => 'user', - :group => 'group', - :mode => '0640', + owner: 'user', + group: 'group', + mode: '0640' } it { is_expected.to contain_file("#{directory}/#{title}").with(parameters) } @@ -270,9 +268,9 @@ context 'when the property file is overridden' do let(:params) do { - :value => 'foo', - :file => 'some-other-property', - :dir => directory, + value: 'foo', + file: 'some-other-property', + dir: directory } end @@ -282,8 +280,8 @@ it do parameters = { - :ensure => 'present', - :content => "foo\n", + ensure: 'present', + content: "foo\n" } is_expected.to contain_file("#{directory}/some-other-property").with(parameters) end @@ -292,10 +290,10 @@ context 'service notification' do let(:params) do { - :ensure => 'present', - :value => 'test', - :service => 'Service[my-service]', - :dir => directory, + ensure: 'present', + value: 'test', + service: 'Service[my-service]', + dir: directory } end @@ -305,5 +303,4 @@ end.to raise_error /service is deprecated and will be removed in the next major release/ end end - end diff --git a/spec/defines/service_spec.rb b/spec/defines/service_spec.rb index 1c76fde..70e1db2 100644 --- a/spec/defines/service_spec.rb +++ b/spec/defines/service_spec.rb @@ -1,79 +1,90 @@ require 'spec_helper' -describe 'mesos::service', :type => :define do +describe 'mesos::service', type: :define do let(:title) { 'slave' } before(:each) do puppet_debug_override end - let(:params) {{ - :manage_service_file => false, - :systemd_after => '', - :systemd_wants => '', - }} + let(:params) do + { + manage_service_file: false, + systemd_after: '', + systemd_wants: '' + } + end - shared_examples 'mesos-service' do |family, os, codename, majdistrelease, release| + shared_examples 'mesos-service' do |family, os, codename, majdistrelease, _release| let(:facts) do { - :mesos_version => '1.2.0', - :osfamily => family, - :os => { - :family => family, - :name => os, - :distro => { :codename => codename}, - :release => { :major => majdistrelease}, + mesos_version: '1.2.0', + osfamily: family, + os: { + family: family, + name: os, + distro: { codename: codename }, + release: { major: majdistrelease } }, - :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :puppetversion => Puppet.version, + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + puppetversion: Puppet.version } end - it { is_expected.to contain_service('mesos-slave').with( - :ensure => 'stopped', - :enable => false, - :hasstatus => true, - :hasrestart => true - )} + it { + is_expected.to contain_service('mesos-slave').with( + ensure: 'stopped', + enable: false, + hasstatus: true, + hasrestart: true + ) + } context 'enable service' do - let(:params) {{ - :enable => true, - :manage_service_file => false, - :systemd_after => '', - :systemd_wants => '', - }} + let(:params) do + { + enable: true, + manage_service_file: false, + systemd_after: '', + systemd_wants: '' + } + end - it { is_expected.to contain_service('mesos-slave').with( - :enable => true, - :ensure => 'running', - )} + it { + is_expected.to contain_service('mesos-slave').with( + enable: true, + ensure: 'running' + ) + } end context 'do not manage service' do - let(:params) {{ - :enable => true, - :manage => false, # won't start service if it's not running - :manage_service_file => false, - :systemd_after => '', - :systemd_wants => '', - }} + let(:params) do + { + enable: true, + manage: false, # won't start service if it's not running + manage_service_file: false, + systemd_after: '', + systemd_wants: '' + } + end - it { is_expected.to contain_service('mesos-slave').with( - :enable => true, - :ensure => nil, - )} + it { + is_expected.to contain_service('mesos-slave').with( + enable: true, + ensure: nil + ) + } end end context 'on debian-like system' do # last argument should be service provider it_behaves_like 'mesos-service', 'Debian', 'Debian', '7', 'wheezy' - it_behaves_like 'mesos-service', 'Debian', 'Ubuntu', '12.04','precise' + it_behaves_like 'mesos-service', 'Debian', 'Ubuntu', '12.04', 'precise' end context 'on red-hat-like system' do it_behaves_like 'mesos-service', 'RedHat', 'RedHat', '6', '6' it_behaves_like 'mesos-service', 'RedHat', 'CentOS', '7', '7' end - end diff --git a/spec/functions/mesos_hash_parser_spec.rb b/spec/functions/mesos_hash_parser_spec.rb old mode 100644 new mode 100755 index 0065967..d4a18aa --- a/spec/functions/mesos_hash_parser_spec.rb +++ b/spec/functions/mesos_hash_parser_spec.rb @@ -3,19 +3,18 @@ require 'rspec-puppet' describe 'mesos_hash_parser' do - describe 'convert key-value to a puppet resource hash' do it 'convert simple hash' do param = { - 'isolation' => 'cgroups', + 'isolation' => 'cgroups' } - is_expected.to run.with_params(param).and_return({ + is_expected.to run.with_params(param).and_return( 'isolation' => { 'value' => 'cgroups', - 'file' => 'isolation', + 'file' => 'isolation' } - }) + ) end it 'should raise an error if run with extra arguments' do @@ -31,41 +30,40 @@ end it 'works with simple hash' do - is_expected.to run.with_params({'foo' => 'bar'}).and_return({ + is_expected.to run.with_params('foo' => 'bar').and_return( 'foo' => { 'value' => 'bar', - 'file' => 'foo', + 'file' => 'foo' } - }) + ) end end describe 'support prefixes' do it 'should prefix keys' do param = { - 'root' => '/cgroups', + 'root' => '/cgroups' } - is_expected.to run.with_params(param, 'cg').and_return({ + is_expected.to run.with_params(param, 'cg').and_return( 'cg_root' => { 'value' => '/cgroups', - 'file' => 'root', + 'file' => 'root' } - }) + ) end it 'should prefix files' do param = { - 'root' => '/cgroups', + 'root' => '/cgroups' } - is_expected.to run.with_params(param, 'cg', 'cg').and_return({ + is_expected.to run.with_params(param, 'cg', 'cg').and_return( 'cg_root' => { 'value' => '/cgroups', - 'file' => 'cg_root', + 'file' => 'cg_root' } - }) + ) end end - end diff --git a/spec/functions/zookeeper_servers_url_spec.rb b/spec/functions/zookeeper_servers_url_spec.rb old mode 100644 new mode 100755 index f392987..500fb99 --- a/spec/functions/zookeeper_servers_url_spec.rb +++ b/spec/functions/zookeeper_servers_url_spec.rb @@ -3,10 +3,9 @@ require 'rspec-puppet' describe 'zookeeper_servers_url' do - describe 'convert zookeeper servers list to a valid zookeeper url' do it 'convert zookeeper server list to zookeeper url only 1 server' do - param = [ '192.168.1.1:2181' ] + param = ['192.168.1.1:2181'] is_expected.to run.with_params(param).and_return( 'zk://192.168.1.1:2181/mesos' @@ -14,7 +13,7 @@ end it 'convert zookeeper server list to zookeeper url with more than 1 server' do - param = [ '192.168.1.1:2181', '192.168.1.2:2181' ] + param = ['192.168.1.1:2181', '192.168.1.2:2181'] is_expected.to run.with_params(param).and_return( 'zk://192.168.1.1:2181,192.168.1.2:2181/mesos' @@ -37,22 +36,19 @@ end it 'allow changing zookeeper path' do - param = [ '192.168.1.1:2181','192.168.1.2:2181' ] + param = ['192.168.1.1:2181', '192.168.1.2:2181'] is_expected.to run.with_params(param, 'foo').and_return( - "zk://192.168.1.1:2181,192.168.1.2:2181/foo" + 'zk://192.168.1.1:2181,192.168.1.2:2181/foo' ) end it 'allows changing default port' do - param = [ '192.168.1.1:2180','192.168.1.2', '192.168.1.3' ] + param = ['192.168.1.1:2180', '192.168.1.2', '192.168.1.3'] is_expected.to run.with_params(param, 'bar', 2222).and_return( - "zk://192.168.1.1:2180,192.168.1.2:2222,192.168.1.3:2222/bar" + 'zk://192.168.1.1:2180,192.168.1.2:2222,192.168.1.3:2222/bar' ) end - end - end - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61c900f..6fb4c61 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,7 @@ # Store any environment variables away to be restored later @old_env = {} - ENV.each_key {|k| @old_env[k] = ENV[k]} + ENV.each_key { |k| @old_env[k] = ENV[k] } if ENV['STRICT_VARIABLES'] == 'yes' Puppet.settings[:strict_variables] = true diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb index bf7c535..7c782d5 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -20,7 +20,7 @@ puppet_install # Install modules and dependencies - puppet_module_install(:source => proj_root, :module_name => 'mesos') + puppet_module_install(source: proj_root, module_name: 'mesos') shell('puppet module install puppetlabs-stdlib') shell('puppet module install puppetlabs-apt') end diff --git a/spec/unit/facter/mesos_version_spec.rb b/spec/unit/facter/mesos_version_spec.rb index cd82061..ec41b7a 100644 --- a/spec/unit/facter/mesos_version_spec.rb +++ b/spec/unit/facter/mesos_version_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' describe Facter::Util::Fact do - before { + before do Facter.clear - } + end describe 'mesos_version' do context 'returns mesos version when mesos present' do it do mesos_version_output = 'mesos 0.27.1' Facter::Util::Resolution.expects(:which).with('mesos-master').returns('/usr/sbin/mesos-master') - Facter::Util::Resolution.expects(:exec).with("mesos-master --version 2>&1").returns(mesos_version_output) - Facter.value(:mesos_version).should == "0.27.1" + Facter::Util::Resolution.expects(:exec).with('mesos-master --version 2>&1').returns(mesos_version_output) + Facter.value(:mesos_version).should == '0.27.1' end end end