PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/unit/plugins/cloud_spec.rb

https://github.com/jmanero/ohai
Ruby | 159 lines | 140 code | 3 blank | 16 comment | 0 complexity | 0d7479206689897f4e8c8e94c1bcb106 MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Author:: Cary Penniman (<cary@rightscale.com>)
  3. # License:: Apache License, Version 2.0
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
  18. describe Ohai::System, "plugin cloud" do
  19. before do
  20. @ohai = Ohai::System.new
  21. @ohai.stub!(:require_plugin).and_return(true)
  22. end
  23. describe "with no cloud mashes" do
  24. it "doesn't populate the cloud data" do
  25. @ohai[:ec2] = nil
  26. @ohai[:rackspace] = nil
  27. @ohai[:eucalyptus] = nil
  28. @ohai[:linode] = nil
  29. @ohai._require_plugin("cloud")
  30. @ohai[:cloud].should be_nil
  31. end
  32. end
  33. describe "with EC2 mash" do
  34. before do
  35. @ohai[:ec2] = Mash.new()
  36. end
  37. it "populates cloud public ip" do
  38. @ohai[:ec2]['public_ipv4'] = "174.129.150.8"
  39. @ohai._require_plugin("cloud")
  40. @ohai[:cloud][:public_ips][0].should == @ohai[:ec2]['public_ipv4']
  41. end
  42. it "populates cloud private ip" do
  43. @ohai[:ec2]['local_ipv4'] = "10.252.42.149"
  44. @ohai._require_plugin("cloud")
  45. @ohai[:cloud][:private_ips][0].should == @ohai[:ec2]['local_ipv4']
  46. end
  47. it "populates cloud provider" do
  48. @ohai._require_plugin("cloud")
  49. @ohai[:cloud][:provider].should == "ec2"
  50. end
  51. end
  52. describe "with rackspace" do
  53. before do
  54. @ohai[:rackspace] = Mash.new()
  55. end
  56. it "populates cloud public ip" do
  57. @ohai[:rackspace][:public_ipv4] = "174.129.150.8"
  58. @ohai._require_plugin("cloud")
  59. @ohai[:cloud][:public_ipv4].should == @ohai[:rackspace][:public_ipv4]
  60. end
  61. it "populates cloud public ipv6" do
  62. @ohai[:rackspace][:public_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
  63. @ohai._require_plugin("cloud")
  64. @ohai[:cloud][:public_ipv6].should == @ohai[:rackspace][:public_ipv6]
  65. end
  66. it "populates cloud private ip" do
  67. @ohai[:rackspace][:local_ipv4] = "10.252.42.149"
  68. @ohai._require_plugin("cloud")
  69. @ohai[:cloud][:local_ipv4].should == @ohai[:rackspace][:local_ipv4]
  70. end
  71. it "populates cloud private ipv6" do
  72. @ohai[:rackspace][:local_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
  73. @ohai._require_plugin("cloud")
  74. @ohai[:cloud][:local_ipv6].should == @ohai[:rackspace][:local_ipv6]
  75. end
  76. it "populates first cloud public ip" do
  77. @ohai[:rackspace][:public_ipv4] = "174.129.150.8"
  78. @ohai._require_plugin("cloud")
  79. @ohai[:cloud][:public_ips].first.should == @ohai[:rackspace][:public_ipv4]
  80. end
  81. it "populates first cloud public ip" do
  82. @ohai[:rackspace][:local_ipv4] = "174.129.150.8"
  83. @ohai._require_plugin("cloud")
  84. @ohai[:cloud][:private_ips].first.should == @ohai[:rackspace][:local_ipv4]
  85. end
  86. it "populates cloud provider" do
  87. @ohai._require_plugin("cloud")
  88. @ohai[:cloud][:provider].should == "rackspace"
  89. end
  90. end
  91. describe "with linode mash" do
  92. before do
  93. @ohai[:linode] = Mash.new()
  94. end
  95. it "populates cloud public ip" do
  96. @ohai[:linode]['public_ip'] = "174.129.150.8"
  97. @ohai._require_plugin("cloud")
  98. @ohai[:cloud][:public_ips][0].should == @ohai[:linode][:public_ip]
  99. end
  100. it "populates cloud private ip" do
  101. @ohai[:linode]['private_ip'] = "10.252.42.149"
  102. @ohai._require_plugin("cloud")
  103. @ohai[:cloud][:private_ips][0].should == @ohai[:linode][:private_ip]
  104. end
  105. it "populates first cloud public ip" do
  106. @ohai[:linode]['public_ip'] = "174.129.150.8"
  107. @ohai._require_plugin("cloud")
  108. @ohai[:cloud][:public_ips].first.should == @ohai[:linode][:public_ip]
  109. end
  110. it "populates cloud provider" do
  111. @ohai._require_plugin("cloud")
  112. @ohai[:cloud][:provider].should == "linode"
  113. end
  114. end
  115. describe "with eucalyptus mash" do
  116. before do
  117. @ohai[:eucalyptus] = Mash.new()
  118. end
  119. it "populates cloud public ip" do
  120. @ohai[:eucalyptus]['public_ipv4'] = "174.129.150.8"
  121. @ohai._require_plugin("cloud")
  122. @ohai[:cloud][:public_ips][0].should == @ohai[:eucalyptus]['public_ipv4']
  123. end
  124. it "populates cloud private ip" do
  125. @ohai[:eucalyptus]['local_ipv4'] = "10.252.42.149"
  126. @ohai._require_plugin("cloud")
  127. @ohai[:cloud][:private_ips][0].should == @ohai[:eucalyptus]['local_ipv4']
  128. end
  129. it "populates cloud provider" do
  130. @ohai._require_plugin("cloud")
  131. @ohai[:cloud][:provider].should == "eucalyptus"
  132. end
  133. end
  134. end