// MakeConfig creates a functional environConfig for a test. func MakeConfig(c *gc.C, attrs testing.Attrs) *environConfig { cfg, err := config.New(config.NoDefaults, attrs) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) return env.(*joyentEnviron).Ecfg() }
func (*OpenSuite) TestPrepareGeneratesDifferentAdminSecrets(c *gc.C) { baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{ "state-server": false, "name": "erewhemos", }).Delete( "admin-secret", ) cfg, err := config.New(config.NoDefaults, baselineAttrs) c.Assert(err, gc.IsNil) ctx := testing.Context(c) env0, err := environs.Prepare(cfg, ctx, configstore.NewMem()) c.Assert(err, gc.IsNil) adminSecret0 := env0.Config().AdminSecret() c.Assert(adminSecret0, gc.HasLen, 32) c.Assert(adminSecret0, gc.Matches, "^[0-9a-f]*$") env1, err := environs.Prepare(cfg, ctx, configstore.NewMem()) c.Assert(err, gc.IsNil) adminSecret1 := env1.Config().AdminSecret() c.Assert(adminSecret1, gc.HasLen, 32) c.Assert(adminSecret1, gc.Matches, "^[0-9a-f]*$") c.Assert(adminSecret1, gc.Not(gc.Equals), adminSecret0) }
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) { if !t.HasProvisioner { c.Skip("HasProvisioner is false; cannot test deployment") } current := version.Current other := current other.Series = "quantal" if current == other { other.Series = "precise" } dummyCfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(coretesting.Attrs{ "state-server": false, "name": "dummy storage", })) dummyenv, err := environs.Prepare(dummyCfg, coretesting.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) defer dummyenv.Destroy() t.Destroy(c) attrs := t.TestConfig.Merge(coretesting.Attrs{"default-series": other.Series}) cfg, err := config.New(config.NoDefaults, attrs) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore) c.Assert(err, gc.IsNil) defer environs.Destroy(env, t.ConfigStore) currentName := envtools.StorageName(current) otherName := envtools.StorageName(other) envStorage := env.Storage() dummyStorage := dummyenv.Storage() defer envStorage.Remove(otherName) _, err = sync.Upload(dummyStorage, ¤t.Number) c.Assert(err, gc.IsNil) // This will only work while cross-compiling across releases is safe, // which depends on external elements. Tends to be safe for the last // few releases, but we may have to refactor some day. err = storageCopy(dummyStorage, currentName, envStorage, otherName) c.Assert(err, gc.IsNil) err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) st := t.Env.(testing.GetStater).GetStateInAPIServer() // Wait for machine agent to come up on the bootstrap // machine and ensure it deployed the proper series. m0, err := st.Machine("0") c.Assert(err, gc.IsNil) mw0 := newMachineToolWaiter(m0) defer mw0.Stop() waitAgentTools(c, mw0, other) }
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) { if !t.HasProvisioner { c.Skip("HasProvisioner is false; cannot test deployment") } current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } other := current other.Series = "quantal" if current == other { other.Series = "precise" } dummyCfg := dummy.SampleConfig().Merge(coretesting.Attrs{ "controller": false, "name": "dummy storage", }) args := t.prepareForBootstrapParams(c) args.BaseConfig = dummyCfg dummyenv, err := environs.Prepare(envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), args, ) c.Assert(err, jc.ErrorIsNil) defer dummyenv.Destroy() t.Destroy(c) attrs := t.TestConfig.Merge(coretesting.Attrs{ "name": "livetests", "default-series": other.Series, }) args.BaseConfig = attrs env, err := environs.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args) c.Assert(err, jc.ErrorIsNil) defer environs.Destroy("livetests", env, t.ControllerStore) err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) st := t.Env.(jujutesting.GetStater).GetStateInAPIServer() // Wait for machine agent to come up on the bootstrap // machine and ensure it deployed the proper series. m0, err := st.Machine("0") c.Assert(err, jc.ErrorIsNil) mw0 := newMachineToolWaiter(m0) defer mw0.Stop() waitAgentTools(c, mw0, other) }
func (*OpenSuite) TestPrepare(c *gc.C) { baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{ "state-server": false, "name": "erewhemos", }).Delete( "ca-cert", "ca-private-key", "admin-secret", "uuid", ) cfg, err := config.New(config.NoDefaults, baselineAttrs) c.Assert(err, gc.IsNil) store := configstore.NewMem() ctx := testing.Context(c) env, err := environs.Prepare(cfg, ctx, store) c.Assert(err, gc.IsNil) // Check we can access storage ok, which implies the environment has been prepared. c.Assert(env.Storage(), gc.NotNil) // Check that the environment info file was correctly created. info, err := store.ReadInfo("erewhemos") c.Assert(err, gc.IsNil) c.Assert(info.Initialized(), jc.IsTrue) c.Assert(info.BootstrapConfig(), gc.DeepEquals, env.Config().AllAttrs()) c.Logf("bootstrap config: %#v", info.BootstrapConfig()) // Check that an admin-secret was chosen. adminSecret := env.Config().AdminSecret() c.Assert(adminSecret, gc.HasLen, 32) c.Assert(adminSecret, gc.Matches, "^[0-9a-f]*$") // Check that the CA cert was generated. cfgCertPEM, cfgCertOK := env.Config().CACert() cfgKeyPEM, cfgKeyOK := env.Config().CAPrivateKey() c.Assert(cfgCertOK, gc.Equals, true) c.Assert(cfgKeyOK, gc.Equals, true) // Check the common name of the generated cert caCert, _, err := cert.ParseCertAndKey(cfgCertPEM, cfgKeyPEM) c.Assert(err, gc.IsNil) c.Assert(caCert.Subject.CommonName, gc.Equals, `juju-generated CA for environment "`+testing.SampleEnvName+`"`) // Check that a uuid was chosen. uuid, exists := env.Config().UUID() c.Assert(exists, gc.Equals, true) c.Assert(uuid, gc.Matches, `[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`) // Check we can call Prepare again. env, err = environs.Prepare(cfg, ctx, store) c.Assert(err, gc.IsNil) c.Assert(env.Storage(), gc.NotNil) c.Assert(env.Config().AllAttrs(), gc.DeepEquals, info.BootstrapConfig()) }
func (*OpenSuite) TestPrepare(c *gc.C) { baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{ "controller": false, "name": "erewhemos", }).Delete( "ca-cert", "ca-private-key", "admin-secret", ) cfg, err := config.New(config.NoDefaults, baselineAttrs) c.Assert(err, jc.ErrorIsNil) controllerStore := jujuclienttesting.NewMemStore() ctx := envtesting.BootstrapContext(c) env, err := environs.Prepare(ctx, controllerStore, environs.PrepareParams{ ControllerName: cfg.Name(), BaseConfig: cfg.AllAttrs(), CloudName: "dummy", }) c.Assert(err, jc.ErrorIsNil) // Check that an admin-secret was chosen. adminSecret := env.Config().AdminSecret() c.Assert(adminSecret, gc.HasLen, 32) c.Assert(adminSecret, gc.Matches, "^[0-9a-f]*$") // Check that the CA cert was generated. cfgCertPEM, cfgCertOK := env.Config().CACert() cfgKeyPEM, cfgKeyOK := env.Config().CAPrivateKey() c.Assert(cfgCertOK, jc.IsTrue) c.Assert(cfgKeyOK, jc.IsTrue) // Check the common name of the generated cert caCert, _, err := cert.ParseCertAndKey(cfgCertPEM, cfgKeyPEM) c.Assert(err, jc.ErrorIsNil) c.Assert(caCert.Subject.CommonName, gc.Equals, `juju-generated CA for model "`+testing.SampleModelName+`"`) // Check that controller was cached foundController, err := controllerStore.ControllerByName(cfg.Name()) c.Assert(err, jc.ErrorIsNil) c.Assert(foundController.ControllerUUID, gc.DeepEquals, cfg.UUID()) // Check we cannot call Prepare again. env, err = environs.Prepare(ctx, controllerStore, environs.PrepareParams{ ControllerName: cfg.Name(), BaseConfig: cfg.AllAttrs(), CloudName: "dummy", }) c.Assert(err, jc.Satisfies, errors.IsAlreadyExists) c.Assert(err, gc.ErrorMatches, `controller "erewhemos" already exists`) }
func (s *Suite) SetUpTest(c *gc.C) { // Set up InitialConfig with a dummy provider configuration. This // is required to allow model import test to work. env, err := environs.Prepare( modelcmd.BootstrapContext(testing.Context(c)), jujuclienttesting.NewMemStore(), environs.PrepareParams{ ControllerName: "dummycontroller", BaseConfig: dummy.SampleConfig(), CloudName: "dummy", }, ) c.Assert(err, jc.ErrorIsNil) s.InitialConfig = testing.CustomModelConfig(c, env.Config().AllAttrs()) // The call up to StateSuite's SetUpTest uses s.InitialConfig so // it has to happen here. s.StateSuite.SetUpTest(c) s.resources = common.NewResources() s.AddCleanup(func(*gc.C) { s.resources.StopAll() }) s.authorizer = apiservertesting.FakeAuthorizer{ Tag: s.Owner, } }
func (s *funcSuite) SetUpTest(c *gc.C) { s.baseImageMetadataSuite.SetUpTest(c) var err error s.env, err = environs.Prepare( envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), environs.PrepareParams{ ControllerName: "dummycontroller", BaseConfig: mockConfig(), CloudName: "dummy", }, ) c.Assert(err, jc.ErrorIsNil) s.state = s.constructState(s.env.Config()) s.expected = cloudimagemetadata.Metadata{ cloudimagemetadata.MetadataAttributes{ Stream: "released", Source: "custom", Series: config.LatestLtsSeries(), Arch: "amd64", Region: "dummy_region", }, 0, "", } }
func (s *OpenSuite) TestUpdateEnvInfo(c *gc.C) { store := jujuclienttesting.NewMemStore() ctx := envtesting.BootstrapContext(c) cfg, err := config.New(config.UseDefaults, map[string]interface{}{ "type": "dummy", "name": "admin-model", "controller-uuid": utils.MustNewUUID().String(), "uuid": utils.MustNewUUID().String(), }) c.Assert(err, jc.ErrorIsNil) _, err = environs.Prepare(ctx, store, environs.PrepareParams{ ControllerName: "controller-name", BaseConfig: cfg.AllAttrs(), CloudName: "dummy", }) c.Assert(err, jc.ErrorIsNil) foundController, err := store.ControllerByName("controller-name") c.Assert(err, jc.ErrorIsNil) c.Assert(foundController.ControllerUUID, gc.Equals, cfg.ControllerUUID()) c.Assert(foundController.CACert, gc.Not(gc.Equals), "") foundModel, err := store.ModelByName("controller-name", "admin@local", "admin-model") c.Assert(err, jc.ErrorIsNil) c.Assert(foundModel, jc.DeepEquals, &jujuclient.ModelDetails{ ModelUUID: cfg.UUID(), }) }
func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) { s.PatchValue(&jujuversion.Current, testing.FakeVersionNumber) // matches *Settings.Map() cfg, err := config.New(config.NoDefaults, dummySampleConfig()) c.Assert(err, jc.ErrorIsNil) ctx := envtesting.BootstrapContext(c) cache := jujuclienttesting.NewMemStore() env, err := environs.Prepare(ctx, cache, environs.PrepareParams{ ControllerName: cfg.Name(), BaseConfig: cfg.AllAttrs(), CloudName: "dummy", }) c.Assert(err, jc.ErrorIsNil) storageDir := c.MkDir() s.PatchValue(&envtools.DefaultBaseURL, storageDir) stor, err := filestorage.NewFileStorageWriter(storageDir) c.Assert(err, jc.ErrorIsNil) envtesting.UploadFakeTools(c, stor, cfg.AgentStream(), cfg.AgentStream()) err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) // New controller should have been added to collection. foundController, err := cache.ControllerByName(cfg.Name()) c.Assert(err, jc.ErrorIsNil) c.Assert(foundController.ControllerUUID, gc.DeepEquals, cfg.UUID()) }
func (*OpenSuite) TestDestroy(c *gc.C) { cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge( testing.Attrs{ "name": "erewhemos", }, )) c.Assert(err, jc.ErrorIsNil) store := jujuclienttesting.NewMemStore() // Prepare the environment and sanity-check that // the config storage info has been made. ctx := envtesting.BootstrapContext(c) e, err := environs.Prepare(ctx, store, environs.PrepareParams{ ControllerName: "controller-name", BaseConfig: cfg.AllAttrs(), CloudName: "dummy", }) c.Assert(err, jc.ErrorIsNil) _, err = store.ControllerByName("controller-name") c.Assert(err, jc.ErrorIsNil) err = environs.Destroy("controller-name", e, store) c.Assert(err, jc.ErrorIsNil) // Check that the environment has actually been destroyed // and that the controller details been removed too. _, err = e.ControllerInstances() c.Assert(err, gc.ErrorMatches, "model is not prepared") _, err = store.ControllerByName("controller-name") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) { s.FakeJujuXDGDataHomeSuite.SetUpTest(c) s.AddCleanup(dummy.Reset) s.AddCleanup(func(*gc.C) { loggo.ResetLoggers() }) cfg, err := config.New(config.UseDefaults, map[string]interface{}{ "name": "erewhemos", "type": "dummy", "uuid": coretesting.ModelTag.Id(), "controller-uuid": coretesting.ModelTag.Id(), "conroller": true, }) c.Assert(err, jc.ErrorIsNil) env, err := environs.Prepare( modelcmd.BootstrapContextNoVerify(coretesting.Context(c)), jujuclienttesting.NewMemStore(), environs.PrepareParams{ ControllerName: cfg.Name(), BaseConfig: cfg.AllAttrs(), CloudName: "dummy", }, ) c.Assert(err, jc.ErrorIsNil) s.env = env loggo.GetLogger("").SetLogLevel(loggo.INFO) // Switch the default tools location. s.publicStorageDir = c.MkDir() s.PatchValue(&tools.DefaultBaseURL, s.publicStorageDir) }
func (*NewAPIStateSuite) TestNewAPIState(c *gc.C) { cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) c.Assert(err, gc.IsNil) ctx := coretesting.Context(c) env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) c.Assert(err, gc.IsNil) envtesting.UploadFakeTools(c, env.Storage()) err = bootstrap.Bootstrap(ctx, env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) cfg = env.Config() cfg, err = cfg.Apply(map[string]interface{}{ "secret": "fnord", }) c.Assert(err, gc.IsNil) err = env.SetConfig(cfg) c.Assert(err, gc.IsNil) st, err := juju.NewAPIState(env, api.DialOpts{}) c.Assert(st, gc.NotNil) // the secrets will not be updated, as they already exist attrs, err := st.Client().EnvironmentGet() c.Assert(attrs["secret"], gc.Equals, "pork") c.Assert(st.Close(), gc.IsNil) }
func (t *ProviderSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) { // Make an env configured with the stream. envAttrs := localConfigAttrs if stream != "" { envAttrs = envAttrs.Merge(coretesting.Attrs{ "image-stream": stream, }) } cfg, err := config.New(config.NoDefaults, envAttrs) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) c.Assert(env, gc.NotNil) sources, err := imagemetadata.GetMetadataSources(env) c.Assert(err, gc.IsNil) c.Assert(len(sources), gc.Equals, 2) var urls = make([]string, len(sources)) for i, source := range sources { url, err := source.URL("") c.Assert(err, gc.IsNil) urls[i] = url } // The control bucket URL contains the bucket name. c.Check(strings.Contains(urls[0], ec2.ControlBucketName(env)+"/images"), jc.IsTrue) c.Assert(urls[1], gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath)) }
func (t *localNonUSEastSuite) SetUpTest(c *gc.C) { t.BaseSuite.SetUpTest(c) t.srv.config = &s3test.Config{ Send409Conflict: true, } t.srv.startServer(c) env, err := environs.Prepare( envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), environs.PrepareParams{ BaseConfig: localConfigAttrs, Credential: cloud.NewCredential( cloud.AccessKeyAuthType, map[string]string{ "access-key": "x", "secret-key": "x", }, ), ControllerName: localConfigAttrs["name"].(string), CloudName: "ec2", CloudRegion: "test", }, ) c.Assert(err, jc.ErrorIsNil) t.env = env }
func (cs *NewAPIStateSuite) TestNewAPIState(c *gc.C) { cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) c.Assert(err, jc.ErrorIsNil) ctx := envtesting.BootstrapContext(c) env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) c.Assert(err, jc.ErrorIsNil) storageDir := c.MkDir() cs.PatchValue(&envtools.DefaultBaseURL, storageDir) stor, err := filestorage.NewFileStorageWriter(storageDir) c.Assert(err, jc.ErrorIsNil) envtesting.UploadFakeTools(c, stor, "released", "released") err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) cfg = env.Config() cfg, err = cfg.Apply(map[string]interface{}{ "secret": "fnord", }) c.Assert(err, jc.ErrorIsNil) err = env.SetConfig(cfg) c.Assert(err, jc.ErrorIsNil) st, err := juju.NewAPIState(dummy.AdminUserTag(), env, api.DialOpts{}) c.Assert(st, gc.NotNil) // the secrets will not be updated, as they already exist attrs, err := st.Client().EnvironmentGet() c.Assert(attrs["secret"], gc.Equals, "pork") c.Assert(st.Close(), gc.IsNil) }
// If the environment is configured not to require a public IP address for nodes, // bootstrapping and starting an instance should occur without any attempt to // allocate a public address. func (s *localServerSuite) TestStartInstanceWithoutPublicIP(c *gc.C) { cleanup := s.srv.Service.Nova.RegisterControlPoint( "addFloatingIP", func(sc hook.ServiceControl, args ...interface{}) error { return fmt.Errorf("add floating IP should not have been called") }, ) defer cleanup() cleanup = s.srv.Service.Nova.RegisterControlPoint( "addServerFloatingIP", func(sc hook.ServiceControl, args ...interface{}) error { return fmt.Errorf("add server floating IP should not have been called") }, ) defer cleanup() cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{ "use-floating-ip": false, })) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, coretesting.Context(c), s.ConfigStore) c.Assert(err, gc.IsNil) err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) inst, _ := testing.AssertStartInstance(c, env, "100") err = env.StopInstances(inst.Id()) c.Assert(err, gc.IsNil) }
func (*OpenSuite) TestDestroy(c *gc.C) { cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge( testing.Attrs{ "state-server": false, "name": "erewhemos", }, )) c.Assert(err, gc.IsNil) store := configstore.NewMem() // Prepare the environment and sanity-check that // the config storage info has been made. ctx := testing.Context(c) e, err := environs.Prepare(cfg, ctx, store) c.Assert(err, gc.IsNil) _, err = store.ReadInfo(e.Config().Name()) c.Assert(err, gc.IsNil) err = environs.Destroy(e, store) c.Assert(err, gc.IsNil) // Check that the environment has actually been destroyed // and that the config info has been destroyed too. _, err = e.StateServerInstances() c.Assert(err, gc.ErrorMatches, "environment has been destroyed") _, err = store.ReadInfo(e.Config().Name()) c.Assert(err, jc.Satisfies, errors.IsNotFound) }
// mockTestingEnvConfig prepares an environment configuration using // the mock provider which does not support networking. func mockTestingEnvConfig(c *gc.C) *config.Config { cfg, err := config.New(config.NoDefaults, mockConfig()) c.Assert(err, jc.ErrorIsNil) env, err := environs.Prepare(cfg, modelcmd.BootstrapContext(coretesting.Context(c)), configstore.NewMem()) c.Assert(err, jc.ErrorIsNil) return env.Config() }
func (c *ImageMetadataCommandBase) prepare(context *cmd.Context, store configstore.Storage) (environs.Environ, error) { cfg, err := c.Config(store) if err != nil { return nil, errors.Annotate(err, "could not get config from store") } return environs.Prepare(cfg, context, store) }
// testingEnvConfig prepares an environment configuration using // the dummy provider. func testingEnvConfig(c *gc.C) *config.Config { cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) c.Assert(err, jc.ErrorIsNil) env, err := environs.Prepare(cfg, envcmd.BootstrapContext(testing.Context(c)), configstore.NewMem()) c.Assert(err, jc.ErrorIsNil) return env.Config() }
func (s *ConfigSuite) TestFirewallMode(c *gc.C) { for i, test := range firewallModeTests { c.Logf("test %d: %s", i, test.configFirewallMode) attrs := dummy.SampleConfig() if test.configFirewallMode != "" { attrs = attrs.Merge(testing.Attrs{ "firewall-mode": test.configFirewallMode, }) } cfg, err := config.New(config.NoDefaults, attrs) if err != nil { c.Assert(err, gc.ErrorMatches, test.errorMsg) continue } ctx := testing.Context(c) env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) if test.errorMsg != "" { c.Assert(err, gc.ErrorMatches, test.errorMsg) continue } c.Assert(err, gc.IsNil) defer env.Destroy() firewallMode := env.Config().FirewallMode() c.Assert(firewallMode, gc.Equals, test.firewallMode) s.TearDownTest(c) } }
func (s *NewAPIClientSuite) bootstrapModel(c *gc.C) (environs.Environ, jujuclient.ClientStore) { const controllerName = "local.my-controller" store := jujuclienttesting.NewMemStore() ctx := envtesting.BootstrapContext(c) env, err := environs.Prepare(ctx, store, environs.PrepareParams{ ControllerName: controllerName, BaseConfig: dummy.SampleConfig(), CloudName: "dummy", }) c.Assert(err, jc.ErrorIsNil) storageDir := c.MkDir() s.PatchValue(&envtools.DefaultBaseURL, storageDir) stor, err := filestorage.NewFileStorageWriter(storageDir) c.Assert(err, jc.ErrorIsNil) envtesting.UploadFakeTools(c, stor, "released", "released") err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) return env, store }
func (s *StorageSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetUpTest(c) cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) c.Assert(err, gc.IsNil) s.env, err = environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) s.dataDir = c.MkDir() }
// Prepare prepares an instance of the testing environment. func (t *Tests) Prepare(c *gc.C) environs.Environ { cfg, err := config.New(config.NoDefaults, t.TestConfig) c.Assert(err, gc.IsNil) e, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore) c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig)) c.Assert(e, gc.NotNil) return e }
func (s *uploadSuite) SetUpTest(c *gc.C) { s.FakeJujuHomeSuite.SetUpTest(c) s.ToolsFixture.SetUpTest(c) // We only want to use simplestreams to find any synced tools. cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) c.Assert(err, gc.IsNil) s.env, err = environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) }
func (s *SimpleStreamsToolsSuite) resetEnv(c *gc.C, attrs map[string]interface{}) { version.Current = s.origCurrentVersion dummy.Reset() cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(attrs)) c.Assert(err, jc.ErrorIsNil) env, err := environs.Prepare(cfg, envtesting.BootstrapContext(c), configstore.NewMem()) c.Assert(err, jc.ErrorIsNil) s.env = env s.removeTools(c) }
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) { if !t.HasProvisioner { c.Skip("HasProvisioner is false; cannot test deployment") } current := version.Current other := current other.Series = "quantal" if current == other { other.Series = "precise" } dummyCfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(coretesting.Attrs{ "state-server": false, "name": "dummy storage", })) dummyenv, err := environs.Prepare(dummyCfg, envtesting.BootstrapContext(c), configstore.NewMem()) c.Assert(err, jc.ErrorIsNil) defer dummyenv.Destroy() t.Destroy(c) attrs := t.TestConfig.Merge(coretesting.Attrs{"default-series": other.Series}) cfg, err := config.New(config.NoDefaults, attrs) c.Assert(err, jc.ErrorIsNil) env, err := environs.Prepare(cfg, envtesting.BootstrapContext(c), t.ConfigStore) c.Assert(err, jc.ErrorIsNil) defer environs.Destroy(env, t.ConfigStore) err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) st := t.Env.(jujutesting.GetStater).GetStateInAPIServer() // Wait for machine agent to come up on the bootstrap // machine and ensure it deployed the proper series. m0, err := st.Machine("0") c.Assert(err, jc.ErrorIsNil) mw0 := newMachineToolWaiter(m0) defer mw0.Stop() waitAgentTools(c, mw0, other) }
func (*OpenSuite) TestNewDummyEnviron(c *gc.C) { // matches *Settings.Map() cfg, err := config.New(config.NoDefaults, dummySampleConfig()) c.Assert(err, gc.IsNil) ctx := testing.Context(c) env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) c.Assert(err, gc.IsNil) envtesting.UploadFakeTools(c, env.Storage()) err = bootstrap.Bootstrap(ctx, env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) }
func (c *imageMetadataCommandBase) prepare(context *cmd.Context, store configstore.Storage) (environs.Environ, error) { cfg, err := c.Config(store, nil) if err != nil { return nil, errors.Annotate(err, "could not get config from store") } // We are preparing an environment to access parameters needed to access // image metadata. We don't need, nor want, credential verification. // In most cases, credentials will not be available. ctx := envcmd.BootstrapContextNoVerify(context) return environs.Prepare(cfg, ctx, store) }