Skip to content

Commit

Permalink
Merge pull request #36 from openconfig/posix-pattern-conversion
Browse files Browse the repository at this point in the history
Convert validators to recognize posix-pattern instead of pattern
  • Loading branch information
wenovus authored Aug 6, 2020
2 parents 900b114 + 7a57602 commit 6534b1e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd_gen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p *postLabelRecorder) PostLabel(labelName, labelColor, owner, repo string,
return nil
}

func TestGenOpenConfigLinterScript(t *testing.T) {
func TestGenOpenConfigValidatorScript(t *testing.T) {
prNumber = 1
basicModelMap, err := commonci.ParseOCModels("testdata")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions commonci/commonci.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ var (
IsWidelyUsedTool: true,
},
"oc-pyang": &Validator{
Name: "OpenConfig Linter",
IsPerModel: true,
Name: "OpenConfig Linter",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"pyangbind": &Validator{
Name: "pyangbind",
Expand Down
2 changes: 1 addition & 1 deletion post_results/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func getGistHeading(validatorId, version, resultsDir string) (string, string, er
// If version is latest, then get the concrete version output by the tool if it exists.
if version == "" {
if outBytes, err := ioutil.ReadFile(filepath.Join(resultsDir, commonci.LatestVersionFileName)); err != nil {
log.Printf("did not read latest version for %s: %v", validatorId, err)
log.Printf("INFO: did not read latest version for %s: %v", validatorId, err)
} else {
// Get the first line of the version output as the tool's display title.
nameAndVersionParts := strings.Fields(strings.TrimSpace(strings.SplitN(string(outBytes), "\n", 2)[0]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ module openconfig-extensions {
specified by RFC6020 and RFC7950.";
}

extension posix-pattern {
argument "pattern" {
yin-element false;
}
description
"Provides a POSIX ERE regular expression pattern statement as an
alternative to YANG regular expresssions based on XML Schema Datatypes.
It is used the same way as the standard YANG pattern statement defined in
RFC6020 and RFC7950, but takes an argument that is a POSIX ERE regular
expression string.
If present, any posix-pattern statement should have a corresponding
pattern statement that provides equivalent behavior.";
reference
"POSIX Extended Regular Expressions (ERE) Specification:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04";
}

extension telemetry-on-change {
description
"The telemetry-on-change annotation is specified in the context
Expand Down
4 changes: 4 additions & 0 deletions validators/misc-checks/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ if find $REPODIR -name '*.yang' | xargs $GOPATH/bin/ocversion -p $REPODIR > $RES
fi

$GOPATH/bin/post_results -validator=misc-checks -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
4 changes: 4 additions & 0 deletions validators/oc-pyang/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ if bash $RESULTSDIR/script.sh $VENVDIR/bin/pyang --plugindir $OCPYANG_PLUGIN_DIR
find $FAILFILE -size 0 -delete
fi
$GOPATH/bin/post_results -validator=oc-pyang -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

########################## CLEANUP #############################
teardown
6 changes: 3 additions & 3 deletions validators/regexp/go/src/gotests/regexp/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ func TestRegexps(t *testing.T) {
for _, tc := range tt.testData {
var gotMatch bool
if len(leaf.Type.Type) == 0 {
_, gotMatch = checkPattern(tc.inData, leaf.Type.Pattern)
_, gotMatch = checkPattern(tc.inData, leaf.Type.POSIXPattern)
} else {
// Handle unions
results := make([]bool, 0)
for _, membertype := range leaf.Type.Type {
// Only do the test when there is a pattern specified against the
// type as it may not be a string.
if membertype.Kind != yang.Ystring || len(membertype.Pattern) == 0 {
if membertype.Kind != yang.Ystring || len(membertype.POSIXPattern) == 0 {
continue
}
matchedAllForType := true
_, matchedAllForType = checkPattern(tc.inData, membertype.Pattern)
_, matchedAllForType = checkPattern(tc.inData, membertype.POSIXPattern)
results = append(results, matchedAllForType)
}

Expand Down
4 changes: 4 additions & 0 deletions validators/regexp/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ if go test -v gotests/regexp > $OUTFILE 2> $FAILFILE; then
find $FAILFILE -size 0 -delete
fi
$GOPATH/bin/post_results -validator=regexp -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 6534b1e

Please sign in to comment.