本文整理匯總了Golang中bosh/system/fakes.NewFakeCmdRunner函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFakeCmdRunner函數的具體用法?Golang NewFakeCmdRunner怎麽用?Golang NewFakeCmdRunner使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFakeCmdRunner函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: buildCompiler
func buildCompiler() (
deps compilerDeps,
compiler Compiler,
) {
deps.compressor = fakecmd.NewFakeCompressor()
deps.blobstore = &fakeblobstore.FakeBlobstore{}
deps.fs = fakesys.NewFakeFileSystem()
deps.runner = fakesys.NewFakeCmdRunner()
deps.packageApplier = fakepa.NewFakePackageApplier()
fakeBundleCollection := fakebc.NewFakeBundleCollection()
bundleDefinition := boshmodels.Package{
Name: "pkg_name",
Version: "pkg_version",
}
deps.bundle = fakeBundleCollection.FakeGet(bundleDefinition)
deps.bundle.InstallPath = "/fake-dir/data/packages/pkg_name/pkg_version"
deps.bundle.EnablePath = "/fake-dir/packages/pkg_name"
deps.packagesBc = fakeBundleCollection
compiler = NewConcreteCompiler(
deps.compressor,
deps.blobstore,
deps.fs,
deps.runner,
boshdirs.NewDirectoriesProvider("/fake-dir"),
deps.packageApplier,
deps.packagesBc,
)
return
}
示例2: TestNewDrainScript
func TestNewDrainScript(t *testing.T) {
runner := fakesys.NewFakeCmdRunner()
fs := fakesys.NewFakeFileSystem()
dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
scriptProvider := NewConcreteDrainScriptProvider(runner, fs, dirProvider)
drainScript := scriptProvider.NewDrainScript("foo")
assert.Equal(t, drainScript.Path(), "/var/vcap/jobs/foo/bin/drain")
}
示例3: buildCompiler
func buildCompiler() (
compressor *fakecmd.FakeCompressor,
blobstore *fakeblobstore.FakeBlobstore,
fs *fakesys.FakeFileSystem,
runner *fakesys.FakeCmdRunner,
compiler Compiler,
) {
compressor = fakecmd.NewFakeCompressor()
blobstore = &fakeblobstore.FakeBlobstore{}
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
compiler = newConcreteCompiler(compressor, blobstore, fs, runner, boshdirs.NewDirectoriesProvider("/fake-dir"))
return
}
示例4: NewFakePlatform
func NewFakePlatform() (platform *FakePlatform) {
platform = new(FakePlatform)
platform.Fs = fakesys.NewFakeFileSystem()
platform.Runner = fakesys.NewFakeCmdRunner()
platform.FakeCompressor = fakecmd.NewFakeCompressor()
platform.FakeCopier = fakecmd.NewFakeCopier()
platform.FakeVitalsService = fakevitals.NewFakeService()
platform.DevicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
platform.AddUserToGroupsGroups = make(map[string][]string)
platform.SetupSshPublicKeys = make(map[string]string)
platform.UserPasswords = make(map[string]string)
platform.ScsiDiskMap = make(map[string]string)
return
}
示例5: init
func init() {
Describe("Testing with Ginkgo", func() {
It("new drain script", func() {
runner := fakesys.NewFakeCmdRunner()
fs := fakesys.NewFakeFileSystem()
dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
scriptProvider := NewConcreteDrainScriptProvider(runner, fs, dirProvider)
drainScript := scriptProvider.NewDrainScript("foo")
Expect(drainScript.Path()).To(Equal("/var/vcap/jobs/foo/bin/drain"))
})
})
}
示例6: buildDrain
func buildDrain() (
cmdRunner *fakesys.FakeCmdRunner,
fs *fakesys.FakeFileSystem,
notifier *fakenotif.FakeNotifier,
specService *fakeas.FakeV1Service,
action drainAction,
) {
cmdRunner = fakesys.NewFakeCmdRunner()
fs = fakesys.NewFakeFileSystem()
notifier = fakenotif.NewFakeNotifier()
specService = fakeas.NewFakeV1Service()
dirProvider := boshdirs.NewDirectoriesProvider("/fake-dir")
drainScriptProvider := boshdrain.NewDrainScriptProvider(cmdRunner, fs, dirProvider)
action = newDrain(notifier, specService, drainScriptProvider)
return
}
示例7: buildDrainScript
func buildDrainScript(commandResult fakesys.FakeCmdResult) (
drainScript ConcreteDrainScript,
params staticDrainParams,
runner *fakesys.FakeCmdRunner,
fs *fakesys.FakeFileSystem,
) {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
drainScript = NewConcreteDrainScript(fs, runner, "/fake/script")
params = staticDrainParams{
jobChange: "job_shutdown",
hashChange: "hash_unchanged",
updatedPackages: []string{"foo", "bar"},
}
runner.AddCmdResult("/fake/script"+" job_shutdown hash_unchanged foo bar", commandResult)
return
}
示例8: TestDecompressFileToDirUsesNoSameOwnerOption
func TestDecompressFileToDirUsesNoSameOwnerOption(t *testing.T) {
fs, _ := getCompressorDependencies()
cmdRunner := fakesys.NewFakeCmdRunner()
dc := NewTarballCompressor(cmdRunner, fs)
dstDir := createdTmpDir(t, fs)
defer os.RemoveAll(dstDir)
tarball := fixtureSrcTgz(t)
err := dc.DecompressFileToDir(tarball, dstDir)
assert.NoError(t, err)
assert.Equal(t, 1, len(cmdRunner.RunCommands))
assert.Equal(t, []string{
"tar", "--no-same-owner",
"-xzvf", tarball.Name(),
"-C", dstDir,
}, cmdRunner.RunCommands[0])
}
示例9: GetIP
func (ia failingInterfaceAddress) GetIP() (string, error) {
return "", errors.New("fake-get-ip-err")
}
var _ = Describe("arping", func() {
const arpingIterations = 6
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
arping AddressBroadcaster
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
logger := boshlog.NewLogger(boshlog.LevelNone)
arping = NewArping(cmdRunner, fs, logger, arpingIterations, 0, 0)
})
Describe("BroadcastMACAddresses", func() {
BeforeEach(func() {
fs.WriteFile("/sys/class/net/eth0", []byte{})
fs.WriteFile("/sys/class/net/eth1", []byte{})
})
It("runs arping commands for each interface", func() {
addresses := []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "192.168.195.6"),
boship.NewSimpleInterfaceAddress("eth1", "127.0.0.1"),
}
示例10: init
func init() {
const expectedUbuntuDHCPConfig = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
prepend domain-name-servers zz.zz.zz.zz, yy.yy.yy.yy, xx.xx.xx.xx;
`
Describe("ubuntuNetManager", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
defaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
netManager NetManager
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
defaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
netManager = NewUbuntuNetManager(fs, cmdRunner, defaultNetworkResolver, 1*time.Millisecond, logger)
})
Describe("SetupDhcp", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns"},
DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy", "zz.zz.zz.zz"},
},
"vip": boshsettings.Network{
Default: []string{},
DNS: []string{"aa.aa.aa.aa"},
},
}
ItRestartsDhcp := func() {
Context("when ifconfig version is 0.7", func() {
BeforeEach(func() {
cmdRunner.AddCmdResult("ifup --version", fakesys.FakeCmdResult{
Stdout: "ifup version 0.7.47",
})
})
It("restarts dhclient", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(3))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"ifdown", "-a", "--no-loopback"}))
Expect(cmdRunner.RunCommands[2]).To(Equal([]string{"ifup", "-a", "--no-loopback"}))
})
})
Context("when ifconfig version is 0.6", func() {
BeforeEach(func() {
cmdRunner.AddCmdResult("ifup --version", fakesys.FakeCmdResult{
Stdout: "ifup version 0.6.0",
})
})
It("restarts dhclient", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(3))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"ifdown", "-a", "--exclude=lo"}))
Expect(cmdRunner.RunCommands[2]).To(Equal([]string{"ifup", "-a", "--exclude=lo"}))
})
})
}
ItUpdatesDhcp3Config := func() {
It("updates /etc/dhcp3/dhclient.conf", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp3/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
}
ItUpdatesDhcpConfig := func() {
It("updates /etc/dhcp/dhclient.conf", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
}
//.........這裏部分代碼省略.........
示例11: init
func init() {
const expectedCentosDHCPConfig = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
prepend domain-name-servers zz.zz.zz.zz;
prepend domain-name-servers yy.yy.yy.yy;
prepend domain-name-servers xx.xx.xx.xx;
`
const expectedCentosIfcfg = `DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.195.6
NETMASK=255.255.255.0
BROADCAST=192.168.195.255
GATEWAY=192.168.195.1
ONBOOT=yes`
Describe("centos", func() {
var (
collector *fakestats.FakeStatsCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager *fakedisk.FakeDiskManager
dirProvider boshdirs.DirectoriesProvider
platform Platform
cdutil *fakecd.FakeCdUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeStatsCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs)
vitalsService = boshvitals.NewService(collector, dirProvider)
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
netManager := boshnet.NewCentosNetManager(fs, cmdRunner, 1*time.Millisecond)
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
netManager,
1*time.Millisecond,
logger,
)
})
Describe("SetupDhcp", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns"},
DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy", "zz.zz.zz.zz"},
},
"vip": boshsettings.Network{
Default: []string{},
DNS: []string{"aa.aa.aa.aa"},
},
}
Context("when dhcp was not previously configured", func() {
It("writes dhcp configuration", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedCentosDHCPConfig))
})
It("restarts network", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network", "restart"}))
//.........這裏部分代碼省略.........
示例12: init
func init() {
Describe("Testing with Ginkgo", func() {
It("sfdisk partition", func() {
runner := fakesys.NewFakeCmdRunner()
runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskEmptyDump})
partitioner := createSfdiskPartitionerForTests(runner)
partitions := []Partition{
{Type: PartitionTypeSwap, SizeInMb: 512},
{Type: PartitionTypeLinux, SizeInMb: 1024},
{Type: PartitionTypeLinux, SizeInMb: 512},
}
partitioner.Partition("/dev/sda", partitions)
Expect(1).To(Equal(len(runner.RunCommandsWithInput)))
Expect(runner.RunCommandsWithInput[0]).To(Equal([]string{",512,S\n,1024,L\n,,L\n", "sfdisk", "-uM", "/dev/sda"}))
})
It("sfdisk partition with no partition table", func() {
runner := fakesys.NewFakeCmdRunner()
runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stderr: devSdaSfdiskNotableDumpStderr})
partitioner := createSfdiskPartitionerForTests(runner)
partitions := []Partition{
{Type: PartitionTypeSwap, SizeInMb: 512},
{Type: PartitionTypeLinux, SizeInMb: 1024},
{Type: PartitionTypeLinux, SizeInMb: 512},
}
partitioner.Partition("/dev/sda", partitions)
Expect(1).To(Equal(len(runner.RunCommandsWithInput)))
Expect(runner.RunCommandsWithInput[0]).To(Equal([]string{",512,S\n,1024,L\n,,L\n", "sfdisk", "-uM", "/dev/sda"}))
})
It("sfdisk get device size in mb", func() {
runner := fakesys.NewFakeCmdRunner()
runner.AddCmdResult("sfdisk -s /dev/sda", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 40000*1024)})
partitioner := createSfdiskPartitionerForTests(runner)
size, err := partitioner.GetDeviceSizeInMb("/dev/sda")
Expect(err).ToNot(HaveOccurred())
Expect(uint64(40000)).To(Equal(size))
})
It("sfdisk partition when partitions already match", func() {
runner := fakesys.NewFakeCmdRunner()
runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskDump})
runner.AddCmdResult("sfdisk -s /dev/sda", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 2048*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda1", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 525*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda2", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 1020*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda3", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 500*1024)})
partitioner := createSfdiskPartitionerForTests(runner)
partitions := []Partition{
{Type: PartitionTypeSwap, SizeInMb: 512},
{Type: PartitionTypeLinux, SizeInMb: 1024},
{Type: PartitionTypeLinux, SizeInMb: 512},
}
partitioner.Partition("/dev/sda", partitions)
Expect(0).To(Equal(len(runner.RunCommandsWithInput)))
})
It("sfdisk partition with last partition not matching size", func() {
runner := fakesys.NewFakeCmdRunner()
runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskDumpOnePartition})
runner.AddCmdResult("sfdisk -s /dev/sda", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 2048*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda1", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 1024*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda2", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 512*1024)})
partitioner := createSfdiskPartitionerForTests(runner)
partitions := []Partition{
{Type: PartitionTypeLinux, SizeInMb: 1024},
{Type: PartitionTypeLinux},
}
partitioner.Partition("/dev/sda", partitions)
Expect(1).To(Equal(len(runner.RunCommandsWithInput)))
Expect(runner.RunCommandsWithInput[0]).To(Equal([]string{",1024,L\n,,L\n", "sfdisk", "-uM", "/dev/sda"}))
})
It("sfdisk partition with last partition filling disk", func() {
runner := fakesys.NewFakeCmdRunner()
runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskDumpOnePartition})
runner.AddCmdResult("sfdisk -s /dev/sda", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 2048*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda1", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 1024*1024)})
runner.AddCmdResult("sfdisk -s /dev/sda2", fakesys.FakeCmdResult{Stdout: fmt.Sprintf("%d\n", 1024*1024)})
partitioner := createSfdiskPartitionerForTests(runner)
partitions := []Partition{
{Type: PartitionTypeLinux, SizeInMb: 1024},
{Type: PartitionTypeLinux},
}
//.........這裏部分代碼省略.........
示例13: init
func init() {
Describe("Testing with Ginkgo", func() {
It("compress files in dir", func() {
fs, cmdRunner := getCompressorDependencies()
dc := NewTarballCompressor(cmdRunner, fs)
srcDir := fixtureSrcDir(GinkgoT())
tgzName, err := dc.CompressFilesInDir(srcDir)
Expect(err).ToNot(HaveOccurred())
defer os.Remove(tgzName)
dstDir := createdTmpDir(GinkgoT(), fs)
defer os.RemoveAll(dstDir)
_, _, err = cmdRunner.RunCommand("tar", "--no-same-owner", "-xzpf", tgzName, "-C", dstDir)
Expect(err).ToNot(HaveOccurred())
content, err := fs.ReadFileString(dstDir + "/app.stdout.log")
Expect(err).ToNot(HaveOccurred())
assert.Contains(GinkgoT(), content, "this is app stdout")
content, err = fs.ReadFileString(dstDir + "/app.stderr.log")
Expect(err).ToNot(HaveOccurred())
assert.Contains(GinkgoT(), content, "this is app stderr")
content, err = fs.ReadFileString(dstDir + "/other_logs/other_app.stdout.log")
Expect(err).ToNot(HaveOccurred())
assert.Contains(GinkgoT(), content, "this is other app stdout")
})
It("decompress file to dir", func() {
fs, cmdRunner := getCompressorDependencies()
dc := NewTarballCompressor(cmdRunner, fs)
dstDir := createdTmpDir(GinkgoT(), fs)
defer os.RemoveAll(dstDir)
err := dc.DecompressFileToDir(fixtureSrcTgz(GinkgoT()), dstDir)
Expect(err).ToNot(HaveOccurred())
content, err := fs.ReadFileString(dstDir + "/not-nested-file")
Expect(err).ToNot(HaveOccurred())
assert.Contains(GinkgoT(), content, "not-nested-file")
content, err = fs.ReadFileString(dstDir + "/dir/nested-file")
Expect(err).ToNot(HaveOccurred())
assert.Contains(GinkgoT(), content, "nested-file")
content, err = fs.ReadFileString(dstDir + "/dir/nested-dir/double-nested-file")
Expect(err).ToNot(HaveOccurred())
assert.Contains(GinkgoT(), content, "double-nested-file")
content, err = fs.ReadFileString(dstDir + "/empty-dir")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("is a directory"))
content, err = fs.ReadFileString(dstDir + "/dir/empty-nested-dir")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("is a directory"))
})
It("decompress file to dir returns error", func() {
nonExistentDstDir := filepath.Join(os.TempDir(), "TestDecompressFileToDirReturnsError")
fs, cmdRunner := getCompressorDependencies()
dc := NewTarballCompressor(cmdRunner, fs)
err := dc.DecompressFileToDir(fixtureSrcTgz(GinkgoT()), nonExistentDstDir)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(nonExistentDstDir))
})
It("decompress file to dir uses no same owner option", func() {
fs, _ := getCompressorDependencies()
cmdRunner := fakesys.NewFakeCmdRunner()
dc := NewTarballCompressor(cmdRunner, fs)
dstDir := createdTmpDir(GinkgoT(), fs)
defer os.RemoveAll(dstDir)
tarballPath := fixtureSrcTgz(GinkgoT())
err := dc.DecompressFileToDir(tarballPath, dstDir)
Expect(err).ToNot(HaveOccurred())
Expect(1).To(Equal(len(cmdRunner.RunCommands)))
assert.Equal(GinkgoT(), []string{
"tar", "--no-same-owner",
"-xzvf", tarballPath,
"-C", dstDir,
}, cmdRunner.RunCommands[0])
})
})
}
示例14: init
func init() {
Describe("Testing with Ginkgo", func() {
It("linux format when using swap fs", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mkswap", "/dev/xvda1"}))
})
It("linux format when using swap fs and partition is swap", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="swap" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
It("linux format when using ext4 fs with lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "-E", "lazy_itable_init=1", "/dev/xvda2"}))
})
It("linux format when using ext4 fs without lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "/dev/xvda2"}))
})
It("linux format when using ext4 fs and partition is ext4", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemExt4)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
})
}
示例15: init
func init() {
const expectedUbuntuDHCPConfig = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
prepend domain-name-servers zz.zz.zz.zz;
prepend domain-name-servers yy.yy.yy.yy;
prepend domain-name-servers xx.xx.xx.xx;
`
Describe("ubuntu", func() {
var (
collector *fakestats.FakeStatsCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager *fakedisk.FakeDiskManager
dirProvider boshdirs.DirectoriesProvider
platform Platform
cdutil *fakecd.FakeCdUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeStatsCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs)
vitalsService = boshvitals.NewService(collector, dirProvider)
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
netManager := boshnet.NewUbuntuNetManager(fs, cmdRunner, 1*time.Millisecond)
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
netManager,
1*time.Millisecond,
logger,
)
})
Describe("SetupDhcp", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns"},
DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy", "zz.zz.zz.zz"},
},
"vip": boshsettings.Network{
Default: []string{},
DNS: []string{"aa.aa.aa.aa"},
},
}
Context("when dhcp was not previously configured", func() {
It("updates dhclient.conf", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp3/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
It("restarts dhclient", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(2))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"pkill", "dhclient3"}))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"/etc/init.d/networking", "restart"}))
})
})
Context("when dhcp was previously configured with different configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp3/dhclient.conf", "fake-other-configuration")
})
//.........這裏部分代碼省略.........