Skip to content

Commit

Permalink
Add config/config type tests for router data model
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Dec 20, 2024
1 parent 8c4441d commit b60ab64
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 67 deletions.
5 changes: 3 additions & 2 deletions common/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ func (self *IdentitySubscription) Diff(rdm *RouterDataModel, sink DiffSink) {

adapter := cmp.Reporter(diffReporter)
cmp.Diff(currentState, self, cmpopts.IgnoreUnexported(
sync.Mutex{}, IdentitySubscription{},
ConfigType{}, DataStateConfigType{},
sync.Mutex{}, IdentitySubscription{}, IdentityService{},
Config{}, ConfigType{},
DataStateConfig{}, DataStateConfigType{},
Identity{}, DataStateIdentity{},
Service{}, DataStateService{},
ServicePolicy{}, DataStateServicePolicy{},
Expand Down
15 changes: 15 additions & 0 deletions controller/db/config_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/openziti/storage/boltz"
"github.com/openziti/ziti/common/eid"
"go.etcd.io/bbolt"
"slices"
)

const (
Expand Down Expand Up @@ -132,6 +133,20 @@ func (store *configStoreImpl) DeleteById(ctx boltz.MutateContext, id string) err
return err
}

// clear config from referencing services
for _, serviceId := range store.GetRelatedEntitiesIdList(ctx.Tx(), id, EntityTypeServices) {
service, err := store.stores.edgeService.LoadById(ctx.Tx(), serviceId)
if err != nil {
return fmt.Errorf("error loading service %s to clear reference to config %s (%w)", serviceId, id, err)
}
service.Configs = slices.DeleteFunc(service.Configs, func(s string) bool {
return s == id
})
if err = store.stores.edgeService.Update(ctx, service, nil); err != nil {
return fmt.Errorf("error updating service %s to clear reference to config %s (%w)", serviceId, id, err)
}
}

err := store.symbolIdentityServices.Map(ctx.Tx(), []byte(id), func(mapCtx *boltz.MapContext) {
keys, err := boltz.DecodeStringSlice(mapCtx.Value())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions controller/internal/routes/config_type_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/edge-api/rest_management_api_server/operations/config"
"github.com/openziti/ziti/controller/env"
"github.com/openziti/ziti/controller/fields"
"github.com/openziti/ziti/controller/internal/permissions"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/response"
"github.com/openziti/ziti/controller/fields"
)

func init() {
Expand Down Expand Up @@ -68,7 +68,7 @@ func (r *ConfigTypeRouter) Register(ae *env.AppEnv) {
})

ae.ManagementApi.ConfigListConfigsForConfigTypeHandler = config.ListConfigsForConfigTypeHandlerFunc(func(params config.ListConfigsForConfigTypeParams, _ interface{}) middleware.Responder {
return ae.IsAllowed(func(ae *env.AppEnv, rc *response.RequestContext) { r.ListConfigs(ae, rc, params) }, params.HTTPRequest, "", "", permissions.IsAdmin())
return ae.IsAllowed(func(ae *env.AppEnv, rc *response.RequestContext) { r.ListConfigs(ae, rc) }, params.HTTPRequest, params.ID, "", permissions.IsAdmin())
})
}

Expand Down Expand Up @@ -125,6 +125,6 @@ func (r *ConfigTypeRouter) Patch(ae *env.AppEnv, rc *response.RequestContext, pa
})
}

func (r *ConfigTypeRouter) ListConfigs(ae *env.AppEnv, rc *response.RequestContext, params config.ListConfigsForConfigTypeParams) {
func (r *ConfigTypeRouter) ListConfigs(ae *env.AppEnv, rc *response.RequestContext) {
ListAssociationWithHandler[*model.ConfigType, *model.Config](ae, rc, ae.Managers.ConfigType, ae.Managers.Config, MapConfigToRestEntity)
}
2 changes: 1 addition & 1 deletion controller/internal/routes/edge_router_policy_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/edge-api/rest_management_api_server/operations/edge_router_policy"
"github.com/openziti/ziti/controller/env"
"github.com/openziti/ziti/controller/fields"
"github.com/openziti/ziti/controller/internal/permissions"
"github.com/openziti/ziti/controller/model"
"github.com/openziti/ziti/controller/response"
"github.com/openziti/ziti/controller/fields"
)

