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.

Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +14 -0
  3. data/ext/project_data.yaml +9 -6
  4. data/lib/facter/core/execution/base.rb +3 -3
  5. data/lib/facter/core/suitable.rb +1 -5
  6. data/lib/facter/dhcp_servers.rb +39 -0
  7. data/lib/facter/ec2.rb +33 -26
  8. data/lib/facter/ec2/rest.rb +130 -0
  9. data/lib/facter/fqdn.rb +2 -0
  10. data/lib/facter/gce.rb +16 -0
  11. data/lib/facter/gce/metadata.rb +87 -0
  12. data/lib/facter/kernelmajversion.rb +8 -0
  13. data/lib/facter/kernelrelease.rb +8 -0
  14. data/lib/facter/memory.rb +21 -15
  15. data/lib/facter/netmask.rb +1 -1
  16. data/lib/facter/operatingsystem.rb +20 -0
  17. data/lib/facter/operatingsystemmajrelease.rb +2 -1
  18. data/lib/facter/operatingsystemrelease.rb +19 -0
  19. data/lib/facter/osfamily.rb +3 -1
  20. data/lib/facter/partitions.rb +35 -0
  21. data/lib/facter/physicalprocessorcount.rb +9 -0
  22. data/lib/facter/processor.rb +25 -25
  23. data/lib/facter/util/config.rb +3 -1
  24. data/lib/facter/util/dhcp_servers.rb +43 -0
  25. data/lib/facter/util/ec2.rb +5 -0
  26. data/lib/facter/util/formatter.rb +2 -1
  27. data/lib/facter/util/ip.rb +1 -1
  28. data/lib/facter/util/loader.rb +10 -1
  29. data/lib/facter/util/manufacturer.rb +15 -16
  30. data/lib/facter/util/memory.rb +12 -12
  31. data/lib/facter/util/netmask.rb +1 -1
  32. data/lib/facter/util/operatingsystem.rb +21 -0
  33. data/lib/facter/util/partitions.rb +41 -0
  34. data/lib/facter/util/partitions/linux.rb +65 -0
  35. data/lib/facter/util/posix.rb +16 -0
  36. data/lib/facter/util/processor.rb +8 -10
  37. data/lib/facter/util/resolution.rb +4 -0
  38. data/lib/facter/util/values.rb +29 -0
  39. data/lib/facter/util/virtual.rb +32 -3
  40. data/lib/facter/util/windows_root.rb +2 -32
  41. data/lib/facter/version.rb +1 -1
  42. data/lib/facter/virtual.rb +53 -12
  43. data/spec/fixtures/ifconfig/openbsd_bridge_rules +11 -0
  44. data/spec/fixtures/unit/dhcp_servers/nmcli_devices +4 -0
  45. data/spec/fixtures/unit/dhcp_servers/nmcli_devices_disconnected +4 -0
  46. data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_dhcp +36 -0
  47. data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_static +24 -0
  48. data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_dhcp +49 -0
  49. data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_static +37 -0
  50. data/spec/fixtures/unit/dhcp_servers/route +3 -0
  51. data/spec/fixtures/unit/dhcp_servers/route_nogw +1 -0
  52. data/spec/fixtures/unit/ec2/rest/meta-data/root +20 -0
  53. data/spec/fixtures/unit/gce/metadata/metadata.json +69 -0
  54. data/spec/fixtures/unit/kernelrelease/openbsd-5.3 +2 -0
  55. data/spec/fixtures/unit/kernelrelease/openbsd-5.3-current +3 -0
  56. data/spec/fixtures/unit/memory/aix-svmon +9 -0
  57. data/spec/fixtures/unit/memory/aix-swap_l +2 -0
  58. data/spec/fixtures/unit/memory/darwin-swapinfo-multiple +3 -0
  59. data/spec/fixtures/unit/memory/darwin-swapinfo-single +2 -0
  60. data/spec/fixtures/unit/memory/darwin-vm_stat +13 -0
  61. data/spec/fixtures/unit/memory/dragonfly-vmstat +3 -0
  62. data/spec/fixtures/unit/memory/freebsd-vmstat +3 -0
  63. data/spec/fixtures/unit/memory/linux-proc_meminfo +10 -0
  64. data/spec/fixtures/unit/memory/openbsd-vmstat +3 -0
  65. data/spec/fixtures/unit/memory/smartos_zone_swap_l-single +2 -0
  66. data/spec/fixtures/unit/memory/solaris-prtconf +4 -0
  67. data/spec/fixtures/unit/memory/solaris-swap_l-multiple +3 -0
  68. data/spec/fixtures/unit/memory/solaris-swap_l-single +2 -0
  69. data/spec/fixtures/unit/memory/solaris-vmstat +3 -0
  70. data/spec/fixtures/unit/netmask/ifconfig_aix_7.txt +3 -0
  71. data/spec/fixtures/unit/util/dhcp_servers/route +3 -0
  72. data/spec/fixtures/unit/util/dhcp_servers/route_nogw +1 -0
  73. data/spec/fixtures/unit/util/manufacturer/smartos_smbios +533 -0
  74. data/spec/fixtures/unit/util/operatingsystem/cumuluslinux.txt +8 -0
  75. data/spec/fixtures/unit/util/operatingsystem/redhat-7.txt +12 -0
  76. data/spec/fixtures/unit/util/operatingsystem/sabayon.txt +7 -0
  77. data/spec/fixtures/unit/util/operatingsystem/wheezy.txt +9 -0
  78. data/spec/fixtures/unit/util/partitions/partitions/mount +9 -0
  79. data/spec/fixtures/virtual/proc_1_cgroup/in_a_container +9 -0
  80. data/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container +8 -0
  81. data/spec/fixtures/virtual/proc_1_cgroup/not_in_a_container +9 -0
  82. data/spec/spec_helper.rb +1 -1
  83. data/spec/unit/core/execution/base_spec.rb +3 -5
  84. data/spec/unit/core/execution/posix_spec.rb +2 -2
  85. data/spec/unit/core/suitable_spec.rb +10 -0
  86. data/spec/unit/dhcp_servers_spec.rb +152 -0
  87. data/spec/unit/ec2/rest_spec.rb +145 -0
  88. data/spec/unit/ec2_spec.rb +87 -147
  89. data/spec/unit/fqdn_spec.rb +16 -0
  90. data/spec/unit/gce/metadata_spec.rb +49 -0
  91. data/spec/unit/gce_spec.rb +34 -0
  92. data/spec/unit/interfaces_spec.rb +9 -9
  93. data/spec/unit/kernelmajversion_spec.rb +14 -9
  94. data/spec/unit/kernelrelease_spec.rb +16 -0
  95. data/spec/unit/macaddress_spec.rb +12 -0
  96. data/spec/unit/memory_spec.rb +53 -122
  97. data/spec/unit/netmask_spec.rb +11 -0
  98. data/spec/unit/operatingsystem_spec.rb +19 -0
  99. data/spec/unit/operatingsystemmajrelease_spec.rb +1 -1
  100. data/spec/unit/operatingsystemrelease_spec.rb +8 -0
  101. data/spec/unit/osfamily_spec.rb +62 -0
  102. data/spec/unit/partitions_spec.rb +48 -0
  103. data/spec/unit/physicalprocessorcount_spec.rb +9 -0
  104. data/spec/unit/processor_spec.rb +15 -7
  105. data/spec/unit/util/config_spec.rb +13 -0
  106. data/spec/unit/util/dhcp_servers_spec.rb +63 -0
  107. data/spec/unit/util/ec2_spec.rb +4 -0
  108. data/spec/unit/util/formatter_spec.rb +50 -0
  109. data/spec/unit/util/loader_spec.rb +4 -4
  110. data/spec/unit/util/macosx_spec.rb +3 -2
  111. data/spec/unit/util/manufacturer_spec.rb +44 -0
  112. data/spec/unit/util/operatingsystem_spec.rb +92 -0
  113. data/spec/unit/util/partitions/partitions_spec.rb +67 -0
  114. data/spec/unit/util/partitions_spec.rb +19 -0
  115. data/spec/unit/util/posix_spec.rb +11 -0
  116. data/spec/unit/util/values_spec.rb +40 -0
  117. data/spec/unit/util/virtual_spec.rb +72 -2
  118. data/spec/unit/virtual_spec.rb +67 -18
  119. metadata +116 -4
  120. data/spec/fixtures/unit/util/loader/nosuchfact.rb +0 -1
