Skip to content

Commit

Permalink
Fixed Issue 80: Modified the test framework for tink repo
Browse files Browse the repository at this point in the history
This framework was written a while ago but is commented and there have been a lot of changes since then.
1. Remove the target concepts completely
2. Changed the way of writting templates
3. Changed the way of creating workflows
4. Generating certs are not the part of docker-compose anymore

TODO:
This framework works well for single worker. There are few changes required in the framework to make it work for multiple workers
  • Loading branch information
parauliya committed Jun 18, 2020
1 parent db1c9c2 commit b678d32
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 344 deletions.
158 changes: 0 additions & 158 deletions test-docker-compose.yml

This file was deleted.

5 changes: 1 addition & 4 deletions test/actions/update_data/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
FROM bash
ADD hello_world.sh /bin/hello_world.sh
RUN chmod +x /bin/hello_world.sh
#CMD echo '{"action_01": "data_01"}' > /workflow/data
ENTRYPOINT [ "/bin/hello_world.sh" ]
CMD echo '{"action_01": "data_01"}' > /workflow/data
2 changes: 1 addition & 1 deletion test/data/hardware/hardware_1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d1",
"allow_pxe": true,
"arch": "x86_64",
"bonding_mode": 4,
"efi_boot": true,
"facility_code": "ewr1",
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d1",
"instance": {
"allow_pxe": true,
"always_pxe": true,
Expand Down
2 changes: 1 addition & 1 deletion test/data/hardware/hardware_2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d2",
"allow_pxe": true,
"arch": "x86_64",
"bonding_mode": 4,
"efi_boot": true,
"facility_code": "ewr1",
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d2",
"instance": {
"allow_pxe": true,
"always_pxe": true,
Expand Down
2 changes: 1 addition & 1 deletion test/data/template/sample_1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks:
environment:
NGINX_HOST: 192.168.1.2
- name: "update_db"
image: update-data
image: overwrite-data
timeout: 50
environment:
MIRROR_HOST: 192.168.1.3
141 changes: 71 additions & 70 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
package e2e

//import (
// "os"
// "time"
// "testing"
//
// "github.com/tinkerbell/tink/client"
// "github.com/tinkerbell/tink/protos/workflow"
// "github.com/tinkerbell/tink/test/framework"
// "github.com/sirupsen/logrus"
//)
//
//var log *logrus.Logger = framework.Log
//
//func TestMain(m *testing.M) {
// log.Infoln("########Creating Setup########")
// time.Sleep(10 * time.Second)
// err := framework.StartStack()
// if err != nil {
// os.Exit(1)
// }
// os.Setenv("TINKERBELL_GRPC_AUTHORITY", "127.0.0.1:42113")
// os.Setenv("TINKERBELL_CERT_URL", "http://127.0.0.1:42114/cert")
// client.Setup()
// log.Infoln("########Setup Created########")
//
// log.Infoln("Creating hardware inventory")
// //push hardware data into hardware table
// hwData := []string{"hardware_1.json", "hardware_2.json"}
// err = framework.PushHardwareData(hwData)
// if err != nil {
// log.Errorln("Failed to push hardware inventory : ", err)
// os.Exit(2)
// }
// log.Infoln("Hardware inventory created")
//
// log.Infoln("########Starting Tests########")
// status := m.Run()
// log.Infoln("########Finished Tests########")
// log.Infoln("########Removing setup########")
// //err = framework.TearDown()
// if err != nil {
// os.Exit(3)
// }
// log.Infoln("########Setup removed########")
// os.Exit(status)
//}
//
//var testCases = map[string]struct {
// hardware string
// template string
// workers int64
// expected workflow.ActionState
// ephData string
//}{
// "testWfWithWorker": {"hardware_1.json", "sample_1", 1, workflow.ActionState_ACTION_SUCCESS, `{"action_02": "data_02"}`},
// "testWfTimeout": {"hardware_1.json", "sample_2", 1, workflow.ActionState_ACTION_TIMEOUT, `{"action_01": "data_01"}`},
// //"testWfWithMultiWorkers": {"hardware_1.json", "sample_3", 2, workflow.ActionState_ACTION_SUCCESS, `{"action_01": "data_01"}`},
//}
//
//var runTestMap = map[string]func(t *testing.T){
// "testWfWithWorker": TestWfWithWorker,
// "testWfTimeout": TestWfTimeout,
// //"testWfWithMultiWorkers": TestWfWithMultiWorkers,
//}
//
//func TestE2E(t *testing.T) {
// for key, val := range runTestMap {
// t.Run(key, val)
// }
//}
import (
"os"
"testing"
"time"

"github.com/sirupsen/logrus"
"github.com/tinkerbell/tink/client"
"github.com/tinkerbell/tink/protos/workflow"
"github.com/tinkerbell/tink/test/framework"
)

var log *logrus.Logger = framework.Log

func TestMain(m *testing.M) {
log.Infoln("########Creating Setup########")
time.Sleep(10 * time.Second)
err := framework.StartStack()
if err != nil {
os.Exit(1)
}
os.Setenv("TINKERBELL_GRPC_AUTHORITY", "127.0.0.1:42113")
os.Setenv("TINKERBELL_CERT_URL", "http://127.0.0.1:42114/cert")
client.Setup()
log.Infoln("########Setup Created########")

log.Infoln("Creating hardware inventory")
//push hardware data into hardware table
hwData := []string{"hardware_1.json", "hardware_2.json"}
err = framework.PushHardwareData(hwData)
if err != nil {
log.Errorln("Failed to push hardware inventory : ", err)
os.Exit(2)
}
log.Infoln("Hardware inventory created")

log.Infoln("########Starting Tests########")
status := m.Run()
log.Infoln("########Finished Tests########")
log.Infoln("########Removing setup########")
//err = framework.TearDown()
if err != nil {
os.Exit(3)
}
log.Infoln("########Setup removed########")
os.Exit(status)
}

var testCases = map[string]struct {
hardware string
hMAC string
template string
workers int64
expected workflow.ActionState
ephData string
}{
"testWfWithWorker": {"hardware_1.json", "98:03:9b:89:d7:ba", "sample_1", 1, workflow.ActionState_ACTION_SUCCESS, `{"action_02": "data_02"}`},
"testWfTimeout": {"hardware_1.json", "98:03:9b:89:d7:ba", "sample_2", 1, workflow.ActionState_ACTION_TIMEOUT, `{"action_01": "data_01"}`},
//"testWfWithMultiWorkers": {"hardware_1.json", "sample_3", 2, workflow.ActionState_ACTION_SUCCESS, `{"action_01": "data_01"}`},
}

var runTestMap = map[string]func(t *testing.T){
"testWfWithWorker": TestWfWithWorker,
"testWfTimeout": TestWfTimeout,
//"testWfWithMultiWorkers": TestWfWithMultiWorkers,
}

func TestE2E(t *testing.T) {
for key, val := range runTestMap {
t.Run(key, val)
}
}
11 changes: 6 additions & 5 deletions test/framework/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func buildCerts(filepath string) error {
cmd := exec.Command("/bin/sh", "-c", "docker-compose -f "+filepath+" up --build certs")
cmd := exec.Command("/bin/sh", "-c", "./generate_certs.sh")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
Expand Down Expand Up @@ -59,7 +59,7 @@ func removeWorkerImage() error {
}

func createWorkerImage() error {
cmd := exec.Command("/bin/sh", "-c", "docker build -t worker ../worker/")
cmd := exec.Command("/bin/sh", "-c", "docker build -t worker ../cmd/tink-worker/")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
Expand Down Expand Up @@ -94,15 +94,15 @@ func initializeLogger() {
}
} else {
logger.SetLevel(logrus.InfoLevel)
logger.Errorln("Variable TEST_LOG_LEVEL is not set. Default is Info.")
logger.Errorln("Variable TEST_LOG_LEVEL is not set. Default is INFO.")
}
logger.SetFormatter(&logrus.JSONFormatter{})
}

// StartStack : Starting stack
func StartStack() error {
// Docker compose file for starting the containers
filepath := "../test-docker-compose.yml"
filepath := "../deploy/docker-compose.yml"

// Initialize logger
initializeLogger()
Expand Down Expand Up @@ -153,9 +153,10 @@ func StartStack() error {
initializeLogger()

// Start other containers
cmd := exec.Command("/bin/sh", "-c", "docker-compose -f "+filepath+" up --build -d")
cmd := exec.Command("/bin/sh", "-c", "docker-compose -f "+filepath+" up --build -d tink-server ")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
//sleep(10)
return nil
}
2 changes: 1 addition & 1 deletion test/framework/tearDown.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// TearDown : remove the setup
func TearDown() error {
cmd := exec.Command("/bin/sh", "-c", "docker-compose rm -svf")
cmd := exec.Command("/bin/sh", "-c", "docker-compose -f ../deploy/docker-compose rm -svf")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
Expand Down
Loading

0 comments on commit b678d32

Please sign in to comment.