(MAINT) Reduce redis Calls in API

The return values from most redis calls inform the caller of whether a
key or hash value exists. Several exists() calls can be removed in
favor of this approach.

Updated spec tests to account for a removal of exists() and ismember()
calls in API tests.
This commit is contained in:
Colin 2015-07-28 14:40:52 -07:00
parent 5789d2c708
commit acb95d34c8
2 changed files with 10 additions and 24 deletions

View file

@ -438,9 +438,7 @@ describe Vmpooler::API::V1 do
let(:config) { { auth: false } }
it 'does not delete a non-existant VM' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return false
expect(redis).not_to receive(:sismember)
expect(redis).not_to receive(:hgetall)
expect(redis).to receive(:hgetall).and_return({})
expect(redis).not_to receive(:sadd)
expect(redis).not_to receive(:srem)
@ -453,11 +451,9 @@ describe Vmpooler::API::V1 do
end
it 'deletes an existing VM' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return '1'
expect(redis).to receive(:sismember).with('vmpooler__running__pool1', 'testhost').and_return '1'
expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1"})
expect(redis).to receive(:srem).and_return(true)
expect(redis).to receive(:sadd)
expect(redis).to receive(:srem)
delete "#{prefix}/vm/testhost"
@ -473,11 +469,9 @@ describe Vmpooler::API::V1 do
context '(checked-out without token)' do
it 'deletes a VM without supplying a token' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return '1'
expect(redis).to receive(:sismember).with('vmpooler__running__pool1', 'testhost').and_return '1'
expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1"})
expect(redis).to receive(:srem).and_return(true)
expect(redis).to receive(:sadd)
expect(redis).to receive(:srem)
delete "#{prefix}/vm/testhost"
@ -490,7 +484,6 @@ describe Vmpooler::API::V1 do
context '(checked-out with token)' do
it 'fails to delete a VM without supplying a token' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return '1'
expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1", "token:token" => "abcdefghijklmnopqrstuvwxyz012345"})
expect(redis).not_to receive(:sadd)
expect(redis).not_to receive(:srem)
@ -504,11 +497,9 @@ describe Vmpooler::API::V1 do
end
it 'deletes a VM when token is supplied' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return '1'
expect(redis).to receive(:hgetall).with('vmpooler__vm__testhost').and_return({"template" => "pool1", "token:token" => "abcdefghijklmnopqrstuvwxyz012345"})
expect(redis).to receive(:sismember).with('vmpooler__running__pool1', 'testhost').and_return '1'
expect(redis).to receive(:srem).and_return(true)
expect(redis).to receive(:sadd)
expect(redis).to receive(:srem)
delete "#{prefix}/vm/testhost", "", {
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
@ -571,7 +562,6 @@ describe Vmpooler::API::V1 do
let(:config) { { auth: false } }
it 'reverts to a snapshot' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return(1)
expect(redis).to receive(:hget).with('vmpooler__vm__testhost', 'snapshot:testsnapshot').and_return(1)
expect(redis).to receive(:sadd)
@ -596,7 +586,6 @@ describe Vmpooler::API::V1 do
end
it 'reverts to a snapshot if authed' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return(1)
expect(redis).to receive(:hget).with('vmpooler__vm__testhost', 'snapshot:testsnapshot').and_return(1)
expect(redis).to receive(:sadd)