@@ -1,187 +1,127 @@
1
- #! /usr/bin/env ruby
2
-
3
1
  require 'spec_helper'
4
- require 'facter/util/ec2'
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
- it "should create flat meta-data facts" do
23
- Object.any_instance.expects(:open).
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
- Object.any_instance.expects(:open).
28
- with("#{api_prefix}/2008-02-01/meta-data/foo").
29
- at_least_once.returns(StringIO.new("bar"))
7
+ before do
8
+ Facter::EC2::Metadata.stubs(:new).returns querier
30
9
 
31
- Facter.collection.internal_loader.load(:ec2)
32
-
33
- Facter.fact(:ec2_foo).value.should == "bar"
34
- end
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
- it "should create flat meta-data facts with comma seperation" do
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
- Object.any_instance.expects(:open).
42
- with("#{api_prefix}/2008-02-01/meta-data/foo").
43
- at_least_once.returns(StringIO.new("bar\nbaz"))
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
- Facter.collection.internal_loader.load(:ec2)
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
- Facter.fact(:ec2_foo).value.should == "bar,baz"
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 "should create structured meta-data facts" do
51
- Object.any_instance.expects(:open).
52
- with("#{api_prefix}/2008-02-01/meta-data/").
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
- Object.any_instance.expects(:open).
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 "should create ec2_user_data fact" do
69
- # No meta-data
70
- Object.any_instance.expects(:open).
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
- describe "when running on eucalyptus" do
84
- before :each do
85
- # Return false for ec2, true for eucalyptus
86
- Facter::Util::EC2.stubs(:has_euca_mac?).returns(true)
87
- Facter::Util::EC2.stubs(:has_openstack_mac?).returns(false)
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
- # Assume we can connect
91
- Facter::Util::EC2.stubs(:can_connect?).returns(true)
92
- end
54
+ describe "ec2_userdata" do
55
+ let(:querier) { stub('EC2 metadata querier') }
93
56
 
