From e804c5f778ca5e4957953d73ec31fe8919c72eae Mon Sep 17 00:00:00 2001 From: Michael Goff Date: Wed, 16 Nov 2016 19:53:33 -0800 Subject: [PATCH] rook: remove block mount and unmount on mac Block mount and unmount is not supported and will error so I've removed it from the rook client (only on mac) for now. --- cmd/rook/block-list.go | 27 ++++++++++++++------------ cmd/rook/block-list_test.go | 9 +++++++-- cmd/rook/block.go | 13 ++++++++++--- cmd/rook/block_test.go | 38 +++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 cmd/rook/block_test.go diff --git a/cmd/rook/block-list.go b/cmd/rook/block-list.go index ecaf85b96..8bd84900d 100644 --- a/cmd/rook/block-list.go +++ b/cmd/rook/block-list.go @@ -20,6 +20,7 @@ import ( "fmt" "net/http" "os" + "runtime" "strings" "github.com/rook/rook/pkg/rook/client" @@ -66,20 +67,22 @@ func listBlocks(rbdSysBusPath string, c client.RookRestClient, executor exec.Exe return "", nil } - // for each image returned from the client API call, look up local details - for i := range images { - image := &(images[i]) + if runtime.GOOS == "linux" { + // for each image returned from the client API call, look up local details + for i := range images { + image := &(images[i]) - // look up local device and mount point, ignoring errors - devPath, _ := findDevicePath(image.Name, image.PoolName, rbdSysBusPath) - dev := strings.TrimPrefix(devPath, devicePathPrefix) - var mountPoint string - if dev != "" { - mountPoint, _ = sys.GetDeviceMountPoint(dev, executor) + // look up local device and mount point, ignoring errors + devPath, _ := findDevicePath(image.Name, image.PoolName, rbdSysBusPath) + dev := strings.TrimPrefix(devPath, devicePathPrefix) + var mountPoint string + if dev != "" { + mountPoint, _ = sys.GetDeviceMountPoint(dev, executor) + } + + image.Device = dev + image.MountPoint = mountPoint } - - image.Device = dev - image.MountPoint = mountPoint } var buffer bytes.Buffer diff --git a/cmd/rook/block-list_test.go b/cmd/rook/block-list_test.go index cde65dffb..c2e784498 100644 --- a/cmd/rook/block-list_test.go +++ b/cmd/rook/block-list_test.go @@ -20,6 +20,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strings" "testing" @@ -58,8 +59,12 @@ func TestListBlockImages(t *testing.T) { out, err := listBlocks(mockRBDSysBusPath, c, e) assert.Nil(t, err) - expectedOut := "NAME POOL SIZE DEVICE MOUNT\n" + - "myimage1 mypool1 1.00 KiB rbd5 /tmp/mymount1\n" + expectedOut := "NAME POOL SIZE DEVICE MOUNT\n" + if runtime.GOOS == "linux" { + expectedOut += "myimage1 mypool1 1.00 KiB rbd5 /tmp/mymount1\n" + } else { + expectedOut += "myimage1 mypool1 1.00 KiB \n" + } assert.Equal(t, expectedOut, out) } diff --git a/cmd/rook/block.go b/cmd/rook/block.go index edafb8450..9d57e13b8 100644 --- a/cmd/rook/block.go +++ b/cmd/rook/block.go @@ -15,7 +15,11 @@ limitations under the License. */ package rook -import "github.com/spf13/cobra" +import ( + "runtime" + + "github.com/spf13/cobra" +) var blockCmd = &cobra.Command{ Use: "block", @@ -25,6 +29,9 @@ var blockCmd = &cobra.Command{ func init() { blockCmd.AddCommand(blockListCmd) blockCmd.AddCommand(blockCreateCmd) - blockCmd.AddCommand(blockMountCmd) - blockCmd.AddCommand(blockUnmountCmd) + + if runtime.GOOS == "linux" { + blockCmd.AddCommand(blockMountCmd) + blockCmd.AddCommand(blockUnmountCmd) + } } diff --git a/cmd/rook/block_test.go b/cmd/rook/block_test.go new file mode 100644 index 000000000..107a5dce4 --- /dev/null +++ b/cmd/rook/block_test.go @@ -0,0 +1,38 @@ +/* +Copyright 2016 The Rook Authors. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package rook + +import ( + "runtime" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBlockCommand(t *testing.T) { + assert.Equal(t, "block", blockCmd.Use) + + commands := []string{} + for _, command := range blockCmd.Commands() { + commands = append(commands, command.Name()) + } + + if runtime.GOOS == "linux" { + assert.Equal(t, []string{"create", "ls", "mount", "unmount"}, commands) + } else { + assert.Equal(t, []string{"create", "ls"}, commands) + } +}