Skip to content

Commit

Permalink
import-installation no longer fails when opsman already configured
Browse files Browse the repository at this point in the history
* this will make the command idempotent

[#155197711]

Signed-off-by: Kevin Kelani <[email protected]>
  • Loading branch information
Kalai Wei authored and Kevin Kelani committed Feb 13, 2018
1 parent d6ddccf commit 620df71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions acceptance/import_installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ var _ = Describe("import-installation command", func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(session, 5).Should(gexec.Exit(1))
Eventually(session.Err, 5).Should(gbytes.Say("cannot import installation to an Ops Manager that is already configured"))
Eventually(session, 5).Should(gexec.Exit(0))
Eventually(session.Out, 5).Should(gbytes.Say("Ops Manager is already configured"))
})
})

Expand Down
4 changes: 2 additions & 2 deletions commands/import_installation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commands

import (
"errors"
"fmt"

"github.com/pivotal-cf/jhanda"
Expand Down Expand Up @@ -53,7 +52,8 @@ func (ii ImportInstallation) Execute(args []string) error {
}

if ensureAvailabilityOutput.Status != api.EnsureAvailabilityStatusUnstarted {
return errors.New("cannot import installation to an Ops Manager that is already configured")
ii.logger.Printf("Ops Manager is already configured")
return nil
}

ii.logger.Printf("processing installation")
Expand Down
7 changes: 5 additions & 2 deletions commands/import_installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var _ = Describe("ImportInstallation", func() {
})

Context("when the Ops Manager is already configured", func() {
It("returns an error", func() {
It("prints a helpful message", func() {
setupService = &fakes.SetupService{}
setupService.EnsureAvailabilityReturns(api.EnsureAvailabilityOutput{
Status: api.EnsureAvailabilityStatusComplete,
Expand All @@ -140,7 +140,10 @@ var _ = Describe("ImportInstallation", func() {
"--installation", "/path/to/some-installation",
"--decryption-passphrase", "some-passphrase",
})
Expect(err).To(MatchError(ContainSubstring("cannot import installation to an Ops Manager that is already configured")))
Expect(err).NotTo(HaveOccurred())

format, v := logger.PrintfArgsForCall(0)
Expect(fmt.Sprintf(format, v...)).To(Equal("Ops Manager is already configured"))
Expect(setupService.EnsureAvailabilityCallCount()).To(Equal(1))
})
})
Expand Down

0 comments on commit 620df71

Please sign in to comment.