# # Author:: Cary Penniman () # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb') require 'flexmock' describe Ohai::System, "plugin rightscale" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end # # EC2 Cloud Support # describe "ec2 with RightScale platform" do before(:each) do @ohai[:ec2] = Mash.new() @ohai[:ec2][:userdata] = "RS_api_url=https:\/\/my.rightscale.com\/api\/inst\/ec2_instances\/c18c07eb8d33456db3d75fe65c56e8bae94d8f59&RS_server=my.rightscale.com&RS_sketchy=sketchy1-12.rightscale.com&RS_token=e668bb0be59d061b8b60f08765902a90" end it "should create rightscale mash" do @ohai._require_plugin("rightscale") @ohai[:rightscale].should_not be_nil end it "should create rightscale server mash" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server].should_not be_nil end it "should populate sketchy server attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server]['sketchy'].should == "sketchy1-12.rightscale.com" end it "should populate core server attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server][:core].should == "my.rightscale.com" end it "should populate token attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:token].should == "e668bb0be59d061b8b60f08765902a90" end end describe "ec2 without rightscale" do before(:each) do @ohai[:ec2] = Mash.new() @ohai[:ec2][:userdata] = "some other form of userdata" end it "should NOT populate the rightscale data" do @ohai._require_plugin("rightscale") @ohai[:rightscale].should be_nil end end # # Generic Cloud Support # describe "cloud without rightscale" do before(:each) do @ohai[:cloud] = Mash.new() end it "should NOT populate the rightscale data" do @ohai._require_plugin("rightscale") @ohai[:rightscale].should be_nil end end describe "cloud with RightScale platform" do before(:each) do @ohai[:cloud] = Mash.new() @ohai[:cloud][:provider] = "rackspace" File.stub!(:exists?).and_return(true) @mock_file = mock("datafile") @mock_file.stub!(:each). # json input file (future?) #and_yield('{"rightscale":{"token":"8bd736d4a8de91b143bcebbb3e513f5f","server":{"syslog":"syslog.rightscale.com","sketchy":"sketchy1-11.rightscale.com","core":"my.rightscale.com","lumberjack":"lumberjack.rightscale.com"},"api_url":"https:\/\/my.rightscale.com\/api\/inst\/ec2_instances\/40e9d3956ad2e059f9f4054c6272ce2a38155273"}}') and_yield('RS_syslog=syslog.rightscale.com'). and_yield('RS_sketchy=sketchy1-11.rightscale.com'). and_yield('RS_server=my.rightscale.com'). and_yield('RS_lumberjack=lumberjack.rightscale.com'). and_yield('RS_src=dobedobedo'). and_yield('RS_token=8bd736d4a8de91b143bcebbb3e513f5f'). and_yield('RS_api_url=https://my.rightscale.com/api/inst/ec2_instances/40e9d3956ad2e059f9f4054c6272ce2a38155273'). and_yield('RS_token_id=blabla'). and_yield('RS_amqp_url=yakityyakyak') File.stub!(:open).and_return(@mock_file) end it "should create rightscale mash" do @ohai._require_plugin("rightscale") @ohai[:rightscale].should_not be_nil end it "should create rightscale server mash" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server].should_not be_nil end it "should populate sketchy server attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server][:sketchy].should == "sketchy1-11.rightscale.com" end it "should populate core server attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server][:core].should == "my.rightscale.com" end it "should populate syslog server attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server][:syslog].should == "syslog.rightscale.com" end it "should populate lumberjack server attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:server][:lumberjack].should == "lumberjack.rightscale.com" end it "should populate token attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:token].should == "8bd736d4a8de91b143bcebbb3e513f5f" end it "should populate api_url attribute" do @ohai._require_plugin("rightscale") @ohai[:rightscale][:api_url].should == "https://my.rightscale.com/api/inst/ec2_instances/40e9d3956ad2e059f9f4054c6272ce2a38155273" end end end