[#217] netmap: Return node netmap state directly
All checks were successful
DCO / DCO (pull_request) Successful in 54s
Tests and linters / Tests (1.23) (pull_request) Successful in 1m3s
Tests and linters / Tests (1.22) (pull_request) Successful in 1m6s
Tests and linters / Lint (pull_request) Successful in 1m37s

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-09-03 17:17:25 +03:00
parent 8f751d9dd0
commit 3b25f94237
No known key found for this signature in database
2 changed files with 32 additions and 0 deletions

View file

@ -460,6 +460,8 @@ func (x *NodeInfo) SortAttributes() {
// SetOffline sets the state of the node to "offline". When a node updates
// information about itself in the network map, this action is interpreted as
// an intention to leave the network.
//
// See also IsOffline.
func (x *NodeInfo) SetOffline() {
x.m.SetState(netmap.Offline)
}
@ -470,6 +472,8 @@ func (x *NodeInfo) SetOffline() {
// mean online).
//
// See also SetOffline.
//
// Deprecated: use Status instead.
func (x NodeInfo) IsOffline() bool {
return x.m.GetState() == netmap.Offline
}
@ -489,6 +493,8 @@ func (x *NodeInfo) SetOnline() {
// mean offline).
//
// See also SetOnline.
//
// Deprecated: use Status instead.
func (x NodeInfo) IsOnline() bool {
return x.m.GetState() == netmap.Online
}
@ -507,6 +513,15 @@ func (x *NodeInfo) SetMaintenance() {
// Zero NodeInfo has undefined state.
//
// See also SetMaintenance.
//
// Deprecated: use Status instead.
func (x NodeInfo) IsMaintenance() bool {
return x.m.GetState() == netmap.Maintenance
}
// Status returns the current state of the node in the network map.
//
// Zero NodeInfo has an undefined state, neither online nor offline.
func (x NodeInfo) Status() netmap.NodeState {
return x.m.GetState()
}

View file

@ -3,6 +3,7 @@ package netmap
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
"github.com/stretchr/testify/require"
)
@ -30,20 +31,36 @@ func TestNodeInfo_Status(t *testing.T) {
require.False(t, n.IsOffline())
require.False(t, n.IsMaintenance())
require.NotEqual(t, netmap.Online, n.Status())
require.NotEqual(t, netmap.Offline, n.Status())
require.NotEqual(t, netmap.Maintenance, n.Status())
n.SetOnline()
require.True(t, n.IsOnline())
require.False(t, n.IsOffline())
require.False(t, n.IsMaintenance())
require.Equal(t, netmap.Online, n.Status())
require.NotEqual(t, netmap.Offline, n.Status())
require.NotEqual(t, netmap.Maintenance, n.Status())
n.SetOffline()
require.True(t, n.IsOffline())
require.False(t, n.IsOnline())
require.False(t, n.IsMaintenance())
require.NotEqual(t, netmap.Online, n.Status())
require.Equal(t, netmap.Offline, n.Status())
require.NotEqual(t, netmap.Maintenance, n.Status())
n.SetMaintenance()
require.True(t, n.IsMaintenance())
require.False(t, n.IsOnline())
require.False(t, n.IsOffline())
require.NotEqual(t, netmap.Online, n.Status())
require.NotEqual(t, netmap.Offline, n.Status())
require.Equal(t, netmap.Maintenance, n.Status())
}
func TestNodeInfo_ExternalAddr(t *testing.T) {