Changeset 90
- Timestamp:
- 04/23/08 23:21:57 (7 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 modified
-
CHANGELOG.txt (modified) (1 diff)
-
app/helpers/deployments_helper.rb (modified) (1 diff)
-
app/models/deployment.rb (modified) (3 diffs)
-
app/views/deployments/new.html.erb (modified) (2 diffs)
-
app/views/stylesheets/application.html.erb (modified) (1 diff)
-
public/images/peritor_theme/host_off.png (added)
-
public/images/peritor_theme/host_on.png (added)
-
test/functional/deployments_controller_test.rb (modified) (1 diff)
-
test/test_helper.rb (modified) (1 diff)
-
test/unit/deployment_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG.txt
r88 r90 1 1 2 2 * SVN * 3 4 * Ability to disable host per deloy. This way host that are down do not block a deployment 3 5 4 6 * Check syntax of recipes. Provided by Mathias Meyer -
trunk/app/helpers/deployments_helper.rb
r1 r90 8 8 end 9 9 end 10 11 def if_disabled_host?(host, text) 12 (@deployment.excluded_host_ids.include?(host.id) ? text : '' rescue '') 13 end 14 15 def if_enabled_host?(host, text) 16 (@deployment.excluded_host_ids.include?(host.id) ? '' : text rescue text) 17 end 10 18 end -
trunk/app/models/deployment.rb
r89 r90 33 33 end 34 34 35 ensure_not_all_hosts_excluded 35 36 end 36 37 end … … 126 127 # will deploy to. This computed out of the list 127 128 # of given roles and the excluded hosts 128 def deploy_to_roles 129 self.roles.delete_if{|role| self.excluded_hosts.include?(role.host) }129 def deploy_to_roles(base_roles=self.roles) 130 base_roles.dup.delete_if{|role| self.excluded_hosts.include?(role.host) } 130 131 end 131 132 … … 146 147 def excluded_host_ids=(val) 147 148 val = [val] unless val.is_a?(Array) 148 self.write_attribute('excluded_host_ids', val) 149 self.write_attribute('excluded_host_ids', val.map(&:to_i)) 150 end 151 152 protected 153 def ensure_not_all_hosts_excluded 154 unless self.stage.blank? || self.excluded_host_ids.blank? 155 if deploy_to_roles(self.stage.roles).blank? 156 errors.add('base', "You cannot exclude all hosts.") 157 end 158 end 149 159 end 150 160 end -
trunk/app/views/deployments/new.html.erb
r73 r90 25 25 26 26 <p> 27 <b>Deployment Options</b><br /> 28 <a id="s_e_h" href="#" onclick="show_disable_hosts(); return false" class="arrow_link">Show Manage Deployed Hosts</a> 29 <a id="h_e_h" href="#" onclick="hide_disable_hosts(); return false" class="arrow_link" style="display:none;">Hide Manage Deployed Hosts</a> 30 <div id="excluded_hosts" style="display:none;"> 31 <% if @stage.roles.count > 0 %> 32 <table class="sortable" style="width: 410px;"> 33 <tr> 34 <th width="1%">Status</th> 35 <th width="99%">Host</th> 36 </tr> 37 <% for host in @stage.hosts %> 38 <tr class="<%= cycle :even, :odd, :name => 'hosts' %> <%= if_disabled_host?(host,'disabled_host') %>"> 39 <td style="padding:3px 0px 0px 0px;" valign="middle" align="center"> 40 <%= image_tag('peritor_theme/host_on.png', 41 :id => "host_#{host.id}_on", 42 :class => 'exlcude_host_trigger_on', 43 :style => if_disabled_host?(host,'display:none;') + 'cursor:pointer;')%> 44 <%= image_tag('peritor_theme/host_off.png', 45 :id => "host_#{host.id}_off", 46 :class => 'exlcude_host_trigger_off', 47 :style => if_enabled_host?(host,'display:none;') + 'cursor:pointer;')%> 48 <input style="display:none;" type="checkbox" value="<%=h host.id %>" name="deployment[excluded_host_ids][]" id="deployment_excluded_host_ids_<%=h host.id %>" <%= (@deployment.excluded_host_ids.include?(host.id) ? 'checked="checked"' : '' rescue '')%>/></td> 49 <td><%= link_to h(host.name), host_path(host) %></td> 50 </tr> 51 <% end %> 52 </table> 53 54 <% else %> 55 No hosts for this stage!<br /><br /> 56 <% end %> 57 <br /> 58 </div> 59 </p> 60 <p> 27 61 <%= submit_tag "Start Deployment" %> 28 62 </p> … … 30 64 31 65 <%= link_to 'Back', project_stage_path(@project, @stage), :class => 'arrow_link' %> 66 67 <% content_for(:page_scripts) do %> 68 <script type="text/javascript"> 69 70 function show_disable_hosts(){ 71 $('h_e_h').show(); 72 $('s_e_h').hide(); 73 $('excluded_hosts').show(); 74 } 75 76 function hide_disable_hosts(){ 77 $('h_e_h').hide(); 78 $('s_e_h').show(); 79 $('excluded_hosts').hide(); 80 } 81 82 function disable_host(){ 83 var own_id = /host_(\d)_on/.exec(this.id)[1]; 84 var other_id = "host_" + own_id + '_off'; 85 console.log('in diable host ' + own_id + '. other: ' + other_id); 86 $(this).hide(); 87 $(other_id).show(); 88 $('deployment_excluded_host_ids_' + own_id).writeAttribute('checked', 'checked'); 89 $(this).up('tr').removeClassName('enabled_host'); 90 $(this).up('tr').addClassName('disabled_host'); 91 } 92 93 function enable_host(){ 94 var own_id = /host_(\d)_off/.exec(this.id)[1]; 95 var other_id = "host_" + own_id + '_on'; 96 console.log('in enable host ' + own_id + '. other: ' + other_id); 97 $(this).hide(); 98 $(other_id).show(); 99 $('deployment_excluded_host_ids_' + own_id).writeAttribute('checked', false); 100 $(this).up('tr').removeClassName('disabled_host'); 101 $(this).up('tr').addClassName('enabled_host'); 102 } 103 104 Event.observe(window, 'load', function(){ 105 <% unless @deployment.excluded_host_ids.blank? %> 106 show_disable_hosts(); 107 <% end %> 108 109 $$('img.exlcude_host_trigger_on').each(function(el){ 110 el.observe('click', disable_host); 111 }); 112 113 $$('img.exlcude_host_trigger_off').each(function(el){ 114 el.observe('click', enable_host); 115 }) 116 }); 117 </script> 118 <% end %> -
trunk/app/views/stylesheets/application.html.erb
r73 r90 604 604 .alt { 605 605 background: #eef; 606 } 607 608 tr.disabled_host a{ 609 color: grey; 606 610 } 607 611 -
trunk/test/functional/deployments_controller_test.rb
r42 r90 93 93 assert_equal 1, Deployment.count 94 94 end 95 96 def test_excluded_hosts 97 Deployment.delete_all 98 host_down = create_new_host 99 down_role = create_new_role(:stage => @stage, :name => 'foo', :host => host_down) 100 101 assert_equal 2, @stage.roles.count 102 103 post :create, :deployment => { :excluded_host_ids => [host_down.id],:task => 'deploy:default', :description => 'update to newest', :prompt_config => {} }, :project_id => @project.id, :stage_id => @stage.id 104 105 assert_equal 1, Deployment.count 106 deployment = Deployment.find(:first) 107 assert_equal [host_down], deployment.excluded_hosts 108 assert_equal [@role], deployment.deploy_to_roles 109 end 95 110 96 111 end -
trunk/test/test_helper.rb
r89 r90 69 69 end 70 70 71 def create_new_role(options = {})72 options = {73 :stage => create_new_stage,74 :host => create_new_host,75 :name => random_string,76 :primary => 077 }.update(options)78 79 r = Role.new80 r.name = options[:name]81 r.stage = options[:stage]82 r.host = options[:host]83 r.primary = options[:primary]84 r.save!85 86 return r87 end71 # def create_new_role(options = {}) 72 # options = { 73 # :stage => create_new_stage, 74 # :host => create_new_host, 75 # :name => random_string, 76 # :primary => 0 77 # }.update(options) 78 # 79 # r = Role.new 80 # r.name = options[:name] 81 # r.stage = options[:stage] 82 # r.host = options[:host] 83 # r.primary = options[:primary] 84 # r.save! 85 # 86 # return r 87 # end 88 88 89 89 def create_new_project_configuration(options = {}) -
trunk/test/unit/deployment_test.rb
r89 r90 234 234 assert_equal [host], deployment.excluded_hosts 235 235 236 deployment.excluded_host_ids = host.id 236 deployment.excluded_host_ids = host.id.to_s 237 237 assert_equal [host.id], deployment.excluded_host_ids 238 238 end … … 246 246 role_db = create_new_role(:name => 'db', :stage => stage, :host => host_2) 247 247 248 stage.reload 249 assert_equal 3, stage.roles.count 248 250 deployment = create_new_deployment( 249 251 :stage => stage, … … 257 259 end 258 260 261 def test_cannot_exclude_all_hosts 262 stage = create_new_stage 263 host = create_new_host 264 role_app = create_new_role(:name => 'app', :stage => stage, :host => host) 265 266 d = Deployment.new 267 d.task = 'foo' 268 d.stage = stage 269 d.description = 'foo bar' 270 d.excluded_host_ids = role_app.host.id 271 d.user = create_new_user 272 273 assert !d.valid? 274 assert d.errors.on('base') 275 end 259 276 260 277
