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

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: 155
Merged at revision: 153
Proposed branch: lp:~julian-edwards/gwacl/getrole
Merge into: lp:gwacl
Diff against target: 168 lines (+135/-1)
3 files modified
storage_test.go (+1/-1)
xmlobjects.go (+22/-0)
xmlobjects_test.go (+112/-0)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/getrole
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+172465@code.launchpad.net

Commit message

Define XML response struct for the GetRole API call.

Description of the change

This will be required for port listing/opening/closing.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

The test is ginormous. All that, basically, just to establish that the struct represents the right XML! I see the value though.

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On 02/07/13 17:39, Jeroen T. Vermeulen wrote:
> Review: Approve
>
> The test is ginormous. All that, basically, just to establish that the struct represents the right XML! I see the value though.
>

Yeah, we learned our lesson previously not testing these structs
thoroughly! The XML tags are very important and easy to get wrong.

Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storage_test.go'
2--- storage_test.go 2013-07-02 04:18:26 +0000
3+++ storage_test.go 2013-07-02 06:12:22 +0000
4@@ -397,7 +397,7 @@
5 DeepEquals, url.Values{
6 "restype": {"container"},
7 "comp": {"list"},
8- })
9+ })
10
11 // Check the DeleteBlob exchanges.
12 c.Check(
13
14=== modified file 'xmlobjects.go'
15--- xmlobjects.go 2013-07-02 00:29:45 +0000
16+++ xmlobjects.go 2013-07-02 06:12:22 +0000
17@@ -479,6 +479,28 @@
18 var restartRoleOperation = newRoleOperation("RestartRoleOperation")
19
20 //
21+// GetRole response bits
22+//
23+type GetRole struct {
24+ XMLName xml.Name `xml:"PersistentVMRole"`
25+ XMLNS string `xml:"xmlns,attr"`
26+ XMLNS_I string `xml:"xmlns:i,attr"`
27+ RoleName string `xml:"RoleName"`
28+ OsVersion string `xml:"OsVersion"`
29+ RoleType string `xml:"RoleType"` // Always PersistentVMRole
30+ ConfigurationSets []NetworkConfiguration `xml:"ConfigurationSets>ConfigurationSet"`
31+ AvailabilitySetName string `xml:"AvailabilitySetName"`
32+ OSVirtualHardDisk OSVirtualHardDisk `xml:"OSVirtualHardDisk"`
33+ RoleSize string `xml:"RoleSize"`
34+ DefaultWinRmCertificateThumbprint string `xml:"DefaultWinRmCertificateThumbprint"`
35+ // TODO: DataVirtualHardDisks and other info we don't need right now
36+}
37+
38+func (g *GetRole) Deserialize(data []byte) error {
39+ return xml.Unmarshal(data, g)
40+}
41+
42+//
43 // Storage Services bits
44 //
45
46
47=== modified file 'xmlobjects_test.go'
48--- xmlobjects_test.go 2013-07-01 01:14:04 +0000
49+++ xmlobjects_test.go 2013-07-02 06:12:22 +0000
50@@ -140,6 +140,118 @@
51 c.Check(xml, Equals, expected)
52 }
53
54+func (suite *xmlSuite) TestGetRole(c *C) {
55+ expected := &GetRole{
56+ XMLName: xml.Name{
57+ Space: "http://schemas.microsoft.com/windowsazure",
58+ Local: "PersistentVMRole"},
59+ XMLNS: XMLNS,
60+ RoleName: "name-of-the-vm",
61+ OsVersion: "operating-system-version",
62+ RoleType: "PersistentVMRole",
63+ ConfigurationSets: []NetworkConfiguration{
64+ {
65+ InputEndpoints: []InputEndpoint{
66+ {
67+ LoadBalancedEndpointSetName: "name-of-load-balanced-endpoint-set",
68+ LocalPort: 1,
69+ Name: "name-of-input-endpoint",
70+ Port: 1,
71+ Protocol: "TCP|UDP",
72+ },
73+ {
74+ LoadBalancedEndpointSetName: "name-of-load-balanced-endpoint-set",
75+ LocalPort: 2,
76+ Name: "name-of-input-endpoint",
77+ Port: 2,
78+ Protocol: "TCP|UDP",
79+ },
80+ },
81+ },
82+ },
83+ AvailabilitySetName: "name-of-availability-set",
84+ OSVirtualHardDisk: OSVirtualHardDisk{
85+ HostCaching: "host-caching-mode-of-os-disk",
86+ DiskName: "name-of-os-disk",
87+ MediaLink: "path-to-vhd",
88+ SourceImageName: "image-used-to-create-os-disk",
89+ OS: "operating-system-on-os-disk",
90+ },
91+ RoleSize: "size-of-instance",
92+ DefaultWinRmCertificateThumbprint: "winrm-cert-thumbprint",
93+ }
94+
95+ // This template is from
96+ // http://msdn.microsoft.com/en-us/library/windowsazure/jj157193.aspx
97+ template := dedent.Dedent(`
98+ <PersistentVMRole xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
99+ <RoleName>name-of-the-vm</RoleName>
100+ <OsVersion>operating-system-version</OsVersion>
101+ <RoleType>PersistentVMRole</RoleType>
102+ <ConfigurationSets>
103+ <ConfigurationSet>
104+ <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
105+ <InputEndpoints>
106+ <InputEndpoint>
107+ <LoadBalancedEndpointSetName>name-of-load-balanced-endpoint-set</LoadBalancedEndpointSetName>
108+ <LocalPort>1</LocalPort>
109+ <Name>name-of-input-endpoint</Name>
110+ <Port>1</Port>
111+ <LoadBalancerProbe>
112+ <Path>path-of-probe</Path>
113+ <Port>port-assigned-to-probe</Port>
114+ <Protocol>protocol-of-input-endpoint</Protocol>
115+ </LoadBalancerProbe>
116+ <Protocol>TCP|UDP</Protocol>
117+ <Vip>virtual-ip-address-of-input-endpoint</Vip>
118+ </InputEndpoint>
119+ <InputEndpoint>
120+ <LoadBalancedEndpointSetName>name-of-load-balanced-endpoint-set</LoadBalancedEndpointSetName>
121+ <LocalPort>2</LocalPort>
122+ <Name>name-of-input-endpoint</Name>
123+ <Port>2</Port>
124+ <LoadBalancerProbe>
125+ <Path>path-of-probe</Path>
126+ <Port>port-assigned-to-probe</Port>
127+ <Protocol>protocol-of-input-endpoint</Protocol>
128+ </LoadBalancerProbe>
129+ <Protocol>TCP|UDP</Protocol>
130+ <Vip>virtual-ip-address-of-input-endpoint</Vip>
131+ </InputEndpoint>
132+ </InputEndpoints>
133+ <SubnetNames>
134+ <SubnetName>name-of-subnet</SubnetName>
135+ </SubnetNames>
136+ </ConfigurationSet>
137+ </ConfigurationSets>
138+ <AvailabilitySetName>name-of-availability-set</AvailabilitySetName>
139+ <DataVirtualHardDisks>
140+ <DataVirtualHardDisk>
141+ <HostCaching>host-caching-mode-of-data-disk</HostCaching>
142+ <DiskName>new-or-existing-disk-name</DiskName>
143+ <Lun>logical-unit-number-of-data-disk</Lun>
144+ <LogicalDiskSizeInGB>size-of-data-disk</LogicalDiskSizeInGB>
145+ <MediaLink>path-to-vhd</MediaLink>
146+ </DataVirtualHardDisk>
147+ </DataVirtualHardDisks>
148+ <OSVirtualHardDisk>
149+ <HostCaching>host-caching-mode-of-os-disk</HostCaching>
150+ <DiskName>name-of-os-disk</DiskName>
151+ <MediaLink>path-to-vhd</MediaLink>
152+ <SourceImageName>image-used-to-create-os-disk</SourceImageName>
153+ <OS>operating-system-on-os-disk</OS>
154+ </OSVirtualHardDisk>
155+ <RoleSize>size-of-instance</RoleSize>
156+ <DefaultWinRmCertificateThumbprint>winrm-cert-thumbprint</DefaultWinRmCertificateThumbprint>
157+ </PersistentVMRole>
158+ `)
159+
160+ observed := &GetRole{}
161+ err := observed.Deserialize([]byte(template))
162+ c.Assert(err, IsNil)
163+ c.Assert(observed, DeepEquals, expected)
164+}
165+
166 func (suite *xmlSuite) TestDeployment(c *C) {
167 deployment := makeDeployment()
168 dns := deployment.DNS[0]

Subscribers

People subscribed via source and target branches

to all changes: