diff --git a/go.sum b/go.sum index 427049923d..9cd8b44a45 100644 --- a/go.sum +++ b/go.sum @@ -8,10 +8,14 @@ github.com/antchfx/xmlquery v1.2.1 h1:wE4xjHrqOScP440wdv23Xkg0Gr8JryW0ptqodPH+y2 github.com/antchfx/xmlquery v1.2.1/go.mod h1:/+CnyD/DzHRnv2eRxrVbieRU/FIF6N0C+7oTtyUtCKk= github.com/antchfx/xpath v1.1.2 h1:YziPrtM0gEJBnhdUGxYcIVYXZ8FXbtbovxOi+UW/yWQ= github.com/antchfx/xpath v1.1.2/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= +github.com/cenkalti/backoff/v4 v4.0.0/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= @@ -29,7 +33,20 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0 h1:aRz0NBceriICVtjhCgKkDvl+RudKu1CT6h0ZvUTrNfE= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/protobuf v3.11.4+incompatible/go.mod h1:lUQ9D1ePzbH2PrIS7ob/bjm9HXyH5WHB0Akwh7URreM= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -42,10 +59,19 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c h1:a380JP+B7xlMbEQOlha1buKhzBPXFqgFXplyWCEIGEY= github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc= +github.com/openconfig/gnmi v0.0.0-20200307010808-e7106f7f5493/go.mod h1:jMSUQIR4z9WTtM58/QBHbElXAwbUnomFdty1aund1uY= +github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 h1:WXFwJlWOJINlwlyAZuNo4GdYZS6qPX36+rRUncLmN8Q= +github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A= github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f h1:BaekRUaWpfaRBP3mShDZaNi4+EHbdli7D6YXc/TP3lo= github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= +github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= +github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc h1:W6XYKuH3mxF5WFhsSQOPPN9DRDba1xz9lbUbQR3uHkg= +github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= +github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs= github.com/openconfig/ygot v0.6.1-0.20190723223108-724a6b18a922 h1:zBLb75mrLMxabjsAhPk/2qxbht+BwHKFWBvRAB4Fd2U= github.com/openconfig/ygot v0.6.1-0.20190723223108-724a6b18a922/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs= +github.com/openconfig/ygot v0.7.1 h1:kqDRYQpowXTr7EhGwr2BBDKJzqs+H8aFYjffYQ8lBsw= +github.com/openconfig/ygot v0.7.1/go.mod h1:5MwNX6DMP1QMf2eQjW+aJN/KNslVqRJtbfSL3SO6Urk= github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= github.com/pkg/profile v1.4.0 h1:uCmaf4vVbWAOZz36k1hrQD7ijGRzLwaME8Am/7a4jZI= github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE= @@ -67,6 +93,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -85,15 +113,29 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200319113533-08878b785e9c h1:5aI3/f/3eCZps9xwoEnmgfDJDhMbnJpfqeGpjVNgVEI= +google.golang.org/genproto v0.0.0-20200319113533-08878b785e9c/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0 h1:bO/TA4OxCOummhSf10siHuG7vJOiwh7SpRpFZDkOgl4= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.20.1/go.mod h1:KqelGeouBkcbcuB3HCk4/YH2tmNLk6YSWA5LIWeI/lY= +google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= diff --git a/rest/server/error.go b/rest/server/error.go index b88f5dfad1..0c5072abd3 100644 --- a/rest/server/error.go +++ b/rest/server/error.go @@ -39,11 +39,12 @@ type errorResponse struct { // errorEntry defines the RESTCONF compilant error information // payload. type errorEntry struct { - Type errtype `json:"error-type"` - Tag errtag `json:"error-tag"` - AppTag string `json:"error-app-tag,omitempty"` - Path string `json:"error-path,omitempty"` - Message string `json:"error-message,omitempty"` + Type errtype `json:"error-type"` + Tag errtag `json:"error-tag"` + AppTag string `json:"error-app-tag,omitempty"` + Path string `json:"error-path,omitempty"` + Message string `json:"error-message,omitempty"` + ErrInfo interface{} `json:"error-info,omitempty"` } type errtype string @@ -139,6 +140,13 @@ func toErrorEntry(err error, r *http.Request) (status int, errInfo errorEntry) { errInfo.Tag = errtagInvalidValue errInfo.Message = e.ErrorStr.Error() + case tlerr.TranslibUnsupportedClientVersion: + status = http.StatusBadRequest + errInfo.Type = errtypeProtocol + errInfo.Tag = errtagOperationNotSupported + errInfo.Message = e.Error() + errInfo.ErrInfo = map[string]interface{}{"version-error": e} + case tlerr.TranslibRedisClientEntryNotExist: status = http.StatusNotFound errInfo.Tag = errtagInvalidValue diff --git a/rest/server/error_test.go b/rest/server/error_test.go index eba815f8e6..723b39aca3 100644 --- a/rest/server/error_test.go +++ b/rest/server/error_test.go @@ -161,6 +161,11 @@ func TestErrorEntry(t *testing.T) { tlerr.TranslibSyntaxValidationError{ErrorStr: errors.New("ygot")}, 400, "protocol", "invalid-value", "", "ygot")) + t.Run("Version_err", testErrorEntry( + tlerr.TranslibUnsupportedClientVersion{ + ClientVersion: "1.2.3", ServerVersion: "1.2.0", ServerBaseVersion: "1.0.0"}, + 400, "protocol", "operation-not-supported", "", "Unsupported client version 1.2.3")) + } func testErrorEntry(err error, diff --git a/rest/server/handler.go b/rest/server/handler.go index 0ab0733db0..1ac9307459 100644 --- a/rest/server/handler.go +++ b/rest/server/handler.go @@ -46,6 +46,11 @@ func Process(w http.ResponseWriter, r *http.Request) { glog.Infof("[%s] %s %s; content-len=%d", reqID, r.Method, r.URL.Path, r.ContentLength) _, args.data, err = getRequestBody(r, rc) + + if err == nil { + err = args.parseClientVersion(r, rc) + } + if err != nil { status, data, rtype = prepareErrorResponse(err, r) goto write_resp @@ -219,8 +224,21 @@ func trimRestconfPrefix(path string) string { // translibArgs holds arguments for invoking translib APIs. type translibArgs struct { - path string // Translib path - data []byte // payload + path string // Translib path + data []byte // payload + version translib.Version // client version +} + +// parseClientVersion parses the Accept-Version request header value +func (args *translibArgs) parseClientVersion(r *http.Request, rc *RequestContext) error { + if v := r.Header.Get("Accept-Version"); len(v) != 0 { + if err := args.version.Set(v); err != nil { + return httpBadRequest("Invalid Accept-Version \"%s\"", v) + } + } + + glog.V(1).Infof("[%s] Client version = \"%s\"", rc.ID, args.version) + return nil } // invokeTranslib calls appropriate TransLib API for the given HTTP @@ -233,7 +251,8 @@ func invokeTranslib(args *translibArgs, r *http.Request, rc *RequestContext) (in switch r.Method { case "GET", "HEAD": req := translib.GetRequest{ - Path: args.path, + Path: args.path, + ClientVersion: args.version, } resp, err1 := translib.Get(req) if err1 == nil { @@ -247,8 +266,9 @@ func invokeTranslib(args *translibArgs, r *http.Request, rc *RequestContext) (in //TODO return 200 for operations request status = 201 req := translib.SetRequest{ - Path: args.path, - Payload: args.data, + Path: args.path, + Payload: args.data, + ClientVersion: args.version, } _, err = translib.Create(req) @@ -256,23 +276,26 @@ func invokeTranslib(args *translibArgs, r *http.Request, rc *RequestContext) (in //TODO send 201 if PUT resulted in creation status = 204 req := translib.SetRequest{ - Path: args.path, - Payload: args.data, + Path: args.path, + Payload: args.data, + ClientVersion: args.version, } _, err = translib.Replace(req) case "PATCH": status = 204 req := translib.SetRequest{ - Path: args.path, - Payload: args.data, + Path: args.path, + Payload: args.data, + ClientVersion: args.version, } _, err = translib.Update(req) case "DELETE": status = 204 req := translib.SetRequest{ - Path: args.path, + Path: args.path, + ClientVersion: args.version, } _, err = translib.Delete(req) diff --git a/rest/server/handler_test.go b/rest/server/handler_test.go index d3c3cc6529..8eb04f44b4 100644 --- a/rest/server/handler_test.go +++ b/rest/server/handler_test.go @@ -28,6 +28,8 @@ import ( "sort" "strings" "testing" + + "github.com/Azure/sonic-mgmt-common/translib" ) var testRouter *Router @@ -501,6 +503,52 @@ func testRespData(r *http.Request, rc *RequestContext, data []byte, expType stri } } +func TestVersion_none(t *testing.T) { + r := httptest.NewRequest("GET", "/test", nil) + verifyParseVersion(t, r, true, translib.Version{}) +} + +func TestVersion_empty(t *testing.T) { + r := httptest.NewRequest("GET", "/test", nil) + r.Header.Set("Accept-Version", "") + verifyParseVersion(t, r, true, translib.Version{}) +} + +func TestVersion_000(t *testing.T) { + r := httptest.NewRequest("GET", "/test", nil) + r.Header.Set("Accept-Version", "0.0.0") + verifyParseVersion(t, r, false, translib.Version{}) +} + +func TestVersion_123(t *testing.T) { + r := httptest.NewRequest("GET", "/test", nil) + r.Header.Set("Accept-Version", "1.2.3") + verifyParseVersion(t, r, true, translib.Version{Major: 1, Minor: 2, Patch: 3}) +} + +func TestVersion_bad(t *testing.T) { + r := httptest.NewRequest("GET", "/test", nil) + r.Header.Set("Accept-Version", "bad") + verifyParseVersion(t, r, false, translib.Version{}) +} + +func verifyParseVersion(t *testing.T, r *http.Request, expSuccess bool, expVer translib.Version) { + var args translibArgs + rc, r := GetContext(r) + err := args.parseClientVersion(r, rc) + ver := r.Header.Get("Accept-Version") + + if expSuccess && err != nil { + t.Fatalf("Unexpected error parsing AcceptVersion \"%s\"; err=%v", ver, err) + } + if !expSuccess && err == nil { + t.Fatalf("Expected error parsing AcceptVersion \"%s\"", ver) + } + if expSuccess && args.version != expVer { + t.Fatalf("Failed to parse AcceptVersion \"%s\"; expected=%s, found=%s", ver, expVer, args.version) + } +} + func TestProcessGET(t *testing.T) { w := httptest.NewRecorder() Process(w, prepareRequest(t, "GET", "/api-tests:sample", "")) diff --git a/tools/test/rest-server.sh b/tools/test/rest-server.sh index ebd3db10a6..89109ef9d1 100755 --- a/tools/test/rest-server.sh +++ b/tools/test/rest-server.sh @@ -21,7 +21,7 @@ set -e -TOPDIR=$PWD +TOPDIR=$(git rev-parse --show-toplevel || echo ${PWD}) BUILD_DIR=$TOPDIR/build SERVER_DIR=$TOPDIR/build/rest_server MGMT_COMMON_DIR=$(realpath $TOPDIR/../sonic-mgmt-common) @@ -32,6 +32,11 @@ if [[ ! -f $SERVER_DIR/rest_server ]]; then exit 1 fi +# Setup database config file path +if [[ -z ${DB_CONFIG_PATH} ]]; then + export DB_CONFIG_PATH=${MGMT_COMMON_DIR}/tools/test/database_config.json +fi + # LD_LIBRARY_PATH for CVL [ -z $LD_LIBRARY_PATH ] && export LD_LIBRARY_PATH=/usr/local/lib @@ -55,6 +60,19 @@ if [[ -z $CVL_CFG_FILE ]]; then fi fi +# Prepare yang files directiry for transformer +if [[ -z ${YANG_MODELS_PATH} ]]; then + export YANG_MODELS_PATH=${BUILD_DIR}/all_yangs + mkdir -p ${YANG_MODELS_PATH} + pushd ${YANG_MODELS_PATH} > /dev/null + MGMT_COMN=$(realpath --relative-to=${PWD} ${MGMT_COMMON_DIR}) + rm -f * + find ${MGMT_COMN}/models/yang -name "*.yang" -not -path "*/testdata/*" -exec ln -sf {} \; + ln -sf ${MGMT_COMN}/models/yang/version.xml + ln -sf ${MGMT_COMN}/config/transformer/models_list + popd > /dev/null +fi + EXTRA_ARGS="-rest_ui $SERVER_DIR/dist/ui -logtostderr" for V in $@; do