Exemple #1
0
func basicDeps() (boshlog.Logger, boshsys.FileSystem, boshsys.CmdRunner, boshuuid.Generator) {
	logger := boshlog.NewWriterLogger(boshlog.LevelDebug, os.Stderr, os.Stderr)

	fs := boshsys.NewOsFileSystem(logger)

	runner := boshsys.NewExecCmdRunner(logger)

	uuidGen := boshuuid.NewGenerator()

	return logger, fs, runner, uuidGen
}
Exemple #2
0
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
	runner := boshsys.NewExecCmdRunner(logger)
	fs := boshsys.NewOsFileSystem(logger, runner)
	sigarCollector := boshstats.NewSigarStatsCollector()
	linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs)

	udev := boshudev.NewConcreteUdevDevice(runner)
	linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
	linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)

	compressor := boshcmd.NewTarballCompressor(runner, fs)
	copier := boshcmd.NewCpCopier(runner, fs)
	vitalsService := boshvitals.NewService(sigarCollector, dirProvider)

	centosNetManager := boshnet.NewCentosNetManager(fs, runner, 10*time.Second)
	ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, 10*time.Second)

	centos := NewLinuxPlatform(
		fs,
		runner,
		sigarCollector,
		compressor,
		copier,
		dirProvider,
		vitalsService,
		linuxCdutil,
		linuxDiskManager,
		centosNetManager,
		500*time.Millisecond,
		logger,
	)

	ubuntu := NewLinuxPlatform(
		fs,
		runner,
		sigarCollector,
		compressor,
		copier,
		dirProvider,
		vitalsService,
		linuxCdutil,
		linuxDiskManager,
		ubuntuNetManager,
		500*time.Millisecond,
		logger,
	)

	p.platforms = map[string]Platform{
		"ubuntu": ubuntu,
		"centos": centos,
		"dummy":  NewDummyPlatform(sigarCollector, fs, runner, dirProvider, linuxDiskManager),
	}
	return
}
Exemple #3
0
// There is a reason the runner is not injected.
// Other entities should not use a runner, they should go through the platform
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
	runner := boshsys.NewExecCmdRunner(logger)
	fs := boshsys.NewOsFileSystem(logger, runner)
	sigarStatsCollector := boshstats.NewSigarStatsCollector()
	ubuntuDiskManager := boshdisk.NewUbuntuDiskManager(logger, runner, fs)
	compressor := boshcmd.NewTarballCompressor(runner, fs)

	p.platforms = map[string]Platform{
		"ubuntu": newUbuntuPlatform(sigarStatsCollector, fs, runner, ubuntuDiskManager, compressor, dirProvider),
		"dummy":  newDummyPlatform(),
	}
	return
}
Exemple #4
0
func TestDecompressFileToDirReturnsError(t *testing.T) {
	nonExistentDstDir := filepath.Join(os.TempDir(), "TestDecompressFileToDirReturnsError")

	cmdRunner := boshsys.NewExecCmdRunner()
	fs := boshsys.NewOsFileSystem()
	dc := NewCompressor(cmdRunner, fs)

	// propagates errors raised when untarring
	err := dc.DecompressFileToDir(fixtureSrcTgz(t), nonExistentDstDir)
	assert.Error(t, err)

	// path is in the error message
	assert.Contains(t, err.Error(), nonExistentDstDir)
}
Exemple #5
0
// There is a reason the runner is not injected.
// Other entities should not use a runner, they should go through the platform
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider) (p provider) {
	runner := boshsys.NewExecCmdRunner(logger)
	fs := boshsys.NewOsFileSystem(logger, runner)
	sigarStatsCollector := boshstats.NewSigarStatsCollector()
	ubuntuDiskManager := boshdisk.NewUbuntuDiskManager(logger, runner, fs)
	centosDiskManager := boshdisk.NewCentosDiskManager(logger, runner, fs)

	p.platforms = map[string]Platform{
		"ubuntu": NewUbuntuPlatform(sigarStatsCollector, fs, runner, ubuntuDiskManager, dirProvider, 500*time.Millisecond, 10*time.Second, 3*time.Minute),
		"centos": NewCentosPlatform(sigarStatsCollector, fs, runner, centosDiskManager, dirProvider, 500*time.Millisecond, 10*time.Second, 3*time.Minute),
		"dummy":  NewDummyPlatform(sigarStatsCollector, fs, runner, dirProvider),
	}
	return
}
Exemple #6
0
func NewProvider() (p provider) {
	fs := boshsys.NewOsFileSystem()

	// There is a reason the runner is not injected.
	// Other entities should not use a runner, they should go through the platform
	runner := boshsys.NewExecCmdRunner()

	ubuntuDiskManager := boshdisk.NewUbuntuDiskManager(runner, fs)
	sigarStatsCollector := boshstats.NewSigarStatsCollector()

	p.platforms = map[string]Platform{
		"ubuntu": newUbuntuPlatform(sigarStatsCollector, fs, runner, ubuntuDiskManager),
		"dummy":  newDummyPlatform(),
	}
	return
}
Exemple #7
0
func TestCompressFilesInDir(t *testing.T) {
	fakeStats, _, _, fakeDiskManager := getUbuntuDependencies()
	osFs := boshsys.NewOsFileSystem()
	execCmdRunner := boshsys.NewExecCmdRunner()

	tmpDir := filepath.Join(os.TempDir(), "TestCompressFilesInDir")
	err := osFs.MkdirAll(tmpDir, os.ModePerm)

	assert.NoError(t, err)
	defer os.RemoveAll(tmpDir)

	ubuntu := newUbuntuPlatform(fakeStats, osFs, execCmdRunner, fakeDiskManager)

	pwd, err := os.Getwd()
	assert.NoError(t, err)
	fixturesDir := filepath.Join(pwd, "..", "..", "..", "fixtures", "test_get_files_in_dir")

	tgz, err := ubuntu.CompressFilesInDir(fixturesDir, []string{"**/*.stdout.log", "*.stderr.log", "../some.config"})
	assert.NoError(t, err)

	defer os.Remove(tgz.Name())

	_, _, err = execCmdRunner.RunCommand("tar", "xzf", tgz.Name(), "-C", tmpDir)
	assert.NoError(t, err)

	content, err := osFs.ReadFile(tmpDir + "/app.stdout.log")
	assert.NoError(t, err)
	assert.Contains(t, content, "this is app stdout")

	content, err = osFs.ReadFile(tmpDir + "/app.stderr.log")
	assert.NoError(t, err)
	assert.Contains(t, content, "this is app stderr")

	content, err = osFs.ReadFile(tmpDir + "/other_logs/other_app.stdout.log")
	assert.NoError(t, err)
	assert.Contains(t, content, "this is other app stdout")

	content, err = osFs.ReadFile(tmpDir + "/other_logs/other_app.stderr.log")
	assert.Error(t, err)

	content, err = osFs.ReadFile(tmpDir + "/../some.config")
	assert.Error(t, err)
}
Exemple #8
0
func TestCompressFilesInDir(t *testing.T) {
	cmdRunner := boshsys.NewExecCmdRunner()
	fs := boshsys.NewOsFileSystem()
	dc := NewCompressor(cmdRunner, fs)

	srcDir := fixtureSrcDir(t)
	tgz, err := dc.CompressFilesInDir(srcDir, []string{"**/*.stdout.log", "*.stderr.log", "../some.config"})
	assert.NoError(t, err)

	defer os.Remove(tgz.Name())

	dstDir := createdTmpDir(t, fs)
	defer os.RemoveAll(dstDir)

	_, _, err = cmdRunner.RunCommand("tar", "xzf", tgz.Name(), "-C", dstDir)
	assert.NoError(t, err)

	// regular files
	content, err := fs.ReadFile(dstDir + "/app.stdout.log")
	assert.NoError(t, err)
	assert.Contains(t, content, "this is app stdout")

	content, err = fs.ReadFile(dstDir + "/app.stderr.log")
	assert.NoError(t, err)
	assert.Contains(t, content, "this is app stderr")

	// file in a directory
	content, err = fs.ReadFile(dstDir + "/other_logs/other_app.stdout.log")
	assert.NoError(t, err)
	assert.Contains(t, content, "this is other app stdout")

	// file that is not matching filter
	content, err = fs.ReadFile(dstDir + "/other_logs/other_app.stderr.log")
	assert.Error(t, err)

	content, err = fs.ReadFile(dstDir + "/../some.config")
	assert.Error(t, err)
}
Exemple #9
0
func TestDecompressFileToDir(t *testing.T) {
	fs := boshsys.NewOsFileSystem()
	dstDir := createdTmpDir(t, fs)
	defer os.RemoveAll(dstDir)

	cmdRunner := boshsys.NewExecCmdRunner()
	dc := NewCompressor(cmdRunner, fs)

	err := dc.DecompressFileToDir(fixtureSrcTgz(t), dstDir)
	assert.NoError(t, err)

	// regular files
	content, err := fs.ReadFile(dstDir + "/not-nested-file")
	assert.NoError(t, err)
	assert.Contains(t, content, "not-nested-file")

	// nested directory with a file
	content, err = fs.ReadFile(dstDir + "/dir/nested-file")
	assert.NoError(t, err)
	assert.Contains(t, content, "nested-file")

	// nested directory with a file inside another directory
	content, err = fs.ReadFile(dstDir + "/dir/nested-dir/double-nested-file")
	assert.NoError(t, err)
	assert.Contains(t, content, "double-nested-file")

	// directory without a file (empty)
	content, err = fs.ReadFile(dstDir + "/empty-dir")
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "is a directory")

	// nested directory without a file (empty) inside another directory
	content, err = fs.ReadFile(dstDir + "/dir/empty-nested-dir")
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "is a directory")
}
func getCompressorDependencies() (boshsys.FileSystem, boshsys.CmdRunner) {
	logger := boshlog.NewLogger(boshlog.LEVEL_NONE)
	fs := boshsys.NewOsFileSystem(logger)
	cmdRunner := boshsys.NewExecCmdRunner(logger)
	return fs, cmdRunner
}
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider, options ProviderOptions) (p provider) {
	runner := boshsys.NewExecCmdRunner(logger)
	fs := boshsys.NewOsFileSystem(logger)

	linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs, options.Linux.BindMountPersistentDisk)

	udev := boshudev.NewConcreteUdevDevice(runner)
	linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
	linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)

	compressor := boshcmd.NewTarballCompressor(runner, fs)
	copier := boshcmd.NewCpCopier(runner, fs, logger)

	sigarCollector := boshstats.NewSigarStatsCollector(&sigar.ConcreteSigar{})

	// Kick of stats collection as soon as possible
	go sigarCollector.StartCollecting(SigarStatsCollectionInterval, nil)

	vitalsService := boshvitals.NewService(sigarCollector, dirProvider)

	routesSearcher := boshnet.NewCmdRoutesSearcher(runner)
	ipResolver := boship.NewIPResolver(boship.NetworkInterfaceToAddrsFunc)

	defaultNetworkResolver := boshnet.NewDefaultNetworkResolver(routesSearcher, ipResolver)
	arping := bosharp.NewArping(runner, fs, logger, ArpIterations, ArpIterationDelay, ArpInterfaceCheckDelay)

	centosNetManager := boshnet.NewCentosNetManager(fs, runner, defaultNetworkResolver, ipResolver, arping, logger)
	ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, defaultNetworkResolver, ipResolver, arping, logger)

	centos := NewLinuxPlatform(
		fs,
		runner,
		sigarCollector,
		compressor,
		copier,
		dirProvider,
		vitalsService,
		linuxCdutil,
		linuxDiskManager,
		centosNetManager,
		500*time.Millisecond,
		options.Linux,
		logger,
	)

	ubuntu := NewLinuxPlatform(
		fs,
		runner,
		sigarCollector,
		compressor,
		copier,
		dirProvider,
		vitalsService,
		linuxCdutil,
		linuxDiskManager,
		ubuntuNetManager,
		500*time.Millisecond,
		options.Linux,
		logger,
	)

	p.platforms = map[string]Platform{
		"ubuntu": ubuntu,
		"centos": centos,
		"dummy":  NewDummyPlatform(sigarCollector, fs, runner, dirProvider, logger),
	}
	return
}
Exemple #12
0
func getCopierDependencies() (boshsys.FileSystem, boshsys.CmdRunner) {
	logger := boshlog.NewLogger(boshlog.LevelNone)
	cmdRunner := boshsys.NewExecCmdRunner(logger)
	fs := boshsys.NewOsFileSystem(logger, cmdRunner)
	return fs, cmdRunner
}
Exemple #13
0
func NewProvider(logger boshlog.Logger, dirProvider boshdirs.DirectoriesProvider, options ProviderOptions) (p provider) {
	runner := boshsys.NewExecCmdRunner(logger)
	fs := boshsys.NewOsFileSystem(logger)

	linuxDiskManager := boshdisk.NewLinuxDiskManager(logger, runner, fs, options.Linux.BindMountPersistentDisk)

	udev := boshudev.NewConcreteUdevDevice(runner)
	linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
	linuxCdutil := boshcd.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom)

	compressor := boshcmd.NewTarballCompressor(runner, fs)
	copier := boshcmd.NewCpCopier(runner, fs, logger)

	sigarCollector := boshstats.NewSigarStatsCollector()
	vitalsService := boshvitals.NewService(sigarCollector, dirProvider)

	routesSearcher := boshnet.NewCmdRoutesSearcher(runner)
	defaultNetworkResolver := boshnet.NewDefaultNetworkResolver(
		routesSearcher,
		boshnet.DefaultInterfaceToAddrsFunc,
	)

	centosNetManager := boshnet.NewCentosNetManager(fs, runner, defaultNetworkResolver, 10*time.Second, logger)
	ubuntuNetManager := boshnet.NewUbuntuNetManager(fs, runner, defaultNetworkResolver, 10*time.Second, logger)

	centos := NewLinuxPlatform(
		fs,
		runner,
		sigarCollector,
		compressor,
		copier,
		dirProvider,
		vitalsService,
		linuxCdutil,
		linuxDiskManager,
		centosNetManager,
		500*time.Millisecond,
		options.Linux,
		logger,
	)

	ubuntu := NewLinuxPlatform(
		fs,
		runner,
		sigarCollector,
		compressor,
		copier,
		dirProvider,
		vitalsService,
		linuxCdutil,
		linuxDiskManager,
		ubuntuNetManager,
		500*time.Millisecond,
		options.Linux,
		logger,
	)

	p.platforms = map[string]Platform{
		"ubuntu": ubuntu,
		"centos": centos,
		"dummy":  NewDummyPlatform(sigarCollector, fs, runner, dirProvider, linuxDiskManager, logger),
	}
	return
}
	boshlog "bosh/logger"
	. "bosh/platform/commands"
	boshsys "bosh/system"
)

var _ = Describe("cpCopier", func() {
	var (
		fs        boshsys.FileSystem
		cmdRunner boshsys.CmdRunner
		cpCopier  Copier
	)

	BeforeEach(func() {
		logger := boshlog.NewLogger(boshlog.LevelNone)
		fs = boshsys.NewOsFileSystem(logger)
		cmdRunner = boshsys.NewExecCmdRunner(logger)
		cpCopier = NewCpCopier(cmdRunner, fs, logger)
	})

	Describe("FilteredCopyToTemp", func() {
		copierFixtureSrcDir := func() string {
			pwd, err := os.Getwd()
			Expect(err).ToNot(HaveOccurred())
			return filepath.Join(pwd, "..", "..", "..", "..", "fixtures", "test_filtered_copy_to_temp")
		}

		It("filtered copy to temp", func() {
			srcDir := copierFixtureSrcDir()
			dstDir, err := cpCopier.FilteredCopyToTemp(srcDir, []string{
				"**/*.stdout.log",
				"*.stderr.log",