forked from TrueCloudLab/frostfs-node
Compare commits
5 commits
master
...
bugfix/set
Author | SHA1 | Date | |
---|---|---|---|
81f1e48786 | |||
512a2fa4ce | |||
e05deb6dea | |||
a9b93676e0 | |||
4331bd1143 |
3 changed files with 107 additions and 23 deletions
|
@ -137,6 +137,8 @@ func SetConfigCmd(cmd *cobra.Command, args []string) error {
|
|||
return wCtx.AwaitTx()
|
||||
}
|
||||
|
||||
const maxECSum = 256
|
||||
|
||||
func validateConfig(args map[string]any, forceFlag bool) error {
|
||||
var sumEC int64
|
||||
_, okData := args[netmap.MaxECDataCountConfig]
|
||||
|
@ -147,19 +149,34 @@ func validateConfig(args map[string]any, forceFlag bool) error {
|
|||
}
|
||||
|
||||
for k, v := range args {
|
||||
value, ok := v.(int64)
|
||||
if !ok || value < 0 {
|
||||
return fmt.Errorf("%s must be >= 0, got %v", k, v)
|
||||
}
|
||||
switch k {
|
||||
case netmap.ContainerFeeConfig, netmap.ContainerAliasFeeConfig,
|
||||
netmap.EpochDurationConfig, netmap.IrCandidateFeeConfig,
|
||||
netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig,
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig:
|
||||
value, ok := v.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s has an invalid type. Expected type: int", k)
|
||||
}
|
||||
|
||||
if k == netmap.MaxECDataCountConfig || k == netmap.MaxECParityCountConfig {
|
||||
sumEC += value
|
||||
if value < 0 {
|
||||
return fmt.Errorf("%s must be >= 0, got %v", k, v)
|
||||
}
|
||||
|
||||
if k == netmap.MaxECDataCountConfig || k == netmap.MaxECParityCountConfig {
|
||||
sumEC += value
|
||||
}
|
||||
case netmap.HomomorphicHashingDisabledKey, netmap.MaintenanceModeAllowedConfig:
|
||||
_, ok := v.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s has an invalid type. Expected type: bool", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if sumEC > 256 && !forceFlag {
|
||||
return fmt.Errorf("the sum of %s and %s must be <= 256, got %d",
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig, sumEC)
|
||||
if sumEC > maxECSum && !forceFlag {
|
||||
return fmt.Errorf("the sum of %s and %s must be <= %d, got %d",
|
||||
netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig, maxECSum, sumEC)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
34
cmd/frostfs-adm/internal/modules/morph/config/config_test.go
Normal file
34
cmd/frostfs-adm/internal/modules/morph/config/config_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_ValidateConfig(t *testing.T) {
|
||||
testArgs := make(map[string]any)
|
||||
|
||||
testArgs[netmap.MaxECDataCountConfig] = int64(11)
|
||||
require.Error(t, validateConfig(testArgs, false))
|
||||
|
||||
testArgs[netmap.MaxECParityCountConfig] = int64(256)
|
||||
require.Error(t, validateConfig(testArgs, false))
|
||||
require.NoError(t, validateConfig(testArgs, true))
|
||||
|
||||
testArgs[netmap.MaxECParityCountConfig] = int64(-1)
|
||||
require.Error(t, validateConfig(testArgs, false))
|
||||
|
||||
testArgs[netmap.MaxECParityCountConfig] = int64(55)
|
||||
require.NoError(t, validateConfig(testArgs, false))
|
||||
|
||||
testArgs[netmap.HomomorphicHashingDisabledKey] = "1"
|
||||
require.Error(t, validateConfig(testArgs, false))
|
||||
|
||||
testArgs[netmap.HomomorphicHashingDisabledKey] = true
|
||||
require.NoError(t, validateConfig(testArgs, false))
|
||||
|
||||
testArgs["not-well-known-configuration-key"] = "key"
|
||||
require.NoError(t, validateConfig(testArgs, false))
|
||||
}
|
|
@ -3,6 +3,9 @@ package frostfsid
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||
"sort"
|
||||
|
||||
frostfsidclient "git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
||||
|
@ -250,12 +253,21 @@ func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func frostfsidListNamespaces(cmd *cobra.Command, _ []string) {
|
||||
ffsid, err := newFrostfsIDClient(cmd)
|
||||
commonCmd.ExitOnErr(cmd, "init contract invoker: %w", err)
|
||||
c, err := helper.GetN3Client(viper.GetViper())
|
||||
commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err)
|
||||
|
||||
namespaces, err := ffsid.roCli.ListNamespaces()
|
||||
inv := invoker.New(c, nil)
|
||||
r := management.NewReader(inv)
|
||||
|
||||
cs, err := r.GetContractByID(1)
|
||||
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
|
||||
|
||||
nmHash, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
||||
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
||||
|
||||
item, err := commonclient.ReadIteratorItems(inv, 100, nmHash, "listNamespaces")
|
||||
commonCmd.ExitOnErr(cmd, "list namespaces: %w", err)
|
||||
|
||||
namespaces, _ := frostfsidclient.ParseNamespaces(item)
|
||||
sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].Name < namespaces[j].Name })
|
||||
|
||||
for _, namespace := range namespaces {
|
||||
|
@ -296,14 +308,21 @@ func frostfsidDeleteSubject(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func frostfsidListSubjects(cmd *cobra.Command, _ []string) {
|
||||
ns := getFrostfsIDNamespace(cmd)
|
||||
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
||||
c, err := helper.GetN3Client(viper.GetViper())
|
||||
commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err)
|
||||
|
||||
ffsid, err := newFrostfsIDClient(cmd)
|
||||
commonCmd.ExitOnErr(cmd, "init contract invoker: %w", err)
|
||||
inv := invoker.New(c, nil)
|
||||
r := management.NewReader(inv)
|
||||
|
||||
subAddresses, err := ffsid.roCli.ListNamespaceSubjects(ns)
|
||||
commonCmd.ExitOnErr(cmd, "list subjects: %w", err)
|
||||
cs, err := r.GetContractByID(1)
|
||||
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
|
||||
|
||||
nmHash, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
||||
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
||||
|
||||
ns := getFrostfsIDNamespace(cmd)
|
||||
subAddresses, _ := frostfsidclient.UnwrapArrayOfUint160(commonclient.ReadIteratorItems(inv, 100, nmHash, "listNamespaceSubjects", ns))
|
||||
|
||||
sort.Slice(subAddresses, func(i, j int) bool { return subAddresses[i].Less(subAddresses[j]) })
|
||||
|
||||
|
@ -313,7 +332,10 @@ func frostfsidListSubjects(cmd *cobra.Command, _ []string) {
|
|||
continue
|
||||
}
|
||||
|
||||
subj, err := ffsid.roCli.GetSubject(addr)
|
||||
items, err := unwrap.Array(inv.Call(nmHash, "getSubject", addr))
|
||||
commonCmd.ExitOnErr(cmd, "get subject: %w", err)
|
||||
|
||||
subj, err := frostfsidclient.ParseSubject(items)
|
||||
commonCmd.ExitOnErr(cmd, "get subject: %w", err)
|
||||
|
||||
cmd.Printf("%s (%s)\n", address.Uint160ToString(addr), subj.Name)
|
||||
|
@ -349,12 +371,23 @@ func frostfsidDeleteGroup(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func frostfsidListGroups(cmd *cobra.Command, _ []string) {
|
||||
c, err := helper.GetN3Client(viper.GetViper())
|
||||
commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err)
|
||||
|
||||
inv := invoker.New(c, nil)
|
||||
r := management.NewReader(inv)
|
||||
|
||||
cs, err := r.GetContractByID(1)
|
||||
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
|
||||
|
||||
nmHash, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
||||
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
||||
|
||||
ns := getFrostfsIDNamespace(cmd)
|
||||
items, err := commonclient.ReadIteratorItems(inv, 100, nmHash, "listGroups", ns)
|
||||
commonCmd.ExitOnErr(cmd, "list groups: %w", err)
|
||||
|
||||
ffsid, err := newFrostfsIDClient(cmd)
|
||||
commonCmd.ExitOnErr(cmd, "init contract invoker: %w", err)
|
||||
|
||||
groups, err := ffsid.roCli.ListGroups(ns)
|
||||
groups, err := frostfsidclient.ParseGroups(items)
|
||||
commonCmd.ExitOnErr(cmd, "list groups: %w", err)
|
||||
|
||||
sort.Slice(groups, func(i, j int) bool { return groups[i].Name < groups[j].Name })
|
||||
|
|
Loading…
Reference in a new issue