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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package integration_test_labs
import (
"context"
"fmt"
"testing"
mnepb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/networkelement"
integration_test_utils "code.fbi.h-da.de/danet/gosdn/integration-tests/integrationTestUtils"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
)
const pndID = "5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d"
const (
targetAName = "gnmi-targetA"
targetAUUID = "e3cc56ad-2a6c-4b76-8315-5f17a6dc25bf"
targetBName = "gnmi-targetB"
targetBUUID = "87c8bcc1-d95c-401e-b447-f02c56abd8b1"
)
// The connection to the controller to use in each test.
var conn *grpc.ClientConn
// The context containing the credentials when authenticated.
var ctx context.Context
// A defaultSDN config with default/empty values.
var defaultSDNConfig string
func TestMain(m *testing.M) {
localConn, localCtx, err := integration_test_utils.CreateSecureConnection()
if err != nil {
fmt.Println(err.Error())
}
conn = localConn
ctx = localCtx
sndConfig, err := integration_test_utils.ExportCurrentSDNConfig(conn, ctx)
defaultSDNConfig = sndConfig
if err != nil {
fmt.Println(err.Error())
}
integration_test_utils.ApplySDNConfig(conn, ctx, defaultSDNConfig)
m.Run()
}
// The following test describes a chain of commands (see
// https://code.fbi.h-da.de/danet/gosdn/-/wikis/Labs/Lab00-education).
func TestLab00(t *testing.T) {
defer integration_test_utils.ApplySDNConfig(conn, ctx, defaultSDNConfig)
managedNetworkElements := []struct {
name string
newHostname string
id string
addr string
username string
password string
}{
{
name: targetAName,
newHostname: "newHostnameForTargetA",
id: targetAUUID,
addr: integration_test_utils.DefaultTargetAAdress,
},
{
name: targetBName,
newHostname: "newHostnameForTargetB",
id: targetBUUID,
addr: integration_test_utils.DefaultTargetBAdress,
},
}
mneService := mnepb.NewNetworkElementServiceClient(conn)
// Create the two managed network elements.
for i, mne := range managedNetworkElements {
alr := createAddListRequestSingleMne(mne.addr, mne.name, mne.id, integration_test_utils.DefaultTargetUsername, integration_test_utils.DefaultTargetPassword)
_, err := mneService.AddList(ctx, alr)
if err != nil {
t.Error(err)
}
getAllMneRequest := &mnepb.GetAllRequest{
Timestamp: integration_test_utils.GetTimestamp(),
Pid: pndID,
}
getAllResponse, err := mneService.GetAll(ctx, getAllMneRequest)
if err != nil {
t.Error(err)
}
assert.Equal(t, i+1, len(getAllResponse.GetMne()), "Amount of registered managed network elements is not correct.")
}
// Check the initial hostname of both managed network elements.
for _, mne := range managedNetworkElements {
hostnameRequest := getHostnameSingleMne(mne.id)
resp, err := mneService.GetPath(ctx, hostnameRequest)
if err != nil {
t.Error(err)
}
assert.Equal(t, 1, len(resp.GetMneNotification()), "The hostname for the managed network element has been requested. Therefore exactly one response is expected.")
assert.NotEmpty(t, resp.MneNotification[0].GetUpdate()[0].GetVal().GetStringVal(), "It is expected, that the hostname of the managed network element is not empty.")
}
// Change the hostname of both managed network elements.
for _, mne := range managedNetworkElements {
hostnamePathListRequest, err := setHostnamePathListRequestSingleMne(mne.id, mne.newHostname, mnepb.ApiOperation_API_OPERATION_UPDATE)
if err != nil {
t.Error(err)
}
setResp, err := mneService.SetPathList(ctx, hostnamePathListRequest)
if err != nil {
t.Error(err)
}
assert.Equal(t, 1, len(setResp.GetResponses()), "A single path change for the hostname has been requested. Therefore exactly one response is expected.")
// Commit the change.
commitChange := commitOrConfirmChange(setResp.GetResponses()[0].GetId(), mnepb.Operation_OPERATION_COMMIT)
_, err = mneService.SetChangeList(ctx, commitChange)
if err != nil {
t.Error(err)
}
// Confirm the change.
confirmChange := commitOrConfirmChange(setResp.GetResponses()[0].GetId(), mnepb.Operation_OPERATION_CONFIRM)
_, err = mneService.SetChangeList(ctx, confirmChange)
if err != nil {
t.Error(err)
}
}
// Check if the hostname has been changed and is accessible through a
// GetPath request.
for _, mne := range managedNetworkElements {
hostnameRequest := getHostnameSingleMne(mne.id)
resp, err := mneService.GetPath(ctx, hostnameRequest)
if err != nil {
t.Error(err)
}
assert.Equal(t, 1, len(resp.GetMneNotification()), "The hostname for the managed network element has been requested. Therefore exactly one response is expected.")
assert.Equal(t, mne.newHostname, resp.MneNotification[0].GetUpdate()[0].GetVal().GetStringVal(), "Exptected the new changed hostname.")
}
}