Skip to content

Commit

Permalink
Merge branch '2.x' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNagy authored Sep 30, 2019
2 parents 4a11e53 + 70f0e08 commit 0f03e19
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ notifications:
email: false
rvm:
- 1.9.3
- 1.8.7-p374
- 2.0.0
- 2.1.5
- 2.2.0
Expand All @@ -15,3 +14,5 @@ matrix:
fast_finish: true
allow_failures:
- rvm: ruby-head
git:
depth: false
20 changes: 17 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"
source ENV['GEM_SOURCE'] || 'https://artifactory.delivery.puppetlabs.net/artifactory/api/gems/rubygems/'

def location_for(place, fake_version = nil)
if place =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
elsif place =~ /^file:\/\/(.*)/
['>= 0', { :path => File.expand_path($1), :require => false }]
else
[place, { :require => false }]
end
end

# C Ruby (MRI) or Rubinius, but NOT Windows
platforms :ruby do
Expand All @@ -18,6 +28,8 @@ group :development, :test do
gem 'puppetlabs_spec_helper'
end

gem 'packaging', *location_for(ENV['PACKAGING_LOCATION'] || '~> 0.99') if RUBY_VERSION.to_f >= 2.3

require 'yaml'
data = YAML.load_file(File.join(File.dirname(__FILE__), 'ext', 'project_data.yaml'))
bundle_platforms = data['bundle_platforms']
Expand All @@ -39,10 +51,12 @@ mingw << :x64_mingw if Bundler::Dsl::VALID_PLATFORMS.include?(:x64_mingw)
platform(*mingw) do
# FFI dropped 1.9.3 support in 1.9.16, and 1.9.15 was an incomplete release.
# 1.9.18 is required to support Ruby 2.4
if RUBY_VERSION < '2.0.0'
if RUBY_VERSION.to_f < 2.0
gem 'ffi', '<= 1.9.14', :require => false
else
elsif RUBY_VERSION.to_f < 2.6
gem 'ffi', '~> 1.9.18', :require => false
else
gem 'ffi', '~> 1.10', :require => false
end
end

Expand Down
55 changes: 11 additions & 44 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,33 @@
# Rakefile for facter

# We need access to the Puppet.version method
$LOAD_PATH.unshift(File.expand_path("lib"))
require 'facter/version'

$LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks')
RAKE_ROOT = File.expand_path(File.dirname(__FILE__))

$LOAD_PATH << File.join(RAKE_ROOT, 'tasks')

require 'rake'
Dir['tasks/**/*.rake'].each { |t| load t }

begin
load File.join(File.dirname(__FILE__), 'ext', 'packaging', 'packaging.rake')
rescue LoadError
end

['rubygems',
'rspec',
'rspec/core/rake_task',
'rcov',].each do |lib|
['rubygems', 'rspec', 'rspec/core/rake_task','rcov', 'packaging'].each do |lib|
begin
require lib
rescue LoadError
end
end

#load packaging tasks
Pkg::Util::RakeUtils.load_packaging_tasks if defined?(Pkg)

build_defs_file = 'ext/build_defaults.yaml'
if File.exist?(build_defs_file)
begin
require 'yaml'
@build_defaults ||= YAML.load_file(build_defs_file)
rescue Exception => e
STDERR.puts "Unable to load yaml from #{build_defs_file}:"
STDERR.puts e
namespace :package do
task :bootstrap do
puts 'Bootstrap is no longer needed, using packaging-as-a-gem'
end
@packaging_url = @build_defaults['packaging_url']
@packaging_repo = @build_defaults['packaging_repo']
raise "Could not find packaging url in #{build_defs_file}" if @packaging_url.nil?
raise "Could not find packaging repo in #{build_defs_file}" if @packaging_repo.nil?

