vmpooler/spec/integration/dashboard_spec.rb
kirby@puppetlabs.com 528020fec7 (POOLER-109) Allow API to run independently
This commit updates vmpooler to allow the API component and dashboard to
run separately from pool_manager. Without this change vmpooler does not
offer a mechanism to run only the API, or pool_manager components.

Two instances of hardcoded puma environment settings are removed. This
is still set in the init script explicitly as well as via an environment
variable in the dockerfile.

To extend the mechanism of running the API or pool_manager components to
instances running in docker an entrypoint is added in the dockerfile.
The entrypoint allows a user to specify whether to run the API or
pool_manager components when running the application. The default
behavior is preserved where both components are run.

To support these changes vmpooler.rb is updated to allow more of the
configuration to be specified via individual environment variables. It
was already possible to specify the entire config block as an
environment variable, but this is more difficult to manage and less of a
standard implementation than specifying individual parameters. Where
specified environment variable options will override a value configured
via the configuration file or environment.

The running pool configuration when starting pool_manager is loaded to
redis at pool_manager start time. This allows the API to load the
running pool configuration from redis and be able to run without
requiring the pool configuration.

Lastly, the dockerfile leveraging entrypoint will no longer start
vmpooler with the init script or write logs to a file. Instead, LOGFILE
is set to /dev/stdout and the vmpooler application is started directly.
This behavior is preferred because the log file writes to disk are an
unnecessary overhead. Without this change the docker installation will
attempt to daemonize the vmpooler application and always requires puma.
2018-07-13 09:35:18 -07:00

170 lines
5 KiB
Ruby

require 'spec_helper'
require 'rack/test'
describe Vmpooler::API do
include Rack::Test::Methods
def app()
described_class
end
describe 'Dashboard' do
before(:each) do
redis.flushdb
end
context '/' do
before { get '/' }
it { expect(last_response.status).to eq(302) }
it { expect(last_response.location).to eq('http://example.org/dashboard/') }
end
context '/dashboard/' do
ENV['SITE_NAME'] = 'test pooler'
before do
get '/dashboard/'
end
it { expect(last_response).to be_ok }
it { expect(last_response.body).to match(/test pooler/) }
it { expect(last_response.body).not_to match(/<b>vmpooler<\/b>/) }
end
context 'unknown route' do
before { get '/doesnotexist' }
it { expect(last_response.status).to eq(404) }
it { expect(last_response.header['Content-Type']).to eq('application/json') }
it { expect(last_response.body).to eq(JSON.pretty_generate({ok: false})) }
end
describe '/dashboard/stats/vmpooler/pool' do
let(:config) { {
pools: [
{'name' => 'pool1', 'size' => 5},
{'name' => 'pool2', 'size' => 1}
],
graphite: {}
} }
before do
$config = config
app.settings.set :config, config
app.settings.set :redis, redis
app.settings.set :environment, :test
end
context 'without history param' do
it 'returns basic JSON' do
create_ready_vm('pool1', 'vm1')
create_ready_vm('pool1', 'vm2')
create_ready_vm('pool1', 'vm3')
create_ready_vm('pool2', 'vm4')
create_ready_vm('pool2', 'vm5')
get '/dashboard/stats/vmpooler/pool'
json_hash = {
pool1: {size: 5, ready: 3},
pool2: {size: 1, ready: 2}
}
expect(last_response).to be_ok
expect(last_response.body).to eq(JSON.pretty_generate(json_hash))
expect(last_response.header['Content-Type']).to eq('application/json')
end
end
context 'with history param' do
it 'returns JSON with zeroed history when redis does not have values' do
get '/dashboard/stats/vmpooler/pool', :history => true
json_hash = {
pool1: {size: 5, ready: 0, history: [0]},
pool2: {size: 1, ready: 0, history: [0]}
}
expect(last_response).to be_ok
expect(last_response.body).to eq(JSON.pretty_generate(json_hash))
expect(last_response.header['Content-Type']).to eq('application/json')
end
it 'returns JSON with history when redis has values' do
create_ready_vm('pool1', 'vm1')
create_ready_vm('pool1', 'vm2')
create_ready_vm('pool1', 'vm3')
create_ready_vm('pool2', 'vm4')
create_ready_vm('pool2', 'vm5')
get '/dashboard/stats/vmpooler/pool', :history => true
json_hash = {
pool1: {size: 5, ready: 3, history: [3]},
pool2: {size: 1, ready: 2, history: [2]}
}
expect(last_response).to be_ok
expect(last_response.body).to eq(JSON.pretty_generate(json_hash))
expect(last_response.header['Content-Type']).to eq('application/json')
end
end
end
describe '/dashboard/stats/vmpooler/running' do
let(:config) { {
pools: [
{'name' => 'pool-1', 'size' => 5},
{'name' => 'pool-2', 'size' => 1},
{'name' => 'diffpool-1', 'size' => 3}
],
graphite: {}
} }
before do
$config = config
app.settings.set :config, config
app.settings.set :redis, redis
app.settings.set :environment, :test
end
context 'without history param' do
it 'returns basic JSON' do
get '/dashboard/stats/vmpooler/running'
json_hash = {pool: {running: 0}, diffpool: {running: 0}}
expect(last_response).to be_ok
expect(last_response.body).to eq(JSON.pretty_generate(json_hash))
expect(last_response.header['Content-Type']).to eq('application/json')
end
it 'adds major correctly' do
create_running_vm('pool-1', 'vm1')
create_running_vm('pool-1', 'vm2')
create_running_vm('pool-1', 'vm3')
create_running_vm('pool-2', 'vm4')
create_running_vm('pool-2', 'vm5')
create_running_vm('pool-2', 'vm6')
create_running_vm('pool-2', 'vm7')
create_running_vm('pool-2', 'vm8')
create_running_vm('diffpool-1', 'vm9')
create_running_vm('diffpool-1', 'vm10')
get '/dashboard/stats/vmpooler/running'
json_hash = {pool: {running: 8}, diffpool: {running: 2}}
expect(last_response).to be_ok
expect(last_response.body).to eq(JSON.pretty_generate(json_hash))
expect(last_response.header['Content-Type']).to eq('application/json')
end
end
end
end
end