diff --git a/.github/workflows/canary-integration-test.yml b/.github/workflows/canary-integration-test.yml index a122002a1..a72f31b84 100644 --- a/.github/workflows/canary-integration-test.yml +++ b/.github/workflows/canary-integration-test.yml @@ -755,7 +755,7 @@ jobs: run: | kubectl -n rook-ceph get cephfilesystem myfs -o yaml # the check is not super ideal since 'mirroring_failed' is only displayed when there is a failure but not when it's working... - timeout 60 sh -c 'while [ "$(kubectl exec -n rook-ceph deploy/rook-ceph-tools -t -- ceph fs snapshot mirror daemon status myfs|jq -r '.[0].filesystems[0]'|grep -c "mirroring_failed")" -eq 1 ]; do echo "waiting for filesystem to be mirrored" && sleep 1; done' + timeout 60 sh -c 'while [ "$(kubectl exec -n rook-ceph deploy/rook-ceph-tools -t -- ceph fs snapshot mirror daemon status|jq -r '.[0].filesystems[0]'|grep -c "mirroring_failed")" -eq 1 ]; do echo "waiting for filesystem to be mirrored" && sleep 1; done' - name: collect common logs if: always() diff --git a/pkg/daemon/ceph/client/filesystem_mirror.go b/pkg/daemon/ceph/client/filesystem_mirror.go index c1386c4c7..25511ff2a 100644 --- a/pkg/daemon/ceph/client/filesystem_mirror.go +++ b/pkg/daemon/ceph/client/filesystem_mirror.go @@ -25,6 +25,7 @@ import ( "github.com/pkg/errors" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" + cephver "github.com/rook/rook/pkg/operator/ceph/version" "github.com/rook/rook/pkg/util/exec" ) @@ -214,8 +215,12 @@ func GetFSMirrorDaemonStatus(context *clusterd.Context, clusterInfo *ClusterInfo // Using Debug level since this is called in a recurrent go routine logger.Debugf("retrieving filesystem mirror status for filesystem %q", fsName) + args := []string{"fs", "snapshot", "mirror", "daemon", "status"} // for Ceph v16.2.7 and above + if !clusterInfo.CephVersion.IsAtLeast(cephver.CephVersion{Major: 16, Minor: 2, Extra: 7}) { + // fs-name needed for Ceph v16.2.6 and earlier + args = append(args, fsName) + } // Build command - args := []string{"fs", "snapshot", "mirror", "daemon", "status", fsName} cmd := NewCephCommand(context, clusterInfo, args) // Run command diff --git a/pkg/daemon/ceph/client/filesystem_mirror_test.go b/pkg/daemon/ceph/client/filesystem_mirror_test.go index 8b575541c..b7e6efd27 100644 --- a/pkg/daemon/ceph/client/filesystem_mirror_test.go +++ b/pkg/daemon/ceph/client/filesystem_mirror_test.go @@ -22,6 +22,7 @@ import ( "github.com/pkg/errors" "github.com/rook/rook/pkg/clusterd" + cephver "github.com/rook/rook/pkg/operator/ceph/version" exectest "github.com/rook/rook/pkg/util/exec/test" "github.com/stretchr/testify/assert" ) @@ -33,7 +34,10 @@ var ( // response of "ceph fs snapshot mirror daemon status myfs" // fsMirrorDaemonStatus = `{ "daemon_id": "444607", "filesystems": [ { "filesystem_id": "1", "name": "myfs", "directory_count": 0, "peers": [ { "uuid": "4a6983c0-3c9d-40f5-b2a9-2334a4659827", "remote": { "client_name": "client.mirror_remote", "cluster_name": "site-remote", "fs_name": "backup_fs" }, "stats": { "failure_count": 0, "recovery_count": 0 } } ] } ] }` - fsMirrorDaemonStatusNew = `[{"daemon_id":25103, "filesystems": [{"filesystem_id": 1, "name": "myfs", "directory_count": 0, "peers": []}]}]` + fsMirrorDaemonStatus = `[{"daemon_id":25103, "filesystems": [{"filesystem_id": 1, "name": "myfs", "directory_count": 0, "peers": []}]}]` + + // response of "ceph fs snapshot mirror daemon status" + fsMirrorDaemonStatusNew = `[{"daemon_id":23102, "filesystems": [{"filesystem_id": 2, "name": "myfsNew", "directory_count": 0, "peers": []}]}]` ) func TestEnableFilesystemSnapshotMirror(t *testing.T) { @@ -142,20 +146,44 @@ func TestRemoveFilesystemMirrorPeer(t *testing.T) { func TestFSMirrorDaemonStatus(t *testing.T) { fs := "myfs" executor := &exectest.MockExecutor{} - executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) { - if args[0] == "fs" { - assert.Equal(t, "snapshot", args[1]) - assert.Equal(t, "mirror", args[2]) - assert.Equal(t, "daemon", args[3]) - assert.Equal(t, "status", args[4]) - assert.Equal(t, fs, args[5]) - return fsMirrorDaemonStatusNew, nil + t.Run("snapshot status command with fsName - test for Ceph v16.2.6 and earlier", func(t *testing.T) { + executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) { + if args[0] == "fs" { + assert.Equal(t, "snapshot", args[1]) + assert.Equal(t, "mirror", args[2]) + assert.Equal(t, "daemon", args[3]) + assert.Equal(t, "status", args[4]) + assert.Equal(t, fs, args[5]) // fs-name needed for Ceph v16.2.6 and earlier + return fsMirrorDaemonStatus, nil + } + return "", errors.New("unknown command") } - return "", errors.New("unknown command") - } - context := &clusterd.Context{Executor: executor} - - s, err := GetFSMirrorDaemonStatus(context, AdminTestClusterInfo("mycluster"), fs) - assert.NoError(t, err) - assert.Equal(t, "myfs", s[0].Filesystems[0].Name) + context := &clusterd.Context{Executor: executor} + clusterInfo := AdminTestClusterInfo("mycluster") + clusterInfo.CephVersion = cephver.CephVersion{Major: 16, Minor: 2, Extra: 6} + s, err := GetFSMirrorDaemonStatus(context, clusterInfo, fs) + assert.NoError(t, err) + assert.Equal(t, 25103, s[0].DaemonID) + assert.Equal(t, "myfs", s[0].Filesystems[0].Name) + }) + t.Run("snapshot status command without fsName - test for Ceph v16.2.7 and above", func(t *testing.T) { + executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) { + if args[0] == "fs" { + assert.Equal(t, "snapshot", args[1]) + assert.Equal(t, "mirror", args[2]) + assert.Equal(t, "daemon", args[3]) + assert.Equal(t, "status", args[4]) + assert.NotEqual(t, fs, args[5]) + return fsMirrorDaemonStatusNew, nil + } + return "", errors.New("unknown command") + } + context := &clusterd.Context{Executor: executor} + clusterInfo := AdminTestClusterInfo("mycluster") + clusterInfo.CephVersion = cephver.CephVersion{Major: 16, Minor: 2, Extra: 7} + s, err := GetFSMirrorDaemonStatus(context, clusterInfo, fs) + assert.NoError(t, err) + assert.Equal(t, 23102, s[0].DaemonID) + assert.Equal(t, "myfsNew", s[0].Filesystems[0].Name) + }) }