94
- it "should create ec2_user_data fact" do
95
- # No meta-data
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
- Facter::Util::EC2.stubs(:read_uri).
101
- with("#{api_prefix}/latest/user-data/").
102
- returns("test")
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
- # Force a fact load
105
- Facter.collection.internal_loader.load(:ec2)
66
+ subject { Facter.fact(:ec2_userdata).resolution(:rest) }
106
67
 
107
- Facter.fact(:ec2_userdata).value.should == ["test"]
108
- end
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
- describe "when running on openstack" do
112
- before :each do
113
- # Return false for ec2, true for eucalyptus
114
- Facter::Util::EC2.stubs(:has_openstack_mac?).returns(true)
115
- Facter::Util::EC2.stubs(:has_euca_mac?).returns(false)
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
- # Assume we can connect
119
- Facter::Util::EC2.stubs(:can_connect?).returns(true)
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 "should create ec2_user_data fact" do
123
- # No meta-data
124
- Object.any_instance.expects(:open).\
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 "should return nil if open fails" do
139
- Facter.stubs(:warn) # do not pollute test output
140
- Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable')
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
- describe "when api connect test fails" do
159
- before :each do
160
- Facter.stubs(:warnonce)
161
- end
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
- it "should not populate ec2_userdata" do
164
- # Emulate ec2 for now as it matters little to this test
165
- Facter::Util::EC2.stubs(:has_euca_mac?).returns(true)
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
- # The API should never be called at this point
170
- Object.any_instance.expects(:open).
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
- # Force a fact load
176
- Facter.collection.internal_loader.load(:ec2)
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
- Facter.fact(:ec2_userdata).should == nil
179
- end
119
+ Facter.collection.internal_loader.load(:ec2)
180
120
 
181
- it "should rescue the exception" do
182
- Facter::Util::EC2.expects(:open).with("#{api_prefix}:80/").raises(Timeout::Error)
121
+ all_facts = Facter.collection.to_hash
183
122
 
184
- Facter::Util::EC2.should_not be_can_connect
185
- end
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 "netmask_* from ifconfig output" do |platform, interface, address, fixture|
8
- it "correctly on #{platform} interface #{interface}" do
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
- fact = Facter.fact("netmask_#{interface}".intern)
15
- fact.value.should eq(address)
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 "netmask_* from ifconfig output",
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 "netmask_* from ifconfig output",
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
- before do
8
- Facter.fact(:kernelversion).stubs(:value).returns("12.34.56")
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