Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
Scenario manager: fix scenario update and add Status to protobuf (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
cj-chung authored Jul 6, 2022
1 parent d224241 commit 369d7a2
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 14 deletions.
14 changes: 12 additions & 2 deletions api/proto/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ enum ReturnCode {
FAILED = 1;
}

enum Status {
NONE = 0;
DEPLOYING = 1;
READY = 2;
DELETING = 3;
UPDATING = 4;
ERROR = 5;
DONE = 6;
}

message ReturnMessage {
ReturnCode return_code = 1;
string return_message = 2;
Expand All @@ -40,7 +50,7 @@ message InternalServiceInfo {
message InternalHostInfo {
string ip = 1;
repeated string routing_rules = 2;
string status = 3;
Status status = 3;
}

message InternalComputeInfo {
Expand All @@ -50,7 +60,7 @@ message InternalComputeInfo {
string ip = 4;
string mac = 5;
string veth = 6;
string status = 7;
Status status = 7;
}

message InternalSubnetInfo {
Expand Down
2 changes: 1 addition & 1 deletion api/proto/v1/compute.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ message InternalVMInfo {
string subnet_id = 5;
string security_group_id = 6;
string default_gateway = 7;
string status = 8;
Status status = 8;
}

message ReturnComputeMessage {
Expand Down
56 changes: 52 additions & 4 deletions services/scenario-manager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,46 @@ func TestScenarioActions(t *testing.T) {
//utils.AssertEqual(t, test.expectedBody, string(body), test.description)
}

func TestSAGetTopology(t *testing.T) {
var sa entities.ScenarioAction
sa.ScenarioId = "d6f044df409d4836930ee88b540b2610"
var ssa entities.ServiceAction
ssa.ServiceName = "topology"
ssa.Action = "CHECK"
sa.Services = append(sa.Services, ssa)

// Setup the app as it is done in the main function
app := Setup()

reqbody, _ := json.Marshal(sa)
req, _ := http.NewRequest(
"POST",
"/api/scenarios/actions",
bytes.NewReader(reqbody),
)
req.Header.Set("Content-Type", "application/json")

// Perform the request plain with the app.
// The -1 disables request latency.
res, err := app.Test(req, -1)

// verify that no error occured, that is not expected
utils.AssertEqual(t, false, err != nil, "deploy a scenario")

// Verify if the status code is as expected
utils.AssertEqual(t, 200, res.StatusCode, "deploy a scenario")

// Read the response body
//body, err := ioutil.ReadAll(res.Body)

// Reading the response body should work everytime, such that
// the err variable should be nil
// utils.AssertEqual(t, nil, err, test.description)

// Verify, that the reponse body equals the expected body
//utils.AssertEqual(t, test.expectedBody, string(body), test.description)
}

func TestGetScenarios(t *testing.T) {
tests := []struct {
description string
Expand Down Expand Up @@ -346,7 +386,7 @@ func TestPutOperations(t *testing.T) {

// Test input
route string
body map[string]string
body map[string]interface{}

// Expected output
expectedError bool
Expand All @@ -362,9 +402,17 @@ func TestPutOperations(t *testing.T) {
// expectedBody: "OK",
// },
{
description: "put a service",
route: "/api/service-config/508eecdd9d474fc388119601cc31e1c7",
body: map[string]string{"name": "service-test-2"},
description: "put a topology",
route: "/api/topologies/25203a13695a488bb4441bacb1251f2c",
body: map[string]interface{}{
"name": "topology-test-2",
"status": "NONE",
"number_of_vhosts": 10,
"number_of_racks": 2,
"vhosts_per_rack": 5,
"data_plane_cidr": "10.200.0.0/16",
"vnodes": []interface{}{map[string]interface{}{"name": "p1", "type": "vhost", "nics": []interface{}{map[string]interface{}{"name": "eth0", "ip": "10.0.0.1"}}}},
"vlinks": []interface{}{map[string]interface{}{"name": "v1", "from": "p1", "to": "p2"}}},
expectedError: false,
expectedCode: 200,
expectedBody: "OK",
Expand Down
64 changes: 57 additions & 7 deletions services/scenario-manager/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,64 @@ func UpdateChecker(src interface{}, upt interface{}) interface{} {
return upt
}
return src
// case []entities.Service:
// rv := reflect.TypeOf(upt)
// if rv.NumField() < 0 {
// return upt
// }
// return src
case int, uint, uint32:
if upt != 0 {
return upt
}
return src
case []string:
if len(upt.([]string)) > 0 {
return upt
}
return src
case []entities.Service:
if len(upt.([]entities.Service)) > 0 {
return upt
}
return src
case []entities.Image:
if len(upt.([]entities.Image)) > 0 {
return upt
}
return src
case []entities.VNode:
if len(upt.([]entities.VNode)) > 0 {
return upt
}
return src
case []entities.VLink:
if len(upt.([]entities.VLink)) > 0 {
return upt
}
return src
case []entities.VPCInfo:
if len(upt.([]entities.VPCInfo)) > 0 {
return upt
}
return src
case []entities.Router:
if len(upt.([]entities.Router)) > 0 {
return upt
}
return src
case []entities.Gateway:
if len(upt.([]entities.Gateway)) > 0 {
return upt
}
return src
case []entities.SecurityGroup:
if len(upt.([]entities.SecurityGroup)) > 0 {
return upt
}
return src
case []entities.Test:
if len(upt.([]entities.Test)) > 0 {
return upt
}
return src
default:
return src
}
return src
}

func EntityUpdateCheck(check func(interface{}, interface{}) interface{}, origin interface{}, update interface{}) {
Expand Down

0 comments on commit 369d7a2

Please sign in to comment.