Exemple #1
0
func main() {
	configuration, err := flags.ParseFlags(os.Args[1:])
	if err != nil {
		fmt.Fprintf(os.Stderr, "\n\n%s\n", err)
		os.Exit(1)
	}

	boshConfig := bosh.Config{
		URL:              configuration.BoshDirector,
		Password:         configuration.BoshPassword,
		Username:         configuration.BoshUser,
		AllowInsecureSSL: true,
	}

	aws := clients.NewAWS(configuration.AWSAccessKeyID, configuration.AWSSecretAccessKey,
		configuration.AWSRegion, configuration.AWSEndpointOverride)
	bosh := clients.NewBOSH(bosh.NewClient(boshConfig), os.Stdout)
	subnetChecker := subnetchecker.NewSubnetChecker(aws)

	awsDeployer := awsdeployer.NewAWSDeployer(bosh, subnetChecker, os.Stdout)

	err = awsDeployer.Deploy(configuration.ManifestPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "\n\n%s\n", err)
		os.Exit(1)
	}

	os.Exit(0)
}
			username, password, ok := r.BasicAuth()
			Expect(ok).To(BeTrue())
			Expect(username).To(Equal("some-username"))
			Expect(password).To(Equal("some-password"))

			rawBody, err := ioutil.ReadAll(r.Body)

			Expect(err).NotTo(HaveOccurred())
			Expect(string(rawBody)).To(Equal(cloudConfig))

			w.WriteHeader(http.StatusCreated)
		}))

		client := bosh.NewClient(bosh.Config{
			URL:      testServer.URL,
			Username: "******",
			Password: "******",
		})

		err := client.UpdateCloudConfig([]byte(cloudConfig))

		Expect(err).NotTo(HaveOccurred())
		Expect(testServerCallCount).To(Equal(1))
	})

	Context("failure cases", func() {
		It("returns an error when request creation fails", func() {
			client := bosh.NewClient(bosh.Config{
				URL: "%%%%%",
			})
func TestDeploy(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "turbulence")
}

var _ = BeforeSuite(func() {
	configPath, err := helpers.ConfigPath()
	Expect(err).NotTo(HaveOccurred())

	config, err = helpers.LoadConfig(configPath)
	Expect(err).NotTo(HaveOccurred())

	consulReleaseVersion = helpers.ConsulReleaseVersion()
	boshClient = bosh.NewClient(bosh.Config{
		URL:              fmt.Sprintf("https://%s:25555", config.BOSH.Target),
		Username:         config.BOSH.Username,
		Password:         config.BOSH.Password,
		AllowInsecureSSL: true,
	})
})

func lockedDeployments() ([]string, error) {
	var lockNames []string
	locks, err := boshClient.Locks()
	if err != nil {
		return []string{}, err
	}
	for _, lock := range locks {
		lockNames = append(lockNames, lock.Resource[0])
	}
	return lockNames, nil
}
		server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			serverCallCount++
			Expect(r.URL.Path).To(Equal("/locks"))
			Expect(r.Method).To(Equal("GET"))

			username, password, ok := r.BasicAuth()
			Expect(ok).To(BeTrue())
			Expect(username).To(Equal("some-username"))
			Expect(password).To(Equal("some-password"))

			w.Write([]byte(`[{"type":"deployment","resource":["some-deployment"],"timeout":"1475796348.793560"}]`))
		}))

		client = bosh.NewClient(bosh.Config{
			URL:      server.URL,
			Username: "******",
			Password: "******",
		})

		locks, err := client.Locks()
		Expect(err).NotTo(HaveOccurred())
		Expect(serverCallCount).To(Equal(1))

		Expect(locks).To(Equal([]bosh.Lock{
			{Type: "deployment", Resource: []string{"some-deployment"}, Timeout: "1475796348.793560"},
		}))
	})

	Context("failure cases", func() {
		It("returns an error when url is invalid", func() {
			client := bosh.NewClient(bosh.Config{
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Info", func() {
	It("fetches the director info", func() {
		server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			Expect(r.URL.Path).To(Equal("/info"))
			Expect(r.Method).To(Equal("GET"))

			w.Write([]byte(`{"uuid":"some-director-uuid", "cpi":"some-cpi"}`))
		}))

		client := bosh.NewClient(bosh.Config{
			URL:                 server.URL,
			TaskPollingInterval: time.Nanosecond,
		})

		info, err := client.Info()

		Expect(err).NotTo(HaveOccurred())
		Expect(info).To(Equal(bosh.DirectorInfo{
			UUID: "some-director-uuid",
			CPI:  "some-cpi",
		}))
	})

	Context("failure cases", func() {
		It("should error on malformed json", func() {
			server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.Write([]byte(`&&%%%%%&%&%&%&%&%&%&%&`))
	})

	It("is able to deploy concourse", func() {
		bbl.Up()

		certPath, err := testhelpers.WriteContentsToTempFile(testhelpers.BBL_CERT)
		Expect(err).NotTo(HaveOccurred())

		keyPath, err := testhelpers.WriteContentsToTempFile(testhelpers.BBL_KEY)
		Expect(err).NotTo(HaveOccurred())

		bbl.CreateLB("concourse", certPath, keyPath, "")

		boshClient := bosh.NewClient(bosh.Config{
			URL:              bbl.DirectorAddress(),
			Username:         bbl.DirectorUsername(),
			Password:         bbl.DirectorPassword(),
			AllowInsecureSSL: true,
		})

		err = downloadAndUploadRelease(boshClient, ConcourseReleaseURL)
		Expect(err).NotTo(HaveOccurred())

		err = downloadAndUploadRelease(boshClient, GardenReleaseURL)
		Expect(err).NotTo(HaveOccurred())

		err = downloadAndUploadStemcell(boshClient, StemcellURL)
		Expect(err).NotTo(HaveOccurred())

		concourseExampleManifest, err := downloadConcourseExampleManifest()
		Expect(err).NotTo(HaveOccurred())
				Expect(taskCallCount).NotTo(Equal(0))

				w.Write([]byte(`
						{"index": 0, "job_name": "consul_z1", "job_state":"some-state", "ips": ["1.2.3.4"]}
						{"index": 0, "job_name": "etcd_z1", "job_state":"some-state", "ips": ["1.2.3.5"]}
						{"index": 1, "job_name": "etcd_z1", "job_state":"some-other-state", "ips": ["1.2.3.6"]}
						{"index": 2, "job_name": "etcd_z1", "job_state":"some-more-state", "ips": ["1.2.3.7"]}
					`))
			default:
				Fail("unknown route")
			}
		}))

		client := bosh.NewClient(bosh.Config{
			URL:      server.URL,
			Username: "******",
			Password: "******",
		})

		vms, err := client.DeploymentVMs("some-deployment-name")
		Expect(err).NotTo(HaveOccurred())
		Expect(vms).To(ConsistOf([]bosh.VM{
			{
				Index:   0,
				JobName: "consul_z1",
				State:   "some-state",
				IPs:     []string{"1.2.3.4"},
			},
			{
				Index:   0,
				JobName: "etcd_z1",
				Expect(r.Method).To(Equal("GET"))
				w.Write([]byte(`{"versions":["2.0.0","3.0.0","4.0.0"]}`))
			case "/stemcells":
				Expect(r.Method).To(Equal("GET"))
				w.Write([]byte(`[
					{"name": "some-stemcell-name","version": "1"},
					{"name": "some-stemcell-name","version": "2"},
					{"name": "some-other-stemcell-name","version": "100"}
				]`))
			default:
				Fail("unexpected route")
			}
		}))
		client = bosh.NewClient(bosh.Config{
			URL:                 server.URL,
			Username:            "******",
			Password:            "******",
			TaskPollingInterval: time.Nanosecond,
		})
	})

	It("resolves manifest-v2 latest version of releases", func() {
		manifest := `---
director_uuid: some-director-uuid
name: some-name
stemcells:
- alias: default
  name: some-stemcell-name
  version: latest
instance_groups:
- azs:
  - z1
				Expect(password).To(Equal("some-password"))

				if callCount == 3 {
					w.Write([]byte(`{"id": 1, "state": "done"}`))
				} else {
					w.Write([]byte(`{"id": 1, "state": "processing"}`))
				}
				callCount++
			default:
				Fail("could not match any URL endpoints")
			}
		}))

		client := bosh.NewClient(bosh.Config{
			URL:                 server.URL,
			Username:            "******",
			Password:            "******",
			TaskPollingInterval: time.Nanosecond,
		})

		taskId, err := client.Deploy([]byte("some-yaml"))

		Expect(err).NotTo(HaveOccurred())
		Expect(callCount).To(Equal(4))
		Expect(taskId).To(Equal(1))
	})

	Context("failure cases", func() {
		It("should error on a non 302 redirect response with a body", func() {
			server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				switch r.URL.Path {
				case "/deployments":