Skip to content

Commit

Permalink
Added remote remove
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Bhatt <[email protected]>
  • Loading branch information
UtkarshBhatthere committed Aug 12, 2024
1 parent baa384e commit 3a2b4e7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,6 @@ jobs:

- name: Verify Remote authentication
run: ~/actionutils.sh remote_perform_remote_ops_check

- name: Verify Remote removal
run: ~/actionutils.sh remote_remove_and_verify
15 changes: 14 additions & 1 deletion microceph/client/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ func SendRemoteImportRequest(ctx context.Context, c *microCli.Client, data types
return nil
}

// SendRemoteImportToClusterMembers Sends the remote import request to every other member of the cluster.
// SendRemoteRemoveRequest sends the remote remove op to MicroCeph.
func SendRemoteRemoveRequest(ctx context.Context, c *microCli.Client, remote string) error {
queryCtx, cancel := context.WithTimeout(ctx, time.Second*120)
defer cancel()

err := c.Query(queryCtx, "PUT", types.ExtendedPathPrefix, api.NewURL().Path("client", "remotes", remote), nil, nil)
if err != nil {
return fmt.Errorf("failed to import MicroCeph remote: %w", err)
}

return nil
}

// Sends the remote import request to every other member of the cluster.
func SendRemoteImportToClusterMembers(s *state.State, data types.Remote) error {
// Get a collection of clients to every other cluster member.
cluster, err := s.Cluster(false)
Expand Down
7 changes: 5 additions & 2 deletions microceph/cmd/microceph/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ func (c *cmdRemote) Command() *cobra.Command {
}

// Import subcommand
remoteImportCmd := cmdRemoteImport{common: c.common, remote: c}
remoteImportCmd := cmdRemoteImport{common: c.common}
cmd.AddCommand(remoteImportCmd.Command())
// List subcommand
remoteListCmd := cmdRemoteList{common: c.common, remote: c}
remoteListCmd := cmdRemoteList{common: c.common}
cmd.AddCommand(remoteListCmd.Command())
// Remove subcommand
remoteRemoveCmd := cmdRemoteRemove{common: c.common}
cmd.AddCommand(remoteRemoveCmd.Command())

// Workaround for subcommand usage errors. See: https://github.com/spf13/cobra/issues/706
cmd.Args = cobra.NoArgs
Expand Down
1 change: 0 additions & 1 deletion microceph/cmd/microceph/remote_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

type cmdRemoteImport struct {
common *CmdControl
remote *cmdRemote
localName string
}

Expand Down
1 change: 0 additions & 1 deletion microceph/cmd/microceph/remote_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

type cmdRemoteList struct {
common *CmdControl
remote *cmdRemote
json bool
}

Expand Down
42 changes: 42 additions & 0 deletions microceph/cmd/microceph/remote_remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"context"

"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)

type cmdRemoteRemove struct {
common *CmdControl
}

func (c *cmdRemoteRemove) Command() *cobra.Command {
cmd := &cobra.Command{
Use: "remove <Name>",
Short: "Remove configured remote",
RunE: c.Run,
}

return cmd
}

func (c *cmdRemoteRemove) Run(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Help()
}

m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}

cli, err := m.LocalClient()
if err != nil {
return err
}

// send remote remove request
return client.SendRemoteRemoveRequest(context.Background(), cli, args[0])
}
12 changes: 12 additions & 0 deletions tests/scripts/actionutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ function remote_perform_remote_ops_check() {
lxc exec node-wrk3 -- sh -c "microceph remote list --json | grep '\"LocalName\":\"siteb\"'"
}

function remote_remove_and_verify() {
# Remove the configured remote from MicroCeph
lxc exec node-wrk0 -- sh -c "microceph remote remove siteb"
# Verify list output
match=$((lxc exec node-wrk0 -- sh -c "microceph remote list --json | grep '\"Name\":\"siteb\"'") || true )
if [[ $match -ne 0 ]] ; then
echo "Remote record still present."
lxc exec node-wrk0 -- sh -c "microceph remote list --json"
exit -1
fi
}
function install_multinode() {
# Install and setup microceph snap
for container in node-wrk0 node-wrk1 node-wrk2 node-wrk3 ; do
Expand Down

0 comments on commit 3a2b4e7

Please sign in to comment.