Skip to content

Commit d752ef5

Browse files
author
Nuo Yan
committed
more roles and environments related work
1 parent 95e4215 commit d752ef5

6 files changed

Lines changed: 48 additions & 6 deletions

File tree

‎chef/lib/chef/role.rb‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def run_list(*args)
111111
end
112112
@run_list
113113
end
114+
115+
alias_method :recipes, :run_list
114116

115117
def run_list_for_environment(environment='_default')
116118
if env_run_lists[environment].nil? || env_run_lists[environment].empty? || env_run_lists[environment]["run_list"].nil?
@@ -120,11 +122,14 @@ def run_list_for_environment(environment='_default')
120122
end
121123
end
122124

123-
alias_method :recipes, :run_list
124-
125125
def env_run_lists(hash=nil)
126126
# should have btter validation, but leaving it as it is for now to make everything work first [nuo]
127-
(!hash.nil? && hash.length > 0) ? @env_run_lists = hash : @env_run_lists
127+
if (!hash.nil? && hash.length > 0)
128+
hash.values.map!{|r| r["run_list"] = Chef::RunList.new << r["run_list"] unless r["run_list"].class == Chef::RunList}
129+
@env_run_lists = hash
130+
else
131+
@env_run_lists
132+
end
128133
end
129134

130135
# def recipes(*args)

‎features/api/environments/show_role_in_environment.feature‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Feature: Show a role in an environment via the REST API
44
As a Developer
55
I want to show the run list for a specific Role in a specific environment
66

7-
@foo
87
Scenario: Show an environment specific run list and attribuets in a role
98
Given I am an administrator
109
And an 'environment' named 'cucumber' exists

‎features/api/roles/list_roles_api.feature‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: List roles via the REST API
88
Given I am an administrator
99
And there are no roles
1010
When I 'GET' the path '/roles'
11-
Then the inflated response should be '1' items long
11+
Then the inflated response should be '2' items long
1212

1313
Scenario: List roles when one has been created
1414
Given I am an administrator
@@ -21,7 +21,7 @@ Feature: List roles via the REST API
2121
And a 'role' named 'webserver' exists
2222
And a 'role' named 'db' exists
2323
When I 'GET' the path '/roles'
24-
Then the inflated response should be '3' items long
24+
Then the inflated response should be '4' items long
2525
And the inflated responses key 'role_test' should match '^http://.+/roles/role_test$'
2626
And the inflated responses key 'webserver' should match '^http://.+/roles/webserver$'
2727
And the inflated responses key 'db' should match '^http://.+/roles/db$'

‎features/chef-client/roles.feature‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@ Feature: Configure nodes based on their role
1414
And a file named 'role_test_ossining.txt' should contain 'whatever'
1515
And a file named 'role_test_ruby_version.txt' should contain '1.\d+.\d+'
1616

17+
Scenario: Apply a role with multiple environment specific run_lists to a node
18+
Given an 'environment' named 'cucumber' exists
19+
Given a validated node in the 'cucumber' environment
20+
And it includes the role 'role_env_test'
21+
When I run the chef-client with '-l debug'
22+
Then the run should exit '0'
23+
And 'stdout' should have 'DEBUG: Loading Recipe roles'
24+
And a file named 'role_test_reason.txt' should contain 'unbalancing'
25+
And a file named 'role_test_ossining.txt' should contain 'whatever'
26+
And a file named 'role_test_ruby_version.txt' should contain '1.\d+.\d+'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "role_env_test",
3+
"chef_type": "role",
4+
"json_class": "Chef::Role",
5+
"default_attributes": {
6+
"reason": "unbalancing",
7+
"ossining": "this time around"
8+
},
9+
"description": "A simple test role with environment specific run list",
10+
"run_list": [
11+
],
12+
"env_run_lists": {
13+
"cucumber" : {"default_attributes":{}, "override_attributes":{}, "run_list":"recipe[roles]"},
14+
"_default" : {}
15+
},
16+
"override_attributes": {
17+
"ossining": "whatever",
18+
"snakes": "on a plane"
19+
}
20+
}

‎features/steps/node_steps.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
client.node.run_list << "integration_setup"
2727
end
2828

29+
Given /^a validated node in the 'cucumber' environment$/ do
30+
# client should have cached ohai assigned to it
31+
client.register
32+
client.build_node
33+
client.node.chef_environment("cucumber")
34+
client.node.run_list << "integration_setup"
35+
end
36+
2937
Given /^a validated node with an empty runlist$/ do
3038
# client should have cached ohai assigned to it
3139
client.register

0 commit comments

Comments
 (0)