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 12, 2019
1 parent a513724 commit faa4fc8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 23 deletions.
4 changes: 3 additions & 1 deletion cmd/datamon/cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func addDaemonizeFlag(cmd *cobra.Command) string {
}

func addStreamFlag(cmd *cobra.Command) string {
cmd.Flags().BoolVar(&bundleOptions.Stream, stream, true, "Stream in the FS view of the bundle, do not download all files. Default to true.")
cmd.Flags().BoolVar(&bundleOptions.Stream, stream, true,
"Stream in the FS view of the bundle, do not download all files. "+
"use '--"+stream+"=false' to toggle off.")
return stream
}

Expand Down
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(bundleOptions.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", bundleOptions.DataPath)
return
var err error

var consumableStorePath string
if bundleOptions.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(bundleOptions.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", bundleOptions.DataPath)
return
}
createPath(consumableStorePath)
}
createPath(path)

metadataSource, err := gcs.New(repoParams.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
26 changes: 22 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 @@ -35,7 +37,23 @@ var mutableMountBundleCmd = &cobra.Command{
return
}

DieIfNotDirectory(bundleOptions.DataPath)
var err error

var consumableStorePath string
if bundleOptions.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(bundleOptions.DataPath)
if err != nil {
log.Fatalf("Failed to sanitize destination: %s\n", bundleOptions.DataPath)
return
}
createPath(consumableStorePath)
}

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

bd := core.NewBDescriptor(
core.Message(bundleOptions.Message),
Expand All @@ -62,7 +80,7 @@ var mutableMountBundleCmd = &cobra.Command{
core.MetaStore(metadataSource),
)

fs, err := core.NewMutableFS(bundle, bundleOptions.DataPath)
fs, err := core.NewMutableFS(bundle, consumableStorePath)
if err != nil {
onDaemonError(err)
}
Expand Down Expand Up @@ -91,7 +109,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", repoParams.MetadataBucket,
"--blob", repoParams.BlobBucket,
)
var cmdParams []string
switch testType {
case "nostream-dest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", repoParams.MetadataBucket,
"--blob", repoParams.BlobBucket,
"--stream=false",
}
case "stream-dest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--destination", pathBackingFs,
"--mount", pathToMount,
"--meta", repoParams.MetadataBucket,
"--blob", repoParams.BlobBucket,
}
case "nostream-nodest":
cmdParams = []string{
"bundle", "mount",
"--repo", repo1,
"--bundle", rll[0].hash,
"--mount", pathToMount,
"--meta", repoParams.MetadataBucket,
"--blob", repoParams.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

0 comments on commit faa4fc8

Please sign in to comment.