Merge lp:~rvb/gwacl/exclude-daily into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 143
Merged at revision: 142
Proposed branch: lp:~rvb/gwacl/exclude-daily
Merge into: lp:gwacl
Diff against target: 75 lines (+28/-5)
2 files modified
xmlobjects.go (+11/-5)
xmlobjects_test.go (+17/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/exclude-daily
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+171837@code.launchpad.net

Commit message

Exclude daily builds from the list of images we are using.

Description of the change

While debugging something today with smoser I found that gwacl is using daily images instead of released images. This is due to the fact that, when GetLatestUbuntuImage() was written, only released versions of Ubuntu where present in Azure.

In the long run, GetLatestUbuntuImage() might be replaced by simplestreams but in the meantime, we're stuck with the list of images that Azure gives us.

This branch changes GetLatestUbuntuImage() so that it won't pick daily builds and thus pick released images.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks good.

[1]

+func (suite *xmlSuite) TestIsDailyBuild(c *C) {
+    var testValues = []struct {
+        image          *OSImage
+        expectedResult bool
+    }{
+        {&OSImage{Label: "Ubuntu Server 12.04.2 LTS DAILY"}, true},
+        {&OSImage{Label: "Ubuntu Server 12.04.2 LTS"}, false},
+        {&OSImage{Label: "Ubuntu Server 13.04"}, false},
+    }
+    for _, test := range testValues {
+        c.Check(test.image.isDailyBuild(), Equals, test.expectedResult)
+    }
+}

Go's typing boilerplate makes this much longer and less readable than
doing it the stupid way:

func (suite *xmlSuite) TestIsDailyBuild(c *C) {
    c.Check(OSImage{Label: "Ubuntu Server 12.04.2 LTS DAILY"}.isDailyBuild(), Equals, true)
    c.Check(OSImage{Label: "Ubuntu Server 12.04.2 LTS"}.isDailyBuild(), Equals, false),
    c.Check(OSImage{Label: "Ubuntu Server 13.04"}.isDailyBuild(), Equals, false),
}

review: Approve
lp:~rvb/gwacl/exclude-daily updated
143. By Raphaël Badin

Simplify tests.

Revision history for this message
Raphaël Badin (rvb) wrote :

> Looks good.
>
>
> [1]
>
> +func (suite *xmlSuite) TestIsDailyBuild(c *C) {
> +    var testValues = []struct {
> +        image          *OSImage
> +        expectedResult bool
> +    }{
> +        {&OSImage{Label: "Ubuntu Server 12.04.2 LTS DAILY"}, true},
> +        {&OSImage{Label: "Ubuntu Server 12.04.2 LTS"}, false},
> +        {&OSImage{Label: "Ubuntu Server 13.04"}, false},
> +    }
> +    for _, test := range testValues {
> +        c.Check(test.image.isDailyBuild(), Equals, test.expectedResult)
> +    }
> +}
>
> Go's typing boilerplate makes this much longer and less readable than
> doing it the stupid way:
>
> func (suite *xmlSuite) TestIsDailyBuild(c *C) {
>    c.Check(OSImage{Label: "Ubuntu Server 12.04.2 LTS DAILY"}.isDailyBuild(),
> Equals, true)
>    c.Check(OSImage{Label: "Ubuntu Server 12.04.2 LTS"}.isDailyBuild(),
> Equals, false),
>    c.Check(OSImage{Label: "Ubuntu Server 13.04"}.isDailyBuild(), Equals,
> false),
> }

Okay, thanks for the review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'xmlobjects.go'
2--- xmlobjects.go 2013-06-27 11:53:50 +0000
3+++ xmlobjects.go 2013-06-27 16:18:34 +0000
4@@ -123,10 +123,10 @@
5 return dateI.After(dateJ)
6 }
7
8-// GetLatestUbuntuImage returns the most recent available OSImage, for the given release name
9-// and location. The 'releaseName' parameter is the Ubuntu version number
10-// present in the 'ImageFamily' tag present in Azure's representation of an OS Image
11-// (e.g. '12.04', '12.10').
12+// GetLatestUbuntuImage returns the most recent released available OSImage,
13+// for the given release name and location. The 'releaseName' parameter is
14+// the Ubuntu version number present in the 'ImageFamily' tag present in
15+// Azure's representation of an OS Image (e.g. '12.04', '12.10').
16 func (images *Images) GetLatestUbuntuImage(releaseName string, location string) (image *OSImage, err error) {
17 // The Less method defined above can panic if one of the published dates cannot be parsed,
18 // this code recovers from that and transforms that into an error.
19@@ -141,7 +141,8 @@
20 for _, image := range images.Images {
21 if image.PublisherName == canonicalPublisherName &&
22 matcherRegexp.MatchString(image.ImageFamily) &&
23- image.hasLocation(location) {
24+ image.hasLocation(location) &&
25+ !image.isDailyBuild() {
26 matchingImages.Images = append(matchingImages.Images, image)
27 }
28 }
29@@ -192,6 +193,11 @@
30 return false
31 }
32
33+// isDailyBuild returns whether this image is a daily build.
34+func (image *OSImage) isDailyBuild() bool {
35+ return strings.Contains(image.Label, "DAILY")
36+}
37+
38 func (i *OSImage) Deserialize(data []byte) error {
39 return xml.Unmarshal(data, i)
40 }
41
42=== modified file 'xmlobjects_test.go'
43--- xmlobjects_test.go 2013-06-27 11:53:50 +0000
44+++ xmlobjects_test.go 2013-06-27 16:18:34 +0000
45@@ -1246,6 +1246,12 @@
46 }
47 }
48
49+func (suite *xmlSuite) TestIsDailyBuild(c *C) {
50+ c.Check((&OSImage{Label: "Ubuntu Server 12.04.2 LTS DAILY"}).isDailyBuild(), Equals, true)
51+ c.Check((&OSImage{Label: "Ubuntu Server 12.04.2 LTS"}).isDailyBuild(), Equals, false)
52+ c.Check((&OSImage{Label: "Ubuntu Server 13.04"}).isDailyBuild(), Equals, false)
53+}
54+
55 func (suite *xmlSuite) TestSortImages(c *C) {
56 input := `
57 <?xml version="1.0"?>
58@@ -1312,6 +1318,17 @@
59 </OSImage>
60 <OSImage>
61 <Category>Canonical</Category>
62+ <Label>Ubuntu Server 13.04 DAILY</Label>
63+ <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
64+ <LogicalSizeInGB>30</LogicalSizeInGB>
65+ <Name>fake-name__Ubuntu-13_04-amd64-server-20130423-en-us-30GB</Name>
66+ <OS>Linux</OS>
67+ <ImageFamily>Ubuntu Server 13.04</ImageFamily>
68+ <PublishedDate>2013-06-25T00:00:00Z</PublishedDate>
69+ <PublisherName>Canonical</PublisherName>
70+ </OSImage>
71+ <OSImage>
72+ <Category>Canonical</Category>
73 <Label>Ubuntu Server 13.04</Label>
74 <Location>East Asia;Southeast Asia;North Europe;West Europe;East US;West US</Location>
75 <LogicalSizeInGB>30</LogicalSizeInGB>

Subscribers

People subscribed via source and target branches

to all changes: