Merge lp:~elopio/snappy-tests-job/flavor into lp:snappy-tests-job

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 72
Merged at revision: 70
Proposed branch: lp:~elopio/snappy-tests-job/flavor
Merge into: lp:snappy-tests-job
Diff against target: 221 lines (+29/-32)
6 files modified
cloud/cloud.go (+3/-4)
cloud/cloud_test.go (+1/-1)
cloud/openstack.go (+8/-9)
cloud/openstack_test.go (+13/-14)
cmd/snappy-cloud-client/main.go (+2/-2)
cmd/snappy-tests-job/main.go (+2/-2)
To merge this branch: bzr merge lp:~elopio/snappy-tests-job/flavor
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+279064@code.launchpad.net

Commit message

Moved the flavor argument to the Create method.

To post a comment you must log in.
lp:~elopio/snappy-tests-job/flavor updated
71. By Leo Arias

Improved the message.

72. By Leo Arias

Improved the message.

Revision history for this message
Federico Gimenez (fgimenez) wrote :

LGTM thanks Leo

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloud/cloud.go'
2--- cloud/cloud.go 2015-11-27 18:18:21 +0000
3+++ cloud/cloud.go 2015-12-01 03:50:30 +0000
4@@ -23,12 +23,11 @@
5
6 // Clouder is the interface for all the cloud clients
7 type Clouder interface {
8- CreateInstance(release, channel string) (ip string, id string, err error)
9+ CreateInstance(flavor, release, channel string) (ip string, id string, err error)
10 KillInstance() error
11 }
12
13 // NewCloudClient is the factory for the cloud clients of type "provider"
14-func NewCloudClient(provider, flavor string, util utils.Utilizer) Clouder {
15-
16- return NewOpenstackClient(flavor, util)
17+func NewCloudClient(provider string, util utils.Utilizer) Clouder {
18+ return NewOpenstackClient(util)
19 }
20
21=== modified file 'cloud/cloud_test.go'
22--- cloud/cloud_test.go 2015-11-27 16:29:33 +0000
23+++ cloud/cloud_test.go 2015-12-01 03:50:30 +0000
24@@ -30,7 +30,7 @@
25
26 func (s *cloudSuite) TestNewOpenstackCloudClient(c *check.C) {
27 utilHandler := utils.NewBasicHandler()
28- subject := NewCloudClient("openstack", "m1.small", utilHandler)
29+ subject := NewCloudClient("openstack", utilHandler)
30 _, ok := subject.(*OpenstackClient)
31
32 c.Assert(ok, check.Equals, true,
33
34=== modified file 'cloud/openstack.go'
35--- cloud/openstack.go 2015-11-27 18:18:21 +0000
36+++ cloud/openstack.go 2015-12-01 03:50:30 +0000
37@@ -46,17 +46,16 @@
38 // OpenstackClient is the client for connecting to Openstack
39 type OpenstackClient struct {
40 Util utils.Utilizer
41- flavor string
42 InstanceID string
43 }
44
45 // CreateInstance launches a snappy instance from the latest image with the passed release
46 // and channel and returns its ip and id
47-func (c *OpenstackClient) CreateInstance(release, channel string) (ip string, id string, err error) {
48- log.Printf("*** Creating Snappy instance for release %s and channel %s ***", release, channel)
49+func (c *OpenstackClient) CreateInstance(flavor, release, channel string) (ip string, id string, err error) {
50+ log.Printf("*** Creating a Snappy %s instance for release %s and channel %s ***", flavor, release, channel)
51 imageID, err := c.listImages(release, channel)
52 if err == nil {
53- ip, id, err = c.launchInstance(imageID)
54+ ip, id, err = c.launchInstance(flavor, imageID)
55 }
56 return
57 }
58@@ -71,8 +70,8 @@
59 }
60
61 // NewOpenstackClient is OpenstackClient's constructor
62-func NewOpenstackClient(flavor string, util utils.Utilizer) *OpenstackClient {
63- return &OpenstackClient{flavor: flavor, Util: util}
64+func NewOpenstackClient(util utils.Utilizer) *OpenstackClient {
65+ return &OpenstackClient{Util: util}
66 }
67
68 func (c *OpenstackClient) imgTemplate(release, channel string) string {
69@@ -90,10 +89,10 @@
70 return
71 }
72
73-func (c *OpenstackClient) launchInstance(imageID string) (ip string, id string, err error) {
74- log.Printf("Launching instance for Snappy image %s", imageID)
75+func (c *OpenstackClient) launchInstance(flavor, imageID string) (ip string, id string, err error) {
76+ log.Printf("Launching a %s instance for Snappy image %s", flavor, imageID)
77
78- launchInstanceCmd := fmt.Sprintf(launchInstanceCmdTpl, c.flavor, imageID, os.Getpid())
79+ launchInstanceCmd := fmt.Sprintf(launchInstanceCmdTpl, flavor, imageID, os.Getpid())
80 params := utils.NewExecCommandParams("", strings.Fields(launchInstanceCmd), false)
81
82 output, err := c.Util.ExecCommand(params)
83
84=== modified file 'cloud/openstack_test.go'
85--- cloud/openstack_test.go 2015-11-27 18:18:21 +0000
86+++ cloud/openstack_test.go 2015-12-01 03:50:30 +0000
87@@ -31,6 +31,7 @@
88 )
89
90 const (
91+ defaultFlavor = "m1.quitelarge"
92 defaultRelease = "1504"
93 defaultChannel = "edge"
94 imageListTpl = `| e37ef727-014d-48e8-b0e4-94cf39e1dbbc | ubuntu-released/ubuntu-wily-alpha1-amd64-server-20150624-disk1.img | ACTIVE | |
95@@ -111,7 +112,6 @@
96 subject Clouder
97 instanceID string
98 imageID string
99- flavor string
100 imageList string
101 describeOutputPending string
102 describeOutputFinished string
103@@ -121,9 +121,8 @@
104
105 func (s *openstackSuite) SetUpTest(c *check.C) {
106 s.fakeUtil = testhelpers.NewFakeUtils()
107- s.flavor = "m1.quitelarge"
108
109- s.subject = NewOpenstackClient(s.flavor, s.fakeUtil)
110+ s.subject = NewOpenstackClient(s.fakeUtil)
111
112 s.instanceID = "instanceID1"
113 s.imageID = imgTemplate(defaultRelease, defaultChannel)
114@@ -140,7 +139,7 @@
115 }
116
117 func (s *openstackSuite) TestCreateInstanceCallsListImages(c *check.C) {
118- s.subject.CreateInstance(defaultRelease, defaultChannel)
119+ s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
120
121 cmdParams := utils.NewExecCommandParams("", strings.Fields(listImagesCmd), false)
122
123@@ -150,16 +149,16 @@
124
125 func (s *openstackSuite) TestCreateInstanceReturnsErrorOnListError(c *check.C) {
126 s.fakeUtil.FailExec = true
127- _, _, err := s.subject.CreateInstance(defaultRelease, defaultChannel)
128+ _, _, err := s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
129
130 c.Assert(err, check.NotNil, check.Commentf("Expected error from euca list images"))
131 }
132
133 func (s *openstackSuite) TestCreateInstanceDoesNotCreateNewInstanceOnListError(c *check.C) {
134 s.fakeUtil.FailExec = true
135- s.subject.CreateInstance(defaultRelease, defaultChannel)
136+ s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
137
138- cmd := s.launchInstanceCmd(s.imageID, s.flavor)
139+ cmd := s.launchInstanceCmd(s.imageID, defaultFlavor)
140 cmdParams := utils.NewExecCommandParams("", strings.Fields(cmd), false)
141
142 c.Assert(s.fakeUtil.ExecCalls[cmdParams.String()], check.Equals, 0,
143@@ -167,9 +166,9 @@
144 }
145
146 func (s *openstackSuite) TestCreateInstanceCallsLaunchInstance(c *check.C) {
147- s.subject.CreateInstance(defaultRelease, defaultChannel)
148+ s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
149
150- cmd := s.launchInstanceCmd(s.imageID, s.flavor)
151+ cmd := s.launchInstanceCmd(s.imageID, defaultFlavor)
152 cmdParams := utils.NewExecCommandParams("", strings.Fields(cmd), false)
153
154 c.Assert(s.fakeUtil.ExecCalls[cmdParams.String()], check.Equals, 1,
155@@ -177,21 +176,21 @@
156 }
157
158 func (s *openstackSuite) TestCreateInstanceReturnsInstanceIP(c *check.C) {
159- ip, _, _ := s.subject.CreateInstance(defaultRelease, defaultChannel)
160+ ip, _, _ := s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
161
162 c.Assert(ip, check.Equals, instanceIP,
163 check.Commentf("Expected instance IP not returned %s, got %s", instanceIP, ip))
164 }
165
166 func (s *openstackSuite) TestCreateInstanceReturnsInstanceID(c *check.C) {
167- _, id, _ := s.subject.CreateInstance(defaultRelease, defaultChannel)
168+ _, id, _ := s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
169
170 c.Assert(id, check.Equals, s.instanceID,
171 check.Commentf("Expected instance ID not returned %s, got %s", s.instanceID, id))
172 }
173
174 func (s *openstackSuite) TestKillInstanceCallsKillCommand(c *check.C) {
175- s.subject.CreateInstance(defaultRelease, defaultChannel)
176+ s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
177 s.subject.KillInstance()
178
179 cmd := s.killInstanceCmd()
180@@ -229,9 +228,9 @@
181 s.fakeUtil.ExecReturnValues = append(s.fakeUtil.ExecReturnValues, launchOutput)
182 s.fakeUtil.ExecReturnValues = append(s.fakeUtil.ExecReturnValues, s.describeOutputFinished)
183
184- s.subject.CreateInstance(defaultRelease, defaultChannel)
185+ s.subject.CreateInstance(defaultFlavor, defaultRelease, defaultChannel)
186
187- cmd := s.launchInstanceCmd(imageIDNew, s.flavor)
188+ cmd := s.launchInstanceCmd(imageIDNew, defaultFlavor)
189 cmdParams := utils.NewExecCommandParams("", strings.Fields(cmd), false)
190
191 c.Assert(s.fakeUtil.ExecCalls[cmdParams.String()], check.Equals, 1,
192
193=== modified file 'cmd/snappy-cloud-client/main.go'
194--- cmd/snappy-cloud-client/main.go 2015-11-30 15:31:26 +0000
195+++ cmd/snappy-cloud-client/main.go 2015-12-01 03:50:30 +0000
196@@ -53,8 +53,8 @@
197 switch os.Args[1] {
198 case "create":
199 if err := fCreate.Parse(os.Args[2:]); err == nil {
200- cloudClient := cloud.NewCloudClient(defaultCloudProvider, *flavor, utilHandler)
201- ip, id, err := cloudClient.CreateInstance(*release, *channel)
202+ cloudClient := cloud.NewCloudClient(defaultCloudProvider, utilHandler)
203+ ip, id, err := cloudClient.CreateInstance(*flavor, *release, *channel)
204 if err != nil {
205 log.Panicf("Error creating image for release %s and channel %s, %s", *release, *channel, err)
206 }
207
208=== modified file 'cmd/snappy-tests-job/main.go'
209--- cmd/snappy-tests-job/main.go 2015-11-27 18:18:21 +0000
210+++ cmd/snappy-tests-job/main.go 2015-12-01 03:50:30 +0000
211@@ -80,8 +80,8 @@
212
213 ipString := *ip
214 if ipString == "" {
215- cloudClient := cloud.NewCloudClient(*cloudProvider, *flavor, utilHandler)
216- ipString, _, err = cloudClient.CreateInstance(*release, *channel)
217+ cloudClient := cloud.NewCloudClient(*cloudProvider, utilHandler)
218+ ipString, _, err = cloudClient.CreateInstance(*flavor, *release, *channel)
219 defer cloudClient.KillInstance()
220
221 if err != nil {

Subscribers

People subscribed via source and target branches

to all changes: