Skip to content

Commit bda58b8

Browse files
committed
Updating Platform to use os instead of operatingsystem, Updating Client specs to use Ohai style platform/platform_version, removing specs that are no longer relevant from Platform
1 parent 521d220 commit bda58b8

4 files changed

Lines changed: 12 additions & 71 deletions

File tree

chef/lib/chef/platform.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def find_platform_and_version(node)
111111

112112
if node[:platform]
113113
platform = node[:platform]
114-
elsif node.attribute?("operatingsystem")
115-
platform = node[:operatingsystem]
114+
elsif node.attribute?("os")
115+
platform = node[:os]
116116
end
117117

118118
raise ArgumentError, "Cannot find a platform for #{node}" unless platform

chef/spec/unit/client_spec.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@
128128
@mock_facter_fqdn.stub!(:value).and_return("foo.bar.com")
129129
@mock_facter_hostname = mock("Facter Hostname")
130130
@mock_facter_hostname.stub!(:value).and_return("foo")
131-
Facter.stub!(:[]).with("fqdn").and_return(@mock_facter_fqdn)
132-
Facter.stub!(:[]).with("hostname").and_return(@mock_facter_hostname)
133-
Facter.stub!(:each).and_return(true)
131+
@mock_ohai = {
132+
:fqdn => "foo.bar.com",
133+
:hostname => "foo"
134+
}
135+
@mock_ohai.stub!(:all_plugins).and_return(true)
136+
Ohai::System.stub!(:new).and_return(@mock_ohai)
134137
@node = Chef::Node.new
135138
@mock_rest.stub!(:get_rest).and_return(@node)
136139
Chef::REST.stub!(:new).and_return(@mock_rest)
@@ -145,7 +148,7 @@
145148
end
146149

147150
it "should set the name equal to the hostname if FQDN is not available" do
148-
@mock_facter_fqdn.stub!(:value).and_return(nil)
151+
@mock_ohai[:fqdn] = nil
149152
@mock_rest.stub!(:get_rest).and_return(nil)
150153
@client.build_node
151154
@client.node.name.should eql("foo")

chef/spec/unit/platform_spec.rb

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -94,73 +94,11 @@
9494
kitty = Chef::Resource::Cat.new("loulou")
9595
node = Chef::Node.new
9696
node.name("Intel")
97-
node.operatingsystem("Darwin")
98-
node.operatingsystemversion("9.2.2")
97+
node.platform("mac_os_x")
98+
node.platform_version("9.2.2")
9999
Chef::Platform.find_provider_for_node(node, kitty).should eql("nice")
100100
end
101101

102-
it "should prefer lsbdistid over operatingsystem when looking up via node" do
103-
kitty = Chef::Resource::Cat.new("loulou")
104-
node = Chef::Node.new
105-
node.name("Intel")
106-
node.operatingsystem("Darwin")
107-
node.operatingsystemversion("9.2.2")
108-
node.lsbdistid("Not Linux")
109-
Chef::Platform.set(
110-
:platform => :not_linux,
111-
:resource => :cat,
112-
:provider => "bourbon"
113-
)
114-
Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
115-
end
116-
117-
it "should prefer macosx_productnmae over operatingsystem when looking up via node" do
118-
kitty = Chef::Resource::Cat.new("loulou")
119-
node = Chef::Node.new
120-
node.name("Intel")
121-
node.operatingsystem("Darwin")
122-
node.operatingsystemversion("9.2.2")
123-
node.macosx_productname("Mac OS X")
124-
Chef::Platform.set(
125-
:platform => :mac_os_x,
126-
:resource => :cat,
127-
:provider => "bourbon"
128-
)
129-
Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
130-
end
131-
132-
it "should prefer lsbdistrelease over operatingsystem when looking up via node" do
133-
kitty = Chef::Resource::Cat.new("loulou")
134-
node = Chef::Node.new
135-
node.name("Intel")
136-
node.operatingsystem("Darwin")
137-
node.operatingsystemversion("9.2.2")
138-
node.lsbdistrelease("10")
139-
Chef::Platform.set(
140-
:platform => :darwin,
141-
:version => "10",
142-
:resource => :cat,
143-
:provider => "bourbon"
144-
)
145-
Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
146-
end
147-
148-
it "should prefer macosx_productversion over operatingsystem when looking up via node" do
149-
kitty = Chef::Resource::Cat.new("loulou")
150-
node = Chef::Node.new
151-
node.name("Intel")
152-
node.operatingsystem("Darwin")
153-
node.operatingsystemversion("9.2.2")
154-
node.macosx_productversion("10")
155-
Chef::Platform.set(
156-
:platform => :darwin,
157-
:version => "10",
158-
:resource => :cat,
159-
:provider => "bourbon"
160-
)
161-
Chef::Platform.find_provider_for_node(node, kitty).should eql("bourbon")
162-
end
163-
164102
it "should update the provider map with map" do
165103
Chef::Platform.set(
166104
:platform => :darwin,

example-repository/cookbooks/fakefile/recipes/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
mode 0755
7979
source "remote_test"
8080
files_owner "root"
81-
files_group(@node['operatingsystem'] == "Ubuntu" ? "admin" : "wheel")
81+
files_group(@node['platform'] == "ubuntu" ? "admin" : "wheel")
8282
files_mode 0644
8383
files_backup false
8484
end

0 commit comments

Comments
 (0)