Merge lp:~rvb/gwacl/media-link into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 174
Merged at revision: 173
Proposed branch: lp:~rvb/gwacl/media-link
Merge into: lp:gwacl
Diff against target: 82 lines (+27/-4)
4 files modified
example/management/run.go (+3/-3)
management_base_test.go (+0/-1)
xmlobjects.go (+10/-0)
xmlobjects_test.go (+14/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/media-link
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+173899@code.launchpad.net

Commit message

Add CreateVirtualHardDiskMediaLink utility.

Description of the change

The main reason for this new utility is to avoid having to hardcode the Azure hostname in client applications like the Azure provider in Juju.

Drive-by fix: fix message displayed in example/management/run.go

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

Looks good.

[1]

+func CreateVirtualHardDiskMediaLink(StorageName, StoragePath string) string {
+    pathComponents := strings.Split(StoragePath, "/")

I think you ought to strip leading and trailing forward-slashes first:

  len(strings.Split("/fred/", "/")) -> 3

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

> [1]
>
> +func CreateVirtualHardDiskMediaLink(StorageName, StoragePath string) string {
> +    pathComponents := strings.Split(StoragePath, "/")
>
> I think you ought to strip leading and trailing forward-slashes first:
>
>  len(strings.Split("/fred/", "/")) -> 3

I don't this matters much actually; I didn't read ahead (i.e. this is only used for validation).

lp:~rvb/gwacl/media-link updated
174. By Raphaël Badin

Fix run.go.

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

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'example/management/run.go'
2--- example/management/run.go 2013-07-10 09:12:01 +0000
3+++ example/management/run.go 2013-07-10 10:28:25 +0000
4@@ -102,12 +102,12 @@
5 release := "13.04"
6
7 affinityGroupName := gwacl.MakeRandomHostname("affinitygroup")
8- fmt.Printf("Creating an affinity group...")
9+ fmt.Println("Creating an affinity group...")
10 cag := gwacl.NewCreateAffinityGroup(affinityGroupName, "affinity-label", "affinity-description", location)
11 err = api.CreateAffinityGroup(&gwacl.CreateAffinityGroupRequest{
12 CreateAffinityGroup: cag})
13 checkError(err)
14- fmt.Println("created %s", affinityGroupName)
15+ fmt.Printf("Created affinity group %s\n", affinityGroupName)
16
17 defer func() {
18 fmt.Println("Deleting affinity group %s", affinityGroupName)
19@@ -185,7 +185,7 @@
20 fmt.Println("Done deleting storage account\n")
21 }()
22
23- mediaLink := fmt.Sprintf("http://%s.blob.core.windows.net/vhds/%s.vhd", storageAccount, vhdName)
24+ mediaLink := gwacl.CreateVirtualHardDiskMediaLink(storageAccount, fmt.Sprintf("vhds/%s.vhd", vhdName))
25 diskName := makeRandomIdentifier("gwacldisk", 16)
26 diskLabel := makeRandomIdentifier("gwacl", 64)
27 vhd := gwacl.NewOSVirtualHardDisk("", diskLabel, diskName, mediaLink, sourceImageName, "Linux")
28
29=== modified file 'management_base_test.go'
30--- management_base_test.go 2013-07-10 09:12:01 +0000
31+++ management_base_test.go 2013-07-10 10:28:25 +0000
32@@ -1017,4 +1017,3 @@
33 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/networking/media"
34 checkOneRequest(c, &recordedRequests, expectedURL, requestPayload, "PUT")
35 }
36-
37
38=== modified file 'xmlobjects.go'
39--- xmlobjects.go 2013-07-10 09:12:01 +0000
40+++ xmlobjects.go 2013-07-10 10:28:25 +0000
41@@ -271,6 +271,16 @@
42 }
43 }
44
45+// CreateVirtualHardDiskMediaLink creates a media link string used to specify
46+// the location of a physical blob in the given Windows Azure storage account.
47+// Example: http://example.blob.core.windows.net/disks/mydatadisk.vhd
48+func CreateVirtualHardDiskMediaLink(StorageName, StoragePath string) string {
49+ pathComponents := strings.Split(StoragePath, "/")
50+ components := append(pathComponents, StorageName)
51+ checkPathComponents(components...)
52+ return fmt.Sprintf("http://%s.blob.core.windows.net/%s", StorageName, StoragePath)
53+}
54+
55 type Role struct {
56 RoleName string `xml:"RoleName"`
57 RoleType string `xml:"RoleType"` // Always "PersistentVMRole"
58
59=== modified file 'xmlobjects_test.go'
60--- xmlobjects_test.go 2013-07-10 09:12:01 +0000
61+++ xmlobjects_test.go 2013-07-10 10:28:25 +0000
62@@ -888,6 +888,20 @@
63 c.Check(deployment.VirtualNetworkName, Equals, virtualNetworkName)
64 }
65
66+func (suite *xmlSuite) TestCreateVirtualHardDiskMediaLinkHappyPath(c *C) {
67+ mediaLink := CreateVirtualHardDiskMediaLink("storage-name", "storage/path")
68+ c.Check(mediaLink, Equals, "http://storage-name.blob.core.windows.net/storage/path")
69+}
70+
71+func (suite *xmlSuite) TestCreateVirtualHardDiskMediaLinkChecksParams(c *C) {
72+ c.Check(
73+ func() { CreateVirtualHardDiskMediaLink("foo^bar", "valid") },
74+ PanicMatches, "'foo\\^bar' contains URI special characters")
75+ c.Check(
76+ func() { CreateVirtualHardDiskMediaLink("valid", "a/foo^bar/test") },
77+ PanicMatches, "'foo\\^bar' contains URI special characters")
78+}
79+
80 func (suite *xmlSuite) TestCreateStorageServiceInput(c *C) {
81 s := makeCreateStorageServiceInput()
82 extProperty := s.ExtendedProperties[0]

Subscribers

People subscribed via source and target branches

to all changes: