Alternative fix for #2641: make random script name actually random
This commit is contained in:
parent
45829c30e5
commit
e5a713ff01
|
@ -4,9 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
||||||
|
@ -211,9 +209,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||||
// Seed the random number generator
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
// Create the driver that we'll use to communicate with VirtualBox
|
// Create the driver that we'll use to communicate with VirtualBox
|
||||||
driver, err := vboxcommon.NewDriver()
|
driver, err := vboxcommon.NewDriver()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
||||||
|
@ -35,9 +33,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
// Run executes a Packer build and returns a packer.Artifact representing
|
// Run executes a Packer build and returns a packer.Artifact representing
|
||||||
// a VirtualBox appliance.
|
// a VirtualBox appliance.
|
||||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||||
// Seed the random number generator
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
// Create the driver that we'll use to communicate with VirtualBox
|
// Create the driver that we'll use to communicate with VirtualBox
|
||||||
driver, err := vboxcommon.NewDriver()
|
driver, err := vboxcommon.NewDriver()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -246,9 +245,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
|
|
||||||
// Seed the random number generator
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
steps := []multistep.Step{
|
steps := []multistep.Step{
|
||||||
&vmwcommon.StepPrepareTools{
|
&vmwcommon.StepPrepareTools{
|
||||||
RemoteType: b.config.RemoteType,
|
RemoteType: b.config.RemoteType,
|
||||||
|
|
7
main.go
7
main.go
|
@ -6,10 +6,12 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/mitchellh/packer/command"
|
"github.com/mitchellh/packer/command"
|
||||||
|
@ -292,3 +294,8 @@ func copyOutput(r io.Reader, doneCh chan<- struct{}) {
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Seed the random number generator
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -33,3 +34,9 @@ func TestExtractMachineReadable(t *testing.T) {
|
||||||
t.Fatal("should be mr")
|
t.Fatal("should be mr")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRandom(t *testing.T) {
|
||||||
|
if rand.Intn(9999999) == 8498210 {
|
||||||
|
t.Fatal("math.rand is not seeded properly")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,12 +13,14 @@ import (
|
||||||
packrpc "github.com/mitchellh/packer/packer/rpc"
|
packrpc "github.com/mitchellh/packer/packer/rpc"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is a count of the number of interrupts the process has received.
|
// This is a count of the number of interrupts the process has received.
|
||||||
|
@ -138,3 +140,8 @@ func serverListener_unix() (net.Listener, error) {
|
||||||
|
|
||||||
return net.Listen("unix", path)
|
return net.Listen("unix", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Seed the random number generator
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPluginServerRandom(t *testing.T) {
|
||||||
|
if rand.Intn(9999999) == 8498210 {
|
||||||
|
t.Fatal("math.rand is not seeded properly")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue