From 543677b99a2d343c4f7f20b1f36371e740ca5ef6 Mon Sep 17 00:00:00 2001 From: Chadwick Banning Date: Tue, 7 Jun 2016 21:52:54 -0400 Subject: [PATCH] Convert rvm_system_ruby autolib_mode to parameter This should be a parameter that affects whether the --autolibs argument is passed to the `rvm install` command and what its value is. --- .../rvm_system_ruby/rvm_system_ruby.rb | 12 +++------- lib/puppet/type/rvm_system_ruby.rb | 16 +++++++++++-- spec/unit/puppet/type/rvm_system_ruby_spec.rb | 24 +++++++++++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 spec/unit/puppet/type/rvm_system_ruby_spec.rb diff --git a/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb b/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb index c4ed75f3..79ac1dce 100644 --- a/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb +++ b/lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb @@ -47,14 +47,6 @@ def set_default rvmcmd "alias", "create", "default", resource[:name] end - def set_autolib_mode - begin - rvmcmd "autolibs", resource[:autolib_mode] - rescue Puppet::ExecutionFailure => detail - raise Puppet::Error, "Could not set autolib mode: #{detail}" - end - end - private def install @@ -65,8 +57,10 @@ def install ENV['no_proxy'] = resource[:no_proxy] end end - set_autolib_mode if resource.value(:autolib_mode) options = Array(resource[:build_opts]) + if resource[:autolibs_mode] + options << "--autolibs #{resource[:autolibs_mode]}" + end if resource[:proxy_url] and !resource[:proxy_url].empty? rvmcmd "install", resource[:name], "--proxy", resource[:proxy_url], *options else diff --git a/lib/puppet/type/rvm_system_ruby.rb b/lib/puppet/type/rvm_system_ruby.rb index 4c1910e0..eb8dd43b 100644 --- a/lib/puppet/type/rvm_system_ruby.rb +++ b/lib/puppet/type/rvm_system_ruby.rb @@ -28,8 +28,20 @@ defaultto false end - newproperty(:autolib_mode) do - desc "Set RVM autolib mode" + newparam(:autolib_mode) do + desc "Set RVM autolib mode for the Ruby installation" + + validate do |value| + modes = [ + 0, 'disable', 'disabled', + 1, 'read', 'read-only', + 2, 'fail', 'read-fail', + 3, 'packages', 'install-packages', + 4, 'enable', 'enabled', + ] + + fail("Invalid autolib mode: #{value}") unless modes.include? value + end end newparam(:mount_from) do diff --git a/spec/unit/puppet/type/rvm_system_ruby_spec.rb b/spec/unit/puppet/type/rvm_system_ruby_spec.rb new file mode 100644 index 00000000..202ff6f5 --- /dev/null +++ b/spec/unit/puppet/type/rvm_system_ruby_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' +require 'puppet' +require 'puppet/type/rvm_system_ruby' + +describe Puppet::Type.type(:rvm_system_ruby) do + context 'with autolib_mode set' do + it 'should not raise error' do + expect do + Puppet::Type.type(:rvm_system_ruby).new(:name => 'ruby-1.9.3-p448', :autolib_mode => 'enabled') + end.not_to raise_error + end + + it 'should set mode correctly' do + @system_ruby = Puppet::Type.type(:rvm_system_ruby).new(:name => 'jruby-1.7.6', :autolib_mode => 'read-fail') + expect(@system_ruby[:autolib_mode]).to eq('read-fail') + end + end + + it 'should error on an incorrect autolib_mode' do + expect do + Puppet::Type.type(:rvm_system_ruby).new(:name => 'ruby-1.9.3-p448', :autolib_mode => 'foo') + end.to raise_error(Puppet::ResourceError, /Invalid autolib mode: foo/) + end +end