Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Raise error when ip address is not given to vm after clone. #619

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/vmpooler/pool_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ def _clone_vm(pool_name, provider, dns_plugin, request_id = nil, pool_alias = ni
ip_start = Time.now
ip = provider.get_vm_ip_address(new_vmname, pool_name)
ip_finish = format('%<time>.2f', time: Time.now - ip_start)

raise StandardError, "failed to obtain IP after #{ip_finish} seconds" if ip.nil?

$logger.log('s', "[+] [#{pool_name}] Obtained IP for '#{new_vmname}' in #{ip_finish} seconds")

@redis.with_metrics do |redis|
Expand Down
15 changes: 13 additions & 2 deletions spec/unit/pool_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@
allow(metrics).to receive(:timing)
expect(metrics).to receive(:timing).with(/clone\./,/0/)
expect(provider).to receive(:create_vm).with(pool, String)
allow(provider).to receive(:get_vm_ip_address)
allow(provider).to receive(:get_vm_ip_address).and_return(1)
allow(subject).to receive(:get_domain_for_pool).and_return('example.com')
allow(subject).to receive(:get_dns_plugin_class_name_for_pool).and_return(dns_plugin)
allow(logger).to receive(:log)
Expand Down Expand Up @@ -1035,6 +1035,17 @@
end
end

context 'with a failure to get ip address after cloning' do
it 'should log a message that it completed being cloned' do
allow(metrics).to receive(:timing)
expect(metrics).to receive(:timing).with(/clone\./,/0/)
expect(provider).to receive(:create_vm).with(pool, String)
allow(provider).to receive(:get_vm_ip_address).and_return(nil)

expect{subject._clone_vm(pool,provider,dns_plugin)}.to raise_error(StandardError)
end
end

context 'with an error during cloning' do
before(:each) do
expect(provider).to receive(:create_vm).with(pool, String).and_raise('MockError')
Expand Down Expand Up @@ -1088,7 +1099,7 @@
allow(metrics).to receive(:timing)
expect(metrics).to receive(:timing).with(/clone\./,/0/)
expect(provider).to receive(:create_vm).with(pool, String)
allow(provider).to receive(:get_vm_ip_address).with(vm,pool)
allow(provider).to receive(:get_vm_ip_address).with(vm,pool).and_return(1)
allow(subject).to receive(:get_dns_plugin_class_name_for_pool).and_return(dns_plugin)
expect(dns_plugin).to receive(:create_or_replace_record)
allow(logger).to receive(:log)
Expand Down