From 8ef26c8b41e642a825f48c81cb887b4d6c1967d7 Mon Sep 17 00:00:00 2001 From: "tiwillia@redhat.com" Date: Fri, 30 Oct 2015 11:39:12 -0400 Subject: [PATCH] Inform user of the need to scale up when enabling HA on a scaled application Bug 1256952 https://bugzilla.redhat.com/show_bug.cgi?id=1256952 When an application with more than one gear ha HA enabled, a short message will now be given stating the possible need to scale the application up to actually receive the second haproxy instance. In addition to a adding a new test, the `app_spec.rb` now requires 'net/ssh/multi' to allow the spec to be run on its own outside of the RHC spec test suite. This has been resolved. --- lib/rhc/commands/app.rb | 32 ++++++++++++++++++++++++++++++-- spec/rhc/commands/app_spec.rb | 17 +++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/rhc/commands/app.rb b/lib/rhc/commands/app.rb index b33bae840..abb94532f 100644 --- a/lib/rhc/commands/app.rb +++ b/lib/rhc/commands/app.rb @@ -376,9 +376,37 @@ def tidy(app) syntax " [--namespace NAME]" takes_application :argument => true def enable_ha(app) - app_action :enable_ha + rest_app = find_app + + scaleup_needed = false + cant_scale_up = false + gear_groups = rest_app.gear_groups + gear_groups.each do |gg| + if gg.attributes["scales_from"] > 1 + scaleup_needed = true + if rest_app.gear_count == gg.attributes["scales_to"] + cant_scale_up = true + end + end + end - results { say "#{app} is now highly available" } + rest_app.send :enable_ha + results do + # If the application was already scaled, a scale up may be required. + if scaleup_needed + say "#{app} is now configured to be highly available" + if cant_scale_up + msg = "You will need to scale down the application, then scale back up to create an additional " + + "haproxy instance:\n rhc app scale-down #{rest_app.name} && rhc app scale-up #{rest_app.name}" + else + msg = "You will need to scale up the application to create an additional haproxy instance:\n" + + " rhc app scale-up #{rest_app.name}" + end + warn msg + else + say "#{app} is now highly available" + end + end 0 end diff --git a/spec/rhc/commands/app_spec.rb b/spec/rhc/commands/app_spec.rb index 1c058a060..b08d3fa8c 100644 --- a/spec/rhc/commands/app_spec.rb +++ b/spec/rhc/commands/app_spec.rb @@ -4,6 +4,7 @@ require 'rhc/config' require 'rhc/servers' require 'resolv' +require 'net/ssh/multi' describe RHC::Commands::App do let!(:rest_client){ MockRestClient.new } @@ -933,6 +934,22 @@ end end + describe 'app enable-ha on scaled application' do + before do + @domain = rest_client.add_domain("mockdomain") + @app = @domain.add_application("app1", "mock_type", true) + @app.add_cartridge('mock_cart-1') + @app.scale_up + end + + let(:arguments) { ['app', 'enable-ha', 'app1'] } + + it "should suggest scaling up to receive additional haproxy instances" do + run_output.should match(/You will need to scale/) + expect{ run }.to exit_with_code(0) + end + end + describe "#create_app" do it("should list cartridges when a server error happens") do subject.should_receive(:list_cartridges)