forked from TrueCloudLab/frostfs-node
f64ae55806
There is a need to prevent limitless abuse of MAINTENANCE status of the storage nodes. To do this, configuration of the NeoFS network is going to be extended with the flag which allows the state. Until this is done, it makes sense to prepare a site for this in the code. Define `state.NetworkSettings` interface as an abstraction of global network configuration within the `state` package. Make `NetMapCandidateValidator` to depend on `NetworkSettings` and provide corresponding field setter. Change `VerifyAndUpdate` method's behavior to return an error for candidates with MAINTENANCE state if this state is disallowed by the network configuration. Provide `NetworkSettings` from the wrapper over Netmap contract's client on Inner Ring application side. The provider is implemented to statically disallow MAINTENANCE mode in order to save previous behavior. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru> Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
package state_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/state"
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// implements state.NetworkSettings for testing.
|
|
type testNetworkSettings struct {
|
|
disallowed bool
|
|
}
|
|
|
|
func (x testNetworkSettings) MaintenanceModeAllowed() error {
|
|
if x.disallowed {
|
|
return state.ErrMaintenanceModeDisallowed
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func TestValidator_VerifyAndUpdate(t *testing.T) {
|
|
var vDefault state.NetMapCandidateValidator
|
|
var s testNetworkSettings
|
|
|
|
vDefault.SetNetworkSettings(s)
|
|
|
|
for _, testCase := range []struct {
|
|
name string
|
|
preparer func(*netmap.NodeInfo) // modifies zero instance
|
|
valid bool // is node valid after preparation
|
|
|
|
validatorPreparer func(*state.NetMapCandidateValidator) // optionally modifies default validator
|
|
}{
|
|
{
|
|
name: "UNDEFINED",
|
|
preparer: func(info *netmap.NodeInfo) {},
|
|
valid: false,
|
|
},
|
|
{
|
|
name: "ONLINE",
|
|
preparer: (*netmap.NodeInfo).SetOnline,
|
|
valid: true,
|
|
},
|
|
{
|
|
name: "OFFLINE",
|
|
preparer: (*netmap.NodeInfo).SetOffline,
|
|
valid: false,
|
|
},
|
|
{
|
|
name: "MAINTENANCE/allowed",
|
|
preparer: (*netmap.NodeInfo).SetMaintenance,
|
|
valid: true,
|
|
},
|
|
{
|
|
name: "MAINTENANCE/disallowed",
|
|
preparer: (*netmap.NodeInfo).SetMaintenance,
|
|
valid: false,
|
|
validatorPreparer: func(v *state.NetMapCandidateValidator) {
|
|
var s testNetworkSettings
|
|
s.disallowed = true
|
|
|
|
v.SetNetworkSettings(s)
|
|
},
|
|
},
|
|
} {
|
|
var node netmap.NodeInfo
|
|
|
|
// prepare node
|
|
testCase.preparer(&node)
|
|
|
|
// save binary representation for mutation check
|
|
binNode := node.Marshal()
|
|
|
|
var v state.NetMapCandidateValidator
|
|
if testCase.validatorPreparer == nil {
|
|
v = vDefault
|
|
} else {
|
|
testCase.validatorPreparer(&v)
|
|
}
|
|
|
|
err := v.VerifyAndUpdate(&node)
|
|
|
|
if testCase.valid {
|
|
require.NoError(t, err, testCase.name)
|
|
} else {
|
|
require.Error(t, err, testCase.name)
|
|
}
|
|
|
|
// check mutation
|
|
require.Equal(t, binNode, node.Marshal(), testCase.name)
|
|
}
|
|
}
|