Skip to content

Commit

Permalink
Add Go generator option -keep_deviate_notsupported (#753)
Browse files Browse the repository at this point in the history
* Add Go generator option `-keep_deviate_notsupported`

* keep -> ignore
  • Loading branch information
wenovus authored Dec 2, 2022
1 parent 4670419 commit 7baa5b4
Show file tree
Hide file tree
Showing 7 changed files with 683 additions and 3 deletions.
4 changes: 4 additions & 0 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var (
includeDescriptions = flag.Bool("include_descriptions", false, "If set to true when generateSchema=true, the YANG descriptions will be included in the generated code artefact.")
enumOrgPrefixesToTrim []string
ignoreUnsupportedStatements = flag.Bool("ignore_unsupported", false, "If set to true, unsupported YANG statements are ignored.")
ignoreDeviateNotsupported = flag.Bool("ignore_deviate_notsupported", false, "If set to true, 'deviate not-supported' YANG statements are ignored, thus target nodes are retained in the generated code.")

// Flags used for GoStruct generation only.
generateFakeRoot = flag.Bool("generate_fakeroot", false, "If set to true, a fake element at the root of the data tree is generated. By default the fake root entity is named Device, its name can be controlled with the fakeroot_name flag.")
Expand Down Expand Up @@ -335,6 +336,9 @@ func main() {
ExcludeModules: modsExcluded,
YANGParseOptions: yang.Options{
IgnoreSubmoduleCircularDependencies: *ignoreCircDeps,
DeviateOptions: yang.DeviateOptions{
IgnoreDeviateNotSupported: *ignoreDeviateNotsupported,
},
},
},
TransformationOptions: ygen.TransformationOpts{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/go-cmp v0.5.7
github.com/kylelemons/godebug v1.1.0
github.com/openconfig/gnmi v0.0.0-20220920173703-480bf53a74d2
github.com/openconfig/goyang v1.1.0
github.com/openconfig/goyang v1.2.0
github.com/openconfig/gribi v0.1.1-0.20210423184541-ce37eb4ba92f
github.com/pmezard/go-difflib v1.0.0
google.golang.org/grpc v1.40.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/openconfig/gnmi v0.0.0-20220920173703-480bf53a74d2 h1:3YLlQFLDsFTvruK
github.com/openconfig/gnmi v0.0.0-20220920173703-480bf53a74d2/go.mod h1:Y9os75GmSkhHw2wX8sMsxfI7qRGAEcDh8NTa5a8vj6E=
github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
github.com/openconfig/goyang v0.2.2/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/goyang v1.1.0 h1:noOfMyWq1eXo9djmJ9MtY4qg/j/5z03lgsku7jvxPws=
github.com/openconfig/goyang v1.1.0/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/goyang v1.2.0 h1:mChUZvp1kCWq6Q00wVCtOToddFzEsGlMGG+V+wNXva8=
github.com/openconfig/goyang v1.2.0/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/gribi v0.1.1-0.20210423184541-ce37eb4ba92f h1:8vRtC+y0xh9BYPrEGf/jG/paYXiDUJ6P8iYt5rCVols=
github.com/openconfig/gribi v0.1.1-0.20210423184541-ce37eb4ba92f/go.mod h1:OoH46A2kV42cIXGyviYmAlGmn6cHjGduyC2+I9d/iVs=
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70/go.mod h1:OmTWe7RyZj2CIzIgy4ovEBzCLBJzRvWSZmn7u02U9gU=
Expand Down
50 changes: 50 additions & 0 deletions gogen/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/openconfig/gnmi/errdiff"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/genutil"
"github.com/openconfig/ygot/testutil"
"github.com/openconfig/ygot/ygen"
Expand Down Expand Up @@ -183,6 +184,55 @@ func TestSimpleStructs(t *testing.T) {
},
},
wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-simple-with-unsupported.formatted-txt"),
}, {
name: "simple openconfig test with deviate not-supported",
inFiles: []string{filepath.Join(datapath, "deviate-not-supported.yang")},
inConfig: CodeGenerator{
IROptions: ygen.IROptions{
TransformationOptions: ygen.TransformationOpts{
CompressBehaviour: genutil.PreferIntendedConfig,
ShortenEnumLeafNames: true,
EnumOrgPrefixesToTrim: []string{"openconfig"},
UseDefiningModuleForTypedefEnumNames: true,
EnumerationsUseUnderscores: true,
},
},
GoOptions: GoOpts{
GenerateSimpleUnions: true,
GenerateLeafGetters: true,
GenerateLeafSetters: true,
GeneratePopulateDefault: true,
},
},
wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/deviate-not-supported.formatted-txt"),
}, {
name: "simple openconfig test with deviate not-supported ignored",
inFiles: []string{filepath.Join(datapath, "deviate-not-supported.yang")},
inConfig: CodeGenerator{
IROptions: ygen.IROptions{
ParseOptions: ygen.ParseOpts{
YANGParseOptions: yang.Options{
DeviateOptions: yang.DeviateOptions{
IgnoreDeviateNotSupported: true,
},
},
},
TransformationOptions: ygen.TransformationOpts{
CompressBehaviour: genutil.PreferIntendedConfig,
ShortenEnumLeafNames: true,
EnumOrgPrefixesToTrim: []string{"openconfig"},
UseDefiningModuleForTypedefEnumNames: true,
EnumerationsUseUnderscores: true,
},
},
GoOptions: GoOpts{
GenerateSimpleUnions: true,
GenerateLeafGetters: true,
GenerateLeafSetters: true,
GeneratePopulateDefault: true,
},
},
wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/deviate-not-supported-keep.formatted-txt"),
}, {
name: "OpenConfig leaf-list defaults test, with compression",
inFiles: []string{filepath.Join(datapath, "openconfig-leaflist-default.yang")},
Expand Down
Loading

0 comments on commit 7baa5b4

Please sign in to comment.