Skip to content

Commit

Permalink
Merge pull request #93 from openconfig/ygnmi-for-ygot
Browse files Browse the repository at this point in the history
Add ygnmi validator
  • Loading branch information
wenovus authored Nov 13, 2023
2 parents 5bb9ae5 + a5f245c commit f098639
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 8 deletions.
47 changes: 44 additions & 3 deletions cmd_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ script_options=(
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
outdir=$GOPATH/src/"$1"."$2"/
mkdir "$outdir"
outdir=$GOPATH/src/ygot/"$1"."$2"/
mkdir -p "$outdir"
local options=( -output_file="$outdir"/oc.go "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
Expand All @@ -246,6 +246,47 @@ function run-dir() {
}
`),
perModelTemplate: mustTemplate("goyang-ygot", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"ygnmi": {
headerTemplate: mustTemplate("ygnmi-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
cmd="ygnmi generator"
options=(
--trim_module_prefix=openconfig
--exclude_modules=ietf-interfaces
--split_package_paths="/network-instances/network-instance/protocols/protocol/isis=netinstisis,/network-instances/network-instance/protocols/protocol/bgp=netinstbgp"
--paths={{ .ModelRoot }}/...,{{ .RepoRoot }}/third_party/ietf/...
--annotations
)
script_options=(
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
outdir=$GOPATH/src/ygnmi/"$1"."$2"
mkdir -p "$outdir"
local options=( --output_dir="${outdir}"/oc --base_package_path=ygnmi/"$1"."$2"/oc "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
if [[ $status -eq "0" ]]; then
cd "$outdir/oc"
go mod init &> /dev/null || status=1
go mod tidy &> /dev/null || status=1
goimports -w *.go &> /dev/null || status=1
go build &> /dev/null || status=1
fi
if [[ $status -eq "1" ]]; then
# Only output if there is an error: otherwise the gist comment is too long.
go build &>> ${prefix}pass || status=1
mv ${prefix}pass ${prefix}fail
fi
}
go install golang.org/x/tools/cmd/goimports@latest &>> ${prefix}pass || status=1
`),
perModelTemplate: mustTemplate("ygnmi", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"yanglint": {
Expand Down Expand Up @@ -301,7 +342,7 @@ fi
// runInParallel determines whether a particular validator and version should be run in parallel.
func runInParallel(validatorId, version string) bool {
switch {
case validatorId == "goyang-ygot", validatorId == "pyang" && version == "head":
case validatorId == "pyang" && version == "head":
return false
default:
return true
Expand Down
55 changes: 50 additions & 5 deletions cmd_gen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ script_options=(
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
outdir=$GOPATH/src/"$1"."$2"/
mkdir "$outdir"
outdir=$GOPATH/src/ygot/"$1"."$2"/
mkdir -p "$outdir"
local options=( -output_file="$outdir"/oc.go "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
Expand All @@ -214,9 +214,54 @@ function run-dir() {
mv ${prefix}pass ${prefix}fail
fi
}
run-dir "acl" "openconfig-acl" testdata/acl/openconfig-acl.yang testdata/acl/openconfig-acl-evil-twin.yang
run-dir "optical-transport" "openconfig-optical-amplifier" testdata/optical-transport/openconfig-optical-amplifier.yang
run-dir "optical-transport" "openconfig-transport-line-protection" testdata/optical-transport/openconfig-transport-line-protection.yang
run-dir "acl" "openconfig-acl" testdata/acl/openconfig-acl.yang testdata/acl/openconfig-acl-evil-twin.yang &
run-dir "optical-transport" "openconfig-optical-amplifier" testdata/optical-transport/openconfig-optical-amplifier.yang &
run-dir "optical-transport" "openconfig-transport-line-protection" testdata/optical-transport/openconfig-transport-line-protection.yang &
wait
`,
}, {
name: "basic ygnmi",
inModelMap: basicModelMap,
inValidatorName: "ygnmi",
wantCmd: `#!/bin/bash
workdir=/workspace/results/ygnmi
mkdir -p "$workdir"
cmd="ygnmi generator"
options=(
--trim_module_prefix=openconfig
--exclude_modules=ietf-interfaces
--split_package_paths="/network-instances/network-instance/protocols/protocol/isis=netinstisis,/network-instances/network-instance/protocols/protocol/bgp=netinstbgp"
--paths=testdata/...,/workspace/third_party/ietf/...
--annotations
)
script_options=(
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
outdir=$GOPATH/src/ygnmi/"$1"."$2"
mkdir -p "$outdir"
local options=( --output_dir="${outdir}"/oc --base_package_path=ygnmi/"$1"."$2"/oc "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
if [[ $status -eq "0" ]]; then
cd "$outdir/oc"
go mod init &> /dev/null || status=1
go mod tidy &> /dev/null || status=1
goimports -w *.go &> /dev/null || status=1
go build &> /dev/null || status=1
fi
if [[ $status -eq "1" ]]; then
# Only output if there is an error: otherwise the gist comment is too long.
go build &>> ${prefix}pass || status=1
mv ${prefix}pass ${prefix}fail
fi
}
go install golang.org/x/tools/cmd/goimports@latest &>> ${prefix}pass || status=1
run-dir "acl" "openconfig-acl" testdata/acl/openconfig-acl.yang testdata/acl/openconfig-acl-evil-twin.yang &
run-dir "optical-transport" "openconfig-optical-amplifier" testdata/optical-transport/openconfig-optical-amplifier.yang &
run-dir "optical-transport" "openconfig-transport-line-protection" testdata/optical-transport/openconfig-transport-line-protection.yang &
wait
`,
}, {
Expand Down
5 changes: 5 additions & 0 deletions commonci/commonci.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ var (
IsPerModel: true,
IsWidelyUsedTool: true,
},
"ygnmi": {
Name: "ygnmi",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"yanglint": {
Name: "yanglint",
IsPerModel: true,
Expand Down
5 changes: 5 additions & 0 deletions commonci/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"log"
"math"
"os"
"strings"
"time"
Expand Down Expand Up @@ -101,6 +102,10 @@ func (g *GithubRequestHandler) AddGistComment(gistID, title, output string) (int
defer cancel() // cancel context if the function returns before the timeout

gistComment := fmt.Sprintf("# %s\n%s", title, output)
if bs := []byte(gistComment); len(bs) > math.MaxUint16 {
log.Printf("Truncating gist comment from %d bytes to %d bytes", len(bs), math.MaxUint16)
gistComment = string(bs[:math.MaxUint16])
}

var id int64
if err := Retry(5, "gist comment creation", func() error {
Expand Down
40 changes: 40 additions & 0 deletions validators/ygnmi/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


ROOT_DIR=/workspace
RESULTSDIR=$ROOT_DIR/results/ygnmi
OUTFILE=$RESULTSDIR/out
FAILFILE=$RESULTSDIR/fail

if ! stat $RESULTSDIR; then
exit 0
fi

# module download logs go to stderr, so only fail if command failed.
if ! go install github.com/openconfig/ygnmi/app/ygnmi@latest &> "${OUTFILE}"; then
echo "failed: go install github.com/openconfig/ygnmi/app/ygnmi@latest" > "${FAILFILE}"
fi

go list -m github.com/openconfig/ygnmi@latest > $RESULTSDIR/latest-version.txt
if bash $RESULTSDIR/script.sh >> $OUTFILE 2>> $FAILFILE; then
# Delete fail file if it's empty and the script passed.
find $FAILFILE -size 0 -delete
fi
$GOPATH/bin/post_results -validator=ygnmi -modelRoot=$_MODEL_ROOT -repo-slug=$_REPO_SLUG -pr-number=$_PR_NUMBER -commit-sha=$COMMIT_SHA -branch=$BRANCH_NAME
BADGEFILE=$RESULTSDIR/upload-badge.sh
if stat $BADGEFILE; then
bash $BADGEFILE
fi

0 comments on commit f098639

Please sign in to comment.