summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Goldschrafe <jeff@rabb.it>2014-10-18 15:55:35 -0400
committerBryan McLellan <btm@opscode.com>2015-02-17 12:33:57 -0500
commit1cc97562ba923b81957e6e1ee134434da981950d (patch)
tree379a067f34e5214ce121f6b2dd947bfbb5a0c980
parent3376e7f608590f4099e738f413232e24a1f7b2ab (diff)
downloadohai-1cc97562ba923b81957e6e1ee134434da981950d.tar.gz
Fix GitHub Issue #432
Fixes GitHub issue #432: cloud_v2 fails to initialize on GCE hosts without external IP Resolves a special-case issue where an empty public IP address is not handled correctly, causing cloud_v2 to fail to initialize when a GCE instance does not have a public IP. Spec included. Obvious fix, though I think I signed the CLA last year anyway.
-rw-r--r--lib/ohai/plugins/cloud_v2.rb2
-rw-r--r--spec/unit/plugins/cloud_v2_spec.rb81
2 files changed, 57 insertions, 26 deletions
diff --git a/lib/ohai/plugins/cloud_v2.rb b/lib/ohai/plugins/cloud_v2.rb
index 944112fa..6aceeb93 100644
--- a/lib/ohai/plugins/cloud_v2.rb
+++ b/lib/ohai/plugins/cloud_v2.rb
@@ -125,7 +125,7 @@ Ohai.plugin(:CloudV2) do
def get_gce_values
public_ips = gce['instance']['networkInterfaces'].collect do |interface|
if interface.has_key?('accessConfigs')
- interface['accessConfigs'].collect{|ac| ac['externalIp']}
+ interface['accessConfigs'].collect{|ac| ac['externalIp'] unless ac['externalIp'] == ''}
end
end.flatten.compact
diff --git a/spec/unit/plugins/cloud_v2_spec.rb b/spec/unit/plugins/cloud_v2_spec.rb
index 5dc2b6ce..f5fe0de0 100644
--- a/spec/unit/plugins/cloud_v2_spec.rb
+++ b/spec/unit/plugins/cloud_v2_spec.rb
@@ -116,31 +116,62 @@ describe Ohai::System, "plugin cloud" do
end
describe "with GCE mash" do
- before do
- @plugin[:gce] = Mash.new()
- @plugin[:gce]['instance'] = Mash.new()
- @plugin[:gce]['instance']['networkInterfaces'] = [
- {
- "accessConfigs" => [ {"externalIp" => "8.35.198.173", "type"=>"ONE_TO_ONE_NAT"} ],
- "ip" => "10.240.0.102",
- "network"=> "projects/foo/networks/default"
- }
- ]
- end
-
- it "populates cloud public ip" do
- @plugin.run
- expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq("8.35.198.173")
- end
-
- it "populates cloud private ip" do
- @plugin.run
- expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq("10.240.0.102")
- end
-
- it "populates cloud provider" do
- @plugin.run
- expect(@plugin[:cloud_v2][:provider]).to eq("gce")
+ describe "with a public IP" do
+ before do
+ @plugin[:gce] = Mash.new()
+ @plugin[:gce]['instance'] = Mash.new()
+ @plugin[:gce]['instance']['networkInterfaces'] = [
+ {
+ "accessConfigs" => [ {"externalIp" => "8.35.198.173", "type"=>"ONE_TO_ONE_NAT"} ],
+ "ip" => "10.240.0.102",
+ "network"=> "projects/foo/networks/default"
+ }
+ ]
+ end
+
+ it "populates cloud public ip" do
+ @plugin.run
+ expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq("8.35.198.173")
+ end
+
+ it "populates cloud private ip" do
+ @plugin.run
+ expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq("10.240.0.102")
+ end
+
+ it "populates cloud provider" do
+ @plugin.run
+ expect(@plugin[:cloud_v2][:provider]).to eq("gce")
+ end
+ end
+
+ describe "with no public IP" do
+ before do
+ @plugin[:gce] = Mash.new()
+ @plugin[:gce]['instance'] = Mash.new()
+ @plugin[:gce]['instance']['networkInterfaces'] = [
+ {
+ "accessConfigs" => [ {"externalIp" => "", "type" => "ONE_TO_ONE_NAT"} ],
+ "ip" => "10.240.0.102",
+ "network" => "projects/foo/networks/default"
+ }
+ ]
+ end
+
+ it "does not populate cloud public ip" do
+ @plugin.run
+ expect(@plugin[:cloud_v2][:public_ipv4_addrs]).to be_nil
+ end
+
+ it "populates cloud private ip" do
+ @plugin.run
+ expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq("10.240.0.102")
+ end
+
+ it "populates cloud provider" do
+ @plugin.run
+ expect(@plugin[:cloud_v2][:provider]).to eq("gce")
+ end
end
end