GetMetadata was dropping out if a datasource
returned no matching product IDs, without an
error. I've changed it to check that a non-
empty list of products is returned before
bailing out.
Affected files (+71, -2 lines):
A [revision details]
M environs/simplestreams/simplestreams.go
M environs/simplestreams/simplestreams_test.go
M environs/simplestreams/testing/testing.go
Reviewers: mp+188758_ code.launchpad. net,
Message:
Please take a look.
Description: simplestreams: fix GetMetadata
environs/
GetMetadata was dropping out if a datasource
returned no matching product IDs, without an
error. I've changed it to check that a non-
empty list of products is returned before
bailing out.
Fixes #1233924
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1233924- simplestreams- getmetadata- fallback/ +merge/ 188758
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/14218044/
Affected files (+71, -2 lines): simplestreams/ simplestreams. go simplestreams/ simplestreams_ test.go simplestreams/ testing/ testing. go
A [revision details]
M environs/
M environs/
M environs/
Index: [revision details] 20131001213504- 4ynrkuya2i22q87 q
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: environs/ simplestreams/ simplestreams. go simplestreams/ simplestreams. go' simplestreams/ simplestreams. go 2013-09-27 07:05:45 +0000 simplestreams/ simplestreams. go 2013-10-02 03:04:13 +0000 net/loggo"
=== modified file 'environs/
--- environs/
+++ environs/
@@ -17,6 +17,7 @@
"io/ioutil"
"net/http"
"os"
+ "path"
"reflect"
"sort"
"strings"
@@ -25,7 +26,6 @@
"launchpad.
"launchpad. net/juju- core/errors"
- "path"
)
var logger = loggo.GetLogger ("juju. environs. simplestreams" ) etadata( source, baseIndexPath, cons, false,
@@ -403,7 +403,7 @@
if err != nil && len(items) == 0 && !onlySigned {
items, err = getMaybeSignedM
params)
}
- if err == nil {
+ if err == nil && len(items) != 0 {
break
}
}
Index: environs/ simplestreams/ simplestreams_ test.go simplestreams/ simplestreams_ test.go' simplestreams/ simplestreams_ test.go 2013-09-26 04:11:52 +0000 simplestreams/ simplestreams_ test.go 2013-10-02 03:04:13 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -9,9 +9,11 @@
"testing"
gc "launchpad. net/gocheck" net/loggo"
+ "launchpad.
"launchpad. net/juju- core/environs/ simplestreams" net/juju- core/environs/ simplestreams/ testing" net/juju- core/testing/ checkers"
sstesting "launchpad.
+ jc "launchpad.
)
func Test(t *testing.T) { dotOFormats, gc.DeepEquals, IndexMetadataSl ice{array[ 0], array[2]})
@@ -284,6 +286,47 @@
c.Check(
simplestreams.
}
+func (s *simplestreamsS uite) TestGetMetadata NoMatching( c *gc.C) { .DataSource{ NewURLDataSourc e("test: /daily" , VerifySSLHostna mes), NewURLDataSourc e("test: /daily" , VerifySSLHostna mes), ValueParams{ DataType: "image-ids"} NewTestConstrai nt(simplestream s.LookupParams{ CloudSpec{ /ec2.us- east-1. amazonaws. com", "precise" }, // never match loggo.RegisterW riter(" filter- tester" , tw, loggo.DEBUG), gc.IsNil) ter("filter- tester" ) GetMetadata( DefaultIndexPat h, uite) TestMetadataCat alog(c *gc.C) { data(c) len(metadata. Products) , gc.Equals, 2)
+ sources := []simplestreams
+ simplestreams.
simplestreams.
+ simplestreams.
simplestreams.
+ }
+ params := simplestreams.
+ constraint := sstesting.
+ CloudSpec: simplestreams.
+ Region: "us-east-1",
+ Endpoint: "https:/
+ },
+ Series: []string{
+ Arches: []string{"arm"},
+ })
+
+ tw := &loggo.TestWriter{}
+ c.Assert(
+ defer loggo.RemoveWri
+
+ items, err := simplestreams.
+ sources,
+ simplestreams.
+ constraint,
+ false,
+ params,
+ )
+ c.Assert(err, gc.IsNil)
+ c.Assert(items, gc.HasLen, 0)
+ messages := []jc.SimpleMessage{
+ {loggo.DEBUG, "cannot find URL.*sjson"},
+ {loggo.DEBUG, "cannot load index.*sjson"},
+ {loggo.DEBUG, "read metadata index at.*index\\.json"},
+ {loggo.DEBUG, "index file has no data for product name"},
+ }
+ // We should get duplicates of the messages, as the first
+ // data source returns nothing, causing GetMetadata to
+ // attempt the next one.
+ messages = append(messages, messages...)
+ c.Check(tw.Log, jc.LogMatches, messages)
+}
+
func (s *simplestreamsS
metadata := s.AssertGetMeta
c.Check(
Index: environs/ simplestreams/ testing/ testing. go simplestreams/ testing/ testing. go' simplestreams/ testing/ testing. go 2013-09-26 04:11:52 +0000 simplestreams/ testing/ testing. go 2013-10-02 03:04:13 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -17,6 +17,30 @@
)
var imageData = map[string]string{ streams/ v1/index. json": ` cloud:released: raring" : { /ec2.us- east-1. amazonaws. com" cloud:server: 13.04:amd64" v1/raring_ metadata. json" v1/index. json": `
+ "/daily/
+ {
+ "index": {
+ "com.ubuntu.
+ "updated": "Wed, 01 May 2013 13:31:26 +0000",
+ "clouds": [
+ {
+ "region": "us-east-1",
+ "endpoint": "https:/
+ }
+ ],
+ "cloudname": "aws",
+ "datatype": "image-ids",
+ "format": "products:1.0",
+ "products": [
+ "com.ubuntu.
+ ],
+ "path": "streams/
+ }
+ },
+ "updated": "Wed, 01 May 2013 13:31:26 +0000",
+ "format": "index:1.0"
+ }
+ `,
"/streams/
{
"index": {