Skip to content

Commit 8b36825

Browse files
christianangjoshzarrabi
authored andcommitted
Add NSX configuration support to configure-product
[#148604193] Signed-off-by: John Calabrese <[email protected]>
1 parent 583114f commit 8b36825

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

acceptance/configure_product_test.go

+74
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ const productNetworkJSON = `{
2626
"network": {"name": "network-one"}
2727
}`
2828

29+
const nsxResourceConfigJSON = `
30+
{
31+
"some-job": {
32+
"instances": 1,
33+
"persistent_disk": { "size_mb": "20480" },
34+
"instance_type": { "id": "m1.medium" },
35+
"nsx_security_groups":["sg1", "sg2"],
36+
"nsx_lbs": [
37+
{
38+
"edge_name": "edge-1",
39+
"pool_name": "pool-1",
40+
"security_group": "sg-1",
41+
"port": "5000"
42+
},
43+
{
44+
"edge_name": "edge-2",
45+
"pool_name": "pool-2",
46+
"security_group": "sg-2",
47+
"port": "5000"
48+
}]
49+
}
50+
}`
51+
2952
const resourceConfigJSON = `
3053
{
3154
"some-job": {
@@ -130,6 +153,11 @@ var _ = Describe("configure-product command", func() {
130153
}))
131154
})
132155

156+
AfterEach(func() {
157+
resourceConfigMethod = []string{}
158+
resourceConfigBody = [][]byte{}
159+
})
160+
133161
It("successfully configures any product", func() {
134162
command := exec.Command(pathToMain,
135163
"--target", server.URL,
@@ -181,4 +209,50 @@ var _ = Describe("configure-product command", func() {
181209
"elb_names": null
182210
}`))
183211
})
212+
213+
It("successfully configures a product on nsx", func() {
214+
command := exec.Command(pathToMain,
215+
"--target", server.URL,
216+
"--username", "some-username",
217+
"--password", "some-password",
218+
"--skip-ssl-validation",
219+
"configure-product",
220+
"--product-name", "cf",
221+
"--product-properties", propertiesJSON,
222+
"--product-network", productNetworkJSON,
223+
"--product-resources", nsxResourceConfigJSON,
224+
)
225+
226+
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
227+
Expect(err).NotTo(HaveOccurred())
228+
229+
Eventually(session).Should(gexec.Exit(0))
230+
231+
Expect(resourceConfigMethod[1]).To(Equal("PUT"))
232+
Expect(resourceConfigBody[1]).To(MatchJSON(`{
233+
"instances": 1,
234+
"persistent_disk": {
235+
"size_mb": "20480"
236+
},
237+
"instance_type": {
238+
"id": "m1.medium"
239+
},
240+
"elb_names": null,
241+
"nsx_security_groups":["sg1", "sg2"],
242+
"nsx_lbs": [
243+
{
244+
"edge_name": "edge-1",
245+
"pool_name": "pool-1",
246+
"security_group": "sg-1",
247+
"port": "5000"
248+
},
249+
{
250+
"edge_name": "edge-2",
251+
"pool_name": "pool-2",
252+
"security_group": "sg-2",
253+
"port": "5000"
254+
}
255+
]
256+
}`))
257+
})
184258
})

api/jobs_service.go

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ type JobProperties struct {
1818
InstanceType InstanceType `json:"instance_type"`
1919
InternetConnected *bool `json:"internet_connected,omitempty"`
2020
LBNames []string `json:"elb_names"`
21+
NSXSecurityGroups []string `json:"nsx_security_groups,omitempty"`
22+
NSXLBS []NSXLB `json:"nsx_lbs,omitempty"`
23+
}
24+
25+
type NSXLB struct {
26+
EdgeName string `json:"edge_name"`
27+
PoolName string `json:"pool_name"`
28+
SecurityGroup string `json:"security_group"`
29+
Port string `json:"port"`
2130
}
2231

2332
type Disk struct {

api/jobs_service_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,68 @@ var _ = Describe("JobsService", func() {
117117
Expect("/api/v0/staged/products/some-product-guid/jobs/some-guid/resource_config").To(Equal(request.URL.Path))
118118
})
119119

120+
Context("with nsx", func() {
121+
It("fetches the resource config for a given job including nsx properties", func() {
122+
client.DoReturns(&http.Response{
123+
StatusCode: http.StatusOK,
124+
Body: ioutil.NopCloser(strings.NewReader(`{
125+
"instances": 1,
126+
"instance_type": { "id": "number-1" },
127+
"persistent_disk": { "size_mb": "290" },
128+
"internet_connected": true,
129+
"elb_names": ["something"],
130+
"nsx_security_groups":["sg1", "sg2"],
131+
"nsx_lbs": [
132+
{
133+
"edge_name": "edge-1",
134+
"pool_name": "pool-1",
135+
"security_group": "sg-1",
136+
"port": "5000"
137+
},
138+
{
139+
"edge_name": "edge-2",
140+
"pool_name": "pool-2",
141+
"security_group": "sg-2",
142+
"port": "5000"
143+
}
144+
]
145+
}`)),
146+
}, nil)
147+
148+
service := api.NewJobsService(client)
149+
job, err := service.GetExistingJobConfig("some-product-guid", "some-guid")
150+
151+
Expect(err).NotTo(HaveOccurred())
152+
Expect(client.DoCallCount()).To(Equal(1))
153+
jobProperties := api.JobProperties{
154+
Instances: float64(1),
155+
PersistentDisk: &api.Disk{Size: "290"},
156+
InstanceType: api.InstanceType{ID: "number-1"},
157+
InternetConnected: new(bool),
158+
LBNames: []string{"something"},
159+
NSXSecurityGroups: []string{"sg1", "sg2"},
160+
NSXLBS: []api.NSXLB{
161+
api.NSXLB{
162+
EdgeName: "edge-1",
163+
PoolName: "pool-1",
164+
SecurityGroup: "sg-1",
165+
Port: "5000",
166+
},
167+
api.NSXLB{
168+
EdgeName: "edge-2",
169+
PoolName: "pool-2",
170+
SecurityGroup: "sg-2",
171+
Port: "5000",
172+
},
173+
},
174+
}
175+
*jobProperties.InternetConnected = true
176+
Expect(job).To(Equal(jobProperties))
177+
request := client.DoArgsForCall(0)
178+
Expect("/api/v0/staged/products/some-product-guid/jobs/some-guid/resource_config").To(Equal(request.URL.Path))
179+
})
180+
})
181+
120182
Context("failure cases", func() {
121183
Context("when the resource config endpoint returns an error", func() {
122184
It("returns an error", func() {

0 commit comments

Comments
 (0)