remove delete step of `login key` and `public ip instance`.
This commit is contained in:
parent
2a3a35334a
commit
e57a8161e0
|
@ -56,8 +56,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
NewStepCreateServerImage(conn, ui, b.config),
|
||||
NewStepDeleteBlockStorageInstance(conn, ui, b.config),
|
||||
NewStepTerminateServerInstance(conn, ui),
|
||||
NewStepDeleteLoginKey(conn, ui),
|
||||
NewStepDeletePublicIPInstance(conn, ui),
|
||||
}
|
||||
} else if b.config.Comm.Type == "Windows" {
|
||||
steps = []multistep.Step{
|
||||
|
@ -84,8 +82,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
NewStepCreateServerImage(conn, ui, b.config),
|
||||
NewStepDeleteBlockStorageInstance(conn, ui, b.config),
|
||||
NewStepTerminateServerInstance(conn, ui),
|
||||
NewStepDeleteLoginKey(conn, ui),
|
||||
NewStepDeletePublicIPInstance(conn, ui),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,13 +57,6 @@ func (s *StepCreateLoginKey) Run(state multistep.StateBag) multistep.StepAction
|
|||
}
|
||||
|
||||
func (s *StepCreateLoginKey) Cleanup(state multistep.StateBag) {
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
|
||||
if !cancelled && !halted {
|
||||
return
|
||||
}
|
||||
|
||||
if loginKey, ok := state.GetOk("LoginKey"); ok {
|
||||
s.Say("Clean up login key")
|
||||
s.Conn.DeleteLoginKey(loginKey.(*LoginKey).KeyName)
|
||||
|
|
|
@ -105,13 +105,6 @@ func (s *StepCreatePublicIPInstance) Run(state multistep.StateBag) multistep.Ste
|
|||
}
|
||||
|
||||
func (s *StepCreatePublicIPInstance) Cleanup(state multistep.StateBag) {
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
|
||||
if !cancelled && !halted {
|
||||
return
|
||||
}
|
||||
|
||||
publicIPInstance, ok := state.GetOk("PublicIPInstance")
|
||||
if !ok {
|
||||
return
|
||||
|
@ -148,6 +141,11 @@ func (s *StepCreatePublicIPInstance) waitPublicIPInstanceStatus(publicIPInstance
|
|||
return
|
||||
}
|
||||
|
||||
if resp.TotalRows == 0 {
|
||||
c1 <- nil
|
||||
return
|
||||
}
|
||||
|
||||
instance := resp.PublicIPInstanceList[0]
|
||||
if instance.PublicIPInstanceStatus.Code == status && instance.PublicIPInstanceOperation.Code == "NULL" {
|
||||
c1 <- nil
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package ncloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/mitchellh/multistep"
|
||||
)
|
||||
|
||||
type StepDeleteLoginKey struct {
|
||||
Conn *ncloud.Conn
|
||||
DeleteLoginKey func(keyName string) error
|
||||
Say func(message string)
|
||||
Error func(e error)
|
||||
}
|
||||
|
||||
func NewStepDeleteLoginKey(conn *ncloud.Conn, ui packer.Ui) *StepDeleteLoginKey {
|
||||
var step = &StepDeleteLoginKey{
|
||||
Conn: conn,
|
||||
Say: func(message string) { ui.Say(message) },
|
||||
Error: func(e error) { ui.Error(e.Error()) },
|
||||
}
|
||||
|
||||
step.DeleteLoginKey = step.deleteLoginKey
|
||||
|
||||
return step
|
||||
}
|
||||
|
||||
func (s *StepDeleteLoginKey) deleteLoginKey(keyName string) error {
|
||||
_, err := s.Conn.DeleteLoginKey(keyName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StepDeleteLoginKey) Run(state multistep.StateBag) multistep.StepAction {
|
||||
var loginKey = state.Get("LoginKey").(*LoginKey)
|
||||
|
||||
err := s.DeleteLoginKey(loginKey.KeyName)
|
||||
if err == nil {
|
||||
s.Say(fmt.Sprintf("Login Key[%s] is deleted", loginKey.KeyName))
|
||||
}
|
||||
|
||||
return processStepResult(err, s.Error, state)
|
||||
}
|
||||
|
||||
func (*StepDeleteLoginKey) Cleanup(multistep.StateBag) {
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package ncloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStepDeleteLoginKeyShouldFailIfOperationDeleteLoginKeyFails(t *testing.T) {
|
||||
var testSubject = &StepDeleteLoginKey{
|
||||
DeleteLoginKey: func(keyName string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
|
||||
Say: func(message string) {},
|
||||
Error: func(e error) {},
|
||||
}
|
||||
|
||||
stateBag := DeleteTestStateBagStepDeleteLoginKey()
|
||||
|
||||
var result = testSubject.Run(stateBag)
|
||||
|
||||
if result != multistep.ActionHalt {
|
||||
t.Fatalf("Expected the step to return 'ActionHalt', but got '%d'.", result)
|
||||
}
|
||||
|
||||
if _, ok := stateBag.GetOk("Error"); ok == false {
|
||||
t.Fatal("Expected the step to set stateBag['Error'], but it was not.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStepDeleteLoginKeyShouldPassIfOperationDeleteLoginKeyPasses(t *testing.T) {
|
||||
var testSubject = &StepDeleteLoginKey{
|
||||
DeleteLoginKey: func(keyName string) error { return nil },
|
||||
Say: func(message string) {},
|
||||
Error: func(e error) {},
|
||||
}
|
||||
|
||||
stateBag := DeleteTestStateBagStepDeleteLoginKey()
|
||||
|
||||
var result = testSubject.Run(stateBag)
|
||||
|
||||
if result != multistep.ActionContinue {
|
||||
t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
|
||||
}
|
||||
|
||||
if _, ok := stateBag.GetOk("Error"); ok == true {
|
||||
t.Fatalf("Expected the step to not set stateBag['Error'], but it was.")
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteTestStateBagStepDeleteLoginKey() multistep.StateBag {
|
||||
stateBag := new(multistep.BasicStateBag)
|
||||
|
||||
stateBag.Put("LoginKey", &LoginKey{"a", "b"})
|
||||
|
||||
return stateBag
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package ncloud
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/mitchellh/multistep"
|
||||
)
|
||||
|
||||
type StepDeletePublicIPInstance struct {
|
||||
Conn *ncloud.Conn
|
||||
DeletePublicIPInstance func(publicIPInstanceNo string) error
|
||||
Say func(message string)
|
||||
Error func(e error)
|
||||
}
|
||||
|
||||
func NewStepDeletePublicIPInstance(conn *ncloud.Conn, ui packer.Ui) *StepDeletePublicIPInstance {
|
||||
var step = &StepDeletePublicIPInstance{
|
||||
Conn: conn,
|
||||
Say: func(message string) { ui.Say(message) },
|
||||
Error: func(e error) { ui.Error(e.Error()) },
|
||||
}
|
||||
|
||||
step.DeletePublicIPInstance = step.deletePublicIPInstance
|
||||
|
||||
return step
|
||||
}
|
||||
|
||||
func (s *StepDeletePublicIPInstance) deletePublicIPInstance(publicIPInstanceNo string) error {
|
||||
reqParams := new(ncloud.RequestDeletePublicIPInstances)
|
||||
reqParams.PublicIPInstanceNoList = []string{publicIPInstanceNo}
|
||||
|
||||
c1 := make(chan error, 1)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
resp, err := s.Conn.DeletePublicIPInstances(reqParams)
|
||||
if err != nil && (resp.ReturnCode == 24073 || resp.ReturnCode == 25032) {
|
||||
// error code : 24073 : Unable to destroy the server since a public IP is associated with the server. First, please disassociate a public IP from the server.
|
||||
// error code : 25032 : You may not delete sk since (other) user is changing the target official IP settings.
|
||||
log.Println(resp.ReturnCode, resp.ReturnMessage)
|
||||
} else if err != nil {
|
||||
c1 <- fmt.Errorf("error code: %d, error message: %s", resp.ReturnCode, resp.ReturnMessage)
|
||||
return
|
||||
} else if err == nil {
|
||||
s.Say(fmt.Sprintf("Public IP Instance [%s] is deleted.", publicIPInstanceNo))
|
||||
c1 <- nil
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case res := <-c1:
|
||||
return res
|
||||
case <-time.After(time.Second * 60):
|
||||
return errors.New("TIMEOUT : Can't delete server instance")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StepDeletePublicIPInstance) Run(state multistep.StateBag) multistep.StepAction {
|
||||
s.Say("Delete Public IP Instance")
|
||||
|
||||
publicIPInstance := state.Get("PublicIPInstance").(*ncloud.PublicIPInstance)
|
||||
|
||||
err := s.DeletePublicIPInstance(publicIPInstance.PublicIPInstanceNo)
|
||||
|
||||
return processStepResult(err, s.Error, state)
|
||||
}
|
||||
|
||||
func (*StepDeletePublicIPInstance) Cleanup(multistep.StateBag) {
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package ncloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk"
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/multistep"
|
||||
)
|
||||
|
||||
func TestStepDeletePublicIPInstanceShouldFailIfOperationDeletePublicIPInstanceFails(t *testing.T) {
|
||||
var testSubject = &StepDeletePublicIPInstance{
|
||||
DeletePublicIPInstance: func(publicIPInstanceNo string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
|
||||
Say: func(message string) {},
|
||||
Error: func(e error) {},
|
||||
}
|
||||
|
||||
stateBag := createTestStateBagStepDeletePublicIPInstance()
|
||||
|
||||
var result = testSubject.Run(stateBag)
|
||||
|
||||
if result != multistep.ActionHalt {
|
||||
t.Fatalf("Expected the step to return 'ActionHalt', but got '%d'.", result)
|
||||
}
|
||||
|
||||
if _, ok := stateBag.GetOk("Error"); ok == false {
|
||||
t.Fatal("Expected the step to set stateBag['Error'], but it was not.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStepDeletePublicIPInstanceShouldPassIfOperationDeletePublicIPInstancePasses(t *testing.T) {
|
||||
var testSubject = &StepDeletePublicIPInstance{
|
||||
DeletePublicIPInstance: func(publicIPInstanceNo string) error { return nil },
|
||||
Say: func(message string) {},
|
||||
Error: func(e error) {},
|
||||
}
|
||||
|
||||
stateBag := createTestStateBagStepDeletePublicIPInstance()
|
||||
|
||||
var result = testSubject.Run(stateBag)
|
||||
|
||||
if result != multistep.ActionContinue {
|
||||
t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
|
||||
}
|
||||
|
||||
if _, ok := stateBag.GetOk("Error"); ok == true {
|
||||
t.Fatalf("Expected the step to not set stateBag['Error'], but it was.")
|
||||
}
|
||||
}
|
||||
|
||||
func createTestStateBagStepDeletePublicIPInstance() multistep.StateBag {
|
||||
stateBag := new(multistep.BasicStateBag)
|
||||
|
||||
stateBag.Put("PublicIPInstance", &ncloud.PublicIPInstance{PublicIPInstanceNo: "22"})
|
||||
|
||||
return stateBag
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package ncloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/mitchellh/multistep"
|
||||
|
|
Loading…
Reference in New Issue