It("allows 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/xvda2", 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"})) }) Context("when mke2fs errors", func() { var fakeRunner *fakesys.FakeCmdRunner var fakeFs *fakesys.FakeFileSystem var mkeCmd string BeforeEach(func() { fakeRunner = fakesys.NewFakeCmdRunner() fakeFs = fakesys.NewFakeFileSystem() fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{}) fakeRunner.AddCmdResult("blkid -p /dev/xvda2", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`}) mkeCmd = fmt.Sprintf("mke2fs -t %s -j -E lazy_itable_init=1 %s", FileSystemExt4, "/dev/xvda2") }) It("retries mke2fs if the erros is 'device is already in use'", func() { fakeRunner.AddCmdResult(mkeCmd, fakesys.FakeCmdResult{ Error: errors.New(`mke2fs 1.42.9 (4-Feb-2014)
"strings" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" boshassert "github.com/cloudfoundry/bosh-utils/assert" . "github.com/cloudfoundry/bosh-utils/blobstore" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" fakeuuid "github.com/cloudfoundry/bosh-utils/uuid/fakes" ) var _ = Describe("externalBlobstore", func() { var ( fs *fakesys.FakeFileSystem runner *fakesys.FakeCmdRunner uuidGen *fakeuuid.FakeGenerator configPath string blobstore Blobstore ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() runner = fakesys.NewFakeCmdRunner() uuidGen = &fakeuuid.FakeGenerator{} configPath = filepath.Join("/etc/", "blobstore-fake-provider.json") blobstore = NewExternalBlobstore("fake-provider", map[string]interface{}{}, fs, runner, uuidGen, configPath) }) Describe("Validate", func() { It("external validate writes config file", func() { options := map[string]interface{}{"fake-key": "fake-value"}
BeforeEach(func() { mockCtrl = gomock.NewController(GinkgoT()) }) AfterEach(func() { mockCtrl.Finish() }) var ( logger boshlog.Logger compiler bistatepkg.Compiler runner *fakesys.FakeCmdRunner pkg *birelpkg.Package fs *fakesys.FakeFileSystem compressor *fakecmd.FakeCompressor packagesDir string blobstore *fakeblobstore.FakeBlobstore mockCompiledPackageRepo *mock_state_package.MockCompiledPackageRepo fakeExtractor *fakeblobextract.FakeExtractor dependency1 *birelpkg.Package dependency2 *birelpkg.Package ) BeforeEach(func() { logger = boshlog.NewLogger(boshlog.LevelNone) packagesDir = "fake-packages-dir" runner = fakesys.NewFakeCmdRunner() fs = fakesys.NewFakeFileSystem() compressor = fakecmd.NewFakeCompressor()
fakeaction "github.com/cloudfoundry/bosh-agent/agent/action/fakes" "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec" . "github.com/cloudfoundry/bosh-agent/agent/script/drain" "github.com/cloudfoundry/bosh-agent/agent/script/drain/fakes" boshlog "github.com/cloudfoundry/bosh-utils/logger" boshsys "github.com/cloudfoundry/bosh-utils/system" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("ConcreteScript", func() { var ( fs *fakesys.FakeFileSystem runner *fakesys.FakeCmdRunner params ScriptParams fakeClock *fakeaction.FakeClock script ConcreteScript exampleSpec func() applyspec.V1ApplySpec scriptCommandFactory boshsys.ScriptCommandFactory ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() runner = fakesys.NewFakeCmdRunner() params = &fakes.FakeScriptParams{} fakeClock = &fakeaction.FakeClock{} scriptCommandFactory = boshsys.NewScriptCommandFactory("linux") }) JustBeforeEach(func() { logger := boshlog.NewLogger(boshlog.LevelNone)
package net_test import ( "errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-agent/platform/net" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("cmdRoutesSeacher", func() { var ( runner *fakesys.FakeCmdRunner searcher RoutesSearcher ) BeforeEach(func() { runner = fakesys.NewFakeCmdRunner() searcher = NewCmdRoutesSearcher(runner) }) Describe("SearchRoutes", func() { Context("when running command succeeds", func() { It("returns parsed routes information", func() { runner.AddCmdResult("route -n", fakesys.FakeCmdResult{ Stdout: `Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 172.16.79.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
import ( "errors" "path/filepath" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" boshscript "github.com/cloudfoundry/bosh-agent/agent/script" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("GenericScript", func() { var ( fs *fakesys.FakeFileSystem cmdRunner *fakesys.FakeCmdRunner genericScript boshscript.GenericScript stdoutLogPath string stderrLogPath string ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() cmdRunner = fakesys.NewFakeCmdRunner() stdoutLogPath = filepath.Join("base", "stdout", "logdir", "stdout.log") stderrLogPath = filepath.Join("base", "stderr", "logdir", "stderr.log") genericScript = boshscript.NewScript( fs, cmdRunner, "my-tag", "/path-to-script", stdoutLogPath,
import ( "errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" fakeboshaction "github.com/cloudfoundry/bosh-agent/agent/action/fakes" . "github.com/cloudfoundry/bosh-agent/platform/disk" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("PartedPartitioner", func() { var ( fakeCmdRunner *fakesys.FakeCmdRunner partitioner Partitioner fakeclock *fakeboshaction.FakeClock logger boshlog.Logger ) BeforeEach(func() { logger = boshlog.NewLogger(boshlog.LevelNone) fakeCmdRunner = fakesys.NewFakeCmdRunner() fakeclock = &fakeboshaction.FakeClock{} partitioner = NewPartedPartitioner(logger, fakeCmdRunner, fakeclock) }) Describe("Partition", func() { Context("when the desired partitions do not exist", func() { Context("when there is no partition table", func() { BeforeEach(func() { fakeCmdRunner.AddCmdResult(
. "github.com/cloudfoundry/bosh-agent/platform/net/arp" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) func expectedLogFormat(level, msg string) string { return fmt.Sprintf("\\[arp] [0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} %s - %s\n", level, msg) } var _ = Describe("arp", func() { var ( address string arp Arp cmdRunner *fakesys.FakeCmdRunner logger boshlog.Logger outBuf *bytes.Buffer errBuf *bytes.Buffer ) BeforeEach(func() { address = "10.0.0.1" cmdRunner = fakesys.NewFakeCmdRunner() outBuf = bytes.NewBufferString("") errBuf = bytes.NewBufferString("") logger = boshlog.NewWriterLogger(boshlog.LevelDebug, outBuf, errBuf) arp = NewArp(cmdRunner, logger) }) Describe("Delete", func() { JustBeforeEach(func() {
import ( "errors" . "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer" fakebierbrenderer "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer/fakes" boshlog "github.com/cloudfoundry/bosh-utils/logger" boshsys "github.com/cloudfoundry/bosh-utils/system" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("ErbRenderer", func() { var ( fs *fakesys.FakeFileSystem runner *fakesys.FakeCmdRunner erbRenderer ERBRenderer context *fakebierbrenderer.FakeTemplateEvaluationContext ) BeforeEach(func() { logger := boshlog.NewLogger(boshlog.LevelNone) fs = fakesys.NewFakeFileSystem() runner = fakesys.NewFakeCmdRunner() context = &fakebierbrenderer.FakeTemplateEvaluationContext{} erbRenderer = NewERBRenderer(fs, runner, logger) fs.TempDirDir = "fake-temp-dir" }) It("constructs ruby erb rendering command", func() { err := erbRenderer.Render("fake-src-path", "fake-dst-path", context)
package disk_test import ( "errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-agent/platform/disk" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("cmdMountsSeacher", func() { var ( runner *fakesys.FakeCmdRunner searcher MountsSearcher ) BeforeEach(func() { runner = fakesys.NewFakeCmdRunner() searcher = NewCmdMountsSearcher(runner) }) Describe("SearchMounts", func() { Context("when running command succeeds", func() { It("returns parsed mount information", func() { runner.AddCmdResult("mount", fakesys.FakeCmdResult{ Stdout: `devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) /dev/sda1 on /boot type ext2 (rw) none on /tmp/warden/cgroup type tmpfs (rw)`,
import ( "errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" boshretry "github.com/cloudfoundry/bosh-utils/retrystrategy" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" . "github.com/cloudfoundry/bosh-agent/platform" ) var _ = Describe("MonitRetryable", func() { var ( cmdRunner *fakesys.FakeCmdRunner monitRetryable boshretry.Retryable ) BeforeEach(func() { cmdRunner = fakesys.NewFakeCmdRunner() monitRetryable = NewMonitRetryable(cmdRunner) }) Describe("Attempt", func() { Context("when starting monit fails", func() { BeforeEach(func() { cmdRunner.AddCmdResult("sv start monit", fakesys.FakeCmdResult{ ExitStatus: 255, Error: errors.New("fake-start-monit-error"), }) })
} return hw.String() } type fakeMACAddressDetector struct { macs map[string]string } func (m *fakeMACAddressDetector) MACAddresses() (map[string]string, error) { return m.macs, nil } var _ = Describe("WindowsNetManager", func() { var ( clock *fakeclock.FakeClock runner *fakesys.FakeCmdRunner netManager Manager interfaceConfigurationCreator InterfaceConfigurationCreator ) macAddressDetector := new(fakeMACAddressDetector) setupMACs := func(networks ...boshsettings.Network) error { m := make(map[string]string) for i, net := range networks { if net.Mac != "" { m[net.Mac] = fmt.Sprintf("Eth_HW %d", i) } else { m[randomMAC()] = fmt.Sprintf("Eth_Rand %d", i) } } macAddressDetector.macs = m return nil
/dev/sda3 : start= xxxx, size= xxxx, Id=83 /dev/sda4 : start= 0, size= 0, Id= 0 ` const devSdaSfdiskDumpOnePartition = `# partition table of /dev/sda unit: sectors /dev/sda1 : start= 1, size= xxxx, Id=83 /dev/sda2 : start= xxxx, size= xxxx, Id=83 /dev/sda3 : start= 0, size= 0, Id= 0 /dev/sda4 : start= 0, size= 0, Id= 0 ` var _ = Describe("sfdiskPartitioner", func() { var ( runner *fakesys.FakeCmdRunner partitioner Partitioner ) BeforeEach(func() { runner = fakesys.NewFakeCmdRunner() logger := boshlog.NewLogger(boshlog.LevelNone) partitioner = NewSfdiskPartitioner(logger, runner) }) It("sfdisk partition", func() { runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskEmptyDump}) partitions := []Partition{ {Type: PartitionTypeSwap, SizeInBytes: 512 * 1024 * 1024}, {Type: PartitionTypeLinux, SizeInBytes: 1024 * 1024 * 1024},
boshalert "github.com/cloudfoundry/bosh-agent/agent/alert" . "github.com/cloudfoundry/bosh-agent/jobsupervisor" boshmonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit" fakemonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit/fakes" boshdir "github.com/cloudfoundry/bosh-agent/settings/directories" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("monitJobSupervisor", func() { var ( fs *fakesys.FakeFileSystem runner *fakesys.FakeCmdRunner client *fakemonit.FakeMonitClient logger boshlog.Logger dirProvider boshdir.Provider jobFailuresServerPort int monit JobSupervisor ) var jobFailureServerPort = 5000 getJobFailureServerPort := func() int { jobFailureServerPort++ return jobFailureServerPort } BeforeEach(func() { fs = fakesys.NewFakeFileSystem() runner = fakesys.NewFakeCmdRunner()
import ( "errors" "os" . "github.com/cloudfoundry/bosh-utils/internal/github.com/onsi/ginkgo" . "github.com/cloudfoundry/bosh-utils/internal/github.com/onsi/gomega" boshlog "github.com/cloudfoundry/bosh-utils/logger" . "github.com/cloudfoundry/bosh-utils/system" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("ScriptRunner", func() { var ( cmdRunner *fakesys.FakeCmdRunner fs *fakesys.FakeFileSystem scriptRunner ScriptRunner logger boshlog.Logger ) BeforeEach(func() { scriptCommandFactory := &fakesys.FakeCommandFactory{} scriptCommandFactory.ReturnExtension = ".fake-ext" cmdRunner = fakesys.NewFakeCmdRunner() fs = fakesys.NewFakeFileSystem() var err error fs.ReturnTempFile, err = fs.OpenFile("/fake-temp-file", os.O_WRONLY, os.ModePerm) Expect(err).NotTo(HaveOccurred())
package cdrom_test import ( "errors" . "github.com/cloudfoundry/bosh-agent/platform/cdrom" fakeudev "github.com/cloudfoundry/bosh-agent/platform/udevdevice/fakes" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("LinuxCdrom", func() { var ( udev *fakeudev.FakeUdevDevice runner *fakesys.FakeCmdRunner cd Cdrom ) BeforeEach(func() { udev = fakeudev.NewFakeUdevDevice() runner = fakesys.NewFakeCmdRunner() }) JustBeforeEach(func() { cd = NewLinuxCdrom("/dev/sr0", udev, runner) }) Describe("WaitForMedia", func() { It("polls the cdrom to force udev to notice it", func() { err := cd.WaitForMedia()
func describeUbuntuNetManager() { var ( fs *fakesys.FakeFileSystem cmdRunner *fakesys.FakeCmdRunner ipResolver *fakeip.FakeResolver addressBroadcaster *fakearp.FakeAddressBroadcaster interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider netManager UbuntuNetManager interfaceConfigurationCreator InterfaceConfigurationCreator ) writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string { interfacePath := fmt.Sprintf("/sys/class/net/%s", iface) fs.WriteFile(interfacePath, []byte{}) if isPhysical { fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{}) } fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress)) return interfacePath } stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) { interfacePaths := []string{} for iface, networkSettings := range physicalInterfaces { interfacePaths = append(interfacePaths, writeNetworkDevice(iface, networkSettings.Mac, true)) } for _, iface := range virtualInterfaces { interfacePaths = append(interfacePaths, writeNetworkDevice(iface, "virtual", false)) } fs.SetGlob("/sys/class/net/*", interfacePaths) } stubInterfaces := func(physicalInterfaces map[string]boshsettings.Network) { stubInterfacesWithVirtual(physicalInterfaces, nil) } BeforeEach(func() { fs = fakesys.NewFakeFileSystem() cmdRunner = fakesys.NewFakeCmdRunner() ipResolver = &fakeip.FakeResolver{} logger := boshlog.NewLogger(boshlog.LevelNone) interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger) addressBroadcaster = &fakearp.FakeAddressBroadcaster{} interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{} interfaceAddrsValidator := boship.NewInterfaceAddressesValidator(interfaceAddrsProvider) dnsValidator := NewDNSValidator(fs) netManager = NewUbuntuNetManager( fs, cmdRunner, ipResolver, interfaceConfigurationCreator, interfaceAddrsValidator, dnsValidator, addressBroadcaster, logger, ).(UbuntuNetManager) }) Describe("ComputeNetworkConfig", func() { Context("when there is one manual network and neither is marked as default for DNS", func() { It("should use the manual network for DNS", func() { networks := boshsettings.Networks{ "manual": factory.Network{DNS: &[]string{"8.8.8.8"}}.Build(), } stubInterfaces(networks) _, _, dnsServers, err := netManager.ComputeNetworkConfig(networks) Expect(err).ToNot(HaveOccurred()) Expect(dnsServers).To(Equal([]string{"8.8.8.8"})) }) }) Context("when there is a vip network and a manual network and neither is marked as default for DNS", func() { It("should use the manual network for DNS", func() { networks := boshsettings.Networks{ "vip": boshsettings.Network{Type: "vip"}, "manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}}.Build(), } stubInterfaces(networks) _, _, dnsServers, err := netManager.ComputeNetworkConfig(networks) Expect(err).ToNot(HaveOccurred()) Expect(dnsServers).To(Equal([]string{"8.8.8.8"})) }) }) Context("when there is a vip network and a manual network and the manual network is marked as default for DNS", func() { It("should use the manual network for DNS", func() { networks := boshsettings.Networks{ "vip": boshsettings.Network{Type: "vip"}, "manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}, Default: []string{"dns"}}.Build(), } stubInterfaces(networks) _, _, dnsServers, err := netManager.ComputeNetworkConfig(networks) Expect(err).ToNot(HaveOccurred()) Expect(dnsServers).To(Equal([]string{"8.8.8.8"})) }) }) Context("when specified more than one DNS", func() { It("extracts all DNS servers from the network configured as default DNS", func() { networks := boshsettings.Networks{ "default": factory.Network{ IP: "10.10.0.32", Netmask: "255.255.255.0", Mac: "aa::bb::cc", Default: []string{"dns", "gateway"}, DNS: &[]string{"54.209.78.6", "127.0.0.5"}, Gateway: "10.10.0.1", }.Build(), } stubInterfaces(networks) staticInterfaceConfigurations, dhcpInterfaceConfigurations, dnsServers, err := netManager.ComputeNetworkConfig(networks) Expect(err).ToNot(HaveOccurred()) Expect(staticInterfaceConfigurations).To(Equal([]StaticInterfaceConfiguration{ { Name: "default", Address: "10.10.0.32", Netmask: "255.255.255.0", Network: "10.10.0.0", IsDefaultForGateway: true, Broadcast: "10.10.0.255", Mac: "aa::bb::cc", Gateway: "10.10.0.1", }, })) Expect(dhcpInterfaceConfigurations).To(BeEmpty()) Expect(dnsServers).To(Equal([]string{"54.209.78.6", "127.0.0.5"})) }) }) }) Describe("SetupNetworking", func() { var ( dhcpNetwork boshsettings.Network staticNetwork boshsettings.Network expectedNetworkConfigurationForStaticAndDhcp string ) BeforeEach(func() { dhcpNetwork = boshsettings.Network{ Type: "dynamic", Default: []string{"dns"}, DNS: []string{"8.8.8.8", "9.9.9.9"}, Mac: "fake-dhcp-mac-address", } staticNetwork = boshsettings.Network{ Type: "manual", IP: "1.2.3.4", Default: []string{"gateway"}, Netmask: "255.255.255.0", Gateway: "3.4.5.6", Mac: "fake-static-mac-address", } interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{ boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"), } fs.WriteFileString("/etc/resolv.conf", ` nameserver 8.8.8.8 nameserver 9.9.9.9 `) expectedNetworkConfigurationForStaticAndDhcp = `# Generated by bosh-agent auto lo iface lo inet loopback auto ethdhcp iface ethdhcp inet dhcp auto ethstatic iface ethstatic inet static address 1.2.3.4 network 1.2.3.0 netmask 255.255.255.0 broadcast 1.2.3.255 gateway 3.4.5.6 dns-nameservers 8.8.8.8 9.9.9.9` }) It("writes interfaces in /etc/network/interfaces in alphabetic order", func() { anotherDHCPNetwork := boshsettings.Network{ Type: "dynamic", Default: []string{"dns"}, DNS: []string{"8.8.8.8", "9.9.9.9"}, Mac: "fake-another-mac-address", } stubInterfaces(map[string]boshsettings.Network{ "ethstatic": staticNetwork, "ethdhcp1": dhcpNetwork, "ethdhcp0": anotherDHCPNetwork, }) err := netManager.SetupNetworking(boshsettings.Networks{ "dhcp-network-1": dhcpNetwork, "dhcp-network-2": anotherDHCPNetwork, "static-network": staticNetwork, }, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig).ToNot(BeNil()) expectedNetworkConfigurationForStaticAndDhcp = `# Generated by bosh-agent auto lo iface lo inet loopback auto ethdhcp0 iface ethdhcp0 inet dhcp auto ethdhcp1 iface ethdhcp1 inet dhcp auto ethstatic iface ethstatic inet static address 1.2.3.4 network 1.2.3.0 netmask 255.255.255.0 broadcast 1.2.3.255 gateway 3.4.5.6 dns-nameservers 8.8.8.8 9.9.9.9` Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp)) }) It("configures gateway, broadcast and dns for default network only", func() { staticNetwork = boshsettings.Network{ Type: "manual", IP: "1.2.3.4", Netmask: "255.255.255.0", Gateway: "3.4.5.6", Mac: "fake-static-mac-address", } secondStaticNetwork := boshsettings.Network{ Type: "manual", IP: "5.6.7.8", Netmask: "255.255.255.0", Gateway: "6.7.8.9", Mac: "second-fake-static-mac-address", DNS: []string{"8.8.8.8"}, Default: []string{"gateway", "dns"}, } stubInterfaces(map[string]boshsettings.Network{ "eth0": staticNetwork, "eth1": secondStaticNetwork, }) interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{ boship.NewSimpleInterfaceAddress("eth0", "1.2.3.4"), boship.NewSimpleInterfaceAddress("eth1", "5.6.7.8"), } err := netManager.SetupNetworking(boshsettings.Networks{ "static-1": staticNetwork, "static-2": secondStaticNetwork, }, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig).ToNot(BeNil()) Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 1.2.3.4 network 1.2.3.0 netmask 255.255.255.0 auto eth1 iface eth1 inet static address 5.6.7.8 network 5.6.7.0 netmask 255.255.255.0 broadcast 5.6.7.255 gateway 6.7.8.9 dns-nameservers 8.8.8.8`)) }) It("writes /etc/network/interfaces without dns-namservers if there are no dns servers", func() { staticNetworkWithoutDNS := boshsettings.Network{ Type: "manual", IP: "1.2.3.4", Default: []string{"gateway"}, Netmask: "255.255.255.0", Gateway: "3.4.5.6", Mac: "fake-static-mac-address", } stubInterfaces(map[string]boshsettings.Network{ "ethstatic": staticNetworkWithoutDNS, }) err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetworkWithoutDNS}, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig).ToNot(BeNil()) Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent auto lo iface lo inet loopback auto ethstatic iface ethstatic inet static address 1.2.3.4 network 1.2.3.0 netmask 255.255.255.0 broadcast 1.2.3.255 gateway 3.4.5.6 `)) }) It("returns errors from glob /sys/class/net/", func() { fs.GlobErr = errors.New("fs-glob-error") err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fs-glob-error")) }) It("returns errors from writing the network configuration", func() { stubInterfaces(map[string]boshsettings.Network{ "dhcp": dhcpNetwork, "static": staticNetwork, }) fs.WriteFileError = errors.New("fs-write-file-error") err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fs-write-file-error")) }) It("returns errors when it can't creating network interface configurations", func() { stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) staticNetwork.Netmask = "not an ip" //will cause InterfaceConfigurationCreator to fail err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, nil) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Creating interface configurations")) }) It("writes a dhcp configuration if there are dhcp networks", func() { stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).ToNot(HaveOccurred()) dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf") Expect(dhcpConfig).ToNot(BeNil()) Expect(dhcpConfig.StringContents()).To(Equal(`# 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 8.8.8.8, 9.9.9.9; `)) }) It("writes a dhcp configuration without prepended dns servers if there are no dns servers specified", func() { dhcpNetworkWithoutDNS := boshsettings.Network{ Type: "dynamic", Mac: "fake-dhcp-mac-address", } stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, }) err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetworkWithoutDNS}, nil) Expect(err).ToNot(HaveOccurred()) dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf") Expect(dhcpConfig).ToNot(BeNil()) Expect(dhcpConfig.StringContents()).To(Equal(`# 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; `)) }) It("returns an error if it can't write a dhcp configuration", func() { stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) fs.WriteFileErrors["/etc/dhcp/dhclient.conf"] = errors.New("dhclient.conf-write-error") err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("dhclient.conf-write-error")) }) It("doesn't write a dhcp configuration if there are no dhcp networks", func() { stubInterfaces(map[string]boshsettings.Network{ "ethstatic": staticNetwork, }) err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, nil) Expect(err).ToNot(HaveOccurred()) dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf") Expect(dhcpConfig).To(BeNil()) }) It("restarts the networks if /etc/network/interfaces changes", func() { initialDhcpConfig := `# 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 8.8.8.8, 9.9.9.9; ` stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) fs.WriteFileString("/etc/dhcp/dhclient.conf", initialDhcpConfig) err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).ToNot(HaveOccurred()) Expect(len(cmdRunner.RunCommands)).To(Equal(5)) Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"pkill", "dhclient"})) Expect(cmdRunner.RunCommands[1:3]).To(ContainElement([]string{"resolvconf", "-d", "ethdhcp.dhclient"})) Expect(cmdRunner.RunCommands[1:3]).To(ContainElement([]string{"resolvconf", "-d", "ethstatic.dhclient"})) Expect(cmdRunner.RunCommands[3]).To(Equal([]string{"ifdown", "--force", "ethdhcp", "ethstatic"})) Expect(cmdRunner.RunCommands[4]).To(Equal([]string{"ifup", "--force", "ethdhcp", "ethstatic"})) }) It("doesn't restart the networks if /etc/network/interfaces and /etc/dhcp/dhclient.conf don't change", func() { initialDhcpConfig := `# 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 8.8.8.8, 9.9.9.9; ` stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) fs.WriteFileString("/etc/network/interfaces", expectedNetworkConfigurationForStaticAndDhcp) fs.WriteFileString("/etc/dhcp/dhclient.conf", initialDhcpConfig) err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp)) dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf") Expect(dhcpConfig.StringContents()).To(Equal(initialDhcpConfig)) Expect(len(cmdRunner.RunCommands)).To(Equal(0)) }) It("restarts the networks if /etc/dhcp/dhclient.conf changes", func() { stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) fs.WriteFileString("/etc/network/interfaces", expectedNetworkConfigurationForStaticAndDhcp) err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp)) Expect(len(cmdRunner.RunCommands)).To(Equal(5)) Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"pkill", "dhclient"})) Expect(cmdRunner.RunCommands[1:3]).To(ContainElement([]string{"resolvconf", "-d", "ethdhcp.dhclient"})) Expect(cmdRunner.RunCommands[1:3]).To(ContainElement([]string{"resolvconf", "-d", "ethstatic.dhclient"})) Expect(cmdRunner.RunCommands[3]).To(Equal([]string{"ifdown", "--force", "ethdhcp", "ethstatic"})) Expect(cmdRunner.RunCommands[4]).To(Equal([]string{"ifup", "--force", "ethdhcp", "ethstatic"})) }) It("broadcasts MAC addresses for all interfaces", func() { stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) errCh := make(chan error) err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, errCh) Expect(err).ToNot(HaveOccurred()) broadcastErr := <-errCh // wait for all arpings Expect(broadcastErr).ToNot(HaveOccurred()) Expect(addressBroadcaster.BroadcastMACAddressesAddresses).To(Equal([]boship.InterfaceAddress{ boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"), boship.NewResolvingInterfaceAddress("ethdhcp", ipResolver), })) }) It("skips vip networks", func() { stubInterfaces(map[string]boshsettings.Network{ "ethdhcp": dhcpNetwork, "ethstatic": staticNetwork, }) vipNetwork := boshsettings.Network{ Type: "vip", Default: []string{"dns"}, DNS: []string{"8.8.8.8", "9.9.9.9"}, Mac: "fake-vip-mac-address", IP: "9.8.7.6", } err := netManager.SetupNetworking(boshsettings.Networks{ "dhcp-network": dhcpNetwork, "static-network": staticNetwork, "vip-network": vipNetwork, }, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig).ToNot(BeNil()) Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp)) }) Context("when manual networks were not configured with proper IP addresses", func() { BeforeEach(func() { interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{ boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.5"), } }) It("fails", func() { stubInterfaces(map[string]boshsettings.Network{ "ethstatic": staticNetwork, }) errCh := make(chan error) err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, errCh) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Validating static network configuration")) }) }) Context("when dns is not properly configured", func() { BeforeEach(func() { fs.WriteFileString("/etc/resolv.conf", "") }) It("fails", func() { staticNetwork = boshsettings.Network{ Type: "manual", IP: "1.2.3.4", Default: []string{"dns"}, DNS: []string{"8.8.8.8"}, Netmask: "255.255.255.0", Gateway: "3.4.5.6", Mac: "fake-static-mac-address", } stubInterfaces(map[string]boshsettings.Network{ "ethstatic": staticNetwork, }) errCh := make(chan error) err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, errCh) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Validating dns configuration")) }) }) Context("when no MAC address is provided in the settings", func() { It("configures network for single device", func() { staticNetworkWithoutMAC := boshsettings.Network{ Type: "manual", IP: "2.2.2.2", Default: []string{"gateway"}, Netmask: "255.255.255.0", Gateway: "3.4.5.6", } stubInterfaces( map[string]boshsettings.Network{ "ethstatic": staticNetwork, }, ) interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{ boship.NewSimpleInterfaceAddress("ethstatic", "2.2.2.2"), } err := netManager.SetupNetworking(boshsettings.Networks{ "static-network": staticNetworkWithoutMAC, }, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig).ToNot(BeNil()) expectedNetworkConfiguration := `# Generated by bosh-agent auto lo iface lo inet loopback auto ethstatic iface ethstatic inet static address 2.2.2.2 network 2.2.2.0 netmask 255.255.255.0 broadcast 2.2.2.255 gateway 3.4.5.6 ` Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfiguration)) }) It("configures network for a single physical device, when a virtual device is also present", func() { staticNetworkWithoutMAC := boshsettings.Network{ Type: "manual", IP: "2.2.2.2", Default: []string{"gateway"}, Netmask: "255.255.255.0", Gateway: "3.4.5.6", } stubInterfacesWithVirtual( map[string]boshsettings.Network{ "ethstatic": staticNetwork, }, []string{"virtual"}, ) interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{ boship.NewSimpleInterfaceAddress("ethstatic", "2.2.2.2"), } err := netManager.SetupNetworking(boshsettings.Networks{ "static-network": staticNetworkWithoutMAC, }, nil) Expect(err).ToNot(HaveOccurred()) networkConfig := fs.GetFileTestStat("/etc/network/interfaces") Expect(networkConfig).ToNot(BeNil()) expectedNetworkConfiguration := `# Generated by bosh-agent auto lo iface lo inet loopback auto ethstatic iface ethstatic inet static address 2.2.2.2 network 2.2.2.0 netmask 255.255.255.0 broadcast 2.2.2.255 gateway 3.4.5.6 ` Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfiguration)) }) }) }) Describe("GetConfiguredNetworkInterfaces", func() { Context("when there are network devices", func() { BeforeEach(func() { interfacePaths := []string{} interfacePaths = append(interfacePaths, writeNetworkDevice("fake-eth0", "aa:bb", true)) interfacePaths = append(interfacePaths, writeNetworkDevice("fake-eth1", "cc:dd", true)) interfacePaths = append(interfacePaths, writeNetworkDevice("fake-eth2", "ee:ff", true)) fs.SetGlob("/sys/class/net/*", interfacePaths) }) It("returns networks that are defined in /etc/network/interfaces", func() { cmdRunner.AddCmdResult("ifup --no-act fake-eth0", fakesys.FakeCmdResult{ Stdout: "", Stderr: "ifup: interface fake-eth0 already configured", ExitStatus: 0, }) cmdRunner.AddCmdResult("ifup --no-act fake-eth1", fakesys.FakeCmdResult{ Stdout: "", Stderr: "Ignoring unknown interface fake-eth1=fake-eth1.", ExitStatus: 0, }) cmdRunner.AddCmdResult("ifup --no-act fake-eth2", fakesys.FakeCmdResult{ Stdout: "", Stderr: "ifup: interface fake-eth2 already configured", ExitStatus: 0, }) interfaces, err := netManager.GetConfiguredNetworkInterfaces() Expect(err).ToNot(HaveOccurred()) Expect(interfaces).To(ConsistOf("fake-eth0", "fake-eth2")) }) }) Context("when there are no network devices", func() { It("returns empty list", func() { interfaces, err := netManager.GetConfiguredNetworkInterfaces() Expect(err).ToNot(HaveOccurred()) Expect(interfaces).To(Equal([]string{})) }) }) }) }
package disk_test import ( "errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-agent/platform/disk" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("rootDevicePartitioner", func() { var ( fakeCmdRunner *fakesys.FakeCmdRunner partitioner Partitioner ) BeforeEach(func() { logger := boshlog.NewLogger(boshlog.LevelNone) fakeCmdRunner = fakesys.NewFakeCmdRunner() partitioner = NewRootDevicePartitioner(logger, fakeCmdRunner, 1) }) Describe("Partition", func() { Context("when the desired partitions do not exist", func() { BeforeEach(func() { // 20GiB device, ~3GiB partition 0, 18403868671B remaining fakeCmdRunner.AddCmdResult( "parted -m /dev/sda unit B print", fakesys.FakeCmdResult{
import ( "errors" "os" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-agent/agent/cmdrunner" boshsys "github.com/cloudfoundry/bosh-utils/system" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("FileLoggingCmdRunner", func() { var ( fs *fakesys.FakeFileSystem cmdRunner *fakesys.FakeCmdRunner cmd boshsys.Command runner CmdRunner ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() cmdRunner = fakesys.NewFakeCmdRunner() runner = NewFileLoggingCmdRunner(fs, cmdRunner, "/fake-base-dir", 15) cmd = boshsys.Command{ Name: "fake-cmd", Args: []string{"fake-args"}, Env: map[string]string{"fake-env-key": "fake-env-var"}, WorkingDir: "/fake-working-dir", } })
/dev/sda1 : start= 1, size= xxxx, Id=83 /dev/sda2 : start= xxxx, size= xxxx, Id=83 /dev/sda3 : start= 0, size= 0, Id= 0 /dev/sda4 : start= 0, size= 0, Id= 0 ` const expectedDmSetupLs = ` xxxxxx-part1 (252:1) xxxxxx (252:0) ` var _ = Describe("sfdiskPartitioner", func() { var ( runner *fakesys.FakeCmdRunner partitioner Partitioner fakeclock *fakeboshaction.FakeClock ) BeforeEach(func() { runner = fakesys.NewFakeCmdRunner() logger := boshlog.NewLogger(boshlog.LevelNone) fakeclock = &fakeboshaction.FakeClock{} partitioner = NewSfdiskPartitioner(logger, runner, fakeclock) }) It("sfdisk partition", func() { runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskEmptyDump}) partitions := []Partition{
"errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "fmt" fakeboshaction "github.com/cloudfoundry/bosh-agent/agent/action/fakes" . "github.com/cloudfoundry/bosh-agent/platform/disk" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("PartedPartitioner", func() { var ( fakeCmdRunner *fakesys.FakeCmdRunner partitioner Partitioner fakeclock *fakeboshaction.FakeClock logger boshlog.Logger ) BeforeEach(func() { logger = boshlog.NewLogger(boshlog.LevelNone) fakeCmdRunner = fakesys.NewFakeCmdRunner() fakeclock = &fakeboshaction.FakeClock{} partitioner = NewPartedPartitioner(logger, fakeCmdRunner, fakeclock) }) Describe("Partition", func() { Context("when the desired partitions do not exist", func() { Context("when there is no partition table", func() { BeforeEach(func() { fakeCmdRunner.AddCmdResult(
s.mounts = s.mounts[1:] return result, nil } const swaponUsageOutput = `Filename Type Size Used Priority /dev/swap partition 78180316 0 -1 ` const swaponUsageOutputWithOtherDevice = `Filename Type Size Used Priority /dev/swap2 partition 78180316 0 -1 ` var _ = Describe("linuxMounter", func() { var ( runner *fakesys.FakeCmdRunner mountsSearcher *fakedisk.FakeMountsSearcher mounter Mounter ) BeforeEach(func() { runner = fakesys.NewFakeCmdRunner() mountsSearcher = &fakedisk.FakeMountsSearcher{} mounter = NewLinuxMounter(runner, mountsSearcher, 1*time.Millisecond) }) Describe("Mount", func() { It("allows to mount disk at given mount point", func() { err := mounter.Mount("/dev/foo", "/mnt/foo") Expect(err).ToNot(HaveOccurred()) Expect(1).To(Equal(len(runner.RunCommands))) Expect(runner.RunCommands[0]).To(Equal([]string{"mount", "/dev/foo", "/mnt/foo"}))
boshalert "github.com/cloudfoundry/bosh-agent/agent/alert" . "github.com/cloudfoundry/bosh-agent/jobsupervisor" boshmonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit" fakemonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit/fakes" boshdir "github.com/cloudfoundry/bosh-agent/settings/directories" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("monitJobSupervisor", func() { var ( fs *fakesys.FakeFileSystem runner *fakesys.FakeCmdRunner client *fakemonit.FakeMonitClient logger boshlog.Logger dirProvider boshdir.Provider jobFailuresServerPort int monit JobSupervisor timeService *fakeclock.FakeClock ) var jobFailureServerPort = 5000 getJobFailureServerPort := func() int { jobFailureServerPort++ return jobFailureServerPort } BeforeEach(func() { fs = fakesys.NewFakeFileSystem() runner = fakesys.NewFakeCmdRunner()
/dev/mapper/xxxxxx1 : start= 1, size= xxxx , Id=83 /dev/mapper/xxxxxx2 : start= 0, size= 0, Id= 0 /dev/mapper/xxxxxx3 : start= 0, size= 0, Id= 0 /dev/mapper/xxxxxx4 : start= 0, size= 0, Id= 0 ` const expectedDmSetupLs = ` xxxxxx-part1 (252:1) xxxxxx (252:0) ` var _ = Describe("sfdiskPartitioner", func() { var ( runner *fakesys.FakeCmdRunner partitioner Partitioner fakeclock *fakeboshaction.FakeClock ) BeforeEach(func() { runner = fakesys.NewFakeCmdRunner() logger := boshlog.NewLogger(boshlog.LevelNone) fakeclock = &fakeboshaction.FakeClock{} partitioner = NewSfdiskPartitioner(logger, runner, fakeclock) }) It("sfdisk partition", func() { runner.AddCmdResult("sfdisk -d /dev/sda", fakesys.FakeCmdResult{Stdout: devSdaSfdiskEmptyDump}) runner.AddCmdResult("sfdisk -s /dev/sda", fakesys.FakeCmdResult{Stdout: "1048576"})
package blobstore_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-utils/blobstore" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" boshuuid "github.com/cloudfoundry/bosh-utils/uuid" ) var _ = Describe("Provider", func() { var ( fs *fakesys.FakeFileSystem runner *fakesys.FakeCmdRunner logger boshlog.Logger provider Provider ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() runner = fakesys.NewFakeCmdRunner() logger = boshlog.NewLogger(boshlog.LevelNone) provider = NewProvider(fs, runner, "/var/vcap/config", logger) }) Describe("Get", func() { It("get dummy", func() { blobstore, err := provider.Get(BlobstoreTypeDummy, map[string]interface{}{}) Expect(err).ToNot(HaveOccurred()) Expect(blobstore).ToNot(BeNil())
package infrastructure_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-agent/infrastructure" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("DigDNSResolver", func() { var ( resolver DigDNSResolver runner *fakesys.FakeCmdRunner ) BeforeEach(func() { logger := boshlog.NewLogger(boshlog.LevelNone) runner = fakesys.NewFakeCmdRunner() resolver = NewDigDNSResolver(runner, logger) }) Describe("LookupHost", func() { Context("when host is an ip", func() { It("lookup host with an ip", func() { ip, err := resolver.LookupHost([]string{"8.8.8.8"}, "74.125.239.101") Expect(err).ToNot(HaveOccurred()) Expect(runner.RunCommands).To(BeEmpty()) Expect(ip).To(Equal("74.125.239.101")) })
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry/bosh-agent/agent/action" boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec" fakeas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec/fakes" boshlog "github.com/cloudfoundry/bosh-utils/logger" boshsys "github.com/cloudfoundry/bosh-utils/system" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" ) var _ = Describe("RunErrand", func() { var ( specService *fakeas.FakeV1Service cmdRunner *fakesys.FakeCmdRunner action RunErrandAction ) BeforeEach(func() { specService = fakeas.NewFakeV1Service() cmdRunner = fakesys.NewFakeCmdRunner() logger := boshlog.NewLogger(boshlog.LevelNone) action = NewRunErrand(specService, "/fake-jobs-dir", cmdRunner, logger) }) It("is asynchronous", func() { Expect(action.IsAsynchronous()).To(BeTrue()) }) It("is not persistent", func() {
bltaction "github.com/cloudfoundry-incubator/bosh-load-tests/action" bltclirunner "github.com/cloudfoundry-incubator/bosh-load-tests/action/clirunner" boshlog "github.com/cloudfoundry/bosh-utils/logger" boshsys "github.com/cloudfoundry/bosh-utils/system" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" . "github.com/cloudfoundry-incubator/bosh-fuzz-tests/deployment" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Deployer", func() { var ( cmdRunner *fakesys.FakeCmdRunner fs *fakesys.FakeFileSystem deployer Deployer ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() cmdRunner = fakesys.NewFakeCmdRunner() directorInfo := bltaction.DirectorInfo{ UUID: "fake-director-uuid", URL: "fake-director-url", } boshCmd := boshsys.Command{Name: "bosh"} fs.ReturnTempFile = fakesys.NewFakeFile("cli-config-path", fs) cliRunner := bltclirunner.NewRunner(boshCmd, cmdRunner, fs)
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_1.foo", "goodbye") fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_2.bar", "goodbye") fakeFs.SetGlob("/path/to/delete/stuff/in/delete_me_*", []string{ "/path/to/delete/stuff/in/delete_me_1.foo", "/path/to/delete/stuff/in/delete_me_2.bar", }) count, err := cert.DeleteFiles(fakeFs, "/path/to/delete/stuff/in/", "delete_me_") Expect(err).To(HaveOccurred()) Expect(count).To(Equal(0)) }) }) Describe("cert.Manager implementations", func() { var ( fakeFs *fakesys.FakeFileSystem fakeCmd *fakesys.FakeCmdRunner certManager cert.Manager ) SharedLinuxCertManagerExamples := func(certBasePath, certUpdateProgram string) { It("writes 1 cert to a file", func() { err := certManager.UpdateCertificates(cert1) Expect(err).NotTo(HaveOccurred()) Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath))).To(BeTrue()) }) It("writes each cert to its own file", func() { certs := fmt.Sprintf("%s\n%s\n", cert1, cert1) err := certManager.UpdateCertificates(certs) Expect(err).NotTo(HaveOccurred())
import ( "encoding/json" "errors" "io/ioutil" . "github.com/cloudfoundry/bosh-init/cloud" boshlog "github.com/cloudfoundry/bosh-utils/logger" fakesys "github.com/cloudfoundry/bosh-utils/system/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("CpiCmdRunner", func() { var ( cpiCmdRunner CPICmdRunner context CmdContext cmdRunner *fakesys.FakeCmdRunner cpi CPI ) BeforeEach(func() { context = CmdContext{ DirectorID: "fake-director-id", } cpi = CPI{ JobPath: "/jobs/cpi", JobsDir: "/jobs", PackagesDir: "/packages", } cmdRunner = fakesys.NewFakeCmdRunner()