Skip to content

Commit

Permalink
optional --destination flag on mount
Browse files Browse the repository at this point in the history
Signed-off-by: Ransom Williams <rwilliams@oneconcern.com>
  • Loading branch information
ransomw1c committed Jun 24, 2019
1 parent 3ded5bd commit 26c6c36
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 22 deletions.
26 changes: 19 additions & 7 deletions cmd/datamon/cmd/bundle_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"

Expand Down Expand Up @@ -77,12 +78,23 @@ var mountBundleCmd = &cobra.Command{
return
}

path, err := sanitizePath(params.bundle.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", params.bundle.DataPath)
return
var err error

var consumableStorePath string
if params.bundle.DataPath == "" {
consumableStorePath, err = ioutil.TempDir("", "datamon-mount-destination")
if err != nil {
log.Fatalf("Couldn't create temporary directory: %v\n", err)
return
}
} else {
consumableStorePath, err = sanitizePath(params.bundle.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", params.bundle.DataPath)
return
}
createPath(consumableStorePath)
}
createPath(path)

metadataSource, err := gcs.New(params.repo.MetadataBucket, config.Credential)
if err != nil {
Expand All @@ -92,7 +104,7 @@ var mountBundleCmd = &cobra.Command{
if err != nil {
onDaemonError(err)
}
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), path))
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), consumableStorePath))

err = setLatestOrLabelledBundle(metadataSource)
if err != nil {
Expand Down Expand Up @@ -141,7 +153,7 @@ func init() {
addLabelNameFlag(mountBundleCmd)
// todo: #165 add --cpuprof to all commands via root
addCPUProfFlag(mountBundleCmd)
requiredFlags = append(requiredFlags, addDataPathFlag(mountBundleCmd))
addDataPathFlag(mountBundleCmd)
requiredFlags = append(requiredFlags, addMountPathFlag(mountBundleCmd))

for _, flag := range requiredFlags {
Expand Down
24 changes: 20 additions & 4 deletions cmd/datamon/cmd/bundle_mutable_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"log"

daemonizer "github.com/jacobsa/daemonize"

Expand Down Expand Up @@ -34,8 +36,22 @@ var mutableMountBundleCmd = &cobra.Command{
runDaemonized()
return
}

DieIfNotDirectory(params.bundle.DataPath)
var err error
var consumableStorePath string
if params.bundle.DataPath == "" {
consumableStorePath, err = ioutil.TempDir("", "datamon-mount-destination")
if err != nil {
log.Fatalf("Couldn't create temporary directory: %v\n", err)
return
}
} else {
consumableStorePath, err = sanitizePath(params.bundle.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", params.bundle.DataPath)
return
}
createPath(consumableStorePath)
}

metadataSource, err := gcs.New(params.repo.MetadataBucket, config.Credential)
if err != nil {
Expand All @@ -45,7 +61,7 @@ var mutableMountBundleCmd = &cobra.Command{
if err != nil {
onDaemonError(err)
}
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), params.bundle.DataPath))
consumableStore := localfs.New(afero.NewBasePathFs(afero.NewOsFs(), consumableStorePath))

bd := core.NewBDescriptor(
core.Message(params.bundle.Message),
Expand Down Expand Up @@ -91,7 +107,7 @@ func init() {
addBucketNameFlag(mutableMountBundleCmd)
addDaemonizeFlag(mutableMountBundleCmd)
addBlobBucket(mutableMountBundleCmd)
requiredFlags = append(requiredFlags, addDataPathFlag(mutableMountBundleCmd))
addDataPathFlag(mutableMountBundleCmd)
requiredFlags = append(requiredFlags, addMountPathFlag(mutableMountBundleCmd))
requiredFlags = append(requiredFlags, addCommitMessageFlag(mutableMountBundleCmd))

Expand Down
60 changes: 49 additions & 11 deletions cmd/datamon/cmd/cli_fuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestBundleMount(t *testing.T) {
func testBundleMount(t *testing.T, testType string) {
cleanup := setupTests(t)
defer cleanup()
runCmd(t, []string{"repo",
Expand All @@ -39,16 +39,42 @@ func TestBundleMount(t *testing.T) {
)
defer os.RemoveAll(pathBackingFs)
defer os.RemoveAll(pathToMount)
cmd := exec.Command(
"../datamon",
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
)
var cmdParams []string
switch testType {
case "nostream-dest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
"--stream=false",
}
case "stream-dest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
}
case "nostream-nodest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--mount", pathToMount,
"--meta", params.repo.MetadataBucket,
"--blob", params.repo.BlobBucket,
}
default:
require.True(t, false, "unexpected test type '"+testType+"'")
}
cmd := exec.Command("../datamon", cmdParams...)
require.NoError(t, cmd.Start())
time.Sleep(5 * time.Second)
for _, file := range testUploadTrees[1] {
Expand All @@ -62,6 +88,18 @@ func TestBundleMount(t *testing.T) {
require.Equal(t, "signal: killed", err.Error(), "cmd exit with killed error")
}

func TestBundleMount(t *testing.T) {
testBundleMount(t, "stream-dest")
}

func TestBundleMountNoStream(t *testing.T) {
testBundleMount(t, "nostream-dest")
}

func TestBundleMountNoStreamNoDest(t *testing.T) {
testBundleMount(t, "nostream-nodest")
}

func mutableMountOutputToBundleID(t *testing.T, out string) string {
lines := strings.Split(out, "\n")
var bundleKVLine string
Expand Down
12 changes: 12 additions & 0 deletions cmd/datamon/cmd/cli_fuse_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/sh

# this shell wrapper around the cli_fuse_tests.go to remind how to run the tests.
# these tests are not run as part of CI since FUSE is unavailable via CircleCI.

(cd .. && go build)

go test -tags fuse_cli -list Mount |grep -v '^ok' |while read -r test_name; do
umount /tmp/mmp
rm -r /tmp/mmp /tmp/mmfs
go test -v -tags fuse_cli -run '^'"${test_name}"'$'
done

0 comments on commit 26c6c36

Please sign in to comment.