Skip to content

Commit

Permalink
Add NSX configuration support to configure-product
Browse files Browse the repository at this point in the history
[#148604193]

Signed-off-by: John Calabrese <[email protected]>
  • Loading branch information
christianang authored and joshzarrabi committed Jul 13, 2017
1 parent 583114f commit 8b36825
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
74 changes: 74 additions & 0 deletions acceptance/configure_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ const productNetworkJSON = `{
"network": {"name": "network-one"}
}`

const nsxResourceConfigJSON = `
{
"some-job": {
"instances": 1,
"persistent_disk": { "size_mb": "20480" },
"instance_type": { "id": "m1.medium" },
"nsx_security_groups":["sg1", "sg2"],
"nsx_lbs": [
{
"edge_name": "edge-1",
"pool_name": "pool-1",
"security_group": "sg-1",
"port": "5000"
},
{
"edge_name": "edge-2",
"pool_name": "pool-2",
"security_group": "sg-2",
"port": "5000"
}]
}
}`

const resourceConfigJSON = `
{
"some-job": {
Expand Down Expand Up @@ -130,6 +153,11 @@ var _ = Describe("configure-product command", func() {
}))
})

AfterEach(func() {
resourceConfigMethod = []string{}
resourceConfigBody = [][]byte{}
})

It("successfully configures any product", func() {
command := exec.Command(pathToMain,
"--target", server.URL,
Expand Down Expand Up @@ -181,4 +209,50 @@ var _ = Describe("configure-product command", func() {
"elb_names": null
}`))
})

It("successfully configures a product on nsx", func() {
command := exec.Command(pathToMain,
"--target", server.URL,
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"configure-product",
"--product-name", "cf",
"--product-properties", propertiesJSON,
"--product-network", productNetworkJSON,
"--product-resources", nsxResourceConfigJSON,
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))

Expect(resourceConfigMethod[1]).To(Equal("PUT"))
Expect(resourceConfigBody[1]).To(MatchJSON(`{
"instances": 1,
"persistent_disk": {
"size_mb": "20480"
},
"instance_type": {
"id": "m1.medium"
},
"elb_names": null,
"nsx_security_groups":["sg1", "sg2"],
"nsx_lbs": [
{
"edge_name": "edge-1",
"pool_name": "pool-1",
"security_group": "sg-1",
"port": "5000"
},
{
"edge_name": "edge-2",
"pool_name": "pool-2",
"security_group": "sg-2",
"port": "5000"
}
]
}`))
})
})
9 changes: 9 additions & 0 deletions api/jobs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ type JobProperties struct {
InstanceType InstanceType `json:"instance_type"`
InternetConnected *bool `json:"internet_connected,omitempty"`
LBNames []string `json:"elb_names"`
NSXSecurityGroups []string `json:"nsx_security_groups,omitempty"`
NSXLBS []NSXLB `json:"nsx_lbs,omitempty"`
}

type NSXLB struct {
EdgeName string `json:"edge_name"`
PoolName string `json:"pool_name"`
SecurityGroup string `json:"security_group"`
Port string `json:"port"`
}

type Disk struct {
Expand Down
62 changes: 62 additions & 0 deletions api/jobs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,68 @@ var _ = Describe("JobsService", func() {
Expect("/api/v0/staged/products/some-product-guid/jobs/some-guid/resource_config").To(Equal(request.URL.Path))
})

Context("with nsx", func() {
It("fetches the resource config for a given job including nsx properties", func() {
client.DoReturns(&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(`{
"instances": 1,
"instance_type": { "id": "number-1" },
"persistent_disk": { "size_mb": "290" },
"internet_connected": true,
"elb_names": ["something"],
"nsx_security_groups":["sg1", "sg2"],
"nsx_lbs": [
{
"edge_name": "edge-1",
"pool_name": "pool-1",
"security_group": "sg-1",
"port": "5000"
},
{
"edge_name": "edge-2",
"pool_name": "pool-2",
"security_group": "sg-2",
"port": "5000"
}
]
}`)),
}, nil)

service := api.NewJobsService(client)
job, err := service.GetExistingJobConfig("some-product-guid", "some-guid")

Expect(err).NotTo(HaveOccurred())
Expect(client.DoCallCount()).To(Equal(1))
jobProperties := api.JobProperties{
Instances: float64(1),
PersistentDisk: &api.Disk{Size: "290"},
InstanceType: api.InstanceType{ID: "number-1"},
InternetConnected: new(bool),
LBNames: []string{"something"},
NSXSecurityGroups: []string{"sg1", "sg2"},
NSXLBS: []api.NSXLB{
api.NSXLB{
EdgeName: "edge-1",
PoolName: "pool-1",
SecurityGroup: "sg-1",
Port: "5000",
},
api.NSXLB{
EdgeName: "edge-2",
PoolName: "pool-2",
SecurityGroup: "sg-2",
Port: "5000",
},
},
}
*jobProperties.InternetConnected = true
Expect(job).To(Equal(jobProperties))
request := client.DoArgsForCall(0)
Expect("/api/v0/staged/products/some-product-guid/jobs/some-guid/resource_config").To(Equal(request.URL.Path))
})
})

Context("failure cases", func() {
Context("when the resource config endpoint returns an error", func() {
It("returns an error", func() {
Expand Down

0 comments on commit 8b36825

Please sign in to comment.