diff options
author | Adam Jacob <adam@opscode.com> | 2009-05-28 09:49:10 -0700 |
---|---|---|
committer | Adam Jacob <adam@opscode.com> | 2009-05-28 09:49:10 -0700 |
commit | b134af4a053eda678e0e04e165743a5b3d91606c (patch) | |
tree | 29b23cd2cdbd12fafb49f77d62a470ac8af6c86c | |
parent | fb1431585170b3cd178e04f8b5f033898d97de91 (diff) | |
download | chef-b134af4a053eda678e0e04e165743a5b3d91606c.tar.gz |
Fixing up a bug in the Role/Node UI that showed cookbooks where it should have been showing recipes, adding more integration tests for roles
-rw-r--r-- | chef-server-slice/app/controllers/application.rb | 25 | ||||
-rw-r--r-- | chef-server-slice/app/controllers/nodes.rb | 12 | ||||
-rw-r--r-- | chef-server-slice/app/controllers/roles.rb | 9 | ||||
-rw-r--r-- | chef-server-slice/app/views/nodes/_form.html.haml | 4 | ||||
-rw-r--r-- | example-repository/cookbooks/fakefile/metadata.json | 18 | ||||
-rw-r--r-- | example-repository/cookbooks/tempfile/metadata.json | 18 | ||||
-rw-r--r-- | features/chef-client/roles.feature | 1 | ||||
-rw-r--r-- | features/steps/node_steps.rb | 6 |
8 files changed, 50 insertions, 43 deletions
diff --git a/chef-server-slice/app/controllers/application.rb b/chef-server-slice/app/controllers/application.rb index ee91e1cd2f..ec3de37824 100644 --- a/chef-server-slice/app/controllers/application.rb +++ b/chef-server-slice/app/controllers/application.rb @@ -164,8 +164,12 @@ class ChefServerSlice::Application < Merb::Controller def specific_cookbooks(node_name, cl) valid_cookbooks = Hash.new - node = Chef::Node.load(node_name) - recipes, default_attrs, override_attrs = node.run_list.expand('couchdb') + begin + node = Chef::Node.load(node_name) + recipes, default_attrs, override_attrs = node.run_list.expand('couchdb') + rescue Net::HTTPServerException + recipes = [] + end recipes.each do |recipe| valid_cookbooks = expand_cookbook_deps(valid_cookbooks, cl, recipe) end @@ -188,7 +192,7 @@ class ChefServerSlice::Application < Merb::Controller def load_all_files(segment, node_name=nil) cl = Chef::CookbookLoader.new files = Array.new - valid_cookbooks = node_name ? specific_cookbooks(node_name, cl) : nil + valid_cookbooks = node_name ? specific_cookbooks(node_name, cl) : {} cl.each do |cookbook| if node_name next unless valid_cookbooks[cookbook.name.to_s] @@ -206,4 +210,19 @@ class ChefServerSlice::Application < Merb::Controller files end + def get_available_recipes + cl = Chef::CookbookLoader.new + available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s }.inject([]) do |result, element| + element.recipes.sort.each do |r| + if r =~ /^(.+)::default$/ + result << $1 + else + result << r + end + end + result + end + available_recipes + end + end diff --git a/chef-server-slice/app/controllers/nodes.rb b/chef-server-slice/app/controllers/nodes.rb index 20e58fdf31..26e291df8c 100644 --- a/chef-server-slice/app/controllers/nodes.rb +++ b/chef-server-slice/app/controllers/nodes.rb @@ -43,8 +43,7 @@ class ChefServerSlice::Nodes < ChefServerSlice::Application def new @node = Chef::Node.new - cl = Chef::CookbookLoader.new - @available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s } + @available_recipes = get_available_recipes @available_roles = Chef::Role.list.sort @run_list = @node.run_list render @@ -56,8 +55,7 @@ class ChefServerSlice::Nodes < ChefServerSlice::Application rescue Net::HTTPServerException => e raise NotFound, "Cannot load node #{params[:id]}" end - cl = Chef::CookbookLoader.new - @available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s } + @available_recipes = get_available_recipes @available_roles = Chef::Role.list.sort @run_list = @node.run_list render @@ -85,9 +83,8 @@ class ChefServerSlice::Nodes < ChefServerSlice::Application @node.save redirect(slice_url(:nodes), :message => { :notice => "Created Node #{@node.name}" }) rescue - cl = Chef::CookbookLoader.new @node.attribute = JSON.parse(params[:attributes]) - @available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s } + @available_recipes = get_available_recipes @available_roles = Chef::Role.list.sort @run_list = params[:for_node] @_message = { :error => $! } @@ -117,8 +114,7 @@ class ChefServerSlice::Nodes < ChefServerSlice::Application @_message = { :notice => "Updated Node" } render :show rescue - cl = Chef::CookbookLoader.new - @available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s } + @available_recipes = get_available_recipes @available_roles = Chef::Role.list.sort @run_list = Chef::RunList.new @run_list.reset(params[:for_node]) diff --git a/chef-server-slice/app/controllers/roles.rb b/chef-server-slice/app/controllers/roles.rb index cb6d25899b..27851d1d8c 100644 --- a/chef-server-slice/app/controllers/roles.rb +++ b/chef-server-slice/app/controllers/roles.rb @@ -134,13 +134,4 @@ class ChefServerSlice::Roles < ChefServerSlice::Application end end - def get_available_recipes - cl = Chef::CookbookLoader.new - available_recipes = cl.sort{ |a,b| a.name.to_s <=> b.name.to_s }.inject([]) do |result, element| - element.recipes.sort.each { |r| result << r =~ /^(.+)::default$/ ? $1 : r } - result - end - available_recipes - end - end diff --git a/chef-server-slice/app/views/nodes/_form.html.haml b/chef-server-slice/app/views/nodes/_form.html.haml index cac9179765..d150eb59a7 100644 --- a/chef-server-slice/app/views/nodes/_form.html.haml +++ b/chef-server-slice/app/views/nodes/_form.html.haml @@ -36,8 +36,8 @@ %td %div.sortable %ul#node_available_recipes.connectedSortable - - @available_recipes.each do |cookbook| - %li{ :id => "recipe[#{cookbook.name}]", :class => 'ui-state-default' }= h cookbook.name + - @available_recipes.each do |recipe| + %li{ :id => "recipe[#{recipe}]", :class => 'ui-state-default' }= h recipe %div.group.form diff --git a/example-repository/cookbooks/fakefile/metadata.json b/example-repository/cookbooks/fakefile/metadata.json index a6f2bd5787..02d17674a8 100644 --- a/example-repository/cookbooks/fakefile/metadata.json +++ b/example-repository/cookbooks/fakefile/metadata.json @@ -1,4 +1,8 @@ { + "maintainer": "Your Name", + "recommendations": { + + }, "maintainer_email": "youremail@example.com", "recipes": { "fakefile": "" @@ -6,10 +10,6 @@ "suggestions": { }, - "license": "Apache v2.0", - "conflicting": { - - }, "dependencies": { "tempfile": [ @@ -21,21 +21,21 @@ "attributes": { }, + "license": "Apache v2.0", "name": "fakefile", + "conflicting": { + + }, "providing": { "fakefile": [ ] }, + "description": "A fabulous new cookbook", "replacing": { }, "long_description": "", - "description": "A fabulous new cookbook", - "maintainer": "Your Name", - "recommendations": { - - }, "platforms": { } diff --git a/example-repository/cookbooks/tempfile/metadata.json b/example-repository/cookbooks/tempfile/metadata.json index 4e0ed852f1..d778c651ed 100644 --- a/example-repository/cookbooks/tempfile/metadata.json +++ b/example-repository/cookbooks/tempfile/metadata.json @@ -1,4 +1,8 @@ { + "maintainer": "Your Name", + "recommendations": { + + }, "maintainer_email": "youremail@example.com", "recipes": { "tempfile": "" @@ -6,10 +10,6 @@ "suggestions": { }, - "license": "Apache v2.0", - "conflicting": { - - }, "dependencies": { "fakefile": [ @@ -18,21 +18,21 @@ "attributes": { }, + "license": "Apache v2.0", "name": "tempfile", + "conflicting": { + + }, "providing": { "tempfile": [ ] }, + "description": "A fabulous new cookbook", "replacing": { }, "long_description": "", - "description": "A fabulous new cookbook", - "maintainer": "Your Name", - "recommendations": { - - }, "platforms": { } diff --git a/features/chef-client/roles.feature b/features/chef-client/roles.feature index 80a3de016f..267fa4e1f2 100644 --- a/features/chef-client/roles.feature +++ b/features/chef-client/roles.feature @@ -10,3 +10,4 @@ Feature: Configure nodes based on their role When I run the chef-client with '-l debug' Then the run should exit '0' + diff --git a/features/steps/node_steps.rb b/features/steps/node_steps.rb index 7152b6c996..d1aa9a0045 100644 --- a/features/steps/node_steps.rb +++ b/features/steps/node_steps.rb @@ -33,9 +33,9 @@ Given /^it includes the recipe '(.+)'$/ do |recipe| client.save_node end -Given /^it includes the role '(.+)'$/ do |recipe| - self.recipe = recipe - client.node.recipes << recipe +Given /^it includes the role '(.+)'$/ do |role| + self.recipe = "role[#{role}]" + client.node.run_list << "role[#{role}]" client.save_node end |