func init() { Describe("ReleaseApplySpec", func() { var ( platform *fakeplatform.FakePlatform action ReleaseApplySpecAction ) BeforeEach(func() { platform = fakeplatform.NewFakePlatform() action = NewReleaseApplySpec(platform) }) It("is synchronous", func() { Expect(action.IsAsynchronous()).To(BeFalse()) }) It("is not persistent", func() { Expect(action.IsPersistent()).To(BeFalse()) }) It("run", func() { err := platform.GetFs().WriteFileString("/var/vcap/micro/apply_spec.json", `{"json":["objects"]}`) Expect(err).ToNot(HaveOccurred()) value, err := action.Run() Expect(err).ToNot(HaveOccurred()) Expect(value).To(Equal(map[string]interface{}{"json": []interface{}{"objects"}})) }) }) }
func init() { Describe("concreteFactory", func() { var ( settings *fakesettings.FakeSettingsService platform *fakeplatform.FakePlatform infrastructure *fakeinfrastructure.FakeInfrastructure blobstore *fakeblobstore.FakeBlobstore taskService *faketask.FakeService notifier *fakenotif.FakeNotifier applier *fakeappl.FakeApplier compiler *fakecomp.FakeCompiler jobSupervisor *fakejobsuper.FakeJobSupervisor specService *fakeas.FakeV1Service drainScriptProvider boshdrain.DrainScriptProvider factory Factory logger boshlog.Logger ) BeforeEach(func() { settings = &fakesettings.FakeSettingsService{} platform = fakeplatform.NewFakePlatform() infrastructure = fakeinfrastructure.NewFakeInfrastructure() blobstore = &fakeblobstore.FakeBlobstore{} taskService = &faketask.FakeService{} notifier = fakenotif.NewFakeNotifier() applier = fakeappl.NewFakeApplier() compiler = fakecomp.NewFakeCompiler() jobSupervisor = fakejobsuper.NewFakeJobSupervisor() specService = fakeas.NewFakeV1Service() drainScriptProvider = boshdrain.NewConcreteDrainScriptProvider(nil, nil, platform.GetDirProvider()) logger = boshlog.NewLogger(boshlog.LEVEL_NONE) }) JustBeforeEach(func() { factory = NewFactory( settings, platform, infrastructure, blobstore, taskService, notifier, applier, compiler, jobSupervisor, specService, drainScriptProvider, logger, ) }) It("new factory", func() { actions := []string{ "apply", "drain", "fetch_logs", "get_task", "get_state", "list_disk", "migrate_disk", "mount_disk", "ping", "prepare_network_change", "ssh", "start", "stop", "unmount_disk", "compile_package", "release_apply_spec", } for _, actionName := range actions { action, err := factory.Create(actionName) Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) } action, err := factory.Create("gobberish") Expect(err).To(HaveOccurred()) Expect(action).To(BeNil()) }) It("apply", func() { action, err := factory.Create("apply") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewApply(applier, specService)).To(Equal(action)) }) It("drain", func() { action, err := factory.Create("drain") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewDrain(notifier, specService, drainScriptProvider, jobSupervisor)).To(Equal(action)) }) It("fetch_logs", func() { action, err := factory.Create("fetch_logs") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewLogs(platform.GetCompressor(), platform.GetCopier(), blobstore, platform.GetDirProvider())).To(Equal(action)) }) It("get_task", func() { action, err := factory.Create("get_task") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewGetTask(taskService)).To(Equal(action)) }) It("get_state", func() { ntpService := boshntp.NewConcreteService(platform.GetFs(), platform.GetDirProvider()) action, err := factory.Create("get_state") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewGetState(settings, specService, jobSupervisor, platform.GetVitalsService(), ntpService)).To(Equal(action)) }) It("list_disk", func() { action, err := factory.Create("list_disk") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewListDisk(settings, platform, logger)).To(Equal(action)) }) It("migrate_disk", func() { action, err := factory.Create("migrate_disk") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewMigrateDisk(platform, platform.GetDirProvider())).To(Equal(action)) }) It("mount_disk", func() { action, err := factory.Create("mount_disk") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewMountDisk(settings, infrastructure, platform, platform.GetDirProvider())).To(Equal(action)) }) It("prepare_network_change", func() { action, err := factory.Create("prepare_network_change") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewPrepareNetworkChange(platform.GetFs(), settings)).To(Equal(action)) }) It("prepare_configure_networks", func() { action, err := factory.Create("prepare_configure_networks") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewPrepareConfigureNetworks(platform.GetFs(), settings)).To(Equal(action)) }) It("configure_networks", func() { action, err := factory.Create("configure_networks") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewConfigureNetworks()).To(Equal(action)) }) It("ssh", func() { action, err := factory.Create("ssh") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewSsh(settings, platform, platform.GetDirProvider())).To(Equal(action)) }) It("start", func() { action, err := factory.Create("start") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewStart(jobSupervisor)).To(Equal(action)) }) It("unmount_disk", func() { action, err := factory.Create("unmount_disk") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewUnmountDisk(settings, platform)).To(Equal(action)) }) It("compile_package", func() { action, err := factory.Create("compile_package") Expect(err).NotTo(HaveOccurred()) Expect(action).ToNot(BeNil()) Expect(NewCompilePackage(compiler)).To(Equal(action)) }) }) }
logger = boshlog.NewLogger(boshlog.LevelNone) provider = NewProvider(logger, platform) }) Describe("Get", func() { It("returns aws infrastructure", func() { metadataService := NewConcreteMetadataService( "http://169.254.169.254", NewDigDNSResolver(logger), ) registry := NewConcreteRegistry(metadataService, false) expectedDevicePathResolver := boshdpresolv.NewMappedDevicePathResolver( 500*time.Millisecond, platform.GetFs(), ) expectedInf := NewAwsInfrastructure( metadataService, registry, platform, expectedDevicePathResolver, logger, ) inf, err := provider.Get("aws") Expect(err).ToNot(HaveOccurred()) Expect(inf).To(Equal(expectedInf)) })
}) Describe("Get", func() { It("returns nats handler", func() { settingsService.Settings.Mbus = "nats://lol" handler, err := provider.Get(platform, dirProvider) Expect(err).ToNot(HaveOccurred()) // yagnats.NewClient returns new object every time expectedHandler := NewNatsHandler(settingsService, yagnats.NewClient(), logger) Expect(reflect.TypeOf(handler)).To(Equal(reflect.TypeOf(expectedHandler))) }) It("returns https handler", func() { url, err := gourl.Parse("https://lol") Expect(err).ToNot(HaveOccurred()) settingsService.Settings.Mbus = "https://lol" handler, err := provider.Get(platform, dirProvider) Expect(err).ToNot(HaveOccurred()) Expect(handler).To(Equal(micro.NewHTTPSHandler(url, logger, platform.GetFs(), dirProvider))) }) It("returns an error if not supported", func() { settingsService.Settings.Mbus = "unknown-scheme://lol" _, err := provider.Get(platform, dirProvider) Expect(err).To(HaveOccurred()) }) }) })
func init() { Describe("bootstrap", func() { Describe("Run", func() { var ( inf *fakeinf.FakeInfrastructure platform *fakeplatform.FakePlatform dirProvider boshdir.DirectoriesProvider settingsServiceProvider *fakesettings.FakeSettingsServiceProvider settingsService *fakesettings.FakeSettingsService ) BeforeEach(func() { inf = &fakeinf.FakeInfrastructure{ GetEphemeralDiskPathFound: true, GetEphemeralDiskPathRealPath: "/dev/sdz", } platform = fakeplatform.NewFakePlatform() dirProvider = boshdir.NewDirectoriesProvider("/var/vcap") settingsServiceProvider = fakesettings.NewServiceProvider() settingsService = settingsServiceProvider.NewServiceSettingsService }) bootstrap := func() (boshsettings.Service, error) { logger := boshlog.NewLogger(boshlog.LevelNone) return New(inf, platform, dirProvider, settingsServiceProvider, logger).Run() } It("sets up runtime configuration", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupRuntimeConfigurationWasInvoked).To(BeTrue()) }) It("sets up ssh", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(inf.SetupSshUsername).To(Equal("vcap")) }) It("sets up hostname", func() { settingsService.Settings.AgentID = "foo-bar-baz-123" _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupHostnameHostname).To(Equal("foo-bar-baz-123")) }) It("returns the settings service", func() { settingsService, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(settingsService).To(Equal(settingsService)) Expect(settingsServiceProvider.NewServiceFs).To(Equal(platform.GetFs())) Expect(settingsServiceProvider.NewServiceDir).To(Equal(dirProvider.BoshDir())) fetchedSettings, err := settingsServiceProvider.NewServiceFetcher() Expect(err).NotTo(HaveOccurred()) Expect(fetchedSettings).To(Equal(inf.Settings)) }) It("fetches initial settings", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(settingsService.SettingsWereLoaded).To(BeTrue()) }) It("returns error from loading initial settings", func() { settingsService.LoadSettingsError = errors.New("fake-load-error") _, err := bootstrap() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fake-load-error")) }) It("sets up networking", func() { networks := boshsettings.Networks{ "bosh": boshsettings.Network{}, } settingsService.Settings.Networks = networks _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(inf.SetupNetworkingNetworks).To(Equal(networks)) }) It("sets up ephemeral disk", func() { settingsService.Disks = boshsettings.Disks{ Ephemeral: "fake-ephemeral-disk-setting", } inf.GetEphemeralDiskPathRealPath = "/dev/sda" inf.GetEphemeralDiskPathFound = true _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupEphemeralDiskWithPathDevicePath).To(Equal("/dev/sda")) Expect(inf.GetEphemeralDiskPathDevicePath).To(Equal("fake-ephemeral-disk-setting")) }) It("returns error if setting ephemeral disk fails", func() { platform.SetupEphemeralDiskWithPathErr = errors.New("fake-setup-ephemeral-disk-err") _, err := bootstrap() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fake-setup-ephemeral-disk-err")) }) It("sets up data dir", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupDataDirCalled).To(BeTrue()) }) It("returns error if set up of data dir fails", func() { platform.SetupDataDirErr = errors.New("fake-setup-data-dir-err") _, err := bootstrap() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fake-setup-data-dir-err")) }) It("sets up tmp dir", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupTmpDirCalled).To(BeTrue()) }) It("returns error if set up of tmp dir fails", func() { platform.SetupTmpDirErr = errors.New("fake-setup-tmp-dir-err") _, err := bootstrap() Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("fake-setup-tmp-dir-err")) }) It("mounts persistent disk", func() { settingsService.Disks = boshsettings.Disks{ Persistent: map[string]string{"vol-123": "/dev/sdb"}, } _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.MountPersistentDiskDevicePath).To(Equal("/dev/sdb")) Expect(platform.MountPersistentDiskMountPoint).To(Equal(dirProvider.StoreDir())) }) It("errors if there is more than one persistent disk", func() { settingsService.Disks = boshsettings.Disks{ Persistent: map[string]string{ "vol-123": "/dev/sdb", "vol-456": "/dev/sdc", }, } _, err := bootstrap() Expect(err).To(HaveOccurred()) }) It("does not try to mount when no persistent disk", func() { settingsService.Disks = boshsettings.Disks{ Persistent: map[string]string{}, } _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.MountPersistentDiskDevicePath).To(Equal("")) Expect(platform.MountPersistentDiskMountPoint).To(Equal("")) }) It("sets root and vcap passwords", func() { settingsService.Settings.Env.Bosh.Password = "******" _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(2).To(Equal(len(platform.UserPasswords))) Expect("some-encrypted-password").To(Equal(platform.UserPasswords["root"])) Expect("some-encrypted-password").To(Equal(platform.UserPasswords["vcap"])) }) It("does not set password if not provided", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(0).To(Equal(len(platform.UserPasswords))) }) It("sets ntp", func() { settingsService.Settings.Ntp = []string{ "0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org", } _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(2).To(Equal(len(platform.SetTimeWithNtpServersServers))) Expect("0.north-america.pool.ntp.org").To(Equal(platform.SetTimeWithNtpServersServers[0])) Expect("1.north-america.pool.ntp.org").To(Equal(platform.SetTimeWithNtpServersServers[1])) }) It("setups up monit user", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupMonitUserSetup).To(BeTrue()) }) It("starts monit", func() { _, err := bootstrap() Expect(err).NotTo(HaveOccurred()) Expect(platform.StartMonitStarted).To(BeTrue()) }) }) }) }
func init() { Describe("vSphere Infrastructure", func() { var ( logger boshlog.Logger vsphere Infrastructure platform *fakeplatform.FakePlatform fakeDevicePathResolver *fakedpresolv.FakeDevicePathResolver ) BeforeEach(func() { platform = fakeplatform.NewFakePlatform() fakeDevicePathResolver = fakedpresolv.NewFakeDevicePathResolver(1*time.Millisecond, platform.GetFs()) logger = boshlog.NewLogger(boshlog.LevelNone) }) JustBeforeEach(func() { vsphere = NewVsphereInfrastructure(platform, fakeDevicePathResolver, logger) }) Describe("GetSettings", func() { It("vsphere get settings", func() { platform.GetFileContentsFromCDROMContents = []byte(`{"agent_id": "123"}`) settings, err := vsphere.GetSettings() Expect(err).NotTo(HaveOccurred()) Expect(platform.GetFileContentsFromCDROMPath).To(Equal("env")) Expect(settings.AgentID).To(Equal("123")) }) }) Describe("SetupNetworking", func() { It("vsphere setup networking", func() { networks := boshsettings.Networks{"bosh": boshsettings.Network{}} vsphere.SetupNetworking(networks) Expect(platform.SetupManualNetworkingNetworks).To(Equal(networks)) }) }) Describe("GetEphemeralDiskPath", func() { It("vsphere get ephemeral disk path", func() { realPath, found := vsphere.GetEphemeralDiskPath("does not matter") Expect(found).To(Equal(true)) Expect(realPath).To(Equal("/dev/sdb")) }) }) Describe("MountPersistentDisk", func() { BeforeEach(func() { fakeDevicePathResolver.RealDevicePath = "fake-real-device-path" }) It("creates the mount directory with the correct permissions", func() { vsphere.MountPersistentDisk("fake-volume-id", "/mnt/point") mountPoint := platform.Fs.GetFileTestStat("/mnt/point") Expect(mountPoint.FileType).To(Equal(fakesys.FakeFileTypeDir)) Expect(mountPoint.FileMode).To(Equal(os.FileMode(0700))) }) It("partitions the disk", func() { vsphere.MountPersistentDisk("fake-volume-id", "/mnt/point") Expect(platform.FakeDiskManager.FakePartitioner.PartitionDevicePath).To(Equal("fake-real-device-path")) partitions := []boshdisk.Partition{ {Type: boshdisk.PartitionTypeLinux}, } Expect(platform.FakeDiskManager.FakePartitioner.PartitionPartitions).To(Equal(partitions)) }) It("formats the disk", func() { vsphere.MountPersistentDisk("fake-volume-id", "/mnt/point") Expect(platform.FakeDiskManager.FakeFormatter.FormatPartitionPaths).To(Equal([]string{"fake-real-device-path1"})) Expect(platform.FakeDiskManager.FakeFormatter.FormatFsTypes).To(Equal([]boshdisk.FileSystemType{boshdisk.FileSystemExt4})) }) It("mounts the disk", func() { vsphere.MountPersistentDisk("fake-volume-id", "/mnt/point") Expect(platform.FakeDiskManager.FakeMounter.MountPartitionPaths).To(Equal([]string{"fake-real-device-path1"})) Expect(platform.FakeDiskManager.FakeMounter.MountMountPoints).To(Equal([]string{"/mnt/point"})) }) }) }) }
}) It("get_task", func() { action, err := factory.Create("get_task") Expect(err).ToNot(HaveOccurred()) Expect(action).To(Equal(NewGetTask(taskService))) }) It("cancel_task", func() { action, err := factory.Create("cancel_task") Expect(err).ToNot(HaveOccurred()) Expect(action).To(Equal(NewCancelTask(taskService))) }) It("get_state", func() { ntpService := boshntp.NewConcreteService(platform.GetFs(), platform.GetDirProvider()) action, err := factory.Create("get_state") Expect(err).ToNot(HaveOccurred()) Expect(action).To(Equal(NewGetState(settingsService, specService, jobSupervisor, platform.GetVitalsService(), ntpService))) }) It("list_disk", func() { action, err := factory.Create("list_disk") Expect(err).ToNot(HaveOccurred()) Expect(action).To(Equal(NewListDisk(settingsService, platform, logger))) }) It("migrate_disk", func() { action, err := factory.Create("migrate_disk") Expect(err).ToNot(HaveOccurred()) Expect(action).To(Equal(NewMigrateDisk(platform, platform.GetDirProvider())))
func init() { var ( platform *fakeplatform.FakePlatform fakeDevicePathResolver *fakedpresolv.FakeDevicePathResolver ) BeforeEach(func() { platform = fakeplatform.NewFakePlatform() fakeDevicePathResolver = fakedpresolv.NewFakeDevicePathResolver( 1*time.Millisecond, platform.GetFs(), ) }) Describe("AWS Infrastructure", func() { Describe("SetupSsh", func() { var ( ts *httptest.Server aws Infrastructure ) const expectedKey = "some public key" BeforeEach(func() { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Expect(r.Method).To(Equal("GET")) Expect(r.URL.Path).To(Equal("/latest/meta-data/public-keys/0/openssh-key")) w.Write([]byte(expectedKey)) }) ts = httptest.NewServer(handler) }) AfterEach(func() { ts.Close() }) It("gets the public key and sets up ssh via the platform", func() { aws = NewAwsInfrastructure(ts.URL, &FakeDNSResolver{}, platform, fakeDevicePathResolver) err := aws.SetupSsh("vcap") Expect(err).NotTo(HaveOccurred()) Expect(platform.SetupSshPublicKey).To(Equal(expectedKey)) Expect(platform.SetupSshUsername).To(Equal("vcap")) }) }) Describe("GetSettings", func() { var ( settingsJSON string expectedSettings boshsettings.Settings ) BeforeEach(func() { settingsJSON = `{ "agent_id": "my-agent-id", "blobstore": { "options": { "bucket_name": "george", "encryption_key": "optional encryption key", "access_key_id": "optional access key id", "secret_access_key": "optional secret access key" }, "provider": "s3" }, "disks": { "ephemeral": "/dev/sdb", "persistent": { "vol-xxxxxx": "/dev/sdf" }, "system": "/dev/sda1" }, "env": { "bosh": { "password": "******" } }, "networks": { "netA": { "default": ["dns", "gateway"], "ip": "ww.ww.ww.ww", "dns": [ "xx.xx.xx.xx", "yy.yy.yy.yy" ] }, "netB": { "dns": [ "zz.zz.zz.zz" ] } }, "mbus": "https://*****:*****@0.0.0.0:6868", "ntp": [ "0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org" ], "vm": { "name": "vm-abc-def" } }` settingsJSON = strings.Replace(settingsJSON, `"`, `\"`, -1) settingsJSON = strings.Replace(settingsJSON, "\n", "", -1) settingsJSON = strings.Replace(settingsJSON, "\t", "", -1) settingsJSON = fmt.Sprintf(`{"settings": "%s"}`, settingsJSON) expectedSettings = boshsettings.Settings{ AgentID: "my-agent-id", Blobstore: boshsettings.Blobstore{ Options: map[string]string{ "bucket_name": "george", "encryption_key": "optional encryption key", "access_key_id": "optional access key id", "secret_access_key": "optional secret access key", }, Type: "s3", }, Disks: boshsettings.Disks{ Ephemeral: "/dev/sdb", Persistent: map[string]string{"vol-xxxxxx": "/dev/sdf"}, System: "/dev/sda1", }, Env: boshsettings.Env{ Bosh: boshsettings.BoshEnv{ Password: "******", }, }, Networks: boshsettings.Networks{ "netA": boshsettings.Network{ Default: []string{"dns", "gateway"}, IP: "ww.ww.ww.ww", DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy"}, }, "netB": boshsettings.Network{ DNS: []string{"zz.zz.zz.zz"}, }, }, Mbus: "https://*****:*****@0.0.0.0:6868", Ntp: []string{ "0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org", }, VM: boshsettings.VM{ Name: "vm-abc-def", }, } }) Context("when a dns is not provided", func() { It("aws get settings", func() { boshRegistryHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Expect(r.Method).To(Equal("GET")) Expect(r.URL.Path).To(Equal("/instances/123-456-789/settings")) w.Write([]byte(settingsJSON)) }) registryTs := httptest.NewServer(boshRegistryHandler) defer registryTs.Close() expectedUserData := fmt.Sprintf(`{"registry":{"endpoint":"%s"}}`, registryTs.URL) instanceID := "123-456-789" awsMetaDataHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Expect(r.Method).To(Equal("GET")) switch r.URL.Path { case "/latest/user-data": w.Write([]byte(expectedUserData)) case "/latest/meta-data/instance-id": w.Write([]byte(instanceID)) } }) metadataTs := httptest.NewServer(awsMetaDataHandler) defer metadataTs.Close() platform := fakeplatform.NewFakePlatform() aws := NewAwsInfrastructure(metadataTs.URL, &FakeDNSResolver{}, platform, fakeDevicePathResolver) settings, err := aws.GetSettings() Expect(err).NotTo(HaveOccurred()) Expect(settings).To(Equal(expectedSettings)) }) }) Context("when dns servers are provided", func() { It("aws get settings", func() { fakeDNSResolver := &FakeDNSResolver{ LookupHostIP: "127.0.0.1", } registryHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Expect(r.Method).To(Equal("GET")) Expect(r.URL.Path).To(Equal("/instances/123-456-789/settings")) w.Write([]byte(settingsJSON)) }) registryTs := httptest.NewServer(registryHandler) registryURL, err := url.Parse(registryTs.URL) Expect(err).NotTo(HaveOccurred()) registryTsPort := strings.Split(registryURL.Host, ":")[1] defer registryTs.Close() expectedUserData := fmt.Sprintf(` { "registry":{ "endpoint":"http://the.registry.name:%s" }, "dns":{ "nameserver": ["8.8.8.8", "9.9.9.9"] } }`, registryTsPort) instanceID := "123-456-789" awsMetaDataHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Expect(r.Method).To(Equal("GET")) switch r.URL.Path { case "/latest/user-data": w.Write([]byte(expectedUserData)) case "/latest/meta-data/instance-id": w.Write([]byte(instanceID)) } }) metadataTs := httptest.NewServer(awsMetaDataHandler) defer metadataTs.Close() platform := fakeplatform.NewFakePlatform() aws := NewAwsInfrastructure(metadataTs.URL, fakeDNSResolver, platform, fakeDevicePathResolver) settings, err := aws.GetSettings() Expect(err).NotTo(HaveOccurred()) Expect(settings).To(Equal(expectedSettings)) Expect(fakeDNSResolver.LookupHostHost).To(Equal("the.registry.name")) Expect(fakeDNSResolver.LookupHostDNSServers).To(Equal([]string{"8.8.8.8", "9.9.9.9"})) }) }) }) Describe("SetupNetworking", func() { It("sets up DHCP on the platform", func() { fakeDNSResolver := &FakeDNSResolver{} platform := fakeplatform.NewFakePlatform() aws := NewAwsInfrastructure("", fakeDNSResolver, platform, fakeDevicePathResolver) networks := boshsettings.Networks{"bosh": boshsettings.Network{}} aws.SetupNetworking(networks) Expect(platform.SetupDhcpNetworks).To(Equal(networks)) }) }) Describe("GetEphemeralDiskPath", func() { It("returns the real disk path given an AWS EBS hint", func() { fakeDNSResolver := &FakeDNSResolver{} platform := fakeplatform.NewFakePlatform() aws := NewAwsInfrastructure("", fakeDNSResolver, platform, fakeDevicePathResolver) platform.NormalizeDiskPathRealPath = "/dev/xvdb" platform.NormalizeDiskPathFound = true realPath, found := aws.GetEphemeralDiskPath("/dev/sdb") Expect(found).To(Equal(true)) Expect(realPath).To(Equal("/dev/xvdb")) Expect(platform.NormalizeDiskPathPath).To(Equal("/dev/sdb")) }) }) Describe("MountPersistentDisk", func() { It("mounts the persistent disk", func() { fakePlatform := fakeplatform.NewFakePlatform() fakeFormatter := fakePlatform.FakeDiskManager.FakeFormatter fakePartitioner := fakePlatform.FakeDiskManager.FakePartitioner fakeMounter := fakePlatform.FakeDiskManager.FakeMounter fakePlatform.GetFs().WriteFile("/dev/vdf", []byte{}) fakeDNSResolver := &FakeDNSResolver{} aws := NewAwsInfrastructure("", fakeDNSResolver, fakePlatform, fakeDevicePathResolver) fakeDevicePathResolver.RealDevicePath = "/dev/vdf" err := aws.MountPersistentDisk("/dev/sdf", "/mnt/point") Expect(err).NotTo(HaveOccurred()) mountPoint := fakePlatform.Fs.GetFileTestStat("/mnt/point") Expect(mountPoint.FileType).To(Equal(fakesys.FakeFileTypeDir)) Expect(mountPoint.FileMode).To(Equal(os.FileMode(0700))) partition := fakePartitioner.PartitionPartitions[0] Expect(fakePartitioner.PartitionDevicePath).To(Equal("/dev/vdf")) Expect(len(fakePartitioner.PartitionPartitions)).To(Equal(1)) Expect(partition.Type).To(Equal(boshdisk.PartitionTypeLinux)) Expect(len(fakeFormatter.FormatPartitionPaths)).To(Equal(1)) Expect(fakeFormatter.FormatPartitionPaths[0]).To(Equal("/dev/vdf1")) Expect(len(fakeFormatter.FormatFsTypes)).To(Equal(1)) Expect(fakeFormatter.FormatFsTypes[0]).To(Equal(boshdisk.FileSystemExt4)) Expect(len(fakeMounter.MountMountPoints)).To(Equal(1)) Expect(fakeMounter.MountMountPoints[0]).To(Equal("/mnt/point")) Expect(len(fakeMounter.MountPartitionPaths)).To(Equal(1)) Expect(fakeMounter.MountPartitionPaths[0]).To(Equal("/dev/vdf1")) }) }) }) }
}) It("get external when external command in path", func() { options := map[string]interface{}{ "key": "value", } platform.Runner.CommandExistsValue = true blobstore, err := provider.Get(boshsettings.Blobstore{ Type: "fake-external-type", Options: options, }) Expect(err).ToNot(HaveOccurred()) expectedExternalConfigPath := "/var/vcap/bosh/etc/blobstore-fake-external-type.json" expectedBlobstore := NewExternalBlobstore("fake-external-type", options, platform.GetFs(), platform.GetRunner(), boshuuid.NewGenerator(), expectedExternalConfigPath) expectedBlobstore = NewSha1Verifiable(expectedBlobstore) err = expectedBlobstore.Validate() Expect(err).ToNot(HaveOccurred()) Expect(blobstore).To(Equal(expectedBlobstore)) }) It("get external errs when external command not in path", func() { options := map[string]interface{}{ "key": "value", } platform.Runner.CommandExistsValue = false _, err := provider.Get(boshsettings.Blobstore{ Type: "fake-external-type",