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

Do not report type updates as invalid when incompatibilities are allowed #94

Merged
merged 1 commit into from
Nov 20, 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
26 changes: 16 additions & 10 deletions openconfig-ci/ocdiff/ocdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ocdiff produces a report between two sets of OpenConfig YANG files.

Check failure on line 15 in openconfig-ci/ocdiff/ocdiff.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

package comment should be of the form "Package ocdiff ..."
package ocdiff

import (
Expand Down Expand Up @@ -46,7 +46,7 @@
type yangNodeInfo struct {
path string
schema *yang.Entry
allowIncompat bool
incompatAllowed bool
versionChangeDesc string
}

Expand All @@ -56,7 +56,7 @@
path string
oldSchema *yang.Entry
newSchema *yang.Entry
allowIncompat bool
incompatAllowed bool
versionChangeDesc string
incompatComments []string
}
Expand Down Expand Up @@ -113,13 +113,19 @@
}
var b strings.Builder
for _, del := range r.deletedNodes {
if !opts.onlyReportDisallowedIncompats || !del.allowIncompat {
if del.schema.IsLeaf() || del.schema.IsLeafList() {
b.WriteString(fmt.Sprintf(fmtstr, "leaf", "deleted", del.path, del.versionChangeDesc))
}
// All deletions are breaking changes.
if opts.onlyReportDisallowedIncompats && del.incompatAllowed {
continue
}
if del.schema.IsLeaf() || del.schema.IsLeafList() {
b.WriteString(fmt.Sprintf(fmtstr, "leaf", "deleted", del.path, del.versionChangeDesc))
}
}
for _, upd := range r.updatedNodes {
// All type updates are breaking changes.
if opts.onlyReportDisallowedIncompats && upd.incompatAllowed {
continue
}
nodeTypeDesc := "non-leaf"
if upd.oldSchema.IsLeaf() || upd.oldSchema.IsLeafList() {
nodeTypeDesc = "leaf"
Expand All @@ -146,7 +152,7 @@
return b.String()
}

func (r *DiffReport) Sort() {

Check failure on line 155 in openconfig-ci/ocdiff/ocdiff.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

exported method DiffReport.Sort should have comment or be unexported
slices.SortFunc(r.newNodes, func(a, b *yangNodeInfo) int { return strings.Compare(a.path, b.path) })
slices.SortFunc(r.deletedNodes, func(a, b *yangNodeInfo) int { return strings.Compare(a.path, b.path) })
slices.SortFunc(r.updatedNodes, func(a, b *yangNodeUpdateInfo) int { return strings.Compare(a.path, b.path) })
Expand All @@ -155,7 +161,7 @@
func getKind(e *yang.Entry) string {
if e.Type != nil {
return fmt.Sprint(e.Type.Kind)
} else {

Check failure on line 164 in openconfig-ci/ocdiff/ocdiff.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

if block ends with a return statement, so drop this else and outdent its block
return fmt.Sprint(e.Kind)
}
}
Expand All @@ -175,7 +181,7 @@
return moduleName, r.oldModuleVersions[moduleName], r.newModuleVersions[moduleName]
}

func incompatAllowed(oldVersion, newVersion *semver.Version) bool {
func isIncompatAllowed(oldVersion, newVersion *semver.Version) bool {
switch {
case oldVersion == nil, newVersion == nil:
// This can happen if the openconfig-version is not found (e.g. in IETF modules).
Expand All @@ -195,7 +201,7 @@
func (r *DiffReport) addPair(o *yang.Entry, n *yang.Entry) error {
moduleName, oldVersion, newVersion := r.getModuleAndVersions(o)
versionChangeDesc := fmt.Sprintf("%q: openconfig-version %v -> %v", moduleName, oldVersion, newVersion)
allowIncompat := incompatAllowed(oldVersion, newVersion)
incompatAllowed := isIncompatAllowed(oldVersion, newVersion)

switch {
case o == nil && n == nil:
Expand All @@ -210,15 +216,15 @@
r.deletedNodes = append(r.deletedNodes, &yangNodeInfo{
schema: o,
path: o.Path(),
allowIncompat: allowIncompat,
incompatAllowed: incompatAllowed,
versionChangeDesc: versionChangeDesc,
})
default:
upd := &yangNodeUpdateInfo{
oldSchema: o,
newSchema: n,
path: o.Path(),
allowIncompat: allowIncompat,
incompatAllowed: incompatAllowed,
versionChangeDesc: versionChangeDesc,
}
updated := false
Expand Down
5 changes: 0 additions & 5 deletions openconfig-ci/ocdiff/testdata/disallowed-incompats.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
leaf deleted: /openconfig-platform/components/component/linecard/state/slot-id ("openconfig-platform-linecard": openconfig-version 1.1.0 -> 1.2.0)
leaf updated: /openconfig-platform/components/component/chassis/utilization/resources/resource/state/used: type changed from uint64 to uint32 ("openconfig-platform": openconfig-version 0.23.0 -> 0.24.0)
leaf updated: /openconfig-platform/components/component/integrated-circuit/utilization/resources/resource/state/used: type changed from uint64 to uint32 ("openconfig-platform": openconfig-version 0.23.0 -> 0.24.0)
leaf updated: /openconfig-platform/components/component/linecard/state/colour: type changed from string to binary ("openconfig-platform-linecard": openconfig-version 1.1.0 -> 1.2.0)
leaf updated: /openconfig-platform/components/component/linecard/utilization/resources/resource/state/used: type changed from uint64 to uint32 ("openconfig-platform": openconfig-version 0.23.0 -> 0.24.0)
leaf updated: /openconfig-platform/components/component/port/breakout-mode/groups/group/config/num-physical-channels: type changed from uint8 to uint16 ("openconfig-platform-port": openconfig-version 1.0.1 -> 2.0.0)
leaf updated: /openconfig-platform/components/component/port/breakout-mode/groups/group/state/num-physical-channels: type changed from uint8 to uint16 ("openconfig-platform-port": openconfig-version 1.0.1 -> 2.0.0)
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
leaf deleted: `/openconfig-platform/components/component/linecard/state/slot-id`
* ("openconfig-platform-linecard": openconfig-version 1.1.0 -> 1.2.0)

leaf updated: `/openconfig-platform/components/component/chassis/utilization/resources/resource/state/used`
* type changed from uint64 to uint32
* ("openconfig-platform": openconfig-version 0.23.0 -> 0.24.0)

leaf updated: `/openconfig-platform/components/component/integrated-circuit/utilization/resources/resource/state/used`
* type changed from uint64 to uint32
* ("openconfig-platform": openconfig-version 0.23.0 -> 0.24.0)

leaf updated: `/openconfig-platform/components/component/linecard/state/colour`
* type changed from string to binary
* ("openconfig-platform-linecard": openconfig-version 1.1.0 -> 1.2.0)

leaf updated: `/openconfig-platform/components/component/linecard/utilization/resources/resource/state/used`
* type changed from uint64 to uint32
* ("openconfig-platform": openconfig-version 0.23.0 -> 0.24.0)

leaf updated: `/openconfig-platform/components/component/port/breakout-mode/groups/group/config/num-physical-channels`
* type changed from uint8 to uint16
* ("openconfig-platform-port": openconfig-version 1.0.1 -> 2.0.0)

leaf updated: `/openconfig-platform/components/component/port/breakout-mode/groups/group/state/num-physical-channels`
* type changed from uint8 to uint16
* ("openconfig-platform-port": openconfig-version 1.0.1 -> 2.0.0)

Loading