facter 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of facter might be problematic. Click here for more details.
- data/CHANGELOG +11 -0
- data/LICENSE +1 -1
- data/conf/osx/createpackage.sh +1 -1
- data/conf/redhat/facter.spec +9 -6
- data/conf/solaris/pkginfo +1 -1
- data/install.rb +1 -1
- data/lib/facter.rb +2 -2
- data/lib/facter/architecture.rb +1 -2
- data/lib/facter/augeasversion.rb +1 -2
- data/lib/facter/domain.rb +3 -3
- data/lib/facter/hardwareisa.rb +1 -1
- data/lib/facter/ipaddress.rb +2 -2
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +2 -2
- data/lib/facter/manufacturer.rb +1 -1
- data/lib/facter/netmask.rb +0 -3
- data/lib/facter/network.rb +2 -3
- data/lib/facter/operatingsystem.rb +5 -2
- data/lib/facter/operatingsystemrelease.rb +3 -3
- data/lib/facter/osfamily.rb +1 -1
- data/lib/facter/processor.rb +2 -2
- data/lib/facter/selinux.rb +3 -3
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/uptime_days.rb +0 -1
- data/lib/facter/uptime_hours.rb +0 -1
- data/lib/facter/util/manufacturer.rb +2 -3
- data/lib/facter/util/processor.rb +3 -3
- data/lib/facter/util/resolution.rb +3 -3
- data/lib/facter/util/values.rb +1 -1
- data/lib/facter/virtual.rb +2 -2
- data/lib/facter/vlans.rb +1 -2
- data/lib/facter/xendomains.rb +0 -1
- data/spec/fixtures/unit/util/manufacturer/solaris_sunfire_v120_prtdiag +33 -0
- data/spec/fixtures/unit/util/manufacturer/solaris_t5220_prtdiag +136 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/architecture_spec.rb +40 -40
- data/spec/unit/facter_spec.rb +220 -220
- data/spec/unit/id_spec.rb +16 -16
- data/spec/unit/interfaces_spec.rb +6 -6
- data/spec/unit/memory_spec.rb +105 -105
- data/spec/unit/operatingsystem_spec.rb +72 -63
- data/spec/unit/operatingsystemrelease_spec.rb +44 -43
- data/spec/unit/processor_spec.rb +2 -2
- data/spec/unit/selinux_spec.rb +53 -53
- data/spec/unit/util/collection_spec.rb +183 -183
- data/spec/unit/util/confine_spec.rb +92 -92
- data/spec/unit/util/fact_spec.rb +96 -96
- data/spec/unit/util/ip_spec.rb +218 -218
- data/spec/unit/util/loader_spec.rb +193 -193
- data/spec/unit/util/macosx_spec.rb +63 -63
- data/spec/unit/util/manufacturer_spec.rb +124 -107
- data/spec/unit/util/resolution_spec.rb +235 -235
- data/spec/unit/util/virtual_spec.rb +167 -167
- data/spec/unit/util/vlans_spec.rb +6 -6
- data/spec/unit/virtual_spec.rb +246 -246
- data/spec/watchr.rb +1 -1
- metadata +6 -4
@@ -8,133 +8,133 @@ require 'facter/util/values'
|
|
8
8
|
include Facter::Util::Values
|
9
9
|
|
10
10
|
describe Facter::Util::Confine do
|
11
|
-
|
12
|
-
|
11
|
+
it "should require a fact name" do
|
12
|
+
Facter::Util::Confine.new("yay", true).fact.should == "yay"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should accept a value specified individually" do
|
16
|
+
Facter::Util::Confine.new("yay", "test").values.should == ["test"]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should accept multiple values specified at once" do
|
20
|
+
Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fail if no fact name is provided" do
|
24
|
+
lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fail if no values were provided" do
|
28
|
+
lambda { Facter::Util::Confine.new("yay") }.should raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a method for testing whether it matches" do
|
32
|
+
Facter::Util::Confine.new("yay", :test).should respond_to(:true?)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when evaluating" do
|
36
|
+
before do
|
37
|
+
@confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4])
|
38
|
+
@fact = mock 'fact'
|
39
|
+
Facter.stubs(:[]).returns @fact
|
13
40
|
end
|
14
41
|
|
15
|
-
it "should
|
16
|
-
|
17
|
-
end
|
42
|
+
it "should return false if the fact does not exist" do
|
43
|
+
Facter.expects(:[]).with("yay").returns nil
|
18
44
|
|
19
|
-
|
20
|
-
Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"]
|
45
|
+
@confine.true?.should be_false
|
21
46
|
end
|
22
47
|
|
23
|
-
it "should
|
24
|
-
|
25
|
-
end
|
48
|
+
it "should use the returned fact to get the value" do
|
49
|
+
Facter.expects(:[]).with("yay").returns @fact
|
26
50
|
|
27
|
-
|
28
|
-
lambda { Facter::Util::Confine.new("yay") }.should raise_error(ArgumentError)
|
29
|
-
end
|
51
|
+
@fact.expects(:value).returns nil
|
30
52
|
|
31
|
-
|
32
|
-
Facter::Util::Confine.new("yay", :test).should respond_to(:true?)
|
53
|
+
@confine.true?
|
33
54
|
end
|
34
55
|
|
35
|
-
|
36
|
-
|
37
|
-
@confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4])
|
38
|
-
@fact = mock 'fact'
|
39
|
-
Facter.stubs(:[]).returns @fact
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return false if the fact does not exist" do
|
43
|
-
Facter.expects(:[]).with("yay").returns nil
|
44
|
-
|
45
|
-
@confine.true?.should be_false
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should use the returned fact to get the value" do
|
49
|
-
Facter.expects(:[]).with("yay").returns @fact
|
56
|
+
it "should return false if the fact has no value" do
|
57
|
+
@fact.stubs(:value).returns nil
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
@confine.true?
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return false if the fact has no value" do
|
57
|
-
@fact.stubs(:value).returns nil
|
58
|
-
|
59
|
-
@confine.true?.should be_false
|
60
|
-
end
|
59
|
+
@confine.true?.should be_false
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
it "should return true if any of the provided values matches the fact's value" do
|
63
|
+
@fact.stubs(:value).returns "two"
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
@confine.true?.should be_true
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
it "should return true if any of the provided symbol values matches the fact's value" do
|
69
|
+
@fact.stubs(:value).returns :xy
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
@confine.true?.should be_true
|
72
|
+
end
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
it "should return true if any of the provided integer values matches the fact's value" do
|
75
|
+
@fact.stubs(:value).returns 1
|
76
76
|
|
77
|
-
|
78
|
-
|
77
|
+
@confine.true?.should be_true
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
80
|
+
it "should return true if any of the provided boolan values matches the fact's value" do
|
81
|
+
@fact.stubs(:value).returns true
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
@confine.true?.should be_true
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
it "should return true if any of the provided array values matches the fact's value" do
|
87
|
+
@fact.stubs(:value).returns [3,4]
|
88
88
|
|
89
|
-
|
90
|
-
|
89
|
+
@confine.true?.should be_true
|
90
|
+
end
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
it "should return true if any of the provided symbol values matches the fact's string value" do
|
93
|
+
@fact.stubs(:value).returns :one
|
94
94
|
|
95
|
-
|
96
|
-
|
95
|
+
@confine.true?.should be_true
|
96
|
+
end
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
it "should return true if any of the provided string values matches case-insensitive the fact's value" do
|
99
|
+
@fact.stubs(:value).returns "four"
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
@confine.true?.should be_true
|
102
|
+
end
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
it "should return true if any of the provided symbol values matches case-insensitive the fact's string value" do
|
105
|
+
@fact.stubs(:value).returns :four
|
106
106
|
|
107
|
-
|
108
|
-
|
107
|
+
@confine.true?.should be_true
|
108
|
+
end
|
109
109
|
|
110
|
-
|
111
|
-
|
110
|
+
it "should return true if any of the provided symbol values matches the fact's string value" do
|
111
|
+
@fact.stubs(:value).returns :Xy
|
112
112
|
|
113
|
-
|
114
|
-
|
113
|
+
@confine.true?.should be_true
|
114
|
+
end
|
115
115
|
|
116
|
-
|
117
|
-
|
116
|
+
it "should return false if none of the provided values matches the fact's value" do
|
117
|
+
@fact.stubs(:value).returns "three"
|
118
118
|
|
119
|
-
|
120
|
-
|
119
|
+
@confine.true?.should be_false
|
120
|
+
end
|
121
121
|
|
122
|
-
|
123
|
-
|
122
|
+
it "should return false if none of the provided integer values matches the fact's value" do
|
123
|
+
@fact.stubs(:value).returns 2
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
@confine.true?.should be_false
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
128
|
+
it "should return false if none of the provided boolan values matches the fact's value" do
|
129
|
+
@fact.stubs(:value).returns false
|
130
130
|
|
131
|
-
|
132
|
-
|
131
|
+
@confine.true?.should be_false
|
132
|
+
end
|
133
133
|
|
134
|
-
|
135
|
-
|
134
|
+
it "should return false if none of the provided array values matches the fact's value" do
|
135
|
+
@fact.stubs(:value).returns [1,2]
|
136
136
|
|
137
|
-
|
138
|
-
end
|
137
|
+
@confine.true?.should be_false
|
139
138
|
end
|
139
|
+
end
|
140
140
|
end
|
data/spec/unit/util/fact_spec.rb
CHANGED
@@ -5,125 +5,125 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
5
5
|
require 'facter/util/fact'
|
6
6
|
|
7
7
|
describe Facter::Util::Fact do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
it "should require a name" do
|
9
|
+
lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError)
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
it "should always downcase the name and convert it to a symbol" do
|
13
|
+
Facter::Util::Fact.new("YayNess").name.should == :yayness
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
it "should default to its name converted to a string as its ldapname" do
|
17
|
+
Facter::Util::Fact.new("YayNess").ldapname.should == "yayness"
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
it "should allow specifying the ldap name at initialization" do
|
21
|
+
Facter::Util::Fact.new("YayNess", :ldapname => "fooness").ldapname.should == "fooness"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should fail if an unknown option is provided" do
|
25
|
+
lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a method for adding resolution mechanisms" do
|
29
|
+
Facter::Util::Fact.new("yay").should respond_to(:add)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when adding resolution mechanisms" do
|
33
|
+
before do
|
34
|
+
@fact = Facter::Util::Fact.new("yay")
|
35
|
+
|
36
|
+
@resolution = mock 'resolution'
|
37
|
+
@resolution.stub_everything
|
23
38
|
|
24
|
-
it "should fail if an unknown option is provided" do
|
25
|
-
lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError)
|
26
39
|
end
|
27
40
|
|
28
|
-
it "should
|
29
|
-
|
41
|
+
it "should fail if no block is given" do
|
42
|
+
lambda { @fact.add }.should raise_error(ArgumentError)
|
30
43
|
end
|
31
44
|
|
32
|
-
|
33
|
-
|
34
|
-
|
45
|
+
it "should create a new resolution instance" do
|
46
|
+
Facter::Util::Resolution.expects(:new).returns @resolution
|
47
|
+
|
48
|
+
@fact.add { }
|
49
|
+
end
|
35
50
|
|
36
|
-
|
37
|
-
|
51
|
+
it "should instance_eval the passed block on the new resolution" do
|
52
|
+
@resolution.expects(:instance_eval)
|
38
53
|
|
39
|
-
|
54
|
+
Facter::Util::Resolution.stubs(:new).returns @resolution
|
40
55
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
56
|
+
@fact.add { }
|
57
|
+
end
|
44
58
|
|
45
|
-
|
46
|
-
|
59
|
+
it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do
|
60
|
+
r1 = stub 'r1', :weight => 1
|
61
|
+
r2 = stub 'r2', :weight => 2
|
62
|
+
r3 = stub 'r3', :weight => 0
|
63
|
+
Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3)
|
64
|
+
@fact.add { }
|
65
|
+
@fact.add { }
|
66
|
+
@fact.add { }
|
47
67
|
|
48
|
-
|
49
|
-
|
68
|
+
@fact.instance_variable_get("@resolves").should == [r2, r1, r3]
|
69
|
+
end
|
70
|
+
end
|
50
71
|
|
51
|
-
|
52
|
-
|
72
|
+
it "should be able to return a value" do
|
73
|
+
Facter::Util::Fact.new("yay").should respond_to(:value)
|
74
|
+
end
|
53
75
|
|
54
|
-
|
76
|
+
describe "when returning a value" do
|
77
|
+
before do
|
78
|
+
@fact = Facter::Util::Fact.new("yay")
|
79
|
+
end
|
55
80
|
|
56
|
-
|
57
|
-
|
81
|
+
it "should return nil if there are no resolutions" do
|
82
|
+
Facter::Util::Fact.new("yay").value.should be_nil
|
83
|
+
end
|
58
84
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
85
|
+
it "should return the first value returned by a resolution" do
|
86
|
+
r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true
|
87
|
+
r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true
|
88
|
+
r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true
|
89
|
+
Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3)
|
90
|
+
@fact.add { }
|
91
|
+
@fact.add { }
|
92
|
+
@fact.add { }
|
67
93
|
|
68
|
-
|
69
|
-
end
|
94
|
+
@fact.value.should == "yay"
|
70
95
|
end
|
71
96
|
|
72
|
-
it "should
|
73
|
-
|
97
|
+
it "should short-cut returning the value once one is found" do
|
98
|
+
r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true
|
99
|
+
r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for
|
100
|
+
Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2)
|
101
|
+
@fact.add { }
|
102
|
+
@fact.add { }
|
103
|
+
|
104
|
+
@fact.value
|
74
105
|
end
|
75
106
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
it "should return the first value returned by a resolution" do
|
86
|
-
r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true
|
87
|
-
r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true
|
88
|
-
r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true
|
89
|
-
Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3)
|
90
|
-
@fact.add { }
|
91
|
-
@fact.add { }
|
92
|
-
@fact.add { }
|
93
|
-
|
94
|
-
@fact.value.should == "yay"
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should short-cut returning the value once one is found" do
|
98
|
-
r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true
|
99
|
-
r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for
|
100
|
-
Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2)
|
101
|
-
@fact.add { }
|
102
|
-
@fact.add { }
|
103
|
-
|
104
|
-
@fact.value
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should skip unsuitable resolutions" do
|
108
|
-
r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for'
|
109
|
-
r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true
|
110
|
-
Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2)
|
111
|
-
@fact.add { }
|
112
|
-
@fact.add { }
|
113
|
-
|
114
|
-
@fact.value.should == "yay"
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return nil if the value is the empty string" do
|
118
|
-
r1 = stub 'r1', :suitable? => true, :value => ""
|
119
|
-
Facter::Util::Resolution.expects(:new).returns r1
|
120
|
-
@fact.add { }
|
121
|
-
|
122
|
-
@fact.value.should be_nil
|
123
|
-
end
|
107
|
+
it "should skip unsuitable resolutions" do
|
108
|
+
r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for'
|
109
|
+
r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true
|
110
|
+
Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2)
|
111
|
+
@fact.add { }
|
112
|
+
@fact.add { }
|
113
|
+
|
114
|
+
@fact.value.should == "yay"
|
124
115
|
end
|
125
116
|
|
126
|
-
it "should
|
127
|
-
|
117
|
+
it "should return nil if the value is the empty string" do
|
118
|
+
r1 = stub 'r1', :suitable? => true, :value => ""
|
119
|
+
Facter::Util::Resolution.expects(:new).returns r1
|
120
|
+
@fact.add { }
|
121
|
+
|
122
|
+
@fact.value.should be_nil
|
128
123
|
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should have a method for flushing the cached fact" do
|
127
|
+
Facter::Util::Fact.new(:foo).should respond_to(:flush)
|
128
|
+
end
|
129
129
|
end
|
data/spec/unit/util/ip_spec.rb
CHANGED
@@ -5,295 +5,295 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
5
5
|
require 'facter/util/ip'
|
6
6
|
|
7
7
|
describe Facter::Util::IP do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
before :each do
|
9
|
+
Facter::Util::Config.stubs(:is_windows?).returns(false)
|
10
|
+
end
|
11
|
+
|
12
|
+
[:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd", :windows].each do |platform|
|
13
|
+
it "should be supported on #{platform}" do
|
14
|
+
Facter::Util::Config.stubs(:is_windows?).returns(platform == :windows)
|
15
|
+
Facter::Util::IP.supported_platforms.should be_include(platform)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return a list of interfaces" do
|
20
|
+
Facter::Util::IP.should respond_to(:get_interfaces)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return an empty list of interfaces on an unknown kernel" do
|
24
|
+
Facter.stubs(:value).returns("UnknownKernel")
|
25
|
+
Facter::Util::IP.get_interfaces().should == []
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a list with a single interface and the loopback interface on Linux with a single interface" do
|
29
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface'
|
30
|
+
linux_ifconfig = File.read(sample_output_file)
|
31
|
+
Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig)
|
32
|
+
Facter::Util::IP.get_interfaces().should == ["eth0", "lo"]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return a list two interfaces on Darwin with two interfaces" do
|
36
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/darwin_ifconfig_all_with_multiple_interfaces'
|
37
|
+
darwin_ifconfig = File.read(sample_output_file)
|
38
|
+
Facter::Util::IP.stubs(:get_all_interface_output).returns(darwin_ifconfig)
|
39
|
+
Facter::Util::IP.get_interfaces().should == ["lo0", "en0"]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return a list two interfaces on Solaris with two interfaces multiply reporting" do
|
43
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/solaris_ifconfig_all_with_multiple_interfaces'
|
44
|
+
solaris_ifconfig = File.read(sample_output_file)
|
45
|
+
Facter::Util::IP.stubs(:get_all_interface_output).returns(solaris_ifconfig)
|
46
|
+
Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return a list three interfaces on HP-UX with three interfaces multiply reporting" do
|
50
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/hpux_netstat_all_interfaces'
|
51
|
+
hpux_netstat = File.read(sample_output_file)
|
52
|
+
Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
|
53
|
+
Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return a list of six interfaces on a GNU/kFreeBSD with six interfaces" do
|
57
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/debian_kfreebsd_ifconfig'
|
58
|
+
kfreebsd_ifconfig = File.read(sample_output_file)
|
59
|
+
Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig)
|
60
|
+
Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return a list of only connected interfaces on Windows" do
|
64
|
+
Facter.fact(:kernel).stubs(:value).returns("windows")
|
65
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/windows_netsh_all_interfaces'
|
66
|
+
windows_netsh = File.read(sample_output_file)
|
67
|
+
Facter::Util::IP.stubs(:get_all_interface_output).returns(windows_netsh)
|
68
|
+
Facter::Util::IP.get_interfaces().should == ["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"]
|
69
|
+
end
|
22
70
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
71
|
+
it "should return a value for a specific interface" do
|
72
|
+
Facter::Util::IP.should respond_to(:get_interface_value)
|
73
|
+
end
|
27
74
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Facter::Util::IP.get_interfaces().should == ["eth0", "lo"]
|
33
|
-
end
|
75
|
+
it "should not return interface information for unsupported platforms" do
|
76
|
+
Facter.stubs(:value).with(:kernel).returns("bleah")
|
77
|
+
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == []
|
78
|
+
end
|
34
79
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
Facter::Util::IP.stubs(:get_all_interface_output).returns(darwin_ifconfig)
|
39
|
-
Facter::Util::IP.get_interfaces().should == ["lo0", "en0"]
|
40
|
-
end
|
80
|
+
it "should return ipaddress information for Solaris" do
|
81
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
|
82
|
+
solaris_ifconfig_interface = File.read(sample_output_file)
|
41
83
|
|
42
|
-
|
43
|
-
|
44
|
-
solaris_ifconfig = File.read(sample_output_file)
|
45
|
-
Facter::Util::IP.stubs(:get_all_interface_output).returns(solaris_ifconfig)
|
46
|
-
Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"]
|
47
|
-
end
|
84
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
|
85
|
+
Facter.stubs(:value).with(:kernel).returns("SunOS")
|
48
86
|
|
49
|
-
|
50
|
-
|
51
|
-
hpux_netstat = File.read(sample_output_file)
|
52
|
-
Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
|
53
|
-
Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
|
54
|
-
end
|
87
|
+
Facter::Util::IP.get_interface_value("e1000g0", "ipaddress").should == "172.16.15.138"
|
88
|
+
end
|
55
89
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig)
|
60
|
-
Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"]
|
61
|
-
end
|
90
|
+
it "should return netmask information for Solaris" do
|
91
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
|
92
|
+
solaris_ifconfig_interface = File.read(sample_output_file)
|
62
93
|
|
63
|
-
|
64
|
-
|
65
|
-
sample_output_file = File.dirname(__FILE__) + '/../data/windows_netsh_all_interfaces'
|
66
|
-
windows_netsh = File.read(sample_output_file)
|
67
|
-
Facter::Util::IP.stubs(:get_all_interface_output).returns(windows_netsh)
|
68
|
-
Facter::Util::IP.get_interfaces().should == ["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"]
|
69
|
-
end
|
94
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
|
95
|
+
Facter.stubs(:value).with(:kernel).returns("SunOS")
|
70
96
|
|
71
|
-
|
72
|
-
|
73
|
-
end
|
97
|
+
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
|
98
|
+
end
|
74
99
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
100
|
+
it "should return calculated network information for Solaris" do
|
101
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
|
102
|
+
solaris_ifconfig_interface = File.read(sample_output_file)
|
79
103
|
|
80
|
-
|
81
|
-
|
82
|
-
solaris_ifconfig_interface = File.read(sample_output_file)
|
104
|
+
Facter::Util::IP.stubs(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
|
105
|
+
Facter.stubs(:value).with(:kernel).returns("SunOS")
|
83
106
|
|
84
|
-
|
85
|
-
|
107
|
+
Facter::Util::IP.get_network_value("e1000g0").should == "172.16.15.0"
|
108
|
+
end
|
86
109
|
|
87
|
-
|
88
|
-
|
110
|
+
it "should return ipaddress information for HP-UX" do
|
111
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
|
112
|
+
hpux_ifconfig_interface = File.read(sample_output_file)
|
89
113
|
|
90
|
-
|
91
|
-
|
92
|
-
solaris_ifconfig_interface = File.read(sample_output_file)
|
114
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
|
115
|
+
Facter.stubs(:value).with(:kernel).returns("HP-UX")
|
93
116
|
|
94
|
-
|
95
|
-
|
117
|
+
Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == "168.24.80.71"
|
118
|
+
end
|
96
119
|
|
97
|
-
|
98
|
-
|
120
|
+
it "should return macaddress information for HP-UX" do
|
121
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
|
122
|
+
hpux_ifconfig_interface = File.read(sample_output_file)
|
99
123
|
|
100
|
-
|
101
|
-
|
102
|
-
solaris_ifconfig_interface = File.read(sample_output_file)
|
124
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
|
125
|
+
Facter.stubs(:value).with(:kernel).returns("HP-UX")
|
103
126
|
|
104
|
-
|
105
|
-
|
127
|
+
Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7"
|
128
|
+
end
|
106
129
|
|
107
|
-
|
108
|
-
|
130
|
+
it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do
|
131
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig"
|
132
|
+
kfreebsd_ifconfig = File.read(sample_output_file)
|
109
133
|
|
110
|
-
|
111
|
-
|
112
|
-
hpux_ifconfig_interface = File.read(sample_output_file)
|
134
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("em0").returns(kfreebsd_ifconfig)
|
135
|
+
Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
|
113
136
|
|
114
|
-
|
115
|
-
|
137
|
+
Facter::Util::IP.get_interface_value("em0", "macaddress").should == "0:11:a:59:67:90"
|
138
|
+
end
|
116
139
|
|
117
|
-
|
118
|
-
|
140
|
+
it "should return netmask information for HP-UX" do
|
141
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
|
142
|
+
hpux_ifconfig_interface = File.read(sample_output_file)
|
119
143
|
|
120
|
-
|
121
|
-
|
122
|
-
hpux_ifconfig_interface = File.read(sample_output_file)
|
144
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
|
145
|
+
Facter.stubs(:value).with(:kernel).returns("HP-UX")
|
123
146
|
|
124
|
-
|
125
|
-
|
147
|
+
Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0"
|
148
|
+
end
|
126
149
|
|
127
|
-
|
128
|
-
|
150
|
+
it "should return calculated network information for HP-UX" do
|
151
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
|
152
|
+
hpux_ifconfig_interface = File.read(sample_output_file)
|
129
153
|
|
130
|
-
|
131
|
-
|
132
|
-
kfreebsd_ifconfig = File.read(sample_output_file)
|
154
|
+
Facter::Util::IP.stubs(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
|
155
|
+
Facter.stubs(:value).with(:kernel).returns("HP-UX")
|
133
156
|
|
134
|
-
|
135
|
-
|
157
|
+
Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0"
|
158
|
+
end
|
136
159
|
|
137
|
-
|
138
|
-
|
160
|
+
it "should return interface information for FreeBSD supported via an alias" do
|
161
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig"
|
162
|
+
ifconfig_interface = File.read(sample_output_file)
|
139
163
|
|
140
|
-
|
141
|
-
|
142
|
-
hpux_ifconfig_interface = File.read(sample_output_file)
|
164
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface)
|
165
|
+
Facter.stubs(:value).with(:kernel).returns("FreeBSD")
|
143
166
|
|
144
|
-
|
145
|
-
|
167
|
+
Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c"
|
168
|
+
end
|
146
169
|
|
147
|
-
|
148
|
-
|
170
|
+
it "should return macaddress information for OS X" do
|
171
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
|
172
|
+
ifconfig_interface = File.read(sample_output_file)
|
149
173
|
|
150
|
-
|
151
|
-
|
152
|
-
hpux_ifconfig_interface = File.read(sample_output_file)
|
174
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface)
|
175
|
+
Facter.stubs(:value).with(:kernel).returns("Darwin")
|
153
176
|
|
154
|
-
|
155
|
-
|
177
|
+
Facter::Util::IP.get_interface_value("en1", "macaddress").should == "00:1b:63:ae:02:66"
|
178
|
+
end
|
156
179
|
|
157
|
-
|
158
|
-
|
180
|
+
it "should return all interfaces correctly on OS X" do
|
181
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
|
182
|
+
ifconfig_interface = File.read(sample_output_file)
|
159
183
|
|
160
|
-
|
161
|
-
|
162
|
-
ifconfig_interface = File.read(sample_output_file)
|
184
|
+
Facter::Util::IP.expects(:get_all_interface_output).returns(ifconfig_interface)
|
185
|
+
Facter.stubs(:value).with(:kernel).returns("Darwin")
|
163
186
|
|
164
|
-
|
165
|
-
|
187
|
+
Facter::Util::IP.get_interfaces().should == ["lo0", "gif0", "stf0", "en0", "fw0", "en1", "vmnet8", "vmnet1"]
|
188
|
+
end
|
166
189
|
|
167
|
-
|
168
|
-
|
190
|
+
it "should return a human readable netmask on Solaris" do
|
191
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
|
192
|
+
solaris_ifconfig_interface = File.read(sample_output_file)
|
169
193
|
|
170
|
-
|
171
|
-
|
172
|
-
ifconfig_interface = File.read(sample_output_file)
|
194
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
|
195
|
+
Facter.stubs(:value).with(:kernel).returns("SunOS")
|
173
196
|
|
174
|
-
|
175
|
-
|
197
|
+
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
|
198
|
+
end
|
176
199
|
|
177
|
-
|
178
|
-
|
200
|
+
it "should return a human readable netmask on HP-UX" do
|
201
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
|
202
|
+
hpux_ifconfig_interface = File.read(sample_output_file)
|
179
203
|
|
180
|
-
|
181
|
-
|
182
|
-
ifconfig_interface = File.read(sample_output_file)
|
204
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
|
205
|
+
Facter.stubs(:value).with(:kernel).returns("HP-UX")
|
183
206
|
|
184
|
-
|
185
|
-
|
207
|
+
Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0"
|
208
|
+
end
|
186
209
|
|
187
|
-
|
188
|
-
|
210
|
+
it "should return a human readable netmask on Darwin" do
|
211
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface"
|
189
212
|
|
190
|
-
|
191
|
-
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
|
192
|
-
solaris_ifconfig_interface = File.read(sample_output_file)
|
213
|
+
darwin_ifconfig_interface = File.read(sample_output_file)
|
193
214
|
|
194
|
-
|
195
|
-
|
215
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface)
|
216
|
+
Facter.stubs(:value).with(:kernel).returns("Darwin")
|
196
217
|
|
197
|
-
|
198
|
-
|
218
|
+
Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0"
|
219
|
+
end
|
199
220
|
|
200
|
-
|
201
|
-
|
202
|
-
hpux_ifconfig_interface = File.read(sample_output_file)
|
221
|
+
it "should return a human readable netmask on GNU/kFreeBSD" do
|
222
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig"
|
203
223
|
|
204
|
-
|
205
|
-
Facter.stubs(:value).with(:kernel).returns("HP-UX")
|
224
|
+
kfreebsd_ifconfig = File.read(sample_output_file)
|
206
225
|
|
207
|
-
|
208
|
-
|
226
|
+
Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig)
|
227
|
+
Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
|
209
228
|
|
210
|
-
|
211
|
-
|
229
|
+
Facter::Util::IP.get_interface_value("em1", "netmask").should == "255.255.255.0"
|
230
|
+
end
|
212
231
|
|
213
|
-
|
232
|
+
it "should not get bonding master on interface aliases" do
|
233
|
+
Facter.stubs(:value).with(:kernel).returns("Linux")
|
214
234
|
|
215
|
-
|
216
|
-
|
235
|
+
Facter::Util::IP.get_bonding_master("eth0:1").should be_nil
|
236
|
+
end
|
217
237
|
|
218
|
-
|
238
|
+
[:freebsd, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform|
|
239
|
+
it "should require conversion from hex on #{platform}" do
|
240
|
+
Facter::Util::IP.convert_from_hex?(platform).should == true
|
219
241
|
end
|
242
|
+
end
|
220
243
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
kfreebsd_ifconfig = File.read(sample_output_file)
|
225
|
-
|
226
|
-
Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig)
|
227
|
-
Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD")
|
228
|
-
|
229
|
-
Facter::Util::IP.get_interface_value("em1", "netmask").should == "255.255.255.0"
|
244
|
+
[:windows].each do |platform|
|
245
|
+
it "should not require conversion from hex on #{platform}" do
|
246
|
+
Facter::Util::IP.convert_from_hex?(platform).should be_false
|
230
247
|
end
|
248
|
+
end
|
231
249
|
|
232
|
-
|
233
|
-
|
250
|
+
it "should return an arp address on Linux" do
|
251
|
+
Facter.stubs(:value).with(:kernel).returns("Linux")
|
234
252
|
|
235
|
-
|
236
|
-
|
253
|
+
Facter::Util::IP.expects(:get_arp_value).with("eth0").returns("00:00:0c:9f:f0:04")
|
254
|
+
Facter::Util::IP.get_arp_value("eth0").should == "00:00:0c:9f:f0:04"
|
255
|
+
end
|
237
256
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
end
|
257
|
+
describe "on Windows" do
|
258
|
+
before :each do
|
259
|
+
Facter.stubs(:value).with(:kernel).returns("windows")
|
242
260
|
end
|
243
261
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
end
|
248
|
-
end
|
262
|
+
it "should return ipaddress information" do
|
263
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
|
264
|
+
windows_netsh = File.read(sample_output_file)
|
249
265
|
|
250
|
-
|
251
|
-
Facter.stubs(:value).with(:kernel).returns("Linux")
|
266
|
+
Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh)
|
252
267
|
|
253
|
-
|
254
|
-
Facter::Util::IP.get_arp_value("eth0").should == "00:00:0c:9f:f0:04"
|
268
|
+
Facter::Util::IP.get_interface_value("Local Area Connection", "ipaddress").should == "172.16.138.216"
|
255
269
|
end
|
256
270
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should return ipaddress information" do
|
263
|
-
sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
|
264
|
-
windows_netsh = File.read(sample_output_file)
|
271
|
+
it "should return a human readable netmask" do
|
272
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
|
273
|
+
windows_netsh = File.read(sample_output_file)
|
265
274
|
|
266
|
-
|
275
|
+
Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh)
|
267
276
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
it "should return a human readable netmask" do
|
272
|
-
sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
|
273
|
-
windows_netsh = File.read(sample_output_file)
|
274
|
-
|
275
|
-
Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh)
|
276
|
-
|
277
|
-
Facter::Util::IP.get_interface_value("Local Area Connection", "netmask").should == "255.255.255.0"
|
278
|
-
end
|
277
|
+
Facter::Util::IP.get_interface_value("Local Area Connection", "netmask").should == "255.255.255.0"
|
278
|
+
end
|
279
279
|
|
280
|
-
|
281
|
-
|
282
|
-
|
280
|
+
it "should return network information" do
|
281
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface"
|
282
|
+
windows_netsh = File.read(sample_output_file)
|
283
283
|
|
284
|
-
|
285
|
-
|
284
|
+
Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh)
|
285
|
+
Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh)
|
286
286
|
|
287
|
-
|
288
|
-
|
287
|
+
Facter::Util::IP.get_network_value("Local Area Connection").should == "172.16.138.0"
|
288
|
+
end
|
289
289
|
|
290
|
-
|
291
|
-
|
292
|
-
|
290
|
+
it "should return ipaddress6 information" do
|
291
|
+
sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface6"
|
292
|
+
windows_netsh = File.read(sample_output_file)
|
293
293
|
|
294
|
-
|
294
|
+
Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Teredo Tunneling Pseudo-Interface", "ipaddress6").returns(windows_netsh)
|
295
295
|
|
296
|
-
|
297
|
-
end
|
296
|
+
Facter::Util::IP.get_interface_value("Teredo Tunneling Pseudo-Interface", "ipaddress6").should == "2001:0:4137:9e76:2087:77a:53ef:7527"
|
298
297
|
end
|
298
|
+
end
|
299
299
|
end
|