From b1bd66e0899e0a2c728337e31bc73aabb9f17d9e Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Thu, 19 Dec 2019 08:15:49 +0000 Subject: [PATCH] go/oasis-node: Remove the `debug dummy` sub-commands These are only useful for testing, and our test harness has a internal Go API that removes the need to have this functionality exposed as a subcommand. --- go/oasis-node/cmd/debug/debug.go | 2 - go/oasis-node/cmd/debug/dummy/dummy.go | 102 ------------------------- 2 files changed, 104 deletions(-) delete mode 100644 go/oasis-node/cmd/debug/dummy/dummy.go diff --git a/go/oasis-node/cmd/debug/debug.go b/go/oasis-node/cmd/debug/debug.go index 27e76e06ecd..da459f06ac7 100644 --- a/go/oasis-node/cmd/debug/debug.go +++ b/go/oasis-node/cmd/debug/debug.go @@ -5,7 +5,6 @@ import ( "github.com/spf13/cobra" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/debug/byzantine" - "github.com/oasislabs/oasis-core/go/oasis-node/cmd/debug/dummy" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/debug/storage" "github.com/oasislabs/oasis-core/go/oasis-node/cmd/debug/tendermint" ) @@ -17,7 +16,6 @@ var debugCmd = &cobra.Command{ // Register registers the debug sub-command and all of it's children. func Register(parentCmd *cobra.Command) { - dummy.Register(debugCmd) storage.Register(debugCmd) tendermint.Register(debugCmd) byzantine.Register(debugCmd) diff --git a/go/oasis-node/cmd/debug/dummy/dummy.go b/go/oasis-node/cmd/debug/dummy/dummy.go deleted file mode 100644 index c245de38259..00000000000 --- a/go/oasis-node/cmd/debug/dummy/dummy.go +++ /dev/null @@ -1,102 +0,0 @@ -// Package dummy implements the dummy debug sub-commands. -package dummy - -import ( - "context" - "os" - - "github.com/spf13/cobra" - "google.golang.org/grpc" - - "github.com/oasislabs/oasis-core/go/common/logging" - control "github.com/oasislabs/oasis-core/go/control/api" - epochtime "github.com/oasislabs/oasis-core/go/epochtime/api" - cmdCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common" - cmdGrpc "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/grpc" -) - -var ( - epoch uint64 - nodes int - - dummyCmd = &cobra.Command{ - Use: "dummy", - Short: "control dummy node during tests", - } - - dummySetEpochCmd = &cobra.Command{ - Use: "set-epoch", - Short: "set mock epochtime", - Run: doSetEpoch, - } - - dummyWaitNodesCmd = &cobra.Command{ - Use: "wait-nodes", - Short: "wait for specific number of nodes to register", - Run: doWaitNodes, - } - - logger = logging.GetLogger("cmd/dummy") -) - -func doConnect(cmd *cobra.Command) (*grpc.ClientConn, control.DebugController) { - if err := cmdCommon.Init(); err != nil { - cmdCommon.EarlyLogAndExit(err) - } - - conn, err := cmdGrpc.NewClient(cmd) - if err != nil { - logger.Error("failed to establish connection with node", - "err", err, - ) - os.Exit(1) - } - - client := control.NewDebugControllerClient(conn) - - return conn, client -} - -func doSetEpoch(cmd *cobra.Command, args []string) { - conn, client := doConnect(cmd) - defer conn.Close() - - logger.Info("setting epoch", - "epoch", epoch, - ) - - if err := client.SetEpoch(context.Background(), epochtime.EpochTime(epoch)); err != nil { - logger.Error("failed to set epoch", - "err", err, - ) - } -} - -func doWaitNodes(cmd *cobra.Command, args []string) { - conn, client := doConnect(cmd) - defer conn.Close() - - logger.Info("waiting for nodes", - "nodes", nodes, - ) - - if err := client.WaitNodesRegistered(context.Background(), nodes); err != nil { - logger.Error("failed to wait for nodes", - "err", err, - ) - os.Exit(1) - } - - logger.Info("enough nodes have been registered") -} - -// Register registers the dummy sub-command and all of its children. -func Register(parentCmd *cobra.Command) { - dummyCmd.PersistentFlags().AddFlagSet(cmdGrpc.ClientFlags) - dummySetEpochCmd.Flags().Uint64VarP(&epoch, "epoch", "e", 0, "set epoch to given value") - dummyWaitNodesCmd.Flags().IntVarP(&nodes, "nodes", "n", 1, "number of nodes to wait for") - - dummyCmd.AddCommand(dummySetEpochCmd) - dummyCmd.AddCommand(dummyWaitNodesCmd) - parentCmd.AddCommand(dummyCmd) -}