func (s *providerSuite) TestNullAlias(c *gc.C) { p, err := environs.Provider("manual") c.Assert(p, gc.NotNil) c.Assert(err, gc.IsNil) p, err = environs.Provider("null") c.Assert(p, gc.NotNil) c.Assert(err, gc.IsNil) }
func (s *MainSuite) TestProvidersAreRegistered(c *gc.C) { // check that all the expected providers are registered for _, name := range expectedProviders { _, err := environs.Provider(name) c.Assert(err, gc.IsNil) } }
func (s *BootstrapSuite) makeTestEnv(c *gc.C) { attrs := dummy.SampleConfig().Merge( testing.Attrs{ "agent-version": version.Current.Number.String(), }, ).Delete("admin-secret", "ca-private-key") cfg, err := config.New(config.NoDefaults, attrs) c.Assert(err, gc.IsNil) provider, err := environs.Provider(cfg.Type()) c.Assert(err, gc.IsNil) env, err := provider.Prepare(nullContext(), cfg) c.Assert(err, gc.IsNil) envtesting.MustUploadFakeTools(env.Storage()) inst, _, _, err := jujutesting.StartInstance(env, "0") c.Assert(err, gc.IsNil) s.instanceId = inst.Id() s.bootstrapName, err = inst.DNSName() c.Assert(err, gc.IsNil) s.envcfg = b64yaml(env.Config().AllAttrs()).encode() }
func (c *ValidateImageMetadataCommand) Run(context *cmd.Context) error { var params *simplestreams.MetadataLookupParams if c.providerType == "" { store, err := configstore.Default() if err != nil { return err } environ, err := environs.PrepareFromName(c.EnvName, context, store) if err != nil { return err } mdLookup, ok := environ.(simplestreams.MetadataValidator) if !ok { return fmt.Errorf("%s provider does not support image metadata validation", environ.Config().Type()) } params, err = mdLookup.MetadataLookupParams(c.region) if err != nil { return err } oes := &overrideEnvStream{environ, c.stream} params.Sources, err = imagemetadata.GetMetadataSources(oes) if err != nil { return err } } else { prov, err := environs.Provider(c.providerType) if err != nil { return err } mdLookup, ok := prov.(simplestreams.MetadataValidator) if !ok { return fmt.Errorf("%s provider does not support image metadata validation", c.providerType) } params, err = mdLookup.MetadataLookupParams(c.region) if err != nil { return err } } if c.series != "" { params.Series = c.series } if c.region != "" { params.Region = c.region } if c.endpoint != "" { params.Endpoint = c.endpoint } if c.metadataDir != "" { dir := filepath.Join(c.metadataDir, "images") if _, err := os.Stat(dir); err != nil { return err } params.Sources = []simplestreams.DataSource{ simplestreams.NewURLDataSource( "local metadata directory", "file://"+dir, utils.VerifySSLHostnames), } } params.Stream = c.stream image_ids, resolveInfo, err := imagemetadata.ValidateImageMetadata(params) if err != nil { if resolveInfo != nil { metadata := map[string]interface{}{ "Resolve Metadata": *resolveInfo, } if metadataYaml, yamlErr := cmd.FormatYaml(metadata); yamlErr == nil { err = fmt.Errorf("%v\n%v", err, string(metadataYaml)) } } return err } if len(image_ids) > 0 { metadata := map[string]interface{}{ "ImageIds": image_ids, "Region": params.Region, "Resolve Metadata": *resolveInfo, } c.out.Write(context, metadata) } else { var sources []string for _, s := range params.Sources { url, err := s.URL("") if err == nil { sources = append(sources, fmt.Sprintf("- %s (%s)", s.Description(), url)) } } return fmt.Errorf( "no matching image ids for region %s using sources:\n%s", params.Region, strings.Join(sources, "\n")) } return nil }