github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/environs/testing/bootstrap.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "github.com/juju/loggo" 8 "github.com/juju/testing" 9 "github.com/juju/utils/ssh" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/cloudconfig/instancecfg" 13 "github.com/juju/juju/cmd/modelcmd" 14 "github.com/juju/juju/environs" 15 "github.com/juju/juju/instance" 16 "github.com/juju/juju/provider/common" 17 coretesting "github.com/juju/juju/testing" 18 ) 19 20 var logger = loggo.GetLogger("juju.environs.testing") 21 22 // DisableFinishBootstrap disables common.FinishBootstrap so that tests 23 // do not attempt to SSH to non-existent machines. The result is a function 24 // that restores finishBootstrap. 25 func DisableFinishBootstrap() func() { 26 f := func( 27 environs.BootstrapContext, 28 ssh.Client, 29 environs.Environ, 30 instance.Instance, 31 *instancecfg.InstanceConfig, 32 environs.BootstrapDialOpts, 33 ) error { 34 logger.Infof("provider/common.FinishBootstrap is disabled") 35 return nil 36 } 37 return testing.PatchValue(&common.FinishBootstrap, f) 38 } 39 40 // BootstrapContext creates a simple bootstrap execution context. 41 func BootstrapContext(c *gc.C) environs.BootstrapContext { 42 return modelcmd.BootstrapContext(coretesting.Context(c)) 43 }