|
| 1 | +# |
| 2 | +# Author:: Michael Leinartas (<mleinartas@gmail.com>) |
| 3 | +# Copyright:: Copyright (c) 2010 Michael Leinartas |
| 4 | +# License:: Apache License, Version 2.0 |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) |
| 20 | + |
| 21 | +require 'chef/run_context' |
| 22 | + |
| 23 | +describe Chef::Provider::Ohai do |
| 24 | + before(:each) do |
| 25 | + # Copied from client_spec |
| 26 | + FQDN = "hostname.domainname" |
| 27 | + HOSTNAME = "hostname" |
| 28 | + PLATFORM = "example-platform" |
| 29 | + PLATFORM_VERSION = "example-platform" |
| 30 | + Chef::Config[:node_name] = FQDN |
| 31 | + mock_ohai = { |
| 32 | + :fqdn => FQDN, |
| 33 | + :hostname => HOSTNAME, |
| 34 | + :platform => PLATFORM, |
| 35 | + :platform_version => PLATFORM_VERSION, |
| 36 | + :data => { |
| 37 | + :origdata => "somevalue" |
| 38 | + }, |
| 39 | + :data2 => { |
| 40 | + :origdata => "somevalue", |
| 41 | + :newdata => "somevalue" |
| 42 | + } |
| 43 | + } |
| 44 | + mock_ohai.stub!(:all_plugins).and_return(true) |
| 45 | + mock_ohai.stub!(:require_plugin).and_return(true) |
| 46 | + mock_ohai.stub!(:data).and_return(mock_ohai[:data], |
| 47 | + mock_ohai[:data2]) |
| 48 | + Ohai::System.stub!(:new).and_return(mock_ohai) |
| 49 | + Chef::Platform.stub!(:find_platform_and_version).and_return({ "platform" => PLATFORM, |
| 50 | + "platform_version" => PLATFORM_VERSION}) |
| 51 | + # Fake node with a dummy save |
| 52 | + @node = Chef::Node.new(HOSTNAME) |
| 53 | + @node.name(FQDN) |
| 54 | + @node.stub!(:save).and_return(@node) |
| 55 | + @run_context = Chef::RunContext.new(@node, {}) |
| 56 | + @new_resource = Chef::Resource::Ohai.new("ohai_reload") |
| 57 | + ohai = Ohai::System.new |
| 58 | + ohai.all_plugins |
| 59 | + @node.process_external_attrs(ohai.data,{}) |
| 60 | + |
| 61 | + @provider = Chef::Provider::Ohai.new(@new_resource, @run_context) |
| 62 | + end |
| 63 | + |
| 64 | + describe "when reloading ohai" do |
| 65 | + it "should cause node to pick up new values" do |
| 66 | + @node[:origdata].should == 'somevalue' |
| 67 | + @node[:newdata].should == nil |
| 68 | + @provider.action_reload |
| 69 | + @node[:origdata].should == 'somevalue' |
| 70 | + @node[:newdata].should == 'somevalue' |
| 71 | + end |
| 72 | + |
| 73 | + it "should reload a specific plugin and cause node to pick up new values" do |
| 74 | + @new_resource.plugin "someplugin" |
| 75 | + @provider.action_reload |
| 76 | + @node[:origdata].should == 'somevalue' |
| 77 | + @node[:newdata].should == 'somevalue' |
| 78 | + end |
| 79 | + end |
| 80 | +end |
0 commit comments