Skip to content
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

Adding support for dry-run for gNMI GET #478

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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