Skip to content

Commit

Permalink
Merge pull request #833 from jojimt/I827
Browse files Browse the repository at this point in the history
Fixes for L3 CI
  • Loading branch information
jojimt authored Apr 15, 2017
2 parents d225f91 + 7a13951 commit 7290b65
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion netmaster/objApi/apiController.go
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ func (ac *APIController) BgpUpdate(oldbgpCfg *contivModel.Bgp, NewbgpCfg *contiv

//BgpGetOper inspects the oper state of bgp object
func (ac *APIController) BgpGetOper(bgp *contivModel.BgpInspect) error {
var obj *BgpInspect
var obj BgpInspect
var host string

srvList, err := ac.objdbClient.GetService("netplugin")
Expand Down
79 changes: 79 additions & 0 deletions netmaster/objApi/objapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package objApi
import (
"encoding/json"
"log"
"net"
"net/http"
"os"
"reflect"
Expand Down Expand Up @@ -58,6 +59,52 @@ func initStateDriver() (core.StateDriver, error) {
return utils.NewStateDriver(utils.EtcdNameStr, &instInfo)
}

type restAPIFunc func(r *http.Request) (interface{}, error)

func httpWrapper(handlerFunc restAPIFunc) http.HandlerFunc {
// Create a closure and return an anonymous function
return func(w http.ResponseWriter, r *http.Request) {
// Call the handler
resp, err := handlerFunc(r)
if err != nil {
// Log error
log.Fatalf("Handler for %s %s returned error: %s", r.Method, r.URL, err)
} else {
// Send HTTP response as Json
content, err := json.Marshal(resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(content)
}
}
}

func bgpInspector(r *http.Request) (interface{}, error) {
return nil, nil
}

// setupBgpInspectServer
func setupBgpInspectServer() (net.Listener, error) {
r := mux.NewRouter()
r.HandleFunc("/inspect/bgp", httpWrapper(bgpInspector))
listener, err := net.Listen("tcp", "127.0.0.1:9090")
if err != nil {
log.Fatalf("Error creating listener: %v", err)
return nil, err
}
srv := &http.Server{
Handler: r,
WriteTimeout: 20 * time.Second,
ReadTimeout: 20 * time.Second,
}

go srv.Serve(listener)

return listener, nil
}

// setup the test netmaster REST server and client
func TestMain(m *testing.M) {
var err error
Expand Down Expand Up @@ -100,6 +147,9 @@ func TestMain(m *testing.M) {

// Create HTTP server
go http.ListenAndServe(netmasterTestListenURL, router)
// Create bgp inspect server
l, _ := setupBgpInspectServer()
defer l.Close()
time.Sleep(time.Second)

// create a new contiv client
Expand Down Expand Up @@ -1951,6 +2001,35 @@ func TestServicePreferredIP(t *testing.T) {
deleteNetwork(t, "yellow", "default")
}

func TestBgp(t *testing.T) {

bgpCfg := &client.Bgp{
As: "65001",
Hostname: "hostA",
Neighbor: "16.1.2.3",
NeighborAs: "65002",
Routerip: "65.1.1.1/24",
}

err := contivClient.BgpPost(bgpCfg)
if err != nil {
t.Fatalf("Error creating bgp object. Err: %v", err)
}
gotBgp, err := contivClient.BgpGet("hostA")
if err != nil {
t.Fatalf("Error getting bgp object. Err: %v", err)
}

if gotBgp.As != "65001" || gotBgp.Hostname != "hostA" || gotBgp.Neighbor != "16.1.2.3" || gotBgp.NeighborAs != "65002" || gotBgp.Routerip != "65.1.1.1/24" {
t.Fatalf("Error bgp object exp %+v, got %+v", bgpCfg, gotBgp)
}

_, err = contivClient.BgpInspect("hostA")
if err != nil {
t.Fatalf("Error inspecting bgp object. Err: %v", err)
}
}

func checkServiceCreate(t *testing.T, tenant, network, serviceName string, port []string, label []string,
preferredIP string) {

Expand Down
2 changes: 1 addition & 1 deletion test/systemtests/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *systemtestSuite) testServiceAddDeleteService(c *C, encap string) {

serviceNetworks[tenantName] = s.createServiceNetworks(c, i, numSvcNet, tenantName, encap)
}

time.Sleep(6*time.Second)
for tenant, networks := range tenantNames {
endChan := make(chan error)
for _, network := range networks {
Expand Down

0 comments on commit 7290b65

Please sign in to comment.