-
-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from petems/fix_facts_to_not_use_rubygems
Fixes facts not to use Rubygems
- Loading branch information
Showing
4 changed files
with
70 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
# Make pip version available as a fact | ||
# Works with pip loaded and without, pip installed using pip and package installed | ||
require 'puppet' | ||
require 'rubygems' | ||
|
||
facter_puppet_version = Facter.value(:puppetversion) | ||
facter_is_pe = Facter.value(:is_pe) | ||
|
||
if facter_is_pe | ||
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0] | ||
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0] | ||
end | ||
|
||
if Gem::Version.new(facter_puppet_version) >= Gem::Version.new('3.6') | ||
if (Puppet::Util::Package.versioncmp(facter_puppet_version, '3.6') >= 0) | ||
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false') | ||
else | ||
pkg = Puppet::Type.type(:package).new(:name => 'python-pip') | ||
end | ||
|
||
Facter.add("pip_version") do | ||
has_weight 100 | ||
setcode do | ||
begin | ||
/^pip (\d+\.\d+\.?\d*).*$/.match(Facter::Util::Resolution.exec('pip --version 2>/dev/null'))[1] | ||
rescue | ||
false | ||
if Facter::Util::Resolution.which('pip') | ||
Facter::Util::Resolution.exec('pip --version 2>/dev/null').match(/^pip (\d+\.\d+\.?\d*).*$/)[1] | ||
end | ||
end | ||
end | ||
|
||
Facter.add("pip_version") do | ||
has_weight 50 | ||
setcode do | ||
begin | ||
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
/^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] | ||
end | ||
rescue | ||
false | ||
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
pkg.retrieve[pkg.property(:ensure)] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,41 @@ | ||
# Make python versions available as facts | ||
# In lists default python and system python versions | ||
require 'puppet' | ||
require 'rubygems' | ||
|
||
facter_puppet_version = Facter.value(:puppetversion) | ||
facter_is_pe = Facter.value(:is_pe) | ||
|
||
if facter_is_pe | ||
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0] | ||
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0] | ||
end | ||
|
||
if Gem::Version.new(facter_puppet_version) >= Gem::Version.new('3.6') | ||
pkg = Puppet::Type.type(:package).new(:name => 'python', :allow_virtual => 'false') | ||
if (Puppet::Util::Package.versioncmp(facter_puppet_version, '3.6') >= 0) | ||
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false') | ||
else | ||
pkg = Puppet::Type.type(:package).new(:name => 'python') | ||
pkg = Puppet::Type.type(:package).new(:name => 'python-pip') | ||
end | ||
|
||
Facter.add("system_python_version") do | ||
setcode do | ||
begin | ||
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
/^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] | ||
end | ||
rescue | ||
false | ||
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
pkg.retrieve[pkg.property(:ensure)] | ||
end | ||
end | ||
end | ||
|
||
Facter.add("python_version") do | ||
has_weight 100 | ||
setcode do | ||
begin | ||
/^.*(\d+\.\d+\.\d+)$/.match(Facter::Util::Resolution.exec('python -V 2>&1'))[1] | ||
rescue | ||
false | ||
if Facter::Util::Resolution.which('python') | ||
Facter::Util::Resolution.exec('python -V 2>&1').match(/^.*(\d+\.\d+\.\d+)$/)[1] | ||
end | ||
end | ||
end | ||
|
||
Facter.add("python_version") do | ||
has_weight 50 | ||
setcode do | ||
begin | ||
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
/^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] | ||
end | ||
rescue | ||
false | ||
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
pkg.retrieve[pkg.property(:ensure)] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
# Make virtualenv version available as a fact | ||
# Works with virualenv loaded and without, pip installed and package installed | ||
require 'puppet' | ||
require 'rubygems' | ||
|
||
facter_puppet_version = Facter.value(:puppetversion) | ||
facter_is_pe = Facter.value(:is_pe) | ||
|
||
if facter_is_pe | ||
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0] | ||
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0] | ||
end | ||
|
||
if Gem::Version.new(facter_puppet_version) >= Gem::Version.new('3.6') | ||
pkg = Puppet::Type.type(:package).new(:name => 'virtualenv', :allow_virtual => 'false') | ||
if (Puppet::Util::Package.versioncmp(facter_puppet_version, '3.6') >= 0) | ||
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false') | ||
else | ||
pkg = Puppet::Type.type(:package).new(:name => 'virtualenv') | ||
pkg = Puppet::Type.type(:package).new(:name => 'python-pip') | ||
end | ||
|
||
Facter.add("virtualenv_version") do | ||
has_weight 100 | ||
setcode do | ||
begin | ||
Facter::Util::Resolution.exec('virtualenv --version') || "absent" | ||
rescue | ||
false | ||
if Facter::Util::Resolution.which('virtualenv') | ||
Facter::Util::Resolution.exec('virtualenv --version 2>&1') | ||
end | ||
end | ||
end | ||
|
||
Facter.add("virtualenv_version") do | ||
has_weight 50 | ||
setcode do | ||
begin | ||
unless [:absent,'purged'].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
/^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1] | ||
end | ||
rescue | ||
false | ||
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)]) | ||
pkg.retrieve[pkg.property(:ensure)] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'python class' do | ||
|
||
context 'facts' do | ||
install_python = <<-EOS | ||
class { 'python' : | ||
version => 'system', | ||
pip => true, | ||
virtualenv => true, | ||
} | ||
EOS | ||
|
||
fact_notices = <<-EOS | ||
notify{"pip_version: ${::pip_version}":} | ||
notify{"system_python_version: ${::system_python_version}":} | ||
notify{"python_version: ${::python_version}":} | ||
notify{"virtualenv_version: ${::virtualenv_version}":} | ||
EOS | ||
|
||
it 'should output python facts when not installed' do | ||
apply_manifest(fact_notices, :catch_failures => true) do |r| | ||
expect(r.stdout).to match(/python_version: \S+/) | ||
expect(r.stdout).to match(/pip_version: \S+/) | ||
expect(r.stdout).to match(/virtualenv_version: \S+/) | ||
expect(r.stdout).to match(/system_python_version: \S+/) | ||
end | ||
end | ||
|
||
it 'sets up python' do | ||
apply_manifest(install_python, :catch_failures => true) | ||
end | ||
|
||
it 'should output python facts when installed' do | ||
apply_manifest(fact_notices, :catch_failures => true) do |r| | ||
expect(r.stdout).to match(/python_version: \S+/) | ||
expect(r.stdout).to match(/pip_version: \S+/) | ||
expect(r.stdout).to match(/virtualenv_version: \S+/) | ||
expect(r.stdout).to match(/system_python_version: \S+/) | ||
end | ||
end | ||
end | ||
end |