Skip to content

Commit

Permalink
Merge pull request #478 from rao-aneesh/get-dry-run
Browse files Browse the repository at this point in the history
Adding support for dry-run for gNMI GET
  • Loading branch information
karimra authored Jul 15, 2024
2 parents 01ca8fa + 0acf71a commit 93343e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/app/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (a *App) GetRequest(ctx context.Context, tc *types.TargetConfig) {
a.logError(fmt.Errorf("target %q Get request failed: %v", tc.Name, err))
return
}
if response == nil {
return
}
err = a.PrintMsg(tc.Name, "Get Response:", response)
if err != nil {
a.logError(fmt.Errorf("target %q: %v", tc.Name, err))
Expand All @@ -123,12 +126,15 @@ func (a *App) getRequest(ctx context.Context, tc *types.TargetConfig, req *gnmi.
xreq.UseModels = append(xreq.UseModels, m)
}
}
if a.Config.PrintRequest {
if a.Config.PrintRequest || a.Config.GetDryRun {
err := a.PrintMsg(tc.Name, "Get Request:", req)
if err != nil {
a.logError(fmt.Errorf("target %q Get Request printing failed: %v", tc.Name, err))
}
}
if a.Config.GetDryRun {
return nil, nil
}
a.Logger.Printf("sending gNMI GetRequest: prefix='%v', path='%v', type='%v', encoding='%v', models='%+v', extension='%+v' to %s",
xreq.Prefix, xreq.Path, xreq.Type, xreq.Encoding, xreq.UseModels, xreq.Extension, tc.Name)

Expand Down Expand Up @@ -176,6 +182,7 @@ func (a *App) InitGetFlags(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&a.Config.LocalFlags.GetValuesOnly, "values-only", "", false, "print GetResponse values only")
cmd.Flags().StringArrayVarP(&a.Config.LocalFlags.GetProcessor, "processor", "", []string{}, "list of processor names to run")
cmd.Flags().Uint32VarP(&a.Config.LocalFlags.GetDepth, "depth", "", 0, "depth extension value")
cmd.Flags().BoolVarP(&a.Config.LocalFlags.GetDryRun, "dry-run", "", false, "prints the get request without initiating a gRPC connection")

cmd.LocalFlags().VisitAll(func(flag *pflag.Flag) {
a.Config.FileConfig.BindPFlag(fmt.Sprintf("%s-%s", cmd.Name(), flag.Name), flag)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type LocalFlags struct {
GetValuesOnly bool `mapstructure:"get-values-only,omitempty" json:"get-values-only,omitempty" yaml:"get-values-only,omitempty"`
GetProcessor []string `mapstructure:"get-processor,omitempty" json:"get-processor,omitempty" yaml:"get-processor,omitempty"`
GetDepth uint32 `mapstructure:"get-depth,omitempty" yaml:"get-depth,omitempty" json:"get-depth,omitempty"`
GetDryRun bool `mapstructure:"get-dry-run,omitempty" json:"get-dry-run,omitempty" yaml:"get-dry-run,omitempty"`
// Set
SetPrefix string `mapstructure:"set-prefix,omitempty" json:"set-prefix,omitempty" yaml:"set-prefix,omitempty"`
SetDelete []string `mapstructure:"set-delete,omitempty" json:"set-delete,omitempty" yaml:"set-delete,omitempty"`
Expand Down

0 comments on commit 93343e1

Please sign in to comment.