-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
150 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# How to use: See .github/workflows/rspec.yml | ||
|
||
# Standard library | ||
require 'json' | ||
require 'yaml' | ||
|
||
# Gems | ||
require 'rspec' | ||
require 'rack/test' | ||
|
||
# Engine libraries | ||
require 'opennebula' | ||
require 'json-schema' | ||
require_relative '../src/client/client' | ||
require_relative '../src/server/runtime' | ||
|
||
$LOAD_PATH << "#{__dir__}/lib" | ||
require 'log' | ||
require 'crud' | ||
|
||
SR = 'Serverless Runtime' | ||
|
||
# Initialize Provision Engine ruby client | ||
conf_engine = YAML.load_file('/etc/provision-engine/engine.conf') | ||
endpoint = "http://#{conf_engine[:host]}:#{conf_engine[:port]}" | ||
auth = ENV['TESTS_AUTH'] || 'oneadmin:opennebula' | ||
engine_client = ProvisionEngine::Client.new(endpoint, auth) | ||
|
||
# Initialize test configuration | ||
rspec = { | ||
:conf => YAML.load_file('./conf.yaml'), | ||
:engine_client => engine_client, | ||
:sr_templates => [] | ||
} | ||
|
||
describe 'Provision Engine API' do | ||
include Rack::Test::Methods | ||
|
||
let(:rspec) { rspec } | ||
|
||
# test every serverless runtime template available under template directory | ||
Dir.entries("#{__dir__}/templates").select do |sr_template| | ||
# blacklist template from tests by changing preffix or suffix | ||
next unless sr_template.start_with?('sr_') && sr_template.end_with?('.json') | ||
|
||
include_context('crud', sr_template) | ||
end | ||
|
||
include_context('inspect logs') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
RSpec.shared_context 'crud' do |sr_template| | ||
it "create a #{SR}" do | ||
pp "Requesting #{SR} creation with template #{sr_template}" | ||
|
||
specification = File.read("templates/#{sr_template}") | ||
specification = JSON.parse(specification) | ||
|
||
response = rspec[:engine_client].create(specification) | ||
|
||
expect(response.code.to_i).to eq(201) | ||
|
||
runtime = JSON.parse(response.body) | ||
pp runtime | ||
|
||
rspec[:id] = runtime['SERVERLESS_RUNTIME']['ID'].to_i | ||
|
||
validation = ProvisionEngine::ServerlessRuntime.validate(runtime) | ||
pp validation[1] | ||
|
||
expect(validation[0]).to be(true) | ||
end | ||
|
||
it "read a #{SR}" do | ||
attempts = rspec[:conf][:timeouts][:get] | ||
|
||
1.upto(attempts) do |t| | ||
sleep 1 | ||
expect(t == attempts).to be(false) | ||
|
||
response = rspec[:engine_client].get(rspec[:id]) | ||
|
||
expect(response.code.to_i).to eq(200) | ||
|
||
runtime = JSON.parse(response.body) | ||
pp runtime | ||
|
||
# TODO: Check flow service for failed states like 7 => FAILED_DEPLOYING | ||
next unless runtime['SERVERLESS_RUNTIME']['FAAS']['STATE'] == 'ACTIVE' | ||
|
||
break | ||
end | ||
end | ||
|
||
it "not update #{SR}" do | ||
response = rspec[:engine_client].update(rspec[:id], {}) | ||
|
||
expect(response.code.to_i).to eq(501) | ||
|
||
body = JSON.parse(response.body) | ||
pp body | ||
|
||
expect(body).to eq('Serverless Runtime update not implemented') | ||
end | ||
|
||
it "delete a #{SR}" do | ||
attempts = rspec[:conf][:timeouts][:get] | ||
|
||
1.upto(attempts) do |t| | ||
sleep 1 | ||
expect(t == attempts).to be(false) | ||
|
||
response = rspec[:engine_client].delete(rspec[:id]) | ||
rc = response.code.to_i | ||
|
||
next unless rc == 204 | ||
|
||
expect(rc).to eq(204) | ||
|
||
break | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
RSpec.shared_context 'inspect logs' do | ||
it 'print every log' do | ||
logcation = '/var/log/provision-engine' | ||
sep = '-'*32 | ||
pp sep | ||
|
||
Dir.entries(logcation).each do |entry| | ||
next if ['.', '..'].include?(entry) | ||
|
||
pp entry | ||
pp sep | ||
pp File.read("#{logcation}/#{entry}") | ||
pp sep | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.