Skip to content

Commit

Permalink
Add ygnmi validator
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus committed Nov 11, 2023
1 parent 31f8d57 commit 1f3bf43
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 4 deletions.
40 changes: 39 additions & 1 deletion cmd_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,44 @@ function run-dir() {
headerTemplate: mustTemplate("goyang-ygot-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
cmd="generator"
options=(
-path={{ .ModelRoot }},{{ .RepoRoot }}/third_party/ietf
-package_name=exampleoc -generate_fakeroot -fakeroot_name=device -compress_paths=true
-shorten_enum_leaf_names -trim_enum_openconfig_prefix -typedef_enum_with_defmod -enum_suffix_for_simple_union_enums
-exclude_modules=ietf-interfaces -generate_rename -generate_append -generate_getters
-generate_leaf_getters -generate_delete -annotations -generate_simple_unions
-list_builder_key_threshold=3
)
script_options=(
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
outdir=$GOPATH/src/"$1"."$2"/
mkdir "$outdir"
local options=( -output_file="$outdir"/oc.go "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
cd "$outdir"
if [[ $status -eq "0" ]]; then
go mod init &>> ${prefix}pass || status=1
go mod tidy &>> ${prefix}pass || status=1
go build &>> ${prefix}pass || status=1
fi
if [[ $status -eq "1" ]]; then
mv ${prefix}pass ${prefix}fail
fi
}
`),
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
Expand Down Expand Up @@ -246,7 +284,7 @@ function run-dir() {
}
go install golang.org/x/tools/cmd/goimports@latest &>> ${prefix}pass || status=1
`),
perModelTemplate: mustTemplate("goyang-ygot", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
perModelTemplate: mustTemplate("ygnmi", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"yanglint": {
Expand Down
42 changes: 42 additions & 0 deletions cmd_gen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,48 @@ wait
wantCmd: `#!/bin/bash
workdir=/workspace/results/goyang-ygot
mkdir -p "$workdir"
cmd="generator"
options=(
-path=testdata,/workspace/third_party/ietf
-package_name=exampleoc -generate_fakeroot -fakeroot_name=device -compress_paths=true
-shorten_enum_leaf_names -trim_enum_openconfig_prefix -typedef_enum_with_defmod -enum_suffix_for_simple_union_enums
-exclude_modules=ietf-interfaces -generate_rename -generate_append -generate_getters
-generate_leaf_getters -generate_delete -annotations -generate_simple_unions
-list_builder_key_threshold=3
)
script_options=(
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
outdir=$GOPATH/src/"$1"."$2"/
mkdir "$outdir"
local options=( -output_file="$outdir"/oc.go "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
cd "$outdir"
if [[ $status -eq "0" ]]; then
go mod init &>> ${prefix}pass || status=1
go mod tidy &>> ${prefix}pass || status=1
go build &>> ${prefix}pass || status=1
fi
if [[ $status -eq "1" ]]; then
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 &
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
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
6 changes: 3 additions & 3 deletions validators/goyang-ygot/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ if ! stat $RESULTSDIR; then
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}"
if ! go install github.com/openconfig/ygot/generator@latest &> "${OUTFILE}"; then
echo "failed: go install github.com/openconfig/ygot/generator@latest" > "${FAILFILE}"
fi

go list -m github.com/openconfig/ygnmi@latest > $RESULTSDIR/latest-version.txt
go list -m github.com/openconfig/ygot@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
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 1f3bf43

Please sign in to comment.