Пример #1
0
func buildMigrateDiskAction() (platform *fakeplatform.FakePlatform, action migrateDiskAction) {
	platform = fakeplatform.NewFakePlatform()
	settings := &fakesettings.FakeSettingsService{}
	dirProvider := boshdirs.NewDirectoriesProvider("/foo")
	action = newMigrateDisk(settings, platform, dirProvider)
	return
}
Пример #2
0
func getNewProvider() (provider provider) {
	dirProvider := boshsys.NewDirectoriesProvider("/var/vcap")
	fs := fakefs.NewFakeFileSystem()

	provider = NewProvider(boshlog.NewLogger(boshlog.LEVEL_NONE), fs, dirProvider)
	return
}
Пример #3
0
func createBlobManager() (blobManager BlobManager, fs *fakesys.FakeFileSystem) {
	fs = fakesys.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")

	blobManager = NewBlobManager(fs, dirProvider)
	return
}
Пример #4
0
func buildCompiler() (
	deps compilerDeps,
	compiler Compiler,
) {
	deps.compressor = fakecmd.NewFakeCompressor()
	deps.blobstore = &fakeblobstore.FakeBlobstore{}
	deps.fs = fakesys.NewFakeFileSystem()
	deps.runner = fakesys.NewFakeCmdRunner()
	deps.packageApplier = fakepa.NewFakePackageApplier()
	fakeBundleCollection := fakebc.NewFakeBundleCollection()
	bundleDefinition := boshmodels.Package{
		Name:    "pkg_name",
		Version: "pkg_version",
	}
	deps.bundle = fakeBundleCollection.FakeGet(bundleDefinition)
	deps.bundle.InstallPath = "/fake-dir/data/packages/pkg_name/pkg_version"
	deps.bundle.EnablePath = "/fake-dir/packages/pkg_name"
	deps.packagesBc = fakeBundleCollection

	compiler = NewConcreteCompiler(
		deps.compressor,
		deps.blobstore,
		deps.fs,
		deps.runner,
		boshdirs.NewDirectoriesProvider("/fake-dir"),
		deps.packageApplier,
		deps.packagesBc,
	)
	return
}
Пример #5
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
}
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)
}
Пример #7
0
func buildLogsAction() (*fakecmd.FakeCompressor, *fakeblobstore.FakeBlobstore, logsAction) {
	compressor := fakecmd.NewFakeCompressor()
	blobstore := &fakeblobstore.FakeBlobstore{}
	dirProvider := boshdirs.NewDirectoriesProvider("/fake/dir")
	action := newLogs(compressor, blobstore, dirProvider)
	return compressor, blobstore, action
}
Пример #8
0
func getExternalBlobstoreDependencies() (fs *fakesys.FakeFileSystem, runner *fakesys.FakeCmdRunner, uuidGen *fakeuuid.FakeGenerator, configPath string) {
	fs = &fakesys.FakeFileSystem{}
	runner = &fakesys.FakeCmdRunner{}
	uuidGen = &fakeuuid.FakeGenerator{}
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
	configPath = filepath.Join(dirProvider.EtcDir(), "blobstore-fake-provider.json")
	return
}
Пример #9
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
}
Пример #10
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"))
		})
	})
}
Пример #11
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
}
func TestGetSettingsErrsWhenSettingsFileDoesNotExist(t *testing.T) {
	fs := fakefs.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")

	dummy := newDummyInfrastructure(fs, dirProvider)

	_, err := dummy.GetSettings()
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "Read settings file")
}
func TestNewDrainScript(t *testing.T) {
	runner := fakesys.NewFakeCmdRunner()
	fs := fakesys.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")

	scriptProvider := NewConcreteDrainScriptProvider(runner, fs, dirProvider)
	drainScript := scriptProvider.NewDrainScript("foo")

	assert.Equal(t, drainScript.Path(), "/var/vcap/jobs/foo/bin/drain")
}
Пример #15
0
func buildService(NTPData string) (service Service) {
	fs := fakefs.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")

	if NTPData != "" {
		fs.WriteToFile("/var/vcap/bosh/log/ntpdate.out", NTPData)
	}

	service = NewConcreteService(fs, dirProvider)
	return
}
func buildMonitJobSupervisor() (deps monitJobSupDeps, monit monitJobSupervisor) {
	deps = monitJobSupDeps{
		fs:          &fakesys.FakeFileSystem{},
		runner:      &fakesys.FakeCmdRunner{},
		client:      fakemonit.NewFakeMonitClient(),
		logger:      boshlog.NewLogger(boshlog.LEVEL_NONE),
		dirProvider: boshdir.NewDirectoriesProvider("/var/vcap"),
	}

	monit = NewMonitJobSupervisor(deps.fs, deps.runner, deps.client, deps.logger, deps.dirProvider)
	return
}
Пример #17
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")
		})
	})
}
Пример #18
0
func buildCompiler() (
	compressor *fakecmd.FakeCompressor,
	blobstore *fakeblobstore.FakeBlobstore,
	fs *fakesys.FakeFileSystem,
	runner *fakesys.FakeCmdRunner,
	compiler Compiler,
) {
	compressor = fakecmd.NewFakeCompressor()
	blobstore = &fakeblobstore.FakeBlobstore{}
	fs = fakesys.NewFakeFileSystem()
	runner = fakesys.NewFakeCmdRunner()
	compiler = newConcreteCompiler(compressor, blobstore, fs, runner, boshdirs.NewDirectoriesProvider("/fake-dir"))
	return
}
Пример #19
0
func startServer() (serverURL string, handler HttpsHandler, fs *fakesys.FakeFileSystem) {
	serverURL = "https://*****:*****@127.0.0.1:6900"
	mbusUrl, _ := url.Parse(serverURL)
	logger := boshlog.NewLogger(boshlog.LEVEL_NONE)
	fs = fakesys.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
	handler = NewHttpsHandler(mbusUrl, logger, fs, dirProvider)

	go handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
		receivedRequest = req
		return boshhandler.NewValueResponse("expected value")
	})
	return
}
Пример #20
0
func buildApplier() (
	*fakeja.FakeJobApplier,
	*fakepa.FakePackageApplier,
	*FakeLogRotateDelegate,
	*fakejobsuper.FakeJobSupervisor,
	Applier,
) {
	jobApplier := fakeja.NewFakeJobApplier()
	packageApplier := fakepa.NewFakePackageApplier()
	platform := &FakeLogRotateDelegate{}
	jobSupervisor := fakejobsuper.NewFakeJobSupervisor()
	applier := NewConcreteApplier(jobApplier, packageApplier, platform, jobSupervisor, boshdirs.NewDirectoriesProvider("/fake-base-dir"))
	return jobApplier, packageApplier, platform, jobSupervisor, applier
}
func init() {
	Describe("Testing with Ginkgo", func() {
		It("new drain script", func() {

			runner := fakesys.NewFakeCmdRunner()
			fs := fakesys.NewFakeFileSystem()
			dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")

			scriptProvider := NewConcreteDrainScriptProvider(runner, fs, dirProvider)
			drainScript := scriptProvider.NewDrainScript("foo")

			Expect(drainScript.Path()).To(Equal("/var/vcap/jobs/foo/bin/drain"))
		})
	})
}
Пример #22
0
func buildDrain() (
	cmdRunner *fakesys.FakeCmdRunner,
	fs *fakesys.FakeFileSystem,
	notifier *fakenotif.FakeNotifier,
	specService *fakeas.FakeV1Service,
	action drainAction,
) {
	cmdRunner = fakesys.NewFakeCmdRunner()
	fs = fakesys.NewFakeFileSystem()
	notifier = fakenotif.NewFakeNotifier()
	specService = fakeas.NewFakeV1Service()
	dirProvider := boshdirs.NewDirectoriesProvider("/fake-dir")
	drainScriptProvider := boshdrain.NewDrainScriptProvider(cmdRunner, fs, dirProvider)
	action = newDrain(notifier, specService, drainScriptProvider)
	return
}
Пример #23
0
func buildLogsAction() (deps logsDeps, action LogsAction) {
	deps = logsDeps{
		compressor:  fakecmd.NewFakeCompressor(),
		blobstore:   &fakeblobstore.FakeBlobstore{},
		dirProvider: boshdirs.NewDirectoriesProvider("/fake/dir"),
		copier:      fakecmd.NewFakeCopier(),
	}

	action = NewLogs(
		deps.compressor,
		deps.copier,
		deps.blobstore,
		deps.dirProvider,
	)
	return
}
Пример #24
0
func TestGet(t *testing.T) {
	platform := fakeplatform.NewFakePlatform()
	blobstore := fakeblobstore.NewFakeBlobstore()
	dirProvider := boshdirs.NewDirectoriesProvider("/fake-dir")

	compiler := NewCompilerProvider(platform, blobstore, dirProvider).Get()

	expectedCompiler := newConcreteCompiler(
		platform.GetCompressor(),
		blobstore,
		platform.GetFs(),
		platform.GetRunner(),
		dirProvider,
	)

	assert.Equal(t, expectedCompiler, compiler)
}
Пример #25
0
func buildProvider() (
	deps providerDependencies,
	provider provider,
) {
	deps.platform = fakeplatform.NewFakePlatform()
	deps.client = fakemonit.NewFakeMonitClient()
	deps.logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
	deps.dirProvider = boshdir.NewDirectoriesProvider("/fake-base-dir")

	provider = NewProvider(
		deps.platform,
		deps.client,
		deps.logger,
		deps.dirProvider,
	)
	return
}
Пример #26
0
func buildCentos() (
	deps centosDependencies,
	platform centos,
) {
	deps.collector = &fakestats.FakeStatsCollector{}
	deps.fs = &fakesys.FakeFileSystem{}
	deps.cmdRunner = &fakesys.FakeCmdRunner{}
	deps.diskManager = fakedisk.NewFakeDiskManager(deps.cmdRunner)
	deps.dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")

	platform = newCentosPlatform(
		deps.collector,
		deps.fs,
		deps.cmdRunner,
		deps.diskManager,
		deps.dirProvider,
	)
	return
}
Пример #27
0
func buildVitalsService() (statsCollector *fakestats.FakeStatsCollector, service Service) {
	dirProvider := boshdirs.NewDirectoriesProvider("/fake/base/dir")
	statsCollector = &fakestats.FakeStatsCollector{
		CPULoad: boshstats.CPULoad{
			One:     0.2,
			Five:    4.55,
			Fifteen: 1.123,
		},
		StartCollectingCPUStats: boshstats.CPUStats{
			User:  56,
			Sys:   10,
			Wait:  1,
			Total: 100,
		},
		MemStats: boshstats.Usage{
			Used:  700 * 1024,
			Total: 1000 * 1024,
		},
		SwapStats: boshstats.Usage{
			Used:  600 * 1024,
			Total: 1000 * 1024,
		},
		DiskStats: map[string]boshstats.DiskStats{
			"/": boshstats.DiskStats{
				DiskUsage:  boshstats.Usage{Used: 100, Total: 200},
				InodeUsage: boshstats.Usage{Used: 50, Total: 500},
			},
			dirProvider.DataDir(): boshstats.DiskStats{
				DiskUsage:  boshstats.Usage{Used: 15, Total: 20},
				InodeUsage: boshstats.Usage{Used: 10, Total: 50},
			},
			dirProvider.StoreDir(): boshstats.DiskStats{
				DiskUsage:  boshstats.Usage{Used: 2, Total: 2},
				InodeUsage: boshstats.Usage{Used: 3, Total: 4},
			},
		},
	}

	service = NewService(statsCollector, dirProvider)
	statsCollector.StartCollecting(1*time.Millisecond, nil)
	return
}
func TestGetSettings(t *testing.T) {
	fs := fakefs.NewFakeFileSystem()
	dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")

	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)

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

	assert.Equal(t, settings, boshsettings.Settings{
		AgentId:   "123-456-789",
		Blobstore: boshsettings.Blobstore{Type: boshsettings.BlobstoreTypeDummy},
		Mbus:      "nats://127.0.0.1:4222",
	})
}
Пример #29
0
func buildUbuntu() (
	deps ubuntuDependencies,
	platform ubuntu,
) {
	deps.collector = &fakestats.FakeStatsCollector{}
	deps.fs = &fakesys.FakeFileSystem{}
	deps.cmdRunner = &fakesys.FakeCmdRunner{}
	deps.diskManager = fakedisk.NewFakeDiskManager(deps.cmdRunner)
	deps.compressor = fakecmd.NewFakeCompressor()
	deps.dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")

	platform = newUbuntuPlatform(
		deps.collector,
		deps.fs,
		deps.cmdRunner,
		deps.diskManager,
		deps.compressor,
		deps.dirProvider,
	)
	return
}
Пример #30
0
func buildUbuntu(cdromWaitInterval time.Duration, diskWaitTimeout time.Duration) (
	deps ubuntuDependencies,
	platform Platform,
) {
	deps.collector = &fakestats.FakeStatsCollector{}
	deps.fs = &fakesys.FakeFileSystem{}
	deps.cmdRunner = &fakesys.FakeCmdRunner{}
	deps.diskManager = fakedisk.NewFakeDiskManager(deps.cmdRunner)
	deps.dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")

	platform = NewUbuntuPlatform(
		deps.collector,
		deps.fs,
		deps.cmdRunner,
		deps.diskManager,
		deps.dirProvider,
		cdromWaitInterval,
		1*time.Millisecond,
		diskWaitTimeout,
	)
	return
}