Skip to content
Snippets Groups Projects
Commit e288ae6e authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

lightweight Dockerfile.alpine

parent 853041c7
No related branches found
No related tags found
2 merge requests!221Thesis mk,!173Process response overhaul
Pipeline #76538 passed with warnings
This commit is part of merge request !173. Comments created here will be created in the context of that merge request.
...@@ -6,7 +6,6 @@ WORKDIR /src/gosdn ...@@ -6,7 +6,6 @@ WORKDIR /src/gosdn
COPY . . COPY . .
RUN apk add --no-cache git RUN apk add --no-cache git
RUN git config --global url."https://$GITLAB_USER:$GITLAB_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de" RUN git config --global url."https://$GITLAB_USER:$GITLAB_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de"
RUN go mod tidy
RUN GOOS=linux go build -o gosdn ./cmd/gosdn RUN GOOS=linux go build -o gosdn ./cmd/gosdn
FROM alpine FROM alpine
......
package api package api
import ( import (
"os"
"testing" "testing"
"code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto" "github.com/google/uuid"
guuid "github.com/google/uuid" guuid "github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
pb "google.golang.org/protobuf/proto"
) )
const unreachable = "203.0.113.10:6030"
const testPath = "/system/config/hostname"
var testAddress = "141.100.70.170:6030"
var testAPIEndpoint = "gosdn-latest.apps.ocp.fbi.h-da.de"
var testUsername = "admin"
var testPassword = "arista"
var opt *tpb.TransportOption
var gnmiMessages map[string]pb.Message
func TestMain(m *testing.M) {
testSetupIntegration()
os.Exit(m.Run())
}
func testSetupIntegration() {
if os.Getenv("GOSDN_LOG") == "nolog" {
log.SetLevel(log.PanicLevel)
}
addr := os.Getenv("GOSDN_TEST_ENDPOINT")
if addr != "" {
testAddress = addr
log.Infof("GOSDN_TEST_ENDPOINT set to %v", testAddress)
}
api := os.Getenv("GOSDN_TEST_API_ENDPOINT")
if api != "" {
testAPIEndpoint = api
log.Infof("GOSDN_TEST_API_ENDPOINT set to %v", testAPIEndpoint)
}
u := os.Getenv("GOSDN_TEST_USER")
if u != "" {
testUsername = u
log.Infof("GOSDN_TEST_USER set to %v", testUsername)
}
p := os.Getenv("GOSDN_TEST_PASSWORD")
if p != "" {
testPassword = p
log.Infof("GOSDN_TEST_PASSWORD set to %v", testPassword)
}
gnmiMessages = map[string]pb.Message{
"../test/proto/cap-resp-arista-ceos": &gpb.CapabilityResponse{},
"../test/proto/req-full-node": &gpb.GetRequest{},
"../test/proto/req-full-node-arista-ceos": &gpb.GetRequest{},
"../test/proto/req-interfaces-arista-ceos": &gpb.GetRequest{},
"../test/proto/req-interfaces-interface-arista-ceos": &gpb.GetRequest{},
"../test/proto/req-interfaces-wildcard": &gpb.GetRequest{},
"../test/proto/resp-full-node": &gpb.GetResponse{},
"../test/proto/resp-full-node-arista-ceos": &gpb.GetResponse{},
"../test/proto/resp-interfaces-arista-ceos": &gpb.GetResponse{},
"../test/proto/resp-interfaces-interface-arista-ceos": &gpb.GetResponse{},
"../test/proto/resp-interfaces-wildcard": &gpb.GetResponse{},
"../test/proto/resp-set-system-config-hostname": &gpb.SetResponse{},
}
for k, v := range gnmiMessages {
if err := proto.Read(k, v); err != nil {
log.Fatalf("error parsing %v: %v", k, err)
}
}
opt = &tpb.TransportOption{
Address: testAddress,
Username: testUsername,
Password: testPassword,
}
}
func TestApiIntegration(t *testing.T) { func TestApiIntegration(t *testing.T) {
// TDOO: Remove once openshift grpc support is available // TDOO: Remove once openshift grpc support is available
t.Skip("skipped due to openshift limitations") t.Skip("skipped due to openshift limitations")
...@@ -111,24 +39,38 @@ func TestApiIntegration(t *testing.T) { ...@@ -111,24 +39,38 @@ func TestApiIntegration(t *testing.T) {
cliPnd := viper.GetString("CLI_PND") cliPnd := viper.GetString("CLI_PND")
cliSbi := viper.GetString("CLI_SBI") cliSbi := viper.GetString("CLI_SBI")
suid, err := uuid.Parse(cliSbi)
if err != nil {
t.Error(err)
}
puid, err := uuid.Parse(cliPnd)
if err != nil {
t.Error(err)
}
opt := &tpb.TransportOption{
Address: testAddress,
Username: testUsername,
Password: testPassword,
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{},
},
}
if _, err := addDevice( if _, err := addDevice(
testAPIEndpoint, testAPIEndpoint,
testUsername,
testPassword,
cliSbi,
cliPnd,
testAddress,
"test-device", "test-device",
opt,
suid,
puid,
); (err != nil) != tt.wantErr { ); (err != nil) != tt.wantErr {
t.Errorf("gosdn cli add-device error = %v, wantErr %v", err, tt.wantErr) t.Errorf("gosdn cli add-device error = %v, wantErr %v", err, tt.wantErr)
return return
} }
did := viper.GetString("LAST_DEVICE_UUID") did := viper.GetString("LAST_DEVICE_UUID")
_, err := getDevice( _, err = getDevice(
testAPIEndpoint, testAPIEndpoint,
cliPnd, cliPnd,
testPath,
did, did,
) )
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
......
...@@ -24,6 +24,18 @@ func NewDevice(name string, opt *tpb.TransportOption, sbi southbound.SouthboundI ...@@ -24,6 +24,18 @@ func NewDevice(name string, opt *tpb.TransportOption, sbi southbound.SouthboundI
name = namesgenerator.GetRandomName(0) name = namesgenerator.GetRandomName(0)
} }
if opt.Csbi {
return &CsbiDevice{
CommonDevice: CommonDevice{
UUID: uuid.New(),
GoStruct: sbi.Schema().Root,
sbi: sbi,
transport: t,
name: name,
},
}, nil
}
return &CommonDevice{ return &CommonDevice{
UUID: uuid.New(), UUID: uuid.New(),
GoStruct: sbi.Schema().Root, GoStruct: sbi.Schema().Root,
......
...@@ -412,19 +412,14 @@ func (pnd *pndImplementation) createCsbiDevice(name string, d *cpb.Deployment, o ...@@ -412,19 +412,14 @@ func (pnd *pndImplementation) createCsbiDevice(name string, d *cpb.Deployment, o
panic(err) panic(err)
} }
opt.Address = deviceDetails.Address opt.Address = deviceDetails.Address
t, err := NewTransport(opt, csbi)
d, err := NewDevice(name, opt, csbi)
if err != nil { if err != nil {
panic(err) panic(err)
} }
d := &CsbiDevice{ d.(*CsbiDevice).UUID = id
CommonDevice: CommonDevice{
name: name,
UUID: id,
transport: t,
},
}
ch <- DeviceDetails{TransportOption: opt} ch <- DeviceDetails{TransportOption: opt}
if err := pnd.devices.Add(d, d.name); err != nil { if err := pnd.devices.Add(d, d.Name()); err != nil {
panic(err) panic(err)
} }
pnd.callback(id, nil) pnd.callback(id, nil)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment