From 8ffcafdc99754cd5bf54a58ded5ffeade44b352f Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Tue, 12 May 2020 11:32:53 -0700 Subject: [PATCH] Ensure domain is included in the reply for post and get ondemandvm when configured --- lib/vmpooler/api/v1.rb | 2 ++ spec/integration/api/v1/ondemandvm_spec.rb | 41 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index c6aaf3a..ce6423b 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -380,6 +380,7 @@ module Vmpooler backend.hget('vmpooler__token__' + request.env['HTTP_X_AUTH_TOKEN'], 'user')) end + result['domain'] = config['domain'] if config['domain'] result[:ok] = true result end @@ -951,6 +952,7 @@ module Vmpooler instances = backend.smembers("vmpooler__#{request_id}__#{pool_alias}__#{pool}") result[pool_alias] = { 'hostname': instances } end + result['domain'] = config['domain'] if config['domain'] status 200 elsif request_hash['status'] == 'failed' result['ready'] = false diff --git a/spec/integration/api/v1/ondemandvm_spec.rb b/spec/integration/api/v1/ondemandvm_spec.rb index 1e0eae5..0665973 100644 --- a/spec/integration/api/v1/ondemandvm_spec.rb +++ b/spec/integration/api/v1/ondemandvm_spec.rb @@ -86,6 +86,24 @@ describe Vmpooler::API::V1 do expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'poolone:pool1:1') post "#{prefix}/ondemandvm", '{"poolone":"1"}' end + + context 'with domain set in the config' do + let(:domain) { 'example.com' } + before(:each) do + config[:config]['domain'] = domain + end + + it 'should include domain in the return reply' do + post "#{prefix}/ondemandvm", '{"poolone":"1"}' + expect_json(true, 201) + expected = { + "ok": true, + "request_id": uuid, + "domain": domain + } + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + end + end end context 'with a resource request that exceeds the specified limit' do @@ -225,6 +243,29 @@ describe Vmpooler::API::V1 do } expect(last_response.body).to eq(JSON.pretty_generate(expected)) end + + context 'with domain set' do + let(:domain) { 'example.com' } + before(:each) do + config[:config]['domain'] = domain + end + + it 'should include the domain in the result' do + get "#{prefix}/ondemandvm/#{uuid}" + expected = { + "ok": true, + "request_id": uuid, + "ready": true, + "pool1": { + "hostname": [ + vmname + ] + }, + "domain": domain + } + expect(last_response.body).to eq(JSON.pretty_generate(expected)) + end + end end context 'with a deleted request' do