[#1] node: Use a proper validation of a substorage type

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-06-26 14:43:25 +03:00 committed by Evgenii Stratonikov
parent f4c71cea65
commit 73a71a71b0
2 changed files with 5 additions and 14 deletions

View file

@ -5,8 +5,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/storage" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/storage"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
) )
// Config is a wrapper over the config section // Config is a wrapper over the config section
@ -25,14 +23,11 @@ func (x *Config) Storages() []*storage.Config {
typ := config.String( typ := config.String(
(*config.Config)(x), (*config.Config)(x),
strconv.Itoa(i)+".type") strconv.Itoa(i)+".type")
switch typ { if typ == "" {
case "":
return ss return ss
case fstree.Type, blobovniczatree.Type:
sub := storage.From((*config.Config)(x).Sub(strconv.Itoa(i)))
ss = append(ss, sub)
default:
panic("invalid type")
} }
sub := storage.From((*config.Config)(x).Sub(strconv.Itoa(i)))
ss = append(ss, sub)
} }
} }

View file

@ -51,17 +51,13 @@ func validateConfig(c *config.Config) error {
blobstor := sc.BlobStor().Storages() blobstor := sc.BlobStor().Storages()
if len(blobstor) != 2 { if len(blobstor) != 2 {
// TODO (@fyrcik): remove after #1522
return fmt.Errorf("blobstor section must have 2 components, got: %d", len(blobstor)) return fmt.Errorf("blobstor section must have 2 components, got: %d", len(blobstor))
} }
for i := range blobstor { for i := range blobstor {
switch blobstor[i].Type() { switch blobstor[i].Type() {
case fstree.Type, blobovniczatree.Type: case fstree.Type, blobovniczatree.Type:
default: default:
// FIXME #1764 (@fyrchik): this line is currently unreachable, return fmt.Errorf("unexpected storage type: %s (shard %d)", blobstor[i].Type(), shardNum)
// because we panic in `sc.BlobStor().Storages()`.
return fmt.Errorf("unexpected storage type: %s (shard %d)",
blobstor[i].Type(), shardNum)
} }
if blobstor[i].Perm()&0600 != 0600 { if blobstor[i].Perm()&0600 != 0600 {
return fmt.Errorf("invalid permissions for blobstor component: %s, "+ return fmt.Errorf("invalid permissions for blobstor component: %s, "+