func mount() error { var err error if fs != nil || server != nil { // already mounting return nil } // create mountpoint os.Mkdir(TEST_MOUNTPOINT, 0777) // config config := &config.Config{ MountPoint: TEST_MOUNTPOINT, ContainerName: TEST_CONTAINER_NAME, CreateContainer: true, Debug: true, NoDaemon: true, } // swift swift := openstack.NewSwift(config) if err = swift.Auth(); err != nil { return err } swift.DeleteContainer() // mapper mapper, err := mapper.NewObjectMapper(config) if err != nil { return err } // initialize filesystem fs = NewObjectFileSystem(config, mapper) path := pathfs.NewPathNodeFs(fs, nil) con := nodefs.NewFileSystemConnector(path.Root(), &nodefs.Options{}) opts := &fuse.MountOptions{ Name: "test-filesystem", FsName: "test-filesystem", } // create server and do mount with dedicated goroutine server, err = fuse.NewServer(con.RawFS(), TEST_MOUNTPOINT, opts) if err != nil { return err } go func() { server.Serve() }() server.WaitMount() return nil }
func TestSetup(t *testing.T) { var err error c := config.NewConfig() c.MountPoint = TEST_MOUNTPOINT c.ContainerName = TEST_CONTAINER_NAME c.CreateContainer = true c.Debug = true c.NoDaemon = true // initialize swift and uplaod testdata swift := openstack.NewSwift(c) if err = swift.Auth(); err != nil { t.Fatalf("%v", err) } swift.DeleteContainer() swift.CreateContainer() // mapper mp, err := mapper.NewObjectMapper(c) if err != nil { t.Fatalf("%v", err) } obj, err := mp.Create(TEST_OBJECT_NAME) if err != nil { t.Fatalf("%v", err) } file, err := obj.Open(os.O_CREATE|os.O_WRONLY, 0666) if err != nil { t.Fatalf("%v", err) } _, err = file.WriteString(TEST_DATA) if err != nil { t.Fatalf("%v", err) } file.Close() // initialize ObjectFile objfile = NewObjectFile(TEST_OBJECT_NAME, obj) }
func TestNewObjectFileSystem(t *testing.T) { config := &config.Config{ MountPoint: TEST_MOUNTPOINT, ContainerName: TEST_CONTAINER_NAME, CreateContainer: true, } mapper, err := mapper.NewObjectMapper(config) if err != nil { t.Fatalf("%v", err) } f := NewObjectFileSystem(config, mapper) if f.containerName != TEST_CONTAINER_NAME { t.Errorf("ContainerName is different (%s != %s)", f.containerName, TEST_CONTAINER_NAME) } if !f.createContainer { t.Errorf("CreateContainer option is false") } }
func Run() { app := cli.NewApp() app.Name = config.APP_NAME app.Usage = "The file system to mount OpenStack Swift via FUSE." app.Version = config.APP_VERSION app.HideHelp = true app.Author = "Hironobu Saitoh" app.Email = "*****@*****.**" app.ArgsUsage = "container-name mountpoint" conf := config.NewConfig() defer conf.Logfile.Close() app.Flags = conf.GetFlags() app.Action = func(c *cli.Context) { if c.Bool("help") || len(c.Args()) < 2 { cli.ShowAppHelp(c) return } app.Flags = append(app.Flags, cli.BoolFlag{ Name: "child", Usage: "internal use only", }) var err error if err = conf.SetConfigFromContext(c); err != nil { log.Warnf("%v", err) return } if !conf.ChildProcess { if err = daemonize(c, conf); err != nil { log.Warnf("%v", err) return } } log.Debug("Create mapper") mapper, err := mapper.NewObjectMapper(conf) if err != nil { log.Warnf("%v", err) afterDaemonize(err) return } log.Debug("Create filesystem") objectFs := fs.NewObjectFileSystem(conf, mapper) log.Debug("Mount filesystem") server, err := mount(objectFs, conf.MountPoint) if err != nil { log.Warnf("%v", err) afterDaemonize(err) return } if conf.ChildProcess { afterDaemonize(nil) } // main loop log.Debugf("Swiftfs process with pid %d started", syscall.Getpid()) server.Serve() log.Debug("Shutdown") } // In daemonizing process, "--child" flag wil be used to recognize myelf as child process. // Remove this flag before the Apps parsing the arguments. args := make([]string, 0, len(os.Args)) for _, p := range os.Args { if p == "--child" { conf.ChildProcess = true } else { args = append(args, p) } } if err := app.Run(args); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }