[#315] netmap: Add maintenance node state

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-15 08:51:24 +03:00 committed by LeL
parent 3dad44232e
commit 3d6b5d807b
2 changed files with 41 additions and 0 deletions

View file

@ -558,3 +558,21 @@ func (x *NodeInfo) SetOnline() {
func (x NodeInfo) IsOnline() bool {
return x.m.GetState() == netmap.Online
}
// SetMaintenance sets the state of the node to "maintenance". When a node updates
// information about itself in the network map, this
// state declares temporal unavailability for a node.
//
// See also IsMaintenance.
func (x *NodeInfo) SetMaintenance() {
x.m.SetState(netmap.Maintenance)
}
// IsMaintenance checks if the node is in the "maintenance" state.
//
// Zero NodeInfo has undefined state.
//
// See also SetMaintenance.
func (x NodeInfo) IsMaintenance() bool {
return x.m.GetState() == netmap.Maintenance
}

View file

@ -22,3 +22,26 @@ func TestNodeInfo_SetAttribute(t *testing.T) {
n.SetAttribute(key, val)
require.Equal(t, val, n.Attribute(key))
}
func TestNodeInfo_Status(t *testing.T) {
var n NodeInfo
require.False(t, n.IsOnline())
require.False(t, n.IsOffline())
require.False(t, n.IsMaintenance())
n.SetOnline()
require.True(t, n.IsOnline())
require.False(t, n.IsOffline())
require.False(t, n.IsMaintenance())
n.SetOffline()
require.True(t, n.IsOffline())
require.False(t, n.IsOnline())
require.False(t, n.IsMaintenance())
n.SetMaintenance()
require.True(t, n.IsMaintenance())
require.False(t, n.IsOnline())
require.False(t, n.IsOffline())
}