Merge lp:~fgimenez/snappy-tests-job/generic-openstack-provider into lp:snappy-tests-job

Proposed by Federico Gimenez
Status: Merged
Approved by: Federico Gimenez
Approved revision: 68
Merged at revision: 68
Proposed branch: lp:~fgimenez/snappy-tests-job/generic-openstack-provider
Merge into: lp:snappy-tests-job
Diff against target: 325 lines (+39/-60)
7 files modified
cloud/cloud.go (+1/-1)
cloud/cloud_test.go (+4/-4)
cloud/openstack.go (+16/-17)
cloud/openstack_test.go (+17/-33)
data/user.yml (+0/-3)
debian/install (+0/-1)
snappy-tests-job/main.go (+1/-1)
To merge this branch: bzr merge lp:~fgimenez/snappy-tests-job/generic-openstack-provider
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+278846@code.launchpad.net

Commit message

generic openstack provider; also simplified nova boot command to be used with udf generated instances

Description of the change

Generic openstack provider, no more references to Canonistack; also simplified nova boot command to be used with udf generated instances

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

Ok, the rename is trivial and the simplification is nice.
I think at some point we'll need to bring back the key stuff because we will want to verify the official images we publish, but that's a problem from later.

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

Thanks Leo

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-08-11 10:32:38 +0000
3+++ cloud/cloud.go 2015-11-27 16:32:13 +0000
4@@ -30,5 +30,5 @@
5 // NewCloudClient is the factory for the cloud clients of type "provider"
6 func NewCloudClient(provider, flavor string, util utils.Utilizer) Clouder {
7
8- return NewCanonistackClient(flavor, util)
9+ return NewOpenstackClient(flavor, util)
10 }
11
12=== modified file 'cloud/cloud_test.go'
13--- cloud/cloud_test.go 2015-08-11 10:32:38 +0000
14+++ cloud/cloud_test.go 2015-11-27 16:32:13 +0000
15@@ -28,11 +28,11 @@
16
17 type cloudSuite struct{}
18
19-func (s *cloudSuite) TestNewCanonistackCloudClient(c *check.C) {
20+func (s *cloudSuite) TestNewOpenstackCloudClient(c *check.C) {
21 utilHandler := utils.NewBasicHandler()
22- subject := NewCloudClient("canonistack", "m1.small", utilHandler)
23- _, ok := subject.(*CanonistackClient)
24+ subject := NewCloudClient("openstack", "m1.small", utilHandler)
25+ _, ok := subject.(*OpenstackClient)
26
27 c.Assert(ok, check.Equals, true,
28- check.Commentf("Expected type *Canonistack, got %T", subject))
29+ check.Commentf("Expected type *OpenstackClient, got %T", subject))
30 }
31
32=== renamed file 'cloud/canonistack.go' => 'cloud/openstack.go'
33--- cloud/canonistack.go 2015-11-04 16:56:09 +0000
34+++ cloud/openstack.go 2015-11-27 16:32:13 +0000
35@@ -36,15 +36,15 @@
36 const (
37 imgTpl = ".*custom.*%s-snappy-core-amd64-%s.*"
38 listImagesCmd = "nova image-list"
39- launchInstanceCmdTpl = "nova boot --key-name %s_%s --security-groups ssh --flavor %s --user-data /usr/share/snappy-tests-job/user.yml --image %s test-%d"
40+ launchInstanceCmdTpl = "nova boot --security-groups ssh --flavor %s --image %s test-%d"
41 describeInstanceCmdTpl = "nova show %s"
42 killInstanceCmdTpl = "nova delete %s"
43 maxAttempsInstanceWait = 10
44 secondsToWaitForInstance = 20
45 )
46
47-// CanonistackClient is the client for connecting to Canonistack
48-type CanonistackClient struct {
49+// OpenstackClient is the client for connecting to Openstack
50+type OpenstackClient struct {
51 util utils.Utilizer
52 flavor string
53 instanceID string
54@@ -52,7 +52,7 @@
55
56 // CreateInstance launches a snappy instance from the latest image with the passed release
57 // and channel and returns its ip
58-func (c *CanonistackClient) CreateInstance(release, channel string) (ip string, err error) {
59+func (c *OpenstackClient) CreateInstance(release, channel string) (ip string, err error) {
60 log.Printf("*** Creating Snappy instance for release %s and channel %s ***", release, channel)
61 imageID, err := c.listImages(release, channel)
62 if err == nil {
63@@ -62,7 +62,7 @@
64 }
65
66 // KillInstance kills the current running instance if any
67-func (c *CanonistackClient) KillInstance() (err error) {
68+func (c *OpenstackClient) KillInstance() (err error) {
69 if c.instanceID != "" {
70 log.Printf("*** Killing instance %s ***", c.instanceID)
71 err = c.killInstance()
72@@ -70,17 +70,17 @@
73 return
74 }
75
76-// NewCanonistackClient is CanonistackClient's constructor
77-func NewCanonistackClient(flavor string, util utils.Utilizer) *CanonistackClient {
78- return &CanonistackClient{flavor: flavor, util: util}
79+// NewOpenstackClient is OpenstackClient's constructor
80+func NewOpenstackClient(flavor string, util utils.Utilizer) *OpenstackClient {
81+ return &OpenstackClient{flavor: flavor, util: util}
82 }
83
84-func (c *CanonistackClient) imgTemplate(release, channel string) string {
85+func (c *OpenstackClient) imgTemplate(release, channel string) string {
86 fixedRelease := strings.Replace(release, ".", "", -1)
87 return fmt.Sprintf(imgTpl, fixedRelease, channel)
88 }
89
90-func (c *CanonistackClient) listImages(release, channel string) (imageID string, err error) {
91+func (c *OpenstackClient) listImages(release, channel string) (imageID string, err error) {
92 params := utils.NewExecCommandParams("", strings.Fields(listImagesCmd), false)
93 list, err := c.util.ExecCommand(params)
94 if err == nil {
95@@ -90,11 +90,10 @@
96 return
97 }
98
99-func (c *CanonistackClient) launchInstance(imageID string) (ip string, err error) {
100+func (c *OpenstackClient) launchInstance(imageID string) (ip string, err error) {
101 log.Printf("Launching instance for Snappy image %s", imageID)
102
103- launchInstanceCmd := fmt.Sprintf(launchInstanceCmdTpl,
104- os.Getenv("NOVA_USERNAME"), os.Getenv("OS_REGION_NAME"), c.flavor, imageID, os.Getpid())
105+ launchInstanceCmd := fmt.Sprintf(launchInstanceCmdTpl, c.flavor, imageID, os.Getpid())
106 params := utils.NewExecCommandParams("", strings.Fields(launchInstanceCmd), false)
107
108 output, err := c.util.ExecCommand(params)
109@@ -109,7 +108,7 @@
110 return
111 }
112
113-func (c *CanonistackClient) killInstance() (err error) {
114+func (c *OpenstackClient) killInstance() (err error) {
115 killInstanceCmd := fmt.Sprintf(killInstanceCmdTpl, c.instanceID)
116 params := utils.NewExecCommandParams("", strings.Fields(killInstanceCmd), false)
117
118@@ -117,7 +116,7 @@
119 return
120 }
121
122-func (c *CanonistackClient) getLatestImageID(release, channel, list string) (imageID string) {
123+func (c *OpenstackClient) getLatestImageID(release, channel, list string) (imageID string) {
124 // list is of the form:
125 //
126 // | e37ef727-014d-48e8-b0e4-94cf39e1dbbc | ubuntu-released/ubuntu-wily-alpha1-amd64-server-20150624-disk1.img | ACTIVE | |
127@@ -145,7 +144,7 @@
128 return imageIDs[0]
129 }
130
131-func (c *CanonistackClient) getinstanceID(list string) (instanceID string) {
132+func (c *OpenstackClient) getinstanceID(list string) (instanceID string) {
133 /*
134 +--------------------------------------+-----------------------------------------------------------------------------------------------------------+
135 | Property | Value |
136@@ -194,7 +193,7 @@
137 return
138 }
139
140-func (c *CanonistackClient) getInstanceIP() (instanceIP string, err error) {
141+func (c *OpenstackClient) getInstanceIP() (instanceIP string, err error) {
142 describeInstanceCmd := fmt.Sprintf(describeInstanceCmdTpl, c.instanceID)
143
144 params := utils.NewExecCommandParams("", strings.Fields(describeInstanceCmd), false)
145
146=== renamed file 'cloud/canonistack_test.go' => 'cloud/openstack_test.go'
147--- cloud/canonistack_test.go 2015-10-27 16:13:15 +0000
148+++ cloud/openstack_test.go 2015-11-27 16:32:13 +0000
149@@ -25,7 +25,7 @@
150 "strings"
151 "testing"
152
153- check "gopkg.in/check.v1"
154+ "gopkg.in/check.v1"
155 "launchpad.net/snappy-tests-job/testhelpers"
156 "launchpad.net/snappy-tests-job/utils"
157 )
158@@ -101,21 +101,17 @@
159 | updated | 2015-07-27T09:29:27Z |
160 | user_id | 0534127f70534300baf48e8ac1134734 |
161 +--------------------------------------+-----------------------------------------------------------------------------------------------------------+`
162- instanceIP = "1.1.1.1"
163- novaUserName = "my_nova_user_name"
164- osRegionName = "my_os_region_name"
165+ instanceIP = "1.1.1.1"
166 )
167
168-var _ = check.Suite(&canonistackSuite{})
169+var _ = check.Suite(&openstackSuite{})
170
171-type canonistackSuite struct {
172+type openstackSuite struct {
173 fakeUtil *testhelpers.FakeUtils
174 subject Clouder
175 instanceID string
176 imageID string
177 flavor string
178- novaUserNameBack string
179- osRegionNameBack string
180 imageList string
181 describeOutputPending string
182 describeOutputFinished string
183@@ -123,21 +119,15 @@
184
185 func Test(t *testing.T) { check.TestingT(t) }
186
187-func (s *canonistackSuite) SetUpTest(c *check.C) {
188+func (s *openstackSuite) SetUpTest(c *check.C) {
189 s.fakeUtil = testhelpers.NewFakeUtils()
190 s.flavor = "m1.quitelarge"
191
192- s.subject = NewCanonistackClient(s.flavor, s.fakeUtil)
193+ s.subject = NewOpenstackClient(s.flavor, s.fakeUtil)
194
195 s.instanceID = "instanceID1"
196 s.imageID = imgTemplate(defaultRelease, defaultChannel)
197
198- s.novaUserNameBack = os.Getenv("NOVA_USERNAME")
199- s.osRegionNameBack = os.Getenv("OS_REGION_NAME")
200-
201- os.Setenv("NOVA_USERNAME", novaUserName)
202- os.Setenv("OS_REGION_NAME", osRegionName)
203-
204 s.imageList = fmt.Sprintf(imageListTpl, s.imageID)
205 s.describeOutputPending = fmt.Sprintf(describeOutputTpl, "")
206 s.describeOutputFinished = fmt.Sprintf(describeOutputTpl, instanceIP)
207@@ -149,12 +139,7 @@
208 s.fakeUtil.ExecReturnValues = append(s.fakeUtil.ExecReturnValues, s.describeOutputFinished)
209 }
210
211-func (s *canonistackSuite) TearDownTest(c *check.C) {
212- os.Setenv("NOVA_USERNAME", s.novaUserNameBack)
213- os.Setenv("OS_REGION_NAME", s.osRegionNameBack)
214-}
215-
216-func (s *canonistackSuite) TestCreateInstanceCallsListImages(c *check.C) {
217+func (s *openstackSuite) TestCreateInstanceCallsListImages(c *check.C) {
218 s.subject.CreateInstance(defaultRelease, defaultChannel)
219
220 cmdParams := utils.NewExecCommandParams("", strings.Fields(listImagesCmd), false)
221@@ -163,14 +148,14 @@
222 check.Commentf("Expected euca list images called once"))
223 }
224
225-func (s *canonistackSuite) TestCreateInstanceReturnsErrorOnListError(c *check.C) {
226+func (s *openstackSuite) TestCreateInstanceReturnsErrorOnListError(c *check.C) {
227 s.fakeUtil.FailExec = true
228 _, err := s.subject.CreateInstance(defaultRelease, defaultChannel)
229
230 c.Assert(err, check.NotNil, check.Commentf("Expected error from euca list images"))
231 }
232
233-func (s *canonistackSuite) TestCreateInstanceDoesNotCreateNewInstanceOnListError(c *check.C) {
234+func (s *openstackSuite) TestCreateInstanceDoesNotCreateNewInstanceOnListError(c *check.C) {
235 s.fakeUtil.FailExec = true
236 s.subject.CreateInstance(defaultRelease, defaultChannel)
237
238@@ -181,7 +166,7 @@
239 check.Commentf("Called LaunchInstance on ListImages error"))
240 }
241
242-func (s *canonistackSuite) TestCreateInstanceCallsLaunchInstance(c *check.C) {
243+func (s *openstackSuite) TestCreateInstanceCallsLaunchInstance(c *check.C) {
244 s.subject.CreateInstance(defaultRelease, defaultChannel)
245
246 cmd := s.launchInstanceCmd(s.imageID, s.flavor)
247@@ -191,14 +176,14 @@
248 check.Commentf("Expected call to LaunchInstance not occurred"))
249 }
250
251-func (s *canonistackSuite) TestCreateInstanceReturnsInstanceIP(c *check.C) {
252+func (s *openstackSuite) TestCreateInstanceReturnsInstanceIP(c *check.C) {
253 ip, _ := s.subject.CreateInstance(defaultRelease, defaultChannel)
254
255 c.Assert(ip, check.Equals, instanceIP,
256 check.Commentf("Expected instance IP not returned %s, got %s", instanceIP, ip))
257 }
258
259-func (s *canonistackSuite) TestKillInstanceCallsKillCommand(c *check.C) {
260+func (s *openstackSuite) TestKillInstanceCallsKillCommand(c *check.C) {
261 s.subject.CreateInstance(defaultRelease, defaultChannel)
262 s.subject.KillInstance()
263
264@@ -209,7 +194,7 @@
265 check.Commentf("Expected call to KillInstance not occurred"))
266 }
267
268-func (s *canonistackSuite) TestKillInstanceNotCalledIfMisisngInstance(c *check.C) {
269+func (s *openstackSuite) TestKillInstanceNotCalledIfMisisngInstance(c *check.C) {
270 back := s.instanceID
271 s.instanceID = ""
272 defer func() { s.instanceID = back }()
273@@ -223,7 +208,7 @@
274 check.Commentf("Call to KillInstance without active instance"))
275 }
276
277-func (s *canonistackSuite) TestCreateInstanceCallsLaunchInstanceWithLatestImage(c *check.C) {
278+func (s *openstackSuite) TestCreateInstanceCallsLaunchInstanceWithLatestImage(c *check.C) {
279 s.fakeUtil.ExecReturnValues = nil
280
281 imageIDNew := s.imageID + "-" + "20150109"
282@@ -250,11 +235,10 @@
283 return fmt.Sprintf(imgTpl, release, channel)
284 }
285
286-func (s *canonistackSuite) launchInstanceCmd(imgID, flavor string) string {
287- return fmt.Sprintf(launchInstanceCmdTpl,
288- novaUserName, osRegionName, flavor, imgID, os.Getpid())
289+func (s *openstackSuite) launchInstanceCmd(imgID, flavor string) string {
290+ return fmt.Sprintf(launchInstanceCmdTpl, flavor, imgID, os.Getpid())
291 }
292
293-func (s *canonistackSuite) killInstanceCmd() string {
294+func (s *openstackSuite) killInstanceCmd() string {
295 return fmt.Sprintf(killInstanceCmdTpl, s.instanceID)
296 }
297
298=== removed directory 'data'
299=== removed file 'data/user.yml'
300--- data/user.yml 2015-07-23 09:05:39 +0000
301+++ data/user.yml 1970-01-01 00:00:00 +0000
302@@ -1,3 +0,0 @@
303-#cloud-config
304-snappy:
305- ssh_enabled: True
306
307=== removed file 'debian/install'
308--- debian/install 2015-07-28 10:59:08 +0000
309+++ debian/install 1970-01-01 00:00:00 +0000
310@@ -1,1 +0,0 @@
311-data/user.yml /usr/share/snappy-tests-job
312\ No newline at end of file
313
314=== modified file 'snappy-tests-job/main.go'
315--- snappy-tests-job/main.go 2015-11-24 12:25:37 +0000
316+++ snappy-tests-job/main.go 2015-11-27 16:32:13 +0000
317@@ -31,7 +31,7 @@
318 )
319
320 const (
321- defaultCloudProvider = "canonistack"
322+ defaultCloudProvider = "openstack"
323 defaultFlavor = "m1.medium"
324 defaultCommandTpl = "go run ./integration-tests/main.go -ip %s %s"
325 defaultRepo = "https://github.com/ubuntu-core/snappy.git"

Subscribers

People subscribed via source and target branches