diff --git a/README.md b/README.md index 9b28d26..16461c8 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,10 @@ This provider exposes quite a few provider-specific configuration options: * `user_data` - String of User data to be sent to the newly created OpenStack instance. Use this e.g. to inject a script at boot time. * `metadata` - A Hash of metadata that will be sent to the instance for configuration e.g. `os.metadata = { 'key' => 'value' }` * `scheduler_hints` - Pass hints to the OpenStack scheduler, e.g. { "cell": "some cell name" } +* `server_create_timeout` - Time to wait in seconds for the server to be created when `vagrant up`. Default is `200` +* `server_active_timeout` - Time to wait in seconds for the server to become active when `vagrant up` or `vagrant resume`. Default is `200` +* `server_stop_timeout` - Time to wait in seconds for the server to stop when `vagrant halt`. Default is `200` +* `server_delete_timeout` - Time to wait in seconds for the server to be deleted when `vagrant destroy`. Default is `200` #### Floating IPs diff --git a/source/lib/vagrant-openstack-provider/action/create_server.rb b/source/lib/vagrant-openstack-provider/action/create_server.rb index aeeff49..33b4314 100644 --- a/source/lib/vagrant-openstack-provider/action/create_server.rb +++ b/source/lib/vagrant-openstack-provider/action/create_server.rb @@ -127,10 +127,11 @@ def create_server(env, options) nova.create_server(env, create_opts) end - def waiting_for_server_to_be_built(env, server_id, retry_interval = 3, timeout = 200) + def waiting_for_server_to_be_built(env, server_id, retry_interval = 3) @logger.info "Waiting for the server with id #{server_id} to be built..." env[:ui].info(I18n.t('vagrant_openstack.waiting_for_build')) - timeout(timeout, Errors::Timeout) do + config = env[:machine].provider_config + timeout(config.server_create_timeout, Errors::Timeout) do server_status = 'WAITING' until server_status == 'ACTIVE' @logger.debug('Waiting for server to be ACTIVE') diff --git a/source/lib/vagrant-openstack-provider/action/create_stack.rb b/source/lib/vagrant-openstack-provider/action/create_stack.rb index 38dde11..a20e63c 100644 --- a/source/lib/vagrant-openstack-provider/action/create_stack.rb +++ b/source/lib/vagrant-openstack-provider/action/create_stack.rb @@ -48,10 +48,11 @@ def execute(env) private - def waiting_for_stack_to_be_created(env, stack_name, stack_id, retry_interval = 3, timeout = 200) + def waiting_for_stack_to_be_created(env, stack_name, stack_id, retry_interval = 3) @logger.info "Waiting for the stack with id #{stack_id} to be built..." env[:ui].info(I18n.t('vagrant_openstack.waiting_for_stack')) - timeout(timeout, Errors::Timeout) do + config = env[:machine].provider_config + timeout(config.stack_create_timeout, Errors::Timeout) do stack_status = 'CREATE_IN_PROGRESS' until stack_status == 'CREATE_COMPLETE' @logger.debug('Waiting for stack to be CREATED') diff --git a/source/lib/vagrant-openstack-provider/action/delete_server.rb b/source/lib/vagrant-openstack-provider/action/delete_server.rb index 497502f..2dd84d6 100644 --- a/source/lib/vagrant-openstack-provider/action/delete_server.rb +++ b/source/lib/vagrant-openstack-provider/action/delete_server.rb @@ -28,10 +28,11 @@ def execute(env) private - def waiting_for_instance_to_be_deleted(env, instance_id, retry_interval = 3, timeout = 200) + def waiting_for_instance_to_be_deleted(env, instance_id, retry_interval = 3) @logger.info "Waiting for the instance with id #{instance_id} to be deleted..." env[:ui].info(I18n.t('vagrant_openstack.waiting_deleted')) - timeout(timeout, Errors::Timeout) do + config = env[:machine].provider_config + timeout(config.server_delete_timeout, Errors::Timeout) do delete_ok = false until delete_ok begin diff --git a/source/lib/vagrant-openstack-provider/action/delete_stack.rb b/source/lib/vagrant-openstack-provider/action/delete_stack.rb index 0bbf9c1..c3a35cb 100644 --- a/source/lib/vagrant-openstack-provider/action/delete_stack.rb +++ b/source/lib/vagrant-openstack-provider/action/delete_stack.rb @@ -53,10 +53,11 @@ def list_stack_files(env) stack_files end - def waiting_for_stack_to_be_deleted(env, stack_name, stack_id, retry_interval = 3, timeout = 200) + def waiting_for_stack_to_be_deleted(env, stack_name, stack_id, retry_interval = 3) @logger.info "Waiting for the stack with id #{stack_id} to be deleted..." env[:ui].info(I18n.t('vagrant_openstack.waiting_for_stack_deleted')) - timeout(timeout, Errors::Timeout) do + config = env[:machine].provider_config + timeout(config.stack_delete_timeout, Errors::Timeout) do stack_status = 'DELETE_IN_PROGRESS' until stack_status == 'DELETE_COMPLETE' @logger.debug('Waiting for stack to be DELETED') diff --git a/source/lib/vagrant-openstack-provider/action/wait_active.rb b/source/lib/vagrant-openstack-provider/action/wait_active.rb index f3c035d..bc87bb9 100644 --- a/source/lib/vagrant-openstack-provider/action/wait_active.rb +++ b/source/lib/vagrant-openstack-provider/action/wait_active.rb @@ -7,18 +7,18 @@ module VagrantPlugins module Openstack module Action class WaitForServerToBeActive < AbstractAction - def initialize(app, _env, retry_interval = 3, timeout = 200) + def initialize(app, _env, retry_interval = 3) @app = app @logger = Log4r::Logger.new('vagrant_openstack::action::start_server') @retry_interval = retry_interval - @timeout = timeout end def execute(env) if env[:machine].id env[:ui].info(I18n.t('vagrant_openstack.waiting_start')) client = env[:openstack_client].nova - timeout(@timeout, Errors::Timeout) do + config = env[:machine].provider_config + timeout(config.server_active_timeout, Errors::Timeout) do while client.get_server_details(env, env[:machine].id)['status'] != 'ACTIVE' sleep @retry_interval @logger.info('Waiting for server to be active') diff --git a/source/lib/vagrant-openstack-provider/action/wait_stop.rb b/source/lib/vagrant-openstack-provider/action/wait_stop.rb index 5b1f6c5..a3700b8 100644 --- a/source/lib/vagrant-openstack-provider/action/wait_stop.rb +++ b/source/lib/vagrant-openstack-provider/action/wait_stop.rb @@ -7,18 +7,18 @@ module VagrantPlugins module Openstack module Action class WaitForServerToStop < AbstractAction - def initialize(app, _env, retry_interval = 3, timeout = 200) + def initialize(app, _env, retry_interval = 3) @app = app @logger = Log4r::Logger.new('vagrant_openstack::action::stop_server') @retry_interval = retry_interval - @timeout = timeout end def execute(env) if env[:machine].id env[:ui].info(I18n.t('vagrant_openstack.waiting_stop')) client = env[:openstack_client].nova - timeout(@timeout, Errors::Timeout) do + config = env[:machine].provider_config + timeout(config.server_stop_timeout, Errors::Timeout) do while client.get_server_details(env, env[:machine].id)['status'] != 'SHUTOFF' sleep @retry_interval @logger.info('Waiting for server to stop') diff --git a/source/lib/vagrant-openstack-provider/config.rb b/source/lib/vagrant-openstack-provider/config.rb index a5bb65d..c59dc10 100644 --- a/source/lib/vagrant-openstack-provider/config.rb +++ b/source/lib/vagrant-openstack-provider/config.rb @@ -165,6 +165,30 @@ class Config < Vagrant.plugin('2', :config) # @return [String] attr_accessor :endpoint_type + # + # @return [Integer] + attr_accessor :server_create_timeout + + # + # @return [Integer] + attr_accessor :server_active_timeout + + # + # @return [Integer] + attr_accessor :server_stop_timeout + + # + # @return [Integer] + attr_accessor :server_delete_timeout + + # + # @return [Integer] + attr_accessor :stack_create_timeout + + # + # @return [Integer] + attr_accessor :stack_delete_timeout + def initialize @password = UNSET_VALUE @openstack_compute_url = UNSET_VALUE @@ -200,6 +224,12 @@ def initialize @user_data = UNSET_VALUE @metadata = UNSET_VALUE @ssh_disabled = UNSET_VALUE + @server_create_timeout = UNSET_VALUE + @server_active_timeout = UNSET_VALUE + @server_stop_timeout = UNSET_VALUE + @server_delete_timeout = UNSET_VALUE + @stack_create_timeout = UNSET_VALUE + @stack_delete_timeout = UNSET_VALUE end def merge(other) @@ -271,6 +301,12 @@ def finalize! # `config.ssh` values are used. @ssh_username = nil if @ssh_username == UNSET_VALUE @ssh_timeout = 180 if @ssh_timeout == UNSET_VALUE + @server_create_timeout = 200 if @server_create_timeout == UNSET_VALUE + @server_active_timeout = 200 if @server_active_timeout == UNSET_VALUE + @server_stop_timeout = 200 if @server_stop_timeout == UNSET_VALUE + @server_delete_timeout = 200 if @server_delete_timeout == UNSET_VALUE + @stack_create_timeout = 200 if @stack_create_timeout == UNSET_VALUE + @stack_delete_timeout = 200 if @stack_delete_timeout == UNSET_VALUE @networks = nil if @networks.empty? @volumes = nil if @volumes.empty? @stacks = nil if @stacks.empty? diff --git a/source/spec/vagrant-openstack-provider/action/create_server_spec.rb b/source/spec/vagrant-openstack-provider/action/create_server_spec.rb index 334a3a7..d5ade41 100644 --- a/source/spec/vagrant-openstack-provider/action/create_server_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/create_server_spec.rb @@ -195,17 +195,20 @@ it 'become active after one retry' do nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'ACTIVE' }) nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times - @action.waiting_for_server_to_be_built(env, 'server-01', 1, 5) + config.stub(:server_create_timeout) { 5 } + @action.waiting_for_server_to_be_built(env, 'server-01', 1) end it 'timeout before the server become active' do nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'BUILD' }) nova.should_receive(:get_server_details).with(env, 'server-01').at_least(2).times - expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1, 3) }.to raise_error Errors::Timeout + config.stub(:server_create_timeout) { 3 } + expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1) }.to raise_error Errors::Timeout end it 'raise an error after one retry' do nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'ERROR' }) nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times - expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1, 3) }.to raise_error Errors::ServerStatusError + config.stub(:server_create_timeout) { 3 } + expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1) }.to raise_error Errors::ServerStatusError end end end diff --git a/source/spec/vagrant-openstack-provider/action/create_stack_spec.rb b/source/spec/vagrant-openstack-provider/action/create_stack_spec.rb index 754fe6f..0fe4382 100644 --- a/source/spec/vagrant-openstack-provider/action/create_stack_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/create_stack_spec.rb @@ -22,6 +22,7 @@ } ] end + config.stub(:stack_create_timeout) { 200 } end end @@ -80,17 +81,20 @@ it 'become active after one retry' do heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, { 'stack_status' => 'CREATE_COMPLETE' }) heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').exactly(2).times - @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1, 5) + config.stub(:stack_create_timeout) { 5 } + @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) end it 'timeout before the server become active' do heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, { 'stack_status' => 'CREATE_IN_PROGRESS' }) heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').at_least(2).times - expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1, 3) }.to raise_error Errors::Timeout + config.stub(:stack_create_timeout) { 3 } + expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) }.to raise_error Errors::Timeout end it 'raise an error after one retry' do heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, { 'stack_status' => 'CREATE_FAILED' }) heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').exactly(2).times - expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1, 3) }.to raise_error Errors::StackStatusError + config.stub(:stack_create_timeout) { 3 } + expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) }.to raise_error Errors::StackStatusError end end end diff --git a/source/spec/vagrant-openstack-provider/action/delete_server_spec.rb b/source/spec/vagrant-openstack-provider/action/delete_server_spec.rb index c84f991..23b0ff7 100644 --- a/source/spec/vagrant-openstack-provider/action/delete_server_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/delete_server_spec.rb @@ -15,6 +15,10 @@ end end + let(:config) do + double('config') + end + let(:env) do Hash.new.tap do |env| env[:ui] = double('ui') @@ -22,6 +26,7 @@ env[:ui].stub(:error).with(anything) env[:openstack_client] = openstack_client env[:machine] = OpenStruct.new.tap do |m| + m.provider_config = config m.id = 'server_id' end end @@ -59,22 +64,26 @@ nova.stub(:get_server_details).once.and_return('status' => 'ACTIVE') nova.stub(:get_server_details).once.and_raise(Errors::InstanceNotFound) nova.should_receive(:get_server_details).with(env, 'server-01').exactly(1).times - @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1, 5) + config.stub(:server_delete_timeout) { 5 } + @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1) end it 'become deleted after one retry' do nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'DELETED' }) nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times - @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1, 5) + config.stub(:server_delete_timeout) { 5 } + @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1) end it 'timeout before the server become active' do nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'ACTIVE' }) nova.should_receive(:get_server_details).with(env, 'server-01').at_least(2).times - expect { @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1, 3) }.to raise_error Errors::Timeout + config.stub(:server_delete_timeout) { 3 } + expect { @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1) }.to raise_error Errors::Timeout end it 'raise an error after one retry' do nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'ERROR' }) nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times - expect { @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1, 3) }.to raise_error Errors::ServerStatusError + config.stub(:server_delete_timeout) { 3 } + expect { @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1) }.to raise_error Errors::ServerStatusError end end end diff --git a/source/spec/vagrant-openstack-provider/action/wait_active_spec.rb b/source/spec/vagrant-openstack-provider/action/wait_active_spec.rb index 1fd5f62..21cfed9 100644 --- a/source/spec/vagrant-openstack-provider/action/wait_active_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/wait_active_spec.rb @@ -6,6 +6,10 @@ double('nova') end + let(:config) do + double('config') + end + let(:env) do Hash.new.tap do |env| env[:ui] = double('ui').tap do |ui| @@ -16,6 +20,7 @@ os.stub(:nova) { nova } end env[:machine] = OpenStruct.new.tap do |m| + m.provider_config = config m.id = 'server_id' end end @@ -33,13 +38,15 @@ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'ACTIVE' }) expect(nova).to receive(:get_server_details).with(env, 'server_id').exactly(2).times expect(app).to receive(:call) - @action = WaitForServerToBeActive.new(app, nil, 1, 5) + config.stub(:server_active_timeout) { 5 } + @action = WaitForServerToBeActive.new(app, nil, 1) @action.call(env) end it 'timeout after one retry' do nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'BUILD' }) expect(nova).to receive(:get_server_details).with(env, 'server_id').at_least(2).times - @action = WaitForServerToBeActive.new(app, nil, 1, 2) + config.stub(:server_active_timeout) { 2 } + @action = WaitForServerToBeActive.new(app, nil, 1) expect { @action.call(env) }.to raise_error Errors::Timeout end end diff --git a/source/spec/vagrant-openstack-provider/action/wait_stop_spec.rb b/source/spec/vagrant-openstack-provider/action/wait_stop_spec.rb index d59e2e0..07c135f 100644 --- a/source/spec/vagrant-openstack-provider/action/wait_stop_spec.rb +++ b/source/spec/vagrant-openstack-provider/action/wait_stop_spec.rb @@ -6,6 +6,10 @@ double('nova') end + let(:config) do + double('config') + end + let(:env) do Hash.new.tap do |env| env[:ui] = double('ui').tap do |ui| @@ -16,6 +20,7 @@ os.stub(:nova) { nova } end env[:machine] = OpenStruct.new.tap do |m| + m.provider_config = config m.id = 'server_id' end end @@ -33,13 +38,15 @@ nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'SHUTOFF' }) expect(nova).to receive(:get_server_details).with(env, 'server_id').exactly(2).times expect(app).to receive(:call) - @action = WaitForServerToStop.new(app, nil, 1, 5) + config.stub(:server_stop_timeout) { 5 } + @action = WaitForServerToStop.new(app, nil, 1) @action.call(env) end it 'timeout after one retry' do nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'ACTIVE' }) expect(nova).to receive(:get_server_details).with(env, 'server_id').at_least(2).times - @action = WaitForServerToStop.new(app, nil, 1, 2) + config.stub(:server_stop_timeout) { 2 } + @action = WaitForServerToStop.new(app, nil, 1) expect { @action.call(env) }.to raise_error Errors::Timeout end end