Пример #1
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("list disk should be synchronous", func() {

			settings := &fakesettings.FakeSettingsService{}
			platform := fakeplatform.NewFakePlatform()
			action := NewListDisk(settings, platform)
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("list disk run", func() {

			settings := &fakesettings.FakeSettingsService{
				Disks: boshsettings.Disks{
					Persistent: map[string]string{
						"volume-1": "/dev/sda",
						"volume-2": "/dev/sdb",
						"volume-3": "/dev/sdc",
					},
				},
			}
			platform := fakeplatform.NewFakePlatform()
			platform.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}

			action := NewListDisk(settings, platform)
			value, err := action.Run()
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), value, `["volume-2","volume-3"]`)
		})
	})
}
Пример #2
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("unmount disk should be asynchronous", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

		It("is not persistent", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("unmount disk when the disk is mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = true

			unmountDisk := buildUnmountDiskAction(platform)

			result, err := unmountDisk.Run("vol-123")
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, `{"message":"Unmounted partition of /dev/sdf"}`)

			Expect(platform.UnmountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
		})
		It("unmount disk when the disk is not mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = false

			mountDisk := buildUnmountDiskAction(platform)

			result, err := mountDisk.Run("vol-123")
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, `{"message":"Partition of /dev/sdf is not mounted"}`)

			Expect(platform.UnmountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
		})
		It("unmount disk when device path not found", func() {

			platform := fakeplatform.NewFakePlatform()
			mountDisk := buildUnmountDiskAction(platform)

			_, err := mountDisk.Run("vol-456")
			Expect(err).To(HaveOccurred())
		})
	})
}
Пример #3
0
func buildPrepareAction() (action PrepareNetworkChangeAction, fs boshsys.FileSystem) {
	platform := fakeplatform.NewFakePlatform()
	fs = platform.GetFs()
	action = NewPrepareNetworkChange(platform)

	return
}
Пример #4
0
func buildMigrateDiskAction() (platform *fakeplatform.FakePlatform, action migrateDiskAction) {
	platform = fakeplatform.NewFakePlatform()
	settings := &fakesettings.FakeSettingsService{}
	dirProvider := boshdirs.NewDirectoriesProvider("/foo")
	action = newMigrateDisk(settings, platform, dirProvider)
	return
}
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"}}))
		})
	})
}
Пример #6
0
func buildApplyAction() (*fakeappl.FakeApplier, *fakesys.FakeFileSystem, *fakeplatform.FakePlatform, applyAction) {
	applier := fakeappl.NewFakeApplier()
	platform := fakeplatform.NewFakePlatform()
	fs := platform.Fs
	action := newApply(applier, fs, platform)
	return applier, fs, platform, action
}
func TestHandlerProviderGetReturnsConcreteProvider(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	blobstore := fakeblob.NewFakeBlobstore()
	jobSupervisor := fakejobsuper.NewFakeJobSupervisor()

	expectedPackageApplier := pa.NewConcretePackageApplier(
		bc.NewFileBundleCollection("/fake-base-dir/data", "/fake-base-dir", "packages", platform.GetFs()),
		blobstore,
		platform.GetCompressor(),
	)

	expectedJobApplier := ja.NewRenderedJobApplier(
		bc.NewFileBundleCollection("/fake-base-dir/data", "/fake-base-dir", "jobs", platform.GetFs()),
		blobstore,
		platform.GetCompressor(),
		jobSupervisor,
	)
	dirProvider := boshdirs.NewDirectoriesProvider("/fake-base-dir")
	expectedApplier := NewConcreteApplier(
		expectedJobApplier,
		expectedPackageApplier,
		platform,
		jobSupervisor,
		dirProvider,
	)

	provider := NewApplierProvider(platform, blobstore, jobSupervisor, dirProvider)
	applier := provider.Get()
	assert.Equal(t, expectedApplier, applier)
}
Пример #8
0
func TestAwsGetSettingsWhenDnsServersAreProvided(t *testing.T) {
	fakeDnsResolver := &FakeDnsResolver{
		LookupHostIp: "127.0.0.1",
	}

	registryTs, registryTsPort, expectedSettings := spinUpAwsRegistry(t)
	defer registryTs.Close()

	expectedUserData := fmt.Sprintf(`
		{
			"registry":{
				"endpoint":"http://the.registry.name:%s"
			},
			"dns":{
				"nameserver": ["8.8.8.8", "9.9.9.9"]
			}
		}`,
		registryTsPort)

	metadataTs := spinUpAwsMetadataServer(t, expectedUserData)
	defer metadataTs.Close()

	platform := fakeplatform.NewFakePlatform()

	aws := NewAwsInfrastructure(metadataTs.URL, fakeDnsResolver, platform)

	settings, err := aws.GetSettings()
	assert.NoError(t, err)
	assert.Equal(t, settings, expectedSettings)
	assert.Equal(t, fakeDnsResolver.LookupHostHost, "the.registry.name")
	assert.Equal(t, fakeDnsResolver.LookupHostDnsServers, []string{"8.8.8.8", "9.9.9.9"})
}
Пример #9
0
func getFakeFactoryDependencies() (settings boshsettings.Settings, fs *fakesys.FakeFileSystem, platform *fakeplatform.FakePlatform, taskService *faketask.FakeService) {
	settings = boshsettings.Settings{}
	fs = &fakesys.FakeFileSystem{}
	platform = fakeplatform.NewFakePlatform()
	taskService = &faketask.FakeService{}
	return
}
func buildFactory() (
	deps concreteFactoryDependencies,
	factory Factory) {

	deps.settings = &fakesettings.FakeSettingsService{}
	deps.platform = fakeplatform.NewFakePlatform()
	deps.blobstore = &fakeblobstore.FakeBlobstore{}
	deps.taskService = &faketask.FakeService{}
	deps.notifier = fakenotif.NewFakeNotifier()
	deps.applier = fakeappl.NewFakeApplier()
	deps.compiler = fakecomp.NewFakeCompiler()
	deps.jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
	deps.specService = fakeas.NewFakeV1Service()
	deps.drainScriptProvider = boshdrain.NewConcreteDrainScriptProvider(nil, nil, deps.platform.GetDirProvider())

	factory = NewFactory(
		deps.settings,
		deps.platform,
		deps.blobstore,
		deps.taskService,
		deps.notifier,
		deps.applier,
		deps.compiler,
		deps.jobSupervisor,
		deps.specService,
		deps.drainScriptProvider,
	)
	return
}
Пример #11
0
func buildFactory() (
	deps concreteFactoryDependencies,
	factory Factory) {

	deps.settings = &fakesettings.FakeSettingsService{}
	deps.platform = fakeplatform.NewFakePlatform()
	deps.blobstore = &fakeblobstore.FakeBlobstore{}
	deps.taskService = &faketask.FakeService{}
	deps.notifier = fakenotif.NewFakeNotifier()
	deps.applier = fakeappl.NewFakeApplier()
	deps.compiler = fakecomp.NewFakeCompiler()
	deps.monitor = fakemon.NewFakeMonitor()
	deps.specService = fakeas.NewFakeV1Service()
	deps.dirProvider = boshdirs.NewDirectoriesProvider("/foo")
	deps.drainScriptProvider = boshdrain.NewDrainScriptProvider(nil, nil, deps.dirProvider)

	factory = NewFactory(
		deps.settings,
		deps.platform,
		deps.blobstore,
		deps.taskService,
		deps.notifier,
		deps.applier,
		deps.compiler,
		deps.monitor,
		deps.specService,
		deps.dirProvider,
		deps.drainScriptProvider,
	)
	return
}
Пример #12
0
func TestUnmountDiskWhenDevicePathNotFound(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	mountDisk := buildUnmountDiskAction(platform)

	_, err := mountDisk.Run("vol-456")
	assert.Error(t, err)
}
Пример #13
0
func getBootstrapDependencies() (inf *fakeinf.FakeInfrastructure, platform *fakeplatform.FakePlatform, dirProvider boshdir.DirectoriesProvider) {
	inf = &fakeinf.FakeInfrastructure{}
	inf.GetEphemeralDiskPathFound = true
	inf.GetEphemeralDiskPathRealPath = "/dev/sdz"
	platform = fakeplatform.NewFakePlatform()
	dirProvider = boshdir.NewDirectoriesProvider("/var/vcap")
	return
}
Пример #14
0
func init() {
	Describe("dummyInfrastructure", func() {
		It("get settings", func() {
			fs := fakefs.NewFakeFileSystem()
			dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
			platform := fakeplatform.NewFakePlatform()
			fakeDevicePathResolver := fakedpresolv.NewFakeDevicePathResolver(1*time.Millisecond, platform.GetFs())

			settingsPath := filepath.Join(dirProvider.BoshDir(), "dummy-cpi-agent-env.json")

			expectedSettings := boshsettings.Settings{
				AgentID: "123-456-789",
				Blobstore: boshsettings.Blobstore{
					Type: boshsettings.BlobstoreTypeDummy,
				},
				Mbus: "nats://127.0.0.1:4222",
			}
			existingSettingsBytes, _ := json.Marshal(expectedSettings)
			fs.WriteFile(settingsPath, existingSettingsBytes)

			dummy := NewDummyInfrastructure(fs, dirProvider, platform, fakeDevicePathResolver)

			settings, err := dummy.GetSettings()
			Expect(err).ToNot(HaveOccurred())
			assert.Equal(GinkgoT(), settings, boshsettings.Settings{
				AgentID:   "123-456-789",
				Blobstore: boshsettings.Blobstore{Type: boshsettings.BlobstoreTypeDummy},
				Mbus:      "nats://127.0.0.1:4222",
			})
		})

		It("get settings errs when settings file does not exist", func() {
			fs := fakefs.NewFakeFileSystem()
			dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
			platform := fakeplatform.NewFakePlatform()
			fakeDevicePathResolver := fakedpresolv.NewFakeDevicePathResolver(1*time.Millisecond, platform.GetFs())

			dummy := NewDummyInfrastructure(fs, dirProvider, platform, fakeDevicePathResolver)

			_, err := dummy.GetSettings()
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("Read settings file"))
		})
	})
}
Пример #15
0
func TestUnmountDiskWhenDevicePathNotFound(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	mountDisk := buildUnmountDiskAction(platform)

	payload := `{"arguments":["vol-456"]}`

	_, err := mountDisk.Run([]byte(payload))
	assert.Error(t, err)
}
Пример #16
0
func TestUnmountDiskWithMissingVolumeId(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	unmountDisk := buildUnmountDiskAction(platform)

	payload := `{"arguments":[]}`

	_, err := unmountDisk.Run([]byte(payload))
	assert.Error(t, err)
}
Пример #17
0
func buildProvider(mbusUrl string) (deps providerDeps, provider MbusHandlerProvider) {
	deps.settings = &fakesettings.FakeSettingsService{MbusUrl: mbusUrl}
	deps.logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
	provider = NewHandlerProvider(deps.settings, deps.logger)

	deps.platform = fakeplatform.NewFakePlatform()
	deps.dirProvider = boshdir.NewDirectoriesProvider("/var/vcap")
	return
}
func buildProvider(mbusUrl string) (provider mbusHandlerProvider, platform *fakeplatform.FakePlatform, dirProvider boshdir.DirectoriesProvider) {
	settings := &fakesettings.FakeSettingsService{MbusUrl: mbusUrl}
	logger := boshlog.NewLogger(boshlog.LEVEL_NONE)
	provider = NewHandlerProvider(settings, logger)

	platform = fakeplatform.NewFakePlatform()
	dirProvider = boshdir.NewDirectoriesProvider("/var/vcap")
	return
}
Пример #19
0
func TestAwsSetupNetworking(t *testing.T) {
	fakeDnsResolver := &FakeDnsResolver{}
	platform := fakeplatform.NewFakePlatform()
	aws := NewAwsInfrastructure("", fakeDnsResolver, platform)
	networks := boshsettings.Networks{"bosh": boshsettings.Network{}}

	aws.SetupNetworking(networks)

	assert.Equal(t, platform.SetupDhcpNetworks, networks)
}
Пример #20
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("unmount disk should be asynchronous", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("unmount disk when the disk is mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = true

			unmountDisk := buildUnmountDiskAction(platform)

			result, err := unmountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, `{"message":"Unmounted partition of /dev/sdf"}`)

			assert.Equal(GinkgoT(), platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
		})
		It("unmount disk when the disk is not mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = false

			mountDisk := buildUnmountDiskAction(platform)

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, `{"message":"Partition of /dev/sdf is not mounted"}`)

			assert.Equal(GinkgoT(), platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
		})
		It("unmount disk when device path not found", func() {

			platform := fakeplatform.NewFakePlatform()
			mountDisk := buildUnmountDiskAction(platform)

			_, err := mountDisk.Run("vol-456")
			assert.Error(GinkgoT(), err)
		})
	})
}
Пример #21
0
func TestRun(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	_, err := platform.GetFs().WriteToFile("/var/vcap/micro/apply_spec.json", `{"json":["objects"]}`)
	assert.NoError(t, err)
	action := NewReleaseApplySpec(platform)

	value, err := action.Run()
	assert.NoError(t, err)

	assert.Equal(t, value, map[string]interface{}{"json": []interface{}{"objects"}})
}
Пример #22
0
func TestGetSettingsErrsWhenSettingsFileDoesNotExist(t *testing.T) {
	fs := fakefs.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
	platform := fakeplatform.NewFakePlatform()

	dummy := NewDummyInfrastructure(fs, dirProvider, platform)

	_, err := dummy.GetSettings()
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "Read settings file")
}
Пример #23
0
func TestUnmountDiskWhenTheDiskIsNotMounted(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	platform.UnmountPersistentDiskDidUnmount = false

	mountDisk := buildUnmountDiskAction(platform)

	result, err := mountDisk.Run("vol-123")
	assert.NoError(t, err)
	boshassert.MatchesJsonString(t, result, `{"message":"Partition of /dev/sdf is not mounted"}`)

	assert.Equal(t, platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
}
Пример #24
0
func buildApplier() (
	*fakebc.FakeBundleCollection,
	*fakepa.FakePackageApplier,
	*fakeplatform.FakePlatform,
	Applier,
) {
	jobsBc := fakebc.NewFakeBundleCollection()
	packageApplier := fakepa.NewFakePackageApplier()
	platform := fakeplatform.NewFakePlatform()
	applier := NewConcreteApplier(jobsBc, packageApplier, platform)
	return jobsBc, packageApplier, platform, applier
}
Пример #25
0
func getFakeFactoryDependencies() (
	settings boshsettings.Settings,
	platform *fakeplatform.FakePlatform,
	blobstore *fakeblobstore.FakeBlobstore,
	taskService *faketask.FakeService,
) {
	settings = boshsettings.Settings{}
	platform = fakeplatform.NewFakePlatform()
	blobstore = &fakeblobstore.FakeBlobstore{}
	taskService = &faketask.FakeService{}
	return
}
Пример #26
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("get settings", func() {

			fs := fakefs.NewFakeFileSystem()
			dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
			platform := fakeplatform.NewFakePlatform()

			settingsPath := filepath.Join(dirProvider.BaseDir(), "bosh", "settings.json")

			expectedSettings := boshsettings.Settings{AgentId: "123-456-789", Blobstore: boshsettings.Blobstore{Type: boshsettings.BlobstoreTypeDummy}, Mbus: "nats://127.0.0.1:4222"}
			existingSettingsBytes, _ := json.Marshal(expectedSettings)
			fs.WriteToFile(settingsPath, string(existingSettingsBytes))

			dummy := NewDummyInfrastructure(fs, dirProvider, platform)

			settings, err := dummy.GetSettings()
			assert.NoError(GinkgoT(), err)

			assert.Equal(GinkgoT(), settings, boshsettings.Settings{
				AgentId:   "123-456-789",
				Blobstore: boshsettings.Blobstore{Type: boshsettings.BlobstoreTypeDummy},
				Mbus:      "nats://127.0.0.1:4222",
			})
		})
		It("get settings errs when settings file does not exist", func() {

			fs := fakefs.NewFakeFileSystem()
			dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
			platform := fakeplatform.NewFakePlatform()

			dummy := NewDummyInfrastructure(fs, dirProvider, platform)

			_, err := dummy.GetSettings()
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "Read settings file")
		})
	})
}
Пример #27
0
func TestGet(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()

	platform.GetMonitCredentialsUsername = "******"
	platform.GetMonitCredentialsPassword = "******"

	client, err := NewProvider(platform).Get()

	assert.NoError(t, err)

	expectedClient := NewHttpClient("127.0.0.1:2822", "fake-user", "fake-pass")
	assert.Equal(t, expectedClient, client)
}
Пример #28
0
func TestUnmountDiskWhenTheDiskIsMounted(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	platform.UnmountPersistentDiskDidUnmount = true

	unmountDisk := buildUnmountDiskAction(platform)
	payload := `{"arguments":["vol-123"]}`

	result, err := unmountDisk.Run([]byte(payload))
	assert.NoError(t, err)
	boshassert.MatchesJsonString(t, result, `{"message":"Unmounted partition of /dev/sdf"}`)

	assert.Equal(t, platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
}
Пример #29
0
func buildAgent() (deps agentDeps, agent Agent) {
	deps = agentDeps{
		logger:           boshlog.NewLogger(boshlog.LEVEL_NONE),
		handler:          &fakembus.FakeHandler{},
		platform:         fakeplatform.NewFakePlatform(),
		actionDispatcher: &FakeActionDispatcher{},
		alertBuilder:     fakealert.NewFakeAlertBuilder(),
		jobSupervisor:    fakejobsup.NewFakeJobSupervisor(),
	}

	agent = New(deps.logger, deps.handler, deps.platform, deps.actionDispatcher, deps.alertBuilder, deps.jobSupervisor, 5*time.Millisecond)
	return
}
Пример #30
0
func TestAwsGetEphemeralDiskPath(t *testing.T) {
	fakeDnsResolver := &FakeDnsResolver{}
	platform := fakeplatform.NewFakePlatform()
	aws := NewAwsInfrastructure("", fakeDnsResolver, platform)

	platform.NormalizeDiskPathRealPath = "/dev/xvdb"
	platform.NormalizeDiskPathFound = true

	realPath, found := aws.GetEphemeralDiskPath("/dev/sdb")

	assert.True(t, found)
	assert.Equal(t, realPath, "/dev/xvdb")
	assert.Equal(t, platform.NormalizeDiskPathPath, "/dev/sdb")
}