Skip to content
This repository has been archived by the owner on Jul 12, 2018. It is now read-only.

Commit

Permalink
[#126911079] we now add the bosh uuid to the deployment manifest auto…
Browse files Browse the repository at this point in the history
…matically
  • Loading branch information
xchapter7x committed Jul 24, 2016
1 parent b581d81 commit 4674a1b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
10 changes: 9 additions & 1 deletion utils/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package utils

import "net/http"
import (
"net/http"

"github.com/enaml-ops/enaml/enamlbosh"
)

//HttpClientDoer - interface for a http.Client.Doer
type HttpClientDoer interface {
Do(req *http.Request) (resp *http.Response, err error)
}

type BoshClientCaller interface {
GetInfo() (*enamlbosh.BoshInfo, error)
}
21 changes: 19 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ func GetProductCommands(target string) (commands []cli.Command) {
client, productDeployment := registry.GetProductReference(pluginPath)
defer client.Kill()
boshclient := enamlbosh.NewClientBasic(c.Parent().String("bosh-user"), c.Parent().String("bosh-pass"), c.Parent().String("bosh-url"), c.Parent().Int("bosh-port"))

if cloudConfig, err = boshclient.GetCloudConfig(); err == nil {
var cloudConfigBytes []byte
var task enamlbosh.BoshTask
cloudConfigBytes, err = cloudConfig.Bytes()
deploymentManifest := productDeployment.GetProduct(c.Parent().Args(), cloudConfigBytes)
task, err = processProductDeployment(c, deploymentManifest, true)
lo.G.Debug("bosh task: ", task)

if deploymentManifest, err = DecorateDeploymentWithBoshUUID(deploymentManifest, boshclient); err == nil {
task, err = processProductDeployment(c, deploymentManifest, true)
lo.G.Debug("bosh task: ", task)
}
}
return
},
Expand All @@ -96,6 +100,19 @@ func GetProductCommands(target string) (commands []cli.Command) {
return
}

func DecorateDeploymentWithBoshUUID(deployment []byte, client BoshClientCaller) ([]byte, error) {
var boshinfo *enamlbosh.BoshInfo
var dm *enaml.DeploymentManifest
var err error

if boshinfo, err = client.GetInfo(); err == nil {
dm = enaml.NewDeploymentManifest(deployment)
lo.G.Debug("setting uuid on deployment from bosh: ", boshinfo.UUID)
dm.SetDirectorUUID(boshinfo.UUID)
}
return dm.Bytes(), err
}

//ProcessProductBytes - upload a product deployments bytes to bosh
func ProcessProductBytes(manifest []byte, printManifest bool, user, pass, url string, port int, httpClient HttpClientDoer, poll bool) (task enamlbosh.BoshTask, err error) {
if printManifest {
Expand Down
22 changes: 22 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package utils_test

import (
"github.com/codegangsta/cli"
"github.com/enaml-ops/enaml"
"github.com/enaml-ops/enaml/enamlbosh"
. "github.com/enaml-ops/omg-cli/utils"
"github.com/enaml-ops/omg-cli/utils/utilsfakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -23,6 +26,25 @@ var _ = Describe("utils", func() {
})
})

Describe("given a DecorateDeploymentWithBoshUUID", func() {
Context("when called with a deployment []byte and boshclient", func() {
var dmResult *enaml.DeploymentManifest
var controlUUID = "blah-blah-ble-bui"

BeforeEach(func() {
boshclientfake := new(utilsfakes.FakeBoshClientCaller)
boshclientfake.GetInfoReturns(&enamlbosh.BoshInfo{
UUID: controlUUID,
}, nil)
dm, _ := DecorateDeploymentWithBoshUUID([]byte(``), boshclientfake)
dmResult = enaml.NewDeploymentManifest(dm)
})
It("then should overwrite the uuid in the deployment with the result from a info client call to the bosh", func() {
Ω(dmResult.DirectorUUID).Should(Equal(controlUUID))
})
})
})

/*Describe("given ProcessRemoteStemcells", func() {
var doer *enamlboshfakes.FakeHttpClientDoer
Expand Down
46 changes: 46 additions & 0 deletions utils/utilsfakes/fake_bosh_client_caller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This file was generated by counterfeiter
package utilsfakes

import (
"sync"

"github.com/enaml-ops/enaml/enamlbosh"
"github.com/enaml-ops/omg-cli/utils"
)

type FakeBoshClientCaller struct {
GetInfoStub func() (*enamlbosh.BoshInfo, error)
getInfoMutex sync.RWMutex
getInfoArgsForCall []struct{}
getInfoReturns struct {
result1 *enamlbosh.BoshInfo
result2 error
}
}

func (fake *FakeBoshClientCaller) GetInfo() (*enamlbosh.BoshInfo, error) {
fake.getInfoMutex.Lock()
fake.getInfoArgsForCall = append(fake.getInfoArgsForCall, struct{}{})
fake.getInfoMutex.Unlock()
if fake.GetInfoStub != nil {
return fake.GetInfoStub()
} else {
return fake.getInfoReturns.result1, fake.getInfoReturns.result2
}
}

func (fake *FakeBoshClientCaller) GetInfoCallCount() int {
fake.getInfoMutex.RLock()
defer fake.getInfoMutex.RUnlock()
return len(fake.getInfoArgsForCall)
}

func (fake *FakeBoshClientCaller) GetInfoReturns(result1 *enamlbosh.BoshInfo, result2 error) {
fake.GetInfoStub = nil
fake.getInfoReturns = struct {
result1 *enamlbosh.BoshInfo
result2 error
}{result1, result2}
}

var _ utils.BoshClientCaller = new(FakeBoshClientCaller)

0 comments on commit 4674a1b

Please sign in to comment.