-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fix Wildcard entries to return empty data instead of invalid path #299
Merged
gechiang
merged 15 commits into
sonic-net:master
from
zbud-msft:fix_wildcard_invalid_bug
Nov 11, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0d65793
Fix Wildcard entries to return empty data instead of invalid path
zbud-msft a6bed8e
Use res in log
zbud-msft 02c69e8
Add UT
zbud-msft 10c3af5
Merge branch 'sonic-net:master' into fix_wildcard_invalid_bug
zbud-msft 6cfaebc
Add UT
zbud-msft 30a19a5
Merge branch 'fix_wildcard_invalid_bug' of github.com:zbud-msft/sonic…
zbud-msft 9f60d93
Fix UT
zbud-msft cafc955
Fix UT
zbud-msft cce1a52
Mock result
zbud-msft 34334e1
Mock result
zbud-msft 466a650
Fix UT
zbud-msft d9d7d31
Add logs
zbud-msft ac6668f
Remove unneeded package
zbud-msft ad4d6cf
Add existing table test
zbud-msft 58a5342
Add check for empty json in test
zbud-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1297,11 +1297,11 @@ func runGnmiTestGet(t *testing.T, namespace string) { | |
}, | ||
{ | ||
desc: "Get valid but non-existing node", | ||
pathTarget: "COUNTERS_DB", | ||
pathTarget: stateDBPath, | ||
textPbPath: ` | ||
elem: <name: "MyCounters" > | ||
`, | ||
wantRetCode: codes.NotFound, | ||
elem: <name: "TRANSCEIVER_DOM_SENSOR" > | ||
`, | ||
wantRetCode: codes.OK, | ||
}, { | ||
desc: "Get COUNTERS_PORT_NAME_MAP", | ||
pathTarget: "COUNTERS_DB", | ||
|
@@ -3487,6 +3487,191 @@ func TestClientConnections(t *testing.T) { | |
} | ||
} | ||
|
||
func TestWildcardTableNoError(t *testing.T) { | ||
s := createServer(t, 8081) | ||
go runServer(t, s) | ||
defer s.ForceStop() | ||
|
||
fileName := "../testdata/NEIGH_STATE_TABLE_MAP.txt" | ||
neighStateTableByte, err := ioutil.ReadFile(fileName) | ||
if err != nil { | ||
t.Fatalf("read file %v err: %v", fileName, err) | ||
} | ||
|
||
var neighStateTableJson interface{} | ||
json.Unmarshal(neighStateTableByte, &neighStateTableJson) | ||
|
||
tests := []struct { | ||
desc string | ||
q client.Query | ||
wantNoti []client.Notification | ||
poll int | ||
}{ | ||
{ | ||
desc: "poll query for NEIGH_STATE_TABLE", | ||
poll: 1, | ||
q: client.Query{ | ||
Target: "STATE_DB", | ||
Type: client.Poll, | ||
Queries: []client.Path{{"NEIGH_STATE_TABLE"}}, | ||
TLS: &tls.Config{InsecureSkipVerify: true}, | ||
}, | ||
wantNoti: []client.Notification{ | ||
client.Update{Path: []string{"NEIGH_STATE_TABLE"}, TS: time.Unix(0, 200), Val: neighStateTableJson}, | ||
client.Update{Path: []string{"NEIGH_STATE_TABLE"}, TS: time.Unix(0, 200), Val: neighStateTableJson}, | ||
}, | ||
}, | ||
} | ||
namespace, _ := sdcfg.GetDbDefaultNamespace() | ||
prepareStateDb(t, namespace) | ||
var mutexNoti sync.Mutex | ||
for _, tt := range tests { | ||
|
||
t.Run(tt.desc, func(t *testing.T) { | ||
q := tt.q | ||
q.Addrs = []string{"127.0.0.1:8081"} | ||
c := client.New() | ||
var gotNoti []client.Notification | ||
q.NotificationHandler = func(n client.Notification) error { | ||
mutexNoti.Lock() | ||
if nn, ok := n.(client.Update); ok { | ||
nn.TS = time.Unix(0, 200) | ||
gotNoti = append(gotNoti, nn) | ||
} | ||
mutexNoti.Unlock() | ||
return nil | ||
} | ||
|
||
wg := new(sync.WaitGroup) | ||
wg.Add(1) | ||
|
||
go func() { | ||
defer wg.Done() | ||
if err := c.Subscribe(context.Background(), q); err != nil { | ||
t.Errorf("c.Subscribe(): got error %v, expected nil", err) | ||
} | ||
}() | ||
|
||
wg.Wait() | ||
|
||
for i := 0; i < tt.poll; i++ { | ||
if err := c.Poll(); err != nil { | ||
t.Errorf("c.Poll(): got error %v, expected nil", err) | ||
} | ||
} | ||
|
||
mutexNoti.Lock() | ||
|
||
if len(gotNoti) == 0 { | ||
t.Errorf("expected non zero notifications") | ||
} | ||
|
||
if diff := pretty.Compare(tt.wantNoti, gotNoti); diff != "" { | ||
t.Log("\n Want: \n", tt.wantNoti) | ||
t.Log("\n Got: \n", gotNoti) | ||
t.Errorf("unexpected updates: \n%s", diff) | ||
} | ||
|
||
mutexNoti.Unlock() | ||
|
||
c.Close() | ||
}) | ||
} | ||
} | ||
|
||
func TestNonExistentTableNoError(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test |
||
s := createServer(t, 8081) | ||
go runServer(t, s) | ||
defer s.ForceStop() | ||
|
||
fileName := "../testdata/EMPTY_JSON.txt" | ||
transceiverDomSensorTableByte, err := ioutil.ReadFile(fileName) | ||
if err != nil { | ||
t.Fatalf("read file %v err: %v", fileName, err) | ||
} | ||
|
||
var transceiverDomSensorTableJson interface{} | ||
json.Unmarshal(transceiverDomSensorTableByte, &transceiverDomSensorTableJson) | ||
|
||
tests := []struct { | ||
desc string | ||
q client.Query | ||
wantNoti []client.Notification | ||
poll int | ||
}{ | ||
{ | ||
desc: "poll query for TRANSCEIVER_DOM_SENSOR", | ||
poll: 1, | ||
q: client.Query{ | ||
Target: "STATE_DB", | ||
Type: client.Poll, | ||
Queries: []client.Path{{"TRANSCEIVER_DOM_SENSOR"}}, | ||
TLS: &tls.Config{InsecureSkipVerify: true}, | ||
}, | ||
wantNoti: []client.Notification{ | ||
client.Update{Path: []string{"TRANSCEIVER_DOM_SENSOR"}, TS: time.Unix(0, 200), Val: transceiverDomSensorTableJson}, | ||
client.Update{Path: []string{"TRANSCEIVER_DOM_SENSOR"}, TS: time.Unix(0, 200), Val: transceiverDomSensorTableJson}, | ||
}, | ||
}, | ||
} | ||
namespace, _ := sdcfg.GetDbDefaultNamespace() | ||
prepareStateDb(t, namespace) | ||
var mutexNoti sync.Mutex | ||
|
||
for _, tt := range tests { | ||
prepareStateDb(t, namespace) | ||
t.Run(tt.desc, func(t *testing.T) { | ||
q := tt.q | ||
q.Addrs = []string{"127.0.0.1:8081"} | ||
c := client.New() | ||
var gotNoti []client.Notification | ||
q.NotificationHandler = func(n client.Notification) error { | ||
mutexNoti.Lock() | ||
if nn, ok := n.(client.Update); ok { | ||
nn.TS = time.Unix(0, 200) | ||
gotNoti = append(gotNoti, nn) | ||
} | ||
mutexNoti.Unlock() | ||
return nil | ||
} | ||
|
||
wg := new(sync.WaitGroup) | ||
wg.Add(1) | ||
|
||
go func() { | ||
defer wg.Done() | ||
if err := c.Subscribe(context.Background(), q); err != nil { | ||
t.Errorf("c.Subscribe(): got error %v, expected nil", err) | ||
} | ||
}() | ||
|
||
wg.Wait() | ||
|
||
for i := 0; i < tt.poll; i++ { | ||
if err := c.Poll(); err != nil { | ||
t.Errorf("c.Poll(): got error %v, expected nil", err) | ||
} | ||
} | ||
|
||
mutexNoti.Lock() | ||
|
||
if len(gotNoti) == 0 { | ||
t.Errorf("expected non zero notifications") | ||
} | ||
|
||
if diff := pretty.Compare(tt.wantNoti, gotNoti); diff != "" { | ||
t.Log("\n Want: \n", tt.wantNoti) | ||
t.Log("\n Got: \n", gotNoti) | ||
t.Errorf("unexpected updates: \n%s", diff) | ||
} | ||
|
||
mutexNoti.Unlock() | ||
|
||
c.Close() | ||
}) | ||
} | ||
} | ||
|
||
func TestConnectionDataSet(t *testing.T) { | ||
s := createServer(t, 8081) | ||
go runServer(t, s) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to verify if the gnmi response is correct.
Seems like a bug in your manual test: "{}" #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test to verify gnmi response is empty json, please take a look at EMPTY_JSON.txt.
It is not a bug, as gnmi_client as part of subscribe will print out json_ietf_value as json string and "{}" is a valid response.
json_ietf structured value should be a valid json string, which empty json represented as string, "{}", is.
https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#23-structured-data-types
If we use gnmi_get which prints out json and not json string, we indeed get expected empty json
[elem {
name: "PSU_INFO"
}
]
The GetResponse is below
{}