Beispiel #1
0
func DeployConsulWithInstanceCount(count int, client bosh.Client, config Config) (manifest destiny.Manifest, kv consul.KV, err error) {
	guid, err := NewGUID()
	if err != nil {
		return
	}

	info, err := client.Info()
	if err != nil {
		return
	}

	manifestConfig := destiny.Config{
		DirectorUUID: info.UUID,
		Name:         fmt.Sprintf("consul-%s", guid),
	}

	switch info.CPI {
	case "aws_cpi":
		manifestConfig.IAAS = destiny.AWS
		if config.AWS.Subnet != "" {
			manifestConfig.AWS.Subnet = config.AWS.Subnet
		} else {
			err = errors.New("AWSSubnet is required for AWS IAAS deployment")
			return
		}
	case "warden_cpi":
		manifestConfig.IAAS = destiny.Warden
	default:
		err = errors.New("unknown infrastructure type")
		return
	}

	manifest = destiny.NewConsul(manifestConfig)

	manifest.Jobs[0], manifest.Properties = destiny.SetJobInstanceCount(manifest.Jobs[0], manifest.Networks[0], manifest.Properties, count)

	yaml, err := manifest.ToYAML()
	if err != nil {
		return
	}

	yaml, err = client.ResolveManifestVersions(yaml)
	if err != nil {
		return
	}

	manifest, err = destiny.FromYAML(yaml)
	if err != nil {
		return
	}

	err = client.Deploy(yaml)
	if err != nil {
		return
	}

	kv, err = NewKV(manifest, count)

	return
}
Beispiel #2
0
package destiny_test

import (
	"acceptance-tests/testing/destiny"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consul Manifest", func() {
	Describe("NewConsul", func() {
		It("generates a valid Consul BOSH-Lite manifest", func() {
			manifest := destiny.NewConsul(destiny.Config{
				DirectorUUID: "some-director-uuid",
				Name:         "consul-some-random-guid",
				IAAS:         destiny.Warden,
			})

			Expect(manifest).To(Equal(destiny.Manifest{
				DirectorUUID: "some-director-uuid",
				Name:         "consul-some-random-guid",
				Releases: []destiny.Release{{
					Name:    "consul",
					Version: "latest",
				}},
				Compilation: destiny.Compilation{
					Network:             "consul1",
					ReuseCompilationVMs: true,
					Workers:             3,
				},
				Update: destiny.Update{
func DeployConsulWithInstanceCount(count int, client bosh.Client, config Config) (manifest destiny.Manifest, kv consul.KV, err error) {
	guid, err := NewGUID()
	if err != nil {
		return
	}

	info, err := client.Info()
	if err != nil {
		return
	}

	manifestConfig := destiny.Config{
		DirectorUUID: info.UUID,
		Name:         fmt.Sprintf("consul-%s", guid),
	}

	switch info.CPI {
	case "aws_cpi":
		manifestConfig.IAAS = destiny.AWS
		if config.AWS.Subnet != "" {
			manifestConfig.AWS.Subnet = config.AWS.Subnet
		} else {
			err = errors.New("AWSSubnet is required for AWS IAAS deployment")
			return
		}
	case "warden_cpi":
		manifestConfig.IAAS = destiny.Warden
	default:
		err = errors.New("unknown infrastructure type")
		return
	}

	manifest = destiny.NewConsul(manifestConfig)

	manifest.Jobs[0], manifest.Properties = destiny.SetJobInstanceCount(manifest.Jobs[0], manifest.Networks[0], manifest.Properties, count)

	yaml, err := manifest.ToYAML()
	if err != nil {
		return
	}

	yaml, err = client.ResolveManifestVersions(yaml)
	if err != nil {
		return
	}

	manifest, err = destiny.FromYAML(yaml)
	if err != nil {
		return
	}

	err = client.Deploy(yaml)
	if err != nil {
		return
	}

	members := manifest.ConsulMembers()
	if len(members) != count {
		err = fmt.Errorf("expected %d consul members, found %d", count, len(members))
		return
	}

	consulMemberAddresses := []string{}
	for _, member := range members {
		consulMemberAddresses = append(consulMemberAddresses, member.Address)
	}

	dataDir, err := ioutil.TempDir("", "consul")
	if err != nil {
		return
	}

	configDir, err := ioutil.TempDir("", "consul-config")
	if err != nil {
		return
	}

	var encryptKey string
	if len(manifest.Properties.Consul.EncryptKeys) > 0 {
		encryptKey = manifest.Properties.Consul.EncryptKeys[0]
	}

	agent := consul.NewAgent(consul.AgentOptions{
		DataDir:    dataDir,
		RetryJoin:  consulMemberAddresses,
		ConfigDir:  configDir,
		Domain:     "cf.internal",
		Key:        manifest.Properties.Consul.AgentKey,
		Cert:       manifest.Properties.Consul.AgentCert,
		CACert:     manifest.Properties.Consul.CACert,
		Encrypt:    encryptKey,
		ServerName: "consul agent",
	})

	agentLocation := "http://127.0.0.1:8500"
	kv = consul.NewManagedKV(consul.ManagedKVConfig{
		Agent:   agent,
		KV:      consul.NewHTTPKV(agentLocation),
		Catalog: consul.NewHTTPCatalog(agentLocation),
	})

	return
}
Beispiel #4
0
package destiny_test

import (
	"acceptance-tests/testing/destiny"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Job", func() {
	Describe("SetJobInstanceCount", func() {
		It("sets the correct values for instances and static_ips given a count", func() {
			manifest := destiny.NewConsul(destiny.Config{
				IAAS: destiny.Warden,
			})
			job := manifest.Jobs[0]
			network := manifest.Networks[0]
			properties := manifest.Properties

			Expect(job.Instances).To(Equal(1))
			Expect(job.Networks[0].StaticIPs).To(HaveLen(1))
			Expect(job.Networks[0].Name).To(Equal(network.Name))
			Expect(properties.Consul.Agent.Servers.Lan).To(Equal(job.Networks[0].StaticIPs))

			job, properties = destiny.SetJobInstanceCount(job, network, properties, 3)
			Expect(job.Instances).To(Equal(3))
			Expect(job.Networks[0].StaticIPs).To(HaveLen(3))
			Expect(properties.Consul.Agent.Servers.Lan).To(Equal(job.Networks[0].StaticIPs))
		})
	})
})
Beispiel #5
0
	"io/ioutil"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/pivotal-cf-experimental/gomegamatchers"
)

var _ = Describe("Manifest", func() {
	Describe("ToYAML", func() {
		It("returns a YAML representation of the consul manifest", func() {
			consulManifest, err := ioutil.ReadFile("fixtures/consul_manifest.yml")
			Expect(err).NotTo(HaveOccurred())

			manifest := destiny.NewConsul(destiny.Config{
				DirectorUUID: "some-director-uuid",
				Name:         "consul",
				IAAS:         destiny.Warden,
			})

			yaml, err := manifest.ToYAML()
			Expect(err).NotTo(HaveOccurred())
			Expect(yaml).To(MatchYAML(consulManifest))
		})

		It("returns a YAML representation of the turbulence manifest", func() {
			turbulenceManifest, err := ioutil.ReadFile("fixtures/turbulence_manifest.yml")
			Expect(err).NotTo(HaveOccurred())

			manifest := destiny.NewTurbulence(destiny.Config{
				DirectorUUID: "some-director-uuid",
				Name:         "turbulence",