Skip to content

Commit

Permalink
Call DELETE iaas_configurations only after creating
Browse files Browse the repository at this point in the history
- Ops Manager returns an error if the last iaas configuration would be deleted
  so we create what we need before deleting any.

[#171449333]
  • Loading branch information
Jeremy Alvis committed Mar 16, 2020
1 parent b4c41d0 commit 541ff49
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 65 deletions.
14 changes: 7 additions & 7 deletions api/director_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,6 @@ func (a Api) UpdateStagedDirectorIAASConfigurations(iaasConfig IAASConfiguration
}
}

if !hasDefault {
err = a.deleteExtraneousDefaultIaaSConfig(existingIAASes)
if err != nil {
return err
}
}

for _, config := range iaasConfigurations {
decoratedConfig, err := yaml.Marshal(map[string]interface{}{
"iaas_configuration": config,
Expand Down Expand Up @@ -366,6 +359,13 @@ func (a Api) UpdateStagedDirectorIAASConfigurations(iaasConfig IAASConfiguration
}
}

if !hasDefault {
err = a.deleteExtraneousDefaultIaaSConfig(existingIAASes)
if err != nil {
return err
}
}

return nil
}

Expand Down
93 changes: 35 additions & 58 deletions api/director_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,6 @@ var _ = Describe("Director", func() {
}]
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/api/v0/staged/director/iaas_configurations/some-guid"),
ghttp.RespondWith(http.StatusNoContent, `{}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api/v0/staged/director/iaas_configurations"),
ghttp.VerifyJSON(`{
Expand All @@ -930,14 +926,8 @@ var _ = Describe("Director", func() {
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", "/api/v0/staged/director/iaas_configurations/some-guid"),
ghttp.VerifyJSON(`{
"iaas_configuration": {
"name": "something-else",
"guid": "some-guid",
"vsphere": "something"
}
}`),
ghttp.VerifyRequest("DELETE", "/api/v0/staged/director/iaas_configurations/some-guid"),
ghttp.RespondWith(http.StatusNoContent, `{}`),
),
)

Expand Down Expand Up @@ -994,6 +984,15 @@ var _ = Describe("Director", func() {
}]
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api/v0/staged/director/iaas_configurations"),
ghttp.VerifyJSON(`{
"iaas_configuration": {
"name": "something-else",
"vsphere": "something"
}
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/api/v0/staged/director/iaas_configurations/some-guid"),
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
Expand All @@ -1019,6 +1018,15 @@ var _ = Describe("Director", func() {
}]
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api/v0/staged/director/iaas_configurations"),
ghttp.VerifyJSON(`{
"iaas_configuration": {
"name": "something-else",
"vsphere": "something"
}
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/api/v0/staged/director/iaas_configurations/some-guid"),
ghttp.RespondWith(http.StatusInternalServerError, `{}`),
Expand Down Expand Up @@ -1083,37 +1091,6 @@ var _ = Describe("Director", func() {
err := service.UpdateStagedDirectorIAASConfigurations(api.IAASConfigurationsInput(`[{"name": "existing", "vsphere": "something"}]`), false)
Expect(err).To(MatchError(ContainSubstring("failed to unmarshal JSON response from Ops Manager")))
})

})

When("IAASConfigurations DELETE endpoint is not implemented", func() {
It("allows later logic to handle non-implementation of the multi-iaas API", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v0/staged/director/iaas_configurations"),
ghttp.RespondWith(http.StatusOK, `{
"iaas_configurations": [{
"guid": "some-guid",
"name": "default",
"vcenter_host": null,
}]
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/api/v0/staged/director/iaas_configurations/some-guid"),
ghttp.RespondWith(http.StatusNotImplemented, ""),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api/v0/staged/director/iaas_configurations"),
ghttp.RespondWith(http.StatusNotImplemented, ""),
),
)

err := service.UpdateStagedDirectorIAASConfigurations(api.IAASConfigurationsInput(`[{"name": "something-else", "vsphere": "something"}, {"name": "another", "vsphere": "another"}]`), false)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("multiple iaas_configurations are not allowed for your IAAS.")))
Expect(err).To(MatchError(ContainSubstring("Supported IAASes include: vsphere and openstack.")))
})
})

When("IAASConfigurations POST endpoint is not implemented", func() {
Expand All @@ -1139,10 +1116,10 @@ var _ = Describe("Director", func() {
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", "/api/v0/staged/director/properties"),
ghttp.VerifyJSON(`{
"iaas_configuration": {
"name": "new"
}
}`),
"iaas_configuration": {
"name": "new"
}
}`),
),
)

Expand All @@ -1160,21 +1137,21 @@ var _ = Describe("Director", func() {
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v0/staged/director/properties"),
ghttp.RespondWith(http.StatusOK, `{
"iaas_configuration": {
"guid": "some-guid",
"name": "existing"
}
}`),
"iaas_configuration": {
"guid": "some-guid",
"name": "existing"
}
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", "/api/v0/staged/director/properties"),
ghttp.VerifyJSON(`{
"iaas_configuration": {
"name": "existing",
"guid": "some-guid",
"other-field": "value"
}
}`),
"iaas_configuration": {
"name": "existing",
"guid": "some-guid",
"other-field": "value"
}
}`),
),
)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/sclevine/spec v1.4.0 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/api v0.20.0
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20200311144346-b662892dd51b // indirect
google.golang.org/grpc v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
Expand Down

0 comments on commit 541ff49

Please sign in to comment.