facter 2.4.1 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/facter/ec2.rb +1 -1
- data/lib/facter/ec2/rest.rb +3 -0
- data/lib/facter/operatingsystem/implementation.rb +3 -0
- data/lib/facter/operatingsystem/osreleaselinux.rb +28 -0
- data/lib/facter/puppetversion.rb +2 -2
- data/lib/facter/selinux.rb +1 -1
- data/lib/facter/util/config.rb +24 -3
- data/lib/facter/util/directory_loader.rb +2 -2
- data/lib/facter/util/ip.rb +2 -2
- data/lib/facter/util/virtual.rb +11 -3
- data/lib/facter/util/xendomains.rb +10 -1
- data/lib/facter/version.rb +1 -1
- data/lib/facter/virtual.rb +2 -1
- data/spec/fixtures/unit/selinux/selinux_sestatus2 +9 -0
- data/spec/fixtures/unit/util/operatingsystem/coreos.txt +9 -0
- data/spec/unit/operatingsystem/implementation_spec.rb +1 -0
- data/spec/unit/operatingsystem/linux_spec.rb +1 -1
- data/spec/unit/selinux_spec.rb +5 -0
- data/spec/unit/util/config_spec.rb +26 -3
- data/spec/unit/util/operatingsystem_spec.rb +15 -0
- data/spec/unit/util/virtual_spec.rb +22 -12
- data/spec/unit/util/xendomains_spec.rb +73 -25
- data/spec/unit/virtual_spec.rb +7 -0
- metadata +658 -651
- checksums.yaml +0 -7
data/lib/facter/ec2.rb
CHANGED
data/lib/facter/ec2/rest.rb
CHANGED
@@ -96,6 +96,9 @@ module Facter
|
|
96
96
|
rescue *CONNECTION_ERRORS => e
|
97
97
|
Facter.log_exception(e, "Failed to fetch ec2 uri #{uri}: #{e.message}")
|
98
98
|
return nil
|
99
|
+
rescue Timeout::Error => e
|
100
|
+
Facter.log_exception(e, "Failed to fetch ec2 uri #{uri}: #{e.message}")
|
101
|
+
return nil
|
99
102
|
end
|
100
103
|
|
101
104
|
private
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'facter/operatingsystem/base'
|
2
|
+
require 'facter/operatingsystem/osreleaselinux'
|
2
3
|
require 'facter/operatingsystem/cumuluslinux'
|
3
4
|
require 'facter/operatingsystem/linux'
|
4
5
|
require 'facter/operatingsystem/sunos'
|
@@ -13,6 +14,8 @@ module Facter
|
|
13
14
|
release_info = Facter::Util::Operatingsystem.os_release
|
14
15
|
if release_info['NAME'] == "Cumulus Linux"
|
15
16
|
Facter::Operatingsystem::CumulusLinux.new
|
17
|
+
elsif release_info['NAME'] == "CoreOS"
|
18
|
+
Facter::Operatingsystem::OsReleaseLinux.new
|
16
19
|
else
|
17
20
|
Facter::Operatingsystem::Linux.new
|
18
21
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'facter/util/operatingsystem'
|
2
|
+
require 'facter/operatingsystem/linux'
|
3
|
+
|
4
|
+
module Facter
|
5
|
+
module Operatingsystem
|
6
|
+
class OsReleaseLinux < Linux
|
7
|
+
def get_operatingsystem
|
8
|
+
# Native cfacter also uses the NAME field.
|
9
|
+
Facter::Util::Operatingsystem.os_release['NAME']
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_osfamily
|
13
|
+
Facter::Util::Operatingsystem.os_release['NAME']
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_operatingsystemrelease
|
17
|
+
@operatingsystemrelease ||= Facter::Util::Operatingsystem.os_release['VERSION_ID']
|
18
|
+
@operatingsystemrelease
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_operatingsystemmajrelease
|
22
|
+
if operatingsystemrelease = get_operatingsystemrelease
|
23
|
+
operatingsystemrelease.split(".").first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/facter/puppetversion.rb
CHANGED
data/lib/facter/selinux.rb
CHANGED
@@ -148,7 +148,7 @@ Facter.add("selinux_config_policy") do
|
|
148
148
|
setcode do
|
149
149
|
result = 'unknown'
|
150
150
|
mode = Facter::Core::Execution.exec(sestatus_cmd)
|
151
|
-
mode.each_line { |l| result = $
|
151
|
+
mode.each_line { |l| result = $2 if l =~ /^(Policy from config file|Loaded policy name)\:\s+(\w+)$/i }
|
152
152
|
result.chomp
|
153
153
|
end
|
154
154
|
end
|
data/lib/facter/util/config.rb
CHANGED
@@ -41,16 +41,19 @@ module Facter::Util::Config
|
|
41
41
|
if Facter::Util::Root.root?
|
42
42
|
windows_dir = windows_data_dir
|
43
43
|
if windows_dir.nil? then
|
44
|
-
# Note: Beginning with Facter 3, /opt/puppetlabs/
|
44
|
+
# Note: Beginning with Facter 3, /opt/puppetlabs/facter/facts.d will be the only
|
45
45
|
# default external fact directory.
|
46
|
-
@external_facts_dirs = ["/opt/puppetlabs/
|
46
|
+
@external_facts_dirs = ["/opt/puppetlabs/facter/facts.d",
|
47
47
|
"/etc/facter/facts.d",
|
48
48
|
"/etc/puppetlabs/facter/facts.d"]
|
49
49
|
else
|
50
50
|
@external_facts_dirs = [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
|
51
51
|
end
|
52
52
|
elsif ENV['HOME']
|
53
|
-
|
53
|
+
# Note: Beginning with Facter 3, ~/.puppetlabs/opt/facter/facts.d will be the only
|
54
|
+
# default external fact directory.
|
55
|
+
@external_facts_dirs = [File.expand_path(File.join(ENV['HOME'], ".puppetlabs", "opt", "facter", "facts.d")),
|
56
|
+
File.expand_path(File.join(ENV['HOME'], ".facter", "facts.d"))]
|
54
57
|
else
|
55
58
|
@external_facts_dirs = []
|
56
59
|
end
|
@@ -64,4 +67,22 @@ module Facter::Util::Config
|
|
64
67
|
end
|
65
68
|
|
66
69
|
setup_default_ext_facts_dirs
|
70
|
+
|
71
|
+
def self.override_binary_dir=(dir)
|
72
|
+
@override_binary_dir = dir
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.override_binary_dir
|
76
|
+
@override_binary_dir
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.setup_default_override_binary_dir
|
80
|
+
if Facter::Util::Config.is_windows?
|
81
|
+
@override_binary_dir = nil
|
82
|
+
else
|
83
|
+
@override_binary_dir = "/opt/puppetlabs/puppet/bin"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
setup_default_override_binary_dir
|
67
88
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# A Facter plugin that loads external facts.
|
2
2
|
#
|
3
3
|
# Default Unix Directories:
|
4
|
-
# /opt/puppetlabs/
|
4
|
+
# /opt/puppetlabs/facter/facts.d, /etc/facter/facts.d, /etc/puppetlabs/facter/facts.d
|
5
5
|
#
|
6
|
-
# Beginning with Facter 3, only /opt/puppetlabs/
|
6
|
+
# Beginning with Facter 3, only /opt/puppetlabs/facter/facts.d will be a default external fact
|
7
7
|
# directory in Unix.
|
8
8
|
#
|
9
9
|
# Default Windows Direcotires:
|
data/lib/facter/util/ip.rb
CHANGED
@@ -286,8 +286,8 @@ module Facter::Util::IP
|
|
286
286
|
# Linux changes the MAC address reported via ifconfig when an ethernet interface
|
287
287
|
# becomes a slave of a bonding device to the master MAC address.
|
288
288
|
# We have to dig a bit to get the original/real MAC address of the interface.
|
289
|
-
bonddev = get_bonding_master(interface)
|
290
|
-
if
|
289
|
+
bonddev = get_bonding_master(interface) if label == 'macaddress'
|
290
|
+
if bonddev
|
291
291
|
bondinfo = read_proc_net_bonding("/proc/net/bonding/#{bonddev}")
|
292
292
|
re = /^Slave Interface: #{interface}\b.*?\bPermanent HW addr: (([0-9A-F]{2}:?)*)$/im
|
293
293
|
if match = re.match(bondinfo)
|
data/lib/facter/util/virtual.rb
CHANGED
@@ -13,9 +13,17 @@ module Facter::Util::Virtual
|
|
13
13
|
# and later versions of virt-what may emit this message on stderr. This
|
14
14
|
# method ensures stderr is redirected and that error messages are stripped
|
15
15
|
# from stdout.
|
16
|
-
def self.virt_what(
|
17
|
-
|
18
|
-
|
16
|
+
def self.virt_what(cmd = "virt-what")
|
17
|
+
if bindir = Facter::Util::Config.override_binary_dir
|
18
|
+
command = Facter::Core::Execution.which(File.join(bindir, cmd))
|
19
|
+
else
|
20
|
+
command = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
if !command
|
24
|
+
command = Facter::Core::Execution.which(cmd)
|
25
|
+
return unless command
|
26
|
+
end
|
19
27
|
|
20
28
|
if Facter.value(:kernel) == 'windows'
|
21
29
|
redirected_cmd = "#{command} 2>NUL"
|
@@ -4,7 +4,16 @@ module Facter::Util::Xendomains
|
|
4
4
|
XEN_COMMANDS = ['/usr/sbin/xl', '/usr/sbin/xm']
|
5
5
|
|
6
6
|
def self.xen_command
|
7
|
-
|
7
|
+
if File.file?('/usr/lib/xen-common/bin/xen-toolstack')
|
8
|
+
xen_toolstack_cmd = Facter::Util::Resolution.exec('/usr/lib/xen-common/bin/xen-toolstack')
|
9
|
+
if xen_toolstack_cmd
|
10
|
+
xen_toolstack_cmd.chomp
|
11
|
+
else
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
else
|
15
|
+
XEN_COMMANDS.find { |cmd| Facter::Util::Resolution.which(cmd) }
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
def self.get_domains
|
data/lib/facter/version.rb
CHANGED
data/lib/facter/virtual.rb
CHANGED
@@ -73,7 +73,7 @@ end
|
|
73
73
|
Facter.add("virtual") do
|
74
74
|
confine :kernel => 'SunOS'
|
75
75
|
has_weight 10
|
76
|
-
self.timeout =
|
76
|
+
self.timeout = 20
|
77
77
|
|
78
78
|
setcode do
|
79
79
|
next "zone" if Facter::Util::Virtual.zone?
|
@@ -164,6 +164,7 @@ Facter.add("virtual") do
|
|
164
164
|
next "rhev" if lines.any? {|l| l =~ /Product Name: RHEV Hypervisor/ }
|
165
165
|
next "ovirt" if lines.any? {|l| l =~ /Product Name: oVirt Node/ }
|
166
166
|
next "bochs" if lines.any? {|l| l =~ /Bochs/ }
|
167
|
+
next "kvm" if lines.any? {|l| l =~ /Manufacturer: QEMU/ }
|
167
168
|
end
|
168
169
|
|
169
170
|
# Default to 'physical'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
SELinux status: enabled
|
2
|
+
SELinuxfs mount: /sys/fs/selinux
|
3
|
+
SELinux root directory: /etc/selinux
|
4
|
+
Loaded policy name: default
|
5
|
+
Current mode: enforcing
|
6
|
+
Mode from config file: permissive
|
7
|
+
Policy MLS status: enabled
|
8
|
+
Policy deny_unknown status: denied
|
9
|
+
Max kernel policy version: 29
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'facter/operatingsystem/implementation'
|
3
3
|
require 'facter/operatingsystem/base'
|
4
4
|
require 'facter/operatingsystem/cumuluslinux'
|
5
|
+
require 'facter/operatingsystem/osreleaselinux'
|
5
6
|
require 'facter/operatingsystem/linux'
|
6
7
|
require 'facter/operatingsystem/sunos'
|
7
8
|
require 'facter/operatingsystem/vmkernel'
|
@@ -298,7 +298,7 @@ describe Facter::Operatingsystem::Linux do
|
|
298
298
|
end
|
299
299
|
|
300
300
|
describe "Operatingsystemmajrelease key" do
|
301
|
-
['Amazon' 'AristaEOS', 'CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC','CumulusLinux'].each do |operatingsystem|
|
301
|
+
['Amazon' 'AristaEOS', 'CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC','CumulusLinux','CoreOS'].each do |operatingsystem|
|
302
302
|
describe "on #{operatingsystem} operatingsystems" do
|
303
303
|
it "should be derived from operatingsystemrelease" do
|
304
304
|
subject.stubs(:get_operatingsystem).returns(operatingsystem)
|
data/spec/unit/selinux_spec.rb
CHANGED
@@ -96,6 +96,11 @@ describe "SELinux facts" do
|
|
96
96
|
|
97
97
|
Facter.fact(:selinux_config_policy).value.should == "targeted"
|
98
98
|
end
|
99
|
+
it "should return the loaded SELinux policy" do
|
100
|
+
sestatus_is(my_fixture_read("selinux_sestatus2"))
|
101
|
+
|
102
|
+
Facter.fact(:selinux_config_policy).value.should == "default"
|
103
|
+
end
|
99
104
|
end
|
100
105
|
|
101
106
|
def sestatus_is(status)
|
@@ -55,7 +55,7 @@ describe Facter::Util::Config do
|
|
55
55
|
Facter::Util::Config.stubs(:is_windows?).returns(false)
|
56
56
|
Facter::Util::Config.stubs(:windows_data_dir).returns(nil)
|
57
57
|
Facter::Util::Config.setup_default_ext_facts_dirs
|
58
|
-
Facter::Util::Config.external_facts_dirs.should == ["/opt/puppetlabs/
|
58
|
+
Facter::Util::Config.external_facts_dirs.should == ["/opt/puppetlabs/facter/facts.d", "/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return the default value for windows 2008" do
|
@@ -72,10 +72,11 @@ describe Facter::Util::Config do
|
|
72
72
|
Facter::Util::Config.external_facts_dirs.should == [File.join("C:\\Documents", 'PuppetLabs', 'facter', 'facts.d')]
|
73
73
|
end
|
74
74
|
|
75
|
-
it "returns the
|
75
|
+
it "returns the old and new (AIO) paths under user's home directory when not root" do
|
76
76
|
Facter::Util::Root.stubs(:root?).returns(false)
|
77
77
|
Facter::Util::Config.setup_default_ext_facts_dirs
|
78
|
-
Facter::Util::Config.external_facts_dirs.should == [File.expand_path(File.join("~", ".facter", "facts.d"))
|
78
|
+
Facter::Util::Config.external_facts_dirs.should == [File.expand_path(File.join("~", ".puppetlabs", "opt", "facter", "facts.d")),
|
79
|
+
File.expand_path(File.join("~", ".facter", "facts.d"))]
|
79
80
|
end
|
80
81
|
|
81
82
|
it "includes additional values when user appends to the list" do
|
@@ -94,4 +95,26 @@ describe Facter::Util::Config do
|
|
94
95
|
end
|
95
96
|
|
96
97
|
end
|
98
|
+
|
99
|
+
describe "override_binary_dir" do
|
100
|
+
it "should return the default value for linux" do
|
101
|
+
Facter::Util::Config.stubs(:is_windows?).returns(false)
|
102
|
+
Facter::Util::Config.setup_default_override_binary_dir
|
103
|
+
Facter::Util::Config.override_binary_dir.should == "/opt/puppetlabs/puppet/bin"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return nil for windows" do
|
107
|
+
Facter::Util::Config.stubs(:is_windows?).returns(true)
|
108
|
+
Facter::Util::Config.setup_default_override_binary_dir
|
109
|
+
Facter::Util::Config.override_binary_dir.should == nil
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should output new values when explicitly set" do
|
113
|
+
Facter::Util::Config.setup_default_override_binary_dir
|
114
|
+
new_value = '/usr/share/newdir'
|
115
|
+
Facter::Util::Config.override_binary_dir = new_value
|
116
|
+
Facter::Util::Config.override_binary_dir.should == new_value
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
97
120
|
end
|
@@ -19,6 +19,21 @@ describe Facter::Util::Operatingsystem do
|
|
19
19
|
})
|
20
20
|
end
|
21
21
|
|
22
|
+
it "correctly parses the file on CoreOS Linux" do
|
23
|
+
values = described_class.os_release(my_fixture('coreos.txt'))
|
24
|
+
|
25
|
+
expect(values).to eq({
|
26
|
+
'NAME' => "CoreOS",
|
27
|
+
'VERSION_ID' => "575.0.0",
|
28
|
+
'VERSION' => "575.0.0",
|
29
|
+
'PRETTY_NAME' => "CoreOS 575.0.0",
|
30
|
+
'ID' => "coreos",
|
31
|
+
'HOME_URL' => "https://coreos.com/",
|
32
|
+
'BUG_REPORT_URL' => "https://github.com/coreos/bugs/issues",
|
33
|
+
'ANSI_COLOR' => "1;32",
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
22
37
|
it "correctly parses the file on Sabayon" do
|
23
38
|
values = described_class.os_release(my_fixture('sabayon.txt'))
|
24
39
|
|
@@ -278,10 +278,15 @@ describe Facter::Util::Virtual do
|
|
278
278
|
mockfile
|
279
279
|
end
|
280
280
|
|
281
|
-
shared_examples_for "virt-what" do |kernel, path, null_device|
|
281
|
+
shared_examples_for "virt-what" do |kernel, path, null_device, override_location|
|
282
282
|
before(:each) do
|
283
283
|
Facter.fact(:kernel).stubs(:value).returns(kernel)
|
284
|
-
|
284
|
+
if override_location
|
285
|
+
Facter::Core::Execution.expects(:which).with(File.join(Facter::Util::Config.override_binary_dir, "virt-what")).returns(path)
|
286
|
+
else
|
287
|
+
Facter::Core::Execution.expects(:which).with(File.join(Facter::Util::Config.override_binary_dir, "virt-what")).returns(nil)
|
288
|
+
Facter::Core::Execution.expects(:which).with("virt-what").returns(path)
|
289
|
+
end
|
285
290
|
Facter::Core::Execution.expects(:exec).with("#{path} 2>#{null_device}")
|
286
291
|
end
|
287
292
|
|
@@ -291,23 +296,28 @@ describe Facter::Util::Virtual do
|
|
291
296
|
end
|
292
297
|
|
293
298
|
context "on linux" do
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
299
|
+
describe "override binary dir doesn't exist" do
|
300
|
+
it_should_behave_like "virt-what", "linux", "/usr/bin/virt-what", "/dev/null", true
|
301
|
+
it_should_behave_like "virt-what", "linux", "/usr/bin/virt-what", "/dev/null", false
|
302
|
+
|
303
|
+
it "should strip out warnings on stdout from virt-what" do
|
304
|
+
virt_what_warning = "virt-what: this script must be run as root"
|
305
|
+
Facter.fact(:kernel).stubs(:value).returns('linux')
|
306
|
+
Facter::Core::Execution.expects(:which).with(File.join(Facter::Util::Config.override_binary_dir, "virt-what")).returns(nil)
|
307
|
+
Facter::Core::Execution.expects(:which).with('virt-what').returns "/usr/bin/virt-what"
|
308
|
+
Facter::Core::Execution.expects(:exec).with('/usr/bin/virt-what 2>/dev/null').returns virt_what_warning
|
309
|
+
Facter::Util::Virtual.virt_what.should_not match /^virt-what: /
|
310
|
+
end
|
302
311
|
end
|
303
312
|
end
|
304
313
|
|
305
314
|
context "on unix" do
|
306
|
-
it_should_behave_like "virt-what", "unix", "/usr/bin/virt-what", "/dev/null"
|
315
|
+
it_should_behave_like "virt-what", "unix", "/usr/bin/virt-what", "/dev/null", true
|
316
|
+
it_should_behave_like "virt-what", "unix", "/usr/bin/virt-what", "/dev/null", false
|
307
317
|
end
|
308
318
|
|
309
319
|
context "on windows" do
|
310
|
-
it_should_behave_like "virt-what", "windows", 'c:\windows\system32\virt-what', "NUL"
|
320
|
+
it_should_behave_like "virt-what", "windows", 'c:\windows\system32\virt-what', "NUL", false
|
311
321
|
end
|
312
322
|
|
313
323
|
describe '.lxc?' do
|
@@ -7,60 +7,108 @@ describe Facter::Util::Xendomains do
|
|
7
7
|
|
8
8
|
let(:xen0_domains) { my_fixture_read("xendomains") }
|
9
9
|
|
10
|
-
describe "when the
|
10
|
+
describe "when the xen-toolstack command is present" do
|
11
11
|
before do
|
12
|
-
|
12
|
+
File.expects(:file?).with('/usr/lib/xen-common/bin/xen-toolstack').returns true
|
13
13
|
end
|
14
14
|
|
15
|
-
describe "and the
|
16
|
-
|
15
|
+
describe "and the xen-toolstack returns xl" do
|
17
16
|
before do
|
18
|
-
Facter::Util::Resolution.stubs(:
|
19
|
-
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xm list 2>/dev/null').never
|
17
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/lib/xen-common/bin/xen-toolstack').returns('/usr/sbin/xl')
|
20
18
|
end
|
21
19
|
|
22
20
|
it "lists the domains running on Xen0 with the 'xl' command" do
|
23
21
|
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xl list 2>/dev/null').returns(xen0_domains)
|
24
22
|
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
|
25
23
|
end
|
24
|
+
|
26
25
|
end
|
27
26
|
|
28
|
-
describe "and the
|
27
|
+
describe "and the xen-toolstack returns xm" do
|
29
28
|
before do
|
30
|
-
Facter::Util::Resolution.stubs(:
|
31
|
-
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xm list 2>/dev/null').never
|
29
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/lib/xen-common/bin/xen-toolstack').returns('/usr/sbin/xm')
|
32
30
|
end
|
33
31
|
|
34
|
-
it "
|
35
|
-
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/
|
32
|
+
it "lists the domains running on Xen0 with the 'xm' command" do
|
33
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xm list 2>/dev/null').returns(xen0_domains)
|
36
34
|
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
|
37
35
|
end
|
36
|
+
|
38
37
|
end
|
38
|
+
|
39
|
+
describe "and the xen-toolstack returns nil" do
|
40
|
+
before do
|
41
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/lib/xen-common/bin/xen-toolstack').returns(nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns nil" do
|
45
|
+
Facter::Util::Xendomains.get_domains.should == nil
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
39
50
|
end
|
40
51
|
|
41
|
-
describe "when
|
52
|
+
describe "when the xen-toolstack command is not present" do
|
42
53
|
before do
|
43
|
-
|
44
|
-
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xl list 2>/dev/null').never
|
54
|
+
File.expects(:file?).with('/usr/lib/xen-common/bin/xen-toolstack').returns false
|
45
55
|
end
|
46
56
|
|
47
|
-
describe "and the
|
57
|
+
describe "and the xl command is present" do
|
48
58
|
before do
|
49
|
-
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/
|
59
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xl').returns('/usr/sbin/xl')
|
50
60
|
end
|
51
61
|
|
52
|
-
|
53
|
-
|
54
|
-
|
62
|
+
describe "and the xm command is not present" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xm').returns(nil)
|
66
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xm list 2>/dev/null').never
|
67
|
+
end
|
68
|
+
|
69
|
+
it "lists the domains running on Xen0 with the 'xl' command" do
|
70
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xl list 2>/dev/null').returns(xen0_domains)
|
71
|
+
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "and the xm command is also present" do
|
76
|
+
before do
|
77
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xm').returns('/usr/bin/xm')
|
78
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xm list 2>/dev/null').never
|
79
|
+
end
|
80
|
+
|
81
|
+
it "prefers xl over xm" do
|
82
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xl list 2>/dev/null').returns(xen0_domains)
|
83
|
+
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "when xl is not present" do
|
89
|
+
before do
|
90
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xl').returns(nil)
|
91
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xl list 2>/dev/null').never
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "and the xm command is present" do
|
95
|
+
before do
|
96
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xm').returns('/usr/sbin/xm')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "lists the domains running on Xen0 with the 'xm' command" do
|
100
|
+
Facter::Util::Resolution.expects(:exec).with('/usr/sbin/xm list 2>/dev/null').returns(xen0_domains)
|
101
|
+
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
|
102
|
+
end
|
55
103
|
end
|
56
104
|
end
|
57
|
-
end
|
58
105
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
106
|
+
describe "neither xl or xm are present" do
|
107
|
+
it "returns nil" do
|
108
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xl').returns(nil)
|
109
|
+
Facter::Util::Resolution.stubs(:which).with('/usr/sbin/xm').returns(nil)
|
110
|
+
Facter::Util::Xendomains.get_domains.should == nil
|
111
|
+
end
|
64
112
|
end
|
65
113
|
end
|
66
114
|
end
|