-
Notifications
You must be signed in to change notification settings - Fork 92
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
Showtech sonic mgmt framework: Add Management Framework functionality for "show tech-support" #49
Merged
renukamanavalan
merged 4 commits into
sonic-net:master
from
kerry-meyer:showtech_sonic_mgmt_framework
Jan 20, 2022
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f643d5
Provide initial files for SONiC Community mgmt-framework Showtech
5fd8cb8
Add host_comm.go to the translib/tranformer directory
06a82da
Showtech sonic mgmt framework: Add handling for an output "status" fi…
kerry-meyer 781856d
Delete commented out code from host_comm.go
kerry-meyer 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module sonic-showtech-annot { | ||
|
||
yang-version "1"; | ||
|
||
namespace "http://openconfig.net/Azure/sonic-showtech-annot"; | ||
prefix "showtech-annot"; | ||
|
||
import sonic-extensions { prefix sonic-ext; } | ||
import sonic-show-techsupport { prefix sshwtchspt; } | ||
|
||
deviation /sshwtchspt:sonic-show-techsupport-info { | ||
deviate add { | ||
sonic-ext:rpc-callback "rpc_showtech_cb"; | ||
} | ||
} | ||
|
||
} |
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,49 @@ | ||
module sonic-show-techsupport { | ||
namespace "http://github.com/Azure/sonic-show-techsupport"; | ||
prefix sshwtchspt; | ||
yang-version 1.1; | ||
|
||
import ietf-yang-types { | ||
prefix yang; | ||
} | ||
|
||
organization | ||
"SONiC"; | ||
|
||
contact | ||
"SONiC"; | ||
|
||
description | ||
"SONiC TECH SUPPORT INFORMATION"; | ||
|
||
revision 2019-10-15 { | ||
description | ||
"Initial revision."; | ||
} | ||
|
||
rpc sonic-show-techsupport-info { | ||
input { | ||
leaf date { | ||
type yang:date-and-time; | ||
description | ||
"Date and time specification of the desired start | ||
point for collected log and core information"; | ||
} | ||
} | ||
output { | ||
leaf output-status { | ||
type string; | ||
description | ||
"'Success' or detailed failure message for execution of the | ||
'show tech-support' request"; | ||
} | ||
leaf output-filename { | ||
type string; | ||
description | ||
"Name of the host compressed tar file containing the collected | ||
technical support information"; | ||
} | ||
} | ||
} | ||
} | ||
|
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,134 @@ | ||
package transformer | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/godbus/dbus/v5" | ||
log "github.com/golang/glog" | ||
) | ||
|
||
// HostResult contains the body of the response and the error if any, when the | ||
// endpoint finishes servicing the D-Bus request. | ||
type HostResult struct { | ||
Body []interface{} | ||
Err error | ||
} | ||
|
||
// HostQuery calls the corresponding D-Bus endpoint on the host and returns | ||
// any error and response body | ||
func HostQuery(endpoint string, args ...interface{}) (result HostResult) { | ||
log.Infof("HostQuery called") | ||
result_ch, err := hostQueryAsync(endpoint, args...) | ||
|
||
if err != nil { | ||
result.Err = err | ||
return | ||
} | ||
|
||
result = <-result_ch | ||
return | ||
} | ||
|
||
// hostQueryAsync calls the corresponding D-Bus endpoint on the host and returns | ||
// a channel for the result, and any error | ||
func hostQueryAsync(endpoint string, args ...interface{}) (chan HostResult, error) { | ||
log.Infof("HostQueryAsync called") | ||
var result_ch = make(chan HostResult, 1) | ||
conn, err := dbus.SystemBus() | ||
if err != nil { | ||
return result_ch, err | ||
} | ||
log.Infof("HostQueryAsync conn established") | ||
|
||
service := strings.SplitN(endpoint, ".", 2) | ||
const bus_name_base = "org.SONiC.HostService." | ||
bus_name := bus_name_base + service[0] | ||
bus_path := dbus.ObjectPath("/org/SONiC/HostService/" + service[0]) | ||
|
||
obj := conn.Object(bus_name, bus_path) | ||
dest := bus_name_base + endpoint | ||
dbus_ch := make(chan *dbus.Call, 1) | ||
//log.Infof("HostQueryAsync dbus called %s "% string(bus_path)) | ||
//log.Infof("HostQueryAsync dbus called %s "% string(bus_name)) | ||
|
||
go func() { | ||
var result HostResult | ||
|
||
// Wait for a read on the channel | ||
call := <-dbus_ch | ||
|
||
if call.Err != nil { | ||
log.Infof("HostQueryAsync Err is not nill while reading") | ||
result.Err = call.Err | ||
} else { | ||
log.Infof("HostQueryAsync Body is taken") | ||
result.Body = call.Body | ||
} | ||
|
||
// Write the result to the channel | ||
result_ch <- result | ||
}() | ||
|
||
log.Infof("HostQueryAsync Before objgo") | ||
call := obj.Go(dest, 0, dbus_ch, args...) | ||
|
||
if call.Err != nil { | ||
log.Infof("HostQueryAsync Err is not after obj.Go") | ||
return result_ch, call.Err | ||
} | ||
|
||
return result_ch, nil | ||
} | ||
|
||
// Example | ||
/* | ||
ztpAction calls the ZTP endpoint on the host and returns the status | ||
func ztpAction(action string) (string, error) { | ||
var output string | ||
// result.Body is of type []interface{}, since any data may be returned by | ||
// the host server. The application is responsible for performing | ||
// type assertions to get the correct data. | ||
result := HostQuery("ztp." + action) | ||
|
||
if result.Err != nil { | ||
return output, result.Err | ||
} | ||
|
||
if action == "status" { | ||
// ztp.status returns an exit code and the stdout of the command | ||
// We only care about the stdout (which is at [1] in the slice) | ||
output, _ = result.Body[1].(string) | ||
} | ||
|
||
return output, nil | ||
} | ||
|
||
// The following uses the hostQueryAsync option | ||
func ztpAction(action string) (string, error) { | ||
var output string | ||
// body is of type []interface{}, since any data may be returned by | ||
// the host server. The application is responsible for performing | ||
// type assertions to get the correct data. | ||
ch, err := hostQueryAsync("ztp." + action) | ||
|
||
if err != nil { | ||
return output, err | ||
} | ||
|
||
// Wait for the call to finish | ||
result := <-ch | ||
if result.Err != nil { | ||
return output, result.Err | ||
} | ||
|
||
if action == "status" { | ||
// ztp.status returns an exit code and the stdout of the command | ||
// We only care about the stdout (which is at [1] in the slice) | ||
output, _ = result.Body[1].(string) | ||
} | ||
|
||
return output, nil | ||
} | ||
|
||
*/ | ||
|
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,100 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// Copyright 2019 Dell, Inc. // | ||
// // | ||
// 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 transformer | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/Azure/sonic-mgmt-common/translib/tlerr" | ||
"github.com/Azure/sonic-mgmt-common/translib/db" | ||
"github.com/golang/glog" | ||
"regexp" | ||
) | ||
|
||
func init() { | ||
XlateFuncBind("rpc_showtech_cb", rpc_showtech_cb) | ||
} | ||
|
||
var rpc_showtech_cb RpcCallpoint = func(body []byte, dbs [db.MaxDB]*db.DB) ([]byte, error) { | ||
var err error | ||
var matched bool | ||
var output string | ||
var operand struct { | ||
Input struct { | ||
Date string `json:"date"` | ||
} `json:"sonic-show-techsupport:input"` | ||
} | ||
|
||
err = json.Unmarshal(body, &operand) | ||
if err != nil { | ||
glog.Errorf("%Error: Failed to parse rpc input; err=%v", err) | ||
return nil,tlerr.InvalidArgs("Invalid rpc input") | ||
} | ||
|
||
if operand.Input.Date == "" { | ||
matched = true | ||
} else { | ||
matched, _ = regexp.MatchString((`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?` + | ||
`(Z|[\+\-]\d{2}:\d{2})`), operand.Input.Date) | ||
if err != nil { | ||
glog.Errorf("%Error: Failed to match regex pattern for parsesd rpc input; err=%v", err) | ||
} | ||
|
||
} | ||
|
||
var showtech struct { | ||
Output struct { | ||
Status string `json:"output-status"` | ||
Filename string `json:"output-filename"` | ||
} `json:"sonic-show-techsupport:output"` | ||
} | ||
|
||
if !(matched) { | ||
showtech.Output.Status = "Invalid input: Incorrect DateTime format" | ||
showtech.Output.Filename = "" | ||
result, _ := json.Marshal(&showtech) | ||
return result, nil | ||
} | ||
|
||
host_output := HostQuery("showtech.info", operand.Input.Date) | ||
if host_output.Err != nil { | ||
glog.Errorf("%Error: Showtech host Query failed: err=%v", host_output.Err) | ||
glog.Flush() | ||
showtech.Output.Status = host_output.Err.Error() | ||
showtech.Output.Filename = "" | ||
result, _ := json.Marshal(&showtech) | ||
return result, nil | ||
} | ||
|
||
output, _ = host_output.Body[1].(string) | ||
matched, _ = regexp.MatchString(`\/var\/.*dump.*\.gz`, output) | ||
if err != nil { | ||
glog.Errorf("%Error: Failed to find a filename in rpc output: %v", output) | ||
showtech.Output.Status = output | ||
showtech.Output.Filename = "" | ||
result, _ := json.Marshal(&showtech) | ||
return result, nil | ||
} | ||
|
||
showtech.Output.Status = "Success" | ||
showtech.Output.Filename = output | ||
result, _ := json.Marshal(&showtech) | ||
|
||
return result, nil | ||
} | ||
|
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.
why these yang model not in sonic-yang-model in build image?
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 use RPC (to invoke internal Click command via d-bus infra) for show-tech operation from mgmt-framework and no config-DB update here and hence no YANG model is present in sonic-yang-model in build image.