Skip to content

Commit 5156527

Browse files
authored
Showtech sonic mgmt framework: Add Management Framework functionality for "show tech-support" (#49)
Provide the changes required for supporting the "show-techsupport" command via the SONiC Management Framework front end mechanisms (CLI, REST, and gNOI). The Management Framework functionality implemented by this PR improves on the the capabilities currently provided by the SONiC Click CLI interface via the "show techsupport" command by providing the following additional features: User-friendly "help" information describing command syntax details for CLI invocation. Ability to invoke the command via REST and gNOI mechanisms. Unit test results are attached to this PR. unit_test_log_0607.txt Corequisite PRs: sonic-net/sonic-telemetry#78 sonic-net/sonic-telemetry#79
1 parent d43a607 commit 5156527

4 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module sonic-showtech-annot {
2+
3+
yang-version "1";
4+
5+
namespace "http://openconfig.net/Azure/sonic-showtech-annot";
6+
prefix "showtech-annot";
7+
8+
import sonic-extensions { prefix sonic-ext; }
9+
import sonic-show-techsupport { prefix sshwtchspt; }
10+
11+
deviation /sshwtchspt:sonic-show-techsupport-info {
12+
deviate add {
13+
sonic-ext:rpc-callback "rpc_showtech_cb";
14+
}
15+
}
16+
17+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module sonic-show-techsupport {
2+
namespace "http://github.com/Azure/sonic-show-techsupport";
3+
prefix sshwtchspt;
4+
yang-version 1.1;
5+
6+
import ietf-yang-types {
7+
prefix yang;
8+
}
9+
10+
organization
11+
"SONiC";
12+
13+
contact
14+
"SONiC";
15+
16+
description
17+
"SONiC TECH SUPPORT INFORMATION";
18+
19+
revision 2019-10-15 {
20+
description
21+
"Initial revision.";
22+
}
23+
24+
rpc sonic-show-techsupport-info {
25+
input {
26+
leaf date {
27+
type yang:date-and-time;
28+
description
29+
"Date and time specification of the desired start
30+
point for collected log and core information";
31+
}
32+
}
33+
output {
34+
leaf output-status {
35+
type string;
36+
description
37+
"'Success' or detailed failure message for execution of the
38+
'show tech-support' request";
39+
}
40+
leaf output-filename {
41+
type string;
42+
description
43+
"Name of the host compressed tar file containing the collected
44+
technical support information";
45+
}
46+
}
47+
}
48+
}
49+

translib/transformer/host_comm.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package transformer
2+
3+
import (
4+
"strings"
5+
6+
"github.com/godbus/dbus/v5"
7+
log "github.com/golang/glog"
8+
)
9+
10+
// HostResult contains the body of the response and the error if any, when the
11+
// endpoint finishes servicing the D-Bus request.
12+
type HostResult struct {
13+
Body []interface{}
14+
Err error
15+
}
16+
17+
// HostQuery calls the corresponding D-Bus endpoint on the host and returns
18+
// any error and response body
19+
func HostQuery(endpoint string, args ...interface{}) (result HostResult) {
20+
log.Infof("HostQuery called")
21+
result_ch, err := hostQueryAsync(endpoint, args...)
22+
23+
if err != nil {
24+
result.Err = err
25+
return
26+
}
27+
28+
result = <-result_ch
29+
return
30+
}
31+
32+
// hostQueryAsync calls the corresponding D-Bus endpoint on the host and returns
33+
// a channel for the result, and any error
34+
func hostQueryAsync(endpoint string, args ...interface{}) (chan HostResult, error) {
35+
log.Infof("HostQueryAsync called")
36+
var result_ch = make(chan HostResult, 1)
37+
conn, err := dbus.SystemBus()
38+
if err != nil {
39+
return result_ch, err
40+
}
41+
log.Infof("HostQueryAsync conn established")
42+
43+
service := strings.SplitN(endpoint, ".", 2)
44+
const bus_name_base = "org.SONiC.HostService."
45+
bus_name := bus_name_base + service[0]
46+
bus_path := dbus.ObjectPath("/org/SONiC/HostService/" + service[0])
47+
48+
obj := conn.Object(bus_name, bus_path)
49+
dest := bus_name_base + endpoint
50+
dbus_ch := make(chan *dbus.Call, 1)
51+
//log.Infof("HostQueryAsync dbus called %s "% string(bus_path))
52+
//log.Infof("HostQueryAsync dbus called %s "% string(bus_name))
53+
54+
go func() {
55+
var result HostResult
56+
57+
// Wait for a read on the channel
58+
call := <-dbus_ch
59+
60+
if call.Err != nil {
61+
log.Infof("HostQueryAsync Err is not nill while reading")
62+
result.Err = call.Err
63+
} else {
64+
log.Infof("HostQueryAsync Body is taken")
65+
result.Body = call.Body
66+
}
67+
68+
// Write the result to the channel
69+
result_ch <- result
70+
}()
71+
72+
log.Infof("HostQueryAsync Before objgo")
73+
call := obj.Go(dest, 0, dbus_ch, args...)
74+
75+
if call.Err != nil {
76+
log.Infof("HostQueryAsync Err is not after obj.Go")
77+
return result_ch, call.Err
78+
}
79+
80+
return result_ch, nil
81+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// Copyright 2019 Dell, Inc. //
4+
// //
5+
// Licensed under the Apache License, Version 2.0 (the "License"); //
6+
// you may not use this file except in compliance with the License. //
7+
// You may obtain a copy of the License at //
8+
// //
9+
// http://www.apache.org/licenses/LICENSE-2.0 //
10+
// //
11+
// Unless required by applicable law or agreed to in writing, software //
12+
// distributed under the License is distributed on an "AS IS" BASIS, //
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
14+
// See the License for the specific language governing permissions and //
15+
// limitations under the License. //
16+
// //
17+
////////////////////////////////////////////////////////////////////////////////
18+
19+
package transformer
20+
21+
import (
22+
"encoding/json"
23+
"github.com/Azure/sonic-mgmt-common/translib/tlerr"
24+
"github.com/Azure/sonic-mgmt-common/translib/db"
25+
"github.com/golang/glog"
26+
"regexp"
27+
)
28+
29+
func init() {
30+
XlateFuncBind("rpc_showtech_cb", rpc_showtech_cb)
31+
}
32+
33+
var rpc_showtech_cb RpcCallpoint = func(body []byte, dbs [db.MaxDB]*db.DB) ([]byte, error) {
34+
var err error
35+
var matched bool
36+
var output string
37+
var operand struct {
38+
Input struct {
39+
Date string `json:"date"`
40+
} `json:"sonic-show-techsupport:input"`
41+
}
42+
43+
err = json.Unmarshal(body, &operand)
44+
if err != nil {
45+
glog.Errorf("%Error: Failed to parse rpc input; err=%v", err)
46+
return nil,tlerr.InvalidArgs("Invalid rpc input")
47+
}
48+
49+
if operand.Input.Date == "" {
50+
matched = true
51+
} else {
52+
matched, _ = regexp.MatchString((`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?` +
53+
`(Z|[\+\-]\d{2}:\d{2})`), operand.Input.Date)
54+
if err != nil {
55+
glog.Errorf("%Error: Failed to match regex pattern for parsesd rpc input; err=%v", err)
56+
}
57+
58+
}
59+
60+
var showtech struct {
61+
Output struct {
62+
Status string `json:"output-status"`
63+
Filename string `json:"output-filename"`
64+
} `json:"sonic-show-techsupport:output"`
65+
}
66+
67+
if !(matched) {
68+
showtech.Output.Status = "Invalid input: Incorrect DateTime format"
69+
showtech.Output.Filename = ""
70+
result, _ := json.Marshal(&showtech)
71+
return result, nil
72+
}
73+
74+
host_output := HostQuery("showtech.info", operand.Input.Date)
75+
if host_output.Err != nil {
76+
glog.Errorf("%Error: Showtech host Query failed: err=%v", host_output.Err)
77+
glog.Flush()
78+
showtech.Output.Status = host_output.Err.Error()
79+
showtech.Output.Filename = ""
80+
result, _ := json.Marshal(&showtech)
81+
return result, nil
82+
}
83+
84+
output, _ = host_output.Body[1].(string)
85+
matched, _ = regexp.MatchString(`\/var\/.*dump.*\.gz`, output)
86+
if err != nil {
87+
glog.Errorf("%Error: Failed to find a filename in rpc output: %v", output)
88+
showtech.Output.Status = output
89+
showtech.Output.Filename = ""
90+
result, _ := json.Marshal(&showtech)
91+
return result, nil
92+
}
93+
94+
showtech.Output.Status = "Success"
95+
showtech.Output.Filename = output
96+
result, _ := json.Marshal(&showtech)
97+
98+
return result, nil
99+
}
100+

0 commit comments

Comments
 (0)