facter 2.0.2-universal-darwin → 2.1.0-universal-darwin
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.
- checksums.yaml +4 -4
- data/Gemfile +14 -0
- data/ext/project_data.yaml +9 -6
- data/lib/facter/core/execution/base.rb +3 -3
- data/lib/facter/core/suitable.rb +1 -5
- data/lib/facter/dhcp_servers.rb +39 -0
- data/lib/facter/ec2.rb +33 -26
- data/lib/facter/ec2/rest.rb +130 -0
- data/lib/facter/fqdn.rb +2 -0
- data/lib/facter/gce.rb +16 -0
- data/lib/facter/gce/metadata.rb +87 -0
- data/lib/facter/kernelmajversion.rb +8 -0
- data/lib/facter/kernelrelease.rb +8 -0
- data/lib/facter/memory.rb +21 -15
- data/lib/facter/netmask.rb +1 -1
- data/lib/facter/operatingsystem.rb +20 -0
- data/lib/facter/operatingsystemmajrelease.rb +2 -1
- data/lib/facter/operatingsystemrelease.rb +19 -0
- data/lib/facter/osfamily.rb +3 -1
- data/lib/facter/partitions.rb +35 -0
- data/lib/facter/physicalprocessorcount.rb +9 -0
- data/lib/facter/processor.rb +25 -25
- data/lib/facter/util/config.rb +3 -1
- data/lib/facter/util/dhcp_servers.rb +43 -0
- data/lib/facter/util/ec2.rb +5 -0
- data/lib/facter/util/formatter.rb +2 -1
- data/lib/facter/util/ip.rb +1 -1
- data/lib/facter/util/loader.rb +10 -1
- data/lib/facter/util/manufacturer.rb +15 -16
- data/lib/facter/util/memory.rb +12 -12
- data/lib/facter/util/netmask.rb +1 -1
- data/lib/facter/util/operatingsystem.rb +21 -0
- data/lib/facter/util/partitions.rb +41 -0
- data/lib/facter/util/partitions/linux.rb +65 -0
- data/lib/facter/util/posix.rb +16 -0
- data/lib/facter/util/processor.rb +8 -10
- data/lib/facter/util/resolution.rb +4 -0
- data/lib/facter/util/values.rb +29 -0
- data/lib/facter/util/virtual.rb +32 -3
- data/lib/facter/util/windows_root.rb +2 -32
- data/lib/facter/version.rb +1 -1
- data/lib/facter/virtual.rb +53 -12
- data/spec/fixtures/ifconfig/openbsd_bridge_rules +11 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_devices +4 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_devices_disconnected +4 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_dhcp +36 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_static +24 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_dhcp +49 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_static +37 -0
- data/spec/fixtures/unit/dhcp_servers/route +3 -0
- data/spec/fixtures/unit/dhcp_servers/route_nogw +1 -0
- data/spec/fixtures/unit/ec2/rest/meta-data/root +20 -0
- data/spec/fixtures/unit/gce/metadata/metadata.json +69 -0
- data/spec/fixtures/unit/kernelrelease/openbsd-5.3 +2 -0
- data/spec/fixtures/unit/kernelrelease/openbsd-5.3-current +3 -0
- data/spec/fixtures/unit/memory/aix-svmon +9 -0
- data/spec/fixtures/unit/memory/aix-swap_l +2 -0
- data/spec/fixtures/unit/memory/darwin-swapinfo-multiple +3 -0
- data/spec/fixtures/unit/memory/darwin-swapinfo-single +2 -0
- data/spec/fixtures/unit/memory/darwin-vm_stat +13 -0
- data/spec/fixtures/unit/memory/dragonfly-vmstat +3 -0
- data/spec/fixtures/unit/memory/freebsd-vmstat +3 -0
- data/spec/fixtures/unit/memory/linux-proc_meminfo +10 -0
- data/spec/fixtures/unit/memory/openbsd-vmstat +3 -0
- data/spec/fixtures/unit/memory/smartos_zone_swap_l-single +2 -0
- data/spec/fixtures/unit/memory/solaris-prtconf +4 -0
- data/spec/fixtures/unit/memory/solaris-swap_l-multiple +3 -0
- data/spec/fixtures/unit/memory/solaris-swap_l-single +2 -0
- data/spec/fixtures/unit/memory/solaris-vmstat +3 -0
- data/spec/fixtures/unit/netmask/ifconfig_aix_7.txt +3 -0
- data/spec/fixtures/unit/util/dhcp_servers/route +3 -0
- data/spec/fixtures/unit/util/dhcp_servers/route_nogw +1 -0
- data/spec/fixtures/unit/util/manufacturer/smartos_smbios +533 -0
- data/spec/fixtures/unit/util/operatingsystem/cumuluslinux.txt +8 -0
- data/spec/fixtures/unit/util/operatingsystem/redhat-7.txt +12 -0
- data/spec/fixtures/unit/util/operatingsystem/sabayon.txt +7 -0
- data/spec/fixtures/unit/util/operatingsystem/wheezy.txt +9 -0
- data/spec/fixtures/unit/util/partitions/partitions/mount +9 -0
- data/spec/fixtures/virtual/proc_1_cgroup/in_a_container +9 -0
- data/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container +8 -0
- data/spec/fixtures/virtual/proc_1_cgroup/not_in_a_container +9 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/core/execution/base_spec.rb +3 -5
- data/spec/unit/core/execution/posix_spec.rb +2 -2
- data/spec/unit/core/suitable_spec.rb +10 -0
- data/spec/unit/dhcp_servers_spec.rb +152 -0
- data/spec/unit/ec2/rest_spec.rb +145 -0
- data/spec/unit/ec2_spec.rb +87 -147
- data/spec/unit/fqdn_spec.rb +16 -0
- data/spec/unit/gce/metadata_spec.rb +49 -0
- data/spec/unit/gce_spec.rb +34 -0
- data/spec/unit/interfaces_spec.rb +9 -9
- data/spec/unit/kernelmajversion_spec.rb +14 -9
- data/spec/unit/kernelrelease_spec.rb +16 -0
- data/spec/unit/macaddress_spec.rb +12 -0
- data/spec/unit/memory_spec.rb +53 -122
- data/spec/unit/netmask_spec.rb +11 -0
- data/spec/unit/operatingsystem_spec.rb +19 -0
- data/spec/unit/operatingsystemmajrelease_spec.rb +1 -1
- data/spec/unit/operatingsystemrelease_spec.rb +8 -0
- data/spec/unit/osfamily_spec.rb +62 -0
- data/spec/unit/partitions_spec.rb +48 -0
- data/spec/unit/physicalprocessorcount_spec.rb +9 -0
- data/spec/unit/processor_spec.rb +15 -7
- data/spec/unit/util/config_spec.rb +13 -0
- data/spec/unit/util/dhcp_servers_spec.rb +63 -0
- data/spec/unit/util/ec2_spec.rb +4 -0
- data/spec/unit/util/formatter_spec.rb +50 -0
- data/spec/unit/util/loader_spec.rb +4 -4
- data/spec/unit/util/macosx_spec.rb +3 -2
- data/spec/unit/util/manufacturer_spec.rb +44 -0
- data/spec/unit/util/operatingsystem_spec.rb +92 -0
- data/spec/unit/util/partitions/partitions_spec.rb +67 -0
- data/spec/unit/util/partitions_spec.rb +19 -0
- data/spec/unit/util/posix_spec.rb +11 -0
- data/spec/unit/util/values_spec.rb +40 -0
- data/spec/unit/util/virtual_spec.rb +72 -2
- data/spec/unit/virtual_spec.rb +67 -18
- metadata +116 -4
- data/spec/fixtures/unit/util/loader/nosuchfact.rb +0 -1
data/spec/unit/ec2_spec.rb
CHANGED
@@ -1,187 +1,127 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
|
-
require 'facter/
|
5
|
-
|
6
|
-
describe "ec2 facts" do
|
7
|
-
# This is the standard prefix for making an API call in EC2 (or fake)
|
8
|
-
# environments.
|
9
|
-
let(:api_prefix) { "http://169.254.169.254" }
|
10
|
-
|
11
|
-
describe "when running on ec2" do
|
12
|
-
before :each do
|
13
|
-
# This is an ec2 instance, not a eucalyptus instance
|
14
|
-
Facter::Util::EC2.stubs(:has_euca_mac?).returns(false)
|
15
|
-
Facter::Util::EC2.stubs(:has_openstack_mac?).returns(false)
|
16
|
-
Facter::Util::EC2.stubs(:has_ec2_arp?).returns(true)
|
17
|
-
|
18
|
-
# Assume we can connect
|
19
|
-
Facter::Util::EC2.stubs(:can_connect?).returns(true)
|
20
|
-
end
|
2
|
+
require 'facter/ec2/rest'
|
21
3
|
|
22
|
-
|
23
|
-
|
24
|
-
with("#{api_prefix}/2008-02-01/meta-data/").
|
25
|
-
at_least_once.returns(StringIO.new("foo"))
|
4
|
+
describe "ec2_metadata" do
|
5
|
+
let(:querier) { stub('EC2 metadata querier') }
|
26
6
|
|
27
|
-
|
28
|
-
|
29
|
-
at_least_once.returns(StringIO.new("bar"))
|
7
|
+
before do
|
8
|
+
Facter::EC2::Metadata.stubs(:new).returns querier
|
30
9
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
10
|
+
# Prevent flattened facts from forcing evaluation of the ec2 metadata fact
|
11
|
+
Facter.stubs(:value).with(:ec2_metadata)
|
12
|
+
Facter.collection.internal_loader.load(:ec2)
|
13
|
+
Facter.unstub(:value)
|
14
|
+
end
|
35
15
|
|
36
|
-
|
37
|
-
Object.any_instance.expects(:open).
|
38
|
-
with("#{api_prefix}/2008-02-01/meta-data/").
|
39
|
-
at_least_once.returns(StringIO.new("foo"))
|
16
|
+
subject { Facter.fact(:ec2_metadata).resolution(:rest) }
|
40
17
|
|
41
|
-
|
42
|
-
|
43
|
-
|
18
|
+
it "is unsuitable if the virtual fact is not xen" do
|
19
|
+
querier.stubs(:reachable?).returns false
|
20
|
+
Facter.fact(:virtual).stubs(:value).returns "kvm"
|
21
|
+
expect(subject).to_not be_suitable
|
22
|
+
end
|
44
23
|
|
45
|
-
|
24
|
+
it "is unsuitable if ec2 endpoint is not reachable" do
|
25
|
+
Facter.fact(:virtual).stubs(:value).returns "xen"
|
26
|
+
querier.stubs(:reachable?).returns false
|
27
|
+
expect(subject).to_not be_suitable
|
28
|
+
end
|
46
29
|
|
47
|
-
|
30
|
+
describe "when the ec2 endpoint is reachable" do
|
31
|
+
before do
|
32
|
+
querier.stubs(:reachable?).returns true
|
48
33
|
end
|
49
34
|
|
50
|
-
it "
|
51
|
-
|
52
|
-
|
53
|
-
at_least_once.returns(StringIO.new("foo/"))
|
54
|
-
|
55
|
-
Object.any_instance.expects(:open).
|
56
|
-
with("#{api_prefix}/2008-02-01/meta-data/foo/").
|
57
|
-
at_least_once.returns(StringIO.new("bar"))
|
35
|
+
it "is suitable if the virtual fact is xen" do
|
36
|
+
Facter.fact(:virtual).stubs(:value).returns "xen"
|
37
|
+
subject.suitable?
|
58
38
|
|
59
|
-
|
60
|
-
with("#{api_prefix}/2008-02-01/meta-data/foo/bar").
|
61
|
-
at_least_once.returns(StringIO.new("baz"))
|
62
|
-
|
63
|
-
Facter.collection.internal_loader.load(:ec2)
|
64
|
-
|
65
|
-
Facter.fact(:ec2_foo_bar).value.should == "baz"
|
39
|
+
expect(subject).to be_suitable
|
66
40
|
end
|
67
41
|
|
68
|
-
it "
|
69
|
-
|
70
|
-
|
71
|
-
with("#{api_prefix}/2008-02-01/meta-data/").
|
72
|
-
at_least_once.returns(StringIO.new(""))
|
73
|
-
|
74
|
-
Facter::Util::EC2.stubs(:read_uri).
|
75
|
-
with("#{api_prefix}/latest/user-data/").
|
76
|
-
returns("test")
|
77
|
-
|
78
|
-
Facter.collection.internal_loader.load(:ec2)
|
79
|
-
Facter.fact(:ec2_userdata).value.should == ["test"]
|
42
|
+
it "is suitable if the virtual fact is xenu" do
|
43
|
+
Facter.fact(:virtual).stubs(:value).returns "xenu"
|
44
|
+
expect(subject).to be_suitable
|
80
45
|
end
|
81
46
|
end
|
82
47
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
Facter::Util::EC2.stubs(:has_ec2_arp?).returns(false)
|
48
|
+
it "resolves the value by recursively querying the rest endpoint" do
|
49
|
+
querier.expects(:fetch).returns({"hello" => "world"})
|
50
|
+
expect(subject.value).to eq({"hello" => "world"})
|
51
|
+
end
|
52
|
+
end
|
89
53
|
|
90
|
-
|
91
|
-
|
92
|
-
end
|
54
|
+
describe "ec2_userdata" do
|
55
|
+
let(:querier) { stub('EC2 metadata querier') }
|
93
56
|
|
94
|
-
|
95
|
-
|
96
|
-
Object.any_instance.expects(:open).\
|
97
|
-
with("#{api_prefix}/2008-02-01/meta-data/").\
|
98
|
-
at_least_once.returns(StringIO.new(""))
|
57
|
+
before do
|
58
|
+
Facter::EC2::Userdata.stubs(:new).returns querier
|
99
59
|
|
100
|
-
|
101
|
-
|
102
|
-
|
60
|
+
# Prevent flattened facts from forcing evaluation of the ec2 metadata fact
|
61
|
+
Facter.stubs(:value).with(:ec2_metadata)
|
62
|
+
Facter.collection.internal_loader.load(:ec2)
|
63
|
+
Facter.unstub(:value)
|
64
|
+
end
|
103
65
|
|
104
|
-
|
105
|
-
Facter.collection.internal_loader.load(:ec2)
|
66
|
+
subject { Facter.fact(:ec2_userdata).resolution(:rest) }
|
106
67
|
|
107
|
-
|
108
|
-
|
68
|
+
it "is unsuitable if the virtual fact is not xen" do
|
69
|
+
querier.stubs(:reachable?).returns(true)
|
70
|
+
Facter.fact(:virtual).stubs(:value).returns "kvm"
|
71
|
+
expect(subject).to_not be_suitable
|
109
72
|
end
|
110
73
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
Facter::Util::EC2.stubs(:has_ec2_arp?).returns(false)
|
74
|
+
it "is unsuitable if ec2 endpoint is not reachable" do
|
75
|
+
Facter.fact(:virtual).stubs(:value).returns "xen"
|
76
|
+
querier.stubs(:reachable?).returns false
|
77
|
+
expect(subject).to_not be_suitable
|
78
|
+
end
|
117
79
|
|
118
|
-
|
119
|
-
|
80
|
+
describe "when the ec2 endpoint is reachable" do
|
81
|
+
before do
|
82
|
+
querier.stubs(:reachable?).returns true
|
120
83
|
end
|
121
84
|
|
122
|
-
it "
|
123
|
-
|
124
|
-
|
125
|
-
with("#{api_prefix}/2008-02-01/meta-data/").\
|
126
|
-
at_least_once.returns(StringIO.new(""))
|
127
|
-
|
128
|
-
Facter::Util::EC2.stubs(:read_uri).
|
129
|
-
with("#{api_prefix}/latest/user-data/").
|
130
|
-
returns("test")
|
131
|
-
|
132
|
-
# Force a fact load
|
133
|
-
Facter.collection.internal_loader.load(:ec2)
|
134
|
-
|
135
|
-
Facter.fact(:ec2_userdata).value.should == ["test"]
|
85
|
+
it "is suitable if the virtual fact is xen" do
|
86
|
+
Facter.fact(:virtual).stubs(:value).returns "xen"
|
87
|
+
expect(subject).to be_suitable
|
136
88
|
end
|
137
89
|
|
138
|
-
it "
|
139
|
-
Facter.stubs(:
|
140
|
-
|
141
|
-
|
142
|
-
Object.any_instance.expects(:open).
|
143
|
-
with("#{api_prefix}/2008-02-01/meta-data/").
|
144
|
-
at_least_once.raises(RuntimeError, 'host unreachable')
|
145
|
-
|
146
|
-
Facter::Util::EC2.stubs(:read_uri).
|
147
|
-
with("#{api_prefix}/latest/user-data/").
|
148
|
-
raises(RuntimeError, 'host unreachable')
|
149
|
-
|
150
|
-
# Force a fact load
|
151
|
-
Facter.collection.internal_loader.load(:ec2)
|
152
|
-
|
153
|
-
Facter.fact(:ec2_userdata).value.should be_nil
|
90
|
+
it "is suitable if the virtual fact is xenu" do
|
91
|
+
Facter.fact(:virtual).stubs(:value).returns "xenu"
|
92
|
+
expect(subject).to be_suitable
|
154
93
|
end
|
94
|
+
end
|
155
95
|
|
96
|
+
it "resolves the value by fetching the rest endpoint" do
|
97
|
+
querier.expects(:fetch).returns "user data!"
|
98
|
+
expect(subject.value).to eq "user data!"
|
156
99
|
end
|
100
|
+
end
|
157
101
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
102
|
+
describe "flattened versions of ec2 facts" do
|
103
|
+
# These facts are tricky to test because they are dynamic facts, and they are
|
104
|
+
# generated from a fact that is defined in the same file. In order to pull
|
105
|
+
# this off we need to define the ec2_metadata fact ahead of time so that we
|
106
|
+
# can stub the value, and then manually load the correct files.
|
162
107
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
Facter::Util::EC2.stubs(:has_ec2_arp?).never
|
167
|
-
Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(false)
|
108
|
+
it "unpacks the ec2_metadata fact" do
|
109
|
+
Facter.define_fact(:ec2_metadata).stubs(:value).returns({"hello" => "world"})
|
110
|
+
Facter.collection.internal_loader.load(:ec2)
|
168
111
|
|
169
|
-
|
170
|
-
|
171
|
-
with("#{api_prefix}/2008-02-01/meta-data/").never
|
172
|
-
Object.any_instance.expects(:open).
|
173
|
-
with("#{api_prefix}/2008-02-01/user-data/").never
|
112
|
+
expect(Facter.value("ec2_hello")).to eq "world"
|
113
|
+
end
|
174
114
|
|
175
|
-
|
176
|
-
|
115
|
+
it "does not set any flat ec2 facts if the ec2_metadata fact is nil" do
|
116
|
+
Facter.define_fact(:ec2_metadata).stubs(:value)
|
117
|
+
Facter.define_fact(:ec2_userdata).stubs(:value).returns(nil)
|
177
118
|
|
178
|
-
|
179
|
-
end
|
119
|
+
Facter.collection.internal_loader.load(:ec2)
|
180
120
|
|
181
|
-
|
182
|
-
Facter::Util::EC2.expects(:open).with("#{api_prefix}:80/").raises(Timeout::Error)
|
121
|
+
all_facts = Facter.collection.to_hash
|
183
122
|
|
184
|
-
|
185
|
-
|
123
|
+
ec2_facts = all_facts.keys.select { |k| k =~ /^ec2_/ }
|
124
|
+
expect(ec2_facts).to be_empty
|
186
125
|
end
|
126
|
+
|
187
127
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "fqdn fact" do
|
6
|
+
it "should concatenate hostname and domain" do
|
7
|
+
Facter.fact(:hostname).stubs(:value).returns("foo")
|
8
|
+
Facter.fact(:domain).stubs(:value).returns("bar")
|
9
|
+
Facter.fact(:fqdn).value.should == "foo.bar"
|
10
|
+
end
|
11
|
+
it "should return hostname when domain is nil" do
|
12
|
+
Facter.fact(:hostname).stubs(:value).returns("foo")
|
13
|
+
Facter.fact(:domain).stubs(:value).returns(nil)
|
14
|
+
Facter.fact(:fqdn).value.should == "foo"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/gce/metadata'
|
3
|
+
|
4
|
+
describe Facter::GCE::Metadata, :if => Facter.json? do
|
5
|
+
|
6
|
+
describe "contacting the metadata server" do
|
7
|
+
it "retries the request when a connection error is thrown" do
|
8
|
+
subject.stubs(:open).returns(stub(:read => '{"hello": "world"}'))
|
9
|
+
seq = sequence('open-uri seq')
|
10
|
+
Timeout.expects(:timeout).with(0.05).twice.in_sequence(seq).raises(Timeout::Error)
|
11
|
+
Timeout.expects(:timeout).with(0.05).once.in_sequence(seq).yields
|
12
|
+
expect(subject.fetch).to eq({'hello' => 'world'})
|
13
|
+
end
|
14
|
+
|
15
|
+
it "logs the exception when all retries failed" do
|
16
|
+
Timeout.expects(:timeout).with(0.05).times(3).raises(Timeout::Error)
|
17
|
+
Facter.expects(:log_exception).with(instance_of(Timeout::Error), instance_of(String))
|
18
|
+
expect(subject.fetch).to be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "parsing the metadata response" do
|
23
|
+
let(:body) { my_fixture_read('metadata.json') }
|
24
|
+
before do
|
25
|
+
subject.stubs(:open).returns(stub(:read => body))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "transforms hash values with the 'image' key" do
|
29
|
+
expect(subject.fetch['instance']['image']).to eq 'centos6'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "transforms hash values with the 'machineType' key" do
|
33
|
+
expect(subject.fetch['instance']['machineType']).to eq 'n1-standard-1'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "transforms hash values with the 'zone' key" do
|
37
|
+
expect(subject.fetch['instance']['zone']).to eq 'us-central1-b'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "transforms hash values with the 'network' key" do
|
41
|
+
expect(subject.fetch['instance']['networkInterfaces'][0]['network']).to eq 'default'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "splits up the elements of the 'sshKeys' value into an array" do
|
45
|
+
expect(subject.fetch['project']['attributes']['sshKeys'][0]).to match(/justin:ssh-rsa/)
|
46
|
+
expect(subject.fetch['project']['attributes']['sshKeys'][1]).to match(/adrien:ssh-rsa/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/gce/metadata'
|
3
|
+
|
4
|
+
describe "gce_metadata" do
|
5
|
+
let(:querier) { stub('GCE metadata querier') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Facter::GCE::Metadata.stubs(:new).returns querier
|
9
|
+
Facter.collection.internal_loader.load(:ec2)
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { Facter.fact(:gce).resolution(:rest) }
|
13
|
+
|
14
|
+
it "is unsuitable when the virtual type is not gce" do
|
15
|
+
Facter.fact(:virtual).stubs(:value).returns 'kvm'
|
16
|
+
expect(subject).to_not be_suitable
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is unsuitable when JSON is not available" do
|
20
|
+
Facter.stubs(:json?).returns false
|
21
|
+
expect(subject).to_not be_suitable
|
22
|
+
end
|
23
|
+
|
24
|
+
it "is suitable when both the virtual type is gce and JSON is available" do
|
25
|
+
Facter.fact(:virtual).stubs(:value).returns 'gce'
|
26
|
+
Facter.stubs(:json?).returns true
|
27
|
+
expect(subject).to be_suitable
|
28
|
+
end
|
29
|
+
|
30
|
+
it "resolves the fact by querying GCE metadata API" do
|
31
|
+
querier.expects(:fetch).returns({'hello' => 'world'})
|
32
|
+
expect(subject.value).to eq({'hello' => 'world'})
|
33
|
+
end
|
34
|
+
end
|
@@ -4,15 +4,15 @@ require 'spec_helper'
|
|
4
4
|
require 'shared_formats/parses'
|
5
5
|
require 'facter/util/ip'
|
6
6
|
|
7
|
-
shared_examples_for "
|
8
|
-
it "
|
7
|
+
shared_examples_for "interface netmask and mtu from ifconfig output" do |platform, interface, netmask, mtu, fixture|
|
8
|
+
it "should be correct on #{platform} for interface #{interface}" do
|
9
9
|
Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
|
10
10
|
Facter::Util::IP.stubs(:get_output_for_interface_and_label).
|
11
11
|
returns(my_fixture_read("#{fixture}.#{interface}"))
|
12
12
|
Facter.collection.internal_loader.load(:interfaces)
|
13
13
|
|
14
|
-
|
15
|
-
fact.value.should eq(
|
14
|
+
Facter.fact("netmask_#{interface}".intern).value.should eq(netmask)
|
15
|
+
Facter.fact("mtu_#{interface}".intern).value.should eq(mtu)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -43,15 +43,15 @@ describe "Per Interface IP facts" do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe "Netmask handling on Linux" do
|
46
|
+
describe "Netmask and MTU handling on Linux" do
|
47
47
|
before :each do
|
48
48
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
49
49
|
end
|
50
50
|
|
51
|
-
example_behavior_for "
|
51
|
+
example_behavior_for "interface netmask and mtu from ifconfig output",
|
52
52
|
"Archlinux (net-tools 1.60)", "em1",
|
53
|
-
"255.255.255.0", "ifconfig_net_tools_1.60.txt"
|
54
|
-
example_behavior_for "
|
53
|
+
"255.255.255.0", "1500", "ifconfig_net_tools_1.60.txt"
|
54
|
+
example_behavior_for "interface netmask and mtu from ifconfig output",
|
55
55
|
"Archlinux (net-tools 1.60)", "lo",
|
56
|
-
"255.0.0.0", "ifconfig_net_tools_1.60.txt"
|
56
|
+
"255.0.0.0", "16436", "ifconfig_net_tools_1.60.txt"
|
57
57
|
end
|
@@ -3,15 +3,20 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe "Kernel major version fact" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return the kernel major release using the kernel release" do
|
12
|
-
Facter.fact(:kernelmajversion).value.should == "12.34"
|
13
|
-
end
|
14
|
-
end
|
6
|
+
context "when the kernelrelease fact contains three components" do
|
7
|
+
it "returns the first two components" do
|
8
|
+
Facter.fact(:kernelversion).stubs(:value).returns("12.34.56")
|
15
9
|
|
10
|
+
Facter.fact(:kernelmajversion).value.should == "12.34"
|
11
|
+
end
|
12
|
+
end
|
16
13
|
|
14
|
+
context "when the kernelrelease fact only contains two components" do
|
15
|
+
it "returns the first component" do
|
16
|
+
Facter.fact(:kernel).stubs(:value).returns('FreeBSD')
|
17
|
+
Facter.fact(:kernelversion).stubs(:value).returns("9.2")
|
17
18
|
|
19
|
+
Facter.fact(:kernelmajversion).value.should == "9"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|