mirror of https://github.com/hashicorp/packer
Add step_http_ip_discover to virtualbox to allow HTTPIP in vboxmanage (#8700)
parent
a1d9ba0e32
commit
6d7c6ba18c
@ -0,0 +1,21 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
)
|
||||
|
||||
// Step to discover the http ip
|
||||
// which guests use to reach the vm host
|
||||
// To make sure the IP is set before boot command and http server steps
|
||||
type StepHTTPIPDiscover struct{}
|
||||
|
||||
func (s *StepHTTPIPDiscover) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
hostIP := "10.0.2.2"
|
||||
common.SetHTTPIP(hostIP)
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepHTTPIPDiscover) Cleanup(state multistep.StateBag) {}
|
||||
@ -0,0 +1,29 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStepHTTPIPDiscover_Run(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
step := new(StepHTTPIPDiscover)
|
||||
hostIp := "10.0.2.2"
|
||||
previousHttpIp := common.GetHTTPIP()
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
||||
t.Fatalf("bad action: %#v", action)
|
||||
}
|
||||
if _, ok := state.GetOk("error"); ok {
|
||||
t.Fatal("should NOT have error")
|
||||
}
|
||||
httpIp := common.GetHTTPIP()
|
||||
if httpIp != hostIp {
|
||||
t.Fatalf("bad: Http ip is %s but was supposed to be %s", httpIp, hostIp)
|
||||
}
|
||||
|
||||
common.SetHTTPIP(previousHttpIp)
|
||||
}
|
||||
Loading…
Reference in new issue