Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change CNF API file directory to /cnfapi #124

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions cmd/stonework/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
const (
protoFileExt = ".proto"
ligatoApiFileDir = "/api"
protoFileDir = "/run/stonework/proto"
cnfApiFileDir = "/cnfapi"

modelSpecExtNum = 50222
modelTmplExtNum = 50223
Expand Down Expand Up @@ -121,7 +121,7 @@ func registerModels(files linker.Files, specExtDesc, tmplExtDesc protoreflect.Ex
// no model spec detected, continue with next message
continue
}
spec, err := util.ConvertProto(&generic.ModelSpec{}, dynSpec)
specMsg, err := util.ConvertProto(&generic.ModelSpec{}, dynSpec)
if err != nil {
return err
}
Expand All @@ -130,8 +130,15 @@ func registerModels(files linker.Files, specExtDesc, tmplExtDesc protoreflect.Ex
tmpl := proto.GetExtension(opts, tmplExtDesc.Type()).(string)
modelOpts = append(modelOpts, models.WithNameTemplate(tmpl))
}
spec := models.ToSpec(specMsg.(*generic.ModelSpec))
modelName := spec.ModelName()
modelMsg := dynamicpb.NewMessage(msgDesc)
_, err = models.DefaultRegistry.Register(modelMsg, models.ToSpec(spec.(*generic.ModelSpec)), modelOpts...)
if _, err := models.DefaultRegistry.GetModel(modelName); err == nil {
// model already registered, print warning and continue with next message
logging.DefaultLogger.Warnf("Cannot register cnf model: model with name %s is already registered", modelName)
continue
}
_, err = models.DefaultRegistry.Register(modelMsg, spec, modelOpts...)
if err != nil {
return err
}
Expand All @@ -145,12 +152,12 @@ func main() {
fmt.Println(http.ListenAndServe("0.0.0.0:6060", nil))
}()

if _, err := os.Stat(protoFileDir); !os.IsNotExist(err) {
if _, err := os.Stat(cnfApiFileDir); !os.IsNotExist(err) {
ligatoApiFiles, err := compileProtoFiles(findProtoFiles(ligatoApiFileDir), ligatoApiFileDir)
if err != nil {
logging.DefaultLogger.Fatal(err)
}
files, err := compileProtoFiles(findProtoFiles(protoFileDir), protoFileDir, ligatoApiFileDir)
files, err := compileProtoFiles(findProtoFiles(cnfApiFileDir), cnfApiFileDir, ligatoApiFileDir)
if err != nil {
logging.DefaultLogger.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions docker/mockcnf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ COPY ./docker/mockcnf/supervisor-novpp.conf /etc/mockcnf-novpp/supervisor.conf
COPY ./docker/mockcnf/init_hook-novpp.sh /usr/bin/init_hook-novpp.sh

# Copy proto api (mockcnf models)
RUN mkdir -p /run/stonework
RUN cp -r ./proto/mockcnf /run/stonework/proto
RUN mkdir -p /api/mockcnf
RUN cp -r ./proto/mockcnf /api/mockcnf

# Install script for packet tracing on VPP
COPY ./docker/vpptrace.sh /usr/bin/vpptrace.sh
Expand Down
3 changes: 3 additions & 0 deletions examples/testing/100-mock-cnf-module/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ version: '3.3'

volumes:
runtime_data: {}
mockcnfapi: {}

services:
stonework:
Expand All @@ -36,6 +37,7 @@ services:
- "6060:6060" # pprof
volumes:
- runtime_data:/run/stonework
- mockcnfapi:/cnfapi/mockcnf
- /sys/bus/pci:/sys/bus/pci
- /dev:/dev
- /run/docker.sock:/run/docker.sock
Expand All @@ -57,6 +59,7 @@ services:
privileged: true
volumes:
- runtime_data:/run/stonework
- mockcnfapi:/api
environment:
INITIAL_LOGLVL: "debug"
MICROSERVICE_LABEL: "mockcnf1"
Expand Down