Skip to content

Commit 3f16682

Browse files
committed
Ensure existing clusters within availability zones match correctly
The previous implementation expected cluster names to be unique. Unfortunately, this is not true across infras so we instead assume the configuration is complete for a given cluster if the guid is already set. Signed-off-by: Derek Richard <[email protected]>
1 parent 108bcc5 commit 3f16682

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

api/director_service.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,12 @@ func (a Api) addGUIDToExistingAZs(azs AvailabilityZones) (AvailabilityZones, err
481481
az.GUID = existingAZ.GUID
482482

483483
for _, cluster := range az.Clusters {
484-
for _, existingCluster := range existingAZ.Clusters {
485-
if cluster.Name == existingCluster.Name {
486-
cluster.GUID = existingCluster.GUID
487-
break
484+
if cluster.GUID == "" {
485+
for _, existingCluster := range existingAZ.Clusters {
486+
if cluster.Name == existingCluster.Name {
487+
cluster.GUID = existingCluster.GUID
488+
break
489+
}
488490
}
489491
}
490492
}

api/director_service_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,70 @@ var _ = Describe("Director", func() {
207207
})
208208
})
209209

210+
When("there are existing azs and the clusters have the same name", func() {
211+
BeforeEach(func() {
212+
server.AppendHandlers(
213+
ghttp.CombineHandlers(
214+
ghttp.VerifyRequest("GET", "/api/v0/staged/director/iaas_configurations"),
215+
ghttp.RespondWith(http.StatusOK, `{
216+
"iaas_configurations": [{
217+
"guid": "existing-iaas-guid",
218+
"name": "existing-iaas"
219+
}]
220+
}`),
221+
),
222+
ghttp.CombineHandlers(
223+
ghttp.VerifyRequest("GET", "/api/v0/staged/director/availability_zones"),
224+
ghttp.RespondWith(http.StatusOK, `{
225+
"availability_zones": [{
226+
"guid": "existing-az-guid",
227+
"name": "existing-az",
228+
"clusters": [
229+
{ "cluster":"pizza", "guid":"pepperoni", "res_pool":"dcba"},
230+
{ "cluster":"pizza", "guid":"ricotta", "res_pool":"abcd"}
231+
]
232+
}]
233+
}`),
234+
),
235+
)
236+
})
237+
238+
It("correctly matches the existing clusters within the az", func() {
239+
server.AppendHandlers(
240+
ghttp.CombineHandlers(
241+
ghttp.VerifyRequest("PUT", "/api/v0/staged/director/availability_zones/existing-az-guid"),
242+
ghttp.VerifyJSON(`{
243+
"availability_zone": {
244+
"a_field": "some_val",
245+
"guid": "existing-az-guid",
246+
"name": "existing-az",
247+
"iaas_configuration_guid": "existing-iaas-guid",
248+
"clusters": [
249+
{ "cluster":"pizza", "guid":"pepperoni", "res_pool":"dcba"},
250+
{ "cluster":"pizza", "guid":"ricotta", "res_pool":"abcd"}
251+
]
252+
}
253+
}`),
254+
ghttp.RespondWith(http.StatusOK, `{}`),
255+
),
256+
)
257+
err := service.UpdateStagedDirectorAvailabilityZones(api.AvailabilityZoneInput{
258+
AvailabilityZones: json.RawMessage(`[
259+
{
260+
"clusters": [
261+
{"cluster": "pizza", "guid":"pepperoni", "res_pool": "dcba"},
262+
{"cluster": "pizza", "guid":"ricotta", "res_pool": "abcd"}
263+
],
264+
"iaas_configuration_name": "existing-iaas",
265+
"name": "existing-az",
266+
"a_field":"some_val"
267+
}
268+
]`),
269+
}, false)
270+
Expect(err).ToNot(HaveOccurred())
271+
})
272+
})
273+
210274
When("there is only 1 az config passed in without a name and only 1 iaas config is returned by the api", func() {
211275
It("send the request anyway", func() {
212276
server.AppendHandlers(
@@ -466,7 +530,7 @@ var _ = Describe("Director", func() {
466530
ghttp.VerifyHeader(map[string][]string{"Content-Type": []string{"application/json"}}),
467531
ghttp.RespondWith(http.StatusOK, `{
468532
"networks": [{
469-
"guid": "existing-network-guid",
533+
"guid": "existing-network-guid",
470534
"name": "existing-network"
471535
}]
472536
}`),

0 commit comments

Comments
 (0)