本文整理匯總了Golang中github.com/juju/names.NewFilesystemTag函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFilesystemTag函數的具體用法?Golang NewFilesystemTag怎麽用?Golang NewFilesystemTag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFilesystemTag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCreateFilesystems
func (s *rootfsSuite) TestCreateFilesystems(c *gc.C) {
source := s.rootfsFilesystemSource(c)
cmd := s.commands.expect("df", "--output=size", s.storageDir)
cmd.respond("1K-blocks\n2048", nil)
cmd = s.commands.expect("df", "--output=size", s.storageDir)
cmd.respond("1K-blocks\n4096", nil)
results, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("6"),
Size: 2,
}, {
Tag: names.NewFilesystemTag("7"),
Size: 4,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.CreateFilesystemsResult{{
Filesystem: &storage.Filesystem{
Tag: names.NewFilesystemTag("6"),
FilesystemInfo: storage.FilesystemInfo{
FilesystemId: "6",
Size: 2,
},
},
}, {
Filesystem: &storage.Filesystem{
Tag: names.NewFilesystemTag("7"),
FilesystemInfo: storage.FilesystemInfo{
FilesystemId: "7",
Size: 4,
},
},
}})
}
示例2: TestCreateFilesystemsHugePages
func (s *tmpfsSuite) TestCreateFilesystemsHugePages(c *gc.C) {
source := s.tmpfsFilesystemSource(c)
// Set page size to 16MiB.
s.PatchValue(provider.Getpagesize, func() int { return 16 * 1024 * 1024 })
results, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("1"),
Size: 17,
}, {
Tag: names.NewFilesystemTag("2"),
Size: 16,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.CreateFilesystemsResult{{
Filesystem: &storage.Filesystem{
Tag: names.NewFilesystemTag("1"),
FilesystemInfo: storage.FilesystemInfo{
FilesystemId: "filesystem-1",
Size: 32,
},
},
}, {
Filesystem: &storage.Filesystem{
Tag: names.NewFilesystemTag("2"),
FilesystemInfo: storage.FilesystemInfo{
FilesystemId: "filesystem-2",
Size: 16,
},
},
}})
}
示例3: TestRemoveFilesystemsMachineAgent
func (s *provisionerSuite) TestRemoveFilesystemsMachineAgent(c *gc.C) {
s.setupFilesystems(c)
s.authorizer.EnvironManager = false
args := params.Entities{Entities: []params.Entity{
{"filesystem-0-0"}, {"filesystem-0-42"}, {"filesystem-42"},
{"filesystem-invalid"}, {"machine-0"},
}}
err := s.State.DetachFilesystem(names.NewMachineTag("0"), names.NewFilesystemTag("0/0"))
c.Assert(err, jc.ErrorIsNil)
err = s.State.RemoveFilesystemAttachment(names.NewMachineTag("0"), names.NewFilesystemTag("0/0"))
c.Assert(err, jc.ErrorIsNil)
err = s.State.DestroyFilesystem(names.NewFilesystemTag("0/0"))
c.Assert(err, jc.ErrorIsNil)
result, err := s.api.Remove(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{Error: nil},
{Error: nil},
{Error: ¶ms.Error{Message: "permission denied", Code: "unauthorized access"}},
{Error: ¶ms.Error{Message: `"filesystem-invalid" is not a valid filesystem tag`}},
{Error: ¶ms.Error{Message: "permission denied", Code: "unauthorized access"}},
},
})
}
示例4: TestAttachFilesystemsMountReadOnly
func (s *tmpfsSuite) TestAttachFilesystemsMountReadOnly(c *gc.C) {
source := s.tmpfsFilesystemSource(c)
_, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("1"),
Size: 1024,
}})
c.Assert(err, jc.ErrorIsNil)
cmd := s.commands.expect("df", "--output=source", "/var/lib/juju/storage/fs/foo")
cmd.respond("header\nvalue", nil)
s.commands.expect("mount", "-t", "tmpfs", "filesystem-1", "/var/lib/juju/storage/fs/foo", "-o", "size=1024m,ro")
results, err := source.AttachFilesystems([]storage.FilesystemAttachmentParams{{
Filesystem: names.NewFilesystemTag("1"),
Path: "/var/lib/juju/storage/fs/foo",
AttachmentParams: storage.AttachmentParams{
Machine: names.NewMachineTag("2"),
ReadOnly: true,
},
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.AttachFilesystemsResult{{
FilesystemAttachment: &storage.FilesystemAttachment{
Filesystem: names.NewFilesystemTag("1"),
Machine: names.NewMachineTag("2"),
FilesystemAttachmentInfo: storage.FilesystemAttachmentInfo{
Path: "/var/lib/juju/storage/fs/foo",
ReadOnly: true,
},
},
}})
}
示例5: TestAttachFilesystemsBindSameFSNonEmptyDirClaimed
func (s *rootfsSuite) TestAttachFilesystemsBindSameFSNonEmptyDirClaimed(c *gc.C) {
source := s.rootfsFilesystemSource(c)
cmd := s.commands.expect("df", "--output=source", "/srv/666")
cmd.respond("headers\n/src/of/root", nil)
cmd = s.commands.expect("mount", "--bind", filepath.Join(s.storageDir, "6"), "/srv/666")
cmd.respond("", errors.New("mount --bind fails"))
cmd = s.commands.expect("df", "--output=target", filepath.Join(s.storageDir, "6"))
cmd.respond("headers\n/dev", nil)
cmd = s.commands.expect("df", "--output=target", "/srv/666")
cmd.respond("headers\n/dev", nil)
s.mockDirFuncs.Dirs.Add(filepath.Join(s.storageDir, "6", "juju-target-claimed"))
results, err := source.AttachFilesystems([]storage.FilesystemAttachmentParams{{
Filesystem: names.NewFilesystemTag("6"),
FilesystemId: "6",
Path: "/srv/666",
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.AttachFilesystemsResult{{
FilesystemAttachment: &storage.FilesystemAttachment{
Filesystem: names.NewFilesystemTag("6"),
FilesystemAttachmentInfo: storage.FilesystemAttachmentInfo{
Path: "/srv/666",
},
},
}})
}
示例6: TestParseFilesystemTag
func (s *filesystemSuite) TestParseFilesystemTag(c *gc.C) {
assertParseFilesystemTag(c, "filesystem-0", names.NewFilesystemTag("0"))
assertParseFilesystemTag(c, "filesystem-88", names.NewFilesystemTag("88"))
assertParseFilesystemTag(c, "filesystem-0-lxc-0-88", names.NewFilesystemTag("0/lxc/0/88"))
assertParseFilesystemTagInvalid(c, "", names.InvalidTagError("", ""))
assertParseFilesystemTagInvalid(c, "one", names.InvalidTagError("one", ""))
assertParseFilesystemTagInvalid(c, "filesystem-", names.InvalidTagError("filesystem-", names.FilesystemTagKind))
assertParseFilesystemTagInvalid(c, "machine-0", names.InvalidTagError("machine-0", names.FilesystemTagKind))
}
示例7: TestParseFilesystemAttachmentId
func (s *FilesystemStateSuite) TestParseFilesystemAttachmentId(c *gc.C) {
assertValid := func(id string, m names.MachineTag, v names.FilesystemTag) {
machineTag, filesystemTag, err := state.ParseFilesystemAttachmentId(id)
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineTag, gc.Equals, m)
c.Assert(filesystemTag, gc.Equals, v)
}
assertValid("0:0", names.NewMachineTag("0"), names.NewFilesystemTag("0"))
assertValid("0:0/1", names.NewMachineTag("0"), names.NewFilesystemTag("0/1"))
assertValid("0/lxc/0:1", names.NewMachineTag("0/lxc/0"), names.NewFilesystemTag("1"))
}
示例8: TestCreateFilesystemsIsUse
func (s *tmpfsSuite) TestCreateFilesystemsIsUse(c *gc.C) {
source := s.tmpfsFilesystemSource(c)
_, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("1"),
Size: 1,
}, {
Tag: names.NewFilesystemTag("1"),
Size: 2,
}})
c.Assert(err, gc.ErrorMatches, "creating filesystem: filesystem 1 already exists")
}
示例9: TestAttachFilesystemsNoPathSpecified
func (s *tmpfsSuite) TestAttachFilesystemsNoPathSpecified(c *gc.C) {
source := s.tmpfsFilesystemSource(c)
_, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("1"),
Size: 1024,
}})
c.Assert(err, jc.ErrorIsNil)
_, err = source.AttachFilesystems([]storage.FilesystemAttachmentParams{{
Filesystem: names.NewFilesystemTag("6"),
}})
c.Assert(err, gc.ErrorMatches, "attaching filesystem 6: filesystem mount point not specified")
}
示例10: TestAttachFilesystemsPathNotDir
func (s *tmpfsSuite) TestAttachFilesystemsPathNotDir(c *gc.C) {
source := s.tmpfsFilesystemSource(c)
_, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("1"),
Size: 1,
}})
c.Assert(err, jc.ErrorIsNil)
_, err = source.AttachFilesystems([]storage.FilesystemAttachmentParams{{
Filesystem: names.NewFilesystemTag("1"),
Path: "file",
}})
c.Assert(err, gc.ErrorMatches, `.* path "file" must be a directory`)
}
示例11: TestCreateFilesystems
func (s *managedfsSuite) TestCreateFilesystems(c *gc.C) {
source := s.initSource(c)
// sda is (re)partitioned and the filesystem created
// on the partition.
s.commands.expect("sgdisk", "--zap-all", "/dev/sda")
s.commands.expect("sgdisk", "-n", "1:0:-1", "/dev/sda")
s.commands.expect("mkfs.ext4", "/dev/sda1")
// xvdf1 is assumed to not require a partition, on
// account of ending with a digit.
s.commands.expect("mkfs.ext4", "/dev/xvdf1")
s.blockDevices[names.NewVolumeTag("0")] = storage.BlockDevice{
DeviceName: "sda",
HardwareId: "capncrunch",
Size: 2,
}
s.blockDevices[names.NewVolumeTag("1")] = storage.BlockDevice{
DeviceName: "xvdf1",
HardwareId: "weetbix",
Size: 3,
}
results, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("0/0"),
Volume: names.NewVolumeTag("0"),
Size: 2,
}, {
Tag: names.NewFilesystemTag("0/1"),
Volume: names.NewVolumeTag("1"),
Size: 3,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.CreateFilesystemsResult{{
Filesystem: &storage.Filesystem{
names.NewFilesystemTag("0/0"),
names.NewVolumeTag("0"),
storage.FilesystemInfo{
FilesystemId: "filesystem-0-0",
Size: 2,
},
},
}, {
Filesystem: &storage.Filesystem{
names.NewFilesystemTag("0/1"),
names.NewVolumeTag("1"),
storage.FilesystemInfo{
FilesystemId: "filesystem-0-1",
Size: 3,
},
},
}})
}
示例12: testAttachFilesystems
func (s *managedfsSuite) testAttachFilesystems(c *gc.C, readOnly, reattach bool) {
const testMountPoint = "/in/the/place"
source := s.initSource(c)
cmd := s.commands.expect("df", "--output=source", filepath.Dir(testMountPoint))
cmd.respond("headers\n/same/as/rootfs", nil)
cmd = s.commands.expect("df", "--output=source", testMountPoint)
if reattach {
cmd.respond("headers\n/different/to/rootfs", nil)
} else {
cmd.respond("headers\n/same/as/rootfs", nil)
var args []string
if readOnly {
args = append(args, "-o", "ro")
}
args = append(args, "/dev/sda1", testMountPoint)
s.commands.expect("mount", args...)
}
s.blockDevices[names.NewVolumeTag("0")] = storage.BlockDevice{
DeviceName: "sda",
HardwareId: "capncrunch",
Size: 2,
}
s.filesystems[names.NewFilesystemTag("0/0")] = storage.Filesystem{
Tag: names.NewFilesystemTag("0/0"),
Volume: names.NewVolumeTag("0"),
}
results, err := source.AttachFilesystems([]storage.FilesystemAttachmentParams{{
Filesystem: names.NewFilesystemTag("0/0"),
FilesystemId: "filesystem-0-0",
AttachmentParams: storage.AttachmentParams{
Machine: names.NewMachineTag("0"),
InstanceId: "inst-ance",
ReadOnly: readOnly,
},
Path: testMountPoint,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.AttachFilesystemsResult{{
FilesystemAttachment: &storage.FilesystemAttachment{
names.NewFilesystemTag("0/0"),
names.NewMachineTag("0"),
storage.FilesystemAttachmentInfo{
Path: testMountPoint,
ReadOnly: readOnly,
},
},
}})
}
示例13: TestWatchMachineFilesystemAttachments
func (s *FilesystemStateSuite) TestWatchMachineFilesystemAttachments(c *gc.C) {
service := s.setupMixedScopeStorageService(c, "filesystem")
addUnit := func(to *state.Machine) (u *state.Unit, m *state.Machine) {
var err error
u, err = service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
if to != nil {
err = u.AssignToMachine(to)
c.Assert(err, jc.ErrorIsNil)
return u, to
}
err = s.State.AssignUnit(u, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
mid, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
m, err = s.State.Machine(mid)
c.Assert(err, jc.ErrorIsNil)
return u, m
}
_, m0 := addUnit(nil)
w := s.State.WatchMachineFilesystemAttachments(names.NewMachineTag("0"))
defer testing.AssertStop(c, w)
wc := testing.NewStringsWatcherC(c, s.State, w)
wc.AssertChangeInSingleEvent("0:0/1", "0:0/2") // initial
wc.AssertNoChange()
addUnit(nil)
// no change, since we're only interested in the one machine.
wc.AssertNoChange()
err := s.State.DetachFilesystem(names.NewMachineTag("0"), names.NewFilesystemTag("0"))
c.Assert(err, jc.ErrorIsNil)
// no change, since we're only interested in attachments of
// machine-scoped volumes.
wc.AssertNoChange()
err = s.State.DetachFilesystem(names.NewMachineTag("0"), names.NewFilesystemTag("0/1"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0/1") // dying
wc.AssertNoChange()
err = s.State.RemoveFilesystemAttachment(names.NewMachineTag("0"), names.NewFilesystemTag("0/1"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0/1") // removed
wc.AssertNoChange()
addUnit(m0)
wc.AssertChangeInSingleEvent("0:0/7", "0:0/8")
wc.AssertNoChange()
}
示例14: TestCreateFilesystemsIsUse
func (s *tmpfsSuite) TestCreateFilesystemsIsUse(c *gc.C) {
source := s.tmpfsFilesystemSource(c)
results, err := source.CreateFilesystems([]storage.FilesystemParams{{
Tag: names.NewFilesystemTag("1"),
Size: 1,
}, {
Tag: names.NewFilesystemTag("1"),
Size: 2,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.HasLen, 2)
c.Assert(results[0].Error, jc.ErrorIsNil)
c.Assert(results[1].Error, gc.ErrorMatches, "filesystem 1 already exists")
}
示例15: TestDestroyFilesystems
func (s *storageProvisionerSuite) TestDestroyFilesystems(c *gc.C) {
provisionedFilesystem := names.NewFilesystemTag("1")
unprovisionedFilesystem := names.NewFilesystemTag("2")
filesystemAccessor := newMockFilesystemAccessor()
filesystemAccessor.provisionFilesystem(provisionedFilesystem)
life := func(tags []names.Tag) ([]params.LifeResult, error) {
results := make([]params.LifeResult, len(tags))
for i := range results {
results[i].Life = params.Dead
}
return results, nil
}
removedChan := make(chan interface{}, 1)
remove := func(tags []names.Tag) ([]params.ErrorResult, error) {
removedChan <- tags
return make([]params.ErrorResult, len(tags)), nil
}
args := &workerArgs{
filesystems: filesystemAccessor,
life: &mockLifecycleManager{
life: life,
remove: remove,
},
}
worker := newStorageProvisioner(c, args)
defer func() { c.Assert(worker.Wait(), gc.IsNil) }()
defer worker.Kill()
filesystemAccessor.filesystemsWatcher.changes <- []string{
provisionedFilesystem.Id(),
unprovisionedFilesystem.Id(),
}
args.environ.watcher.changes <- struct{}{}
// Both filesystems should be removed; the provisioned one
// *should* be deprovisioned first, but we don't currently
// have the ability to do so via the storage provider API.
var removed []names.Tag
for len(removed) < 2 {
tags := waitChannel(c, removedChan, "waiting for filesystems to be removed").([]names.Tag)
removed = append(removed, tags...)
}
c.Assert(removed, jc.SameContents, []names.Tag{provisionedFilesystem, unprovisionedFilesystem})
assertNoEvent(c, removedChan, "filesystems removed")
}