-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
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
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,75 @@ | ||
// Copyright 2020-present Open Networking Foundation. | ||
// | ||
// 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. | ||
|
||
package gnmi | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/Pallinder/go-randomdata" | ||
|
||
"github.com/onosproject/onos-config/api/types/change/network" | ||
"github.com/onosproject/onos-config/test/utils/gnmi" | ||
"github.com/onosproject/onos-config/test/utils/proto" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func generateTimezoneName() string { | ||
|
||
usCity := randomdata.ProvinceForCountry("US") | ||
timeZone := "US/" + usCity | ||
return timeZone | ||
} | ||
|
||
// TestMultipleSet tests multiple query/set/delete of a single GNMI path to a single device | ||
func (s *TestSuite) TestMultipleSet(t *testing.T) { | ||
// Create a simulated device | ||
simulator := gnmi.CreateSimulator(t) | ||
|
||
// Make a GNMI client to use for requests | ||
gnmiClient := gnmi.GetGNMIClientOrFail(t) | ||
|
||
var changeIDs []network.ID | ||
|
||
for i := 0; i < 10; i++ { | ||
|
||
msValue := generateTimezoneName() | ||
|
||
devicePath := gnmi.GetDevicePathWithValue(simulator.Name(), tzPath, msValue, proto.StringVal) | ||
// Set a value using gNMI client | ||
changeID := gnmi.SetGNMIValueOrFail(t, gnmiClient, devicePath, gnmi.NoPaths, gnmi.NoExtensions) | ||
|
||
// Append the changeID to list of changeIDs | ||
changeIDs = append(changeIDs, changeID) | ||
|
||
// Check that the value was set correctly | ||
gnmi.CheckGNMIValue(t, gnmiClient, devicePath, msValue, 0, "Query after set returned the wrong value") | ||
|
||
// Remove the path we added | ||
gnmi.SetGNMIValueOrFail(t, gnmiClient, gnmi.NoPaths, devicePath, gnmi.NoExtensions) | ||
|
||
// Make sure it got removed | ||
gnmi.CheckGNMIValue(t, gnmiClient, devicePath, "", 0, "incorrect value found for path /system/clock/config/timezone-name after delete") | ||
|
||
} | ||
|
||
// Make sure all of the changes have been completed | ||
for _, changeID := range changeIDs { | ||
complete := gnmi.WaitForNetworkChangeComplete(t, changeID, 5*time.Second) | ||
assert.True(t, complete, "Set never completed") | ||
} | ||
// Shut down the device we created | ||
gnmi.DeleteSimulator(t, simulator) | ||
} |