namespace :package do
desc "Bootstrap packaging automation, e.g. clone into packaging repo"
task :bootstrap do
if File.exist?("ext/#{@packaging_repo}")
puts "It looks like you already have ext/#{@packaging_repo}. If you don't like it, blow it away with package:implode."
else
cd 'ext' do
%x{git clone #{@packaging_url}}
end
end
end
desc "Remove all cloned packaging automation"
task :implode do
rm_rf "ext/#{@packaging_repo}"
end
task :implode do
puts 'Implode is no longer needed, using packaging-as-a-gem'
end
end

task :default do
sh %{rake -T}
end

if defined?(RSpec::Core::RakeTask)
desc "Run all specs"
RSpec::Core::RakeTask.new do |t|
Expand Down
4 changes: 2 additions & 2 deletions ext/project_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ gem_platform_dependencies:
CFPropertyList: '~> 2.2'
x86-mingw32:
gem_runtime_dependencies:
ffi: '~> 1.9.5'
ffi: '~> 1.9'
x64-mingw32:
gem_runtime_dependencies:
ffi: '~> 1.9.5'
ffi: '~> 1.9'
bundle_platforms:
universal-darwin: ruby
x86-mingw32: mingw
Expand Down
4 changes: 2 additions & 2 deletions lib/facter/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Facter.define_fact(:ec2_metadata) do
define_resolution(:rest) do
confine do
Facter.value(:virtual).match /^(xen|kvm|ec2)/
Facter.value(:virtual).match /^(xen|kvm|nitro|ec2)/
end

@querier = Facter::EC2::Metadata.new
Expand All @@ -37,7 +37,7 @@
Facter.define_fact(:ec2_userdata) do
define_resolution(:rest) do
confine do
Facter.value(:virtual).match /^(xen|kvm|ec2)/
Facter.value(:virtual).match /^(xen|kvm|nitro|ec2)/
end

@querier = Facter::EC2::Userdata.new
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/ec2/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def reachable?(retry_limit = 3)
attempts = 0

begin
open(@baseurl, :proxy => nil, :read_timeout => timeout, :open_timeout => timeout).read
open(@baseurl, :proxy => nil, :read_timeout => timeout).read
able_to_connect = true
rescue OpenURI::HTTPError => e
if e.message.match /404 Not Found/i
Expand Down
31 changes: 29 additions & 2 deletions lib/facter/operatingsystem/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def get_osfamily
"Archlinux"
when "Mageia", "Mandriva", "Mandrake"
"Mandrake"
when "ALT Linux", "ALT Starter Kit", "ALT Workstation", "ALT Server"
"ALT"
else
Facter.value("kernel")
end
Expand All @@ -46,6 +48,8 @@ def get_operatingsystemrelease
case get_operatingsystem
when "Alpine"
get_alpine_release_with_release_file
when "ALT", "ALT Starter Kit", "ALT Workstation", "ALT Server"
get_alt_release_with_release_file
when "Amazon"
get_amazon_release_with_lsb
when "AristaEOS"
Expand Down Expand Up @@ -247,7 +251,6 @@ def get_operatingsystem_with_release_files
"AristaEOS" => "/etc/Eos-release",
"Debian" => "/etc/debian_version",
"Gentoo" => "/etc/gentoo-release",
"Fedora" => "/etc/fedora-release",
"Mageia" => "/etc/mageia-release",
"Mandriva" => "/etc/mandriva-release",
"Mandrake" => "/etc/mandrake-release",
Expand Down Expand Up @@ -276,6 +279,10 @@ def get_operatingsystem_with_release_files
else
operatingsystem = "OEL"
end
elsif FileTest.exists?("/etc/altlinux-release")
operatingsystem = get_alt_operatingsystem_name
elsif FileTest.exists?("/etc/fedora-release")
operatingsystem = "Fedora"
elsif FileTest.exists?("/etc/redhat-release")
operatingsystem = get_redhat_operatingsystem_name
elsif FileTest.exists?("/etc/SuSE-release")
Expand Down Expand Up @@ -314,6 +321,22 @@ def get_redhat_operatingsystem_name
end
end

# Uses a regex search on /etc/altlinux-release to determine OS
#
# @return [String]
def get_alt_operatingsystem_name
txt = File.read("/etc/os-release")
matches = {
"ALT Starter Kit" => "^NAME=\"ALT( Linux)? starter kit",
"ALT Workstation" => "^NAME=\"ALT( Linux)? Workstation",
"ALT Server" => "^NAME=\"ALT( Linux)? Server",
}
match = regex_search_release_file_for_operatingsystem(matches, txt)
match = "ALT Linux" if match == nil

match
end

# Uses a regex search on /etc/SuSE-release to determine OS
#
# @return [String]
Expand Down Expand Up @@ -366,7 +389,7 @@ def get_amazon_release_with_lsb
lsbdistrelease
else
if release = Facter::Util::FileRead.read('/etc/system-release')
if match = /\d+\.\d+/.match(release)
if match = /\d+\.?\d*/.match(release)
match[0]
end
end
Expand Down Expand Up @@ -410,6 +433,10 @@ def get_redhatish_release_with_release_file
end
end

def get_alt_release_with_release_file
regex_search_releasefile_for_release(/VERSION_ID=([0-9.]+)/m, "/etc/os-release")
end

def get_debian_release_with_release_file
if release = Facter::Util::FileRead.read('/etc/debian_version')
release.sub!(/\s*$/, '')
Expand Down
4 changes: 4 additions & 0 deletions lib/facter/util/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def self.gce?
File.read("/sys/devices/virtual/dmi/id/product_name") =~ /Google/ rescue false
end

def self.nitro?
File.read("/sys/devices/virtual/dmi/id/bios_vendor") =~ /Amazon/ rescue false
end

def self.jail?
path = case Facter.value(:kernel)
when "FreeBSD" then "/sbin"
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Facter
if not defined? FACTERVERSION then
FACTERVERSION = '2.5.1'
FACTERVERSION = '2.5.6'
end

# Returns the running version of Facter.
Expand Down
5 changes: 5 additions & 0 deletions lib/facter/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
next Facter::Util::Virtual.kvm_type if Facter::Util::Virtual.kvm?
next "rhev" if Facter::Util::Virtual.rhev?
next "ovirt" if Facter::Util::Virtual.ovirt?
next "nitro" if Facter::Util::Virtual.nitro?

# Parse lspci
output = Facter::Util::Virtual.lspci
Expand Down Expand Up @@ -229,6 +230,10 @@
result = "xen"
end

if result.nil? and computersystem.manufacturer =~ /Amazon/
result = "nitro"
end

break
end
result ||= "physical"
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/operatingsystem/linux_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@
expect(release).to eq "2014.03"
end

it "should parse major release only from /etc/system-release" do
subject.expects(:get_operatingsystem).returns("Amazon")
subject.expects(:get_lsbdistrelease).returns(nil)
Facter::Util::FileRead.expects(:read).with('/etc/system-release').returns("Amazon Linux release 2 (Karoo)")
release = subject.get_operatingsystemrelease
expect(release).to eq "2"
end


it "should fall back to kernelrelease fact for gnu/kfreebsd" do
Facter.fact(:kernelrelease).stubs(:value).returns("1.2.3")
subject.expects(:get_operatingsystem).returns("GNU/kFreeBSD")
Expand Down

0 comments on commit 0f03e19

Please sign in to comment.