Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package integration_test_utils
import (
"context"
"fmt"
"os"
"time"
configMgmtPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func CreateConnection() (*grpc.ClientConn, error) {
controller_url := "localhost:55055"
controller_env := os.Getenv("INTEGRATION_TEST_CONTROLLER_URL")
if controller_env != "" {
controller_url = controller_env
}
dialOption := grpc.WithTransportCredentials(insecure.NewCredentials())
conn, err := grpc.Dial(controller_url, dialOption, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(100*1024*1024)))
if err != nil {
return nil, err
}
return conn, nil
}
func PrepareEvironment(conn *grpc.ClientConn) (string, error) {
ctx := context.Background()
pndService := ppb.NewPndServiceClient(conn)
pndRes, err := pndService.GetPndList(ctx, &ppb.GetPndListRequest{Timestamp: getTimestamp()})
if err != nil {
return "", err
}
pndID := pndRes.Pnd[0].Id
configMgmtService := configMgmtPb.NewConfigurationManagementServiceClient(conn)
sdnConfigResponse, err := configMgmtService.ExportSDNConfig(ctx, &configMgmtPb.ExportSDNConfigRequest{Timestamp: getTimestamp(), Pid: pndID})
if err != nil {
return "", err
}
return sdnConfigResponse.SdnConfigData, nil
}
func RestoreEnvironment(conn *grpc.ClientConn, sdnConfig string) {
ctx := context.Background()
pndService := ppb.NewPndServiceClient(conn)
pndRes, err := pndService.GetPndList(ctx, &ppb.GetPndListRequest{Timestamp: getTimestamp()})
if err != nil {
fmt.Println(err)
}
// currently only support for default PND
pndID := pndRes.Pnd[0].Id
configMgmtService := configMgmtPb.NewConfigurationManagementServiceClient(conn)
_, err = configMgmtService.ImportSDNConfig(ctx, &configMgmtPb.ImportSDNConfigRequest{Timestamp: getTimestamp(), Pid: pndID, SdnConfigData: sdnConfig})
if err != nil {
fmt.Println(err)
}
}
func getTimestamp() int64 {
return int64(time.Now().Nanosecond())
}