Skip to content

Commit

Permalink
Automated tests with Github Actions (#24)
Browse files Browse the repository at this point in the history
(cherry picked from commit 22aed97)
  • Loading branch information
dann1 authored and tinova committed Sep 7, 2023
1 parent 9a33036 commit a1b1a15
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 51 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/rspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test
on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.2']
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install
run: ./install.sh

- name: Configure
run: cd ./tests && ./prepare.rb http://3.72.81.234:2633/RPC2 http://3.72.81.234:2474 0 1

# Maybe should be included in rspec
- name: Start engine
run: provision-engine-server start && sleep 2

- name: Test
run: cd ./tests && rspec tests.rb

# Maybe should be included in rspec
- name: Stop engine engine
run: provision-engine-server stop

- name: Uninstall
run: ./install.sh purge
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vs*
Gemfile.lock
vendor/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Provisioning Engine

[![Test](https://github.com/dann1/provisioning-engine/actions/workflows/rspec.yaml/badge.svg)](https://github.com/dann1/provisioning-engine/actions/workflows/rspec.yaml)

Provisioning Engine acts as a entry point for the Device Runtime, instructs the Cloud-Edge Manager to spawn new FaaS/DaaS Runtimes and returns the endpoint back to the device. Afterwards, manages the lifetime of the FaaS/DaaS Runtimes

## Installation
Expand Down
7 changes: 3 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

install() {
for gem in "${gems[@]}"; do
is_gem_installed "$gem" || gem install "$gem"
is_gem_installed "$gem" || sudo gem install "$gem"
done

[ -d "$CONF_DIR" ] || sudo mkdir "$CONF_DIR"
Expand All @@ -29,7 +29,6 @@ install() {
}

postinstall() {
[ -L "$EXEC_PATH" ] || sudo ln -s "${INSTALL_DIR}/server.rb" "$EXEC_PATH"
echo "provision engine installed at ${INSTALL_DIR}"
echo "run engine with ${EXEC_PATH} start/stop"
}
Expand All @@ -52,11 +51,11 @@ clean() {
}

is_gem_installed() {
gem list -i "$1" >/dev/null 2>&1
sudo gem list -i "$1" >/dev/null 2>&1
}

remove_orphan_gem() {
gem uninstall -a --abort-on-dependent "$1" >/dev/null 2>&1
sudo gem uninstall -a --abort-on-dependent "$1" >/dev/null 2>&1
}

CONF_DIR="/etc/provision-engine"
Expand Down
6 changes: 5 additions & 1 deletion src/server/cli/provision-engine-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

PE="provision-engine"
PES="${PE}-server"
LOG="/var/log/${PE}/api.log"
LOG_DIR="/var/log/${PE}"
LOG="${LOG_DIR}/api.log"
SERVER="/opt/${PE}/server.rb"
PID="/tmp/${PES}.pid"

Expand All @@ -15,12 +16,15 @@ start() {

[ "$1" == 'debug' ] && cmd="ruby -dw" || cmd="ruby"

[ -d $LOG_DIR ] || sudo mkdir $LOG_DIR && sudo chown "$USER" $LOG_DIR

# start server in background due to sinatra locking the prompt. Redirect sinatra output to logfile
if $cmd $SERVER > $LOG 2>&1 & then
echo "${PES} started"
echo $! > $PID
else
echo "failed to start ${PES}. Check ${LOG}" >&2
exit 1
fi
}

Expand Down
2 changes: 1 addition & 1 deletion tests/conf.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
:engine_endpoint: 'http://localhost:1337/'
:engine_endpoint: 'http://localhost:1337/' # TODO: load from engine.conf
:auth: 'oneadmin:opennebula'
44 changes: 44 additions & 0 deletions tests/prepare.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby
require 'yaml'
require 'tempfile'

# How to use
# ./prepare.rb http://one_host:2633/RPC2 http://one_host:2474 0 1

GEMS = ['rspec', 'rack-test'] # gems required for running the tests
CONF_PATH = '/etc/provision-engine/engine.conf'

def install_gems
GEMS.each do |gem|
system("sudo gem list -i #{gem} || sudo gem install #{gem}")
end
end

def configure_engine(oned, oneflow, nature, nature_s3)
config = YAML.load_file(CONF_PATH)

# Update the values
config[:one_xmlrpc] = oned if oned
config[:oneflow_server] = oneflow if oneflow
config[:mapping][:nature] = nature if nature
config[:mapping][:"nature-s3"] = nature_s3 if nature_s3

tempfile = Tempfile.new('engine.conf')
tempfile.write(config)
tempfile.flush

# Write back to the file
File.open(tempfile, 'w') do |f|
f.write(config.to_yaml)
end

system("sudo mv #{tempfile.path} #{CONF_PATH}")
end

endpoint_oned = ARGV[0]
endpoint_oneflow = ARGV[1]
nature = ARGV[2].to_i
nature_s3 = ARGV[3].to_i

install_gems
configure_engine(endpoint_oned, endpoint_oneflow, nature, nature_s3)
41 changes: 0 additions & 41 deletions tests/prepare.sh

This file was deleted.

24 changes: 20 additions & 4 deletions tests/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
end

it "should get #{SR} info" do
1.upto(30) do |t|
expect(t == 30).to be(false)
attempts = 30

1.upto(attempts) do |t|
expect(t == attempts).to be(false)

response = engine_client.get(id)

Expand All @@ -63,6 +65,7 @@

body = runtime_body(document)

# Even though the VM reaches RUNNING, the service might not
next unless body['FAAS']['STATE'] == 'ACTIVE'

break
Expand All @@ -81,9 +84,22 @@
end

it "should delete a #{SR}" do
response = engine_client.delete(id)
attempts = 10

1.upto(attempts) do |t|
sleep 1

expect(t == attempts).to be(false)

response = engine_client.delete(id)
rc = response.code.to_i

expect(response.code.to_i).to eq(204)
next unless rc == 204

expect(rc).to eq(204)

break
end
end
end

Expand Down

0 comments on commit a1b1a15

Please sign in to comment.