From f6ff3de0ae5ddf53b77a7d244ccdb0ca7ed432cf Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 1 Feb 2024 15:55:33 +0300 Subject: [PATCH] [#932] adm: Move `set-/dump-policy` to `policy` package Signed-off-by: Anton Nikiforov --- .../internal/modules/morph/initialize_test.go | 5 +- .../modules/morph/{ => policy}/policy.go | 4 +- .../internal/modules/morph/policy/root.go | 47 +++++++++++++++++++ .../internal/modules/morph/root.go | 40 ++-------------- 4 files changed, 55 insertions(+), 41 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => policy}/policy.go (97%) create mode 100644 cmd/frostfs-adm/internal/modules/morph/policy/root.go diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_test.go b/cmd/frostfs-adm/internal/modules/morph/initialize_test.go index 63e9887c0..e9571e50c 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_test.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring" "github.com/nspcc-dev/neo-go/pkg/config" @@ -78,8 +79,8 @@ func testInitialize(t *testing.T, committeeSize int) { require.NoError(t, setConfigCmd(setConfig, []string{"MaintenanceModeAllowed=true"})) }) t.Run("set-policy", func(t *testing.T) { - require.NoError(t, setPolicy.Flags().Set(util.LocalDumpFlag, dumpPath)) - require.NoError(t, setPolicyCmd(setPolicy, []string{"ExecFeeFactor=1"})) + require.NoError(t, policy.Set.Flags().Set(util.LocalDumpFlag, dumpPath)) + require.NoError(t, policy.SetPolicyCmd(policy.Set, []string{"ExecFeeFactor=1"})) }) t.Run("remove-node", func(t *testing.T) { pk, err := keys.NewPrivateKey() diff --git a/cmd/frostfs-adm/internal/modules/morph/policy.go b/cmd/frostfs-adm/internal/modules/morph/policy/policy.go similarity index 97% rename from cmd/frostfs-adm/internal/modules/morph/policy.go rename to cmd/frostfs-adm/internal/modules/morph/policy/policy.go index d01c5e1a5..7f4a8d326 100644 --- a/cmd/frostfs-adm/internal/modules/morph/policy.go +++ b/cmd/frostfs-adm/internal/modules/morph/policy/policy.go @@ -1,4 +1,4 @@ -package morph +package policy import ( "bytes" @@ -24,7 +24,7 @@ const ( setFeeParam = "FeePerByte" ) -func setPolicyCmd(cmd *cobra.Command, args []string) error { +func SetPolicyCmd(cmd *cobra.Command, args []string) error { wCtx, err := util.NewInitializeContext(cmd, viper.GetViper()) if err != nil { return fmt.Errorf("can't to initialize context: %w", err) diff --git a/cmd/frostfs-adm/internal/modules/morph/policy/root.go b/cmd/frostfs-adm/internal/modules/morph/policy/root.go new file mode 100644 index 000000000..99ff56ee8 --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/policy/root.go @@ -0,0 +1,47 @@ +package policy + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var ( + Set = &cobra.Command{ + Use: "set-policy [ExecFeeFactor=] [StoragePrice=] [FeePerByte=]", + DisableFlagsInUseLine: true, + Short: "Set global policy values", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: SetPolicyCmd, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"ExecFeeFactor=", "StoragePrice=", "FeePerByte="}, cobra.ShellCompDirectiveNoSpace + }, + } + + Dump = &cobra.Command{ + Use: "dump-policy", + Short: "Dump FrostFS policy", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: dumpPolicyCmd, + } +) + +func initSetPolicyCmd() { + Set.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) + Set.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + Set.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file") +} + +func initDumpPolicyCmd() { + Dump.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) +} + +func init() { + initSetPolicyCmd() + initDumpPolicyCmd() +} diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index 7585f5845..b53a64486 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -2,6 +2,7 @@ package morph import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/ape" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -130,29 +131,6 @@ var ( RunE: setConfigCmd, } - setPolicy = &cobra.Command{ - Use: "set-policy [ExecFeeFactor=] [StoragePrice=] [FeePerByte=]", - DisableFlagsInUseLine: true, - Short: "Set global policy values", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: setPolicyCmd, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"ExecFeeFactor=", "StoragePrice=", "FeePerByte="}, cobra.ShellCompDirectiveNoSpace - }, - } - - dumpPolicy = &cobra.Command{ - Use: "dump-policy", - Short: "Dump FrostFS policy", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: dumpPolicyCmd, - } - dumpContractHashesCmd = &cobra.Command{ Use: "dump-hashes", Short: "Dump deployed contract hashes", @@ -265,8 +243,8 @@ func init() { initGenerateStorageCmd() initForceNewEpochCmd() initRemoveNodesCmd() - initSetPolicyCmd() - initDumpPolicyCmd() + RootCmd.AddCommand(policy.Set) + RootCmd.AddCommand(policy.Dump) initDumpContractHashesCmd() initDumpNetworkConfigCmd() initSetConfigCmd() @@ -393,18 +371,6 @@ func initDumpContractHashesCmd() { dumpContractHashesCmd.Flags().String(customZoneFlag, "", "Custom zone to search.") } -func initSetPolicyCmd() { - RootCmd.AddCommand(setPolicy) - setPolicy.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) - setPolicy.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - setPolicy.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file") -} - -func initDumpPolicyCmd() { - RootCmd.AddCommand(dumpPolicy) - dumpPolicy.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) -} - func initRemoveNodesCmd() { RootCmd.AddCommand(removeNodes) removeNodes.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)