Merge lp:~julian-edwards/gwacl/deletedisk into lp:gwacl

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: 185
Merged at revision: 179
Proposed branch: lp:~julian-edwards/gwacl/deletedisk
Merge into: lp:gwacl
Diff against target: 971 lines (+150/-103)
10 files modified
deletedisk_test.go (+3/-3)
management_base.go (+63/-30)
management_base_test.go (+30/-28)
management_test.go (+2/-5)
poller.go (+2/-1)
poller_test.go (+3/-3)
x509dispatcher.go (+8/-11)
x509dispatcher_test.go (+15/-6)
x509session.go (+8/-8)
x509session_test.go (+16/-8)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/deletedisk
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+174337@code.launchpad.net

Commit message

Ensures each api call specifies its own x-ms-version and add Azure url links to relevant docs for each api call

Description of the change

I was intending this to be a fix for the disk deletion problem (http://paste.ubuntu.com/5864779/) but it doesn't work. However this branch still sorts out a few things:

 1. Adds Azure url links to relevant docs for each api call
 2. Ensures each api call specifies its own x-ms-version. This is critical to prevent future cock ups and also because the deletedisk call requires a version other than the old base version.
 3. Adds extra test coverage that was missing which ensures x-ms-header is set for all the session op methods.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Well I tell a lie - disk deletion has worked, so this fixes that too.

However the example program is still not cleaning up the storage, that needs looking at still.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Good stuff. Consistent function documentation is lagniappe, but particularly appreciated. Sometimes a top comment for a function doesn't help understanding per se, but I still find that applying them inconsistently can frustrate the scanning of code. It's as if it makes my eyes recover from an exception rather than processing the text in a straight loop.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'deletedisk_test.go'
--- deletedisk_test.go 2013-06-27 10:55:35 +0000
+++ deletedisk_test.go 2013-07-12 05:06:27 +0000
@@ -73,7 +73,7 @@
73 c.Assert(response, IsNil)73 c.Assert(response, IsNil)
74 c.Assert(err, IsNil)74 c.Assert(err, IsNil)
75 expectedURL := api.session.composeURL("services/disks/" + diskName)75 expectedURL := api.session.composeURL("services/disks/" + diskName)
76 checkOneRequest(c, recordedRequests, expectedURL, []byte{}, "DELETE")76 checkOneRequest(c, recordedRequests, expectedURL, "2012-08-01", nil, "DELETE")
77}77}
7878
79func (suite *deleteDiskSuite) TestManagementAPIDeleteDiskPolls(c *C) {79func (suite *deleteDiskSuite) TestManagementAPIDeleteDiskPolls(c *C) {
@@ -98,6 +98,6 @@
98 c.Assert(err, IsNil)98 c.Assert(err, IsNil)
99 expectedURL := api.session.composeURL("services/disks/" + diskName)99 expectedURL := api.session.composeURL("services/disks/" + diskName)
100 c.Check(len(recordedRequests), Equals, 2)100 c.Check(len(recordedRequests), Equals, 2)
101 checkRequest(c, recordedRequests[0], expectedURL, []byte{}, "DELETE")101 checkRequest(c, recordedRequests[0], expectedURL, "2012-08-01", nil, "DELETE")
102 checkRequest(c, recordedRequests[1], expectedURL, []byte{}, "DELETE")102 checkRequest(c, recordedRequests[1], expectedURL, "2012-08-01", nil, "DELETE")
103}103}
104104
=== modified file 'management_base.go'
--- management_base.go 2013-07-10 15:42:42 +0000
+++ management_base.go 2013-07-12 05:06:27 +0000
@@ -97,7 +97,7 @@
97// Images are returned in the order in which Azure lists them.97// Images are returned in the order in which Azure lists them.
98// http://msdn.microsoft.com/en-us/library/windowsazure/jj157191.aspx98// http://msdn.microsoft.com/en-us/library/windowsazure/jj157191.aspx
99func (api *ManagementAPI) ListOSImages() (*Images, error) {99func (api *ManagementAPI) ListOSImages() (*Images, error) {
100 response, err := api.session.get("services/images")100 response, err := api.session.get("services/images", "2013-03-01")
101 if err != nil {101 if err != nil {
102 return nil, err102 return nil, err
103 }103 }
@@ -110,9 +110,9 @@
110// Azure management API. 110// Azure management API.
111// HostedServiceDescriptor objects contains a small subset of the fields present in111// HostedServiceDescriptor objects contains a small subset of the fields present in
112// HostedService objects.112// HostedService objects.
113// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460781.aspx
113func (api *ManagementAPI) ListHostedServices() ([]HostedServiceDescriptor, error) {114func (api *ManagementAPI) ListHostedServices() ([]HostedServiceDescriptor, error) {
114 URI := "services/hostedservices"115 res, err := api.session.get("services/hostedservices", "2012-03-01")
115 res, err := api.session.get(URI)
116 if err != nil {116 if err != nil {
117 return nil, err117 return nil, err
118 }118 }
@@ -123,6 +123,7 @@
123123
124// UpdateHostedService updates the provided values on the named service.124// UpdateHostedService updates the provided values on the named service.
125// Use NewUpdateHostedService() to create an UpdateHostedService params object.125// Use NewUpdateHostedService() to create an UpdateHostedService params object.
126// See http://msdn.microsoft.com/en-us/library/windowsazure/gg441303.aspx
126func (api *ManagementAPI) UpdateHostedService(serviceName string, params *UpdateHostedService) error {127func (api *ManagementAPI) UpdateHostedService(serviceName string, params *UpdateHostedService) error {
127 var err error128 var err error
128 checkPathComponents(serviceName)129 checkPathComponents(serviceName)
@@ -131,7 +132,7 @@
131 if err != nil {132 if err != nil {
132 return err133 return err
133 }134 }
134 response, err := api.session.put(URI, []byte(body), "application/xml")135 response, err := api.session.put(URI, "2012-03-01", []byte(body), "application/xml")
135 if err != nil {136 if err != nil {
136 return err137 return err
137 }138 }
@@ -140,6 +141,7 @@
140141
141// GetHostedServiceProperties loads a HostedService object from the Azure142// GetHostedServiceProperties loads a HostedService object from the Azure
142// management API.143// management API.
144// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460806.aspx
143func (api *ManagementAPI) GetHostedServiceProperties(145func (api *ManagementAPI) GetHostedServiceProperties(
144 serviceName string, embedDetail bool) (*HostedService, error) {146 serviceName string, embedDetail bool) (*HostedService, error) {
145 checkPathComponents(serviceName)147 checkPathComponents(serviceName)
@@ -150,7 +152,7 @@
150 case false:152 case false:
151 URI += "false"153 URI += "false"
152 }154 }
153 res, err := api.session.get(URI)155 res, err := api.session.get(URI, "2012-03-01")
154 if err != nil {156 if err != nil {
155 return nil, err157 return nil, err
156 }158 }
@@ -162,21 +164,25 @@
162// AddHostedService adds a hosted service.164// AddHostedService adds a hosted service.
163// This is an asynchronous operation on Azure, but this call blocks until the165// This is an asynchronous operation on Azure, but this call blocks until the
164// operation is completed.166// operation is completed.
167// This is actually called CreateHostedService in the Azure documentation.
168// See http://msdn.microsoft.com/en-us/library/windowsazure/gg441304.aspx
165func (api *ManagementAPI) AddHostedService(definition *CreateHostedService) error {169func (api *ManagementAPI) AddHostedService(definition *CreateHostedService) error {
166 URI := "services/hostedservices"170 URI := "services/hostedservices"
167 body, err := marshalXML(definition)171 body, err := marshalXML(definition)
168 if err != nil {172 if err != nil {
169 return err173 return err
170 }174 }
171 response, err := api.session.post(URI, []byte(body), "application/xml")175 response, err := api.session.post(URI, "2012-03-01", []byte(body), "application/xml")
172 if err != nil {176 if err != nil {
173 return err177 return err
174 }178 }
175 return api.blockUntilCompleted(response)179 return api.blockUntilCompleted(response)
176}180}
177181
182// DeleteHostedService deletes the named hosted service.
183// See http://msdn.microsoft.com/en-us/library/windowsazure/gg441305.aspx
178func (api *ManagementAPI) DeleteHostedService(serviceName string) error {184func (api *ManagementAPI) DeleteHostedService(serviceName string) error {
179 response, err := api.session.delete("services/hostedservices/" + serviceName)185 response, err := api.session.delete("services/hostedservices/" + serviceName, "2010-10-28")
180 if err != nil {186 if err != nil {
181 return err187 return err
182 }188 }
@@ -184,7 +190,10 @@
184}190}
185191
186// AddDeployment adds a virtual machine deployment.192// AddDeployment adds a virtual machine deployment.
187// This is an asynchronous operation, it blocks until the operation is completed.193// This is an asynchronous operation on Azure, but this call blocks until the
194// operation is completed.
195// This is actually called CreateDeployment in the Azure documentation.
196// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460813.aspx
188func (api *ManagementAPI) AddDeployment(definition *Deployment, serviceName string) error {197func (api *ManagementAPI) AddDeployment(definition *Deployment, serviceName string) error {
189 checkPathComponents(serviceName)198 checkPathComponents(serviceName)
190 URI := "services/hostedservices/" + serviceName + "/deployments"199 URI := "services/hostedservices/" + serviceName + "/deployments"
@@ -192,16 +201,18 @@
192 if err != nil {201 if err != nil {
193 return err202 return err
194 }203 }
195 response, err := api.session.post(URI, []byte(body), "application/xml")204 response, err := api.session.post(URI, "2012-03-01", []byte(body), "application/xml")
196 if err != nil {205 if err != nil {
197 return err206 return err
198 }207 }
199 return api.blockUntilCompleted(response)208 return api.blockUntilCompleted(response)
200}209}
201210
211// DeleteDeployment deletes the named deployment from the named hosted service.
212// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460815.aspx
202func (api *ManagementAPI) DeleteDeployment(serviceName string, deploymentName string) error {213func (api *ManagementAPI) DeleteDeployment(serviceName string, deploymentName string) error {
203 path := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName214 path := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName
204 response, err := api.session.delete(path)215 response, err := api.session.delete(path, "2012-03-01")
205 if err != nil {216 if err != nil {
206 return err217 return err
207 }218 }
@@ -213,11 +224,14 @@
213 DeploymentName string224 DeploymentName string
214}225}
215226
227// GetDeployment returns a Deployment object for the named hosted service and
228// deployment name.
229// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460804.aspx
216func (api *ManagementAPI) GetDeployment(request *GetDeploymentRequest) (*Deployment, error) {230func (api *ManagementAPI) GetDeployment(request *GetDeploymentRequest) (*Deployment, error) {
217 checkPathComponents(request.ServiceName)231 checkPathComponents(request.ServiceName)
218 checkPathComponents(request.DeploymentName)232 checkPathComponents(request.DeploymentName)
219 path := "services/hostedservices/" + request.ServiceName + "/deployments/" + request.DeploymentName233 path := "services/hostedservices/" + request.ServiceName + "/deployments/" + request.DeploymentName
220 response, err := api.session.get(path)234 response, err := api.session.get(path, "2012-03-01")
221 if err != nil {235 if err != nil {
222 return nil, err236 return nil, err
223 }237 }
@@ -232,14 +246,17 @@
232// AddStorageAccount starts the creation of a storage account. This is246// AddStorageAccount starts the creation of a storage account. This is
233// called a storage service in the Azure API, but nomenclature seems to247// called a storage service in the Azure API, but nomenclature seems to
234// have changed.248// have changed.
235// This is an asynchronous operation, it blocks until the operation is completed.249// This is an asynchronous operation on Azure, but the call blocks until the
250// operation is completed.
251// This is actually called CreateStorageAccount in the Azure documentation.
252// See http://msdn.microsoft.com/en-us/library/windowsazure/hh264518.aspx
236func (api *ManagementAPI) AddStorageAccount(definition *CreateStorageServiceInput) error {253func (api *ManagementAPI) AddStorageAccount(definition *CreateStorageServiceInput) error {
237 uri := "services/storageservices"254 uri := "services/storageservices"
238 body, err := marshalXML(definition)255 body, err := marshalXML(definition)
239 if err != nil {256 if err != nil {
240 return err257 return err
241 }258 }
242 response, err := api.session.post(uri, []byte(body), "application/xml")259 response, err := api.session.post(uri, "2012-03-01", []byte(body), "application/xml")
243 if err != nil {260 if err != nil {
244 return err261 return err
245 }262 }
@@ -247,8 +264,9 @@
247}264}
248265
249// DeleteStorageAccount deletes a storage account.266// DeleteStorageAccount deletes a storage account.
267// See http://msdn.microsoft.com/en-us/library/windowsazure/hh264517.aspx
250func (api *ManagementAPI) DeleteStorageAccount(storageAccountName string) error {268func (api *ManagementAPI) DeleteStorageAccount(storageAccountName string) error {
251 response, err := api.session.delete("services/storageservices/" + storageAccountName)269 response, err := api.session.delete("services/storageservices/" + storageAccountName, "2011-06-01")
252 if err != nil {270 if err != nil {
253 return err271 return err
254 }272 }
@@ -257,9 +275,10 @@
257275
258// GetStorageAccountKeys retrieves a storage account's primary and secondary276// GetStorageAccountKeys retrieves a storage account's primary and secondary
259// access keys from the Azure service.277// access keys from the Azure service.
278// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460785.aspx
260func (api *ManagementAPI) GetStorageAccountKeys(accountName string) (*StorageAccountKeys, error) {279func (api *ManagementAPI) GetStorageAccountKeys(accountName string) (*StorageAccountKeys, error) {
261 url := "services/storageservices/" + accountName + "/keys"280 url := "services/storageservices/" + accountName + "/keys"
262 res, err := api.session.get(url)281 res, err := api.session.get(url, "2009-10-01")
263 if err != nil {282 if err != nil {
264 return nil, err283 return nil, err
265 }284 }
@@ -271,6 +290,9 @@
271 return &keys, nil290 return &keys, nil
272}291}
273292
293// DeleteDisk deletes the named OS/data disk.
294// See http://msdn.microsoft.com/en-us/library/windowsazure/jj157200.aspx
295// TODO: set comp=media to optionally delete associated blob.
274func (api *ManagementAPI) DeleteDisk(diskName string) error {296func (api *ManagementAPI) DeleteDisk(diskName string) error {
275 // Use the disk deletion poller to work around a bug in Windows Azure.297 // Use the disk deletion poller to work around a bug in Windows Azure.
276 // See the documentation in the file deletedisk.go for details.298 // See the documentation in the file deletedisk.go for details.
@@ -280,24 +302,25 @@
280}302}
281303
282func (api *ManagementAPI) _DeleteDisk(diskName string) error {304func (api *ManagementAPI) _DeleteDisk(diskName string) error {
283 response, err := api.session.delete("services/disks/" + diskName)305 response, err := api.session.delete(
306 "services/disks/" + diskName, "2012-08-01")
284 if err != nil {307 if err != nil {
285 return err308 return err
286 }309 }
287 return api.blockUntilCompleted(response)310 return api.blockUntilCompleted(response)
288}311}
289312
290// Perform an operation on the specified role (as defined by serviceName, deploymentName and313// Perform an operation on the specified role (as defined by serviceName,
291// roleName)314// deploymentName and roleName) This is an asynchronous operation on Azure, but
292// This is an asynchronous operation, it blocks until the operation is completed.315// the call blocks until the operation is completed.
293func (api *ManagementAPI) performRoleOperation(serviceName string, deploymentName string, roleName string, operation *RoleOperation) error {316func (api *ManagementAPI) performRoleOperation(serviceName, deploymentName, roleName, apiVersion string, operation *RoleOperation) error {
294 checkPathComponents(serviceName, deploymentName, roleName)317 checkPathComponents(serviceName, deploymentName, roleName)
295 URI := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName + "/roleinstances/" + roleName + "/Operations"318 URI := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName + "/roleinstances/" + roleName + "/Operations"
296 body, err := marshalXML(operation)319 body, err := marshalXML(operation)
297 if err != nil {320 if err != nil {
298 return err321 return err
299 }322 }
300 response, err := api.session.post(URI, []byte(body), "application/xml")323 response, err := api.session.post(URI, apiVersion, []byte(body), "application/xml")
301 if err != nil {324 if err != nil {
302 return err325 return err
303 }326 }
@@ -313,40 +336,44 @@
313type StartRoleRequest performRoleOperationRequest336type StartRoleRequest performRoleOperationRequest
314337
315// StartRole starts the named Role.338// StartRole starts the named Role.
339// See http://msdn.microsoft.com/en-us/library/windowsazure/jj157189.aspx
316func (api *ManagementAPI) StartRole(request *StartRoleRequest) error {340func (api *ManagementAPI) StartRole(request *StartRoleRequest) error {
317 return api.performRoleOperation(341 return api.performRoleOperation(
318 request.ServiceName, request.DeploymentName, request.RoleName,342 request.ServiceName, request.DeploymentName, request.RoleName,
319 startRoleOperation)343 "2012-03-01", startRoleOperation)
320}344}
321345
322type RestartRoleRequest performRoleOperationRequest346type RestartRoleRequest performRoleOperationRequest
323347
324// RestartRole restarts the named Role.348// RestartRole restarts the named Role.
349// See http://msdn.microsoft.com/en-us/library/windowsazure/jj157197.aspx
325func (api *ManagementAPI) RestartRole(request *RestartRoleRequest) error {350func (api *ManagementAPI) RestartRole(request *RestartRoleRequest) error {
326 return api.performRoleOperation(351 return api.performRoleOperation(
327 request.ServiceName, request.DeploymentName, request.RoleName,352 request.ServiceName, request.DeploymentName, request.RoleName,
328 restartRoleOperation)353 "2012-03-01", restartRoleOperation)
329}354}
330355
331type ShutdownRoleRequest performRoleOperationRequest356type ShutdownRoleRequest performRoleOperationRequest
332357
333// ShutdownRole shuts down the named Role.358// ShutdownRole shuts down the named Role.
359// See http://msdn.microsoft.com/en-us/library/windowsazure/jj157195.aspx
334func (api *ManagementAPI) ShutdownRole(request *ShutdownRoleRequest) error {360func (api *ManagementAPI) ShutdownRole(request *ShutdownRoleRequest) error {
335 return api.performRoleOperation(361 return api.performRoleOperation(
336 request.ServiceName, request.DeploymentName, request.RoleName,362 request.ServiceName, request.DeploymentName, request.RoleName,
337 shutdownRoleOperation)363 "2012-03-01", shutdownRoleOperation)
338}364}
339365
340type GetRoleRequest performRoleOperationRequest366type GetRoleRequest performRoleOperationRequest
341367
342// GetRole requests the role data for the specified role.368// GetRole requests the role data for the specified role.
369// See http://msdn.microsoft.com/en-us/library/windowsazure/jj157193.aspx
343func (api *ManagementAPI) GetRole(request *GetRoleRequest) (*GetRole, error) {370func (api *ManagementAPI) GetRole(request *GetRoleRequest) (*GetRole, error) {
344 checkPathComponents(371 checkPathComponents(
345 request.ServiceName, request.DeploymentName, request.RoleName)372 request.ServiceName, request.DeploymentName, request.RoleName)
346 url := ("services/hostedservices/" + request.ServiceName +373 url := ("services/hostedservices/" + request.ServiceName +
347 "/deployments/" + request.DeploymentName + "/roles/" +374 "/deployments/" + request.DeploymentName + "/roles/" +
348 request.RoleName)375 request.RoleName)
349 response, err := api.session.get(url)376 response, err := api.session.get(url, "2012-03-01")
350 if err != nil {377 if err != nil {
351 return nil, err378 return nil, err
352 }379 }
@@ -363,6 +390,7 @@
363}390}
364391
365// CreateAffinityGroup sends a request to make a new affinity group.392// CreateAffinityGroup sends a request to make a new affinity group.
393// See http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx
366func (api *ManagementAPI) CreateAffinityGroup(request *CreateAffinityGroupRequest) error {394func (api *ManagementAPI) CreateAffinityGroup(request *CreateAffinityGroupRequest) error {
367 var err error395 var err error
368 url := "affinitygroups"396 url := "affinitygroups"
@@ -370,7 +398,7 @@
370 if err != nil {398 if err != nil {
371 return err399 return err
372 }400 }
373 response, err := api.session.post(url, []byte(body), "application/xml")401 response, err := api.session.post(url, "2012-03-01", []byte(body), "application/xml")
374 return api.blockUntilCompleted(response)402 return api.blockUntilCompleted(response)
375}403}
376404
@@ -380,6 +408,7 @@
380}408}
381409
382// UpdateAffinityGroup sends a request to update the named affinity group.410// UpdateAffinityGroup sends a request to update the named affinity group.
411// See http://msdn.microsoft.com/en-us/library/windowsazure/gg715316.aspx
383func (api *ManagementAPI) UpdateAffinityGroup(request *UpdateAffinityGroupRequest) error {412func (api *ManagementAPI) UpdateAffinityGroup(request *UpdateAffinityGroupRequest) error {
384 var err error413 var err error
385 checkPathComponents(request.Name)414 checkPathComponents(request.Name)
@@ -388,7 +417,7 @@
388 if err != nil {417 if err != nil {
389 return err418 return err
390 }419 }
391 response, err := api.session.put(url, []byte(body), "application/xml")420 response, err := api.session.put(url, "2011-02-25", []byte(body), "application/xml")
392 if err != nil {421 if err != nil {
393 return err422 return err
394 }423 }
@@ -400,6 +429,7 @@
400}429}
401430
402// DeleteAffinityGroup requests a deletion of the named affinity group.431// DeleteAffinityGroup requests a deletion of the named affinity group.
432// See http://msdn.microsoft.com/en-us/library/windowsazure/gg715314.aspx
403func (api *ManagementAPI) DeleteAffinityGroup(request *DeleteAffinityGroupRequest) error {433func (api *ManagementAPI) DeleteAffinityGroup(request *DeleteAffinityGroupRequest) error {
404 var err error434 var err error
405 checkPathComponents(request.Name)435 checkPathComponents(request.Name)
@@ -407,7 +437,7 @@
407 if err != nil {437 if err != nil {
408 return err438 return err
409 }439 }
410 response, err := api.session.delete(url)440 response, err := api.session.delete(url, "2011-02-25")
411 if err != nil {441 if err != nil {
412 return err442 return err
413 }443 }
@@ -417,8 +447,9 @@
417// GetNetworkConfiguration gets the network configuration for this447// GetNetworkConfiguration gets the network configuration for this
418// subscription. If there is no network configuration the configuration will448// subscription. If there is no network configuration the configuration will
419// be nil.449// be nil.
450// See http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx
420func (api *ManagementAPI) GetNetworkConfiguration() (*NetworkConfiguration, error) {451func (api *ManagementAPI) GetNetworkConfiguration() (*NetworkConfiguration, error) {
421 response, err := api.session.get("services/networking/media")452 response, err := api.session.get("services/networking/media", "2012-03-01")
422 if err != nil {453 if err != nil {
423 if IsNotFoundError(err) {454 if IsNotFoundError(err) {
424 return nil, nil455 return nil, nil
@@ -442,7 +473,9 @@
442 if err != nil {473 if err != nil {
443 return err474 return err
444 }475 }
445 response, err := api.session.put("services/networking/media", []byte(body), "application/octet-stream")476 response, err := api.session.put(
477 "services/networking/media", "2012-03-01", []byte(body),
478 "application/octet-stream")
446 if err != nil {479 if err != nil {
447 return err480 return err
448 }481 }
449482
=== modified file 'management_base_test.go'
--- management_base_test.go 2013-07-10 16:02:17 +0000
+++ management_base_test.go 2013-07-12 05:06:27 +0000
@@ -246,17 +246,18 @@
246246
247// checkOneRequest asserts that the given slice contains one request, with the247// checkOneRequest asserts that the given slice contains one request, with the
248// given characteristics.248// given characteristics.
249func checkOneRequest(c *C, recordedRequests *[]*X509Request, URL string, payload []byte, Method string) {249func checkOneRequest(c *C, recordedRequests *[]*X509Request, URL, version string, payload []byte, Method string) {
250 requests := *recordedRequests250 requests := *recordedRequests
251 c.Assert(len(requests), Equals, 1)251 c.Assert(len(requests), Equals, 1)
252 request := requests[0]252 request := requests[0]
253 checkRequest(c, request, URL, payload, Method)253 checkRequest(c, request, URL, version, payload, Method)
254}254}
255255
256func checkRequest(c *C, request *X509Request, URL string, payload []byte, Method string) {256func checkRequest(c *C, request *X509Request, URL, version string, payload []byte, Method string) {
257 c.Assert(request.URL, Equals, URL)257 c.Check(request.URL, Equals, URL)
258 c.Assert(string(request.Payload), Equals, string(payload))258 c.Check(string(request.Payload), Equals, string(payload))
259 c.Assert(request.Method, Equals, Method)259 c.Check(request.Method, Equals, Method)
260 c.Check(request.APIVersion, Equals, version)
260}261}
261262
262func (suite *managementBaseAPISuite) TestGetOperationFailsIfNoHeader(c *C) {263func (suite *managementBaseAPISuite) TestGetOperationFailsIfNoHeader(c *C) {
@@ -366,7 +367,7 @@
366367
367 c.Assert(err, IsNil)368 c.Assert(err, IsNil)
368 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices"369 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices"
369 checkOneRequest(c, &recordedRequests, expectedURL, nil, "GET")370 checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", nil, "GET")
370 c.Assert(descriptors[0].URL, Equals, url)371 c.Assert(descriptors[0].URL, Equals, url)
371}372}
372373
@@ -396,7 +397,7 @@
396397
397 c.Assert(err, IsNil)398 c.Assert(err, IsNil)
398 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + serviceName399 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + serviceName
399 checkOneRequest(c, &recordedRequests, expectedURL, requestPayload, "PUT")400 checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", requestPayload, "PUT")
400}401}
401402
402func assertGetHostedServicePropertiesRequest(c *C, api *ManagementAPI, serviceName string, embedDetail bool, httpRequest *X509Request) {403func assertGetHostedServicePropertiesRequest(c *C, api *ManagementAPI, serviceName string, embedDetail bool, httpRequest *X509Request) {
@@ -408,7 +409,7 @@
408 }409 }
409 expectedURL := fmt.Sprintf("%s%s/services/hostedservices/%s?%s", AZURE_URL,410 expectedURL := fmt.Sprintf("%s%s/services/hostedservices/%s?%s", AZURE_URL,
410 api.session.subscriptionId, serviceName, query)411 api.session.subscriptionId, serviceName, query)
411 checkRequest(c, httpRequest, expectedURL, nil, "GET")412 checkRequest(c, httpRequest, expectedURL, "2012-03-01", nil, "GET")
412}413}
413414
414func (suite *managementBaseAPISuite) TestGetHostedServiceProperties_withoutDetails(c *C) {415func (suite *managementBaseAPISuite) TestGetHostedServiceProperties_withoutDetails(c *C) {
@@ -517,13 +518,13 @@
517 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices"518 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices"
518 expectedPayload, err := marshalXML(createHostedService)519 expectedPayload, err := marshalXML(createHostedService)
519 c.Assert(err, IsNil)520 c.Assert(err, IsNil)
520 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")521 checkOneRequest(c, recordedRequests, expectedURL, "2012-03-01", expectedPayload, "POST")
521}522}
522523
523func assertDeleteHostedServiceRequest(c *C, api *ManagementAPI, serviceName string, httpRequest *X509Request) {524func assertDeleteHostedServiceRequest(c *C, api *ManagementAPI, serviceName string, httpRequest *X509Request) {
524 expectedURL := fmt.Sprintf("%s%s/services/hostedservices/%s", AZURE_URL,525 expectedURL := fmt.Sprintf("%s%s/services/hostedservices/%s", AZURE_URL,
525 api.session.subscriptionId, serviceName)526 api.session.subscriptionId, serviceName)
526 checkRequest(c, httpRequest, expectedURL, nil, "DELETE")527 checkRequest(c, httpRequest, expectedURL, "2010-10-28", nil, "DELETE")
527}528}
528529
529func (suite *managementBaseAPISuite) TestDeleteHostedService(c *C) {530func (suite *managementBaseAPISuite) TestDeleteHostedService(c *C) {
@@ -550,14 +551,14 @@
550 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + serviceName + "/deployments"551 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + serviceName + "/deployments"
551 expectedPayload, err := marshalXML(deployment)552 expectedPayload, err := marshalXML(deployment)
552 c.Assert(err, IsNil)553 c.Assert(err, IsNil)
553 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")554 checkOneRequest(c, recordedRequests, expectedURL, "2012-03-01", expectedPayload, "POST")
554}555}
555556
556func assertDeleteDeploymentRequest(c *C, api *ManagementAPI, hostedServiceName, deploymentName string, httpRequest *X509Request) {557func assertDeleteDeploymentRequest(c *C, api *ManagementAPI, hostedServiceName, deploymentName string, httpRequest *X509Request) {
557 expectedURL := fmt.Sprintf(558 expectedURL := fmt.Sprintf(
558 "%s%s/services/hostedservices/%s/deployments/%s", AZURE_URL,559 "%s%s/services/hostedservices/%s/deployments/%s", AZURE_URL,
559 api.session.subscriptionId, hostedServiceName, deploymentName)560 api.session.subscriptionId, hostedServiceName, deploymentName)
560 checkRequest(c, httpRequest, expectedURL, nil, "DELETE")561 checkRequest(c, httpRequest, expectedURL, "2012-03-01", nil, "DELETE")
561}562}
562563
563func (suite *managementBaseAPISuite) TestDeleteDeployment(c *C) {564func (suite *managementBaseAPISuite) TestDeleteDeployment(c *C) {
@@ -650,7 +651,7 @@
650 expectedURL := fmt.Sprintf(651 expectedURL := fmt.Sprintf(
651 "%s%s/services/hostedservices/%s/deployments/%s", AZURE_URL,652 "%s%s/services/hostedservices/%s/deployments/%s", AZURE_URL,
652 api.session.subscriptionId, request.ServiceName, request.DeploymentName)653 api.session.subscriptionId, request.ServiceName, request.DeploymentName)
653 checkRequest(c, httpRequest, expectedURL, nil, "GET")654 checkRequest(c, httpRequest, expectedURL, "2012-03-01", nil, "GET")
654}655}
655656
656func (suite *managementBaseAPISuite) TestGetDeployment(c *C) {657func (suite *managementBaseAPISuite) TestGetDeployment(c *C) {
@@ -693,7 +694,7 @@
693 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/storageservices"694 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/storageservices"
694 expectedPayload, err := marshalXML(cssi)695 expectedPayload, err := marshalXML(cssi)
695 c.Assert(err, IsNil)696 c.Assert(err, IsNil)
696 checkOneRequest(c, &recordedRequests, expectedURL, expectedPayload, "POST")697 checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", expectedPayload, "POST")
697}698}
698699
699func (suite *managementBaseAPISuite) TestDeleteStorageAccount(c *C) {700func (suite *managementBaseAPISuite) TestDeleteStorageAccount(c *C) {
@@ -705,7 +706,7 @@
705 err := api.DeleteStorageAccount(accountName)706 err := api.DeleteStorageAccount(accountName)
706 c.Assert(err, IsNil)707 c.Assert(err, IsNil)
707708
708 checkOneRequest(c, recordedRequests, accountURL, nil, "DELETE")709 checkOneRequest(c, recordedRequests, accountURL, "2011-06-01", nil, "DELETE")
709}710}
710711
711func (suite *managementBaseAPISuite) TestGetStorageAccountKeys(c *C) {712func (suite *managementBaseAPISuite) TestGetStorageAccountKeys(c *C) {
@@ -741,7 +742,7 @@
741func assertDeleteDiskRequest(c *C, api *ManagementAPI, diskName string, httpRequest *X509Request) {742func assertDeleteDiskRequest(c *C, api *ManagementAPI, diskName string, httpRequest *X509Request) {
742 expectedURL := fmt.Sprintf("%s%s/services/disks/%s", AZURE_URL,743 expectedURL := fmt.Sprintf("%s%s/services/disks/%s", AZURE_URL,
743 api.session.subscriptionId, diskName)744 api.session.subscriptionId, diskName)
744 checkRequest(c, httpRequest, expectedURL, nil, "DELETE")745 checkRequest(c, httpRequest, expectedURL, "2012-08-01", nil, "DELETE")
745}746}
746747
747func (suite *managementBaseAPISuite) TestDeleteDisk(c *C) {748func (suite *managementBaseAPISuite) TestDeleteDisk(c *C) {
@@ -767,13 +768,14 @@
767 deploymentName := "deploymentName"768 deploymentName := "deploymentName"
768 roleName := "roleName"769 roleName := "roleName"
769 operation := newRoleOperation("RandomOperation")770 operation := newRoleOperation("RandomOperation")
770 err := api.performRoleOperation(serviceName, deploymentName, roleName, operation)771 version := "test-version"
772 err := api.performRoleOperation(serviceName, deploymentName, roleName, version, operation)
771773
772 c.Assert(err, IsNil)774 c.Assert(err, IsNil)
773 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + serviceName + "/deployments/" + deploymentName + "/roleinstances/" + roleName + "/Operations"775 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + serviceName + "/deployments/" + deploymentName + "/roleinstances/" + roleName + "/Operations"
774 expectedPayload, err := marshalXML(operation)776 expectedPayload, err := marshalXML(operation)
775 c.Assert(err, IsNil)777 c.Assert(err, IsNil)
776 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")778 checkOneRequest(c, recordedRequests, expectedURL, version, expectedPayload, "POST")
777}779}
778780
779func (suite *managementBaseAPISuite) TestStartRole(c *C) {781func (suite *managementBaseAPISuite) TestStartRole(c *C) {
@@ -787,7 +789,7 @@
787 request.RoleName + "/Operations")789 request.RoleName + "/Operations")
788 expectedPayload, err := marshalXML(startRoleOperation)790 expectedPayload, err := marshalXML(startRoleOperation)
789 c.Assert(err, IsNil)791 c.Assert(err, IsNil)
790 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")792 checkOneRequest(c, recordedRequests, expectedURL, "2012-03-01", expectedPayload, "POST")
791}793}
792794
793func (suite *managementBaseAPISuite) TestRestartRole(c *C) {795func (suite *managementBaseAPISuite) TestRestartRole(c *C) {
@@ -801,7 +803,7 @@
801 request.RoleName + "/Operations")803 request.RoleName + "/Operations")
802 expectedPayload, err := marshalXML(restartRoleOperation)804 expectedPayload, err := marshalXML(restartRoleOperation)
803 c.Assert(err, IsNil)805 c.Assert(err, IsNil)
804 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")806 checkOneRequest(c, recordedRequests, expectedURL, "2012-03-01", expectedPayload, "POST")
805}807}
806808
807func assertShutdownRoleRequest(c *C, api *ManagementAPI, request *ShutdownRoleRequest, httpRequest *X509Request) {809func assertShutdownRoleRequest(c *C, api *ManagementAPI, request *ShutdownRoleRequest, httpRequest *X509Request) {
@@ -811,7 +813,7 @@
811 request.DeploymentName, request.RoleName)813 request.DeploymentName, request.RoleName)
812 expectedPayload, err := marshalXML(shutdownRoleOperation)814 expectedPayload, err := marshalXML(shutdownRoleOperation)
813 c.Assert(err, IsNil)815 c.Assert(err, IsNil)
814 checkRequest(c, httpRequest, expectedURL, expectedPayload, "POST")816 checkRequest(c, httpRequest, expectedURL, "2012-03-01", expectedPayload, "POST")
815}817}
816818
817func (suite *managementBaseAPISuite) TestShutdownRole(c *C) {819func (suite *managementBaseAPISuite) TestShutdownRole(c *C) {
@@ -843,7 +845,7 @@
843 "/services/hostedservices/" +845 "/services/hostedservices/" +
844 request.ServiceName + "/deployments/" + request.DeploymentName +846 request.ServiceName + "/deployments/" + request.DeploymentName +
845 "/roles/" + request.RoleName)847 "/roles/" + request.RoleName)
846 checkOneRequest(c, &recordedRequests, expectedURL, nil, "GET")848 checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", nil, "GET")
847849
848 c.Check(role.RoleName, Equals, "rolename")850 c.Check(role.RoleName, Equals, "rolename")
849}851}
@@ -865,7 +867,7 @@
865867
866 expectedURL := AZURE_URL + api.session.subscriptionId + "/affinitygroups"868 expectedURL := AZURE_URL + api.session.subscriptionId + "/affinitygroups"
867 expectedBody, _ := cag.Serialize()869 expectedBody, _ := cag.Serialize()
868 checkOneRequest(c, &recordedRequests, expectedURL, []byte(expectedBody), "POST")870 checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", []byte(expectedBody), "POST")
869}871}
870872
871func (suite *managementBaseAPISuite) TestUpdateAffinityGroup(c *C) {873func (suite *managementBaseAPISuite) TestUpdateAffinityGroup(c *C) {
@@ -886,7 +888,7 @@
886 expectedURL := (AZURE_URL + api.session.subscriptionId +888 expectedURL := (AZURE_URL + api.session.subscriptionId +
887 "/affinitygroups/" + request.Name)889 "/affinitygroups/" + request.Name)
888 expectedBody, _ := uag.Serialize()890 expectedBody, _ := uag.Serialize()
889 checkOneRequest(c, &recordedRequests, expectedURL, []byte(expectedBody), "PUT")891 checkOneRequest(c, &recordedRequests, expectedURL, "2011-02-25", []byte(expectedBody), "PUT")
890}892}
891893
892func (suite *managementBaseAPISuite) TestDeleteAffinityGroup(c *C) {894func (suite *managementBaseAPISuite) TestDeleteAffinityGroup(c *C) {
@@ -904,7 +906,7 @@
904906
905 expectedURL := (AZURE_URL + api.session.subscriptionId +907 expectedURL := (AZURE_URL + api.session.subscriptionId +
906 "/affinitygroups/" + request.Name)908 "/affinitygroups/" + request.Name)
907 checkOneRequest(c, &recordedRequests, expectedURL, nil, "DELETE")909 checkOneRequest(c, &recordedRequests, expectedURL, "2011-02-25", nil, "DELETE")
908}910}
909911
910func makeNetworkConfiguration() *NetworkConfiguration {912func makeNetworkConfiguration() *NetworkConfiguration {
@@ -964,7 +966,7 @@
964 expectedURL := fmt.Sprintf(966 expectedURL := fmt.Sprintf(
965 "%s%s/services/networking/media", AZURE_URL,967 "%s%s/services/networking/media", AZURE_URL,
966 api.session.subscriptionId)968 api.session.subscriptionId)
967 checkRequest(c, httpRequest, expectedURL, nil, "GET")969 checkRequest(c, httpRequest, expectedURL, "2012-03-01", nil, "GET")
968}970}
969971
970func (suite *managementBaseAPISuite) TestGetNetworkConfiguration(c *C) {972func (suite *managementBaseAPISuite) TestGetNetworkConfiguration(c *C) {
@@ -1014,5 +1016,5 @@
10141016
1015 c.Assert(err, IsNil)1017 c.Assert(err, IsNil)
1016 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/networking/media"1018 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/networking/media"
1017 checkOneRequest(c, &recordedRequests, expectedURL, requestPayload, "PUT")1019 checkOneRequest(c, &recordedRequests, expectedURL, "2012-03-01", requestPayload, "PUT")
1018}1020}
10191021
=== modified file 'management_test.go'
--- management_test.go 2013-07-10 15:37:52 +0000
+++ management_test.go 2013-07-12 05:06:27 +0000
@@ -88,11 +88,8 @@
88 expectedURL := fmt.Sprintf(88 expectedURL := fmt.Sprintf(
89 "%ssubscriptionId/services/hostedservices/%s?embed-detail=true",89 "%ssubscriptionId/services/hostedservices/%s?embed-detail=true",
90 AZURE_URL, service.ServiceName)90 AZURE_URL, service.ServiceName)
91 c.Check(record[0], DeepEquals, &X509Request{91 c.Check(record[0].URL, Equals, expectedURL)
92 APIVersion: baseAPIVersion,92 c.Check(record[0].Method, Equals, "GET")
93 URL: expectedURL,
94 Method: "GET",
95 })
96}93}
9794
98func (suite *managementAPISuite) TestListInstancesFailsGettingDetails(c *C) {95func (suite *managementAPISuite) TestListInstancesFailsGettingDetails(c *C) {
9996
=== modified file 'poller.go'
--- poller.go 2013-07-02 14:22:42 +0000
+++ poller.go 2013-07-12 05:06:27 +0000
@@ -93,9 +93,10 @@
9393
94// Poll issues a blocking request to microsoft Azure to fetch the information94// Poll issues a blocking request to microsoft Azure to fetch the information
95// related to the operation associated with the poller.95// related to the operation associated with the poller.
96// See http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx
96func (poller operationPoller) poll() (*x509Response, error) {97func (poller operationPoller) poll() (*x509Response, error) {
97 URI := "operations/" + poller.operationID98 URI := "operations/" + poller.operationID
98 return poller.api.session.get(URI)99 return poller.api.session.get(URI, "2009-10-01")
99}100}
100101
101// IsDone returns true if the given response has a status code indicating102// IsDone returns true if the given response has a status code indicating
102103
=== modified file 'poller_test.go'
--- poller_test.go 2013-07-02 13:51:00 +0000
+++ poller_test.go 2013-07-12 05:06:27 +0000
@@ -120,7 +120,7 @@
120120
121 c.Assert(err, IsNil)121 c.Assert(err, IsNil)
122 expectedURL := AZURE_URL + api.session.subscriptionId + "/operations/" + operationID122 expectedURL := AZURE_URL + api.session.subscriptionId + "/operations/" + operationID
123 checkOneRequest(c, recordedRequests, expectedURL, []byte{}, "GET")123 checkOneRequest(c, recordedRequests, expectedURL, "2009-10-01", nil, "GET")
124}124}
125125
126var operationXMLTemplate = dedent.Dedent(`126var operationXMLTemplate = dedent.Dedent(`
@@ -212,6 +212,6 @@
212 operationPollerInstance := poller.(operationPoller)212 operationPollerInstance := poller.(operationPoller)
213 expectedURL := AZURE_URL + operationPollerInstance.api.session.subscriptionId + "/operations/" + operationID213 expectedURL := AZURE_URL + operationPollerInstance.api.session.subscriptionId + "/operations/" + operationID
214 c.Assert(len(recordedRequests), Equals, 2)214 c.Assert(len(recordedRequests), Equals, 2)
215 checkRequest(c, recordedRequests[0], expectedURL, []byte{}, "GET")215 checkRequest(c, recordedRequests[0], expectedURL, "2009-10-01", nil, "GET")
216 checkRequest(c, recordedRequests[1], expectedURL, []byte{}, "GET")216 checkRequest(c, recordedRequests[1], expectedURL, "2009-10-01", nil, "GET")
217}217}
218218
=== modified file 'x509dispatcher.go'
--- x509dispatcher.go 2013-07-10 15:42:42 +0000
+++ x509dispatcher.go 2013-07-12 05:06:27 +0000
@@ -25,47 +25,44 @@
25 verbose = newVerbose25 verbose = newVerbose
26}26}
2727
28// baseAPIVersion is the default Azure API version to use.
29const baseAPIVersion = "2013-03-01"
30
31// newX509RequestGET initializes an X509Request for a GET. You may still need28// newX509RequestGET initializes an X509Request for a GET. You may still need
32// to set further values.29// to set further values.
33func newX509RequestGET(url string) *X509Request {30func newX509RequestGET(url, apiVersion string) *X509Request {
34 return &X509Request{31 return &X509Request{
35 Method: "GET",32 Method: "GET",
36 URL: url,33 URL: url,
37 APIVersion: baseAPIVersion,34 APIVersion: apiVersion,
38 }35 }
39}36}
4037
41// newX509RequestPOST initializes an X509Request for a POST. You may still38// newX509RequestPOST initializes an X509Request for a POST. You may still
42// need to set further values.39// need to set further values.
43func newX509RequestPOST(url string, payload []byte, contentType string) *X509Request {40func newX509RequestPOST(url, apiVersion string, payload []byte, contentType string) *X509Request {
44 return &X509Request{41 return &X509Request{
45 Method: "POST",42 Method: "POST",
46 URL: url,43 URL: url,
47 APIVersion: baseAPIVersion,44 APIVersion: apiVersion,
48 Payload: payload,45 Payload: payload,
49 ContentType: contentType,46 ContentType: contentType,
50 }47 }
51}48}
5249
53// newX509RequestDELETE initializes an X509Request for a DELETE.50// newX509RequestDELETE initializes an X509Request for a DELETE.
54func newX509RequestDELETE(url string) *X509Request {51func newX509RequestDELETE(url, apiVersion string) *X509Request {
55 return &X509Request{52 return &X509Request{
56 Method: "DELETE",53 Method: "DELETE",
57 URL: url,54 URL: url,
58 APIVersion: baseAPIVersion,55 APIVersion: apiVersion,
59 }56 }
60}57}
6158
62// newX509RequestPUT initializes an X509Request for a PUT. You may still59// newX509RequestPUT initializes an X509Request for a PUT. You may still
63// need to set further values.60// need to set further values.
64func newX509RequestPUT(url string, payload []byte, contentType string) *X509Request {61func newX509RequestPUT(url, apiVersion string, payload []byte, contentType string) *X509Request {
65 return &X509Request{62 return &X509Request{
66 Method: "PUT",63 Method: "PUT",
67 URL: url,64 URL: url,
68 APIVersion: baseAPIVersion,65 APIVersion: apiVersion,
69 Payload: payload,66 Payload: payload,
70 ContentType: contentType,67 ContentType: contentType,
71 }68 }
7269
=== modified file 'x509dispatcher_test.go'
--- x509dispatcher_test.go 2013-07-10 15:42:42 +0000
+++ x509dispatcher_test.go 2013-07-12 05:06:27 +0000
@@ -78,7 +78,8 @@
78 session, err := newX509Session("subscriptionid", "cert.pem")78 session, err := newX509Session("subscriptionid", "cert.pem")
79 c.Assert(err, IsNil)79 c.Assert(err, IsNil)
80 path := "/foo/bar"80 path := "/foo/bar"
81 request := newX509RequestGET(server.URL + path)81 version := "test-version"
82 request := newX509RequestGET(server.URL + path, version)
8283
83 response, err := performX509CurlRequest(session, request)84 response, err := performX509CurlRequest(session, request)
84 c.Assert(err, IsNil)85 c.Assert(err, IsNil)
@@ -86,6 +87,7 @@
8687
87 httpRequest := <-httpRequests88 httpRequest := <-httpRequests
88 c.Check(httpRequest.Method, Equals, "GET")89 c.Check(httpRequest.Method, Equals, "GET")
90 c.Check(httpRequest.Header[http.CanonicalHeaderKey("X-Ms-Version")], DeepEquals, []string{version})
89 c.Check(httpRequest.URL.String(), Equals, path)91 c.Check(httpRequest.URL.String(), Equals, path)
90 c.Check(httpRequest.BodyContent, HasLen, 0)92 c.Check(httpRequest.BodyContent, HasLen, 0)
91}93}
@@ -101,7 +103,8 @@
101 session, err := newX509Session("subscriptionid", "cert.pem")103 session, err := newX509Session("subscriptionid", "cert.pem")
102 c.Assert(err, IsNil)104 c.Assert(err, IsNil)
103 path := "/foo/bar"105 path := "/foo/bar"
104 request := newX509RequestGET(server.URL + path)106 version := "test-version"
107 request := newX509RequestGET(server.URL + path, version)
105108
106 _, err = performX509CurlRequest(session, request)109 _, err = performX509CurlRequest(session, request)
107 c.Check(err, ErrorMatches, ".*Number of redirects hit maximum amount.*")110 c.Check(err, ErrorMatches, ".*Number of redirects hit maximum amount.*")
@@ -114,6 +117,7 @@
114 c.Error("The original request has not been performed.")117 c.Error("The original request has not been performed.")
115 }118 }
116 c.Check(httpRequest.Method, Equals, "GET")119 c.Check(httpRequest.Method, Equals, "GET")
120 c.Check(httpRequest.Header[http.CanonicalHeaderKey("X-Ms-Version")], DeepEquals, []string{version})
117 c.Check(httpRequest.URL.String(), Equals, path)121 c.Check(httpRequest.URL.String(), Equals, path)
118122
119 // _CURL_MAX_REDIRECTS redirected requests have been performed.123 // _CURL_MAX_REDIRECTS redirected requests have been performed.
@@ -139,7 +143,8 @@
139 session, err := newX509Session("subscriptionid", "cert.pem")143 session, err := newX509Session("subscriptionid", "cert.pem")
140 c.Assert(err, IsNil)144 c.Assert(err, IsNil)
141 path := "/foo/bar"145 path := "/foo/bar"
142 request := newX509RequestPOST(server.URL+path, requestBody, requestContentType)146 version := "test-version"
147 request := newX509RequestPOST(server.URL+path, version, requestBody, requestContentType)
143148
144 response, err := performX509CurlRequest(session, request)149 response, err := performX509CurlRequest(session, request)
145 c.Assert(err, IsNil)150 c.Assert(err, IsNil)
@@ -162,7 +167,8 @@
162 session, err := newX509Session("subscriptionid", "cert.pem")167 session, err := newX509Session("subscriptionid", "cert.pem")
163 c.Assert(err, IsNil)168 c.Assert(err, IsNil)
164 path := "/foo/bar"169 path := "/foo/bar"
165 request := newX509RequestDELETE(server.URL + path)170 version := "test-version"
171 request := newX509RequestDELETE(server.URL + path, version)
166172
167 response, err := performX509CurlRequest(session, request)173 response, err := performX509CurlRequest(session, request)
168 c.Assert(err, IsNil)174 c.Assert(err, IsNil)
@@ -170,6 +176,7 @@
170176
171 httpRequest := <-httpRequests177 httpRequest := <-httpRequests
172 c.Check(httpRequest.Method, Equals, "DELETE")178 c.Check(httpRequest.Method, Equals, "DELETE")
179 c.Check(httpRequest.Header[http.CanonicalHeaderKey("X-Ms-Version")], DeepEquals, []string{version})
173 c.Check(httpRequest.URL.String(), Equals, path)180 c.Check(httpRequest.URL.String(), Equals, path)
174 c.Check(httpRequest.BodyContent, HasLen, 0)181 c.Check(httpRequest.BodyContent, HasLen, 0)
175}182}
@@ -184,7 +191,8 @@
184 session, err := newX509Session("subscriptionid", "cert.pem")191 session, err := newX509Session("subscriptionid", "cert.pem")
185 c.Assert(err, IsNil)192 c.Assert(err, IsNil)
186 path := "/foo/bar"193 path := "/foo/bar"
187 request := newX509RequestPUT(server.URL+path, requestBody, "application/octet-stream")194 version := "test-version"
195 request := newX509RequestPUT(server.URL+path, version, requestBody, "application/octet-stream")
188196
189 response, err := performX509CurlRequest(session, request)197 response, err := performX509CurlRequest(session, request)
190 c.Assert(err, IsNil)198 c.Assert(err, IsNil)
@@ -193,6 +201,7 @@
193201
194 httpRequest := <-httpRequests202 httpRequest := <-httpRequests
195 c.Check(httpRequest.Method, Equals, "PUT")203 c.Check(httpRequest.Method, Equals, "PUT")
204 c.Check(httpRequest.Header[http.CanonicalHeaderKey("X-Ms-Version")], DeepEquals, []string{version})
196 c.Check(httpRequest.URL.String(), Equals, path)205 c.Check(httpRequest.URL.String(), Equals, path)
197 c.Check(httpRequest.BodyContent, DeepEquals, requestBody)206 c.Check(httpRequest.BodyContent, DeepEquals, requestBody)
198}207}
@@ -211,7 +220,7 @@
211 session, err := newX509Session("subscriptionid", "cert.pem")220 session, err := newX509Session("subscriptionid", "cert.pem")
212 c.Assert(err, IsNil)221 c.Assert(err, IsNil)
213 path := "/foo/bar"222 path := "/foo/bar"
214 request := newX509RequestGET(server.URL + path)223 request := newX509RequestGET(server.URL + path, "testversion")
215224
216 response, err := performX509CurlRequest(session, request)225 response, err := performX509CurlRequest(session, request)
217 c.Assert(err, IsNil)226 c.Assert(err, IsNil)
218227
=== modified file 'x509session.go'
--- x509session.go 2013-07-10 15:42:42 +0000
+++ x509session.go 2013-07-12 05:06:27 +0000
@@ -60,8 +60,8 @@
60// It returns the response body and/or an error. If the error is a60// It returns the response body and/or an error. If the error is a
61// ServerError, the returned body will be the one received from the server.61// ServerError, the returned body will be the one received from the server.
62// For any other kind of error, the returned body will be nil.62// For any other kind of error, the returned body will be nil.
63func (session *x509Session) get(path string) (*x509Response, error) {63func (session *x509Session) get(path, apiVersion string) (*x509Response, error) {
64 request := newX509RequestGET(session.composeURL(path))64 request := newX509RequestGET(session.composeURL(path), apiVersion)
65 response, err := _X509Dispatcher(session, request)65 response, err := _X509Dispatcher(session, request)
66 if err != nil {66 if err != nil {
67 return nil, err67 return nil, err
@@ -76,8 +76,8 @@
76// For any other kind of error, the returned body will be nil.76// For any other kind of error, the returned body will be nil.
77// Be aware that Azure may perform POST operations asynchronously. If you are77// Be aware that Azure may perform POST operations asynchronously. If you are
78// not sure, call blockUntilCompleted() on the response.78// not sure, call blockUntilCompleted() on the response.
79func (session *x509Session) post(path string, body []byte, contentType string) (*x509Response, error) {79func (session *x509Session) post(path, apiVersion string, body []byte, contentType string) (*x509Response, error) {
80 request := newX509RequestPOST(session.composeURL(path), body, contentType)80 request := newX509RequestPOST(session.composeURL(path), apiVersion, body, contentType)
81 response, err := _X509Dispatcher(session, request)81 response, err := _X509Dispatcher(session, request)
82 if err != nil {82 if err != nil {
83 return nil, err83 return nil, err
@@ -89,8 +89,8 @@
89// delete performs a DELETE request to the Azure management API.89// delete performs a DELETE request to the Azure management API.
90// Be aware that Azure may perform DELETE operations asynchronously. If you90// Be aware that Azure may perform DELETE operations asynchronously. If you
91// are not sure, call blockUntilCompleted() on the response.91// are not sure, call blockUntilCompleted() on the response.
92func (session *x509Session) delete(path string) (*x509Response, error) {92func (session *x509Session) delete(path, apiVersion string) (*x509Response, error) {
93 request := newX509RequestDELETE(session.composeURL(path))93 request := newX509RequestDELETE(session.composeURL(path), apiVersion)
94 response, err := _X509Dispatcher(session, request)94 response, err := _X509Dispatcher(session, request)
95 if err != nil {95 if err != nil {
96 return response, err96 return response, err
@@ -102,8 +102,8 @@
102// put performs a PUT request to the Azure management API.102// put performs a PUT request to the Azure management API.
103// Be aware that Azure may perform PUT operations asynchronously. If you are103// Be aware that Azure may perform PUT operations asynchronously. If you are
104// not sure, call blockUntilCompleted() on the response.104// not sure, call blockUntilCompleted() on the response.
105func (session *x509Session) put(path string, body []byte, contentType string) (*x509Response, error) {105func (session *x509Session) put(path, apiVersion string, body []byte, contentType string) (*x509Response, error) {
106 request := newX509RequestPUT(session.composeURL(path), body, contentType)106 request := newX509RequestPUT(session.composeURL(path), apiVersion, body, contentType)
107 response, err := _X509Dispatcher(session, request)107 response, err := _X509Dispatcher(session, request)
108 if err != nil {108 if err != nil {
109 return nil, err109 return nil, err
110110
=== modified file 'x509session_test.go'
--- x509session_test.go 2013-07-10 15:42:42 +0000
+++ x509session_test.go 2013-07-12 05:06:27 +0000
@@ -192,13 +192,15 @@
192 recordedRequests := make([]*X509Request, 0)192 recordedRequests := make([]*X509Request, 0)
193 rigRecordingDispatcher(&recordedRequests)193 rigRecordingDispatcher(&recordedRequests)
194194
195 receivedResponse, err := session.get(uri)195 version := "test-version"
196 receivedResponse, err := session.get(uri,version)
196 c.Assert(err, IsNil)197 c.Assert(err, IsNil)
197198
198 c.Assert(len(recordedRequests), Equals, 1)199 c.Assert(len(recordedRequests), Equals, 1)
199 request := recordedRequests[0]200 request := recordedRequests[0]
200 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)201 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)
201 c.Check(request.Method, Equals, "GET")202 c.Check(request.Method, Equals, "GET")
203 c.Check(request.APIVersion, Equals, version)
202 c.Check(*receivedResponse, DeepEquals, fixedResponse)204 c.Check(*receivedResponse, DeepEquals, fixedResponse)
203}205}
204206
@@ -207,7 +209,7 @@
207 msg := "could not dispatch request"209 msg := "could not dispatch request"
208 rigFailingDispatcher(fmt.Errorf(msg))210 rigFailingDispatcher(fmt.Errorf(msg))
209211
210 body, err := session.get("flop")212 body, err := session.get("flop", "version")
211 c.Assert(err, NotNil)213 c.Assert(err, NotNil)
212214
213 c.Check(body, IsNil)215 c.Check(body, IsNil)
@@ -222,7 +224,7 @@
222 }224 }
223 rigFixedResponseDispatcher(&fixedResponse)225 rigFixedResponseDispatcher(&fixedResponse)
224226
225 response, err := session.get("fail")227 response, err := session.get("fail", "version")
226 c.Assert(err, NotNil)228 c.Assert(err, NotNil)
227229
228 serverError := err.(*ServerError)230 serverError := err.(*ServerError)
@@ -233,6 +235,7 @@
233func (suite *x509SessionSuite) TestPostIssuesRequest(c *C) {235func (suite *x509SessionSuite) TestPostIssuesRequest(c *C) {
234 subscriptionID := "subscriptionID"236 subscriptionID := "subscriptionID"
235 uri := "resource"237 uri := "resource"
238 version := "test-version"
236 requestBody := []byte("Request body")239 requestBody := []byte("Request body")
237 requestContentType := "bogusContentType"240 requestContentType := "bogusContentType"
238 session, err := newX509Session(subscriptionID, "cert.pem")241 session, err := newX509Session(subscriptionID, "cert.pem")
@@ -246,13 +249,14 @@
246 recordedRequests := make([]*X509Request, 0)249 recordedRequests := make([]*X509Request, 0)
247 rigRecordingDispatcher(&recordedRequests)250 rigRecordingDispatcher(&recordedRequests)
248251
249 receivedResponse, err := session.post(uri, requestBody, requestContentType)252 receivedResponse, err := session.post(uri, version, requestBody, requestContentType)
250 c.Assert(err, IsNil)253 c.Assert(err, IsNil)
251254
252 c.Assert(len(recordedRequests), Equals, 1)255 c.Assert(len(recordedRequests), Equals, 1)
253 request := recordedRequests[0]256 request := recordedRequests[0]
254 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)257 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)
255 c.Check(request.Method, Equals, "POST")258 c.Check(request.Method, Equals, "POST")
259 c.Check(request.APIVersion, Equals, version)
256 c.Check(request.ContentType, Equals, requestContentType)260 c.Check(request.ContentType, Equals, requestContentType)
257 c.Check(request.Payload, DeepEquals, requestBody)261 c.Check(request.Payload, DeepEquals, requestBody)
258 c.Check(*receivedResponse, DeepEquals, fixedResponse)262 c.Check(*receivedResponse, DeepEquals, fixedResponse)
@@ -263,7 +267,7 @@
263 msg := "could not dispatch request"267 msg := "could not dispatch request"
264 rigFailingDispatcher(fmt.Errorf(msg))268 rigFailingDispatcher(fmt.Errorf(msg))
265269
266 body, err := session.post("flop", []byte("body"), "contentType")270 body, err := session.post("flop", "version", []byte("body"), "contentType")
267 c.Assert(err, NotNil)271 c.Assert(err, NotNil)
268272
269 c.Check(body, IsNil)273 c.Check(body, IsNil)
@@ -278,7 +282,7 @@
278 }282 }
279 rigFixedResponseDispatcher(&fixedResponse)283 rigFixedResponseDispatcher(&fixedResponse)
280284
281 reponse, err := session.post("fail", []byte("request body"), "contentType")285 reponse, err := session.post("fail", "version", []byte("request body"), "contentType")
282 c.Assert(err, NotNil)286 c.Assert(err, NotNil)
283287
284 serverError := err.(*ServerError)288 serverError := err.(*ServerError)
@@ -289,6 +293,7 @@
289func (suite *x509SessionSuite) TestDeleteIssuesRequest(c *C) {293func (suite *x509SessionSuite) TestDeleteIssuesRequest(c *C) {
290 subscriptionID := "subscriptionID"294 subscriptionID := "subscriptionID"
291 uri := "resource"295 uri := "resource"
296 version := "test-version"
292 session, err := newX509Session(subscriptionID, "cert.pem")297 session, err := newX509Session(subscriptionID, "cert.pem")
293 c.Assert(err, IsNil)298 c.Assert(err, IsNil)
294 // Record incoming requests, and have them return a given reply.299 // Record incoming requests, and have them return a given reply.
@@ -297,7 +302,7 @@
297 recordedRequests := make([]*X509Request, 0)302 recordedRequests := make([]*X509Request, 0)
298 rigRecordingDispatcher(&recordedRequests)303 rigRecordingDispatcher(&recordedRequests)
299304
300 response, err := session.delete(uri)305 response, err := session.delete(uri, version)
301 c.Assert(err, IsNil)306 c.Assert(err, IsNil)
302307
303 c.Check(*response, DeepEquals, fixedResponse)308 c.Check(*response, DeepEquals, fixedResponse)
@@ -305,11 +310,13 @@
305 request := recordedRequests[0]310 request := recordedRequests[0]
306 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)311 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)
307 c.Check(request.Method, Equals, "DELETE")312 c.Check(request.Method, Equals, "DELETE")
313 c.Check(request.APIVersion, Equals, version)
308}314}
309315
310func (suite *x509SessionSuite) TestPutIssuesRequest(c *C) {316func (suite *x509SessionSuite) TestPutIssuesRequest(c *C) {
311 subscriptionID := "subscriptionID"317 subscriptionID := "subscriptionID"
312 uri := "resource"318 uri := "resource"
319 version := "test-version"
313 requestBody := []byte("Request body")320 requestBody := []byte("Request body")
314 session, err := newX509Session(subscriptionID, "cert.pem")321 session, err := newX509Session(subscriptionID, "cert.pem")
315 c.Assert(err, IsNil)322 c.Assert(err, IsNil)
@@ -321,12 +328,13 @@
321 recordedRequests := make([]*X509Request, 0)328 recordedRequests := make([]*X509Request, 0)
322 rigRecordingDispatcher(&recordedRequests)329 rigRecordingDispatcher(&recordedRequests)
323330
324 _, err = session.put(uri, requestBody, "text/plain")331 _, err = session.put(uri, version, requestBody, "text/plain")
325 c.Assert(err, IsNil)332 c.Assert(err, IsNil)
326333
327 c.Assert(len(recordedRequests), Equals, 1)334 c.Assert(len(recordedRequests), Equals, 1)
328 request := recordedRequests[0]335 request := recordedRequests[0]
329 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)336 c.Check(request.URL, Equals, AZURE_URL+subscriptionID+"/"+uri)
330 c.Check(request.Method, Equals, "PUT")337 c.Check(request.Method, Equals, "PUT")
338 c.Check(request.APIVersion, Equals, version)
331 c.Check(request.Payload, DeepEquals, requestBody)339 c.Check(request.Payload, DeepEquals, requestBody)
332}340}

Subscribers

People subscribed via source and target branches

to all changes: