-
Notifications
You must be signed in to change notification settings - Fork 101
gNOI System APIs (Reboot, RebootStatus, CancelReboot) changes #308
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
a0e8682
gNOI System APIs (Reboot, RebootStatus, Cancelreboot) changes
ndas7 df12586
gNOI System APIs (Reboot, RebootStatus, Cancelreboot) changes
ndas7 d684c78
gNOI System APIs (Reboot, RebootStatus, Cancelreboot) changes
ndas7 58dc8bc
gNOI System APIs (Reboot, RebootStatus, Cancelreboot) changes
ndas7 e231e75
gNOI System APIs (Reboot, RebootStatus, Cancelreboot) changes
ndas7 457de62
gNOI System APIs (Reboot, RebootStatus, Cancelreboot) changes
ndas7 bfef03a
gNOI System APIs (Reboot, RebootStatus, CancelReboot) changes
ndas7 d2bcd6c
gNOI System APIs (Reboot, RebootStatus, CancelReboot) changes
ndas7 4ab6795
Merge branch 'master' into gnoi_reboot
ndas7 d4f6ae2
gNOI System APIs (Reboot, RebootStatus, CancelReboot) changes
ndas7 55e88d1
gNOI System APIs (Reboot, RebootStatus, CancelReboot) changes
ndas7 1f6e82a
Merge branch 'sonic-net:master' into gnoi_reboot
ndas7 4f8b08c
Update gnoi_system.go
ndas7 32277ed
Update gnoi_system.go
ndas7 f63d712
Update gnoi_system_test.go
ndas7 caf0ea2
Update gnoi_system.go
ndas7 e370d8a
Merge branch 'master' into gnoi_reboot
ndas7 1c175b9
Update gnoi_system.go
ndas7 f5c9091
Merge branch 'master' into gnoi_reboot
ndas7 72965a1
Merge branch 'master' into gnoi_reboot
ndas7 9d2f425
Update gnoi_system.go
ndas7 51fe3cd
Update gnoi_system_test.go
ndas7 2a04d63
Update swss_util.go
ndas7 a194fdf
Merge branch 'master' into gnoi_reboot
ndas7 66455ed
Update go.sum
ndas7 4ceab6a
Update gnoi_system.go
ndas7 76e110b
Update gnoi_system_test.go
ndas7 5b0c49f
Merge branch 'master' into gnoi_reboot
ndas7 06dc0e2
Update Go formatting for files
ndas7 c3a58eb
Remove old way of HALT Reboot method (#1)
vvolam cfb8d78
Fix test_gnoi_reboot_halt
vvolam b11e9b1
Merge branch 'master' into gnoi_reboot
ndas7 226fc74
Update go.mod and go.sum files
ndas7 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 hidden or 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 hidden or 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,89 @@ | ||
| package common_utils | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/go-redis/redis" | ||
| log "github.com/golang/glog" | ||
| sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config" | ||
| ) | ||
|
|
||
| const ( | ||
| dbName = "STATE_DB" | ||
| ) | ||
|
|
||
| func GetRedisDBClient() (*redis.Client, error) { | ||
| ns, _ := sdcfg.GetDbDefaultNamespace() | ||
| addr, err := sdcfg.GetDbTcpAddr(dbName, ns) | ||
| if err != nil { | ||
| log.Errorf("Addr err: %v", err) | ||
| return nil, err | ||
| } | ||
| db, err := sdcfg.GetDbId("STATE_DB", ns) | ||
| if err != nil { | ||
| log.Errorf("DB err: %v", err) | ||
| return nil, err | ||
| } | ||
| rclient := redis.NewClient(&redis.Options{ | ||
| Network: "tcp", | ||
| Addr: addr, | ||
| Password: "", // no password set | ||
| DB: db, | ||
| DialTimeout: 0, | ||
| }) | ||
| if rclient == nil { | ||
| return nil, fmt.Errorf("Cannot create redis client.") | ||
| } | ||
| if _, err := rclient.Ping().Result(); err != nil { | ||
| return nil, err | ||
| } | ||
| return rclient, nil | ||
| } | ||
|
|
||
| // NotificationProducer provides utilities for sending messages using notification channel. | ||
| // NewNotificationProducer must be called for a new producer. | ||
| // Close must be called when finished. | ||
| type NotificationProducer struct { | ||
| ch string | ||
| rc *redis.Client | ||
| } | ||
|
|
||
| // NewNotificationProducer returns a new NotificationProducer. | ||
| func NewNotificationProducer(ch string) (*NotificationProducer, error) { | ||
| n := new(NotificationProducer) | ||
| n.ch = ch | ||
|
|
||
| // Create redis client. | ||
| var err error | ||
| n.rc, err = GetRedisDBClient() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return n, nil | ||
| } | ||
|
|
||
| // Close performs cleanup works. | ||
| // Close must be called when finished. | ||
| func (n *NotificationProducer) Close() { | ||
| if n.rc != nil { | ||
| n.rc.Close() | ||
| } | ||
| } | ||
|
|
||
| func (n *NotificationProducer) Send(op, data string, kvs map[string]string) error { | ||
| fvs := []string{op, data} | ||
| for k, v := range kvs { | ||
| fvs = append(fvs, k) | ||
| fvs = append(fvs, v) | ||
| } | ||
|
|
||
| val, err := json.Marshal(fvs) | ||
| if err != nil { | ||
| log.Error(err.Error()) | ||
| return err | ||
| } | ||
| log.Infof("Publishing to channel %s: %v.", n.ch, string(val)) | ||
| return n.rc.Publish(n.ch, val).Err() | ||
| } |
This file contains hidden or 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 @@ | ||
| package common_utils | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| const ( | ||
| channel string = "channel" | ||
| ) | ||
|
|
||
| func TestNotificationProducerSucceedsWithEmptyOp(t *testing.T) { | ||
| n, _ := NewNotificationProducer(channel) | ||
| defer n.Close() | ||
| if err := n.Send("", "somedata", map[string]string{}); err != nil { | ||
| t.Fatalf("Expected no error!") | ||
| } | ||
| } | ||
|
|
||
| func TestNotificationProducerSucceedsWithEmptyData(t *testing.T) { | ||
| n, _ := NewNotificationProducer(channel) | ||
| defer n.Close() | ||
| if err := n.Send("someop", "", map[string]string{}); err != nil { | ||
| t.Fatalf("Expected no error!") | ||
| } | ||
| } | ||
|
|
||
| func TestNotificationProducerSucceedsWithEmptyOpAndData(t *testing.T) { | ||
| n, _ := NewNotificationProducer(channel) | ||
| defer n.Close() | ||
| if err := n.Send("", "", map[string]string{}); err != nil { | ||
| t.Fatalf("Expected no error!") | ||
| } | ||
| } | ||
|
|
||
| func TestNotificationProducerSucceedsWithEmptyKeyValues(t *testing.T) { | ||
| n, _ := NewNotificationProducer(channel) | ||
| defer n.Close() | ||
| if err := n.Send("someop", "somedata", map[string]string{}); err != nil { | ||
| t.Fatalf("Expected no error!") | ||
| } | ||
| } | ||
|
|
||
| func TestNotificationProducerSucceeds(t *testing.T) { | ||
| n, _ := NewNotificationProducer(channel) | ||
| defer n.Close() | ||
| if err := n.Send("someop", "somedata", map[string]string{"somekey": "somevalue"}); err != nil { | ||
| t.Fatalf("Expected no error!") | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
@vvolam your code is deleted. Could you double check?
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.
Hi Qi, the DBUS handling for HALT method was removed since HALT will now use the Reboot Notification Channel similar to the other Reboot Methods. Hence, this code was removed through Vasundhara's commit https://github.com/ndas7/sonic-gnmi/pull/1/files merged into this PR