コード例 #1
0
			Canaries:                   []int{3},
			MaxInFlight:                []int{3},
			Serial:                     []string{"true"},
			NumOfCloudProperties:       []int{2},
		}

		networks := [][]string{[]string{"manual_with_static", "manual_with_auto"}}

		logger := boshlog.NewLogger(boshlog.LevelNone)
		rand.Seed(64)

		nameGenerator := bftnamegen.NewNameGenerator()
		decider := &fakebftdecider.FakeDecider{}

		ipPoolProvider := bftnetwork.NewIpPoolProvider()
		networkAssigner := bftnetwork.NewAssigner(networks, nameGenerator, ipPoolProvider, decider, logger)
		parameterProvider := bftparam.NewParameterProvider(parameters, nameGenerator, decider, networkAssigner, logger)
		inputGenerator := NewInputGenerator(parameters, parameterProvider, 2, nameGenerator, decider, logger)
		analyzer := bftanalyzer.NewAnalyzer(logger)
		deployer = NewDeployer(cliRunner, directorInfo, renderer, inputGenerator, analyzer, fs, logger, false)
	})

	It("runs deploys with generated manifests", func() {
		fs.ReturnTempFile = fakesys.NewFakeFile("manifest-path", fs)

		err := deployer.RunDeploys()
		Expect(err).ToNot(HaveOccurred())
		Expect(fs.FileExists("config-path")).To(BeFalse())

		Expect(cmdRunner.RunComplexCommands).To(ConsistOf([]boshsys.Command{
			{
コード例 #2
0
func main() {
	if len(os.Args) < 2 || len(os.Args) > 3 {
		println("Usage: bft path/to/config.json seed")
		os.Exit(1)
	}

	logger := boshlog.NewLogger(boshlog.LevelDebug)
	fs := boshsys.NewOsFileSystem(logger)
	cmdRunner := boshsys.NewExecCmdRunner(logger)

	testConfig := bftconfig.NewConfig(fs)
	err := testConfig.Load(os.Args[1])
	if err != nil {
		panic(err)
	}

	envConfig := bltconfig.NewConfig(fs)
	err = envConfig.Load(os.Args[1])
	if err != nil {
		panic(err)
	}

	assetsProvider := bltassets.NewProvider(envConfig.AssetsPath)

	logger.Debug("main", "Setting up environment")

	environmentProvider := bltenv.NewProvider(envConfig, fs, cmdRunner, assetsProvider)
	environment := environmentProvider.Get()

	if !testConfig.GenerateManifestOnly {
		err = environment.Setup()
		if err != nil {
			panic(err)
		}
		defer environment.Shutdown()
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		<-c
		environment.Shutdown()
		os.Exit(1)
	}()

	cliRunnerFactory := bltclirunner.NewFactory(envConfig.CliCmd, cmdRunner, fs)

	var directorInfo bltaction.DirectorInfo
	if testConfig.GenerateManifestOnly {
		directorInfo = bltaction.DirectorInfo{
			UUID: "blah",
			URL:  "xxx",
		}
	} else {
		directorInfo, err = bltaction.NewDirectorInfo(environment.DirectorURL(), cliRunnerFactory)
	}

	if err != nil {
		panic(err)
	}
	cliRunner := cliRunnerFactory.Create()
	cliRunner.Configure()
	defer cliRunner.Clean()

	if !testConfig.GenerateManifestOnly {
		logger.Debug("main", "Preparing to deploy")
		preparer := bftdeployment.NewPreparer(directorInfo, cliRunner, fs, assetsProvider)
		err = preparer.Prepare()
		if err != nil {
			panic(err)
		}
	}

	logger.Debug("main", "Starting deploy")
	renderer := bftdeployment.NewRenderer(fs)

	var seed int64
	if len(os.Args) == 3 {
		seed, _ = strconv.ParseInt(os.Args[2], 10, 64)
	} else {
		seed = time.Now().Unix()
	}

	logger.Info("main", "Seeding with %d", seed)
	rand.Seed(seed)

	nameGenerator := bftnamegen.NewNameGenerator()
	decider := bftdecider.NewRandomDecider()

	ipPoolProvider := bftnetwork.NewIpPoolProvider()
	networksAssigner := bftnetwork.NewAssigner(testConfig.Parameters.Networks, nameGenerator, ipPoolProvider, decider, logger)
	parameterProvider := bftparam.NewParameterProvider(testConfig.Parameters, nameGenerator, decider, networksAssigner, logger)
	inputGenerator := bftdeployment.NewInputGenerator(testConfig.Parameters, parameterProvider, testConfig.NumberOfConsequentDeploys, nameGenerator, decider, logger)
	analyzer := bftanalyzer.NewAnalyzer(logger)

	deployer := bftdeployment.NewDeployer(
		cliRunner,
		directorInfo,
		renderer,
		inputGenerator,
		analyzer,
		fs,
		logger,
		testConfig.GenerateManifestOnly,
	)
	err = deployer.RunDeploys()
	if err != nil {
		panic(err)
	}

	println("Done!")
}