// Fetch returns a list of images for the specified cloud matching the constraint. // The base URL locations are as specified - the first location which has a file is the one used. // Signed data is preferred, but if there is no signed data available and onlySigned is false, // then unsigned data is used. func Fetch( sources []simplestreams.DataSource, indexPath string, cons *ImageConstraint, onlySigned bool) ([]*ImageMetadata, *simplestreams.ResolveInfo, error) { params := simplestreams.ValueParams{ DataType: ImageIds, FilterFunc: appendMatchingImages, ValueTemplate: ImageMetadata{}, PublicKey: simplestreamsImagesPublicKey, } items, resolveInfo, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params) if err != nil { return nil, resolveInfo, err } metadata := make([]*ImageMetadata, len(items)) for i, md := range items { metadata[i] = md.(*ImageMetadata) } // Sorting the metadata is not strictly necessary, but it ensures consistent ordering for // all compilers, and it just makes it easier to look at the data. Sort(metadata) return metadata, resolveInfo, nil }
func (s *simplestreamsSuite) TestGetMetadataNoMatching(c *gc.C) { source := &countingSource{ DataSource: simplestreams.NewURLDataSource( "test", "test:/daily", utils.VerifySSLHostnames, ), } sources := []simplestreams.DataSource{source, source, source} params := simplestreams.ValueParams{DataType: "image-ids"} constraint := sstesting.NewTestConstraint(simplestreams.LookupParams{ CloudSpec: simplestreams.CloudSpec{ Region: "us-east-1", Endpoint: "https://ec2.us-east-1.amazonaws.com", }, Series: []string{"precise"}, Arches: []string{"not-a-real-arch"}, // never matches }) items, resolveInfo, err := simplestreams.GetMetadata( sources, simplestreams.DefaultIndexPath, constraint, false, params, ) c.Assert(err, gc.IsNil) c.Assert(items, gc.HasLen, 0) c.Assert(resolveInfo, gc.DeepEquals, &simplestreams.ResolveInfo{ Source: "test", Signed: false, IndexURL: "test:/daily/streams/v1/index.json", MirrorURL: "", }) // There should be 2 calls to each data-source: // one for .sjson, one for .json. c.Assert(source.count, gc.Equals, 2*len(sources)) }