func init() {
Expand Down
5 changes: 5 additions & 0 deletions controller/sync_strats/sync_instant.go
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,11 @@ func (strategy *InstantStrategy) inspect(val string) (bool, *string, error) {
strVal := fmt.Sprintf("%d", idx)
return true, &strVal, nil
}
if val == "data-model-index" {
idx := strategy.indexProvider.CurrentIndex()
strVal := fmt.Sprintf("%d", idx)
return true, &strVal, nil
}
return false, nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/openziti/agent v1.0.22
github.com/openziti/channel/v3 v3.0.20
github.com/openziti/channel/v3 v3.0.22
github.com/openziti/cobra-to-md v1.0.1
github.com/openziti/edge-api v0.26.36
github.com/openziti/foundation/v2 v2.0.55
Expand Down Expand Up @@ -88,7 +88,7 @@ require (
golang.org/x/sync v0.10.0
golang.org/x/sys v0.28.0
golang.org/x/text v0.21.0
google.golang.org/protobuf v1.35.2
google.golang.org/protobuf v1.36.0
gopkg.in/AlecAivazis/survey.v1 v1.8.8
gopkg.in/go-jose/go-jose.v2 v2.6.3
gopkg.in/resty.v1 v1.12.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ github.com/openziti-incubator/cf v0.0.3 h1:JKs55DbaIxl87nI/Ra/3DHMiz5iaPpu8JjsuN
github.com/openziti-incubator/cf v0.0.3/go.mod h1:6abCY06bCjKmK2I9kohij+cp9uXIPFiFwSCNZPdMk8E=
github.com/openziti/agent v1.0.22 h1:lcehAQb3CnM0HbV9XWjnAxhRFrs77thztHnXKkp59qc=
github.com/openziti/agent v1.0.22/go.mod h1:Mr52m7/r6XA8S+ojWnMo8Ut44eH/gyX4ln1m5v7rw98=
github.com/openziti/channel/v3 v3.0.20 h1:Z3IkqyaSCskDEZErM9xliwzykzws4ETeDooUfM1Nkmg=
github.com/openziti/channel/v3 v3.0.20/go.mod h1:PeLtdfKg5Og3sPDjlDDvsi1SHWA6CmTF9yPJqiFOhLs=
github.com/openziti/channel/v3 v3.0.22 h1:Z7VilNKX04f3lvAw5JHZ1S64bt5o7JtnVhm2qTc8WxE=
github.com/openziti/channel/v3 v3.0.22/go.mod h1:KwRSjcqkUZsEFZZWFvKOH2ihEB/SIy6OgXJddVvN400=
github.com/openziti/cobra-to-md v1.0.1 h1:WRinNoIRmwWUSJm+pSNXMjOrtU48oxXDZgeCYQfVXxE=
github.com/openziti/cobra-to-md v1.0.1/go.mod h1:FjCpk/yzHF7/r28oSTNr5P57yN5VolpdAtS/g7KNi2c=
github.com/openziti/dilithium v0.3.5 h1:+envGNzxc3OyVPiuvtxivQmCsOjdZjtOMLpQBeMz7eM=
Expand Down Expand Up @@ -1275,8 +1275,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/AlecAivazis/survey.v1 v1.8.8 h1:5UtTowJZTz1j7NxVzDGKTz6Lm9IWm8DDF6b7a2wq9VY=
gopkg.in/AlecAivazis/survey.v1 v1.8.8/go.mod h1:CaHjv79TCgAvXMSFJSVgonHXYWxnhzI3eoHtnX5UgUo=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/edge/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func newListCmd(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.AddCommand(newListCmdForEntityType("posture-check-types", runListPostureCheckTypes, newOptions()))

configTypeListRootCmd := newEntityListRootCmd("config-type")
configTypeListRootCmd.AddCommand(newSubListCmdForEntityType("config-type", "configs", outputConfigs, newOptions()))
configTypeListRootCmd.AddCommand(newSubListCmdForEntityType("config-types", "configs", outputConfigs, newOptions()))

configListRootCmd := newEntityListRootCmd("config")
configListRootCmd.AddCommand(newSubListCmdForEntityType("configs", "services", outputServices, newOptions()))
Expand Down
1 change: 1 addition & 0 deletions ziti/cmd/fabric/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func newInspectCmd(p common.OptionsProvider) *cobra.Command {
cmd.AddCommand(action.newInspectSubCmd(p, "router-messaging", "gets information about pending router peer updates and terminator validations"))
cmd.AddCommand(action.newInspectSubCmd(p, "router-data-model", "gets information about the router data model"))
cmd.AddCommand(action.newInspectSubCmd(p, "router-data-model-index", "gets current index of the router data model"))
cmd.AddCommand(action.newInspectSubCmd(p, "data-model-index", "gets current index of the controller data model"))
cmd.AddCommand(action.newInspectSubCmd(p, "router-controllers", "gets information about the state of a router's connections to its controllers"))
cmd.AddCommand(action.newInspectSubCmd(p, "terminator-costs", "gets information about terminator dynamic costs"))
cmd.AddCommand(action.newInspectSubCmd(p, inspectCommon.RouterIdentityConnectionStatusesKey, "gets information about controller identity state"))
Expand Down
10 changes: 5 additions & 5 deletions zititest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ require (
github.com/google/uuid v1.6.0
github.com/michaelquigley/pfxlog v0.6.10
github.com/openziti/agent v1.0.22
github.com/openziti/channel/v3 v3.0.20
github.com/openziti/channel/v3 v3.0.22
github.com/openziti/edge-api v0.26.36
github.com/openziti/fablab v0.5.78-0.20241204213521-407c14614fe3
github.com/openziti/fablab v0.5.82
github.com/openziti/foundation/v2 v2.0.55
github.com/openziti/identity v1.0.93
github.com/openziti/sdk-golang v0.23.44
github.com/openziti/storage v0.3.13
github.com/openziti/transport/v2 v2.0.157
github.com/openziti/ziti v0.28.3
github.com/openziti/ziti v1.2.2
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/pkg/errors v0.9.1
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
Expand All @@ -29,7 +29,7 @@ require (
github.com/stretchr/testify v1.10.0
go.etcd.io/bbolt v1.3.11
golang.org/x/net v0.32.0
google.golang.org/protobuf v1.35.2
google.golang.org/protobuf v1.36.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -103,7 +103,7 @@ require (
github.com/influxdata/influxdb-client-go/v2 v2.14.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/jedib0t/go-pretty/v6 v6.6.2 // indirect
github.com/jedib0t/go-pretty/v6 v6.6.5 // indirect
github.com/jessevdk/go-flags v1.6.1 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions zititest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d h1:/WZ
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/jedib0t/go-pretty/v6 v6.6.2 h1:27bLj3nRODzaiA7tPIxy9UVWHoPspFfME9XxgwiiNsM=
github.com/jedib0t/go-pretty/v6 v6.6.2/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jedib0t/go-pretty/v6 v6.6.5 h1:9PgMJOVBedpgYLI56jQRJYqngxYAAzfEUua+3NgSqAo=
github.com/jedib0t/go-pretty/v6 v6.6.5/go.mod h1:Uq/HrbhuFty5WSVNfjpQQe47x16RwVGXIveNGEyGtHs=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jeremija/gosubmit v0.2.7 h1:At0OhGCFGPXyjPYAsCchoBUhE099pcBXmsb4iZqROIc=
github.com/jeremija/gosubmit v0.2.7/go.mod h1:Ui+HS073lCFREXBbdfrJzMB57OI/bdxTiLtrDHHhFPI=
Expand Down Expand Up @@ -593,16 +593,16 @@ github.com/openziti-incubator/cf v0.0.3 h1:JKs55DbaIxl87nI/Ra/3DHMiz5iaPpu8JjsuN
github.com/openziti-incubator/cf v0.0.3/go.mod h1:6abCY06bCjKmK2I9kohij+cp9uXIPFiFwSCNZPdMk8E=
github.com/openziti/agent v1.0.22 h1:lcehAQb3CnM0HbV9XWjnAxhRFrs77thztHnXKkp59qc=
github.com/openziti/agent v1.0.22/go.mod h1:Mr52m7/r6XA8S+ojWnMo8Ut44eH/gyX4ln1m5v7rw98=
github.com/openziti/channel/v3 v3.0.20 h1:Z3IkqyaSCskDEZErM9xliwzykzws4ETeDooUfM1Nkmg=
github.com/openziti/channel/v3 v3.0.20/go.mod h1:PeLtdfKg5Og3sPDjlDDvsi1SHWA6CmTF9yPJqiFOhLs=
github.com/openziti/channel/v3 v3.0.22 h1:Z7VilNKX04f3lvAw5JHZ1S64bt5o7JtnVhm2qTc8WxE=
github.com/openziti/channel/v3 v3.0.22/go.mod h1:KwRSjcqkUZsEFZZWFvKOH2ihEB/SIy6OgXJddVvN400=
github.com/openziti/cobra-to-md v1.0.1 h1:WRinNoIRmwWUSJm+pSNXMjOrtU48oxXDZgeCYQfVXxE=
github.com/openziti/cobra-to-md v1.0.1/go.mod h1:FjCpk/yzHF7/r28oSTNr5P57yN5VolpdAtS/g7KNi2c=
github.com/openziti/dilithium v0.3.5 h1:+envGNzxc3OyVPiuvtxivQmCsOjdZjtOMLpQBeMz7eM=
github.com/openziti/dilithium v0.3.5/go.mod h1:XONq1iK6te/WwNzkgZHfIDHordMPqb0hMwJ8bs9EfSk=
github.com/openziti/edge-api v0.26.36 h1:zy2DjmIz/B+WxPpIzhFOAxi/LhM/yeKa8s1Vz2h8cQk=
github.com/openziti/edge-api v0.26.36/go.mod h1:sYHVpm26Jr1u7VooNJzTb2b2nGSlmCHMnbGC8XfWSng=
github.com/openziti/fablab v0.5.78-0.20241204213521-407c14614fe3 h1:k4+7Dtfq3FIy1MYq/gbE7vlqQQOHIlN7W3jcL3JuT90=
github.com/openziti/fablab v0.5.78-0.20241204213521-407c14614fe3/go.mod h1:iU3FK+P3tQzU5zPuqHpgk8OXeynmfg5l43B+h+rrOiE=
github.com/openziti/fablab v0.5.82 h1:PYe/vKib/lnQt7f9LhAlzxvd9ZixXctji9A9fUrD9Bg=
github.com/openziti/fablab v0.5.82/go.mod h1:i5KsLUMsXOPsTQLZZSvmSzgJMrXv18PpTIVWL8pTyjs=
github.com/openziti/foundation/v2 v2.0.55 h1:Z3rsZper7DQtBB4H63nS/U40eR5IwsapKQ1xQ8G7IHQ=
github.com/openziti/foundation/v2 v2.0.55/go.mod h1:NG3OI19NT9gtoligfxvbMgTDs8lsJukxNA7N9Ts2WqY=
github.com/openziti/identity v1.0.93 h1:+onWAwfMat4hGkx0VDNHOSzkRaXAL10vGaaiGvt2tao=
Expand Down Expand Up @@ -1311,8 +1311,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/AlecAivazis/survey.v1 v1.8.8 h1:5UtTowJZTz1j7NxVzDGKTz6Lm9IWm8DDF6b7a2wq9VY=
gopkg.in/AlecAivazis/survey.v1 v1.8.8/go.mod h1:CaHjv79TCgAvXMSFJSVgonHXYWxnhzI3eoHtnX5UgUo=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ events:
jsonLogger:
subscriptions:
- type: entityChange
propagateAlways: true
# - type: edge.apiSessions
# - type: edge.entityCounts
# interval: 15s
Expand Down
2 changes: 1 addition & 1 deletion zititest/models/router-data-model-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ var m = &model.Model{

var tasks []parallel.LabeledTask
for range 100 {
task := createNewService(ctrls.getCtrl("ctrl1"))
task := createNewService(ctrls.getCtrl("ctrl1"), nil)
tasks = append(tasks, task)
}
return parallel.ExecuteLabeled(tasks, 2, nil)
Expand Down
Loading

0 comments on commit b60ab64

Please sign in to comment.