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

Commit 369d7a2

Browse files
authored
Scenario manager: fix scenario update and add Status to protobuf (#45)
1 parent d224241 commit 369d7a2

File tree

4 files changed

+122
-14
lines changed

4 files changed

+122
-14
lines changed

api/proto/v1/common.proto

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ enum ReturnCode {
1919
FAILED = 1;
2020
}
2121

22+
enum Status {
23+
NONE = 0;
24+
DEPLOYING = 1;
25+
READY = 2;
26+
DELETING = 3;
27+
UPDATING = 4;
28+
ERROR = 5;
29+
DONE = 6;
30+
}
31+
2232
message ReturnMessage {
2333
ReturnCode return_code = 1;
2434
string return_message = 2;
@@ -40,7 +50,7 @@ message InternalServiceInfo {
4050
message InternalHostInfo {
4151
string ip = 1;
4252
repeated string routing_rules = 2;
43-
string status = 3;
53+
Status status = 3;
4454
}
4555

4656
message InternalComputeInfo {
@@ -50,7 +60,7 @@ message InternalComputeInfo {
5060
string ip = 4;
5161
string mac = 5;
5262
string veth = 6;
53-
string status = 7;
63+
Status status = 7;
5464
}
5565

5666
message InternalSubnetInfo {

api/proto/v1/compute.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ message InternalVMInfo {
6666
string subnet_id = 5;
6767
string security_group_id = 6;
6868
string default_gateway = 7;
69-
string status = 8;
69+
Status status = 8;
7070
}
7171

7272
message ReturnComputeMessage {

services/scenario-manager/main_test.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,46 @@ func TestScenarioActions(t *testing.T) {
277277
//utils.AssertEqual(t, test.expectedBody, string(body), test.description)
278278
}
279279

280+
func TestSAGetTopology(t *testing.T) {
281+
var sa entities.ScenarioAction
282+
sa.ScenarioId = "d6f044df409d4836930ee88b540b2610"
283+
var ssa entities.ServiceAction
284+
ssa.ServiceName = "topology"
285+
ssa.Action = "CHECK"
286+
sa.Services = append(sa.Services, ssa)
287+
288+
// Setup the app as it is done in the main function
289+
app := Setup()
290+
291+
reqbody, _ := json.Marshal(sa)
292+
req, _ := http.NewRequest(
293+
"POST",
294+
"/api/scenarios/actions",
295+
bytes.NewReader(reqbody),
296+
)
297+
req.Header.Set("Content-Type", "application/json")
298+
299+
// Perform the request plain with the app.
300+
// The -1 disables request latency.
301+
res, err := app.Test(req, -1)
302+
303+
// verify that no error occured, that is not expected
304+
utils.AssertEqual(t, false, err != nil, "deploy a scenario")
305+
306+
// Verify if the status code is as expected
307+
utils.AssertEqual(t, 200, res.StatusCode, "deploy a scenario")
308+
309+
// Read the response body
310+
//body, err := ioutil.ReadAll(res.Body)
311+
312+
// Reading the response body should work everytime, such that
313+
// the err variable should be nil
314+
// utils.AssertEqual(t, nil, err, test.description)
315+
316+
// Verify, that the reponse body equals the expected body
317+
//utils.AssertEqual(t, test.expectedBody, string(body), test.description)
318+
}
319+
280320
func TestGetScenarios(t *testing.T) {
281321
tests := []struct {
282322
description string
@@ -346,7 +386,7 @@ func TestPutOperations(t *testing.T) {
346386

347387
// Test input
348388
route string
349-
body map[string]string
389+
body map[string]interface{}
350390

351391
// Expected output
352392
expectedError bool
@@ -362,9 +402,17 @@ func TestPutOperations(t *testing.T) {
362402
// expectedBody: "OK",
363403
// },
364404
{
365-
description: "put a service",
366-
route: "/api/service-config/508eecdd9d474fc388119601cc31e1c7",
367-
body: map[string]string{"name": "service-test-2"},
405+
description: "put a topology",
406+
route: "/api/topologies/25203a13695a488bb4441bacb1251f2c",
407+
body: map[string]interface{}{
408+
"name": "topology-test-2",
409+
"status": "NONE",
410+
"number_of_vhosts": 10,
411+
"number_of_racks": 2,
412+
"vhosts_per_rack": 5,
413+
"data_plane_cidr": "10.200.0.0/16",
414+
"vnodes": []interface{}{map[string]interface{}{"name": "p1", "type": "vhost", "nics": []interface{}{map[string]interface{}{"name": "eth0", "ip": "10.0.0.1"}}}},
415+
"vlinks": []interface{}{map[string]interface{}{"name": "v1", "from": "p1", "to": "p2"}}},
368416
expectedError: false,
369417
expectedCode: 200,
370418
expectedBody: "OK",

services/scenario-manager/utils/utils.go

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,64 @@ func UpdateChecker(src interface{}, upt interface{}) interface{} {
2828
return upt
2929
}
3030
return src
31-
// case []entities.Service:
32-
// rv := reflect.TypeOf(upt)
33-
// if rv.NumField() < 0 {
34-
// return upt
35-
// }
36-
// return src
31+
case int, uint, uint32:
32+
if upt != 0 {
33+
return upt
34+
}
35+
return src
36+
case []string:
37+
if len(upt.([]string)) > 0 {
38+
return upt
39+
}
40+
return src
41+
case []entities.Service:
42+
if len(upt.([]entities.Service)) > 0 {
43+
return upt
44+
}
45+
return src
46+
case []entities.Image:
47+
if len(upt.([]entities.Image)) > 0 {
48+
return upt
49+
}
50+
return src
51+
case []entities.VNode:
52+
if len(upt.([]entities.VNode)) > 0 {
53+
return upt
54+
}
55+
return src
56+
case []entities.VLink:
57+
if len(upt.([]entities.VLink)) > 0 {
58+
return upt
59+
}
60+
return src
61+
case []entities.VPCInfo:
62+
if len(upt.([]entities.VPCInfo)) > 0 {
63+
return upt
64+
}
65+
return src
66+
case []entities.Router:
67+
if len(upt.([]entities.Router)) > 0 {
68+
return upt
69+
}
70+
return src
71+
case []entities.Gateway:
72+
if len(upt.([]entities.Gateway)) > 0 {
73+
return upt
74+
}
75+
return src
76+
case []entities.SecurityGroup:
77+
if len(upt.([]entities.SecurityGroup)) > 0 {
78+
return upt
79+
}
80+
return src
81+
case []entities.Test:
82+
if len(upt.([]entities.Test)) > 0 {
83+
return upt
84+
}
85+
return src
86+
default:
87+
return src
3788
}
38-
return src
3989
}
4090

4191
func EntityUpdateCheck(check func(interface{}, interface{}) interface{}, origin interface{}, update interface{}) {

0 commit comments

Comments
 (0)