From ad8b261a32d8c467ba15d465cd0c27c40bd3af9d Mon Sep 17 00:00:00 2001 From: Utkarsh Bhatt Date: Fri, 8 Nov 2024 22:25:58 +0530 Subject: [PATCH] Make remote replication CLI conformant to CLI guidelines (#456) # Description Modify `remote replication` CLI to `replication` CLI. ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [X] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] CleanCode (Code refactor, test updates, does not introduce functional changes) - [ ] Documentation update (Doc only change) ## How Has This Been Tested? Using CI ## Contributor's Checklist Please check that you have: - [x] self-reviewed the code in this PR. - [ ] added code comments, particularly in hard-to-understand areas. - [x] updated the user documentation with corresponding changes. - [ ] modified tests to verify effectiveness of this change. --------- Signed-off-by: utkarsh bhatt --- .github/workflows/tests.yml | 2 +- docs/how-to/configure-rbd-mirroring.rst | 24 ++++---- docs/how-to/import-remote-cluster.rst | 2 +- docs/how-to/index.rst | 2 +- docs/how-to/perform-site-failover.rst | 14 ++--- ...eplication-rbd.rst => replication-rbd.rst} | 28 ++++----- .../{remote_replication.go => replication.go} | 2 +- microceph/cmd/microceph/main.go | 4 ++ microceph/cmd/microceph/remote.go | 3 - microceph/cmd/microceph/remote_replication.go | 22 ------- .../cmd/microceph/remote_replication_rbd.go | 46 -------------- microceph/cmd/microceph/replication.go | 46 ++++++++++++++ ..._configure.go => replication_configure.go} | 30 +++++++--- ...on_rbd_demote.go => replication_demote.go} | 12 ++-- ..._rbd_disable.go => replication_disable.go} | 30 +++++++--- ...on_rbd_enable.go => replication_enable.go} | 29 ++++++--- ...cation_rbd_list.go => replication_list.go} | 34 ++++++++--- ..._rbd_promote.go => replication_promote.go} | 12 ++-- ...on_rbd_status.go => replication_status.go} | 31 +++++++--- tests/scripts/actionutils.sh | 60 +++++++++---------- 20 files changed, 247 insertions(+), 186 deletions(-) rename docs/reference/commands/{remote-replication-rbd.rst => replication-rbd.rst} (68%) rename microceph/client/{remote_replication.go => replication.go} (90%) delete mode 100644 microceph/cmd/microceph/remote_replication.go delete mode 100644 microceph/cmd/microceph/remote_replication_rbd.go create mode 100644 microceph/cmd/microceph/replication.go rename microceph/cmd/microceph/{remote_replication_rbd_configure.go => replication_configure.go} (57%) rename microceph/cmd/microceph/{remote_replication_rbd_demote.go => replication_demote.go} (70%) rename microceph/cmd/microceph/{remote_replication_rbd_disable.go => replication_disable.go} (57%) rename microceph/cmd/microceph/{remote_replication_rbd_enable.go => replication_enable.go} (68%) rename microceph/cmd/microceph/{remote_replication_rbd_list.go => replication_list.go} (69%) rename microceph/cmd/microceph/{remote_replication_rbd_promote.go => replication_promote.go} (70%) rename microceph/cmd/microceph/{remote_replication_rbd_status.go => replication_status.go} (84%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8a90eedc..a85feabd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -713,7 +713,7 @@ jobs: run : ~/actionutils.sh remote_configure_rbd_mirroring - name: Wait for RBD mirror to sync images - run : ~/actionutils.sh remote_wait_for_secondary_to_sync + run : ~/actionutils.sh remote_wait_for_secondary_to_sync 4 - name: Verify RBD mirror run : ~/actionutils.sh remote_verify_rbd_mirroring diff --git a/docs/how-to/configure-rbd-mirroring.rst b/docs/how-to/configure-rbd-mirroring.rst index 1629d904..2f9ef7fd 100644 --- a/docs/how-to/configure-rbd-mirroring.rst +++ b/docs/how-to/configure-rbd-mirroring.rst @@ -1,5 +1,5 @@ ================================== -Configure RBD remote replication +Configure RBD replication ================================== MicroCeph supports asynchronously replicating (mirroring) RBD images to a remote cluster. @@ -13,25 +13,25 @@ Prerequisites 3. Both clusters have 2 rbd pools: pool_one and pool_two. 4. Both pools at cluster "primary_cluster" have 2 images each (image_one and image_two) while the pools at cluster "secondary_cluster" are empty. -Enable RBD remote replication +Enable RBD replication ------------------------------- An operator can enable replication for a given rbd pool which is present at both clusters as .. code-block:: none - sudo microceph remote replication rbd enable pool_one --remote secondary_cluster + sudo microceph replication enable rbd pool_one --remote secondary_cluster Here, pool_one is the name of the rbd pool and it is expected to be present at both the clusters. -Check RBD remote replication status +Check RBD replication status ------------------------------------ The above command will enable replication for ALL the images inside pool_one, it can be checked as: .. code-block:: none - sudo microceph remote replication rbd status pool_one + sudo microceph replication status rbd pool_one +------------------------+----------------------+ | SUMMARY | HEALTH | +-------------+----------+-------------+--------+ @@ -48,14 +48,14 @@ The above command will enable replication for ALL the images inside pool_one, it The status shows that there are 2 images in the pool which are enabled for mirroring. -Listing all RBD remote replication images +Listing all RBD replication images ------------------------------------------ An operator can list all the images that have replication (mirroring) enabled as follows: .. code-block:: none - sudo microceph remote replication rbd list + sudo microceph replication list rbd +-----------+------------+------------+---------------------+ | POOL NAME | IMAGE NAME | IS PRIMARY | LAST LOCAL UPDATE | +-----------+------------+------------+---------------------+ @@ -65,7 +65,7 @@ An operator can list all the images that have replication (mirroring) enabled as | pool_two | image_two | true | 2024-10-08 13:55:07 | +-----------+------------+------------+---------------------+ -Disabling RBD remote replication +Disabling RBD replication --------------------------------- In some cases, it may be desired to disable replication. A single image ($pool/$image) or @@ -74,8 +74,8 @@ a whole pool ($pool) can be disabled in a single command as follows: Disable Pool replication: .. code-block:: none - sudo microceph remote replication disable pool_one - sudo microceph remote replication list + sudo microceph replication disable rbd pool_one + sudo microceph replication list rbd +-----------+------------+------------+---------------------+ | POOL NAME | IMAGE NAME | IS PRIMARY | LAST LOCAL UPDATE | +-----------+------------+------------+---------------------+ @@ -86,8 +86,8 @@ Disable Pool replication: Disable Image replication: .. code-block:: none - sudo microceph remote replication disable pool_two/image_two - sudo microceph remote replication list + sudo microceph replication disable rbd pool_two/image_two + sudo microceph replication list rbd +-----------+------------+------------+---------------------+ | POOL NAME | IMAGE NAME | IS PRIMARY | LAST LOCAL UPDATE | +-----------+------------+------------+---------------------+ diff --git a/docs/how-to/import-remote-cluster.rst b/docs/how-to/import-remote-cluster.rst index 50fa87e1..edeecff0 100644 --- a/docs/how-to/import-remote-cluster.rst +++ b/docs/how-to/import-remote-cluster.rst @@ -6,7 +6,7 @@ MicroCeph supports adding secondary MicroCeph clusters as remote clusters. This creates ``$remote.conf/$remote.keyring`` files in the snap's config directory allowing users (and microceph) to perform ceph operations on the remote clusters. -This also enables capabilities like remote replication by exposing required +This also enables capabilities like replication to remote clusters by exposing required remote cluster details to MicroCeph and Ceph. Working with remote MicroCeph clusters diff --git a/docs/how-to/index.rst b/docs/how-to/index.rst index bdbb10b0..054b650a 100644 --- a/docs/how-to/index.rst +++ b/docs/how-to/index.rst @@ -47,7 +47,7 @@ migrate services and more. Managing a remote cluster ------------------------- -Make MicroCeph aware of a remote cluster and configure remote replication for +Make MicroCeph aware of a remote cluster and configure replication for RBD pools and images. .. toctree:: diff --git a/docs/how-to/perform-site-failover.rst b/docs/how-to/perform-site-failover.rst index a3995932..282b3352 100644 --- a/docs/how-to/perform-site-failover.rst +++ b/docs/how-to/perform-site-failover.rst @@ -11,7 +11,7 @@ Prerequisites -------------- 1. A primary and a secondary MicroCeph cluster, for example named "primary_cluster" and "secondary_cluster" 2. primary_cluster has imported configurations from secondary_cluster and vice versa. refer to :doc:`import remote <./import-remote-cluster>` -3. RBD remote replication is configured for at least 1 rbd image. refer to :doc:`configure rbd replication <./configure-rbd-mirroring>` +3. RBD replication is configured for at least 1 rbd image. refer to :doc:`configure rbd replication <./configure-rbd-mirroring>` Failover to a non-primary remote cluster ----------------------------------------- @@ -19,7 +19,7 @@ List all the resources on 'secondary_cluster' to check primary status. .. code-block:: none - sudo microceph remote replication rbd list + sudo microceph replication list rbd +-----------+------------+------------+---------------------+ | POOL NAME | IMAGE NAME | IS PRIMARY | LAST LOCAL UPDATE | +-----------+------------+------------+---------------------+ @@ -31,20 +31,20 @@ An operator can perform cluster wide promotion as follows: .. code-block:: none - sudo microceph remote replication rbd promote --remote primary_cluster --yes-i-really-mean-it + sudo microceph replication promote --remote primary_cluster --yes-i-really-mean-it Here, parameter helps microceph filter the resources to promote. Since promotion of secondary_cluster may cause a split-brain condition in future, it is necessary to pass --yes-i-really-mean-it flag. -Verify RBD remote replication primary status +Verify RBD replication primary status --------------------------------------------- List all the resources on 'secondary_cluster' again to check primary status. .. code-block:: none - sudo microceph remote replication rbd status pool_one + sudo microceph replication status rbd pool_one +-----------+------------+------------+---------------------+ | POOL NAME | IMAGE NAME | IS PRIMARY | LAST LOCAL UPDATE | +-----------+------------+------------+---------------------+ @@ -68,14 +68,14 @@ Note: Demotion can cause data loss and hence can only be performed with the 'yes At primary_cluster (was primary before disaster), perform demotion. .. code-block:: none - sudo microceph remote replication rbd demote --remote secondary_cluster + sudo microceph replication demote --remote secondary_cluster failed to process demote_replication request for rbd: demotion may cause data loss on this cluster. If you understand the *RISK* and you're *ABSOLUTELY CERTAIN* that is what you want, pass --yes-i-really-mean-it. Now, again at the 'primary_cluster', perform demotion with --yes-i-really-mean-it flag. .. code-block:: none - sudo microceph remote replication rbd demote --remote secondary_cluster --yes-i-really-mean-it + sudo microceph replication demote --remote secondary_cluster --yes-i-really-mean-it Note: MicroCeph with demote the primary pools and will issue a resync for all the mirroring images, hence it may cause data loss at the old primary cluster. diff --git a/docs/reference/commands/remote-replication-rbd.rst b/docs/reference/commands/replication-rbd.rst similarity index 68% rename from docs/reference/commands/remote-replication-rbd.rst rename to docs/reference/commands/replication-rbd.rst index 2915d913..53801428 100644 --- a/docs/reference/commands/remote-replication-rbd.rst +++ b/docs/reference/commands/replication-rbd.rst @@ -1,21 +1,21 @@ ============================= -``remote replication rbd`` +``replication`` ============================= Usage: .. code-block:: none - microceph remote replication rbd [command] + microceph replication [command] Available commands: .. code-block:: none - configure Configure remote replication parameters for RBD resource (Pool or Image) - disable Disable remote replication for RBD resource (Pool or Image) - enable Enable remote replication for RBD resource (Pool or Image) - list List all configured remotes replication pairs. + configure Configure replication parameters for RBD resource (Pool or Image) + disable Disable replication for RBD resource (Pool or Image) + enable Enable replication for RBD resource (Pool or Image) + list List all configured replications. status Show RBD resource (Pool or Image) replication status Global options: @@ -31,13 +31,13 @@ Global options: ``enable`` ---------- -Enable remote replication for RBD resource (Pool or Image) +Enable replication for RBD resource (Pool or Image) Usage: .. code-block:: none - microceph remote replication rbd enable [flags] + microceph replication enable rbd [flags] Flags: @@ -57,7 +57,7 @@ Usage: .. code-block:: none - microceph remote replication rbd status [flags] + microceph replication status rbd [flags] Flags: @@ -74,7 +74,7 @@ Usage: .. code-block:: none - microceph remote replication rbd list [flags] + microceph replication list rbd [flags] .. code-block:: none @@ -84,13 +84,13 @@ Usage: ``disable`` ------------ -Disable remote replication for RBD resource (Pool or Image) +Disable replication for RBD resource (Pool or Image) Usage: .. code-block:: none - microceph remote replication rbd disable [flags] + microceph replication disable rbd [flags] .. code-block:: none @@ -103,7 +103,7 @@ Promote local cluster to primary .. code-block:: none - microceph remote replication rbd promote [flags] + microceph replication promote [flags] .. code-block:: none @@ -119,7 +119,7 @@ Usage: .. code-block:: none - microceph remote replication rbd demote [flags] + microceph replication demote [flags] .. code-block:: none diff --git a/microceph/client/remote_replication.go b/microceph/client/replication.go similarity index 90% rename from microceph/client/remote_replication.go rename to microceph/client/replication.go index 80929849..4f3b0519 100644 --- a/microceph/client/remote_replication.go +++ b/microceph/client/replication.go @@ -11,7 +11,7 @@ import ( ) // Sends replication request for creating, deleting, getting, and listing remote replication. -func SendRemoteReplicationRequest(ctx context.Context, c *microCli.Client, data types.ReplicationRequest) (string, error) { +func SendReplicationRequest(ctx context.Context, c *microCli.Client, data types.ReplicationRequest) (string, error) { var err error var resp string queryCtx, cancel := context.WithTimeout(ctx, time.Second*120) diff --git a/microceph/cmd/microceph/main.go b/microceph/cmd/microceph/main.go index 8c7f6f2f..f622d1b7 100644 --- a/microceph/cmd/microceph/main.go +++ b/microceph/cmd/microceph/main.go @@ -64,6 +64,10 @@ func main() { var cmdRemote = cmdRemote{common: &commonCmd} app.AddCommand(cmdRemote.Command()) + // Replication command + var cmdReplication = cmdReplication{common: &commonCmd} + app.AddCommand(cmdReplication.Command()) + var cmdDisk = cmdDisk{common: &commonCmd} app.AddCommand(cmdDisk.Command()) diff --git a/microceph/cmd/microceph/remote.go b/microceph/cmd/microceph/remote.go index b634d1d1..5c8c1ab1 100644 --- a/microceph/cmd/microceph/remote.go +++ b/microceph/cmd/microceph/remote.go @@ -23,9 +23,6 @@ func (c *cmdRemote) Command() *cobra.Command { // Remove subcommand remoteRemoveCmd := cmdRemoteRemove{common: c.common} cmd.AddCommand(remoteRemoveCmd.Command()) - // Replication subcommand - remoteReplicationCmd := cmdRemoteReplication{common: c.common} - cmd.AddCommand(remoteReplicationCmd.Command()) // Workaround for subcommand usage errors. See: https://github.com/spf13/cobra/issues/706 cmd.Args = cobra.NoArgs diff --git a/microceph/cmd/microceph/remote_replication.go b/microceph/cmd/microceph/remote_replication.go deleted file mode 100644 index 0b9c3ab7..00000000 --- a/microceph/cmd/microceph/remote_replication.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "github.com/spf13/cobra" -) - -type cmdRemoteReplication struct { - common *CmdControl -} - -func (c *cmdRemoteReplication) Command() *cobra.Command { - cmd := &cobra.Command{ - Use: "replication", - Short: "manage remote replication", - } - - // Replication RBD commands - replicationRbdCmd := cmdRemoteReplicationRbd{common: c.common} - cmd.AddCommand(replicationRbdCmd.Command()) - - return cmd -} diff --git a/microceph/cmd/microceph/remote_replication_rbd.go b/microceph/cmd/microceph/remote_replication_rbd.go deleted file mode 100644 index cadfe3c4..00000000 --- a/microceph/cmd/microceph/remote_replication_rbd.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "github.com/spf13/cobra" -) - -type cmdRemoteReplicationRbd struct { - common *CmdControl -} - -func (c *cmdRemoteReplicationRbd) Command() *cobra.Command { - cmd := &cobra.Command{ - Use: "rbd", - Short: "manage RBD remote replication", - } - - // Replication enable command - remoteReplicationRbdEnableCmd := cmdRemoteReplicationEnableRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdEnableCmd.Command()) - - // Replication disable command - remoteReplicationRbdDisableCmd := cmdRemoteReplicationDisableRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdDisableCmd.Command()) - - // Replication list command - remoteReplicationRbdListCmd := cmdRemoteReplicationListRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdListCmd.Command()) - - // Replication status command - remoteReplicationRbdStatusCmd := cmdRemoteReplicationStatusRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdStatusCmd.Command()) - - // Replication configure command - remoteReplicationRbdConfigureCmd := cmdRemoteReplicationConfigureRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdConfigureCmd.Command()) - - // Replication promote command - remoteReplicationRbdPromoteCmd := cmdRemoteReplicationPromoteRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdPromoteCmd.Command()) - - // Replication demote command - remoteReplicationRbdDemoteCmd := cmdRemoteReplicationDemoteRbd{common: c.common} - cmd.AddCommand(remoteReplicationRbdDemoteCmd.Command()) - - return cmd -} diff --git a/microceph/cmd/microceph/replication.go b/microceph/cmd/microceph/replication.go new file mode 100644 index 00000000..b4cd2133 --- /dev/null +++ b/microceph/cmd/microceph/replication.go @@ -0,0 +1,46 @@ +package main + +import ( + "github.com/spf13/cobra" +) + +type cmdReplication struct { + common *CmdControl +} + +func (c *cmdReplication) Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "replication", + Short: "manage replication to remote clusters", + } + + // Replication enable command + replicationEnableCmd := cmdReplicationEnable{common: c.common} + cmd.AddCommand(replicationEnableCmd.Command()) + + // Replication disable command + replicationDisableCmd := cmdReplicationDisable{common: c.common} + cmd.AddCommand(replicationDisableCmd.Command()) + + // Replication list command + replicationListCmd := cmdReplicationList{common: c.common} + cmd.AddCommand(replicationListCmd.Command()) + + // Replication status command + replicationStatusCmd := cmdReplicationStatus{common: c.common} + cmd.AddCommand(replicationStatusCmd.Command()) + + // Replication configure command + replicationConfigureCmd := cmdReplicationConfigure{common: c.common} + cmd.AddCommand(replicationConfigureCmd.Command()) + + // Replication promote command + replicationPromoteCmd := cmdReplicationPromote{common: c.common} + cmd.AddCommand(replicationPromoteCmd.Command()) + + // Replication demote command + replicationDemoteCmd := cmdReplicationDemote{common: c.common} + cmd.AddCommand(replicationDemoteCmd.Command()) + + return cmd +} diff --git a/microceph/cmd/microceph/remote_replication_rbd_configure.go b/microceph/cmd/microceph/replication_configure.go similarity index 57% rename from microceph/cmd/microceph/remote_replication_rbd_configure.go rename to microceph/cmd/microceph/replication_configure.go index c3b1bb70..6dc99580 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_configure.go +++ b/microceph/cmd/microceph/replication_configure.go @@ -9,15 +9,31 @@ import ( "github.com/spf13/cobra" ) -type cmdRemoteReplicationConfigureRbd struct { +type cmdReplicationConfigure struct { + common *CmdControl +} + +func (c *cmdReplicationConfigure) Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "configure", + Short: "configure replication parameters", + } + + configureRbdCmd := cmdReplicationConfigureRbd{common: c.common} + cmd.AddCommand(configureRbdCmd.Command()) + + return cmd +} + +type cmdReplicationConfigureRbd struct { common *CmdControl schedule string } -func (c *cmdRemoteReplicationConfigureRbd) Command() *cobra.Command { +func (c *cmdReplicationConfigureRbd) Command() *cobra.Command { cmd := &cobra.Command{ - Use: "configure ", - Short: "Configure remote replication parameters for RBD resource (Pool or Image)", + Use: "rbd ", + Short: "Configure replication parameters for RBD resource (Pool or Image)", RunE: c.Run, } @@ -25,7 +41,7 @@ func (c *cmdRemoteReplicationConfigureRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationConfigureRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationConfigureRbd) Run(cmd *cobra.Command, args []string) error { if len(args) != 1 { return cmd.Help() } @@ -45,7 +61,7 @@ func (c *cmdRemoteReplicationConfigureRbd) Run(cmd *cobra.Command, args []string return err } - _, err = client.SendRemoteReplicationRequest(context.Background(), cli, payload) + _, err = client.SendReplicationRequest(context.Background(), cli, payload) if err != nil { return err } @@ -53,7 +69,7 @@ func (c *cmdRemoteReplicationConfigureRbd) Run(cmd *cobra.Command, args []string return nil } -func (c *cmdRemoteReplicationConfigureRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationConfigureRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { pool, image, err := types.GetPoolAndImageFromResource(args[0]) if err != nil { return types.RbdReplicationRequest{}, err diff --git a/microceph/cmd/microceph/remote_replication_rbd_demote.go b/microceph/cmd/microceph/replication_demote.go similarity index 70% rename from microceph/cmd/microceph/remote_replication_rbd_demote.go rename to microceph/cmd/microceph/replication_demote.go index 8be123b5..9727977d 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_demote.go +++ b/microceph/cmd/microceph/replication_demote.go @@ -9,13 +9,13 @@ import ( "github.com/spf13/cobra" ) -type cmdRemoteReplicationDemoteRbd struct { +type cmdReplicationDemote struct { common *CmdControl remoteName string isForce bool } -func (c *cmdRemoteReplicationDemoteRbd) Command() *cobra.Command { +func (c *cmdReplicationDemote) Command() *cobra.Command { cmd := &cobra.Command{ Use: "demote", Short: "Demote a primary cluster to non-primary status", @@ -28,7 +28,7 @@ func (c *cmdRemoteReplicationDemoteRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationDemoteRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationDemote) Run(cmd *cobra.Command, args []string) error { if len(args) != 0 { return cmd.Help() } @@ -43,12 +43,12 @@ func (c *cmdRemoteReplicationDemoteRbd) Run(cmd *cobra.Command, args []string) e return err } - payload, err := c.prepareRbdPayload(types.DemoteReplicationRequest) + payload, err := c.preparePayload(types.DemoteReplicationRequest) if err != nil { return err } - _, err = client.SendRemoteReplicationRequest(context.Background(), cli, payload) + _, err = client.SendReplicationRequest(context.Background(), cli, payload) if err != nil { return err } @@ -56,7 +56,7 @@ func (c *cmdRemoteReplicationDemoteRbd) Run(cmd *cobra.Command, args []string) e return nil } -func (c *cmdRemoteReplicationDemoteRbd) prepareRbdPayload(requestType types.ReplicationRequestType) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationDemote) preparePayload(requestType types.ReplicationRequestType) (types.RbdReplicationRequest, error) { retReq := types.RbdReplicationRequest{ RemoteName: c.remoteName, RequestType: requestType, diff --git a/microceph/cmd/microceph/remote_replication_rbd_disable.go b/microceph/cmd/microceph/replication_disable.go similarity index 57% rename from microceph/cmd/microceph/remote_replication_rbd_disable.go rename to microceph/cmd/microceph/replication_disable.go index 89c56f7a..13bbc97c 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_disable.go +++ b/microceph/cmd/microceph/replication_disable.go @@ -9,15 +9,31 @@ import ( "github.com/spf13/cobra" ) -type cmdRemoteReplicationDisableRbd struct { +type cmdReplicationDisable struct { + common *CmdControl +} + +func (c *cmdReplicationDisable) Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "disable", + Short: "Disable replication", + } + + disableRbdCmd := cmdReplicationDisableRbd{common: c.common} + cmd.AddCommand(disableRbdCmd.Command()) + + return cmd +} + +type cmdReplicationDisableRbd struct { common *CmdControl isForce bool } -func (c *cmdRemoteReplicationDisableRbd) Command() *cobra.Command { +func (c *cmdReplicationDisableRbd) Command() *cobra.Command { cmd := &cobra.Command{ - Use: "disable ", - Short: "Disable remote replication for RBD resource (Pool or Image)", + Use: "rbd ", + Short: "Disable replication for RBD resource (Pool or Image)", RunE: c.Run, } @@ -25,7 +41,7 @@ func (c *cmdRemoteReplicationDisableRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationDisableRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationDisableRbd) Run(cmd *cobra.Command, args []string) error { if len(args) != 1 { return cmd.Help() } @@ -45,11 +61,11 @@ func (c *cmdRemoteReplicationDisableRbd) Run(cmd *cobra.Command, args []string) return err } - _, err = client.SendRemoteReplicationRequest(context.Background(), cli, payload) + _, err = client.SendReplicationRequest(context.Background(), cli, payload) return err } -func (c *cmdRemoteReplicationDisableRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationDisableRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { pool, image, err := types.GetPoolAndImageFromResource(args[0]) if err != nil { return types.RbdReplicationRequest{}, err diff --git a/microceph/cmd/microceph/remote_replication_rbd_enable.go b/microceph/cmd/microceph/replication_enable.go similarity index 68% rename from microceph/cmd/microceph/remote_replication_rbd_enable.go rename to microceph/cmd/microceph/replication_enable.go index e6fae002..2d96913d 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_enable.go +++ b/microceph/cmd/microceph/replication_enable.go @@ -9,7 +9,22 @@ import ( "github.com/spf13/cobra" ) -type cmdRemoteReplicationEnableRbd struct { +type cmdReplicationEnable struct { + common *CmdControl +} + +func (c *cmdReplicationEnable) Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "enable", + Short: "Enable replication", + } + + enableRbdCmd := cmdReplicationEnableRbd{common: c.common} + cmd.AddCommand(enableRbdCmd.Command()) + return cmd +} + +type cmdReplicationEnableRbd struct { common *CmdControl remoteName string repType string @@ -17,10 +32,10 @@ type cmdRemoteReplicationEnableRbd struct { skipAutoEnable bool } -func (c *cmdRemoteReplicationEnableRbd) Command() *cobra.Command { +func (c *cmdReplicationEnableRbd) Command() *cobra.Command { cmd := &cobra.Command{ - Use: "enable ", - Short: "Enable remote replication for RBD resource (Pool or Image)", + Use: "rbd ", + Short: "Enable replication for RBD resource (Pool or Image)", RunE: c.Run, } @@ -32,7 +47,7 @@ func (c *cmdRemoteReplicationEnableRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationEnableRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationEnableRbd) Run(cmd *cobra.Command, args []string) error { if len(args) != 1 { return cmd.Help() } @@ -52,7 +67,7 @@ func (c *cmdRemoteReplicationEnableRbd) Run(cmd *cobra.Command, args []string) e return err } - _, err = client.SendRemoteReplicationRequest(context.Background(), cli, payload) + _, err = client.SendReplicationRequest(context.Background(), cli, payload) if err != nil { return err } @@ -60,7 +75,7 @@ func (c *cmdRemoteReplicationEnableRbd) Run(cmd *cobra.Command, args []string) e return nil } -func (c *cmdRemoteReplicationEnableRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationEnableRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { pool, image, err := types.GetPoolAndImageFromResource(args[0]) if err != nil { return types.RbdReplicationRequest{}, err diff --git a/microceph/cmd/microceph/remote_replication_rbd_list.go b/microceph/cmd/microceph/replication_list.go similarity index 69% rename from microceph/cmd/microceph/remote_replication_rbd_list.go rename to microceph/cmd/microceph/replication_list.go index 6b7f5d8f..dfbfbef9 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_list.go +++ b/microceph/cmd/microceph/replication_list.go @@ -15,16 +15,34 @@ import ( "golang.org/x/crypto/ssh/terminal" ) -type cmdRemoteReplicationListRbd struct { +type cmdReplicationList struct { common *CmdControl poolName string json bool } -func (c *cmdRemoteReplicationListRbd) Command() *cobra.Command { +func (c *cmdReplicationList) Command() *cobra.Command { cmd := &cobra.Command{ Use: "list", - Short: "List all configured remotes replication pairs.", + Short: "List all resources configured for replication.", + } + + listRbdCmd := cmdReplicationListRbd{common: c.common} + cmd.AddCommand(listRbdCmd.Command()) + + return cmd +} + +type cmdReplicationListRbd struct { + common *CmdControl + poolName string + json bool +} + +func (c *cmdReplicationListRbd) Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "rbd", + Short: "List all rbd resources configured for replication.", RunE: c.Run, } @@ -33,7 +51,7 @@ func (c *cmdRemoteReplicationListRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationListRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationListRbd) Run(cmd *cobra.Command, args []string) error { if len(args) != 0 { return cmd.Help() } @@ -53,7 +71,7 @@ func (c *cmdRemoteReplicationListRbd) Run(cmd *cobra.Command, args []string) err return err } - resp, err := client.SendRemoteReplicationRequest(context.Background(), cli, payload) + resp, err := client.SendReplicationRequest(context.Background(), cli, payload) if err != nil { return err } @@ -63,10 +81,10 @@ func (c *cmdRemoteReplicationListRbd) Run(cmd *cobra.Command, args []string) err return nil } - return printRemoteReplicationList(resp) + return printReplicationList(resp) } -func (c *cmdRemoteReplicationListRbd) prepareRbdPayload(requestType types.ReplicationRequestType) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationListRbd) prepareRbdPayload(requestType types.ReplicationRequestType) (types.RbdReplicationRequest, error) { // list fetches ALL POOLS if pool name is empty. retReq := types.RbdReplicationRequest{ SourcePool: c.poolName, @@ -77,7 +95,7 @@ func (c *cmdRemoteReplicationListRbd) prepareRbdPayload(requestType types.Replic return retReq, nil } -func printRemoteReplicationList(response string) error { +func printReplicationList(response string) error { var resp types.RbdPoolList err := json.Unmarshal([]byte(response), &resp) if err != nil { diff --git a/microceph/cmd/microceph/remote_replication_rbd_promote.go b/microceph/cmd/microceph/replication_promote.go similarity index 70% rename from microceph/cmd/microceph/remote_replication_rbd_promote.go rename to microceph/cmd/microceph/replication_promote.go index 1603fd7e..bf4e1e1e 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_promote.go +++ b/microceph/cmd/microceph/replication_promote.go @@ -9,13 +9,13 @@ import ( "github.com/spf13/cobra" ) -type cmdRemoteReplicationPromoteRbd struct { +type cmdReplicationPromote struct { common *CmdControl remoteName string isForce bool } -func (c *cmdRemoteReplicationPromoteRbd) Command() *cobra.Command { +func (c *cmdReplicationPromote) Command() *cobra.Command { cmd := &cobra.Command{ Use: "promote", Short: "Promote a non-primary cluster to primary status", @@ -28,7 +28,7 @@ func (c *cmdRemoteReplicationPromoteRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationPromoteRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationPromote) Run(cmd *cobra.Command, args []string) error { if len(args) != 0 { return cmd.Help() } @@ -43,12 +43,12 @@ func (c *cmdRemoteReplicationPromoteRbd) Run(cmd *cobra.Command, args []string) return err } - payload, err := c.prepareRbdPayload(types.PromoteReplicationRequest) + payload, err := c.preparePayload(types.PromoteReplicationRequest) if err != nil { return err } - _, err = client.SendRemoteReplicationRequest(context.Background(), cli, payload) + _, err = client.SendReplicationRequest(context.Background(), cli, payload) if err != nil { return err } @@ -56,7 +56,7 @@ func (c *cmdRemoteReplicationPromoteRbd) Run(cmd *cobra.Command, args []string) return nil } -func (c *cmdRemoteReplicationPromoteRbd) prepareRbdPayload(requestType types.ReplicationRequestType) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationPromote) preparePayload(requestType types.ReplicationRequestType) (types.RbdReplicationRequest, error) { retReq := types.RbdReplicationRequest{ RemoteName: c.remoteName, RequestType: requestType, diff --git a/microceph/cmd/microceph/remote_replication_rbd_status.go b/microceph/cmd/microceph/replication_status.go similarity index 84% rename from microceph/cmd/microceph/remote_replication_rbd_status.go rename to microceph/cmd/microceph/replication_status.go index 17e0ccb7..04e402af 100644 --- a/microceph/cmd/microceph/remote_replication_rbd_status.go +++ b/microceph/cmd/microceph/replication_status.go @@ -16,12 +16,29 @@ import ( "golang.org/x/crypto/ssh/terminal" ) -type cmdRemoteReplicationStatusRbd struct { +type cmdReplicationStatus struct { common *CmdControl json bool } -func (c *cmdRemoteReplicationStatusRbd) Command() *cobra.Command { +func (c *cmdReplicationStatus) Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "status", + Short: "Show resource replication status", + } + + statusRbdCmd := cmdReplicationStatusRbd{common: c.common} + cmd.AddCommand(statusRbdCmd.Command()) + + return cmd +} + +type cmdReplicationStatusRbd struct { + common *CmdControl + json bool +} + +func (c *cmdReplicationStatusRbd) Command() *cobra.Command { cmd := &cobra.Command{ Use: "status ", Short: "Show RBD resource (Pool or Image) replication status", @@ -32,7 +49,7 @@ func (c *cmdRemoteReplicationStatusRbd) Command() *cobra.Command { return cmd } -func (c *cmdRemoteReplicationStatusRbd) Run(cmd *cobra.Command, args []string) error { +func (c *cmdReplicationStatusRbd) Run(cmd *cobra.Command, args []string) error { if len(args) != 1 { return cmd.Help() } @@ -52,7 +69,7 @@ func (c *cmdRemoteReplicationStatusRbd) Run(cmd *cobra.Command, args []string) e return err } - resp, err := client.SendRemoteReplicationRequest(context.Background(), cli, payload) + resp, err := client.SendReplicationRequest(context.Background(), cli, payload) if err != nil { return err } @@ -62,10 +79,10 @@ func (c *cmdRemoteReplicationStatusRbd) Run(cmd *cobra.Command, args []string) e return nil } - return printRemoteReplicationStatusTable(payload.ResourceType, resp) + return printReplicationStatusTable(payload.ResourceType, resp) } -func (c *cmdRemoteReplicationStatusRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { +func (c *cmdReplicationStatusRbd) prepareRbdPayload(requestType types.ReplicationRequestType, args []string) (types.RbdReplicationRequest, error) { pool, image, err := types.GetPoolAndImageFromResource(args[0]) if err != nil { return types.RbdReplicationRequest{}, err @@ -81,7 +98,7 @@ func (c *cmdRemoteReplicationStatusRbd) prepareRbdPayload(requestType types.Repl return retReq, nil } -func printRemoteReplicationStatusTable(ResourceType types.RbdResourceType, response string) error { +func printReplicationStatusTable(ResourceType types.RbdResourceType, response string) error { var err error // start table object diff --git a/tests/scripts/actionutils.sh b/tests/scripts/actionutils.sh index a97fc324..fbac58f3 100755 --- a/tests/scripts/actionutils.sh +++ b/tests/scripts/actionutils.sh @@ -241,11 +241,11 @@ function remote_configure_rbd_mirroring() { lxc exec node-wrk1 -- sh -c "microceph.rbd create --size 512 pool_two/image_two" # enable mirroring on pool_one - lxc exec node-wrk0 -- sh -c "microceph remote replication rbd enable pool_one --remote siteb" + lxc exec node-wrk0 -- sh -c "microceph replication enable rbd pool_one --remote siteb" # enable mirroring on pool_two images - lxc exec node-wrk0 -- sh -c "microceph remote replication rbd enable pool_two/image_one --type journal --remote siteb" - lxc exec node-wrk0 -- sh -c "microceph remote replication rbd enable pool_two/image_two --type snapshot --remote siteb" + lxc exec node-wrk0 -- sh -c "microceph replication enable rbd pool_two/image_one --type journal --remote siteb" + lxc exec node-wrk0 -- sh -c "microceph replication enable rbd pool_two/image_two --type snapshot --remote siteb" } function remote_enable_rbd_mirror_daemon() { @@ -256,17 +256,17 @@ function remote_enable_rbd_mirror_daemon() { function remote_wait_for_secondary_to_sync() { set -eux - # wait till images are synchronised + # wait till $1 images are synchronised + local threshold="${1?missing}" count=0 for index in {1..100}; do echo "Check run #$index" - list_output=$(lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd list --json") + list_output=$(lxc exec node-wrk2 -- sh -c "sudo microceph replication list rbd --json") echo $list_output - images=$(echo $list_output | jq .[].Images) - echo $images - img_one_count=$(echo $images | grep -c "image_one" || true) - echo $img_one_count - if [[ $img_one_count -gt 0 ]] ; then + echo $list_output | jq .[].Images > images.json + jq length ./images.json > lengths + images=$(awk '{s+=$1} END {print s}' ./lengths) + if [[ $images -eq $threshold ]] ; then break fi @@ -275,8 +275,8 @@ function remote_wait_for_secondary_to_sync() { sleep 30 done - if [count -eq 10] ; then - echo "Remote replication sync check timed out" + if [$count -eq 100] ; then + echo "replication sync check timed out" exit -1 fi } @@ -284,32 +284,32 @@ function remote_wait_for_secondary_to_sync() { function remote_verify_rbd_mirroring() { set -eux - lxc exec node-wrk0 -- sh -c "sudo microceph remote replication rbd list" - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd list" - lxc exec node-wrk0 -- sh -c "sudo microceph remote replication rbd list" | grep "pool_one.*image_one" - lxc exec node-wrk1 -- sh -c "sudo microceph remote replication rbd list" | grep "pool_one.*image_two" - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd list" | grep "pool_two.*image_one" - lxc exec node-wrk3 -- sh -c "sudo microceph remote replication rbd list" | grep "pool_two.*image_two" + lxc exec node-wrk0 -- sh -c "sudo microceph replication list rbd" + lxc exec node-wrk2 -- sh -c "sudo microceph replication list rbd" + lxc exec node-wrk0 -- sh -c "sudo microceph replication list rbd" | grep "pool_one.*image_one" + lxc exec node-wrk1 -- sh -c "sudo microceph replication list rbd" | grep "pool_one.*image_two" + lxc exec node-wrk2 -- sh -c "sudo microceph replication list rbd" | grep "pool_two.*image_one" + lxc exec node-wrk3 -- sh -c "sudo microceph replication list rbd" | grep "pool_two.*image_two" } function remote_failover_to_siteb() { set -eux # check images are secondary on siteb - img_count=$(lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd list --json" | grep -c "\"is_primary\":false") + img_count=$(lxc exec node-wrk2 -- sh -c "sudo microceph replication list rbd --json" | grep -c "\"is_primary\":false") if [[ $img_count -lt 1 ]]; then echo "Site B has $img_count secondary images" exit -1 fi # promote site b to primary - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd promote --remote sitea --yes-i-really-mean-it" + lxc exec node-wrk2 -- sh -c "sudo microceph replication promote --remote sitea --yes-i-really-mean-it" # wait for the site images to show as primary is_primary_count=0 for index in {1..100}; do echo "Check run #$index" - list_output=$(lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd list --json") + list_output=$(lxc exec node-wrk2 -- sh -c "sudo microceph replication list rbd --json") echo $list_output images=$(echo $list_output | jq .[].Images) echo $images @@ -328,13 +328,13 @@ function remote_failover_to_siteb() { fi # resolve the split brain situation by demoting the old primary. - lxc exec node-wrk0 -- sh -c "sudo microceph remote replication rbd demote --remote siteb --yes-i-really-mean-it" + lxc exec node-wrk0 -- sh -c "sudo microceph replication demote --remote siteb --yes-i-really-mean-it" # wait for the site images to show as non-primary is_primary_count=0 for index in {1..100}; do echo "Check run #$index" - list_output=$(lxc exec node-wrk0 -- sh -c "sudo microceph remote replication rbd list --json") + list_output=$(lxc exec node-wrk0 -- sh -c "sudo microceph replication list rbd --json") echo $list_output images=$(echo $list_output | jq .[].Images) echo $images @@ -356,14 +356,14 @@ function remote_failover_to_siteb() { function remote_disable_rbd_mirroring() { set -eux # check disables fail for image mirroring pools with images currently being mirrored - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd disable pool_two 2>&1 || true" | grep "in Image mirroring mode" + lxc exec node-wrk2 -- sh -c "sudo microceph replication disable rbd pool_two 2>&1 || true" | grep "in Image mirroring mode" # disable both images in pool_two and then disable pool_two - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd disable pool_two/image_one" - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd disable pool_two/image_two" - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd disable pool_two" + lxc exec node-wrk2 -- sh -c "sudo microceph replication disable rbd pool_two/image_one" + lxc exec node-wrk2 -- sh -c "sudo microceph replication disable rbd pool_two/image_two" + lxc exec node-wrk2 -- sh -c "sudo microceph replication disable rbd pool_two" # disable pool one - lxc exec node-wrk2 -- sh -c "sudo microceph remote replication rbd disable pool_one" + lxc exec node-wrk2 -- sh -c "sudo microceph replication disable rbd pool_one" } function remote_remove_and_verify() { @@ -421,14 +421,14 @@ function upgrade_multinode() { lxc exec $container -- sh -c "snap connect microceph:block-devices ; snap connect microceph:hardware-observe ; snap connect microceph:mount-observe" sleep 5 expect=3 - for i in $(seq 1 8); do + for i in $(seq 1 20); do res=$( ( lxc exec $container -- sh -c "microceph.ceph osd status" | fgrep -c "exists,up" ) ) if [[ $res -eq $expect ]] ; then echo "Found ${expect} osd up" break else echo -n '.' - sleep 5 + sleep 10 fi done res=$( ( lxc exec $container -- sh -c "microceph.ceph osd status" | fgrep -c "exists,up" ) )