Changeset 89
- Timestamp:
- 04/23/08 18:38:44 (7 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 modified
-
app/models/deployment.rb (modified) (2 diffs)
-
db/migrate/023_add_exclude_hosts_to_deployment.rb (added)
-
db/schema.rb (modified) (3 diffs)
-
lib/webistrano/deployer.rb (modified) (1 diff)
-
test/test_helper.rb (modified) (2 diffs)
-
test/unit/deployment_test.rb (modified) (1 diff)
-
test/unit/webistrano_deployer_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/app/models/deployment.rb
r80 r89 8 8 validates_inclusion_of :success, :in => 0..1 9 9 10 attr_accessible :task, :prompt_config, :description 10 serialize :excluded_host_ids 11 12 attr_accessible :task, :prompt_config, :description, :excluded_host_ids 11 13 12 14 tz_time_attributes :created_at, :updated_at, :completed_at … … 112 114 end 113 115 end 116 117 # returns a list of hosts that this deployment 118 # will deploy to. This computed out of the list 119 # of given roles and the excluded hosts 120 def deploy_to_hosts 121 all_hosts = self.roles.map(&:host).uniq 122 return all_hosts - self.excluded_hosts 123 end 124 125 # returns a list of roles that this deployment 126 # will deploy to. This computed out of the list 127 # of given roles and the excluded hosts 128 def deploy_to_roles 129 self.roles.delete_if{|role| self.excluded_hosts.include?(role.host) } 130 end 131 132 # a list of all excluded hosts for this deployment 133 # see excluded_host_ids 134 def excluded_hosts 135 res = [] 136 self.excluded_host_ids.each do |h_id| 137 res << (Host.find(h_id) rescue nil) 138 end 139 res.compact 140 end 141 142 def excluded_host_ids 143 self.read_attribute('excluded_host_ids').blank? ? [] : self.read_attribute('excluded_host_ids') 144 end 145 146 def excluded_host_ids=(val) 147 val = [val] unless val.is_a?(Array) 148 self.write_attribute('excluded_host_ids', val) 149 end 114 150 end -
trunk/db/schema.rb
r64 r89 10 10 # It's strongly recommended to check this file into your version control system. 11 11 12 ActiveRecord::Schema.define(:version => 2 2) do12 ActiveRecord::Schema.define(:version => 23) do 13 13 14 14 create_table "configuration_parameters", :force => true do |t| … … 26 26 t.string "task" 27 27 t.text "log" 28 t.integer "success", :default => 028 t.integer "success", :default => 0 29 29 t.integer "stage_id" 30 30 t.datetime "created_at" … … 33 33 t.text "description" 34 34 t.integer "user_id" 35 t.string "excluded_host_ids" 35 36 end 36 37 -
trunk/lib/webistrano/deployer.rb
r34 r89 177 177 # sets the roles on the Capistrano configuration 178 178 def set_stage_roles(config) 179 deployment. roles.each do |r|179 deployment.deploy_to_roles.each do |r| 180 180 181 181 # create role attributes hash -
trunk/test/test_helper.rb
r42 r89 174 174 :roles => [], 175 175 :description => random_string, 176 :user => create_new_user 176 :user => create_new_user, 177 :excluded_host_ids => [] 177 178 }.update(options) 178 179 … … 184 185 d.prompt_config = options[:prompt_config] 185 186 d.description = options[:description] 187 d.excluded_host_ids = options[:excluded_host_ids] 186 188 d.user = options[:user] 187 189 -
trunk/test/unit/deployment_test.rb
r80 r89 227 227 end 228 228 229 def test_excluded_hosts_accessor 230 host = create_new_host 231 deployment = create_new_deployment(:excluded_host_ids => [host.id], :stage => @stage) 232 233 assert_equal [host.id], deployment.excluded_host_ids 234 assert_equal [host], deployment.excluded_hosts 235 236 deployment.excluded_host_ids = host.id 237 assert_equal [host.id], deployment.excluded_host_ids 238 end 239 240 def test_excluded_hosts 241 host_1 = create_new_host 242 host_2 = create_new_host 243 stage = create_new_stage 244 role_app = create_new_role(:name => 'app', :stage => stage, :host => host_1) 245 role_www = create_new_role(:name => 'www', :stage => stage, :host => host_2) 246 role_db = create_new_role(:name => 'db', :stage => stage, :host => host_2) 247 248 deployment = create_new_deployment( 249 :stage => stage, 250 :excluded_host_ids => [host_1.id]) 251 252 assert_equal 3, deployment.roles.count 253 assert_equal [host_1], deployment.excluded_hosts 254 255 assert_equal [host_2], deployment.deploy_to_hosts 256 assert_equal [role_www, role_db].map(&:id).sort, deployment.deploy_to_roles.map(&:id).sort 257 end 258 259 260 229 261 end -
trunk/test/unit/webistrano_deployer_test.rb
r82 r89 158 158 end 159 159 160 def test_excluded_hosts 161 # prepare stage + roles 162 @stage = create_new_stage 163 dead_host = create_new_host 164 165 www_role = @stage.roles.build(:name => 'www', :host_id => @host.id) 166 www_role.save! 167 168 app_role = @stage.roles.build(:name => 'app', :host_id => @host.id) 169 app_role.save! 170 171 db_role = @stage.roles.build(:name => 'db', :host_id => dead_host.id) 172 db_role.save! 173 174 @stage.reload 175 176 deployment = create_new_deployment(:stage => @stage, :excluded_host_ids => [dead_host.id]) 177 assert_equal [www_role, app_role].map(&:id).sort, deployment.deploy_to_roles.map(&:id).sort 178 # prepare Mocks 179 # 180 181 # Logger stubing 182 mock_cap_logger = mock 183 mock_cap_logger.expects(:level=).with(3) 184 185 # config stubbing 186 mock_cap_config = mock 187 mock_cap_config.stubs(:logger).returns(mock_cap_logger) 188 mock_cap_config.stubs(:logger=) 189 mock_cap_config.stubs(:load) 190 mock_cap_config.stubs(:trigger) 191 mock_cap_config.stubs(:find_and_execute_task) 192 mock_cap_config.stubs(:[]) 193 mock_cap_config.stubs(:fetch).with(:scm) 194 195 # ignore vars 196 mock_cap_config.stubs(:set) 197 198 # 199 # now check the roles 200 # 201 202 #mock_cap_config.expects(:role).with('db', @host.name) 203 mock_cap_config.expects(:role).with('www', @host.name) 204 mock_cap_config.expects(:role).with('app', @host.name) 205 206 207 # main mock install 208 Webistrano::Configuration.expects(:new).returns(mock_cap_config) 209 210 # get things started 211 deployer = Webistrano::Deployer.new( deployment ) 212 deployer.invoke_task! 213 end 214 160 215 def test_invoke_task 161 216 assert_correct_task_called('deploy:setup')
