From c0cf772281408f43bfba647b27e99f9ff98b1dfe Mon Sep 17 00:00:00 2001 From: Rick Bradley Date: Tue, 24 May 2016 11:27:36 -0500 Subject: [PATCH] (QENG-3919) Add (failing) specs for POST /vm/pool1+pool2 usages This exposes the old (bad) behavior on this other code path. Will fix this up next. --- spec/vmpooler/api/v1_spec.rb | 114 +++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/spec/vmpooler/api/v1_spec.rb b/spec/vmpooler/api/v1_spec.rb index 33cd5f8..41d9bf2 100644 --- a/spec/vmpooler/api/v1_spec.rb +++ b/spec/vmpooler/api/v1_spec.rb @@ -531,6 +531,120 @@ describe Vmpooler::API::V1 do expect_json(ok = true, http = 200) end + it 'returns multiple VMs even when multiple instances from the same pool are requested' do + post "#{prefix}/vm/pool1+pool1+pool2", '' + + expected = { + ok: true, + pool1: { + hostname: [ 'abcdefghijklmnop', 'abcdefghijklmnop' ] + }, + pool2: { + hostname: 'qrstuvwxyz012345' + } + } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + + expect_json(ok = true, http = 200) + end + + it 'returns multiple VMs even when multiple instances from multiple pools are requested' do + post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", '' + + expected = { + ok: true, + pool1: { + hostname: [ 'abcdefghijklmnop', 'abcdefghijklmnop' ] + }, + pool2: { + hostname: [ 'qrstuvwxyz012345', 'qrstuvwxyz012345', 'qrstuvwxyz012345' ] + } + } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + + expect_json(ok = true, http = 200) + end + + it 'fails when not all requested vms can be allocated' do + allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop' + allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return nil + allow(redis).to receive(:spush).with("vmpooler__ready__pool1", "abcdefghijklmnop") + + post "#{prefix}/vm/pool1+pool2", '' + + expected = { ok: false } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + expect_json(ok = false, http = 200) # which HTTP status code? + end + + it 'returns any checked out vms to their pools when not all requested vms can be allocated' do + allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop' + allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return nil + expect(redis).to receive(:spush).with("vmpooler__ready__pool1", "abcdefghijklmnop") + + post "#{prefix}/vm/pool1+pool2", '' + + expected = { ok: false } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + expect_json(ok = false, http = 200) # which HTTP status code? + end + + it 'fails when not all requested vms can be allocated, when requesting multiple instances from a pool' do + allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop' + allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return nil + allow(redis).to receive(:spush).with("vmpooler__ready__pool1", "abcdefghijklmnop") + + post "#{prefix}/vm/pool1+pool1+pool2", '' + + expected = { ok: false } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + expect_json(ok = false, http = 200) # which HTTP status code? + end + + it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from a pool' do + allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop' + allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return nil + expect(redis).to receive(:spush).with("vmpooler__ready__pool1", "abcdefghijklmnop").exactly(2).times + + post "#{prefix}/vm/pool1+pool1+pool2", '' + + expected = { ok: false } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + expect_json(ok = false, http = 200) # which HTTP status code? + end + + it 'fails when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do + allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop' + allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return nil + allow(redis).to receive(:spush).with("vmpooler__ready__pool1", "abcdefghijklmnop") + + post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", '' + + expected = { ok: false } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + expect_json(ok = false, http = 200) # which HTTP status code? + end + + it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do + allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop' + allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return nil + expect(redis).to receive(:spush).with("vmpooler__ready__pool1", "abcdefghijklmnop").exactly(2).times + + post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", '' + + expected = { ok: false } + + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + expect_json(ok = false, http = 200) # which HTTP status code? + end + context '(auth not configured)' do let(:config) { { auth: false } }