Skip to content

Commit

Permalink
Add CB-Tumblebug API calls to the test-client
Browse files Browse the repository at this point in the history
- Test CB-Tumblebug APIs by test-cb-tumblebug-apis.go
- Apply needed sections to test-client.go
- Reorder build sequence by execution order in Makefile
- Update gitignore
  • Loading branch information
yunkon-kim committed Nov 16, 2021
1 parent c4ab5e0 commit ff3e28d
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Ignore configuration directory
# to avoid leaking sensitive information and frequent update
poc-cb-net/config/**
config.yaml
log_conf.yaml
# Provide templates of configuration files
# for users to copy and edit
!poc-cb-net/config/template-*
Expand Down
15 changes: 3 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@ module github.com/cloud-barista/cb-larva
go 1.15

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/aokoli/goutils v1.1.1 // indirect
github.com/buger/jsonparser v1.1.1
github.com/cloud-barista/cb-log v0.4.0
github.com/envoyproxy/protoc-gen-validate v0.6.1 // indirect
github.com/go-ping/ping v0.0.0-20210506233800-ff8be3320020
github.com/go-resty/resty/v2 v2.7.0
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mwitkow/go-proto-validators v0.3.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pseudomuto/protoc-gen-doc v1.5.0 // indirect
github.com/rs/xid v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
Expand All @@ -35,7 +26,7 @@ require (
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20210913180222-943fd674d43e
golang.org/x/net v0.0.0-20211029224645-99673261e6eb
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211018162055-cf77aa76bad2
Expand Down
64 changes: 6 additions & 58 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions poc-cb-net/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

default:
@echo "Build"
go build -mod=mod -o ./cmd/admin-web/admin-web ./cmd/admin-web/admin-web.go
go build -mod=mod -o ./cmd/agent/agent ./cmd/agent/agent.go
go build -mod=mod -o ./cmd/controller/controller ./cmd/controller/controller.go
go build -mod=mod -o ./cmd/service/cladnet-service ./cmd/service/cladnet-service.go
go build -mod=mod -o ./cmd/admin-web/admin-web ./cmd/admin-web/admin-web.go
go build -mod=mod -o ./cmd/agent/agent ./cmd/agent/agent.go
go build -mod=mod -o ./cmd/test-client/test-client ./cmd/test-client/test-client.go

production:
Expand All @@ -13,10 +13,10 @@ production:
# Note - You can find possible platforms by 'go tool dist list' for GOOS and GOARCH
# Note - Using the -ldflags parameter can help set variable values at compile time.
# Note - Using the -s and -w linker flags can strip the debugging information.
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/admin-web/admin-web ./cmd/admin-web/admin-web.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/agent/agent ./cmd/agent/agent.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/controller/controller ./cmd/controller/controller.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/service/cladnet-service ./cmd/service/cladnet-service.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/admin-web/admin-web ./cmd/admin-web/admin-web.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/agent/agent ./cmd/agent/agent.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o ./cmd/test-client/test-client ./cmd/test-client/test-client.go

# cc:
Expand Down
22 changes: 22 additions & 0 deletions poc-cb-net/cmd/test-client/config/template-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# A config for the both cb-network controller and agent as follows:
etcd_cluster:
endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ]

# A config for the cb-network AdminWeb as follows:
admin_web:
host: "localhost"
port: "9999"

# A config for the cb-network agent as follows:
cb_network:
cladnet_id: "xxxx"
host_id: "" # if host_id is "" (empty string), the cb-network agent will use hostname.

# A config for the grpc as follows:
grpc:
service_endpoint: "localhost:8089"
server_port: "8089"
gateway_port: "8088"

demo_app:
is_run: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package main

import (
"fmt"
"time"

"github.com/go-resty/resty/v2"
)

func main() {

start := time.Now()

nsId := "ns01"
mcisId := "mcis01"

client := resty.New()
client.SetBasicAuth("default", "default")

// Step 1: Health-check CB-Tumblebug
fmt.Println("\n\n##### Start ---------- Health-check CB-Tumblebug")
resp, err := client.R().
SetHeader("Content-Type", "application/json").
Get("http://localhost:1323/tumblebug/health")

// Output print
fmt.Printf("\nError: %v\n", err)
fmt.Printf("Time: %v\n", resp.Time())
fmt.Printf("Body: %v\n", resp)

fmt.Println("##### End ---------- Health-check CB-Tumblebug")
fmt.Println("Sleep 5 sec ( _ _ )zZ")
time.Sleep(5 * time.Second)

// // Step 2: Create MCIS by (POST ​/ns​/{nsId}​/mcisDynamic Create MCIS Dynamically)
// fmt.Println("\n\n##### Start ---------- Create MCIS")
// reqBody := `{
// "description": "Made in CB-TB",
// "installMonAgent": "no",
// "label": "custom tag",
// "name": "mcis01",
// "vm": [
// {
// "commonImage": "ubuntu18.04",
// "commonSpec": "aws-ap-northeast-2-t2-large"
// },
// {
// "commonImage": "ubuntu18.04",
// "commonSpec": "azure-westus-standard-b2s"
// },
// {
// "commonImage": "ubuntu18.04",
// "commonSpec": "gcp-asia-east1-e2-standard-2"
// },
// {
// "commonImage": "ubuntu18.04",
// "commonSpec": "alibaba-ap-northeast-1-ecs-t5-lc1m2-large"
// }
// ]
// }`

// resp, err = client.R().
// SetHeader("Content-Type", "application/json").
// SetHeader("Accept", "application/json").
// SetPathParams(map[string]string{
// "nsId": nsId,
// }).
// SetBody(reqBody).
// Post("http://localhost:1323/tumblebug/ns/{nsId}/mcisDynamic")

// // Output print
// fmt.Printf("\nError: %v\n", err)
// fmt.Printf("Time: %v\n", resp.Time())
// fmt.Printf("Body: %v\n", resp)

// fmt.Println("##### End ---------- Create MCIS")
// fmt.Println("Sleep 10 sec ( _ _ )zZ")
// time.Sleep(10 * time.Second)

// // Step x: (Test) Send a command to specified MCIS
// fmt.Println("\n\n##### Start ---------- Send a command to specified MCIS")
// resp, err = client.R().
// SetHeader("Content-Type", "application/json").
// SetHeader("Accept", "application/json").
// SetPathParams(map[string]string{
// "nsId": nsId,
// "mcisId": mcisId,
// }).
// SetBody(`{"command": "hostname", "userName": "cb-user"}`).
// Post("http://localhost:1323/tumblebug/ns/{nsId}/cmd/mcis/{mcisId}")

// // Output print
// fmt.Printf("\nError: %v\n", err)
// fmt.Printf("Time: %v\n", resp.Time())
// fmt.Printf("Body: %v\n", resp)

// fmt.Println("##### End ---------- Send a command to specified MCIS")
// fmt.Println("Sleep 5 sec ( _ _ )zZ")
// time.Sleep(5 * time.Second)

// // Step 3: Get VM address spaces
// fmt.Println("\n\n##### Start ---------- Get VM address spaces")
// data := []byte(resp.String())

// vNetIds := []string{}

// jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
// vNetId, _ := jsonparser.GetString(value, "vNetId")
// vNetIds = append(vNetIds, vNetId)
// }, "vm")

// fmt.Printf("vNetIds: %#v\n", vNetIds)

// ipNets := []string{}

// for _, v := range vNetIds {

// // Get VNet
// // curl -X GET "http://localhost:1323/tumblebug/ns/ns01/resources/vNet/ns01-systemdefault-aws-ap-northeast-2" -H "accept: application/json"
// fmt.Printf("\nvNetId: %v\n", v)
// resp, err = client.R().
// SetHeader("Content-Type", "application/json").
// SetHeader("Accept", "application/json").
// SetPathParams(map[string]string{
// "nsId": nsId,
// "vNetId": v,
// }).
// Get("http://localhost:1323/tumblebug/ns/{nsId}/resources/vNet/{vNetId}")

// // Output print
// fmt.Printf("\nError: %v\n", err)
// fmt.Printf("Time: %v\n", resp.Time())
// fmt.Printf("Body: %v\n", resp)

// data := []byte(resp.String())

// ipNet, _ := jsonparser.GetString(data, "subnetInfoList", "[0]", "IPv4_CIDR")
// // trimmedIpNet := strings.Trim(ipNet, "\n")
// ipNets = append(ipNets, ipNet)
// }

// fmt.Printf("IPNets: %#v\n", ipNets)

// fmt.Println("##### End ---------- Get VM address spaces")
// fmt.Println("Sleep 10 sec ( _ _ )zZ")
// time.Sleep(10 * time.Second)

// Step 4: Delete MCIS
// curl -X DELETE "http://localhost:1323/tumblebug/ns/ns01/mcis/mcis01?option=terminate" -H "accept: application/json"
fmt.Println("\n\n##### Start ---------- Delete MCIS")
resp, err = client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetPathParams(map[string]string{
"nsId": nsId,
"mcisId": mcisId,
}).
SetQueryParams(map[string]string{
"option": "terminate",
}).
Delete("http://localhost:1323/tumblebug/ns/{nsId}/mcis/{mcisId}")

// Output print
fmt.Printf("\nError: %v\n", err)
fmt.Printf("Time: %v\n", resp.Time())
fmt.Printf("Body: %v\n", resp)

fmt.Println("##### End ---------- Delete MCIS")
fmt.Println("Sleep 5 sec ( _ _ )zZ")
time.Sleep(5 * time.Second)

// Step 5: Delete defaultResources
// curl -X DELETE "http://localhost:1323/tumblebug/ns/ns01/defaultResources" -H "accept: application/json"
fmt.Println("\n\n##### Start ---------- Delete defaultResources")
resp, err = client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetPathParams(map[string]string{
"nsId": nsId,
}).
Delete("http://localhost:1323/tumblebug/ns/{nsId}/defaultResources")

// Output print
fmt.Printf("\nError: %v\n", err)
fmt.Printf("Time: %v\n", resp.Time())
fmt.Printf("Body: %v\n", resp)

fmt.Println("##### End ---------- Delete defaultResources")

elapsed := time.Since(start)
fmt.Printf("Elapsed time: %s\n", elapsed)
}
Loading

0 comments on commit ff3e28d

Please sign in to comment.